mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-03 17:59:46 +02:00
Merge remote-tracking branch
'origin/GP-3608_ryanmkurtz_pointer-to-array' (Closes #5248)
This commit is contained in:
commit
180b09041c
2 changed files with 35 additions and 0 deletions
|
@ -531,6 +531,12 @@ public class DataTypeWriter {
|
||||||
name += getArrayDimensions(array);
|
name += getArrayDimensions(array);
|
||||||
dataType = getArrayBaseType(array);
|
dataType = getArrayBaseType(array);
|
||||||
}
|
}
|
||||||
|
else if (dataType instanceof Pointer ptr &&
|
||||||
|
getPointerBaseDataType(ptr) instanceof Array array) {
|
||||||
|
name = "(%s%s)%s".formatted("*".repeat(getPointerDepth(ptr)), name,
|
||||||
|
getArrayDimensions(array));
|
||||||
|
dataType = getArrayBaseType(array);
|
||||||
|
}
|
||||||
|
|
||||||
DataType baseDataType = getBaseDataType(dataType);
|
DataType baseDataType = getBaseDataType(dataType);
|
||||||
if (baseDataType instanceof FunctionDefinition) {
|
if (baseDataType instanceof FunctionDefinition) {
|
||||||
|
|
|
@ -577,4 +577,33 @@ public class DataTypeWriterTest extends AbstractGTest {
|
||||||
assertEquals(expected, actual);
|
assertEquals(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testArrayPointerInStructure() throws IOException, CancelledException {
|
||||||
|
DataType dt = new IntegerDataType();
|
||||||
|
Array array = new ArrayDataType(dt, 300, dt.getLength());
|
||||||
|
Pointer ptr1 = PointerDataType.getPointer(array, null);
|
||||||
|
Pointer ptr2 = PointerDataType.getPointer(ptr1, null);
|
||||||
|
|
||||||
|
Structure struct = new StructureDataType("MyStruct", 0);
|
||||||
|
struct.setDescription("this is my structure");
|
||||||
|
struct.add(ptr1, "myPtr1", "this is my array pointer");
|
||||||
|
struct.add(ptr2, "myPtr2", "this is my array pointer pointer");
|
||||||
|
|
||||||
|
dtWriter.write(struct, TaskMonitor.DUMMY);
|
||||||
|
|
||||||
|
String actual = writer.getBuffer().toString();
|
||||||
|
|
||||||
|
String expected = """
|
||||||
|
typedef struct MyStruct MyStruct, *PMyStruct;
|
||||||
|
|
||||||
|
struct MyStruct { /* this is my structure */
|
||||||
|
int (*myPtr1)[300]; /* this is my array pointer */
|
||||||
|
int (**myPtr2)[300]; /* this is my array pointer pointer */
|
||||||
|
};
|
||||||
|
|
||||||
|
""";
|
||||||
|
|
||||||
|
assertEquals(expected, actual);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue