feat(cli): add option to disable plugins (#2277)
This commit is contained in:
@@ -7,6 +7,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -194,6 +195,8 @@ public class JadxArgs implements Closeable {
|
||||
|
||||
private Map<String, String> pluginOptions = new HashMap<>();
|
||||
|
||||
private Set<String> disabledPlugins = new HashSet<>();
|
||||
|
||||
private JadxPluginLoader pluginLoader = new JadxBasePluginLoader();
|
||||
|
||||
private boolean loadJadxClsSetFile = true;
|
||||
@@ -766,6 +769,14 @@ public class JadxArgs implements Closeable {
|
||||
this.pluginOptions = pluginOptions;
|
||||
}
|
||||
|
||||
public Set<String> getDisabledPlugins() {
|
||||
return disabledPlugins;
|
||||
}
|
||||
|
||||
public void setDisabledPlugins(Set<String> disabledPlugins) {
|
||||
this.disabledPlugins = disabledPlugins;
|
||||
}
|
||||
|
||||
public JadxPluginLoader getPluginLoader() {
|
||||
return pluginLoader;
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ public final class JadxDecompiler implements Closeable {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(JadxDecompiler.class);
|
||||
|
||||
private final JadxArgs args;
|
||||
private final JadxPluginManager pluginManager = new JadxPluginManager(this);
|
||||
private final JadxPluginManager pluginManager;
|
||||
private final List<ICodeLoader> loadedInputs = new ArrayList<>();
|
||||
|
||||
private RootNode root;
|
||||
@@ -93,7 +93,7 @@ public final class JadxDecompiler implements Closeable {
|
||||
private List<ResourceFile> resources;
|
||||
|
||||
private final IDecompileScheduler decompileScheduler = new DecompilerScheduler();
|
||||
private final ResourcesLoader resourcesLoader = new ResourcesLoader(this);
|
||||
private final ResourcesLoader resourcesLoader;
|
||||
|
||||
private final List<ICodeLoader> customCodeLoaders = new ArrayList<>();
|
||||
private final List<CustomResourcesLoader> customResourcesLoaders = new ArrayList<>();
|
||||
@@ -106,7 +106,9 @@ public final class JadxDecompiler implements Closeable {
|
||||
}
|
||||
|
||||
public JadxDecompiler(JadxArgs args) {
|
||||
this.args = args;
|
||||
this.args = Objects.requireNonNull(args);
|
||||
this.pluginManager = new JadxPluginManager(this);
|
||||
this.resourcesLoader = new ResourcesLoader(this);
|
||||
}
|
||||
|
||||
public void load() {
|
||||
|
||||
@@ -4,12 +4,14 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -26,6 +28,7 @@ public class JadxPluginManager {
|
||||
|
||||
private final JadxDecompiler decompiler;
|
||||
private final JadxPluginsData pluginsData;
|
||||
private final Set<String> disabledPlugins;
|
||||
private final SortedSet<PluginContext> allPlugins = new TreeSet<>();
|
||||
private final SortedSet<PluginContext> resolvedPlugins = new TreeSet<>();
|
||||
private final Map<String, String> provideSuggestions = new TreeMap<>();
|
||||
@@ -35,6 +38,7 @@ public class JadxPluginManager {
|
||||
public JadxPluginManager(JadxDecompiler decompiler) {
|
||||
this.decompiler = decompiler;
|
||||
this.pluginsData = new JadxPluginsData(decompiler, this);
|
||||
this.disabledPlugins = decompiler.getArgs().getDisabledPlugins();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,12 +59,19 @@ public class JadxPluginManager {
|
||||
public void register(JadxPlugin plugin) {
|
||||
Objects.requireNonNull(plugin);
|
||||
PluginContext addedPlugin = addPlugin(plugin);
|
||||
if (addedPlugin == null) {
|
||||
LOG.debug("Can't register plugin, it was disabled: {}", plugin.getPluginInfo().getPluginId());
|
||||
return;
|
||||
}
|
||||
LOG.debug("Register plugin: {}", addedPlugin.getPluginId());
|
||||
resolve();
|
||||
}
|
||||
|
||||
private PluginContext addPlugin(JadxPlugin plugin) {
|
||||
private @Nullable PluginContext addPlugin(JadxPlugin plugin) {
|
||||
PluginContext pluginContext = new PluginContext(decompiler, pluginsData, plugin);
|
||||
if (disabledPlugins.contains(pluginContext.getPluginId())) {
|
||||
return null;
|
||||
}
|
||||
LOG.debug("Loading plugin: {}", pluginContext);
|
||||
if (!allPlugins.add(pluginContext)) {
|
||||
throw new IllegalArgumentException("Duplicate plugin id: " + pluginContext + ", class " + plugin.getClass());
|
||||
|
||||
Reference in New Issue
Block a user