mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-06 03:50:02 +02:00
GP-2906_James_exhaust_function_interiors
This commit is contained in:
parent
703043dbf2
commit
d6352a3247
2 changed files with 35 additions and 3 deletions
|
@ -277,15 +277,18 @@ public class RandomForestTrainingTask extends Task {
|
|||
monitor.setMessage(
|
||||
"Selecting " + numEntries * factor + " random addresses within function interiors");
|
||||
start = System.nanoTime();
|
||||
AddressSetView randomFuncInteriors =
|
||||
RandomSubsetUtils.randomSubset(selectableInteriors, numEntries * factor, monitor);
|
||||
long numInteriors = numEntries * factor;
|
||||
|
||||
AddressSetView randomFuncInteriors = numInteriors < selectableInteriors.getNumAddresses()
|
||||
? RandomSubsetUtils.randomSubset(selectableInteriors, numInteriors, monitor)
|
||||
: selectableInteriors;
|
||||
end = System.nanoTime();
|
||||
Msg.info(this, String.format("factor: %d elapsed selecting random interiors: %g seconds",
|
||||
factor, (end - start) / NANOSECONDS_PER_SECOND));
|
||||
trainingNegative = trainingNegative.union(randomFuncInteriors);
|
||||
if (trainingNegative.isEmpty()) {
|
||||
Msg.showError(this, null, "Data Gathering Error",
|
||||
"No function interiors in training set");
|
||||
"No non-starts in training set for sampling factor " + factor);
|
||||
return null;
|
||||
}
|
||||
if (trainingPositive.intersects(trainingNegative)) {
|
||||
|
|
|
@ -358,4 +358,33 @@ public class RandomForestTrainingTaskTest extends AbstractProgramBasedTest {
|
|||
assertTrue(data.getTestNegative().contains(definedData));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExhaustingFunctionInteriors() throws CancelledException {
|
||||
params = new FunctionStartRFParams(program);
|
||||
params.setMaxStarts(5);
|
||||
int tooBig = 10;
|
||||
Address begin = program.getSymbolTable().getSymbols("entry").next().getAddress();
|
||||
AddressSet entries = new AddressSet();
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
entries.add(begin.add(i));
|
||||
}
|
||||
AddressSet interiors = new AddressSet();
|
||||
for (int i = 10; i < 25; ++i) {
|
||||
interiors.add(begin.add(i));
|
||||
}
|
||||
AddressSet definedData = new AddressSet();
|
||||
for (int i = 25; i < 30; ++i) {
|
||||
definedData.add(begin.add(i));
|
||||
}
|
||||
RandomForestTrainingTask task = new RandomForestTrainingTask(program, params, null,
|
||||
RandomForestFunctionFinderPlugin.TEST_SET_MAX_SIZE_DEFAULT);
|
||||
TrainingAndTestData data =
|
||||
task.getTrainingAndTestData(entries, interiors, definedData, tooBig, TaskMonitor.DUMMY);
|
||||
assertTrue(data.getTrainingPositive().getNumAddresses() == 5);
|
||||
assertTrue(data.getTestPositive().getNumAddresses() == 5);
|
||||
assertTrue(data.getTestPositive().union(data.getTrainingPositive()).equals(entries));
|
||||
assertTrue(data.getTrainingNegative().equals(interiors));
|
||||
assertTrue(data.getTestNegative().equals(definedData));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue