Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-3020 - Updated the Fill in Structure action to take into account the structure size

dragonmacherfc6fb6e4ae0b
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/FillOutStructureCmd.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/FillOutStructureCmd.java
index f696c755d7..63a724ffee 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/FillOutStructureCmd.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/FillOutStructureCmd.java
@@ -559,12 +559,16 @@ public class FillOutStructureCmd extends BackgroundCommand {
return currentProgram.getDataTypeManager().getUniqueName(new CategoryPath(category), base);
}
- private boolean sanityCheck(long offset) {
+ private boolean sanityCheck(long offset, long existingSize) {
+
if (offset < 0) {
return false; // offsets shouldn't be negative
}
+ if (offset < existingSize) {
+ return true; // we have room in the structure
+ }
if (offset > 0x1000) {
- return false; // Arbitrary size cut-off to prevent creating huge structures
+ return false; // bigger than existing size; arbitrary cut-off to prevent huge structures
}
return true;
}
@@ -648,7 +652,7 @@ public class FillOutStructureCmd extends BackgroundCommand {
long value = getSigned(inputs[1]);
newOff = currentRef.offset +
((pcodeOp.getOpcode() == PcodeOp.INT_ADD) ? value : (-value));
- if (sanityCheck(newOff)) { // should this offset create a location in the structure?
+ if (sanityCheck(newOff, componentMap.getSize())) { // should this offset create a location in the structure?
putOnList(output, newOff, todoList, doneList);
// Don't do componentMap.addDataType() as data-type info here is likely uninformed
componentMap.setMinimumSize(newOff);
@@ -659,7 +663,7 @@ public class FillOutStructureCmd extends BackgroundCommand {
break;
}
newOff = currentRef.offset + getSigned(inputs[1]) * inputs[2].getOffset();
- if (sanityCheck(newOff)) { // should this offset create a location in the structure?
+ if (sanityCheck(newOff, componentMap.getSize())) { // should this offset create a location in the structure?
putOnList(output, newOff, todoList, doneList);
// Don't do componentMap.addReference() as data-type info here is likely uninformed
componentMap.setMinimumSize(newOff);
@@ -670,7 +674,7 @@ public class FillOutStructureCmd extends BackgroundCommand {
break;
}
long subOff = currentRef.offset + getSigned(inputs[1]);
- if (sanityCheck(subOff)) { // should this offset create a location in the structure?
+ if (sanityCheck(subOff, componentMap.getSize())) { // should this offset create a location in the structure?
putOnList(output, subOff, todoList, doneList);
// Don't do componentMap.addReference() as data-type info here is likely uninformed
componentMap.setMinimumSize(subOff);