GP-3535: Swift fixes/improvements

This commit is contained in:
Ryan Kurtz 2024-02-28 14:43:49 -05:00
parent 21f1a63f51
commit 306fccdae5
57 changed files with 273 additions and 375 deletions

View File

@ -46,7 +46,7 @@ public class DemangledLabel extends DemangledObject {
@Override
public String getSignature(boolean format) {
return originalDemangled;
return getName();
}
}

View File

@ -27,7 +27,7 @@ public class SwiftDemanglerScript extends GhidraScript {
@Override
protected void run() throws Exception {
SwiftDemangler demangler = new SwiftDemangler();
SwiftDemangler demangler = new SwiftDemangler(currentProgram);
SwiftDemanglerOptions options = new SwiftDemanglerOptions();
if (!demangler.canDemangle(currentProgram)) {
println("Not a Swift program");

View File

@ -23,8 +23,11 @@ import ghidra.app.util.demangler.swift.*;
import ghidra.app.util.importer.MessageLog;
import ghidra.framework.options.OptionType;
import ghidra.framework.options.Options;
import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.listing.Program;
import ghidra.util.HelpLocation;
import ghidra.util.exception.CancelledException;
import ghidra.util.task.TaskMonitor;
/**
* An analyzer to demangle Swift mangled symbols
@ -70,14 +73,22 @@ public class SwiftDemanglerAnalyzer extends AbstractDemanglerAnalyzer {
}
@Override
protected DemangledObject doDemangle(String mangled, DemanglerOptions options, MessageLog log)
throws DemangledException {
return demangler.demangle(mangled, options);
public boolean added(Program program, AddressSetView set, TaskMonitor monitor, MessageLog log)
throws CancelledException {
try {
demangler.initialize(program);
}
catch (IOException e) {
log.appendMsg(e.getMessage());
return false;
}
return super.added(program, set, monitor, log);
}
@Override
public void analysisEnded(Program program) {
demangler.clearCache();
protected DemangledObject doDemangle(String mangled, DemanglerOptions options, MessageLog log)
throws DemangledException {
return demangler.demangle(mangled, options);
}
@Override

View File

@ -20,6 +20,7 @@ import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import ghidra.app.util.demangler.DemangledException;
import ghidra.app.util.demangler.swift.SwiftNativeDemangler.SwiftNativeDemangledOutput;
import ghidra.app.util.demangler.swift.nodes.SwiftNode;
import ghidra.app.util.demangler.swift.nodes.SwiftNode.NodeProperties;
@ -78,11 +79,17 @@ public class SwiftDemangledTree {
*
* @param nativeDemangler The Swift native demangler
* @param mangled The mangled string
* @throws IOException If there was an IO-related error
* @throws DemangledException If there was an issue demangling
*/
public SwiftDemangledTree(SwiftNativeDemangler nativeDemangler, String mangled)
throws IOException {
SwiftNativeDemangledOutput demangledOutput = nativeDemangler.demangle(mangled);
throws DemangledException {
SwiftNativeDemangledOutput demangledOutput;
try {
demangledOutput = nativeDemangler.demangle(mangled);
}
catch (IOException e) {
throw new DemangledException(e);
}
demangledString = demangledOutput.demangled();
Stack<SwiftNode> stack = new Stack<>();
for (String line : demangledOutput.tree()) {

View File

@ -33,16 +33,38 @@ import ghidra.util.task.TaskMonitor;
*/
public class SwiftDemangler implements Demangler {
private Program program;
private Map<String, SwiftNode> cache;
private SwiftTypeMetadata typeMetadata;
private SwiftNativeDemangler nativeDemangler;
private SwiftDemanglerOptions options;
private Map<String, SwiftNode> cache;
private DemangledException initException;
/**
* Creates a new {@link SwiftDemangler} that is not associated with any {@link Program}.
* Call {@link #initialize(Program)} to associate it with a program, which will enable access
* to the Swift type metadata.
*/
public SwiftDemangler() {
super();
try {
initialize(null);
}
catch (IOException e) {
// should not happen when initializing with null
}
}
/**
* Creates a new {@link SwiftDemangler} that is associated with the given {@link Program}
*
* @param program The {@link Program} to demangle
* @throws IOException if there was a problem parsing the Swift type metadata
*/
public SwiftDemangler(Program program) throws IOException {
super();
initialize(program);
}
@Override
public boolean canDemangle(Program p) {
this.program = p;
public boolean canDemangle(Program program) {
return SwiftUtils.isSwift(program);
}
@ -57,97 +79,25 @@ public class SwiftDemangler implements Demangler {
return demangle(mangled);
}
/**
* Initializes class variables
*
* @param opt The options
* @throws DemangledException If there was an issue with initialization
*/
private void init(DemanglerOptions opt) throws DemangledException {
if (initException != null) {
throw initException;
}
if (program != null && typeMetadata == null) {
try {
public void initialize(Program program) throws IOException {
cache = new HashMap<>();
nativeDemangler = null;
try {
if (program != null) {
program.setPreferredRootNamespaceCategoryPath(
SwiftDataTypeUtils.SWIFT_CATEGORY.getPath());
typeMetadata = new SwiftTypeMetadata(program, TaskMonitor.DUMMY, new MessageLog());
}
catch (CancelledException e) {
return;
}
catch (IOException e) {
initException = new DemangledException(e);
throw initException;
}
}
if (opt != null) {
options = getSwiftDemanglerOptions(opt);
}
if (nativeDemangler == null) {
try {
nativeDemangler = new SwiftNativeDemangler(options.getSwiftDir());
}
catch (IOException e) {
throw new DemangledException(e);
}
}
if (cache == null) {
cache = new HashMap<>();
}
}
/**
* Demangles the given mangled string
*
* @param mangled The mangled string
* @param originalDemangled The demangled string produced by the native Swift demangler
* @param meta The {@link SwiftTypeMetadata}, or null if unavailable
* @return The {@link Demangled} object, or null if the mangled string is not a supported Swift
* symbol
* @throws DemangledException if a problem occurred
*/
public Demangled demangle(String mangled, String originalDemangled, SwiftTypeMetadata meta)
throws DemangledException {
if (!isSwiftMangledSymbol(mangled)) {
return null;
}
try {
SwiftNode root;
if (cache.containsKey(mangled)) {
root = cache.get(mangled);
}
else {
SwiftDemangledTree tree = new SwiftDemangledTree(nativeDemangler, mangled);
root = tree.getRoot();
}
cache.put(mangled, root);
if (root == null) {
return null;
}
Demangled demangled = root.demangle(this, meta);
if (root.walkAndTest(node -> node.childWasSkipped())) {
demangled.setName(options.getIncompletePrefix() + demangled.getName());
}
return demangled;
}
catch (IOException e) {
throw new DemangledException(e);
catch (CancelledException e) {
return;
}
}
@Override
public DemangledObject demangle(String mangled, DemanglerOptions opt)
throws DemangledException {
init(opt);
Demangled demangled = demangle(mangled, null, typeMetadata);
public DemangledObject demangle(String mangled, DemanglerOptions op) throws DemangledException {
SwiftDemanglerOptions options = getSwiftDemanglerOptions(op);
Demangled demangled = getDemangled(mangled, options);
if (demangled instanceof DemangledFunction func) {
return func;
}
@ -162,12 +112,44 @@ public class SwiftDemangler implements Demangler {
}
/**
* Clears the cache
* Get a new {@link Demangled} by demangling the given mangled string
*
* @param mangled The mangled string
* @param op The options (could be null)
* @return A new {@link Demangled}
* @throws DemangledException if there was an issue demangling
*/
public void clearCache() {
if (cache != null) {
cache.clear();
public Demangled getDemangled(String mangled, SwiftDemanglerOptions op)
throws DemangledException {
if (!isSwiftMangledSymbol(mangled)) {
return null;
}
SwiftDemanglerOptions options = getSwiftDemanglerOptions(op);
setSwiftNativeDemangler(options);
SwiftNode root = cache.containsKey(mangled) ? cache.get(mangled)
: new SwiftDemangledTree(nativeDemangler, mangled).getRoot();
cache.put(mangled, root);
if (root == null) {
return null;
}
Demangled demangled = root.demangle(this);
if (root.walkAndTest(node -> node.childWasSkipped())) {
demangled.setName(options.getIncompletePrefix() + demangled.getName());
}
return demangled;
}
/**
* Gets the {@link SwiftTypeMetadata}
*
* @return The {@link SwiftTypeMetadata}, or null if it is not available
*/
public SwiftTypeMetadata getTypeMetadata() {
return typeMetadata;
}
/**
@ -195,4 +177,21 @@ public class SwiftDemangler implements Demangler {
}
return (SwiftDemanglerOptions) opt;
}
/**
* Ensures that this demangler has access to a {@link SwiftNativeDemangler}
*
* @param options The options
* @throws DemangledException if there was a problem getting the {@link SwiftNativeDemangler}
*/
private void setSwiftNativeDemangler(SwiftDemanglerOptions options) throws DemangledException {
if (nativeDemangler == null) {
try {
nativeDemangler = new SwiftNativeDemangler(options.getSwiftDir());
}
catch (IOException e) {
throw new DemangledException(e);
}
}
}
}

View File

@ -32,7 +32,7 @@ public class SwiftArray extends DemangledDataType {
*/
public SwiftArray(String mangled, String originalDemangled) {
super(mangled, originalDemangled, "Array");
setNamespace(SwiftDataTypeUtils.SWIFT_NAMESPACE);
setNamespace(SwiftDataTypeUtils.getSwiftNamespace());
setBoundType(
new DemangledDataType(mangled, originalDemangled, DemangledDataType.UNDEFINED));
setArray(1);

View File

@ -31,8 +31,9 @@ public class SwiftCharacter extends DemangledStructure {
*/
public SwiftCharacter(String mangled, String originalDemangled) {
super(mangled, originalDemangled, "Character",
SwiftDataTypeUtils.getCategoryPath(SwiftDataTypeUtils.SWIFT_NAMESPACE).getPath(), true);
setNamespace(SwiftDataTypeUtils.SWIFT_NAMESPACE);
SwiftDataTypeUtils.getCategoryPath(SwiftDataTypeUtils.getSwiftNamespace()).getPath(),
true);
setNamespace(SwiftDataTypeUtils.getSwiftNamespace());
DemangledDataType stringDt = new DemangledDataType(mangled, null, DemangledDataType.CHAR);
stringDt.incrementPointerLevels();

View File

@ -30,11 +30,6 @@ public class SwiftDataTypeUtils {
*/
public static final CategoryPath SWIFT_CATEGORY = new CategoryPath("/Demangler");
/**
* A {@link Demangled} to represent the standard Swift namespace
*/
public static final Demangled SWIFT_NAMESPACE = new DemangledUnknown("", null, "Swift");
/**
* Checks to see if the given namespace is the standard Swift namespace
*
@ -42,7 +37,16 @@ public class SwiftDataTypeUtils {
* @return True if the given namespace is the standard Swift namespace; otherwise, false
*/
public static boolean isSwiftNamespace(Demangled namespace) {
return namespace != null && namespace.getName().equals(SWIFT_NAMESPACE.getName());
return namespace != null && namespace.getName().equals("Swift");
}
/**
* Gets a {@link Demangled} to represent the standard Swift namespace
*
* @return A {@link Demangled} to represent the standard Swift namespace
*/
public static Demangled getSwiftNamespace() {
return new DemangledUnknown("", "Swift", "Swift");
}
/**

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.datatypes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.*;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -31,13 +30,11 @@ public class SwiftEnum extends DemangledStructure {
* @param originalDemangled The natively demangled string
* @param name The enum name
* @param namespace The enum namespace (could be null)
* @param typeMetadata The {@link SwiftTypeMetadata}, or null if it is not known
* @param demangler A {@link SwiftDemangler}
* @throws DemangledException if a problem occurred
*/
public SwiftEnum(String mangled, String originalDemangled, String name,
Demangled namespace, SwiftTypeMetadata typeMetadata, SwiftDemangler demangler)
throws DemangledException {
public SwiftEnum(String mangled, String originalDemangled, String name, Demangled namespace,
SwiftDemangler demangler) throws DemangledException {
super(mangled, originalDemangled, name,
SwiftDataTypeUtils.getCategoryPath(namespace).getPath(), true);
setNamespace(namespace);

View File

@ -31,8 +31,9 @@ public class SwiftString extends DemangledStructure {
*/
public SwiftString(String mangled, String originalDemangled) {
super(mangled, originalDemangled, "String",
SwiftDataTypeUtils.getCategoryPath(SwiftDataTypeUtils.SWIFT_NAMESPACE).getPath(), true);
setNamespace(SwiftDataTypeUtils.SWIFT_NAMESPACE);
SwiftDataTypeUtils.getCategoryPath(SwiftDataTypeUtils.getSwiftNamespace()).getPath(),
true);
setNamespace(SwiftDataTypeUtils.getSwiftNamespace());
DemangledDataType stringDt = new DemangledDataType(mangled, null, DemangledDataType.CHAR);
stringDt.incrementPointerLevels();

View File

@ -32,18 +32,17 @@ public class SwiftStructure extends DemangledStructure {
* @param originalDemangled The natively demangled string
* @param name The structure name
* @param namespace The structure namespace (could be null)
* @param typeMetadata The {@link SwiftTypeMetadata}, or null if it is not known
* @param demangler A {@link SwiftDemangler}
* @throws DemangledException if a problem occurred
*/
public SwiftStructure(String mangled, String originalDemangled, String name,
Demangled namespace, SwiftTypeMetadata typeMetadata, SwiftDemangler demangler)
throws DemangledException {
Demangled namespace, SwiftDemangler demangler) throws DemangledException {
super(mangled, originalDemangled, name,
SwiftDataTypeUtils.getCategoryPath(namespace).getPath(), true);
setNamespace(namespace);
// Try to add structure fields from the type metadata
SwiftTypeMetadata typeMetadata = demangler.getTypeMetadata();
if (typeMetadata != null) {
TargetTypeContextDescriptor typeDescriptor =
typeMetadata.getTargetTypeContextDescriptors().get(name);
@ -53,8 +52,7 @@ public class SwiftStructure extends DemangledStructure {
if (fieldDescriptor != null) {
for (FieldRecord fieldRecord : fieldDescriptor.getFieldRecords()) {
String mangledType = "_T" + fieldRecord.getMangledTypeName();
Demangled demangled =
demangler.demangle(mangledType, originalDemangled, typeMetadata);
Demangled demangled = demangler.getDemangled(mangledType, null);
if (demangled instanceof DemangledDataType ddt) {
addField(fieldRecord.getFieldName(), fieldRecord.getDescription(), ddt);
}

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.datatypes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.*;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -30,14 +29,12 @@ public class SwiftTuple extends SwiftStructure {
* @param mangled The mangled string
* @param originalDemangled The natively demangled string
* @param list The elements of the tuple
* @param typeMetadata The {@link SwiftTypeMetadata}, or null if it is not known
* @param demangler A {@link SwiftDemangler}
* @throws DemangledException if a problem occurred
*/
public SwiftTuple(String mangled, String originalDemangled, DemangledList list,
SwiftTypeMetadata typeMetadata, SwiftDemangler demangler) throws DemangledException {
super(mangled, originalDemangled, "tuple%d".formatted(list.size()), null, typeMetadata,
demangler);
SwiftDemangler demangler) throws DemangledException {
super(mangled, originalDemangled, "tuple%d".formatted(list.size()), null, demangler);
int i = 0;
for (Demangled element : list) {

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.Demangled;
import ghidra.app.util.demangler.DemangledException;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
@ -29,8 +28,7 @@ import ghidra.program.model.lang.CompilerSpec;
public class SwiftAllocatorNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
String name = null;
Demangled namespace = null;
Demangled type = null;
@ -39,12 +37,12 @@ public class SwiftAllocatorNode extends SwiftNode {
for (SwiftNode child : getChildren()) {
switch (child.getKind()) {
case Class:
namespace = child.demangle(demangler, typeMetadata);
namespace = child.demangle(demangler);
name = "__allocating_init";
callingConvention = CompilerSpec.CALLING_CONVENTION_thiscall;
break;
case Extension:
namespace = child.demangle(demangler, typeMetadata);
namespace = child.demangle(demangler);
if (child.hasChild(SwiftDemangledNodeKind.Class)) {
name = "__allocating_init";
callingConvention = CompilerSpec.CALLING_CONVENTION_thiscall;
@ -60,14 +58,14 @@ public class SwiftAllocatorNode extends SwiftNode {
case Enum:
case Protocol:
case Structure:
namespace = child.demangle(demangler, typeMetadata);
namespace = child.demangle(demangler);
name = "init";
break;
case Type:
type = child.demangle(demangler, typeMetadata);
type = child.demangle(demangler);
break;
case LabelList:
labelList = child.demangle(demangler, typeMetadata);
labelList = child.demangle(demangler);
break;
default:
skip(child);

View File

@ -17,7 +17,6 @@ package ghidra.app.util.demangler.swift.nodes;
import java.util.stream.Collectors;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.*;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -29,17 +28,16 @@ import ghidra.app.util.demangler.swift.datatypes.SwiftArray;
public class SwiftBoundGenericStructureNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
Demangled type = null;
Demangled typeList = null;
for (SwiftNode child : getChildren()) {
switch (child.getKind()) {
case Type:
type = child.demangle(demangler, typeMetadata);
type = child.demangle(demangler);
break;
case TypeList:
typeList = child.demangle(demangler, typeMetadata);
typeList = child.demangle(demangler);
break;
default:
skip(child);

View File

@ -15,9 +15,7 @@
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.Demangled;
import ghidra.app.util.demangler.DemangledDataType;
import ghidra.app.util.demangler.*;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -27,7 +25,7 @@ import ghidra.app.util.demangler.swift.SwiftDemangler;
public class SwiftBuiltinTypeNameNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata) {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
String orig = getText();
String name = switch (orig) {
case "Builtin.Int1":

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.*;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -26,8 +25,7 @@ import ghidra.app.util.demangler.swift.SwiftDemangler;
public class SwiftClassNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
String name = null;
Demangled namespace = null;
Demangled privateDeclNamespace = null;
@ -37,14 +35,15 @@ public class SwiftClassNode extends SwiftNode {
name = child.getText();
break;
case PrivateDeclName:
Demangled temp = child.demangle(demangler, typeMetadata);
Demangled temp = child.demangle(demangler);
name = temp.getName();
privateDeclNamespace = temp.getNamespace();
break;
case Class:
case Enum:
case Module:
case Structure:
namespace = child.demangle(demangler, typeMetadata);
namespace = child.demangle(demangler);
break;
default:
skip(child);

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.*;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -28,8 +27,7 @@ import ghidra.program.model.lang.CompilerSpec;
public class SwiftConstructorNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
String name = null;
Demangled namespace = null;
Demangled type = null;
@ -37,14 +35,14 @@ public class SwiftConstructorNode extends SwiftNode {
for (SwiftNode child : getChildren()) {
switch (child.getKind()) {
case Class:
namespace = child.demangle(demangler, typeMetadata);
namespace = child.demangle(demangler);
name = "init";
break;
case Type:
type = child.demangle(demangler, typeMetadata);
type = child.demangle(demangler);
break;
case LabelList:
labelList = child.demangle(demangler, typeMetadata);
labelList = child.demangle(demangler);
break;
default:
skip(child);

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.Demangled;
import ghidra.app.util.demangler.DemangledException;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
@ -29,14 +28,13 @@ import ghidra.program.model.lang.CompilerSpec;
public class SwiftDeallocatorNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
String name = null;
Demangled namespace = null;
for (SwiftNode child : getChildren()) {
switch (child.getKind()) {
case Class:
namespace = child.demangle(demangler, typeMetadata);
namespace = child.demangle(demangler);
name = "__deallocating_init";
break;
default:

View File

@ -15,9 +15,7 @@
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.Demangled;
import ghidra.app.util.demangler.DemangledDataType;
import ghidra.app.util.demangler.*;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -27,7 +25,7 @@ import ghidra.app.util.demangler.swift.SwiftDemangler;
public class SwiftDependentGenericParamTypeNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata) {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
// We don't really support this yet
return new DemangledDataType(properties.mangled(), properties.originalDemangled(),
DemangledDataType.UNDEFINED);

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.Demangled;
import ghidra.app.util.demangler.DemangledException;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
@ -27,13 +26,12 @@ import ghidra.app.util.demangler.swift.SwiftDemangler;
public class SwiftDependentGenericTypeNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
Demangled type = null;
for (SwiftNode child : getChildren()) {
switch (child.getKind()) {
case Type:
type = child.demangle(demangler, typeMetadata);
type = child.demangle(demangler);
break;
default:
skip(child);

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.*;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -28,14 +27,13 @@ import ghidra.program.model.lang.CompilerSpec;
public class SwiftDestructorNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
String name = null;
Demangled namespace = null;
for (SwiftNode child : getChildren()) {
switch (child.getKind()) {
case Class:
namespace = child.demangle(demangler, typeMetadata);
namespace = child.demangle(demangler);
name = "deinit";
break;
default:

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.Demangled;
import ghidra.app.util.demangler.DemangledException;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
@ -28,8 +27,7 @@ import ghidra.app.util.demangler.swift.datatypes.SwiftEnum;
public class SwiftEnumNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
String name = null;
Demangled namespace = null;
Demangled privateDeclNamespace = null;
@ -39,15 +37,16 @@ public class SwiftEnumNode extends SwiftNode {
name = child.getText();
break;
case PrivateDeclName:
Demangled temp = child.demangle(demangler, typeMetadata);
Demangled temp = child.demangle(demangler);
name = temp.getName();
privateDeclNamespace = temp.getNamespace();
break;
case Class:
case Enum:
case Extension:
case Module:
case Structure:
namespace = child.demangle(demangler, typeMetadata);
namespace = child.demangle(demangler);
break;
default:
skip(child);
@ -58,6 +57,6 @@ public class SwiftEnumNode extends SwiftNode {
return getUnknown();
}
return new SwiftEnum(properties.mangled(), properties.originalDemangled(), name,
SwiftNode.join(namespace, privateDeclNamespace), typeMetadata, demangler);
SwiftNode.join(namespace, privateDeclNamespace), demangler);
}
}

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.Demangled;
import ghidra.app.util.demangler.DemangledException;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
@ -27,21 +26,20 @@ import ghidra.app.util.demangler.swift.SwiftDemangler;
public class SwiftExtensionNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
Demangled namespace = null;
Demangled type = null;
for (SwiftNode child : getChildren()) {
switch (child.getKind()) {
case Module:
namespace = child.demangle(demangler, typeMetadata);
namespace = child.demangle(demangler);
namespace.setName("(extension_" + namespace.getName() + ")");
break;
case Class:
case Enum:
case Protocol:
case Structure:
type = child.demangle(demangler, typeMetadata);
type = child.demangle(demangler);
break;
default:
skip(child);

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.*;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -28,8 +27,7 @@ import ghidra.program.model.lang.CompilerSpec;
public class SwiftFunctionNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
String name = null;
Demangled namespace = null;
Demangled type = null;
@ -44,7 +42,7 @@ public class SwiftFunctionNode extends SwiftNode {
name = child.getText() + " infix";
break;
case LocalDeclName:
name = child.demangle(demangler, typeMetadata).getName();
name = child.demangle(demangler).getName();
break;
case Class:
callingConvention = CompilerSpec.CALLING_CONVENTION_thiscall;
@ -55,13 +53,13 @@ public class SwiftFunctionNode extends SwiftNode {
case Module:
case Protocol:
case Structure:
namespace = child.demangle(demangler, typeMetadata);
namespace = child.demangle(demangler);
break;
case Type:
type = child.demangle(demangler, typeMetadata);
type = child.demangle(demangler);
break;
case LabelList:
labelList = child.demangle(demangler, typeMetadata);
labelList = child.demangle(demangler);
break;
default:
skip(child);

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.*;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -28,17 +27,16 @@ import ghidra.program.model.lang.CompilerSpec;
public class SwiftFunctionTypeNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
Demangled argumentTuple = null;
Demangled returnType = null;
for (SwiftNode child : getChildren()) {
switch (child.getKind()) {
case ArgumentTuple:
argumentTuple = child.demangle(demangler, typeMetadata);
argumentTuple = child.demangle(demangler);
break;
case ReturnType:
returnType = child.demangle(demangler, typeMetadata);
returnType = child.demangle(demangler);
break;
default:
skip(child);
@ -63,12 +61,12 @@ public class SwiftFunctionTypeNode extends SwiftNode {
SwiftNode struct = functionAncestor.getChild(SwiftDemangledNodeKind.Structure);
SwiftNode enumm = functionAncestor.getChild(SwiftDemangledNodeKind.Enum);
if (struct != null) {
if (struct.demangle(demangler, typeMetadata) instanceof DemangledDataType type) {
if (struct.demangle(demangler) instanceof DemangledDataType type) {
function.addParameter(new DemangledParameter(type));
}
}
else if (enumm != null) {
if (enumm.demangle(demangler, typeMetadata) instanceof DemangledDataType type) {
if (enumm.demangle(demangler) instanceof DemangledDataType type) {
function.addParameter(new DemangledParameter(type));
// Enums are currently represented as single field structures, but in reality,
// there could be more fields. Add a varargs parameter so these other fields
@ -94,7 +92,7 @@ public class SwiftFunctionTypeNode extends SwiftNode {
}
else {
SwiftTuple tuple = new SwiftTuple(properties.mangled(),
properties.originalDemangled(), list, typeMetadata, demangler);
properties.originalDemangled(), list, demangler);
function.setReturnType(tuple);
}
}

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.*;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -29,18 +28,17 @@ import ghidra.program.model.lang.CompilerSpec;
public class SwiftGetterNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
Demangled demangled = null;
String name = "get_";
String callingConvention = CompilerSpec.CALLING_CONVENTION_default;
for (SwiftNode child : getChildren()) {
switch (child.getKind()) {
case Subscript:
demangled = child.demangle(demangler, typeMetadata);
demangled = child.demangle(demangler);
break;
case Variable:
demangled = child.demangle(demangler, typeMetadata);
demangled = child.demangle(demangler);
if (child.hasChild(SwiftDemangledNodeKind.Class)) {
callingConvention = CompilerSpec.CALLING_CONVENTION_thiscall;
}

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.Demangled;
import ghidra.app.util.demangler.DemangledException;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
@ -29,8 +28,7 @@ import ghidra.program.model.data.DataUtilities;
public class SwiftGlobalNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
Demangled demangled = null;
Demangled suffix = null;
for (SwiftNode child : getChildren()) {
@ -40,10 +38,10 @@ public class SwiftGlobalNode extends SwiftNode {
case ObjCAttribute:
continue;
case Suffix:
suffix = child.demangle(demangler, typeMetadata);
suffix = child.demangle(demangler);
break;
default:
demangled = child.demangle(demangler, typeMetadata);
demangled = child.demangle(demangler);
break;
}
}

View File

@ -18,7 +18,6 @@ package ghidra.app.util.demangler.swift.nodes;
import java.util.ArrayList;
import java.util.List;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.*;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -29,13 +28,12 @@ import ghidra.app.util.demangler.swift.SwiftDemangler;
public class SwiftGlobalVariableOnceDeclListNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
List<Demangled> elements = new ArrayList<>();
for (SwiftNode child : getChildren()) {
switch (child.getKind()) {
case Identifier:
elements.add(child.demangle(demangler, typeMetadata));
elements.add(child.demangle(demangler));
break;
default:
skip(child);

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.*;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -28,20 +27,19 @@ import ghidra.program.model.lang.CompilerSpec;
public class SwiftGlobalVariableOnceFunctionNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
Demangled namespace = null;
DemangledList names = null;
for (SwiftNode child : getChildren()) {
switch (child.getKind()) {
case GlobalVariableOnceDeclList:
Demangled demangled = child.demangle(demangler, typeMetadata);
Demangled demangled = child.demangle(demangler);
if (demangled instanceof DemangledList list) {
names = list;
}
break;
case Structure:
namespace = child.demangle(demangler, typeMetadata);
namespace = child.demangle(demangler);
break;
default:
skip(child);

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.*;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -26,9 +25,8 @@ import ghidra.app.util.demangler.swift.SwiftDemangler;
public class SwiftInOutNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
Demangled demangled = demangleFirstChild(demangler, typeMetadata);
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
Demangled demangled = demangleFirstChild(demangler);
if (demangled instanceof DemangledDataType type) {
type.incrementPointerLevels();
}

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.Demangled;
import ghidra.app.util.demangler.DemangledException;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
@ -29,14 +28,13 @@ import ghidra.program.model.lang.CompilerSpec;
public class SwiftInitializerNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
String name = null;
Demangled namespace = null;
for (SwiftNode child : getChildren()) {
switch (child.getKind()) {
case Variable:
namespace = child.demangle(demangler, typeMetadata);
namespace = child.demangle(demangler);
name = "init";
break;
default:

View File

@ -18,7 +18,6 @@ package ghidra.app.util.demangler.swift.nodes;
import java.util.ArrayList;
import java.util.List;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.*;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -29,13 +28,12 @@ import ghidra.app.util.demangler.swift.SwiftDemangler;
public class SwiftLabelListNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
List<Demangled> elements = new ArrayList<>();
for (SwiftNode child : getChildren()) {
switch (child.getKind()) {
case Identifier:
elements.add(child.demangle(demangler, typeMetadata));
elements.add(child.demangle(demangler));
break;
case FirstElementMarker:
elements.add(new DemangledUnknown(properties.mangled(),

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.Demangled;
import ghidra.app.util.demangler.DemangledException;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
@ -29,14 +28,13 @@ import ghidra.program.model.lang.CompilerSpec;
public class SwiftLazyProtocolWitnessTableAccessorNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
String name = null;
Demangled namespace = null;
for (SwiftNode child : getChildren()) {
switch (child.getKind()) {
case Type:
namespace = child.demangle(demangler, typeMetadata);
namespace = child.demangle(demangler);
name = "lazy_protocol_witness_table_accessor";
break;
default:

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.*;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -26,8 +25,7 @@ import ghidra.app.util.demangler.swift.SwiftDemangler;
public class SwiftLocalDeclNameNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
String name = null;
Long number = null;
for (SwiftNode child : getChildren()) {

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.*;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -29,18 +28,17 @@ import ghidra.program.model.lang.CompilerSpec;
public class SwiftModifyAccessorNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
Demangled demangled = null;
String name = "modify_";
String callingConvention = CompilerSpec.CALLING_CONVENTION_thiscall;
for (SwiftNode child : getChildren()) {
switch (child.getKind()) {
case Subscript:
demangled = child.demangle(demangler, typeMetadata);
demangled = child.demangle(demangler);
break;
case Variable:
demangled = child.demangle(demangler, typeMetadata);
demangled = child.demangle(demangler);
break;
default:
skip(child);

View File

@ -19,7 +19,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.*;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -113,7 +112,7 @@ public abstract class SwiftNode {
case Tuple -> new SwiftTupleNode();
case TupleElement -> new SwiftTupleElementNode();
case TupleElementName -> new SwiftGenericTextNode();
case Type -> new SwiftTypeNode();
case Type -> new SwiftGenericPassthroughNode();
case TypeAlias -> new SwiftTypeAliasNode();
case TypeList -> new SwiftTypeListNode();
case TypeMetadataAccessFunction -> new SwiftTypeMetadataAccessFunctionNode();
@ -129,11 +128,10 @@ public abstract class SwiftNode {
* Demangles this {@link SwiftNode}
*
* @param demangler The {@link SwiftDemangler}
* @param typeMetadata The {@link SwiftTypeMetadata}, or null if it is not known
* @return The demangled {@link SwiftNode}
* @throws DemangledException if a problem occurred
*/
public abstract Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
public abstract Demangled demangle(SwiftDemangler demangler)
throws DemangledException;
/**
@ -354,17 +352,16 @@ public abstract class SwiftNode {
* Demangles the first child {@link SwiftNode}, if it exists
*
* @param demangler The {@link SwiftDemangler}
* @param typeMetadata The {@link SwiftTypeMetadata}, or null if it is not known
* @return The demangled first child {@link SwiftNode}
* @throws DemangledException if there are no children or another problem occurred
*/
protected Demangled demangleFirstChild(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
protected Demangled demangleFirstChild(SwiftDemangler demangler)
throws DemangledException {
Demangled first = null;
for (int i = 0; i < children.size(); i++) {
SwiftNode child = children.get(i);
if (i == 0) {
first = child.demangle(demangler, typeMetadata);
first = child.demangle(demangler);
}
else {
child.skip(child);

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.*;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -28,13 +27,12 @@ import ghidra.program.model.lang.CompilerSpec;
public class SwiftOutlinedConsumeNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
Demangled type = null;
for (SwiftNode child : getChildren()) {
switch (child.getKind()) {
case Type:
type = child.demangle(demangler, typeMetadata);
type = child.demangle(demangler);
break;
default:
skip(child);

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.*;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -28,13 +27,12 @@ import ghidra.program.model.lang.CompilerSpec;
public class SwiftOutlinedCopyNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
Demangled type = null;
for (SwiftNode child : getChildren()) {
switch (child.getKind()) {
case Type:
type = child.demangle(demangler, typeMetadata);
type = child.demangle(demangler);
break;
default:
skip(child);

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.*;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -26,15 +25,14 @@ import ghidra.app.util.demangler.swift.SwiftDemangler;
public class SwiftPrivateDeclNameNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
String name = null;
Demangled namespace = null;
for (SwiftNode child : getChildren()) {
switch (child.getKind()) {
case Identifier:
if (namespace == null) {
namespace = child.demangle(demangler, typeMetadata);
namespace = child.demangle(demangler);
}
else {
name = child.getText();

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.*;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -26,22 +25,21 @@ import ghidra.app.util.demangler.swift.SwiftDemangler;
public class SwiftProtocolConformanceNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
Demangled type1 = null;
Demangled type2 = null;
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
Demangled type = null;
Demangled protocol = null;
Demangled namespace = null;
for (SwiftNode child : getChildren()) {
switch (child.getKind()) {
case Module:
namespace = child.demangle(demangler, typeMetadata);
namespace = child.demangle(demangler);
break;
case Type:
if (type1 == null) {
type1 = child.demangle(demangler, typeMetadata);
if (child.hasChild(SwiftDemangledNodeKind.Protocol)) {
protocol = child.demangle(demangler);
}
else {
type2 = child.demangle(demangler, typeMetadata);
type = child.demangle(demangler);
}
break;
default:
@ -49,11 +47,12 @@ public class SwiftProtocolConformanceNode extends SwiftNode {
break;
}
}
if (type1 == null && type2 == null) {
if (type == null || protocol == null) {
return getUnknown();
}
DemangledUnknown demangled = new DemangledUnknown(properties.mangled(),
properties.originalDemangled(), SwiftNode.join(type2, type1).getNamespaceString());
DemangledUnknown demangled =
new DemangledUnknown(properties.mangled(), properties.originalDemangled(),
type.getNamespaceString() + "->" + protocol.getNamespaceString());
demangled.setNamespace(namespace);
return demangled;
}

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.*;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -26,8 +25,7 @@ import ghidra.app.util.demangler.swift.SwiftDemangler;
public class SwiftProtocolNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
String name = null;
Demangled namespace = null;
for (SwiftNode child : getChildren()) {
@ -36,7 +34,7 @@ public class SwiftProtocolNode extends SwiftNode {
name = child.getText();
break;
case Module:
namespace = child.demangle(demangler, typeMetadata);
namespace = child.demangle(demangler);
break;
default:
skip(child);

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.*;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -29,18 +28,17 @@ import ghidra.program.model.lang.CompilerSpec;
public class SwiftSetterNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
Demangled demangled = null;
String name = "set_";
String callingConvention = CompilerSpec.CALLING_CONVENTION_thiscall;
for (SwiftNode child : getChildren()) {
switch (child.getKind()) {
case Subscript:
demangled = child.demangle(demangler, typeMetadata);
demangled = child.demangle(demangler);
break;
case Variable:
demangled = child.demangle(demangler, typeMetadata);
demangled = child.demangle(demangler);
break;
default:
skip(child);

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.*;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -27,8 +26,7 @@ import ghidra.app.util.demangler.swift.datatypes.*;
public class SwiftStructureNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
String name = null;
Demangled namespace = null;
Demangled privateDeclNamespace = null;
@ -38,14 +36,15 @@ public class SwiftStructureNode extends SwiftNode {
name = child.getText();
break;
case PrivateDeclName:
Demangled temp = child.demangle(demangler, typeMetadata);
Demangled temp = child.demangle(demangler);
name = temp.getName();
privateDeclNamespace = temp.getNamespace();
break;
case Class:
case Enum:
case Module:
case Structure:
namespace = child.demangle(demangler, typeMetadata);
namespace = child.demangle(demangler);
break;
default:
skip(child);
@ -85,7 +84,7 @@ public class SwiftStructureNode extends SwiftNode {
}
SwiftStructure struct = new SwiftStructure(mangled, orig, name,
SwiftNode.join(namespace, privateDeclNamespace), typeMetadata, demangler);
SwiftNode.join(namespace, privateDeclNamespace), demangler);
// The structure has no fields, which behaves poorly in the decompiler. Give it one
// undefined* field instead.

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.*;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -28,8 +27,7 @@ import ghidra.program.model.lang.CompilerSpec;
public class SwiftSubscriptNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
String name = null;
Demangled namespace = null;
Demangled type = null;
@ -41,14 +39,14 @@ public class SwiftSubscriptNode extends SwiftNode {
callingConvention = CompilerSpec.CALLING_CONVENTION_thiscall;
// Fall through
case Structure:
namespace = child.demangle(demangler, typeMetadata);
namespace = child.demangle(demangler);
name = "subscript";
break;
case LabelList:
labelList = child.demangle(demangler, typeMetadata);
labelList = child.demangle(demangler);
break;
case Type:
type = child.demangle(demangler, typeMetadata);
type = child.demangle(demangler);
break;
default:
skip(child);

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.*;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -26,8 +25,7 @@ import ghidra.app.util.demangler.swift.SwiftDemangler;
public class SwiftTupleElementNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
Demangled type = null;
String name = null;
for (SwiftNode child : getChildren()) {
@ -36,7 +34,7 @@ public class SwiftTupleElementNode extends SwiftNode {
name = child.getText();
break;
case Type:
type = child.demangle(demangler, typeMetadata);
type = child.demangle(demangler);
break;
default:
skip(child);

View File

@ -18,7 +18,6 @@ package ghidra.app.util.demangler.swift.nodes;
import java.util.ArrayList;
import java.util.List;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.*;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -29,13 +28,12 @@ import ghidra.app.util.demangler.swift.SwiftDemangler;
public class SwiftTupleNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
List<Demangled> elements = new ArrayList<>();
for (SwiftNode child : getChildren()) {
switch (child.getKind()) {
case TupleElement:
elements.add(child.demangle(demangler, typeMetadata));
elements.add(child.demangle(demangler));
break;
default:
skip(child);

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.*;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -26,8 +25,7 @@ import ghidra.app.util.demangler.swift.SwiftDemangler;
public class SwiftTypeAliasNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
String name = null;
Demangled namespace = null;
for (SwiftNode child : getChildren()) {
@ -36,7 +34,7 @@ public class SwiftTypeAliasNode extends SwiftNode {
name = child.getText();
break;
case Module:
namespace = child.demangle(demangler, typeMetadata);
namespace = child.demangle(demangler);
break;
default:
skip(child);

View File

@ -18,7 +18,6 @@ package ghidra.app.util.demangler.swift.nodes;
import java.util.ArrayList;
import java.util.List;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.*;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -29,13 +28,12 @@ import ghidra.app.util.demangler.swift.SwiftDemangler;
public class SwiftTypeListNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
List<Demangled> elements = new ArrayList<>();
for (SwiftNode child : getChildren()) {
switch (child.getKind()) {
case Type:
elements.add(child.demangle(demangler, typeMetadata));
elements.add(child.demangle(demangler));
break;
default:
skip(child);

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.*;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -28,14 +27,13 @@ import ghidra.program.model.lang.CompilerSpec;
public class SwiftTypeMetadataAccessFunctionNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
String name = null;
Demangled namespace = null;
for (SwiftNode child : getChildren()) {
switch (child.getKind()) {
case Type:
namespace = child.demangle(demangler, typeMetadata);
namespace = child.demangle(demangler);
name = "typeMetadataAccessor";
break;
default:

View File

@ -1,34 +0,0 @@
/* ###
* IP: GHIDRA
*
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.Demangled;
import ghidra.app.util.demangler.DemangledException;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
import ghidra.app.util.demangler.swift.SwiftDemangler;
/**
* A {@link SwiftDemangledNodeKind#Type} {@link SwiftNode}
*/
public class SwiftTypeNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
return demangleFirstChild(demangler, typeMetadata);
}
}

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.Demangled;
import ghidra.app.util.demangler.DemangledException;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
@ -29,14 +28,13 @@ import ghidra.program.model.lang.CompilerSpec;
public class SwiftUnsafeMutableAddressorNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
String name = null;
Demangled namespace = null;
for (SwiftNode child : getChildren()) {
switch (child.getKind()) {
case Variable:
namespace = child.demangle(demangler, typeMetadata);
namespace = child.demangle(demangler);
name = "unsafeMutableAddressor";
break;
default:

View File

@ -15,8 +15,8 @@
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.Demangled;
import ghidra.app.util.demangler.DemangledException;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -40,7 +40,7 @@ public class SwiftUnsupportedNode extends SwiftNode {
}
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata) {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
skip(this);
return getUnknown();
}

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.*;
import ghidra.app.util.demangler.swift.SwiftDemangledNodeKind;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -26,8 +25,7 @@ import ghidra.app.util.demangler.swift.SwiftDemangler;
public class SwiftVariableNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
String name = null;
Demangled namespace = null;
Demangled privateDeclNamespace = null;
@ -38,7 +36,7 @@ public class SwiftVariableNode extends SwiftNode {
name = child.getText();
break;
case PrivateDeclName:
Demangled temp = child.demangle(demangler, typeMetadata);
Demangled temp = child.demangle(demangler);
name = temp.getName();
privateDeclNamespace = temp.getNamespace();
break;
@ -48,10 +46,10 @@ public class SwiftVariableNode extends SwiftNode {
case Module:
case Protocol:
case Structure:
namespace = child.demangle(demangler, typeMetadata);
namespace = child.demangle(demangler);
break;
case Type:
type = child.demangle(demangler, typeMetadata);
type = child.demangle(demangler);
break;
default:
skip(child);

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes.generic;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.*;
import ghidra.app.util.demangler.swift.SwiftDemangler;
import ghidra.app.util.demangler.swift.nodes.SwiftNode;
@ -26,9 +25,8 @@ import ghidra.app.util.demangler.swift.nodes.SwiftNode;
public class SwiftGenericDescriptorNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
Demangled demangled = demangleFirstChild(demangler, typeMetadata);
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
Demangled demangled = demangleFirstChild(demangler);
return new DemangledLabel(properties.mangled(), properties.originalDemangled(),
demangled.getNamespaceString());
}

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes.generic;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.Demangled;
import ghidra.app.util.demangler.DemangledLabel;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -27,8 +26,7 @@ import ghidra.app.util.demangler.swift.nodes.SwiftNode;
public class SwiftGenericIndexNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata) {
return new DemangledLabel(properties.mangled(), properties.originalDemangled(),
getIndex());
public Demangled demangle(SwiftDemangler demangler) {
return new DemangledLabel(properties.mangled(), properties.originalDemangled(), getIndex());
}
}

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes.generic;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.Demangled;
import ghidra.app.util.demangler.DemangledException;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -27,8 +26,7 @@ import ghidra.app.util.demangler.swift.nodes.SwiftNode;
public class SwiftGenericPassthroughNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata)
throws DemangledException {
return demangleFirstChild(demangler, typeMetadata);
public Demangled demangle(SwiftDemangler demangler) throws DemangledException {
return demangleFirstChild(demangler);
}
}

View File

@ -15,7 +15,6 @@
*/
package ghidra.app.util.demangler.swift.nodes.generic;
import ghidra.app.util.bin.format.swift.SwiftTypeMetadata;
import ghidra.app.util.demangler.Demangled;
import ghidra.app.util.demangler.DemangledLabel;
import ghidra.app.util.demangler.swift.SwiftDemangler;
@ -27,8 +26,7 @@ import ghidra.app.util.demangler.swift.nodes.SwiftNode;
public class SwiftGenericTextNode extends SwiftNode {
@Override
public Demangled demangle(SwiftDemangler demangler, SwiftTypeMetadata typeMetadata) {
return new DemangledLabel(properties.mangled(), properties.originalDemangled(),
getText());
public Demangled demangle(SwiftDemangler demangler) {
return new DemangledLabel(properties.mangled(), properties.originalDemangled(), getText());
}
}