Search in sources :

Example 1 with JadxPluginOptions

use of jadx.api.plugins.options.JadxPluginOptions in project jadx by skylot.

the class JadxDecompiler method loadPlugins.

private void loadPlugins(JadxArgs args) {
    pluginManager.providesSuggestion("java-input", args.isUseDxInput() ? "java-convert" : "java-input");
    pluginManager.load();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Resolved plugins: {}", Utils.collectionMap(pluginManager.getResolvedPlugins(), p -> p.getPluginInfo().getPluginId()));
    }
    Map<String, String> pluginOptions = args.getPluginOptions();
    if (!pluginOptions.isEmpty()) {
        LOG.debug("Applying plugin options: {}", pluginOptions);
        for (JadxPluginOptions plugin : pluginManager.getPluginsWithOptions()) {
            try {
                plugin.setOptions(pluginOptions);
            } catch (Exception e) {
                String pluginId = plugin.getPluginInfo().getPluginId();
                throw new JadxRuntimeException("Failed to apply options for plugin: " + pluginId, e);
            }
        }
    }
}
Also used : JadxInputPlugin(jadx.api.plugins.input.JadxInputPlugin) JadxPluginManager(jadx.api.plugins.JadxPluginManager) MethodNode(jadx.core.dex.nodes.MethodNode) AFlag(jadx.core.dex.attributes.AFlag) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) LoggerFactory(org.slf4j.LoggerFactory) RootNode(jadx.core.dex.nodes.RootNode) HashMap(java.util.HashMap) VarRef(jadx.api.data.annotations.VarRef) ArrayList(java.util.ArrayList) ExportGradleProject(jadx.core.export.ExportGradleProject) ClassNode(jadx.core.dex.nodes.ClassNode) Map(java.util.Map) JadxPluginOptions(jadx.api.plugins.options.JadxPluginOptions) FieldNode(jadx.core.dex.nodes.FieldNode) DecompilerScheduler(jadx.core.utils.DecompilerScheduler) Path(java.nio.file.Path) Jadx(jadx.core.Jadx) FileUtils(jadx.core.utils.files.FileUtils) ExecutorService(java.util.concurrent.ExecutorService) ApiStatus(org.jetbrains.annotations.ApiStatus) Logger(org.slf4j.Logger) LineAttrNode(jadx.core.dex.attributes.nodes.LineAttrNode) Predicate(java.util.function.Predicate) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BinaryXMLParser(jadx.core.xmlgen.BinaryXMLParser) Set(java.util.Set) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) ILoadResult(jadx.api.plugins.input.data.ILoadResult) ResContainer(jadx.core.xmlgen.ResContainer) Collectors(java.util.stream.Collectors) File(java.io.File) Executors(java.util.concurrent.Executors) SaveCode(jadx.core.dex.visitors.SaveCode) ProtoXMLParser(jadx.core.xmlgen.ProtoXMLParser) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) JadxPlugin(jadx.api.plugins.JadxPlugin) ResourcesSaver(jadx.core.xmlgen.ResourcesSaver) Closeable(java.io.Closeable) Comparator(java.util.Comparator) Collections(java.util.Collections) Utils(jadx.core.utils.Utils) JadxPluginOptions(jadx.api.plugins.options.JadxPluginOptions) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException)

Example 2 with JadxPluginOptions

use of jadx.api.plugins.options.JadxPluginOptions in project jadx by skylot.

the class JadxSettingsWindow method makePluginOptionsGroup.

private SettingsGroup makePluginOptionsGroup() {
    SettingsGroup pluginsGroup = new SettingsGroup(NLS.str("preferences.plugins"));
    JadxPluginManager pluginManager = mainWindow.getWrapper().getDecompiler().getPluginManager();
    for (JadxPlugin plugin : pluginManager.getAllPlugins()) {
        if (!(plugin instanceof JadxPluginOptions)) {
            continue;
        }
        JadxPluginInfo pluginInfo = plugin.getPluginInfo();
        JadxPluginOptions optPlugin = (JadxPluginOptions) plugin;
        for (OptionDescription opt : optPlugin.getOptionsDescriptions()) {
            String title = "[" + pluginInfo.getPluginId() + "]  " + opt.description();
            if (opt.values().isEmpty()) {
                JTextField textField = new JTextField();
                textField.getDocument().addDocumentListener(new DocumentUpdateListener(event -> {
                    settings.getPluginOptions().put(opt.name(), textField.getText());
                    needReload();
                }));
                pluginsGroup.addRow(title, textField);
            } else {
                String curValue = settings.getPluginOptions().get(opt.name());
                JComboBox<String> combo = new JComboBox<>(opt.values().toArray(new String[0]));
                combo.setSelectedItem(curValue != null ? curValue : opt.defaultValue());
                combo.addActionListener(e -> {
                    settings.getPluginOptions().put(opt.name(), ((String) combo.getSelectedItem()));
                    needReload();
                });
                pluginsGroup.addRow(title, combo);
            }
        }
    }
    return pluginsGroup;
}
Also used : JsonObject(com.google.gson.JsonObject) Arrays(java.util.Arrays) DocumentListener(javax.swing.event.DocumentListener) JDialog(javax.swing.JDialog) EditorTheme(jadx.gui.ui.codearea.EditorTheme) LafManager(jadx.gui.utils.LafManager) LoggerFactory(org.slf4j.LoggerFactory) GraphicsEnvironment(java.awt.GraphicsEnvironment) GsonBuilder(com.google.gson.GsonBuilder) CommentsLevel(jadx.api.CommentsLevel) MouseAdapter(java.awt.event.MouseAdapter) ChangeListener(javax.swing.event.ChangeListener) BorderLayout(java.awt.BorderLayout) JComboBox(javax.swing.JComboBox) OptionDescription(jadx.api.plugins.options.OptionDescription) Clipboard(java.awt.datatransfer.Clipboard) KeyStroke(javax.swing.KeyStroke) ScrollPaneConstants(javax.swing.ScrollPaneConstants) ChangeEvent(javax.swing.event.ChangeEvent) ItemEvent(java.awt.event.ItemEvent) Font(java.awt.Font) Collection(java.util.Collection) Set(java.util.Set) BorderFactory(javax.swing.BorderFactory) GridBagConstraints(java.awt.GridBagConstraints) Component(java.awt.Component) Box(javax.swing.Box) JFontChooser(say.swing.JFontChooser) Dimension(java.awt.Dimension) JadxArgs(jadx.api.JadxArgs) JadxPlugin(jadx.api.plugins.JadxPlugin) JadxPluginInfo(jadx.api.plugins.JadxPluginInfo) AbstractAction(javax.swing.AbstractAction) JCheckBox(javax.swing.JCheckBox) DocumentUpdateListener(jadx.gui.utils.ui.DocumentUpdateListener) GridBagLayout(java.awt.GridBagLayout) MainWindow(jadx.gui.ui.MainWindow) JPanel(javax.swing.JPanel) WindowConstants(javax.swing.WindowConstants) Toolkit(java.awt.Toolkit) Insets(java.awt.Insets) JadxPluginManager(jadx.api.plugins.JadxPluginManager) JTextField(javax.swing.JTextField) SpinnerNumberModel(javax.swing.SpinnerNumberModel) NLS(jadx.gui.utils.NLS) SwingConstants(javax.swing.SwingConstants) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SwingUtilities(javax.swing.SwingUtilities) UiUtils(jadx.gui.utils.UiUtils) JadxPluginOptions(jadx.api.plugins.options.JadxPluginOptions) StringSelection(java.awt.datatransfer.StringSelection) Container(java.awt.Container) DocumentEvent(javax.swing.event.DocumentEvent) BoxLayout(javax.swing.BoxLayout) JComponent(javax.swing.JComponent) JButton(javax.swing.JButton) JSpinner(javax.swing.JSpinner) Logger(org.slf4j.Logger) JOptionPane(javax.swing.JOptionPane) ActionEvent(java.awt.event.ActionEvent) MouseEvent(java.awt.event.MouseEvent) JScrollPane(javax.swing.JScrollPane) DeobfuscationMapFileMode(jadx.api.args.DeobfuscationMapFileMode) LangLocale(jadx.gui.utils.LangLocale) JLabel(javax.swing.JLabel) UseKotlinMethodsForVarNames(jadx.api.JadxArgs.UseKotlinMethodsForVarNames) InputMap(javax.swing.InputMap) Collections(java.util.Collections) FontUtils(jadx.gui.utils.FontUtils) DocumentUpdateListener(jadx.gui.utils.ui.DocumentUpdateListener) JadxPluginOptions(jadx.api.plugins.options.JadxPluginOptions) OptionDescription(jadx.api.plugins.options.OptionDescription) JComboBox(javax.swing.JComboBox) JadxPlugin(jadx.api.plugins.JadxPlugin) JadxPluginInfo(jadx.api.plugins.JadxPluginInfo) JadxPluginManager(jadx.api.plugins.JadxPluginManager) JTextField(javax.swing.JTextField)

Example 3 with JadxPluginOptions

use of jadx.api.plugins.options.JadxPluginOptions in project jadx by skylot.

the class JCommanderWrapper method appendPluginOptions.

private String appendPluginOptions(int maxNamesLen) {
    StringBuilder sb = new StringBuilder();
    JadxPluginManager pluginManager = new JadxPluginManager();
    pluginManager.load();
    int k = 1;
    for (JadxPlugin plugin : pluginManager.getAllPlugins()) {
        if (plugin instanceof JadxPluginOptions) {
            if (appendPlugin(((JadxPluginOptions) plugin), sb, maxNamesLen, k)) {
                k++;
            }
        }
    }
    if (sb.length() == 0) {
        return "";
    }
    return "\nPlugin options (-P<name>=<value>):" + sb;
}
Also used : JadxPluginOptions(jadx.api.plugins.options.JadxPluginOptions) JadxPlugin(jadx.api.plugins.JadxPlugin) JadxPluginManager(jadx.api.plugins.JadxPluginManager)

Aggregations

JadxPlugin (jadx.api.plugins.JadxPlugin)3 JadxPluginManager (jadx.api.plugins.JadxPluginManager)3 JadxPluginOptions (jadx.api.plugins.options.JadxPluginOptions)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 GsonBuilder (com.google.gson.GsonBuilder)1 JsonObject (com.google.gson.JsonObject)1 CommentsLevel (jadx.api.CommentsLevel)1 JadxArgs (jadx.api.JadxArgs)1 UseKotlinMethodsForVarNames (jadx.api.JadxArgs.UseKotlinMethodsForVarNames)1 DeobfuscationMapFileMode (jadx.api.args.DeobfuscationMapFileMode)1 VarRef (jadx.api.data.annotations.VarRef)1 JadxPluginInfo (jadx.api.plugins.JadxPluginInfo)1 JadxInputPlugin (jadx.api.plugins.input.JadxInputPlugin)1 ILoadResult (jadx.api.plugins.input.data.ILoadResult)1 OptionDescription (jadx.api.plugins.options.OptionDescription)1 Jadx (jadx.core.Jadx)1 AFlag (jadx.core.dex.attributes.AFlag)1 LineAttrNode (jadx.core.dex.attributes.nodes.LineAttrNode)1