Skip to content

Commit d585467

Browse files
authored
Merge pull request #1 from skylot/new-jadx-api
Use new jadx API for icons and usage dialog
2 parents dea32e7 + 5230a1d commit d585467

10 files changed

Lines changed: 20 additions & 37 deletions

File tree

build.gradle.kts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,13 @@ plugins {
1111
}
1212

1313
dependencies {
14-
val jadxVersion = "1.5.1"
14+
val jadxVersion = "1.5.2-SNAPSHOT"
1515
val isJadxSnapshot = jadxVersion.endsWith("-SNAPSHOT")
1616

1717
// use compile only scope to exclude jadx-core and its dependencies from result jar
1818
compileOnly("io.github.skylot:jadx-core:$jadxVersion") {
1919
isChanging = isJadxSnapshot
2020
}
21-
compileOnly("io.github.skylot:jadx-gui:$jadxVersion") {
22-
isChanging = isJadxSnapshot
23-
}
24-
// don't know why I need this, but tests fail otherwise
25-
testRuntimeOnly("io.github.skylot:jadx-gui:$jadxVersion") {
26-
isChanging = isJadxSnapshot
27-
}
28-
compileOnly("io.github.skylot:jadx-cli:$jadxVersion") {
29-
isChanging = isJadxSnapshot
30-
}
3121

3222
testImplementation("io.github.skylot:jadx-smali-input:$jadxVersion") {
3323
isChanging = isJadxSnapshot

src/main/java/org/ajsmith/jadx/plugins/nativelibraries/NativeLibrariesPlugin.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public JadxPluginInfo getPluginInfo() {
2020
.name("Native Library Info")
2121
.description(DESCRIPTION)
2222
.homepage("https://github.com/andyjsmith/jadx-native-libraries-plugin")
23+
.requiredJadxVersion("1.5.2, r2372")
2324
.build();
2425
}
2526

src/main/java/org/ajsmith/jadx/plugins/nativelibraries/PluginDialog.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
import jadx.api.JavaMethod;
44
import jadx.api.plugins.JadxPluginContext;
5-
import jadx.gui.treemodel.JNode;
6-
import jadx.gui.ui.MainWindow;
7-
import jadx.gui.ui.dialog.UsageDialog;
85
import org.ajsmith.jadx.plugins.nativelibraries.components.NativeMethod;
96
import org.ajsmith.jadx.plugins.nativelibraries.components.NativeRoot;
107
import org.jetbrains.annotations.Nullable;
@@ -65,7 +62,6 @@ public PluginDialog(JFrame parent, JadxPluginContext context, PluginOptions opti
6562
findUsageBtn.setEnabled(false);
6663
findUsageBtn.addActionListener(e -> {
6764
if (context.getGuiContext() == null) return;
68-
MainWindow mw = (MainWindow) context.getGuiContext().getMainFrame();
6965

7066
TreeNode treeNode = (TreeNode) tree.getLastSelectedPathComponent();
7167
if (!(treeNode instanceof NativeMethod)) return;
@@ -76,10 +72,7 @@ public PluginDialog(JFrame parent, JadxPluginContext context, PluginOptions opti
7672
showMethodNotFoundDialog(treeNode);
7773
return;
7874
}
79-
80-
JNode node = mw.getCacheObject().getNodeCache().makeFrom(javaMethod);
81-
if (node == null) return;
82-
new UsageDialog(mw, node).setVisible(true);
75+
context.getGuiContext().openUsageDialog(javaMethod.getCodeNodeRef());
8376
});
8477

8578
JButton closeBtn = new JButton("Close");

src/main/java/org/ajsmith/jadx/plugins/nativelibraries/PluginOptions.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import jadx.api.plugins.JadxPluginContext;
44
import jadx.api.plugins.options.impl.BasePluginOptionsBuilder;
5-
import jadx.gui.settings.JadxSettings;
6-
import jadx.gui.ui.MainWindow;
75

86
public class PluginOptions extends BasePluginOptionsBuilder {
97
private final JadxPluginContext context;
@@ -16,11 +14,4 @@ public PluginOptions(JadxPluginContext context) {
1614
@Override
1715
public void registerOptions() {
1816
}
19-
20-
private void save() {
21-
if (context.getGuiContext() == null) return;
22-
JadxSettings settings = ((MainWindow) context.getGuiContext().getMainFrame()).getSettings();
23-
// save settings here
24-
settings.sync();
25-
}
2617
}

src/main/java/org/ajsmith/jadx/plugins/nativelibraries/components/NativeClass.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.ajsmith.jadx.plugins.nativelibraries.components;
22

3-
import jadx.gui.utils.Icons;
43
import org.jetbrains.annotations.NotNull;
54
import org.jetbrains.annotations.Nullable;
65

@@ -61,7 +60,7 @@ public String toString() {
6160

6261
@Override
6362
public @NotNull ImageIcon getIcon() {
64-
return Icons.CLASS;
63+
return getGuiContext().getSVGIcon("nodes/class");
6564
}
6665

6766
@Override

src/main/java/org/ajsmith/jadx/plugins/nativelibraries/components/NativeLibrary.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import jadx.api.ResourceFile;
44
import jadx.api.ResourcesLoader;
55
import jadx.core.utils.exceptions.JadxException;
6-
import jadx.gui.utils.UiUtils;
76
import org.jetbrains.annotations.NotNull;
87
import org.jetbrains.annotations.Nullable;
98

@@ -17,7 +16,6 @@
1716
import java.util.List;
1817

1918
public class NativeLibrary extends NativeObject {
20-
private static final ImageIcon SO_ICON = UiUtils.openSvgIcon("nodes/binaryFile");
2119
private final String libraryName;
2220
private final NativeRoot root;
2321
private final List<NativePackage> packages = new ArrayList<>();
@@ -144,7 +142,7 @@ public String toString() {
144142

145143
@Override
146144
public @NotNull ImageIcon getIcon() {
147-
return SO_ICON;
145+
return root.getGuiContext().getSVGIcon("nodes/binaryFile");
148146
}
149147

150148
@Override

src/main/java/org/ajsmith/jadx/plugins/nativelibraries/components/NativeMethod.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import jadx.api.JavaMethod;
55
import jadx.api.JavaPackage;
66
import jadx.core.utils.exceptions.DecodeException;
7-
import jadx.gui.utils.Icons;
87
import org.jetbrains.annotations.NotNull;
98
import org.jetbrains.annotations.Nullable;
109
import org.slf4j.Logger;
@@ -275,7 +274,7 @@ public String toString() {
275274

276275
@Override
277276
public @Nullable ImageIcon getIcon() {
278-
return Icons.METHOD;
277+
return getGuiContext().getSVGIcon("nodes/method");
279278
}
280279

281280
@Override

src/main/java/org/ajsmith/jadx/plugins/nativelibraries/components/NativeObject.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package org.ajsmith.jadx.plugins.nativelibraries.components;
22

33
import jadx.api.plugins.JadxPluginContext;
4+
import jadx.api.plugins.gui.JadxGuiContext;
45
import org.jetbrains.annotations.NotNull;
56
import org.jetbrains.annotations.Nullable;
67

78
import javax.swing.ImageIcon;
89
import javax.swing.tree.TreeNode;
10+
import java.util.Objects;
911

1012
public abstract class NativeObject implements TreeNode {
1113
protected static final String JAVA_PREFIX = "Java_";
@@ -55,4 +57,8 @@ public boolean getAllowsChildren() {
5557
if (getParent() == null) return null;
5658
return getParent().getContext();
5759
}
60+
61+
public @NotNull JadxGuiContext getGuiContext() {
62+
return getContext().getGuiContext();
63+
}
5864
}

src/main/java/org/ajsmith/jadx/plugins/nativelibraries/components/NativePackage.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.ajsmith.jadx.plugins.nativelibraries.components;
22

3-
import jadx.gui.utils.Icons;
43
import org.jetbrains.annotations.NotNull;
54
import org.jetbrains.annotations.Nullable;
65

@@ -115,7 +114,7 @@ public String getNameCompacted() {
115114

116115
@Override
117116
public @NotNull ImageIcon getIcon() {
118-
return Icons.PACKAGE;
117+
return getGuiContext().getSVGIcon("nodes/package");
119118
}
120119

121120
@Override

src/main/java/org/ajsmith/jadx/plugins/nativelibraries/components/NativeRoot.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import jadx.api.ResourceFile;
44
import jadx.api.ResourceType;
55
import jadx.api.plugins.JadxPluginContext;
6+
import jadx.api.plugins.gui.JadxGuiContext;
67
import net.fornwall.jelf.ElfFile;
78
import net.fornwall.jelf.ElfSymbol;
89
import org.jetbrains.annotations.NotNull;
@@ -18,6 +19,7 @@
1819
import java.util.Comparator;
1920
import java.util.Enumeration;
2021
import java.util.List;
22+
import java.util.Objects;
2123

2224
public class NativeRoot extends NativeObject {
2325
private static final Logger LOG = LoggerFactory.getLogger(NativeRoot.class);
@@ -77,6 +79,11 @@ public JadxPluginContext getContext() {
7779
return context;
7880
}
7981

82+
@Override
83+
public @NotNull JadxGuiContext getGuiContext() {
84+
return Objects.requireNonNull(context.getGuiContext());
85+
}
86+
8087
@Override
8188
@Nullable
8289
public ImageIcon getIcon() {

0 commit comments

Comments
 (0)