feat(cli): install and manage plugins from command line
This commit is contained in:
@@ -25,6 +25,8 @@ import jadx.api.deobf.IAliasProvider;
|
||||
import jadx.api.deobf.IRenameCondition;
|
||||
import jadx.api.impl.AnnotatedCodeWriter;
|
||||
import jadx.api.impl.InMemoryCodeCache;
|
||||
import jadx.api.plugins.loader.JadxBasePluginLoader;
|
||||
import jadx.api.plugins.loader.JadxPluginLoader;
|
||||
import jadx.api.usage.IUsageInfoCache;
|
||||
import jadx.api.usage.impl.InMemoryUsageInfoCache;
|
||||
import jadx.core.deobf.DeobfAliasProvider;
|
||||
@@ -150,6 +152,8 @@ public class JadxArgs implements Closeable {
|
||||
|
||||
private Map<String, String> pluginOptions = new HashMap<>();
|
||||
|
||||
private JadxPluginLoader pluginLoader = new JadxBasePluginLoader();
|
||||
|
||||
public JadxArgs() {
|
||||
// use default options
|
||||
}
|
||||
@@ -170,6 +174,9 @@ public class JadxArgs implements Closeable {
|
||||
if (usageInfoCache != null) {
|
||||
usageInfoCache.close();
|
||||
}
|
||||
if (pluginLoader != null) {
|
||||
pluginLoader.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.error("Failed to close JadxArgs", e);
|
||||
} finally {
|
||||
@@ -634,6 +641,14 @@ public class JadxArgs implements Closeable {
|
||||
this.pluginOptions = pluginOptions;
|
||||
}
|
||||
|
||||
public JadxPluginLoader getPluginLoader() {
|
||||
return pluginLoader;
|
||||
}
|
||||
|
||||
public void setPluginLoader(JadxPluginLoader pluginLoader) {
|
||||
this.pluginLoader = pluginLoader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hash of all options that can change result code
|
||||
*/
|
||||
|
||||
@@ -182,7 +182,7 @@ public final class JadxDecompiler implements Closeable {
|
||||
|
||||
private void loadPlugins() {
|
||||
pluginManager.providesSuggestion("java-input", args.isUseDxInput() ? "java-convert" : "java-input");
|
||||
pluginManager.load();
|
||||
pluginManager.load(args.getPluginLoader());
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Resolved plugins: {}", pluginManager.getResolvedPluginContexts());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package jadx.api.plugins.loader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
import jadx.api.plugins.JadxPlugin;
|
||||
|
||||
/**
|
||||
* Loading plugins from current classpath
|
||||
*/
|
||||
public class JadxBasePluginLoader implements JadxPluginLoader {
|
||||
|
||||
@Override
|
||||
public List<JadxPlugin> load() {
|
||||
List<JadxPlugin> list = new ArrayList<>();
|
||||
ServiceLoader<JadxPlugin> plugins = ServiceLoader.load(JadxPlugin.class);
|
||||
for (JadxPlugin plugin : plugins) {
|
||||
list.add(plugin);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
// nothing to close
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package jadx.api.plugins.loader;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.util.List;
|
||||
|
||||
import jadx.api.plugins.JadxPlugin;
|
||||
|
||||
public interface JadxPluginLoader extends Closeable {
|
||||
|
||||
List<JadxPlugin> load();
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
@@ -18,6 +17,7 @@ import jadx.api.JadxDecompiler;
|
||||
import jadx.api.plugins.JadxPlugin;
|
||||
import jadx.api.plugins.gui.JadxGuiContext;
|
||||
import jadx.api.plugins.input.JadxCodeInput;
|
||||
import jadx.api.plugins.loader.JadxPluginLoader;
|
||||
import jadx.api.plugins.options.JadxPluginOptions;
|
||||
import jadx.api.plugins.options.OptionDescription;
|
||||
import jadx.core.utils.exceptions.JadxRuntimeException;
|
||||
@@ -43,10 +43,9 @@ public class JadxPluginManager {
|
||||
provideSuggestions.put(provides, pluginId);
|
||||
}
|
||||
|
||||
public void load() {
|
||||
public void load(JadxPluginLoader pluginLoader) {
|
||||
allPlugins.clear();
|
||||
ServiceLoader<JadxPlugin> jadxPlugins = ServiceLoader.load(JadxPlugin.class);
|
||||
for (JadxPlugin plugin : jadxPlugins) {
|
||||
for (JadxPlugin plugin : pluginLoader.load()) {
|
||||
addPlugin(plugin);
|
||||
}
|
||||
resolve();
|
||||
|
||||
Reference in New Issue
Block a user