Merge remote-tracking branch 'origin/GP-4886_ghidra1_UnassignedStorageForDefaultDatatype'

This commit is contained in:
Ryan Kurtz 2024-12-06 07:45:28 -05:00
commit 4f79536a50
20 changed files with 454 additions and 358 deletions

View file

@ -2470,16 +2470,6 @@ public class FunctionDB extends DatabaseObject implements Function {
return thunkedFunction.getSignatureSource();
}
// Force DEFAULT source if any param has unassigned storage
if (!getReturn().isValid()) {
return SourceType.DEFAULT;
}
for (Parameter param : getParameters()) {
if (!param.isValid()) {
return SourceType.DEFAULT;
}
}
return getStoredSignatureSource();
}
finally {

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -23,8 +23,7 @@ import java.util.ArrayList;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressSpace;
import ghidra.program.model.data.DataType;
import ghidra.program.model.data.DataTypeManager;
import ghidra.program.model.data.*;
import ghidra.program.model.lang.protorules.*;
import ghidra.program.model.listing.Program;
import ghidra.program.model.listing.VariableStorage;
@ -85,6 +84,7 @@ public class ParamListStandard implements ParamList {
*/
public int assignAddressFallback(StorageClass resource, DataType tp, boolean matchExact,
int[] status, ParameterPieces param) {
for (ParamEntry element : entry) {
int grp = element.getGroup();
if (status[grp] < 0) {
@ -133,6 +133,12 @@ public class ParamListStandard implements ParamList {
if (dt.isZeroLength()) {
return AssignAction.NO_ASSIGNMENT;
}
if (dt == DataType.DEFAULT) {
return AssignAction.NO_ASSIGNMENT;
}
if (dt instanceof TypeDef td && td.getBaseDataType() == DataType.DEFAULT) {
return AssignAction.NO_ASSIGNMENT;
}
for (ModelRule modelRule : modelRules) {
int responseCode = modelRule.assignAddress(dt, proto, pos, dtManager, status, res);
if (responseCode != AssignAction.FAIL) {

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -239,6 +239,10 @@ public class PrototypeModel {
* i.e. {@link AutoParameterType#RETURN_STORAGE_PTR}, this routine will not pass back
* the storage location of the pointer, but will typically pass
* back the location of the normal return register which holds a copy of the pointer.
* <br>
* Note: storage will not be assigned to the {@link DataType#DEFAULT default undefined} datatype
* or zero-length datatype.
*
* @param dataType first parameter dataType or null for an undefined type.
* @param program is the Program
* @return return location or {@link VariableStorage#UNASSIGNED_STORAGE} if
@ -259,10 +263,22 @@ public class PrototypeModel {
* Get the preferred parameter location for a new parameter which will appended
* to the end of an existing set of params. If existing parameters use custom
* storage, this method should not be used.
* <br>
* Note: storage will not be assigned to the {@link DataType#DEFAULT default undefined} datatype,
* zero-length datatype, or any subsequent parameter following such a parameter.
* <br>
* Warning: The use of this method with a null {@code params} argument, or incorrect
* datatypes, is highly discouraged since it will produce inaccurate results.
* It is recommended that a complete function signature be used in
* conjunction with the {@link #getStorageLocations(Program, DataType[], boolean)}
* method. Parameter storage allocation may be affected by the return datatype
* specified (e.g., hidden return storage parameter).
*
* @param params existing set parameters to which the next parameter will
* be appended. (may be null)
* be appended (may be null). Element-0 corresponds to the return datatype.
* @param dataType dataType associated with next parameter location or null
* for a default undefined type.
* for a default undefined type. If null the speculative first parameter storage
* is returned.
* @param program is the Program
* @return next parameter location or {@link VariableStorage#UNASSIGNED_STORAGE} if
* unable to determine suitable location
@ -276,9 +292,24 @@ public class PrototypeModel {
* Get the preferred parameter location for a specified index,
* which will be added/inserted within the set of existing function params.
* If existing parameters use custom storage, this method should not be used.
* @param argIndex is the index
* <br>
* Note: storage will not be assigned to the {@link DataType#DEFAULT default undefined} datatype,
* zero-length datatype, or any subsequent parameter following such a parameter.
* <br>
* Warning: The use of this method with a null {@code params} argument, or incorrect
* datatypes, is highly discouraged since it will produce inaccurate results.
* It is recommended that a complete function signature be used in
* conjunction with the {@link #getStorageLocations(Program, DataType[], boolean)}
* method. Parameter storage allocation may be affected by the return datatype
* specified (e.g., hidden return storage parameter).
*
* @param argIndex is the index (0: return storage, 1..n: parameter storage)
* @param params existing set parameters to which the parameter specified by
* argIndex will be added/inserted be appended (may be null).
* argIndex will be added/inserted be appended. Element-0 corresponds to the return
* datatype. Parameter elements prior to the argIndex are required for an accurate
* storage determination to be made. Any preceeding parameters not specified will be assumed
* as a 1-byte integer type which could cause an erroneous storage result to be returned.
* A null params list will cause all preceeding params to be assumed in a similar fashion.
* @param dataType dataType associated with next parameter location or null
* for a default undefined type.
* @param program is the Program
@ -302,7 +333,7 @@ public class PrototypeModel {
arr[i + 1] = params[i].getDataType(); // Copy in current types if we have them
}
else {
arr[i + 1] = DataType.DEFAULT; // Otherwise assume default (integer) type
arr[i + 1] = Undefined1DataType.dataType; // Otherwise assume 1-byte (integer) type
}
}
arr[argIndex + 1] = dataType;
@ -353,6 +384,10 @@ public class PrototypeModel {
* input parameters, if needed. In this case, the dataTypes array should not include explicit entries for
* these parameters. If addAutoParams is false, the dataTypes array is assumed to already contain explicit
* entries for any of these parameters.
* <br>
* Note: storage will not be assigned to the {@link DataType#DEFAULT default undefined} datatype
* or zero-length datatypes or any subsequent parameter following such a parameter.
*
* @param program is the Program
* @param dataTypes return/parameter datatypes (first element is always the return datatype,
* i.e., minimum array length is 1)

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -210,11 +210,12 @@ public class LocalSymbolMap {
pcaddr = pcaddr.subtractWrap(1);
List<HighSymbol> paramList = new ArrayList<>();
boolean internalInvalid = false;
for (int i = 0; i < p.length; ++i) {
Parameter var = p[i];
if (!var.isValid()) {
// TODO: exclude parameters which don't have valid storage ??
continue;
internalInvalid = true;
break;
}
DataType dt = var.getDataType();
String name = var.getName();
@ -243,6 +244,12 @@ public class LocalSymbolMap {
paramSymbol.setNameLock(namelock);
paramSymbol.setTypeLock(lock);
}
if (internalInvalid) {
// Can only send down a partial prototype. Let decompiler try to recover the whole.
for (HighSymbol paramSymbol : paramList) {
paramSymbol.setTypeLock(false);
}
}
paramSymbols = new HighSymbol[paramList.size()];
paramList.toArray(paramSymbols);

View file

@ -1153,10 +1153,7 @@ public class PcodeDataTypeManager {
private void generateCoreTypes() {
voidDt = new VoidDataType(progDataTypes);
coreBuiltin = new HashMap<Long, TypeMap>();
TypeMap type = new TypeMap(DataType.DEFAULT, "undefined", "unknown", false, false,
DEFAULT_DECOMPILER_ID);
coreBuiltin.put(type.id, type);
type = new TypeMap(displayLanguage, VoidDataType.dataType, "void", false, false,
TypeMap type = new TypeMap(displayLanguage, VoidDataType.dataType, "void", false, false,
builtInDataTypes);
coreBuiltin.put(type.id, type);