mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 02:39:44 +02:00
Merge remote-tracking branch 'origin/patch'
This commit is contained in:
commit
1281fb979b
3 changed files with 55 additions and 48 deletions
|
@ -588,6 +588,9 @@ public class FunctionEditorModel {
|
||||||
VariableStorage returnStorage = returnInfo.getStorage();
|
VariableStorage returnStorage = returnInfo.getStorage();
|
||||||
if (returnStorage.isForcedIndirect()) {
|
if (returnStorage.isForcedIndirect()) {
|
||||||
DataType returnType = returnInfo.getDataType();
|
DataType returnType = returnInfo.getDataType();
|
||||||
|
if (returnStorage.isVoidStorage()) {
|
||||||
|
returnType = VoidDataType.dataType;
|
||||||
|
}
|
||||||
returnInfo.setFormalDataType(returnType);
|
returnInfo.setFormalDataType(returnType);
|
||||||
returnInfo.setStorage(returnStorage.clone(program));
|
returnInfo.setStorage(returnStorage.clone(program));
|
||||||
signatureTransformed = true;
|
signatureTransformed = true;
|
||||||
|
@ -650,8 +653,8 @@ public class FunctionEditorModel {
|
||||||
try {
|
try {
|
||||||
if (autoParamCount < oldAutoCount) {
|
if (autoParamCount < oldAutoCount) {
|
||||||
if (oldParams.get(autoParamCount)
|
if (oldParams.get(autoParamCount)
|
||||||
.getStorage()
|
.getStorage()
|
||||||
.getAutoParameterType() != storage.getAutoParameterType()) {
|
.getAutoParameterType() != storage.getAutoParameterType()) {
|
||||||
adjustSelectionForRowRemoved(i);
|
adjustSelectionForRowRemoved(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -901,25 +904,18 @@ public class FunctionEditorModel {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean removeExplicitReturnStoragePtrParameter() {
|
private DataType removeExplicitReturnStoragePtrParameter() {
|
||||||
int index = findExplicitReturnStoragePtrParameter();
|
int index = findExplicitReturnStoragePtrParameter();
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
parameters.remove(index); // remove explicit '__return_storage_ptr__' parameter
|
// remove explicit '__return_storage_ptr__' parameter - should always be a pointer
|
||||||
|
ParamInfo returnStoragePtrParameter = parameters.remove(index);
|
||||||
|
DataType dt = returnStoragePtrParameter.getDataType();
|
||||||
adjustSelectionForRowRemoved(index);
|
adjustSelectionForRowRemoved(index);
|
||||||
return true;
|
if (dt instanceof Pointer ptr) {
|
||||||
}
|
return ptr.getDataType();
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void revertIndirectParameter(ParamInfo param) {
|
|
||||||
if (allowCustomStorage) {
|
|
||||||
throw new AssertException(); // auto-storage mode only
|
|
||||||
}
|
|
||||||
DataType dt = param.getDataType();
|
|
||||||
if (dt instanceof Pointer) {
|
|
||||||
param.setFormalDataType(((Pointer) dt).getDataType());
|
|
||||||
param.setStorage(VariableStorage.UNASSIGNED_STORAGE);
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -933,8 +929,10 @@ public class FunctionEditorModel {
|
||||||
allowCustomStorage = b;
|
allowCustomStorage = b;
|
||||||
if (!allowCustomStorage) {
|
if (!allowCustomStorage) {
|
||||||
removeExplicitThisParameter();
|
removeExplicitThisParameter();
|
||||||
if (removeExplicitReturnStoragePtrParameter()) {
|
DataType returnDt = removeExplicitReturnStoragePtrParameter();
|
||||||
revertIndirectParameter(returnInfo);
|
if (returnDt != null) {
|
||||||
|
returnInfo.setFormalDataType(returnDt);
|
||||||
|
returnInfo.setStorage(VariableStorage.UNASSIGNED_STORAGE);
|
||||||
}
|
}
|
||||||
updateParameterAndReturnStorage();
|
updateParameterAndReturnStorage();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1364,8 +1364,9 @@ public class FunctionDB extends DatabaseObject implements Function {
|
||||||
newParams = new ArrayList<Variable>(newParams); // copy for edit
|
newParams = new ArrayList<Variable>(newParams); // copy for edit
|
||||||
boolean thisParamRemoved =
|
boolean thisParamRemoved =
|
||||||
removeExplicitThisParameter(newParams, callingConvention);
|
removeExplicitThisParameter(newParams, callingConvention);
|
||||||
if (removeExplicitReturnStorageParameter(newParams)) {
|
DataType dt = removeExplicitReturnStoragePtrParameter(newParams);
|
||||||
returnVar = revertIndirectParameter(returnVar, true);
|
if (dt != null) {
|
||||||
|
returnVar = revertIndirectParameter(returnVar, dt, true);
|
||||||
}
|
}
|
||||||
if (returnVar instanceof Parameter) {
|
if (returnVar instanceof Parameter) {
|
||||||
returnType = ((Parameter) returnVar).getFormalDataType();
|
returnType = ((Parameter) returnVar).getFormalDataType();
|
||||||
|
@ -2255,7 +2256,7 @@ public class FunctionDB extends DatabaseObject implements Function {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int findExplicitReturnStorageParameter(List<? extends Variable> params) {
|
private static int findExplicitReturnStoragePtrParameter(List<? extends Variable> params) {
|
||||||
for (int i = 0; i < params.size(); i++) {
|
for (int i = 0; i < params.size(); i++) {
|
||||||
Variable p = params.get(i);
|
Variable p = params.get(i);
|
||||||
if (RETURN_PTR_PARAM_NAME.equals(p.getName()) && (p.getDataType() instanceof Pointer)) {
|
if (RETURN_PTR_PARAM_NAME.equals(p.getName()) && (p.getDataType() instanceof Pointer)) {
|
||||||
|
@ -2265,50 +2266,54 @@ public class FunctionDB extends DatabaseObject implements Function {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean removeExplicitReturnStorageParameter(List<? extends Variable> params) {
|
private static DataType removeExplicitReturnStoragePtrParameter(
|
||||||
int paramIndex = findExplicitReturnStorageParameter(params);
|
List<? extends Variable> params) {
|
||||||
|
int paramIndex = findExplicitReturnStoragePtrParameter(params);
|
||||||
if (paramIndex >= 0) {
|
if (paramIndex >= 0) {
|
||||||
params.remove(paramIndex); // remove return storage parameter
|
Variable returnStoragePtrParameter = params.remove(paramIndex); // remove return storage parameter
|
||||||
return true;
|
DataType dt = returnStoragePtrParameter.getDataType();
|
||||||
|
if (dt instanceof Pointer ptr) {
|
||||||
|
return ptr.getDataType();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean removeExplicitReturnStorageParameter() {
|
private DataType removeExplicitReturnStoragePtrParameter() {
|
||||||
int paramIndex = findExplicitReturnStorageParameter(params);
|
int paramIndex = findExplicitReturnStoragePtrParameter(params);
|
||||||
if (paramIndex >= 0) {
|
if (paramIndex >= 0) {
|
||||||
|
ParameterDB returnStoragePtrParameter = params.get(paramIndex);
|
||||||
|
DataType dt = returnStoragePtrParameter.getDataType();
|
||||||
removeParameter(paramIndex); // remove return storage parameter
|
removeParameter(paramIndex); // remove return storage parameter
|
||||||
return true;
|
if (dt instanceof Pointer ptr) {
|
||||||
|
return ptr.getDataType();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Strip indirect pointer data type from a parameter.
|
* Strip indirect pointer data type from a parameter.
|
||||||
* @param param parameter to be examined and optionally modified
|
* @param param parameter to be examined and optionally modified
|
||||||
|
* @param dt return datatype to be applied
|
||||||
* @param create if true the specified param will not be affected and a new parameter
|
* @param create if true the specified param will not be affected and a new parameter
|
||||||
* instance will be returned if strip performed, otherwise orginal param will be changed
|
* instance will be returned if strip performed, otherwise orginal param will be changed
|
||||||
* if possible and returned.
|
* if possible and returned.
|
||||||
* @return parameter with pointer stripped or original param if pointer not used.
|
* @return parameter with pointer stripped or original param if pointer not used.
|
||||||
* Returned parameter will have unassigned storage if affected.
|
* Returned parameter will have unassigned storage if affected.
|
||||||
*/
|
*/
|
||||||
private static Variable revertIndirectParameter(Variable param, boolean create) {
|
private static Variable revertIndirectParameter(Variable param, DataType dt, boolean create) {
|
||||||
DataType dt = param.getDataType();
|
try {
|
||||||
if (dt instanceof Pointer) {
|
if (create) {
|
||||||
try {
|
param = new ParameterImpl(param.getName(), dt, param.getProgram());
|
||||||
dt = ((Pointer) dt).getDataType();
|
|
||||||
if (create) {
|
|
||||||
param = new ParameterImpl(param.getName(), dt, param.getProgram());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
param.setDataType(dt, VariableStorage.UNASSIGNED_STORAGE, false,
|
|
||||||
param.getSource());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (InvalidInputException e) {
|
else {
|
||||||
throw new AssertException(e); // unexpected
|
param.setDataType(dt, VariableStorage.UNASSIGNED_STORAGE, false, param.getSource());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (InvalidInputException e) {
|
||||||
|
throw new AssertException(e); // unexpected
|
||||||
|
}
|
||||||
return param;
|
return param;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2330,8 +2335,9 @@ public class FunctionDB extends DatabaseObject implements Function {
|
||||||
if (!hasCustomVariableStorage) {
|
if (!hasCustomVariableStorage) {
|
||||||
// remove explicit 'this' param and return storage use if switching to dynamic storage
|
// remove explicit 'this' param and return storage use if switching to dynamic storage
|
||||||
removeExplicitThisParameter();
|
removeExplicitThisParameter();
|
||||||
if (removeExplicitReturnStorageParameter()) {
|
DataType returnDt = removeExplicitReturnStoragePtrParameter();
|
||||||
revertIndirectParameter(returnParam, false);
|
if (returnDt != null) {
|
||||||
|
revertIndirectParameter(returnParam, returnDt, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -270,6 +270,9 @@ public class VariableStorage implements Comparable<VariableStorage> {
|
||||||
if (getClass().equals(VariableStorage.class)) {
|
if (getClass().equals(VariableStorage.class)) {
|
||||||
return this; // only reuse if simple VariableStorage instance
|
return this; // only reuse if simple VariableStorage instance
|
||||||
}
|
}
|
||||||
|
if (isVoidStorage()) {
|
||||||
|
return VOID_STORAGE;
|
||||||
|
}
|
||||||
if (isUnassignedStorage()) {
|
if (isUnassignedStorage()) {
|
||||||
return UNASSIGNED_STORAGE;
|
return UNASSIGNED_STORAGE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue