Skip to content

Ghidra is a software reverse engineering (SRE) framework

GT-3438 - Version Tracking - removed exception being thrown by the Exact Function Instructions Match correlator when the number of instructions of the functions differed.

dragonmacherb9143a626581
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/match/ExactInstructionsFunctionHasher.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/match/ExactInstructionsFunctionHasher.java
index 559d7bac57..ca078ec478 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/match/ExactInstructionsFunctionHasher.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/match/ExactInstructionsFunctionHasher.java
@@ -46,8 +46,12 @@ public class ExactInstructionsFunctionHasher extends AbstractFunctionHasher {
Pair<Integer, ArrayList<CodeUnit>> bCodeUnitsPair =
getAllCodeUnits(monitor, funcB.getProgram(), funcB.getBody());
if (aCodeUnitsPair.second.size() != bCodeUnitsPair.second.size()) {
- throw new RuntimeException("different number of codeunits");
+ // This code was expecting the client to validate that the number of instructions in
+ // each function is the same. There is no easy way to do that. Rather than force
+ // the client to do that, just handle it here. (This code is not currently used.)
+ return 0;
}
+
for (int ii = 0; ii < aCodeUnitsPair.second.size(); ++ii) {
CodeUnit aUnit = aCodeUnitsPair.second.get(ii);
CodeUnit bUnit = aCodeUnitsPair.second.get(ii);
diff --git a/Ghidra/Features/VersionTracking/src/main/java/ghidra/feature/vt/api/correlator/program/FunctionMatchProgramCorrelator.java b/Ghidra/Features/VersionTracking/src/main/java/ghidra/feature/vt/api/correlator/program/FunctionMatchProgramCorrelator.java
index 3112059da2..2865aff018 100644
--- a/Ghidra/Features/VersionTracking/src/main/java/ghidra/feature/vt/api/correlator/program/FunctionMatchProgramCorrelator.java
+++ b/Ghidra/Features/VersionTracking/src/main/java/ghidra/feature/vt/api/correlator/program/FunctionMatchProgramCorrelator.java
@@ -18,7 +18,6 @@ package ghidra.feature.vt.api.correlator.program;
import java.util.ArrayList;
import java.util.List;
-import ghidra.app.plugin.core.entropy.EntropyCalculate;
import ghidra.app.plugin.match.FunctionHasher;
import ghidra.app.plugin.match.MatchFunctions;
import ghidra.app.plugin.match.MatchFunctions.MatchedFunctions;
@@ -30,7 +29,6 @@ import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.listing.Function;
import ghidra.program.model.listing.Program;
-import ghidra.program.model.mem.MemoryBlock;
import ghidra.util.exception.CancelledException;
import ghidra.util.task.TaskMonitor;
@@ -51,8 +49,6 @@ public class FunctionMatchProgramCorrelator extends VTAbstractProgramCorrelator
this.hasher = hasher;
}
- private EntropyCalculate[] entropy;
-
@Override
protected void doCorrelate(VTMatchSet matchSet, TaskMonitor monitor) throws CancelledException {
int functionMinimumSize = getOptions().getInt(
@@ -63,8 +59,6 @@ public class FunctionMatchProgramCorrelator extends VTAbstractProgramCorrelator
getSourceAddressSet(), getDestinationProgram(), getDestinationAddressSet(),
functionMinimumSize, oneToOne, !oneToOne, hasher, monitor);
- buildEntropy(1024);
-
monitor.setMessage("Scoring " + matchedFunctions.size() + " matches...");
monitor.initialize(matchedFunctions.size());
List<VTMatchInfo> results = new ArrayList<VTMatchInfo>();
@@ -91,31 +85,6 @@ public class FunctionMatchProgramCorrelator extends VTAbstractProgramCorrelator
}
}
- private void buildEntropy(int chunksize) {
- MemoryBlock[] blocks = getDestinationProgram().getMemory().getBlocks();
- entropy = new EntropyCalculate[blocks.length];
- for (int ii = 0; ii < entropy.length; ++ii) {
- entropy[ii] = new EntropyCalculate(blocks[ii], chunksize);
- }
- }
-
- private int getEntropyIndex(Address addr) {
- MemoryBlock[] blocks = getDestinationProgram().getMemory().getBlocks();
- int i = 0;
- while (i < blocks.length) {
- if (blocks[i].contains(addr)) {
- break;
- }
- i += 1;
- }
- if (i == blocks.length) {
- return -1;
- }
- int offset = (int) addr.subtract(blocks[i].getStart());
-
- return entropy[i].getValue(offset);
- }
-
private VTMatchInfo generateMatchFromMatchedFunctions(VTMatchSet matchSet,
MatchedFunctions matchedFunction, TaskMonitor monitor) {
@@ -136,12 +105,6 @@ public class FunctionMatchProgramCorrelator extends VTAbstractProgramCorrelator
return null;
}
- int commonBitCount = hasher.commonBitCount(sourceFunction, destinationFunction, monitor);
- int totalMaxBits = Math.max(sourceLength, destinationLength) * 8;
- double entropyIndex = getEntropyIndex(destinationAddress);
- double bits = commonBitCount * entropyIndex / 255.0;
- double realSimilarity = (double) commonBitCount / totalMaxBits;
-
VTMatchInfo matchInfo = new VTMatchInfo(matchSet);
matchInfo.setSimilarityScore(similarity);