-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugins): add API for search/use other plugins
- Loading branch information
Showing
14 changed files
with
248 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
jadx-core/src/main/java/jadx/api/plugins/data/IJadxPlugins.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package jadx.api.plugins.data; | ||
|
||
import jadx.api.plugins.JadxPlugin; | ||
|
||
public interface IJadxPlugins { | ||
|
||
JadxPluginRuntimeData getById(String pluginId); | ||
|
||
JadxPluginRuntimeData getProviding(String provideId); | ||
|
||
<P extends JadxPlugin> P getInstance(Class<P> pluginCls); | ||
} |
38 changes: 38 additions & 0 deletions
38
jadx-core/src/main/java/jadx/api/plugins/data/JadxPluginRuntimeData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package jadx.api.plugins.data; | ||
|
||
import java.io.Closeable; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import jadx.api.plugins.JadxPlugin; | ||
import jadx.api.plugins.JadxPluginInfo; | ||
import jadx.api.plugins.input.ICodeLoader; | ||
import jadx.api.plugins.input.JadxCodeInput; | ||
import jadx.api.plugins.options.JadxPluginOptions; | ||
|
||
/** | ||
* Runtime plugin data. | ||
*/ | ||
public interface JadxPluginRuntimeData { | ||
boolean isInitialized(); | ||
|
||
String getPluginId(); | ||
|
||
JadxPlugin getPluginInstance(); | ||
|
||
JadxPluginInfo getPluginInfo(); | ||
|
||
List<JadxCodeInput> getCodeInputs(); | ||
|
||
@Nullable | ||
JadxPluginOptions getOptions(); | ||
|
||
String getInputsHash(); | ||
|
||
/** | ||
* Convenient method to simplify code loading from custom files. | ||
*/ | ||
ICodeLoader loadCodeFiles(List<Path> files, @Nullable Closeable closeable); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
jadx-core/src/main/java/jadx/core/plugins/JadxPluginsData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package jadx.core.plugins; | ||
|
||
import jadx.api.JadxDecompiler; | ||
import jadx.api.plugins.JadxPlugin; | ||
import jadx.api.plugins.data.IJadxPlugins; | ||
import jadx.api.plugins.data.JadxPluginRuntimeData; | ||
import jadx.core.utils.exceptions.JadxRuntimeException; | ||
|
||
public class JadxPluginsData implements IJadxPlugins { | ||
|
||
private final JadxDecompiler decompiler; | ||
private final JadxPluginManager pluginManager; | ||
|
||
public JadxPluginsData(JadxDecompiler decompiler, JadxPluginManager pluginManager) { | ||
this.decompiler = decompiler; | ||
this.pluginManager = pluginManager; | ||
} | ||
|
||
@Override | ||
public JadxPluginRuntimeData getById(String pluginId) { | ||
return pluginManager.getResolvedPluginContexts() | ||
.stream() | ||
.filter(p -> p.getPluginId().equals(pluginId)) | ||
.findFirst() | ||
.orElseThrow(() -> new JadxRuntimeException("Plugin with id '" + pluginId + "' not found")); | ||
} | ||
|
||
@Override | ||
public JadxPluginRuntimeData getProviding(String provideId) { | ||
return pluginManager.getResolvedPluginContexts() | ||
.stream() | ||
.filter(p -> p.getPluginInfo().getProvides().equals(provideId)) | ||
.findFirst() | ||
.orElseThrow(() -> new JadxRuntimeException("Plugin providing '" + provideId + "' not found")); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public <P extends JadxPlugin> P getInstance(Class<P> pluginCls) { | ||
return pluginManager.getResolvedPluginContexts() | ||
.stream() | ||
.filter(p -> p.getPluginInstance().getClass().equals(pluginCls)) | ||
.map(p -> ((P) p.getPluginInstance())) | ||
.findFirst() | ||
.orElseThrow(() -> new JadxRuntimeException("Plugin class '" + pluginCls + "' not found")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...lugins/jadx-input-api/src/main/java/jadx/api/plugins/input/data/impl/MergeCodeLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package jadx.api.plugins.input.data.impl; | ||
|
||
import java.io.Closeable; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import jadx.api.plugins.input.ICodeLoader; | ||
import jadx.api.plugins.input.data.IClassData; | ||
|
||
public class MergeCodeLoader implements ICodeLoader { | ||
|
||
private final List<ICodeLoader> codeLoaders; | ||
private final @Nullable Closeable closeable; | ||
|
||
public MergeCodeLoader(List<ICodeLoader> codeLoaders) { | ||
this(codeLoaders, null); | ||
} | ||
|
||
public MergeCodeLoader(List<ICodeLoader> codeLoaders, @Nullable Closeable closeable) { | ||
this.codeLoaders = codeLoaders; | ||
this.closeable = closeable; | ||
} | ||
|
||
@Override | ||
public void visitClasses(Consumer<IClassData> consumer) { | ||
for (ICodeLoader codeLoader : codeLoaders) { | ||
codeLoader.visitClasses(consumer); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isEmpty() { | ||
for (ICodeLoader codeLoader : codeLoaders) { | ||
if (!codeLoader.isEmpty()) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
for (ICodeLoader codeLoader : codeLoaders) { | ||
codeLoader.close(); | ||
} | ||
if (closeable != null) { | ||
closeable.close(); | ||
} | ||
} | ||
} |
Oops, something went wrong.