Refactoring: extract interface for JadxArgs
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package jadx;
|
||||
|
||||
import jadx.utils.files.InputFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public interface IJadxArgs {
|
||||
File getOutDir();
|
||||
|
||||
int getThreadsCount();
|
||||
|
||||
boolean isCFGOutput();
|
||||
|
||||
boolean isRawCFGOutput();
|
||||
|
||||
List<InputFile> getInput();
|
||||
|
||||
boolean isFallbackMode();
|
||||
|
||||
boolean isNotObfuscated();
|
||||
|
||||
boolean isVerbose();
|
||||
|
||||
boolean isPrintHelp();
|
||||
}
|
||||
@@ -32,7 +32,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class Jadx {
|
||||
public class Jadx implements Runnable {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Jadx.class);
|
||||
|
||||
static {
|
||||
@@ -42,8 +42,14 @@ public class Jadx {
|
||||
LOG.info("assertions enabled");
|
||||
}
|
||||
|
||||
public static int run(JadxArgs args) {
|
||||
int errorCount;
|
||||
private final IJadxArgs args;
|
||||
private int errorsCount;
|
||||
|
||||
public Jadx(IJadxArgs args) {
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
RootNode root = new RootNode(args);
|
||||
LOG.info("loading ...");
|
||||
@@ -72,8 +78,8 @@ public class Jadx {
|
||||
} catch (Throwable e) {
|
||||
LOG.error("jadx error:", e);
|
||||
} finally {
|
||||
errorCount = ErrorsCounter.getErrorCount();
|
||||
if (errorCount != 0)
|
||||
errorsCount = ErrorsCounter.getErrorCount();
|
||||
if (errorsCount != 0)
|
||||
ErrorsCounter.printReport();
|
||||
|
||||
// clear resources if we use jadx as a library
|
||||
@@ -81,10 +87,9 @@ public class Jadx {
|
||||
ErrorsCounter.reset();
|
||||
}
|
||||
LOG.info("done");
|
||||
return errorCount;
|
||||
}
|
||||
|
||||
private static List<IDexTreeVisitor> getPassesList(JadxArgs args) {
|
||||
private static List<IDexTreeVisitor> getPassesList(IJadxArgs args) {
|
||||
List<IDexTreeVisitor> passes = new ArrayList<IDexTreeVisitor>();
|
||||
if (args.isFallbackMode()) {
|
||||
passes.add(new FallbackModeVisitor());
|
||||
@@ -120,4 +125,8 @@ public class Jadx {
|
||||
passes.add(new CodeGen(args));
|
||||
return passes;
|
||||
}
|
||||
|
||||
public int getErrorsCount() {
|
||||
return errorsCount;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,34 +18,34 @@ import com.beust.jcommander.Parameter;
|
||||
import com.beust.jcommander.ParameterDescription;
|
||||
import com.beust.jcommander.ParameterException;
|
||||
|
||||
public class JadxArgs {
|
||||
public class JadxArgs implements IJadxArgs {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(JadxArgs.class);
|
||||
|
||||
@Parameter(description = "<input files> (.dex, .apk, .jar or .class)", required = true)
|
||||
protected List<String> files;
|
||||
|
||||
@Parameter(names = { "-d", "--output-dir" }, description = "output directory")
|
||||
@Parameter(names = {"-d", "--output-dir"}, description = "output directory")
|
||||
protected String outDirName;
|
||||
|
||||
@Parameter(names = { "-j", "--threads-count" }, description = "processing threads count")
|
||||
@Parameter(names = {"-j", "--threads-count"}, description = "processing threads count")
|
||||
protected int threadsCount = Runtime.getRuntime().availableProcessors();
|
||||
|
||||
@Parameter(names = { "-f", "--fallback" }, description = "make simple dump (using goto instead of 'if', 'for', etc)", help = true)
|
||||
@Parameter(names = {"-f", "--fallback"}, description = "make simple dump (using goto instead of 'if', 'for', etc)", help = true)
|
||||
protected boolean fallbackMode = false;
|
||||
|
||||
@Parameter(names = { "--not-obfuscated" }, description = "set this flag if code not obfuscated")
|
||||
@Parameter(names = {"--not-obfuscated"}, description = "set this flag if code not obfuscated")
|
||||
protected boolean notObfuscated = false;
|
||||
|
||||
@Parameter(names = { "--cfg" }, description = "save methods control flow graph")
|
||||
@Parameter(names = {"--cfg"}, description = "save methods control flow graph")
|
||||
protected boolean cfgOutput = false;
|
||||
|
||||
@Parameter(names = { "--raw-cfg" }, description = "save methods control flow graph (use raw instructions)")
|
||||
@Parameter(names = {"--raw-cfg"}, description = "save methods control flow graph (use raw instructions)")
|
||||
protected boolean rawCfgOutput = false;
|
||||
|
||||
@Parameter(names = { "-v", "--verbose" }, description = "verbose output")
|
||||
@Parameter(names = {"-v", "--verbose"}, description = "verbose output")
|
||||
protected boolean verbose = false;
|
||||
|
||||
@Parameter(names = { "-h", "--help" }, description = "print this help", help = true)
|
||||
@Parameter(names = {"-h", "--help"}, description = "print this help", help = true)
|
||||
protected boolean printHelp = false;
|
||||
|
||||
private final List<InputFile> input = new ArrayList<InputFile>();
|
||||
@@ -147,38 +147,47 @@ public class JadxArgs {
|
||||
str.append(' ');
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getOutDir() {
|
||||
return outputDir;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getThreadsCount() {
|
||||
return threadsCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCFGOutput() {
|
||||
return cfgOutput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRawCFGOutput() {
|
||||
return rawCfgOutput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<InputFile> getInput() {
|
||||
return input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFallbackMode() {
|
||||
return fallbackMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNotObfuscated() {
|
||||
return notObfuscated;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVerbose() {
|
||||
return verbose;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPrintHelp() {
|
||||
return printHelp;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package jadx;
|
||||
|
||||
import jadx.utils.exceptions.JadxException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -29,7 +28,8 @@ public class Main {
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
int result = Jadx.run(jadxArgs);
|
||||
System.exit(result);
|
||||
Jadx jadx = new Jadx(jadxArgs);
|
||||
jadx.run();
|
||||
System.exit(jadx.getErrorsCount());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package jadx.codegen;
|
||||
|
||||
import jadx.JadxArgs;
|
||||
import jadx.IJadxArgs;
|
||||
import jadx.dex.nodes.ClassNode;
|
||||
import jadx.dex.visitors.AbstractVisitor;
|
||||
import jadx.utils.exceptions.CodegenException;
|
||||
@@ -10,9 +10,9 @@ import java.io.File;
|
||||
public class CodeGen extends AbstractVisitor {
|
||||
|
||||
private final File dir;
|
||||
private final JadxArgs args;
|
||||
private final IJadxArgs args;
|
||||
|
||||
public CodeGen(JadxArgs args) {
|
||||
public CodeGen(IJadxArgs args) {
|
||||
this.args = args;
|
||||
this.dir = args.getOutDir();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package jadx.dex.nodes;
|
||||
|
||||
import jadx.JadxArgs;
|
||||
import jadx.IJadxArgs;
|
||||
import jadx.dex.info.ClassInfo;
|
||||
import jadx.utils.exceptions.DecodeException;
|
||||
import jadx.utils.files.InputFile;
|
||||
@@ -16,18 +16,18 @@ import org.slf4j.LoggerFactory;
|
||||
public class RootNode {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RootNode.class);
|
||||
|
||||
private final JadxArgs jadxArgs;
|
||||
private final IJadxArgs IJadxArgs;
|
||||
|
||||
private List<DexNode> dexNodes;
|
||||
private final List<ClassNode> classes = new ArrayList<ClassNode>();
|
||||
private final Map<String, ClassNode> names = new HashMap<String, ClassNode>();
|
||||
|
||||
public RootNode(JadxArgs args) {
|
||||
this.jadxArgs = args;
|
||||
public RootNode(IJadxArgs args) {
|
||||
this.IJadxArgs = args;
|
||||
}
|
||||
|
||||
public void load() throws DecodeException {
|
||||
List<InputFile> dexFiles = jadxArgs.getInput();
|
||||
List<InputFile> dexFiles = IJadxArgs.getInput();
|
||||
dexNodes = new ArrayList<DexNode>(dexFiles.size());
|
||||
for (InputFile dex : dexFiles) {
|
||||
DexNode dexNode;
|
||||
@@ -86,7 +86,7 @@ public class RootNode {
|
||||
return dexNodes;
|
||||
}
|
||||
|
||||
public JadxArgs getJadxArgs() {
|
||||
return jadxArgs;
|
||||
public IJadxArgs getJadxArgs() {
|
||||
return IJadxArgs;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user