mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 18:29:37 +02:00
GP-3608: Handling more complex cases of pointer/array combinations
(#5248)
This commit is contained in:
parent
b25dc180ef
commit
dbbfb13a82
2 changed files with 43 additions and 25 deletions
|
@ -520,22 +520,31 @@ public class DataTypeWriter {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (componentString == null) {
|
if (componentString == null) {
|
||||||
|
|
||||||
if (dataType instanceof BitFieldDataType) {
|
if (dataType instanceof BitFieldDataType) {
|
||||||
BitFieldDataType bfDt = (BitFieldDataType) dataType;
|
BitFieldDataType bfDt = (BitFieldDataType) dataType;
|
||||||
name += ":" + bfDt.getDeclaredBitSize();
|
name += ":" + bfDt.getDeclaredBitSize();
|
||||||
dataType = bfDt.getBaseDataType();
|
dataType = bfDt.getBaseDataType();
|
||||||
}
|
}
|
||||||
else if (dataType instanceof Array) {
|
|
||||||
Array array = (Array) dataType;
|
while (true) {
|
||||||
name += getArrayDimensions(array);
|
if (dataType instanceof Array array) {
|
||||||
dataType = getArrayBaseType(array);
|
name += "[" + array.getNumElements() + "]";
|
||||||
|
dataType = array.getDataType();
|
||||||
|
}
|
||||||
|
else if (dataType instanceof Pointer pointer) {
|
||||||
|
DataType elem = pointer.getDataType();
|
||||||
|
if (elem == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
name = "*" + name;
|
||||||
|
dataType = elem;
|
||||||
|
if (dataType instanceof Array) {
|
||||||
|
name = "(" + name + ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
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);
|
||||||
|
|
|
@ -580,14 +580,23 @@ public class DataTypeWriterTest extends AbstractGTest {
|
||||||
@Test
|
@Test
|
||||||
public void testArrayPointerInStructure() throws IOException, CancelledException {
|
public void testArrayPointerInStructure() throws IOException, CancelledException {
|
||||||
DataType dt = new IntegerDataType();
|
DataType dt = new IntegerDataType();
|
||||||
Array array = new ArrayDataType(dt, 300, dt.getLength());
|
Array array300 = new ArrayDataType(dt, 300, dt.getLength());
|
||||||
Pointer ptr1 = PointerDataType.getPointer(array, null);
|
Pointer ptrArray300 = PointerDataType.getPointer(array300, null);
|
||||||
|
|
||||||
|
Array array3 = new ArrayDataType(dt, 3, dt.getLength());
|
||||||
|
Array array2 = new ArrayDataType(array3, 2, array3.getLength());
|
||||||
|
Pointer ptr0 = PointerDataType.getPointer(array2, null);
|
||||||
|
Array array12 = new ArrayDataType(ptr0, 12, dt.getLength());
|
||||||
|
Pointer ptr1 = PointerDataType.getPointer(array12, null);
|
||||||
Pointer ptr2 = PointerDataType.getPointer(ptr1, null);
|
Pointer ptr2 = PointerDataType.getPointer(ptr1, null);
|
||||||
|
Pointer ptr3 = PointerDataType.getPointer(ptr2, null);
|
||||||
|
Pointer ptr4 = PointerDataType.getPointer(ptr3, null);
|
||||||
|
Pointer ptr5 = PointerDataType.getPointer(ptr4, null);
|
||||||
|
|
||||||
Structure struct = new StructureDataType("MyStruct", 0);
|
Structure struct = new StructureDataType("MyStruct", 0);
|
||||||
struct.setDescription("this is my structure");
|
struct.setDescription("this is my structure");
|
||||||
struct.add(ptr1, "myPtr1", "this is my array pointer");
|
struct.add(ptrArray300, "something", "this is my array pointer");
|
||||||
struct.add(ptr2, "myPtr2", "this is my array pointer pointer");
|
struct.add(ptr5, "something", "this is my complex one");
|
||||||
|
|
||||||
dtWriter.write(struct, TaskMonitor.DUMMY);
|
dtWriter.write(struct, TaskMonitor.DUMMY);
|
||||||
|
|
||||||
|
@ -597,8 +606,8 @@ public class DataTypeWriterTest extends AbstractGTest {
|
||||||
typedef struct MyStruct MyStruct, *PMyStruct;
|
typedef struct MyStruct MyStruct, *PMyStruct;
|
||||||
|
|
||||||
struct MyStruct { /* this is my structure */
|
struct MyStruct { /* this is my structure */
|
||||||
int (*myPtr1)[300]; /* this is my array pointer */
|
int (*something)[300]; /* this is my array pointer */
|
||||||
int (**myPtr2)[300]; /* this is my array pointer pointer */
|
int (*(*****something)[12])[2][3]; /* this is my complex one */
|
||||||
};
|
};
|
||||||
|
|
||||||
""";
|
""";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue