mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 10:49:34 +02:00
Merge remote-tracking branch 'origin/GP-119_FillOutStructureRedux'
This commit is contained in:
commit
17d5a14d42
3 changed files with 85 additions and 1 deletions
|
@ -75,6 +75,9 @@ public class FillOutStructureCmd extends BackgroundCommand {
|
|||
private TaskMonitor monitor;
|
||||
private PluginTool tool;
|
||||
|
||||
private List<PcodeOp> storePcodeOps = new ArrayList<PcodeOp>();
|
||||
private List<PcodeOp> loadPcodeOps = new ArrayList<PcodeOp>();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
|
@ -168,6 +171,59 @@ public class FillOutStructureCmd extends BackgroundCommand {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create a structure data type for a variable in the given function.
|
||||
* @param var a parameter, local variable, or global variable used in the given function
|
||||
* @param function the function to process
|
||||
* @return a filled-in structure or null if one could not be created
|
||||
*/
|
||||
public Structure processStructure(HighVariable var, Function function) {
|
||||
|
||||
if (var == null || var.getSymbol() == null || var.getOffset() >= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Structure structDT;
|
||||
|
||||
try {
|
||||
fillOutStructureDef(var);
|
||||
structDT = createStructure(null, var, function, false);
|
||||
populateStructure(structDT);
|
||||
pushIntoCalls(structDT);
|
||||
}
|
||||
catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return structDT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the component map that was generated when structure was created using decomiler info
|
||||
* @return componentMap
|
||||
*/
|
||||
public NoisyStructureBuilder getComponentMap() {
|
||||
return componentMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the pcodeOps that are used to store data into the variable
|
||||
* the FillInStructureCmd was trying to create a structure on.
|
||||
* @return the pcodeOps doing the storing to the associated variable
|
||||
*/
|
||||
public List<PcodeOp> getStorePcodeOps() {
|
||||
return storePcodeOps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the pcodeOps that are used to load data from the variable
|
||||
* the FillInStructureCmd was trying to create a structure on.
|
||||
* @return the pcodeOps doing the loading from the associated variable
|
||||
*/
|
||||
public List<PcodeOp> getLoadPcodeOps() {
|
||||
return loadPcodeOps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the (likely) storage address for a function parameter given its index
|
||||
* @param function is the function
|
||||
|
@ -633,6 +689,11 @@ public class FillOutStructureCmd extends BackgroundCommand {
|
|||
case PcodeOp.LOAD:
|
||||
outDt = getDataTypeTraceForward(output);
|
||||
componentMap.addDataType(currentRef.offset, outDt);
|
||||
|
||||
if (outDt != null && !loadPcodeOps.contains(pcodeOp)) {
|
||||
loadPcodeOps.add(pcodeOp);
|
||||
}
|
||||
|
||||
break;
|
||||
case PcodeOp.STORE:
|
||||
// create a location in the struct
|
||||
|
@ -642,6 +703,11 @@ public class FillOutStructureCmd extends BackgroundCommand {
|
|||
}
|
||||
outDt = getDataTypeTraceBackward(inputs[2]);
|
||||
componentMap.addDataType(currentRef.offset, outDt);
|
||||
|
||||
if (outDt != null && !storePcodeOps.contains(pcodeOp)) {
|
||||
storePcodeOps.add(pcodeOp);
|
||||
}
|
||||
|
||||
break;
|
||||
case PcodeOp.CAST:
|
||||
putOnList(output, currentRef.offset, todoList, doneList);
|
||||
|
|
|
@ -91,10 +91,22 @@ public enum MetaDataType {
|
|||
return aCopy;
|
||||
}
|
||||
if (aMeta == MetaDataType.PTR) {
|
||||
if (a instanceof TypeDef) {
|
||||
a = ((TypeDef) a).getBaseDataType();
|
||||
}
|
||||
if (b instanceof TypeDef) {
|
||||
b = ((TypeDef) b).getBaseDataType();
|
||||
}
|
||||
a = ((Pointer) a).getDataType();
|
||||
b = ((Pointer) b).getDataType();
|
||||
}
|
||||
else if (aMeta == MetaDataType.ARRAY) {
|
||||
if (a instanceof TypeDef) {
|
||||
a = ((TypeDef) a).getBaseDataType();
|
||||
}
|
||||
if (b instanceof TypeDef) {
|
||||
b = ((TypeDef) b).getBaseDataType();
|
||||
}
|
||||
if (!(a instanceof Array) || !(b instanceof Array)) {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -79,10 +79,16 @@ public class NoisyStructureBuilder {
|
|||
* @param dt is the data-type of field if known (null otherwise)
|
||||
*/
|
||||
public void addDataType(long offset, DataType dt) {
|
||||
if (dt == null) {
|
||||
if (dt == null || dt instanceof VoidDataType) {
|
||||
computeMax(offset, 1);
|
||||
return;
|
||||
}
|
||||
if (dt instanceof Pointer && ((Pointer) dt).getDataType().equals(structDT)) {
|
||||
// Be careful of taking a pointer to the structure when the structure
|
||||
// is not fully defined
|
||||
DataTypeManager manager = dt.getDataTypeManager();
|
||||
dt = manager.getPointer(DataType.DEFAULT, dt.getLength());
|
||||
}
|
||||
computeMax(offset, dt.getLength());
|
||||
Entry<Long, DataType> firstEntry = checkForOverlap(offset, dt.getLength());
|
||||
if (firstEntry != null) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue