Merge remote-tracking branch 'origin/GP-0-dragonmacher-test-fixes-3-31-23'

This commit is contained in:
Ryan Kurtz
2023-04-03 06:05:35 -04:00
2 changed files with 36 additions and 53 deletions
@@ -80,7 +80,7 @@ class ListingDisplaySearcher implements Searcher {
/** /**
* Constructor * Constructor
* @param codeViewerService service to get the Layouts * @param tool the tool
* @param program current program * @param program current program
* @param startLocation location from where to begin searching * @param startLocation location from where to begin searching
* @param set address set; may be null * @param set address set; may be null
@@ -168,16 +168,13 @@ class ListingDisplaySearcher implements Searcher {
iterators.add(listing.getCommentAddressIterator(searchAddresses, options.isForward())); iterators.add(listing.getCommentAddressIterator(searchAddresses, options.isForward()));
} }
if (options.searchLabels() || all) { if (options.searchLabels() || all) {
SymbolIterator labels = program.getSymbolTable().getPrimarySymbolIterator( SymbolIterator labels = program.getSymbolTable()
searchAddresses, options.isForward()); .getPrimarySymbolIterator(searchAddresses, options.isForward());
iterators.add(new LabelSearchAddressIterator(labels)); iterators.add(new LabelSearchAddressIterator(labels));
} }
return iterators.toArray(new AddressIterator[iterators.size()]); return iterators.toArray(new AddressIterator[iterators.size()]);
} }
/**
* Get the next location.
*/
ProgramLocation next() { ProgramLocation next() {
if (locationList.size() == 0) { if (locationList.size() == 0) {
findNext(); findNext();
@@ -318,8 +315,8 @@ class ListingDisplaySearcher implements Searcher {
} }
private void searchForward() { private void searchForward() {
for (int i = for (int i = currentFieldIndex; i < currentLayout
currentFieldIndex; i < currentLayout.getNumFields(); i++, currentFieldIndex++) { .getNumFields(); i++, currentFieldIndex++) {
int matchingFieldCount = findLocations(i); int matchingFieldCount = findLocations(i);
if (matchingFieldCount != 0) { if (matchingFieldCount != 0) {
currentFieldIndex += matchingFieldCount; currentFieldIndex += matchingFieldCount;
@@ -422,13 +419,6 @@ class ListingDisplaySearcher implements Searcher {
isInitialized = true; isInitialized = true;
} }
/**
* Sets the currentFieldIndex of the field that corresponds to the
* startLoc program location
* @param field
* @param fieldIndex
* @return true if this field corresponds to the startLoc program location
*/
private boolean getFieldForLocation(ListingField field, int fieldIndex) { private boolean getFieldForLocation(ListingField field, int fieldIndex) {
FieldFactory ff = field.getFieldFactory(); FieldFactory ff = field.getFieldFactory();
FieldLocation floc = ff.getFieldLocation(field, BigInteger.ZERO, fieldIndex, startLocation); FieldLocation floc = ff.getFieldLocation(field, BigInteger.ZERO, fieldIndex, startLocation);
@@ -43,7 +43,6 @@ import ghidra.program.util.*;
import ghidra.test.*; import ghidra.test.*;
import ghidra.util.UserSearchUtils; import ghidra.util.UserSearchUtils;
import ghidra.util.task.TaskMonitor; import ghidra.util.task.TaskMonitor;
import junit.framework.TestCase;
public class ProgramDatabaseSearchIteratorTest extends AbstractGhidraHeadedIntegrationTest { public class ProgramDatabaseSearchIteratorTest extends AbstractGhidraHeadedIntegrationTest {
@@ -55,10 +54,6 @@ public class ProgramDatabaseSearchIteratorTest extends AbstractGhidraHeadedInteg
private ToyProgramBuilder builder; private ToyProgramBuilder builder;
private TaskMonitor monitor = TaskMonitor.DUMMY; private TaskMonitor monitor = TaskMonitor.DUMMY;
public ProgramDatabaseSearchIteratorTest() {
super();
}
private void createIMM(long address) throws MemoryAccessException { private void createIMM(long address) throws MemoryAccessException {
builder.addBytesMoveImmediate(address, (short) 5); builder.addBytesMoveImmediate(address, (short) 5);
builder.disassemble(Long.toHexString(address), 2); builder.disassemble(Long.toHexString(address), 2);
@@ -91,7 +86,7 @@ public class ProgramDatabaseSearchIteratorTest extends AbstractGhidraHeadedInteg
createFallThru(0x1005f50); createFallThru(0x1005f50);
createIMM(0x1005f41); createIMM(0x1005f41);
createFallThru(0x1005ff0); createFallThru(0x1005ff0);
// LAB_010018b3
createIMM(0x10018b3); createIMM(0x10018b3);
builder.createMemoryReference("0x1005f41", "0x10018b3", RefType.COMPUTED_JUMP, builder.createMemoryReference("0x1005f41", "0x10018b3", RefType.COMPUTED_JUMP,
SourceType.ANALYSIS); SourceType.ANALYSIS);
@@ -109,9 +104,6 @@ public class ProgramDatabaseSearchIteratorTest extends AbstractGhidraHeadedInteg
env.showTool(); env.showTool();
} }
/**
* @see TestCase#tearDown()
*/
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
env.dispose(); env.dispose();
@@ -167,7 +159,6 @@ public class ProgramDatabaseSearchIteratorTest extends AbstractGhidraHeadedInteg
assertNotNull(loc); assertNotNull(loc);
assertEquals(getAddr(0x100595f), loc.getAddress()); assertEquals(getAddr(0x100595f), loc.getAddress());
loc = getNextMatch(searcher); loc = getNextMatch(searcher);
System.out.println(loc);
assertEquals(getAddr(0x100595f), loc.getAddress()); assertEquals(getAddr(0x100595f), loc.getAddress());
loc = getNextMatch(searcher); loc = getNextMatch(searcher);
assertNotNull(loc); assertNotNull(loc);
@@ -230,9 +221,9 @@ public class ProgramDatabaseSearchIteratorTest extends AbstractGhidraHeadedInteg
Pattern pattern = UserSearchUtils.createSearchPattern("immxx", false); Pattern pattern = UserSearchUtils.createSearchPattern("immxx", false);
ProgramLocation startLocation = new ProgramLocation(program, program.getMinAddress()); ProgramLocation startLocation = new ProgramLocation(program, program.getMinAddress());
CodeUnitFormat format = new CodeUnitFormat(ShowBlockName.NEVER, ShowNamespace.NEVER); CodeUnitFormat format = new CodeUnitFormat(ShowBlockName.NEVER, ShowNamespace.NEVER);
ProgramDatabaseFieldSearcher searcher = ProgramDatabaseFieldSearcher searcher = InstructionMnemonicOperandFieldSearcher
InstructionMnemonicOperandFieldSearcher.createInstructionMnemonicAndOperandFieldSearcher( .createInstructionMnemonicAndOperandFieldSearcher(program, startLocation, null,
program, startLocation, null, true, pattern, format); true, pattern, format);
currentAddress = searcher.getNextSignificantAddress(null); currentAddress = searcher.getNextSignificantAddress(null);
assertNull(getNextMatch(searcher)); assertNull(getNextMatch(searcher));
@@ -244,18 +235,18 @@ public class ProgramDatabaseSearchIteratorTest extends AbstractGhidraHeadedInteg
Pattern pattern = UserSearchUtils.createSearchPattern("imm", true); Pattern pattern = UserSearchUtils.createSearchPattern("imm", true);
ProgramLocation startLocation = new ProgramLocation(program, program.getMinAddress()); ProgramLocation startLocation = new ProgramLocation(program, program.getMinAddress());
ProgramDatabaseFieldSearcher searcher = ProgramDatabaseFieldSearcher searcher = InstructionMnemonicOperandFieldSearcher
InstructionMnemonicOperandFieldSearcher.createInstructionMnemonicAndOperandFieldSearcher( .createInstructionMnemonicAndOperandFieldSearcher(program, startLocation, null,
program, startLocation, null, true, pattern, CodeUnitFormat.DEFAULT); true, pattern, CodeUnitFormat.DEFAULT);
currentAddress = searcher.getNextSignificantAddress(null); currentAddress = searcher.getNextSignificantAddress(null);
ProgramLocation nextMatch = getNextMatch(searcher); ProgramLocation nextMatch = getNextMatch(searcher);
assertNotNull(nextMatch); assertNotNull(nextMatch);
startLocation = new ProgramLocation(program, getAddr(0x1001000)); startLocation = new ProgramLocation(program, getAddr(0x1001000));
searcher = searcher = InstructionMnemonicOperandFieldSearcher
InstructionMnemonicOperandFieldSearcher.createInstructionMnemonicAndOperandFieldSearcher( .createInstructionMnemonicAndOperandFieldSearcher(program, startLocation, null,
program, startLocation, null, true, pattern, CodeUnitFormat.DEFAULT); true, pattern, CodeUnitFormat.DEFAULT);
currentAddress = searcher.getNextSignificantAddress(null); currentAddress = searcher.getNextSignificantAddress(null);
nextMatch = getNextMatch(searcher); nextMatch = getNextMatch(searcher);
@@ -274,9 +265,9 @@ public class ProgramDatabaseSearchIteratorTest extends AbstractGhidraHeadedInteg
pattern = UserSearchUtils.createSearchPattern("imm", false); pattern = UserSearchUtils.createSearchPattern("imm", false);
startLocation = new ProgramLocation(program, getAddr(0x1005f53)); startLocation = new ProgramLocation(program, getAddr(0x1005f53));
searcher = searcher = InstructionMnemonicOperandFieldSearcher
InstructionMnemonicOperandFieldSearcher.createInstructionMnemonicAndOperandFieldSearcher( .createInstructionMnemonicAndOperandFieldSearcher(program, startLocation, null,
program, startLocation, null, false, pattern, CodeUnitFormat.DEFAULT); false, pattern, CodeUnitFormat.DEFAULT);
currentAddress = searcher.getNextSignificantAddress(null); currentAddress = searcher.getNextSignificantAddress(null);
nextMatch = getNextMatch(searcher); nextMatch = getNextMatch(searcher);
@@ -285,9 +276,9 @@ public class ProgramDatabaseSearchIteratorTest extends AbstractGhidraHeadedInteg
startLocation = new MnemonicFieldLocation(program, startLocation = new MnemonicFieldLocation(program,
program.getMinAddress().getNewAddress(0x1005f53), null, null, "imm", 2); program.getMinAddress().getNewAddress(0x1005f53), null, null, "imm", 2);
searcher = searcher = InstructionMnemonicOperandFieldSearcher
InstructionMnemonicOperandFieldSearcher.createInstructionMnemonicAndOperandFieldSearcher( .createInstructionMnemonicAndOperandFieldSearcher(program, startLocation, null,
program, startLocation, null, false, pattern, CodeUnitFormat.DEFAULT); false, pattern, CodeUnitFormat.DEFAULT);
currentAddress = searcher.getNextSignificantAddress(null); currentAddress = searcher.getNextSignificantAddress(null);
nextMatch = getNextMatch(searcher); nextMatch = getNextMatch(searcher);
@@ -539,8 +530,10 @@ public class ProgramDatabaseSearchIteratorTest extends AbstractGhidraHeadedInteg
TaskMonitor taskMonitor) { TaskMonitor taskMonitor) {
int count = 0; int count = 0;
ArrayList<ProgramLocation> list = new ArrayList<>(); ArrayList<ProgramLocation> list = new ArrayList<>();
Searcher ts = new ProgramDatabaseSearcher(pluginTool, searchProgram, startLoc, set, options, Searcher ts = runSwing(() -> {
return new ProgramDatabaseSearcher(pluginTool, searchProgram, startLoc, set, options,
taskMonitor); taskMonitor);
});
ProgramLocation loc = null; ProgramLocation loc = null;
while ((loc = ts.search()) != null) { while ((loc = ts.search()) != null) {
list.add(loc); list.add(loc);