■ ■ ■ ■ ■ ■
jadx-core/src/main/java/jadx/api/JadxDecompiler.java
| skipped 23 lines |
24 | 24 | | import org.slf4j.Logger; |
25 | 25 | | import org.slf4j.LoggerFactory; |
26 | 26 | | |
27 | | - | import jadx.api.impl.plugins.SimplePluginContext; |
| 27 | + | import jadx.api.impl.plugins.PluginsContext; |
28 | 28 | | import jadx.api.metadata.ICodeAnnotation; |
29 | 29 | | import jadx.api.metadata.ICodeNodeRef; |
30 | 30 | | import jadx.api.metadata.annotations.NodeDeclareRef; |
| skipped 1 lines |
32 | 32 | | import jadx.api.metadata.annotations.VarRef; |
33 | 33 | | import jadx.api.plugins.JadxPlugin; |
34 | 34 | | import jadx.api.plugins.JadxPluginManager; |
35 | | - | import jadx.api.plugins.gui.JadxGuiContext; |
36 | | - | import jadx.api.plugins.input.JadxInputPlugin; |
37 | | - | import jadx.api.plugins.input.data.ILoadResult; |
38 | | - | import jadx.api.plugins.options.JadxPluginOptions; |
| 35 | + | import jadx.api.plugins.input.ICodeLoader; |
| 36 | + | import jadx.api.plugins.input.JadxCodeInput; |
39 | 37 | | import jadx.api.plugins.pass.JadxPass; |
40 | 38 | | import jadx.api.plugins.pass.types.JadxAfterLoadPass; |
41 | 39 | | import jadx.api.plugins.pass.types.JadxPassType; |
| skipped 47 lines |
89 | 87 | | |
90 | 88 | | private final JadxArgs args; |
91 | 89 | | private final JadxPluginManager pluginManager = new JadxPluginManager(); |
92 | | - | private final List<ILoadResult> loadedInputs = new ArrayList<>(); |
| 90 | + | private final List<ICodeLoader> loadedInputs = new ArrayList<>(); |
93 | 91 | | |
94 | 92 | | private RootNode root; |
95 | 93 | | private List<JavaClass> classes; |
| skipped 9 lines |
105 | 103 | | |
106 | 104 | | private final IDecompileScheduler decompileScheduler = new DecompilerScheduler(); |
107 | 105 | | |
108 | | - | private final List<ILoadResult> customLoads = new ArrayList<>(); |
| 106 | + | private final PluginsContext pluginsContext = new PluginsContext(this); |
| 107 | + | private final List<ICodeLoader> customCodeLoaders = new ArrayList<>(); |
109 | 108 | | private final Map<JadxPassType, List<JadxPass>> customPasses = new HashMap<>(); |
110 | | - | private @Nullable JadxGuiContext guiContext; |
111 | 109 | | |
112 | 110 | | public JadxDecompiler() { |
113 | 111 | | this(new JadxArgs()); |
| skipped 27 lines |
141 | 139 | | List<Path> inputPaths = Utils.collectionMap(args.getInputFiles(), File::toPath); |
142 | 140 | | List<Path> inputFiles = FileUtils.expandDirs(inputPaths); |
143 | 141 | | long start = System.currentTimeMillis(); |
144 | | - | for (JadxInputPlugin inputPlugin : pluginManager.getInputPlugins()) { |
145 | | - | ILoadResult loadResult = inputPlugin.loadFiles(inputFiles); |
146 | | - | if (loadResult != null && !loadResult.isEmpty()) { |
147 | | - | loadedInputs.add(loadResult); |
| 142 | + | for (JadxCodeInput codeLoader : pluginsContext.getCodeInputs()) { |
| 143 | + | ICodeLoader loader = codeLoader.loadFiles(inputFiles); |
| 144 | + | if (loader != null && !loader.isEmpty()) { |
| 145 | + | loadedInputs.add(loader); |
148 | 146 | | } |
149 | 147 | | } |
150 | | - | loadedInputs.addAll(customLoads); |
| 148 | + | loadedInputs.addAll(customCodeLoaders); |
151 | 149 | | if (LOG.isDebugEnabled()) { |
152 | 150 | | LOG.debug("Loaded using {} inputs plugin in {} ms", loadedInputs.size(), System.currentTimeMillis() - start); |
153 | 151 | | } |
| skipped 36 lines |
190 | 188 | | LOG.debug("Resolved plugins: {}", Utils.collectionMap(pluginManager.getResolvedPlugins(), |
191 | 189 | | p -> p.getPluginInfo().getPluginId())); |
192 | 190 | | } |
193 | | - | applyPluginOptions(); |
194 | | - | initPlugins(); |
195 | | - | } |
196 | | - | |
197 | | - | private void applyPluginOptions() { |
198 | | - | Map<String, String> pluginOptions = args.getPluginOptions(); |
199 | | - | if (!pluginOptions.isEmpty()) { |
200 | | - | LOG.debug("Applying plugin options: {}", pluginOptions); |
201 | | - | for (JadxPluginOptions plugin : pluginManager.getPluginsWithOptions()) { |
202 | | - | try { |
203 | | - | plugin.setOptions(pluginOptions); |
204 | | - | } catch (Exception e) { |
205 | | - | String pluginId = plugin.getPluginInfo().getPluginId(); |
206 | | - | throw new JadxRuntimeException("Failed to apply options for plugin: " + pluginId, e); |
207 | | - | } |
208 | | - | } |
209 | | - | } |
210 | | - | } |
211 | | - | |
212 | | - | private void initPlugins() { |
213 | | - | customPasses.clear(); |
214 | | - | |
215 | | - | List<JadxPlugin> plugins = pluginManager.getResolvedPlugins(); |
216 | | - | SimplePluginContext context = new SimplePluginContext(this); |
217 | | - | context.setGuiContext(guiContext); |
218 | | - | for (JadxPlugin passPlugin : plugins) { |
219 | | - | try { |
220 | | - | passPlugin.init(context); |
221 | | - | } catch (Exception e) { |
222 | | - | String pluginId = passPlugin.getPluginInfo().getPluginId(); |
223 | | - | throw new JadxRuntimeException("Failed to pass plugin: " + pluginId, e); |
224 | | - | } |
225 | | - | } |
| 191 | + | pluginManager.initResolved(pluginsContext); |
226 | 192 | | if (LOG.isDebugEnabled()) { |
227 | 193 | | List<String> passes = customPasses.values().stream().flatMap(Collection::stream) |
228 | 194 | | .map(p -> p.getInfo().getName()).collect(Collectors.toList()); |
| skipped 455 lines |
684 | 650 | | return decompileScheduler; |
685 | 651 | | } |
686 | 652 | | |
687 | | - | public void addCustomLoad(ILoadResult customLoad) { |
688 | | - | customLoads.add(customLoad); |
| 653 | + | public void addCustomCodeLoader(ICodeLoader customCodeLoader) { |
| 654 | + | customCodeLoaders.add(customCodeLoader); |
689 | 655 | | } |
690 | 656 | | |
691 | | - | public List<ILoadResult> getCustomLoads() { |
692 | | - | return customLoads; |
| 657 | + | public List<ICodeLoader> getCustomCodeLoaders() { |
| 658 | + | return customCodeLoaders; |
693 | 659 | | } |
694 | 660 | | |
695 | 661 | | public void addCustomPass(JadxPass pass) { |
696 | 662 | | customPasses.computeIfAbsent(pass.getPassType(), l -> new ArrayList<>()).add(pass); |
697 | 663 | | } |
698 | 664 | | |
699 | | - | public void setJadxGuiContext(JadxGuiContext guiContext) { |
700 | | - | this.guiContext = guiContext; |
| 665 | + | public PluginsContext getPluginsContext() { |
| 666 | + | return pluginsContext; |
701 | 667 | | } |
702 | 668 | | |
703 | 669 | | @Override |
| skipped 5 lines |