mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-03 17:59:46 +02:00
Merge remote-tracking branch 'origin/GP-0_dev747368_fix_definedstringsiterator_foundstringsiterator_missing_first_struct_field' into Ghidra_11.4
This commit is contained in:
commit
e2332dec70
2 changed files with 20 additions and 3 deletions
|
@ -44,6 +44,7 @@ public class DefinedStringIteratorTest extends AbstractGhidraHeadlessIntegration
|
||||||
private int s1f3Offset = 50;
|
private int s1f3Offset = 50;
|
||||||
private ArrayDataType structArray;
|
private ArrayDataType structArray;
|
||||||
private StructureDataType struct2DT;
|
private StructureDataType struct2DT;
|
||||||
|
private StructureDataType struct3DT;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
@ -68,6 +69,9 @@ public class DefinedStringIteratorTest extends AbstractGhidraHeadlessIntegration
|
||||||
struct2DT.replaceAtOffset(0, intDT, -1, "f1", null);
|
struct2DT.replaceAtOffset(0, intDT, -1, "f1", null);
|
||||||
struct2DT.replaceAtOffset(10, struct1DT, -1, "f2", null);
|
struct2DT.replaceAtOffset(10, struct1DT, -1, "f2", null);
|
||||||
|
|
||||||
|
struct3DT = new StructureDataType("struct3", 200);
|
||||||
|
struct3DT.replaceAtOffset(0, charArray, -1, "f1", null);
|
||||||
|
|
||||||
builder.createMemory("test", "0x0", 0x20000);
|
builder.createMemory("test", "0x0", 0x20000);
|
||||||
program = builder.getProgram();
|
program = builder.getProgram();
|
||||||
}
|
}
|
||||||
|
@ -144,6 +148,19 @@ public class DefinedStringIteratorTest extends AbstractGhidraHeadlessIntegration
|
||||||
assertEquals(s1ArrayElemIndex + 2, list.size());
|
assertEquals(s1ArrayElemIndex + 2, list.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_StructFirstField() throws Exception {
|
||||||
|
// ensure we get the first field of a struct
|
||||||
|
|
||||||
|
int structAddr = 0x100;
|
||||||
|
|
||||||
|
builder.applyFixedLengthDataType(addrStr(structAddr), struct3DT, -1);
|
||||||
|
|
||||||
|
DefinedStringIterator it = DefinedStringIterator.forProgram(program);
|
||||||
|
List<Data> list = IteratorUtils.toList(it);
|
||||||
|
assertEquals(1, list.size());
|
||||||
|
}
|
||||||
|
|
||||||
private long arrayElementAddr(long arrayAddr, int elemSize, int elemIndex) {
|
private long arrayElementAddr(long arrayAddr, int elemSize, int elemIndex) {
|
||||||
return arrayAddr + (elemSize * elemIndex);
|
return arrayAddr + (elemSize * elemIndex);
|
||||||
}
|
}
|
||||||
|
@ -155,7 +172,7 @@ public class DefinedStringIteratorTest extends AbstractGhidraHeadlessIntegration
|
||||||
|
|
||||||
builder.applyFixedLengthDataType("0x0", intDT, -1); // +1 candidate count
|
builder.applyFixedLengthDataType("0x0", intDT, -1); // +1 candidate count
|
||||||
builder.createString(addrStr(str1Addr), "test1", StandardCharsets.UTF_8, true, stringDT); // +1
|
builder.createString(addrStr(str1Addr), "test1", StandardCharsets.UTF_8, true, stringDT); // +1
|
||||||
builder.applyFixedLengthDataType(addrStr(s1ArrayAddr), structArray, -1); // +(1 + 10*3)
|
builder.applyFixedLengthDataType(addrStr(s1ArrayAddr), structArray, -1); // +(1 + 10 + 10*3)
|
||||||
|
|
||||||
DataType byteArray = new ArrayDataType(ByteDataType.dataType, 2000, -1);
|
DataType byteArray = new ArrayDataType(ByteDataType.dataType, 2000, -1);
|
||||||
builder.applyFixedLengthDataType("0x1000", byteArray, -1); // +1
|
builder.applyFixedLengthDataType("0x1000", byteArray, -1); // +1
|
||||||
|
@ -163,7 +180,7 @@ public class DefinedStringIteratorTest extends AbstractGhidraHeadlessIntegration
|
||||||
DefinedStringIterator it = DefinedStringIterator.forProgram(program);
|
DefinedStringIterator it = DefinedStringIterator.forProgram(program);
|
||||||
List<Data> list = IteratorUtils.toList(it);
|
List<Data> list = IteratorUtils.toList(it);
|
||||||
|
|
||||||
assertEquals(34, it.getDataCandidateCount()); // 1 + 1 + 1 + 10*3
|
assertEquals(44, it.getDataCandidateCount()); // 1 + 1 + 1 + 10 + 10*3
|
||||||
assertEquals(21, list.size()); // 1 ds@0x10 + 2 per structArray element
|
assertEquals(21, list.size()); // 1 ds@0x10 + 2 per structArray element
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,7 +177,7 @@ public class DefinedStringIterator implements DataIterator {
|
||||||
|
|
||||||
private static class StructDtcIterator implements DataIterator {
|
private static class StructDtcIterator implements DataIterator {
|
||||||
private Data data;
|
private Data data;
|
||||||
private int currentIndex;
|
private int currentIndex = -1;
|
||||||
private DataTypeComponent[] dtcs;
|
private DataTypeComponent[] dtcs;
|
||||||
|
|
||||||
public StructDtcIterator(Data data, Composite compDT) {
|
public StructDtcIterator(Data data, Composite compDT) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue