feat: allow to disable installed plugins (#2277)
This commit is contained in:
@@ -93,13 +93,14 @@ public final class JadxDecompiler implements Closeable {
|
||||
private List<ResourceFile> resources;
|
||||
|
||||
private final IDecompileScheduler decompileScheduler = new DecompilerScheduler();
|
||||
private final JadxEventsImpl events = new JadxEventsImpl();
|
||||
private final ResourcesLoader resourcesLoader = new ResourcesLoader(this);
|
||||
|
||||
private final List<ICodeLoader> customCodeLoaders = new ArrayList<>();
|
||||
private final List<CustomResourcesLoader> customResourcesLoaders = new ArrayList<>();
|
||||
private final Map<JadxPassType, List<JadxPass>> customPasses = new HashMap<>();
|
||||
|
||||
private IJadxEvents events = new JadxEventsImpl();
|
||||
|
||||
public JadxDecompiler() {
|
||||
this(new JadxArgs());
|
||||
}
|
||||
@@ -666,6 +667,10 @@ public final class JadxDecompiler implements Closeable {
|
||||
return events;
|
||||
}
|
||||
|
||||
public void setEventsImpl(IJadxEvents eventsImpl) {
|
||||
this.events = eventsImpl;
|
||||
}
|
||||
|
||||
public void addCustomCodeLoader(ICodeLoader customCodeLoader) {
|
||||
customCodeLoaders.add(customCodeLoader);
|
||||
}
|
||||
|
||||
@@ -15,4 +15,15 @@ public interface IJadxEvents {
|
||||
* For public event types check {@link JadxEvents} class.
|
||||
*/
|
||||
<E extends IJadxEvent> void addListener(JadxEventType<E> eventType, Consumer<E> listener);
|
||||
|
||||
/**
|
||||
* Remove listener for specific event.
|
||||
* Listener should be same or equal object.
|
||||
*/
|
||||
<E extends IJadxEvent> void removeListener(JadxEventType<E> eventType, Consumer<E> listener);
|
||||
|
||||
/**
|
||||
* Clear all listeners.
|
||||
*/
|
||||
void reset();
|
||||
}
|
||||
|
||||
@@ -6,4 +6,13 @@ public abstract class JadxEventType<T extends IJadxEvent> {
|
||||
return new JadxEventType<>() {
|
||||
};
|
||||
}
|
||||
|
||||
public static <E extends IJadxEvent> JadxEventType<E> create(String name) {
|
||||
return new JadxEventType<>() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,17 +16,17 @@ public class JadxEvents {
|
||||
/**
|
||||
* Notify about renaming done by user (GUI only).
|
||||
*/
|
||||
public static final JadxEventType<NodeRenamedByUser> NODE_RENAMED_BY_USER = create();
|
||||
public static final JadxEventType<NodeRenamedByUser> NODE_RENAMED_BY_USER = create("NODE_RENAMED_BY_USER");
|
||||
|
||||
/**
|
||||
* Request reload of a current project (GUI only).
|
||||
*/
|
||||
public static final JadxEventType<ReloadProject> RELOAD_PROJECT = create();
|
||||
public static final JadxEventType<ReloadProject> RELOAD_PROJECT = create("RELOAD_PROJECT");
|
||||
|
||||
/**
|
||||
* Request reload of a settings window (GUI only).
|
||||
* Useful for a reload custom settings group which was set with
|
||||
* {@link JadxGuiSettings#setCustomSettingsGroup(ISettingsGroup)}.
|
||||
*/
|
||||
public static final JadxEventType<ReloadSettingsWindow> RELOAD_SETTINGS_WINDOW = create();
|
||||
public static final JadxEventType<ReloadSettingsWindow> RELOAD_SETTINGS_WINDOW = create("RELOAD_SETTINGS_WINDOW");
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ public class Consts {
|
||||
public static final boolean DEBUG_FINALLY = false;
|
||||
public static final boolean DEBUG_ATTRIBUTES = false;
|
||||
public static final boolean DEBUG_RESTRUCTURE = false;
|
||||
public static final boolean DEBUG_EVENTS = true;
|
||||
public static final boolean DEBUG_EVENTS = Jadx.isDevVersion();
|
||||
|
||||
public static final String CLASS_OBJECT = "java.lang.Object";
|
||||
public static final String CLASS_STRING = "java.lang.String";
|
||||
|
||||
@@ -26,8 +26,20 @@ public class JadxEventsImpl implements IJadxEvents {
|
||||
@Override
|
||||
public <E extends IJadxEvent> void addListener(JadxEventType<E> eventType, Consumer<E> listener) {
|
||||
manager.addListener(eventType, listener);
|
||||
if (Consts.DEBUG_EVENTS) {
|
||||
LOG.debug("add listener for: {}, stats: {}", eventType, manager.listenersDebugStats());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <E extends IJadxEvent> void removeListener(JadxEventType<E> eventType, Consumer<E> listener) {
|
||||
manager.removeListener(eventType, listener);
|
||||
if (Consts.DEBUG_EVENTS) {
|
||||
LOG.debug("remove listener for: {}, stats: {}", eventType, manager.listenersDebugStats());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
manager.reset();
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -35,6 +36,14 @@ public class JadxEventsManager {
|
||||
.add((Consumer<IJadxEvent>) listener);
|
||||
}
|
||||
|
||||
public synchronized <E extends IJadxEvent> boolean removeListener(JadxEventType<E> eventType, Consumer<E> listener) {
|
||||
List<Consumer<IJadxEvent>> eventListeners = listeners.get(eventType);
|
||||
if (eventListeners != null) {
|
||||
return eventListeners.remove(listener);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public synchronized void send(IJadxEvent event) {
|
||||
List<Consumer<IJadxEvent>> consumers = listeners.get(event.getType());
|
||||
if (consumers != null) {
|
||||
@@ -58,4 +67,12 @@ public class JadxEventsManager {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public String listenersDebugStats() {
|
||||
return listeners.entrySet()
|
||||
.stream()
|
||||
.filter(p -> !p.getValue().isEmpty())
|
||||
.map(p -> p.getKey() + ":" + p.getValue().size())
|
||||
.collect(Collectors.joining(", ", "[", "]"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user