renaming less datatype sensitive

This commit is contained in:
caheckman 2019-09-17 11:30:48 -04:00
parent b2a422329c
commit 1257f06c17
3 changed files with 56 additions and 49 deletions

View file

@ -33,7 +33,8 @@ public class RenameVariableTask extends RenameTask {
private Program program; private Program program;
private Function function; private Function function;
private boolean commitRequired; // Set to true if all parameters are committed before renaming 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, public RenameVariableTask(PluginTool tool, String old, HighFunction hfunc, HighVariable v,
Varnode ex, SourceType st) { Varnode ex, SourceType st) {
@ -44,13 +45,16 @@ public class RenameVariableTask extends RenameTask {
function = hfunc.getFunction(); function = hfunc.getFunction();
program = function.getProgram(); program = function.getProgram();
srctype = st; srctype = st;
signatureSrcType = function.getSignatureSource();
} }
@Override @Override
public void commit() throws DuplicateNameException, InvalidInputException { public void commit() throws DuplicateNameException, InvalidInputException {
if (commitRequired) { if (commitRequired) {
HighFunctionDBUtil.commitParamsToDatabase(hfunction, true, srctype); HighFunctionDBUtil.commitParamsToDatabase(hfunction, false, signatureSrcType);
HighFunctionDBUtil.commitReturnToDatabase(hfunction, srctype); if (signatureSrcType != SourceType.DEFAULT) {
HighFunctionDBUtil.commitReturnToDatabase(hfunction, signatureSrcType);
}
} }
HighFunctionDBUtil.updateDBVariable(var, newName, null, srctype); HighFunctionDBUtil.updateDBVariable(var, newName, null, srctype);
} }

View file

@ -290,10 +290,6 @@ public class RetypeVariableAction extends AbstractDecompilerAction {
return true; return true;
} }
int skipslot = -1;
if (var != null) {
skipslot = ((HighParam) var).getSlot();
}
for (int i = 0; i < numParams; i++) { for (int i = 0; i < numParams; i++) {
HighParam param = localSymbolMap.getParam(i); HighParam param = localSymbolMap.getParam(i);
if (param.getSlot() != i) { if (param.getSlot() != i) {
@ -303,21 +299,6 @@ public class RetypeVariableAction extends AbstractDecompilerAction {
if (!storage.equals(parameters[i].getVariableStorage())) { if (!storage.equals(parameters[i].getVariableStorage())) {
return true; 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; return false;

View file

@ -72,37 +72,43 @@ public class HighFunctionDBUtil {
/** /**
* Commit all parameters associated with HighFunction to the underlying database. * Commit all parameters associated with HighFunction to the underlying database.
* @param highFunction * @param highFunction is the associated HighFunction
* @param renameConflicts if true any name conflicts will be resolved * @param useDataTypes is true if the HighFunction's parameter data-types should be committed
* by renaming the conflicting local variable/label * @param source is the signature source type to set
* @param source source type
* @throws DuplicateNameException if commit of parameters caused conflict with other * @throws DuplicateNameException if commit of parameters caused conflict with other
* local variable/label. Should not occur if renameConflicts is true. * local variable/label.
* @throws InvalidInputException * @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 { SourceType source) throws DuplicateNameException, InvalidInputException {
Function function = highFunction.getFunction(); Function function = highFunction.getFunction();
List<Parameter> params = getParameters(highFunction); List<Parameter> params = getParameters(highFunction, useDataTypes);
commitParamsToDatabase(function, highFunction.getFunctionPrototype(), params, 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 { throws InvalidInputException {
Function function = highFunction.getFunction(); Function function = highFunction.getFunction();
Program program = function.getProgram(); Program program = function.getProgram();
DataTypeManager dtm = program.getDataTypeManager();
LocalSymbolMap symbolMap = highFunction.getLocalSymbolMap(); LocalSymbolMap symbolMap = highFunction.getLocalSymbolMap();
List<Parameter> params = new ArrayList<Parameter>(); List<Parameter> params = new ArrayList<Parameter>();
int paramCnt = symbolMap.getNumParams(); int paramCnt = symbolMap.getNumParams();
for (int i = 0; i < paramCnt; ++i) { for (int i = 0; i < paramCnt; ++i) {
HighParam param = symbolMap.getParam(i); HighParam param = symbolMap.getParam(i);
String name = param.getName(); String name = param.getName();
boolean nameLocked = param.getSymbol().isNameLocked(); DataType dataType;
name = (nameLocked ? name : null); if (useDataTypes) {
params.add(new ParameterImpl(name, param.getDataType(), param.getStorage(), program)); dataType = param.getDataType();
}
else {
dataType = Undefined.getUndefinedDataType(param.getSize());
dataType = dataType.clone(dtm);
}
params.add(new ParameterImpl(name, dataType, param.getStorage(), program));
} }
return params; return params;
} }
@ -407,28 +413,33 @@ public class HighFunctionDBUtil {
HighFunction highFunction = variable.getHighFunction(); HighFunction highFunction = variable.getHighFunction();
Function function = highFunction.getFunction(); Function function = highFunction.getFunction();
Program program = function.getProgram(); Program program = function.getProgram();
DataTypeManager dtm = program.getDataTypeManager();
dataType = dataType != null ? dataType.clone(dtm) : variable.getDataType(); boolean resized = false;
if (dataType.getLength() <= 0) { if (dataType != null) {
throw new InvalidInputException("Data type is not fixed-length: " + dataType.getName()); 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; boolean isRename = name != null;
if (variable instanceof HighParam) { if (variable instanceof HighParam) {
HighParam param = (HighParam) variable; HighParam param = (HighParam) variable;
Parameter dbParam = getDatabaseParameter(param); Parameter dbParam = getDatabaseParameter(param);
VariableStorage storage = param.getStorage(); VariableStorage storage = param.getStorage();
if (resized && function.hasCustomVariableStorage()) { if (dataType != null) {
VariableStorage newStorage = if (resized && function.hasCustomVariableStorage()) {
VariableUtilities.resizeStorage(storage, dataType, true, function); VariableStorage newStorage =
dbParam.setDataType(dataType, newStorage, false, source); VariableUtilities.resizeStorage(storage, dataType, true, function);
} dbParam.setDataType(dataType, newStorage, false, source);
else { }
dbParam.setDataType(dataType, source); else {
dbParam.setDataType(dataType, source);
}
} }
if (name != null && !name.equals(dbParam.getName())) { if (name != null && !name.equals(dbParam.getName())) {
dbParam.setName(name, source); dbParam.setName(name, source);
@ -440,6 +451,15 @@ public class HighFunctionDBUtil {
boolean usesHashStorage = storage.isHashStorage(); boolean usesHashStorage = storage.isHashStorage();
Variable var = clearConflictingLocalVariables(local); 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 (resized) {
if (usesHashStorage) { if (usesHashStorage) {
throw new InvalidInputException( throw new InvalidInputException(
@ -495,7 +515,9 @@ public class HighFunctionDBUtil {
} }
} }
setGlobalDataType(global, dataType); if (dataType != null) {
setGlobalDataType(global, dataType);
}
if (name != null) { if (name != null) {
try { try {