mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 18:29:37 +02:00
renaming less datatype sensitive
This commit is contained in:
parent
b2a422329c
commit
1257f06c17
3 changed files with 56 additions and 49 deletions
|
@ -33,7 +33,8 @@ public class RenameVariableTask extends RenameTask {
|
|||
private Program program;
|
||||
private Function function;
|
||||
private boolean commitRequired; // Set to true if all parameters are committed before renaming
|
||||
private SourceType srctype;
|
||||
private SourceType srctype; // Desired source type for the variable being renamed
|
||||
private SourceType signatureSrcType; // Signature source type of the function (which will be preserved)
|
||||
|
||||
public RenameVariableTask(PluginTool tool, String old, HighFunction hfunc, HighVariable v,
|
||||
Varnode ex, SourceType st) {
|
||||
|
@ -44,13 +45,16 @@ public class RenameVariableTask extends RenameTask {
|
|||
function = hfunc.getFunction();
|
||||
program = function.getProgram();
|
||||
srctype = st;
|
||||
signatureSrcType = function.getSignatureSource();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void commit() throws DuplicateNameException, InvalidInputException {
|
||||
if (commitRequired) {
|
||||
HighFunctionDBUtil.commitParamsToDatabase(hfunction, true, srctype);
|
||||
HighFunctionDBUtil.commitReturnToDatabase(hfunction, srctype);
|
||||
HighFunctionDBUtil.commitParamsToDatabase(hfunction, false, signatureSrcType);
|
||||
if (signatureSrcType != SourceType.DEFAULT) {
|
||||
HighFunctionDBUtil.commitReturnToDatabase(hfunction, signatureSrcType);
|
||||
}
|
||||
}
|
||||
HighFunctionDBUtil.updateDBVariable(var, newName, null, srctype);
|
||||
}
|
||||
|
|
|
@ -290,10 +290,6 @@ public class RetypeVariableAction extends AbstractDecompilerAction {
|
|||
return true;
|
||||
}
|
||||
|
||||
int skipslot = -1;
|
||||
if (var != null) {
|
||||
skipslot = ((HighParam) var).getSlot();
|
||||
}
|
||||
for (int i = 0; i < numParams; i++) {
|
||||
HighParam param = localSymbolMap.getParam(i);
|
||||
if (param.getSlot() != i) {
|
||||
|
@ -303,21 +299,6 @@ public class RetypeVariableAction extends AbstractDecompilerAction {
|
|||
if (!storage.equals(parameters[i].getVariableStorage())) {
|
||||
return true;
|
||||
}
|
||||
if (skipslot != i) { // Compare datatypes unless it is the specific -var- we are skipping
|
||||
if (!param.getDataType().isEquivalent(parameters[i].getDataType())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (var != null) { // A null var indicates we are changing the return type anyway, so we don't need to check it
|
||||
DataType funcReturnType = function.getReturnType();
|
||||
if (funcReturnType != DataType.DEFAULT) {
|
||||
DataType hfuncReturnType = hfunction.getFunctionPrototype().getReturnType();
|
||||
if (!funcReturnType.equals(hfuncReturnType)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -72,37 +72,43 @@ public class HighFunctionDBUtil {
|
|||
|
||||
/**
|
||||
* Commit all parameters associated with HighFunction to the underlying database.
|
||||
* @param highFunction
|
||||
* @param renameConflicts if true any name conflicts will be resolved
|
||||
* by renaming the conflicting local variable/label
|
||||
* @param source source type
|
||||
* @param highFunction is the associated HighFunction
|
||||
* @param useDataTypes is true if the HighFunction's parameter data-types should be committed
|
||||
* @param source is the signature source type to set
|
||||
* @throws DuplicateNameException if commit of parameters caused conflict with other
|
||||
* local variable/label. Should not occur if renameConflicts is true.
|
||||
* @throws InvalidInputException
|
||||
* local variable/label.
|
||||
* @throws InvalidInputException if specified storage is invalid
|
||||
*/
|
||||
public static void commitParamsToDatabase(HighFunction highFunction, boolean renameConflicts,
|
||||
public static void commitParamsToDatabase(HighFunction highFunction, boolean useDataTypes,
|
||||
SourceType source) throws DuplicateNameException, InvalidInputException {
|
||||
Function function = highFunction.getFunction();
|
||||
|
||||
List<Parameter> params = getParameters(highFunction);
|
||||
List<Parameter> params = getParameters(highFunction, useDataTypes);
|
||||
|
||||
commitParamsToDatabase(function, highFunction.getFunctionPrototype(), params,
|
||||
highFunction.getFunctionPrototype().isVarArg(), renameConflicts, source);
|
||||
highFunction.getFunctionPrototype().isVarArg(), true, source);
|
||||
}
|
||||
|
||||
private static List<Parameter> getParameters(HighFunction highFunction)
|
||||
private static List<Parameter> getParameters(HighFunction highFunction, boolean useDataTypes)
|
||||
throws InvalidInputException {
|
||||
Function function = highFunction.getFunction();
|
||||
Program program = function.getProgram();
|
||||
DataTypeManager dtm = program.getDataTypeManager();
|
||||
LocalSymbolMap symbolMap = highFunction.getLocalSymbolMap();
|
||||
List<Parameter> params = new ArrayList<Parameter>();
|
||||
int paramCnt = symbolMap.getNumParams();
|
||||
for (int i = 0; i < paramCnt; ++i) {
|
||||
HighParam param = symbolMap.getParam(i);
|
||||
String name = param.getName();
|
||||
boolean nameLocked = param.getSymbol().isNameLocked();
|
||||
name = (nameLocked ? name : null);
|
||||
params.add(new ParameterImpl(name, param.getDataType(), param.getStorage(), program));
|
||||
DataType dataType;
|
||||
if (useDataTypes) {
|
||||
dataType = param.getDataType();
|
||||
}
|
||||
else {
|
||||
dataType = Undefined.getUndefinedDataType(param.getSize());
|
||||
dataType = dataType.clone(dtm);
|
||||
}
|
||||
params.add(new ParameterImpl(name, dataType, param.getStorage(), program));
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
@ -407,28 +413,33 @@ public class HighFunctionDBUtil {
|
|||
HighFunction highFunction = variable.getHighFunction();
|
||||
Function function = highFunction.getFunction();
|
||||
Program program = function.getProgram();
|
||||
DataTypeManager dtm = program.getDataTypeManager();
|
||||
|
||||
dataType = dataType != null ? dataType.clone(dtm) : variable.getDataType();
|
||||
if (dataType.getLength() <= 0) {
|
||||
throw new InvalidInputException("Data type is not fixed-length: " + dataType.getName());
|
||||
boolean resized = false;
|
||||
if (dataType != null) {
|
||||
dataType = dataType.clone(program.getDataTypeManager());
|
||||
if (dataType.getLength() <= 0) {
|
||||
throw new InvalidInputException(
|
||||
"Data type is not fixed-length: " + dataType.getName());
|
||||
}
|
||||
|
||||
resized = (dataType.getLength() != variable.getSize());
|
||||
}
|
||||
|
||||
boolean resized = (dataType.getLength() != variable.getSize());
|
||||
|
||||
boolean isRename = name != null;
|
||||
|
||||
if (variable instanceof HighParam) {
|
||||
HighParam param = (HighParam) variable;
|
||||
Parameter dbParam = getDatabaseParameter(param);
|
||||
VariableStorage storage = param.getStorage();
|
||||
if (resized && function.hasCustomVariableStorage()) {
|
||||
VariableStorage newStorage =
|
||||
VariableUtilities.resizeStorage(storage, dataType, true, function);
|
||||
dbParam.setDataType(dataType, newStorage, false, source);
|
||||
}
|
||||
else {
|
||||
dbParam.setDataType(dataType, source);
|
||||
if (dataType != null) {
|
||||
if (resized && function.hasCustomVariableStorage()) {
|
||||
VariableStorage newStorage =
|
||||
VariableUtilities.resizeStorage(storage, dataType, true, function);
|
||||
dbParam.setDataType(dataType, newStorage, false, source);
|
||||
}
|
||||
else {
|
||||
dbParam.setDataType(dataType, source);
|
||||
}
|
||||
}
|
||||
if (name != null && !name.equals(dbParam.getName())) {
|
||||
dbParam.setName(name, source);
|
||||
|
@ -440,6 +451,15 @@ public class HighFunctionDBUtil {
|
|||
boolean usesHashStorage = storage.isHashStorage();
|
||||
|
||||
Variable var = clearConflictingLocalVariables(local);
|
||||
if (dataType == null) {
|
||||
if (var != null) {
|
||||
dataType = var.getDataType(); // Use preexisting datatype
|
||||
}
|
||||
else {
|
||||
dataType = Undefined.getUndefinedDataType(variable.getSize());
|
||||
dataType = dataType.clone(program.getDataTypeManager());
|
||||
}
|
||||
}
|
||||
if (resized) {
|
||||
if (usesHashStorage) {
|
||||
throw new InvalidInputException(
|
||||
|
@ -495,7 +515,9 @@ public class HighFunctionDBUtil {
|
|||
}
|
||||
}
|
||||
|
||||
setGlobalDataType(global, dataType);
|
||||
if (dataType != null) {
|
||||
setGlobalDataType(global, dataType);
|
||||
}
|
||||
|
||||
if (name != null) {
|
||||
try {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue