core: change jadx args api for easier processing and validation
This commit is contained in:
@@ -5,7 +5,6 @@ import javax.swing.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jadx.core.utils.exceptions.JadxException;
|
||||
import jadx.gui.settings.JadxSettings;
|
||||
import jadx.gui.settings.JadxSettingsAdapter;
|
||||
import jadx.gui.ui.MainWindow;
|
||||
@@ -17,24 +16,17 @@ public class JadxGUI {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
LogCollector.register();
|
||||
final JadxSettings jadxArgs = JadxSettingsAdapter.load();
|
||||
final JadxSettings settings = JadxSettingsAdapter.load();
|
||||
// overwrite loaded settings by command line arguments
|
||||
if (!jadxArgs.processArgs(args)) {
|
||||
if (!settings.processArgs(args)) {
|
||||
return;
|
||||
}
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
MainWindow window = new MainWindow(jadxArgs);
|
||||
window.open();
|
||||
}
|
||||
catch(JadxException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
MainWindow window = new MainWindow(settings);
|
||||
window.open();
|
||||
});
|
||||
} catch (Throwable e) {
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error: {}", e.getMessage(), e);
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
@@ -2,38 +2,38 @@ package jadx.gui;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jadx.api.IJadxArgs;
|
||||
import jadx.api.JadxDecompiler;
|
||||
import jadx.api.JavaClass;
|
||||
import jadx.api.JavaPackage;
|
||||
import jadx.api.ResourceFile;
|
||||
import jadx.core.utils.exceptions.DecodeException;
|
||||
import jadx.core.utils.exceptions.JadxException;
|
||||
import jadx.gui.settings.JadxSettings;
|
||||
|
||||
public class JadxWrapper {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(JadxWrapper.class);
|
||||
|
||||
private final JadxDecompiler decompiler;
|
||||
private final JadxSettings settings;
|
||||
private JadxDecompiler decompiler;
|
||||
private File openFile;
|
||||
|
||||
public JadxWrapper(IJadxArgs jadxArgs) throws JadxException {
|
||||
this.decompiler = new JadxDecompiler(jadxArgs);
|
||||
public JadxWrapper(JadxSettings settings) {
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
public void openFile(File file) {
|
||||
this.openFile = file;
|
||||
try {
|
||||
this.decompiler.loadFile(file);
|
||||
} catch (DecodeException e) {
|
||||
LOG.error("Error decode file: {}", file, e);
|
||||
} catch (JadxException e) {
|
||||
LOG.error("Error open file: {}", file, e);
|
||||
this.decompiler = new JadxDecompiler(settings.toJadxArgs());
|
||||
this.decompiler.getArgs().setInputFiles(Collections.singletonList(file));
|
||||
this.decompiler.load();
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error load file: {}", file, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class JadxWrapper {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
decompiler.setOutputDir(dir);
|
||||
decompiler.getArgs().setRootDir(dir);
|
||||
ThreadPoolExecutor ex = (ThreadPoolExecutor) decompiler.getSaveExecutor();
|
||||
ex.shutdown();
|
||||
while (ex.isTerminating()) {
|
||||
@@ -53,7 +53,7 @@ public class JadxWrapper {
|
||||
}
|
||||
progressMonitor.close();
|
||||
LOG.info("done");
|
||||
} catch (InterruptedException|JadxException e) {
|
||||
} catch (InterruptedException e) {
|
||||
LOG.error("Save interrupted", e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import java.util.Set;
|
||||
|
||||
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
|
||||
|
||||
import jadx.api.JadxArgs;
|
||||
import jadx.cli.JadxCLIArgs;
|
||||
|
||||
public class JadxSettings extends JadxCLIArgs {
|
||||
@@ -44,7 +45,7 @@ public class JadxSettings extends JadxCLIArgs {
|
||||
|
||||
public void fixOnLoad() {
|
||||
if (threadsCount <= 0) {
|
||||
threadsCount = DEFAULT_THREADS_COUNT;
|
||||
threadsCount = JadxArgs.DEFAULT_THREADS_COUNT;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,8 +166,8 @@ public class JadxSettings extends JadxCLIArgs {
|
||||
this.deobfuscationForceSave = deobfuscationForceSave;
|
||||
}
|
||||
|
||||
public void setUseSourceNameAsClassAlias(boolean useSourceNameAsAlias) {
|
||||
this.deobfuscationUseSourceNameAsAlias = useSourceNameAsAlias;
|
||||
public void setDeobfuscationUseSourceNameAsAlias(boolean deobfuscationUseSourceNameAsAlias) {
|
||||
this.deobfuscationUseSourceNameAsAlias = deobfuscationUseSourceNameAsAlias;
|
||||
}
|
||||
|
||||
public void setEscapeUnicode(boolean escapeUnicode) {
|
||||
|
||||
@@ -145,10 +145,10 @@ public class JadxSettingsWindow extends JDialog {
|
||||
});
|
||||
|
||||
JCheckBox deobfSourceAlias = new JCheckBox();
|
||||
deobfSourceAlias.setSelected(settings.useSourceNameAsClassAlias());
|
||||
deobfSourceAlias.setSelected(settings.isDeobfuscationUseSourceNameAsAlias());
|
||||
deobfSourceAlias.addItemListener(new ItemListener() {
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
settings.setUseSourceNameAsClassAlias(e.getStateChange() == ItemEvent.SELECTED);
|
||||
settings.setDeobfuscationUseSourceNameAsAlias(e.getStateChange() == ItemEvent.SELECTED);
|
||||
needReload();
|
||||
}
|
||||
});
|
||||
@@ -219,6 +219,7 @@ public class JadxSettingsWindow extends JDialog {
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
settings.setThreadsCount((Integer) threadsCount.getValue());
|
||||
needReload();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -27,12 +27,13 @@ import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jadx.api.ResourceFile;
|
||||
import jadx.core.utils.exceptions.JadxException;
|
||||
import jadx.gui.JadxWrapper;
|
||||
import jadx.gui.jobs.BackgroundWorker;
|
||||
import jadx.gui.jobs.DecompileJob;
|
||||
@@ -101,7 +102,7 @@ public class MainWindow extends JFrame {
|
||||
private transient ProgressPanel progressPane;
|
||||
private transient BackgroundWorker backgroundWorker;
|
||||
|
||||
public MainWindow(JadxSettings settings) throws JadxException {
|
||||
public MainWindow(JadxSettings settings) {
|
||||
this.wrapper = new JadxWrapper(settings);
|
||||
this.settings = settings;
|
||||
this.cacheObject = new CacheObject();
|
||||
@@ -119,10 +120,10 @@ public class MainWindow extends JFrame {
|
||||
setLocationRelativeTo(null);
|
||||
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||
|
||||
if (settings.getInput().isEmpty()) {
|
||||
if (settings.getFiles().isEmpty()) {
|
||||
openFile();
|
||||
} else {
|
||||
openFile(settings.getInput().get(0));
|
||||
openFile(new File(settings.getFiles().get(0)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -689,5 +690,4 @@ public class MainWindow extends JFrame {
|
||||
public void menuCanceled(MenuEvent e) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user