From 4901fa5674bf5e406313d8ee92fee4f76b94d6f7 Mon Sep 17 00:00:00 2001 From: "Dimitri A." Date: Sat, 23 Nov 2024 16:05:10 +0100 Subject: [PATCH] Revert "Build for Ghidra 11.2" This brings back the Ghidra 11.3+ changes that were reverted in the previous commit. --- .../CodeWarriorDemanglerAnalyzer.java | 9 ++-- .../common/CodeWarriorDemangler.java | 45 +++++++++---------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/main/java/gamecubeloader/analyzer/CodeWarriorDemanglerAnalyzer.java b/src/main/java/gamecubeloader/analyzer/CodeWarriorDemanglerAnalyzer.java index ca069ee..2087406 100644 --- a/src/main/java/gamecubeloader/analyzer/CodeWarriorDemanglerAnalyzer.java +++ b/src/main/java/gamecubeloader/analyzer/CodeWarriorDemanglerAnalyzer.java @@ -5,11 +5,12 @@ import ghidra.app.util.demangler.DemangledException; import ghidra.app.util.demangler.DemangledObject; import ghidra.app.util.demangler.DemanglerOptions; +import ghidra.app.util.demangler.MangledContext; import ghidra.app.util.importer.MessageLog; import ghidra.program.model.listing.Program; /*** - * + * * Demangler analyzer for CodeWarrior symbols. */ public class CodeWarriorDemanglerAnalyzer extends AbstractDemanglerAnalyzer { @@ -20,7 +21,7 @@ public class CodeWarriorDemanglerAnalyzer extends AbstractDemanglerAnalyzer { "the name and apply datatypes to parameters."; private CodeWarriorDemangler demangler = new CodeWarriorDemangler(); - + public CodeWarriorDemanglerAnalyzer() { super(NAME, DESCRIPTION); setDefaultEnablement(true); @@ -32,9 +33,9 @@ public boolean canAnalyze(Program program) { } @Override - protected DemangledObject doDemangle(String mangled, DemanglerOptions options, MessageLog log) + protected DemangledObject doDemangle(MangledContext context, MessageLog log) throws DemangledException { - DemangledObject demangled = demangler.demangle(mangled, options); + DemangledObject demangled = demangler.demangle(context); return demangled; } diff --git a/src/main/java/gamecubeloader/common/CodeWarriorDemangler.java b/src/main/java/gamecubeloader/common/CodeWarriorDemangler.java index a0d0b4f..a1d78cf 100644 --- a/src/main/java/gamecubeloader/common/CodeWarriorDemangler.java +++ b/src/main/java/gamecubeloader/common/CodeWarriorDemangler.java @@ -9,12 +9,12 @@ public final class CodeWarriorDemangler implements Demangler { public final String CODEWARRIOR_DEMANGLE_PROP = "DemangleCW"; /* When defined, forces CodeWarrior demangling on all symbols. */ public final String CODEWARRIOR_NO_DEMANGLE_PROP = "NoDemangleCW"; /* When defined, prevents CodeWarrior demangling on all symbols. */ - + public String str; public boolean containsInvalidSpecifier; public CodeWarriorDemangler() { } /* Empty constructor for DemanglerCmd::applyTo */ - + public CodeWarriorDemangler(String g) { this.str = g; } @@ -74,7 +74,7 @@ private void demangleTemplates(DemangledDataType o) { break; } } - + o.setTemplate(template); } @@ -106,12 +106,12 @@ public static DemangledObject demangleSymbol(String symbolName) { // If the symbol starts with __, exit. if (firstDunder < 0) return null; - + // Ensure that any trailing underscores in the function name are accounted for while (symbolName.charAt(firstDunder + 2) == '_') { firstDunder++; } - + String parameters = symbolName.substring(firstDunder + 2); // After the dunder comes the class, if it exists, followed by 'F', followed by parameters. var demangler = new CodeWarriorDemangler(parameters); @@ -129,7 +129,7 @@ public static DemangledObject demangleSymbol(String symbolName) { String functionName = symbolName.substring(0, firstDunder); String operatorName = demangleSpecialOperator(functionName); - + if (operatorName != null) { d.setOverloadedOperator(true); d.setName(operatorName); @@ -138,23 +138,23 @@ public static DemangledObject demangleSymbol(String symbolName) { functionName = parentClass.getName(); else if (functionName.equals("__dt")) functionName = "~" + parentClass.getName(); - + d.setName(functionName); - + CodeWarriorDemangler.demangleTemplates(d); } - + if (demangler.containsInvalidSpecifier) return null; - + return d; } - + // It could be a member or vtable if (demangler.isEmpty()) { var name = symbolName.substring(0, firstDunder); var member = new DemangledVariable(symbolName, name, name); - + if (parentClass != null) { var namespace = parentClass.getNamespace(); var className = parentClass.getDemangledName(); @@ -165,10 +165,10 @@ else if (functionName.equals("__dt")) classNamespace.setNamespace(namespace); member.setNamespace(classNamespace); } - + return member; } - + return null; } @@ -243,7 +243,7 @@ public DemangledDataType nextType() { var val = names.get(compCount - 1); var d = new DemangledDataType(null, val, val); demangleTemplates(d); - + // Create namespaces DemangledType namespaceType = new DemangledType(null, names.get(0), names.get(0)); // Top level for (String ns : names.subList(1, names.size() - 1)) @@ -252,7 +252,7 @@ public DemangledDataType nextType() { subNamespace.setNamespace(namespaceType); namespaceType = subNamespace; } - + d.setNamespace(namespaceType); return d; } else if (tok == 'F') { @@ -264,13 +264,13 @@ public DemangledDataType nextType() { break; tok = hd(); - + if (tok == '_') { tk(); func.setReturnType(this.nextType()); break; } - + func.addParameter(this.nextType()); } @@ -428,7 +428,7 @@ private static String demangleSpecialOperator(String symbolName) { return "operator ->*"; } } - + return null; } @@ -446,13 +446,12 @@ public boolean canDemangle(Program program) { } @Override - @SuppressWarnings("removal") - public DemangledObject demangle(String mangled, boolean demangleOnlyKnownPatterns) throws DemangledException { - return CodeWarriorDemangler.demangleSymbol(mangled); + public DemangledObject demangle(MangledContext mangledContext) throws DemangledException { + return CodeWarriorDemangler.demangleSymbol(mangledContext.getMangled()); } @Override - public DemangledObject demangle(String mangled, DemanglerOptions options) throws DemangledException { + public DemangledObject demangle(String mangled) throws DemangledException { return CodeWarriorDemangler.demangleSymbol(mangled); } }