GP-0 Revert GP-4886 change pending further review and rework

This commit is contained in:
ghidra1 2024-11-18 11:29:53 -05:00
parent 81432f75c7
commit 058ecb5eef
6 changed files with 28 additions and 82 deletions

View File

@ -95,8 +95,8 @@ public class DemangledDataType extends DemangledType {
private static final String UNSIGNED_LONG = "unsigned long"; private static final String UNSIGNED_LONG = "unsigned long";
public final static String[] PRIMITIVES = public final static String[] PRIMITIVES =
{ VOID, BOOL, CHAR, WCHAR_T, WCHAR16, WCHAR32, CHAR8_T, SHORT, INT, INT0_T, LONG, LONG_LONG, { VOID, BOOL, CHAR, WCHAR_T, WCHAR16, WCHAR32, CHAR8_T, SHORT, INT, INT0_T, LONG,
FLOAT, FLOAT2, DOUBLE, INT128, FLOAT128, LONG_DOUBLE, }; LONG_LONG, FLOAT, FLOAT2, DOUBLE, INT128, FLOAT128, LONG_DOUBLE, };
private int arrayDimensions = 0; private int arrayDimensions = 0;
private boolean isClass; private boolean isClass;
@ -200,10 +200,10 @@ public class DemangledDataType extends DemangledType {
else if (dt == null) { else if (dt == null) {
// I don't know what this is // I don't know what this is
// If it isn't pointed to, or isn't a referent, then assume undefined typedef. // If it isn't pointed to, or isn't a referent, then assume typedef.
if (!(isReference() || isPointer())) { // Unknown type if (!(isReference() || isPointer())) { // Unknown type
dt = new TypedefDataType(getDemanglerCategoryPath(getNamespace()), name, dt = new TypedefDataType(getDemanglerCategoryPath(getNamespace()), name,
DataType.DEFAULT); new DWordDataType());
} }
else { else {
// try creating empty structures for unknown types instead. // try creating empty structures for unknown types instead.

View File

@ -26,7 +26,6 @@ import generic.test.AbstractGenericTest;
import ghidra.app.util.demangler.*; import ghidra.app.util.demangler.*;
import ghidra.program.database.ProgramDB; import ghidra.program.database.ProgramDB;
import ghidra.program.model.address.Address; import ghidra.program.model.address.Address;
import ghidra.program.model.data.DataType;
import ghidra.program.model.data.TerminatedStringDataType; import ghidra.program.model.data.TerminatedStringDataType;
import ghidra.program.model.listing.CodeUnit; import ghidra.program.model.listing.CodeUnit;
import ghidra.program.model.listing.Data; import ghidra.program.model.listing.Data;
@ -129,60 +128,6 @@ public class GnuDemanglerTest extends AbstractGenericTest {
fullSignature); fullSignature);
} }
@Test
public void testUseStandardReplacements2() throws Exception {
//
// Mangled: _ZN7Greeter5greetENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
//
// Demangled: undefined Greeter::greet(std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>)
//
// Replaced: undefined Greeter::greet(std::string)
//
String mangled = "_ZN7Greeter5greetENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE";
GnuDemangler demangler = new GnuDemangler();
demangler.canDemangle(program);// this perform initialization
GnuDemanglerOptions options = new GnuDemanglerOptions();
options.setUseStandardReplacements(true);
DemangledFunction dobj = (DemangledFunction) demangler.demangle(mangled, options);
assertNotNull(dobj);
String signature = dobj.getSignature();
assertEquals("undefined Greeter::greet(std::string)", signature);
DemangledParameter demangledParameter = dobj.getParameters().get(0);
DemangledDataType type = demangledParameter.getType();
DataType dt = type.getDataType(program.getDataTypeManager());
assertTrue(dt.isNotYetDefined());
//@formatter:off
assertEquals("/Demangler/std/string\n" +
"pack(disabled)\n" +
"Structure string {\n" +
"}\n" +
"Length: 0 Alignment: 1\n", dt.toString());
//@formatter:on
//
// Now disable demangled string replacement
//
options.setUseStandardReplacements(false);
dobj = (DemangledFunction) demangler.demangle(mangled, options);
assertNotNull(dobj);
String fullSignature = dobj.getSignature();
assertEquals(
"undefined Greeter::greet(std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>)",
fullSignature);
demangledParameter = dobj.getParameters().get(0);
type = demangledParameter.getType();
dt = type.getDataType(program.getDataTypeManager());
assertEquals("typedef basic_string undefined", dt.toString());
}
@Test @Test
public void testDemangleOnlyKnownPatterns_True() throws Exception { public void testDemangleOnlyKnownPatterns_True() throws Exception {

View File

@ -2470,6 +2470,16 @@ public class FunctionDB extends DatabaseObject implements Function {
return thunkedFunction.getSignatureSource(); 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(); return getStoredSignatureSource();
} }
finally { finally {

View File

@ -23,7 +23,8 @@ import java.util.ArrayList;
import ghidra.program.model.address.Address; import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressSpace; import ghidra.program.model.address.AddressSpace;
import ghidra.program.model.data.*; import ghidra.program.model.data.DataType;
import ghidra.program.model.data.DataTypeManager;
import ghidra.program.model.lang.protorules.*; import ghidra.program.model.lang.protorules.*;
import ghidra.program.model.listing.Program; import ghidra.program.model.listing.Program;
import ghidra.program.model.listing.VariableStorage; import ghidra.program.model.listing.VariableStorage;
@ -132,12 +133,6 @@ public class ParamListStandard implements ParamList {
if (dt.isZeroLength()) { if (dt.isZeroLength()) {
return AssignAction.NO_ASSIGNMENT; 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) { for (ModelRule modelRule : modelRules) {
int responseCode = modelRule.assignAddress(dt, proto, pos, dtManager, status, res); int responseCode = modelRule.assignAddress(dt, proto, pos, dtManager, status, res);
if (responseCode != AssignAction.FAIL) { if (responseCode != AssignAction.FAIL) {

View File

@ -210,12 +210,11 @@ public class LocalSymbolMap {
pcaddr = pcaddr.subtractWrap(1); pcaddr = pcaddr.subtractWrap(1);
List<HighSymbol> paramList = new ArrayList<>(); List<HighSymbol> paramList = new ArrayList<>();
boolean internalInvalid = false;
for (int i = 0; i < p.length; ++i) { for (int i = 0; i < p.length; ++i) {
Parameter var = p[i]; Parameter var = p[i];
if (!var.isValid()) { if (!var.isValid()) {
internalInvalid = true; // TODO: exclude parameters which don't have valid storage ??
break; continue;
} }
DataType dt = var.getDataType(); DataType dt = var.getDataType();
String name = var.getName(); String name = var.getName();
@ -244,12 +243,6 @@ public class LocalSymbolMap {
paramSymbol.setNameLock(namelock); paramSymbol.setNameLock(namelock);
paramSymbol.setTypeLock(lock); 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()]; paramSymbols = new HighSymbol[paramList.size()];
paramList.toArray(paramSymbols); paramList.toArray(paramSymbols);

View File

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