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