Skip to content

Commit

Permalink
Build for Ghidra 11.2
Browse files Browse the repository at this point in the history
Temporarily reverts the breaking changes in commit 917953a
that were introduced for Ghidra 11.3+ but fail to
build on 11.2.

Please tag this commit '1.2.5' once the PR is merged, if that was not done automatically.
  • Loading branch information
DimitriPilot3 committed Nov 23, 2024
1 parent 0e6714b commit 1ebbcce
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=1.1.5
version=1.2.5
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
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 {
Expand All @@ -21,7 +20,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);
Expand All @@ -33,9 +32,9 @@ public boolean canAnalyze(Program program) {
}

@Override
protected DemangledObject doDemangle(MangledContext context, MessageLog log)
protected DemangledObject doDemangle(String mangled, DemanglerOptions options, MessageLog log)
throws DemangledException {
DemangledObject demangled = demangler.demangle(context);
DemangledObject demangled = demangler.demangle(mangled, options);
return demangled;
}

Expand Down
45 changes: 23 additions & 22 deletions src/main/java/gamecubeloader/common/CodeWarriorDemangler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -74,7 +74,7 @@ private void demangleTemplates(DemangledDataType o) {
break;
}
}

o.setTemplate(template);
}

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -165,10 +165,10 @@ else if (functionName.equals("__dt"))
classNamespace.setNamespace(namespace);
member.setNamespace(classNamespace);
}

return member;
}

return null;
}

Expand Down Expand Up @@ -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))
Expand All @@ -252,7 +252,7 @@ public DemangledDataType nextType() {
subNamespace.setNamespace(namespaceType);
namespaceType = subNamespace;
}

d.setNamespace(namespaceType);
return d;
} else if (tok == 'F') {
Expand All @@ -264,13 +264,13 @@ public DemangledDataType nextType() {
break;

tok = hd();

if (tok == '_') {
tk();
func.setReturnType(this.nextType());
break;
}

func.addParameter(this.nextType());
}

Expand Down Expand Up @@ -428,7 +428,7 @@ private static String demangleSpecialOperator(String symbolName) {
return "operator ->*";
}
}

return null;
}

Expand All @@ -446,12 +446,13 @@ public boolean canDemangle(Program program) {
}

@Override
public DemangledObject demangle(MangledContext mangledContext) throws DemangledException {
return CodeWarriorDemangler.demangleSymbol(mangledContext.getMangled());
@SuppressWarnings("removal")
public DemangledObject demangle(String mangled, boolean demangleOnlyKnownPatterns) throws DemangledException {
return CodeWarriorDemangler.demangleSymbol(mangled);
}

@Override
public DemangledObject demangle(String mangled) throws DemangledException {
public DemangledObject demangle(String mangled, DemanglerOptions options) throws DemangledException {
return CodeWarriorDemangler.demangleSymbol(mangled);
}
}

0 comments on commit 1ebbcce

Please sign in to comment.