Skip to content

Commit 560497c

Browse files
committed
Merge remote-tracking branch 'origin/GP-5762_ghidra007_autoVT_increase_dupe_correlator_min' into Ghidra_11.4
2 parents b0ca297 + 160dfd1 commit 560497c

File tree

3 files changed

+39
-32
lines changed

3 files changed

+39
-32
lines changed

Ghidra/Features/VersionTracking/src/main/java/ghidra/feature/vt/gui/actions/AutoVersionTrackingTask.java

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
7+
*
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -235,7 +235,6 @@ private void doRun(TaskMonitor realMonitor) throws CancelledException {
235235
monitor.doIncrementProgress();
236236
}
237237

238-
239238
// This is the first of the "speculative" post-correlator match algorithm. The correlator
240239
// returns all duplicate function instruction matches so there will always be more
241240
// than one possible match for each function. The compare mechanism used by the
@@ -255,7 +254,7 @@ private void doRun(TaskMonitor realMonitor) throws CancelledException {
255254
// if Auto VT min function length for dupe matches is different than current
256255
// exact instruction match setting temporarily change it for auto VT run
257256
int dupFunctionMinLen =
258-
toolOptions.getInt(VTOptionDefines.DUPE_FUNCTION_CORRELATOR_MIN_LEN_OPTION, 10);
257+
toolOptions.getInt(VTOptionDefines.DUPE_FUNCTION_CORRELATOR_MIN_LEN_OPTION, 25);
259258

260259
vtOptions.setInt(
261260
ExactMatchInstructionsProgramCorrelatorFactory.FUNCTION_MINIMUM_SIZE,
@@ -279,9 +278,10 @@ private void doRun(TaskMonitor realMonitor) throws CancelledException {
279278
toolOptions.getBoolean(VTOptionDefines.RUN_REF_CORRELATORS_OPTION, true);
280279
if (runRefCorrelators) {
281280

282-
double minScore = toolOptions.getDouble(VTOptionDefines.REF_CORRELATOR_MIN_SCORE_OPTION, 0.95);
283-
double minConf = toolOptions.getDouble(VTOptionDefines.REF_CORRELATOR_MIN_CONF_OPTION, 10.0);
284-
281+
double minScore =
282+
toolOptions.getDouble(VTOptionDefines.REF_CORRELATOR_MIN_SCORE_OPTION, 0.95);
283+
double minConf =
284+
toolOptions.getDouble(VTOptionDefines.REF_CORRELATOR_MIN_CONF_OPTION, 10.0);
285285

286286
// Get the number of data and function matches
287287
int numDataMatches = getNumberOfDataMatches(monitor);
@@ -497,32 +497,31 @@ private Set<VTMatch> findGoodImpliedMatches(Collection<VTMatch> matchesToProcess
497497
int minVoteCountNeeded, int maxConflictsAllowed,
498498
TaskMonitor monitor) throws CancelledException {
499499

500-
501500
Set<VTMatch> goodImpliedMatches = new HashSet<>();
502501

503502
for (VTMatch match : matchesToProcess) {
504-
monitor.checkCancelled();
503+
monitor.checkCancelled();
505504

506-
VTAssociation association = match.getAssociation();
505+
VTAssociation association = match.getAssociation();
507506

508-
// skip if already accepted or blocked match
509-
if (association.getStatus() != VTAssociationStatus.AVAILABLE) {
510-
continue;
511-
}
507+
// skip if already accepted or blocked match
508+
if (association.getStatus() != VTAssociationStatus.AVAILABLE) {
509+
continue;
510+
}
512511

513-
// skip if there are any conflicting associations
514-
int numConflicts = association.getRelatedAssociations().size() - 1;
515-
if (numConflicts > maxConflictsAllowed) {
516-
continue;
517-
}
512+
// skip if there are any conflicting associations
513+
int numConflicts = association.getRelatedAssociations().size() - 1;
514+
if (numConflicts > maxConflictsAllowed) {
515+
continue;
516+
}
518517

519-
int voteCount = association.getVoteCount();
518+
int voteCount = association.getVoteCount();
520519

521-
if (voteCount >= minVoteCountNeeded) {
522-
goodImpliedMatches.add(match);
523-
}
520+
if (voteCount >= minVoteCountNeeded) {
521+
goodImpliedMatches.add(match);
522+
}
524523

525-
monitor.incrementProgress();
524+
monitor.incrementProgress();
526525
}
527526

528527
return goodImpliedMatches;
@@ -893,7 +892,6 @@ private VTMatch getAssociationMatchFromMatchSet(VTAssociation association,
893892
return null;
894893
}
895894

896-
897895
/**
898896
* From the given related association, ie a group of src/dest pairs of functions with identical
899897
* instructions, use operand information to find any unique matches in the set.
@@ -907,7 +905,6 @@ private List<VTAssociation> findUniqueAssociations(
907905
Collection<VTAssociation> relatedAssociations, TaskMonitor monitor)
908906
throws CancelledException {
909907

910-
911908
// create function to operand map maps for each source and destination function
912909
// in the given related associations (src/dst function pairs)
913910
Map<Function, Map<Long, Map<Integer, Object>>> sourceFunctionsMap =
@@ -916,7 +913,6 @@ private List<VTAssociation> findUniqueAssociations(
916913
Map<Function, Map<Long, Map<Integer, Object>>> destFunctionsMap =
917914
createFunctionsMap(relatedAssociations, false, monitor);
918915

919-
920916
// only functions with scalar or address operands are mapped so the lists could be
921917
// empty if there are functions with no operand info to be mapped
922918
if (sourceFunctionsMap.isEmpty() || destFunctionsMap.isEmpty()) {
@@ -1032,7 +1028,6 @@ private Map<Function, Map<Long, Map<Integer, Object>>> createFunctionsMap(
10321028
return functionsMap;
10331029
}
10341030

1035-
10361031
/**
10371032
* Using the given source function's map and a list of destination function maps, and a list
10381033
* of destination functions to omit because they already have found matches, try to find a
@@ -1214,7 +1209,6 @@ private boolean isSameOperandType(Address addr1, Address addr2) {
12141209
*/
12151210
private boolean hasAnyAssociations(Address source, Address dest) {
12161211

1217-
12181212
Collection<VTAssociation> sourceAssociations = session.getAssociationManager()
12191213
.getRelatedAssociationsBySourceAddress(source);
12201214

@@ -1261,7 +1255,6 @@ private Map<Long, Map<Integer, Object>> mapFunctionScalarAndAddressOperands(
12611255
throws CancelledException {
12621256

12631257
Map<Long, Map<Integer, Object>> offsetToOperandsMap = new HashMap<>();
1264-
12651258

12661259
Program program = function.getProgram();
12671260

@@ -1278,7 +1271,7 @@ private Map<Long, Map<Integer, Object>> mapFunctionScalarAndAddressOperands(
12781271
if (map.keySet().isEmpty()) {
12791272
continue;
12801273
}
1281-
1274+
12821275
// get offset from top of function to use in function to operandMap map
12831276
// can be positive or negative offset (positive means instruction address is after
12841277
// the entry address, negative means instruction address is before entry address)

Ghidra/Features/VersionTracking/src/main/java/ghidra/feature/vt/gui/provider/matchtable/VTMatchTableProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ private void initializeOptions() {
848848
.setOptionsHelpLocation(
849849
new HelpLocation(VTPlugin.HELP_TOPIC_NAME, "Auto_Version_Tracking_Options"));
850850

851-
vtOptions.registerOption(DUPE_FUNCTION_CORRELATOR_MIN_LEN_OPTION, 10, null,
851+
vtOptions.registerOption(DUPE_FUNCTION_CORRELATOR_MIN_LEN_OPTION, 25, null,
852852
"Minimum Function Length of Auto Version Tracking Duplicate Function Correlator");
853853
vtOptions.getOptions(DUPE_FUNCTION_CORRELATOR_MIN_LEN_OPTION)
854854
.setOptionsHelpLocation(

Ghidra/Features/VersionTracking/src/test.slow/java/ghidra/feature/vt/api/VTAutoVersionTrackingTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ public void testRunAutoVT_moreCautious() throws Exception {
9090

9191
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_SCORE_OPTION, 0.999999999);
9292
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_CONF_OPTION, 10.0);
93+
//min was 10 when tests first written but have changed since so now need to set it manually
94+
vtOptions.setInt(VTOptionDefines.DUPE_FUNCTION_CORRELATOR_MIN_LEN_OPTION, 10);
9395

9496
runAutoVTCommand(vtOptions);
9597

@@ -155,6 +157,8 @@ public void testRunAutoVT_aLittleLessCautious() throws Exception {
155157

156158
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_SCORE_OPTION, 0.5);
157159
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_CONF_OPTION, 1.0);
160+
//min was 10 when tests first written but have changed since so now need to set it manually
161+
vtOptions.setInt(VTOptionDefines.DUPE_FUNCTION_CORRELATOR_MIN_LEN_OPTION, 10);
158162

159163
runAutoVTCommand(vtOptions);
160164

@@ -279,6 +283,8 @@ public void testDuplicateMatches_DifferentRegisterOperands_allUnique() throws Ex
279283

280284
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_SCORE_OPTION, 1.0);
281285
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_CONF_OPTION, 10.0);
286+
//min was 10 when tests first written but have changed since so now need to set it manually
287+
vtOptions.setInt(VTOptionDefines.DUPE_FUNCTION_CORRELATOR_MIN_LEN_OPTION, 10);
282288

283289
runAutoVTCommand(vtOptions);
284290

@@ -329,6 +335,8 @@ public void testDuplicateMatches_DifferentRegisterOperands_someNotUnique() throw
329335

330336
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_SCORE_OPTION, 1.0);
331337
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_CONF_OPTION, 10.0);
338+
//min was 10 when tests first written but have changed since so now need to set it manually
339+
vtOptions.setInt(VTOptionDefines.DUPE_FUNCTION_CORRELATOR_MIN_LEN_OPTION, 10);
332340

333341
runAutoVTCommand(vtOptions);
334342

@@ -369,6 +377,8 @@ public void testDuplicateMatches_allIdentical() throws Exception {
369377

370378
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_SCORE_OPTION, 1.0);
371379
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_CONF_OPTION, 10.0);
380+
//min was 10 when tests first written but have changed since so now need to set it manually
381+
vtOptions.setInt(VTOptionDefines.DUPE_FUNCTION_CORRELATOR_MIN_LEN_OPTION, 10);
372382

373383
runAutoVTCommand(vtOptions);
374384

@@ -442,6 +452,8 @@ public void testDuplicateMatches_threeIdenticalthreeUnique() throws Exception {
442452

443453
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_SCORE_OPTION, 1.0);
444454
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_CONF_OPTION, 10.0);
455+
//min was 10 when tests first written but have changed since so now need to set it manually
456+
vtOptions.setInt(VTOptionDefines.DUPE_FUNCTION_CORRELATOR_MIN_LEN_OPTION, 10);
445457

446458
runAutoVTCommand(vtOptions);
447459

@@ -600,6 +612,8 @@ public void testDuplicateMatches_DifferentConstantOperands_allUnique() throws Ex
600612

601613
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_SCORE_OPTION, 1.0);
602614
vtOptions.setDouble(VTOptionDefines.REF_CORRELATOR_MIN_CONF_OPTION, 10.0);
615+
//min was 10 when tests first written but have changed since so now need to set it manually
616+
vtOptions.setInt(VTOptionDefines.DUPE_FUNCTION_CORRELATOR_MIN_LEN_OPTION, 10);
603617

604618
runAutoVTCommand(vtOptions);
605619

0 commit comments

Comments
 (0)