Skip to content

Commit 4b38db9

Browse files
committed
Merge remote-tracking branch 'origin/patch'
2 parents 5e7a25e + 395cf82 commit 4b38db9

7 files changed

Lines changed: 18 additions & 59 deletions

File tree

Ghidra/Features/Swift/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SwiftDemangler
22

3-
This module provides support for demanling mangled [Swift](https://www.swift.org) symbols. Supported
3+
This module provides support for demangling mangled [Swift](https://www.swift.org) symbols. Supported
44
mangled symbols begin with `$S`, `$s`, `_$S"`, `_$s`, or `_T`.
55

66
The demangler currently relies on making direct calls to the native Swift demangler tool, which
@@ -21,5 +21,4 @@ protocol descriptor for SwiftUI.View
2121
The resulting tree is parsed by the Ghidra Swift Demangler to form and apply a demangled symbol
2222
name.
2323

24-
By default, the `Demangler Swift` Analyzer will search for the native Swift Demangler on the `PATH`.
25-
If it resides elsewhere, its path can be specified in the analyzer's options.
24+
The `Demangler Swift` Analyzer assumes that the native Swift Demangler is on the `PATH`.

Ghidra/Features/Swift/ghidra_scripts/SwiftDemanglerScript.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ protected void run() throws Exception {
5555
return;
5656
}
5757

58-
SwiftNativeDemangler nativeDemangler = new SwiftNativeDemangler(options.getSwiftDir());
58+
SwiftNativeDemangler nativeDemangler = new SwiftNativeDemangler();
5959
SwiftNativeDemangledOutput demangledOutput = nativeDemangler.demangle(mangled);
6060
println(demangledOutput.toString());
6161

Ghidra/Features/Swift/src/main/java/ghidra/app/plugin/core/analysis/SwiftDemanglerAnalyzer.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package ghidra.app.plugin.core.analysis;
1717

18-
import java.io.File;
1918
import java.io.IOException;
2019

2120
import ghidra.app.util.demangler.*;
@@ -36,10 +35,7 @@ public class SwiftDemanglerAnalyzer extends AbstractDemanglerAnalyzer {
3635

3736
private static final String NAME = "Demangler Swift";
3837
private static final String DESCRIPTION =
39-
"Demangles Swift symbols and applies appropriate datatype and calling conventions where possible. Requires Swift to be installed.";
40-
private static final String OPTION_NAME_SWIFT_DIR = "Swift binary directory";
41-
private static final String OPTION_DESCRIPTION_SWIFT_DIR =
42-
"Path to the Swift installation binary directory, if not on PATH";
38+
"Demangles Swift symbols and applies appropriate datatype and calling conventions where possible. Requires Swift to be on the PATH.";
4339

4440
private static final String OPTION_NAME_INCOMPLETE_PREFIX =
4541
"Use incomplete demangle label prefix (%s)"
@@ -54,7 +50,6 @@ public class SwiftDemanglerAnalyzer extends AbstractDemanglerAnalyzer {
5450
"Prefix unsupported demangled labels with '%s'"
5551
.formatted(SwiftDemanglerOptions.UNSUPPORTED_PREFIX);
5652

57-
private File swiftDir;
5853
private boolean useIncompletePrefix = true;
5954
private boolean useUnsupportedPrefix = true;
6055

@@ -94,8 +89,6 @@ protected DemangledObject doDemangle(MangledContext mangledContext, MessageLog l
9489
@Override
9590
public void registerOptions(Options options, Program program) {
9691
HelpLocation help = new HelpLocation("AutoAnalysisPlugin", "Demangler_Analyzer");
97-
options.registerOption(OPTION_NAME_SWIFT_DIR, OptionType.FILE_TYPE, swiftDir, help,
98-
OPTION_DESCRIPTION_SWIFT_DIR);
9992
options.registerOption(OPTION_NAME_INCOMPLETE_PREFIX, OptionType.BOOLEAN_TYPE,
10093
useIncompletePrefix, help, OPTION_DESCRIPTION_INCOMPLETE_PREFIX);
10194
options.registerOption(OPTION_NAME_UNSUPPORTED_PREFIX, OptionType.BOOLEAN_TYPE,
@@ -104,9 +97,9 @@ public void registerOptions(Options options, Program program) {
10497

10598
@Override
10699
protected boolean validateOptions(DemanglerOptions options, MessageLog log) {
107-
if (options instanceof SwiftDemanglerOptions swiftDemanglerOptions) {
100+
if (options instanceof SwiftDemanglerOptions) {
108101
try {
109-
new SwiftNativeDemangler(swiftDemanglerOptions.getSwiftDir());
102+
new SwiftNativeDemangler();
110103
return true;
111104
}
112105
catch (IOException e) {
@@ -120,7 +113,6 @@ protected boolean validateOptions(DemanglerOptions options, MessageLog log) {
120113

121114
@Override
122115
public void optionsChanged(Options options, Program program) {
123-
swiftDir = options.getFile(OPTION_NAME_SWIFT_DIR, swiftDir);
124116
useIncompletePrefix =
125117
options.getBoolean(OPTION_NAME_INCOMPLETE_PREFIX, useIncompletePrefix);
126118
useUnsupportedPrefix =
@@ -130,7 +122,6 @@ public void optionsChanged(Options options, Program program) {
130122
@Override
131123
protected DemanglerOptions getOptions() {
132124
SwiftDemanglerOptions swiftDemanglerOptions = new SwiftDemanglerOptions();
133-
swiftDemanglerOptions.setSwiftDir(swiftDir);
134125
swiftDemanglerOptions.setIncompletePrefix(useIncompletePrefix);
135126
swiftDemanglerOptions.setUnsupportedPrefix(useUnsupportedPrefix);
136127
return swiftDemanglerOptions;

Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/SwiftDemangler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public SwiftDemanglerOptions getSwiftDemanglerOptions(DemanglerOptions opt)
189189
private void setSwiftNativeDemangler(SwiftDemanglerOptions options) throws DemangledException {
190190
if (nativeDemangler == null) {
191191
try {
192-
nativeDemangler = new SwiftNativeDemangler(options.getSwiftDir());
192+
nativeDemangler = new SwiftNativeDemangler();
193193
}
194194
catch (IOException e) {
195195
throw new DemangledException(e);

Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/SwiftDemanglerOptions.java

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
7+
*
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -15,8 +15,6 @@
1515
*/
1616
package ghidra.app.util.demangler.swift;
1717

18-
import java.io.File;
19-
2018
import ghidra.app.util.demangler.DemanglerOptions;
2119

2220
/**
@@ -27,33 +25,9 @@ public class SwiftDemanglerOptions extends DemanglerOptions {
2725
public static final String INCOMPLETE_PREFIX = "$";
2826
public static final String UNSUPPORTED_PREFIX = "$$";
2927

30-
private File swiftDir;
3128
private boolean useIncompletePrefix;
3229
private boolean useUnsupportedPrefix;
3330

34-
/**
35-
* Gets the Swift directory
36-
* <p>
37-
* If the Swift directory is on the PATH environment variable, this may return null
38-
*
39-
* @return The Swift directory
40-
*/
41-
public File getSwiftDir() {
42-
return swiftDir;
43-
}
44-
45-
/**
46-
* Sets the Swift directory
47-
* <p>
48-
* If the Swift directory is on the PATH environment variable, it is fine to set this to
49-
* null
50-
*
51-
* @param swiftDir The Swift directory
52-
*/
53-
public void setSwiftDir(File swiftDir) {
54-
this.swiftDir = swiftDir;
55-
}
56-
5731
/**
5832
* {@return the "incomplete prefix" character to use in label names}
5933
*/

Ghidra/Features/Swift/src/main/java/ghidra/app/util/demangler/swift/SwiftNativeDemangler.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
7+
*
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -34,7 +34,7 @@
3434
*/
3535
public class SwiftNativeDemangler {
3636

37-
private String nativeDemanglerPath;
37+
private String nativeDemanglerCmd;
3838
private boolean standaloneDemanglerBinary;
3939

4040
/**
@@ -54,25 +54,20 @@ public String toString() {
5454
/**
5555
* Creates a new {@link SwiftNativeDemangler}
5656
*
57-
* @param swiftDir The Swift directory
5857
* @throws IOException if there was a problem finding or running the Swift native demangler
5958
*/
60-
public SwiftNativeDemangler(File swiftDir) throws IOException {
59+
public SwiftNativeDemangler() throws IOException {
6160
List<String> demanglerNames = List.of("swift-demangle", "swift");
6261
IOException ioe = null;
6362
for (String demanglerName : demanglerNames) {
64-
nativeDemanglerPath = demanglerName;
65-
if (swiftDir != null) {
66-
nativeDemanglerPath = swiftDir + File.separator + nativeDemanglerPath;
67-
}
63+
nativeDemanglerCmd = demanglerName; // expect swift demangler to be on the PATH
6864
try {
6965
int exitCode =
70-
new ProcessBuilder(List.of(nativeDemanglerPath, "--version")).start()
71-
.waitFor();
66+
new ProcessBuilder(List.of(nativeDemanglerCmd, "--version")).start().waitFor();
7267
if (exitCode == 0) {
7368
ioe = null;
7469
standaloneDemanglerBinary =
75-
new File(nativeDemanglerPath).getName().contains("-demangle");
70+
new File(nativeDemanglerCmd).getName().contains("-demangle");
7671
break;
7772
}
7873
ioe = new IOException("Native Swift demangler exited with code: " + exitCode);
@@ -144,7 +139,7 @@ public SwiftNativeDemangledOutput demangle(String mangled) throws IOException {
144139
*/
145140
private BufferedReader demangle(String mangled, List<String> options) throws IOException {
146141
List<String> command = new ArrayList<>();
147-
command.add(nativeDemanglerPath);
142+
command.add(nativeDemanglerCmd);
148143
if (!standaloneDemanglerBinary) {
149144
command.add("demangle");
150145
}

Ghidra/Features/Swift/src/test/java/ghidra/app/util/demangler/swift/SwiftDemanglerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void setUp() throws Exception {
4343
// Ghidra does not ship the native Swift demangler binary, so it may not be present to run
4444
// these tests. In this scenario, we just want these tests skipped (as opposed to failing).
4545
try {
46-
new SwiftNativeDemangler(new SwiftDemanglerOptions().getSwiftDir());
46+
new SwiftNativeDemangler();
4747
}
4848
catch (IOException e) {
4949
assumeNoException(e); // skip test, don't fail

0 commit comments

Comments
 (0)