GP-5948 Improved auto vt dupe match's operand equivalency check to account for internal function ref operands.

This commit is contained in:
ghidra007 2025-08-26 16:05:05 +00:00
parent daec88be49
commit f71ae463d2

View file

@ -89,14 +89,9 @@ public class AutoVersionTrackingTask extends Task {
/** /**
* Constructor for a modal/blocking AutoVersionTrackingTask * Constructor for a modal/blocking AutoVersionTrackingTask
* *
* @param session The Version Tracking session containing the source, destination, correlator * @param session The Version Tracking session containing the source, destination, correlator
* and match information needed for this command. * and match information needed for this command.
* @param toolOptions the options used when applying matches * @param toolOptions the options used when applying matches
* @param minCombinedReferenceCorrelatorScore The minimum score used to limit matches created by
* the Combined Reference Correlator.
* @param minCombinedReferenceCorrelatorConfidence The minimum confidence used to limit matches
* created by the Combined Reference Correlator.
*/ */
public AutoVersionTrackingTask(VTSession session, ToolOptions toolOptions) { public AutoVersionTrackingTask(VTSession session, ToolOptions toolOptions) {
super(NAME, true, true, true); super(NAME, true, true, true);
@ -379,11 +374,9 @@ public class AutoVersionTrackingTask extends Task {
/** /**
* Method to create implied matches for the existing applied matches in the current session * Method to create implied matches for the existing applied matches in the current session
* @param applyGoodMatches if true, create applied matches for "good" implied matches based on
* votes/conflict information. For all the applied implied matches, rerun the creation of
* applied matches until no new ones found.
* @param applyGoodMatches if true, apply matches if minVotes met and maxConflicts not exceeded * @param applyGoodMatches if true, apply matches if minVotes met and maxConflicts not exceeded
* for particular match, if false, don't apply any matches * for particular match, if false, don't apply any matches. For all the applied implied matches,
* rerun the creation of applied matches until no new ones found.
* @param minVotes minimum votes needed to apply a match * @param minVotes minimum votes needed to apply a match
* @param maxConflicts maximum conflicts allowed to apply a match * @param maxConflicts maximum conflicts allowed to apply a match
* @param monitor the task monitor * @param monitor the task monitor
@ -646,7 +639,7 @@ public class AutoVersionTrackingTask extends Task {
continue; continue;
} }
if (hasAcceptedRelatedAssociation(association, monitor)) { if (hasAcceptedRelatedAssociation(association)) {
Msg.warn(AutoVersionTrackingTask.class, Msg.warn(AutoVersionTrackingTask.class,
"This association has a related association with an accepted match so cannot " + "This association has a related association with an accepted match so cannot " +
"make this association accepted which would try to block the already accepted " + "make this association accepted which would try to block the already accepted " +
@ -702,12 +695,11 @@ public class AutoVersionTrackingTask extends Task {
* Method to test whether any related associations (ie associations with either the same source * Method to test whether any related associations (ie associations with either the same source
* or the same destination address) have already been accepted * or the same destination address) have already been accepted
* @param association the given association (src/dest match pair) * @param association the given association (src/dest match pair)
* @param taskMonitor the task monitor
* @return true if any related associations have already been accepted, false otherwise * @return true if any related associations have already been accepted, false otherwise
* @throws CancelledException if cancelled * @throws CancelledException if cancelled
*/ */
private boolean hasAcceptedRelatedAssociation(VTAssociation association, private boolean hasAcceptedRelatedAssociation(VTAssociation association)
TaskMonitor taskMonitor) throws CancelledException { throws CancelledException {
VTAssociationManager vtAssocManager = session.getAssociationManager(); VTAssociationManager vtAssocManager = session.getAssociationManager();
@ -745,7 +737,7 @@ public class AutoVersionTrackingTask extends Task {
* function pair association or it would have been identified as a unique match by the exact * function pair association or it would have been identified as a unique match by the exact
* unique function instruction correltor. This method attempts to find unique matches from * unique function instruction correltor. This method attempts to find unique matches from
* within the related subsets by comparing operand information. * within the related subsets by comparing operand information.
* @param matches The set of matches from the duplicate function instruction correlator * @param matchSet The set of matches from the duplicate function instruction correlator
* @param monitor Allows user to cancel * @param monitor Allows user to cancel
* @return true if there are any markup errors, false if no markup errors * @return true if there are any markup errors, false if no markup errors
* @throws CancelledException if cancelled * @throws CancelledException if cancelled
@ -1169,7 +1161,8 @@ public class AutoVersionTrackingTask extends Task {
* Method to check to see if both addresses have functions at them or the same data type at them * Method to check to see if both addresses have functions at them or the same data type at them
* @param addr1 the first Address * @param addr1 the first Address
* @param addr2 the second Address * @param addr2 the second Address
* @return * @return true if same operand type (ie both functions, both same data type, same internal
* function reference
*/ */
private boolean isSameOperandType(Address addr1, Address addr2) { private boolean isSameOperandType(Address addr1, Address addr2) {
@ -1179,9 +1172,22 @@ public class AutoVersionTrackingTask extends Task {
if (function2 != null) { if (function2 != null) {
return true; return true;
} }
else {
return false; return false;
} }
// are both references to same offset in the mapped functions
function1 = sourceProgram.getFunctionManager().getFunctionContaining(addr1);
if (function1 != null) {
Function function2 =
destinationProgram.getFunctionManager().getFunctionContaining(addr2);
if (function2 != null) {
long offsetInFunction1 = getOffsetInFunction(function1, addr1);
long offsetInFunction2 = getOffsetInFunction(function2, addr2);
if (offsetInFunction1 == offsetInFunction2) {
return true;
}
}
return false;
} }
Data data1 = sourceProgram.getListing().getDataAt(addr1); Data data1 = sourceProgram.getListing().getDataAt(addr1);
@ -1275,9 +1281,7 @@ public class AutoVersionTrackingTask extends Task {
// get offset from top of function to use in function to operandMap map // get offset from top of function to use in function to operandMap map
// can be positive or negative offset (positive means instruction address is after // can be positive or negative offset (positive means instruction address is after
// the entry address, negative means instruction address is before entry address) // the entry address, negative means instruction address is before entry address)
Long entryOffset = function.getEntryPoint().getOffset(); long offset = getOffsetInFunction(function, inst.getAddress());
Long instOffset = inst.getAddress().getOffset();
Long offset = instOffset - entryOffset;
offsetToOperandsMap.put(offset, map); offsetToOperandsMap.put(offset, map);
} }
@ -1289,6 +1293,15 @@ public class AutoVersionTrackingTask extends Task {
return offsetToOperandsMap; return offsetToOperandsMap;
} }
private long getOffsetInFunction(Function function, Address addressInFunction) {
long entryOffset = function.getEntryPoint().getOffset();
long addrOffset = addressInFunction.getOffset();
long offset = addrOffset - entryOffset;
return offset;
}
/** /**
* Method to create offset/operand mapping for each function in match set * Method to create offset/operand mapping for each function in match set
* if more than one identical offset/operand mapping in src or dest piles then remove * if more than one identical offset/operand mapping in src or dest piles then remove
@ -1343,7 +1356,7 @@ public class AutoVersionTrackingTask extends Task {
// skip already accepted or blocked matches // skip already accepted or blocked matches
if (association.getStatus() == VTAssociationStatus.AVAILABLE) { if (association.getStatus() == VTAssociationStatus.AVAILABLE) {
if (hasAcceptedRelatedAssociation(association, monitor)) { if (hasAcceptedRelatedAssociation(association)) {
Msg.warn(AutoVersionTrackingTask.class, Msg.warn(AutoVersionTrackingTask.class,
"This association has a related association with an accepted match so cannot " + "This association has a related association with an accepted match so cannot " +
"make this association accepted which would try to block the already accepted " + "make this association accepted which would try to block the already accepted " +