Commit cc2ae80e authored by unknown's avatar unknown

Issue #204

parent b921f609
...@@ -32,6 +32,12 @@ public class JadxCLIArgs implements IJadxArgs { ...@@ -32,6 +32,12 @@ public class JadxCLIArgs implements IJadxArgs {
@Parameter(names = {"-d", "--output-dir"}, description = "output directory") @Parameter(names = {"-d", "--output-dir"}, description = "output directory")
protected String outDirName; protected String outDirName;
@Parameter(names = {"-ds", "--output-dir-src"}, description = "output directory for sources")
protected String outDirNameSrc;
@Parameter(names = {"-dr", "--output-dir-res"}, description = "output directory for resources")
protected String outDirNameRes;
@Parameter(names = {"-j", "--threads-count"}, description = "processing threads count") @Parameter(names = {"-j", "--threads-count"}, description = "processing threads count")
protected int threadsCount = DEFAULT_THREADS_COUNT; protected int threadsCount = DEFAULT_THREADS_COUNT;
...@@ -90,6 +96,8 @@ public class JadxCLIArgs implements IJadxArgs { ...@@ -90,6 +96,8 @@ public class JadxCLIArgs implements IJadxArgs {
private final List<File> input = new ArrayList<>(1); private final List<File> input = new ArrayList<>(1);
private File outputDir; private File outputDir;
private File outputDirSrc;
private File outputDirRes;
public boolean processArgs(String[] args) { public boolean processArgs(String[] args) {
return parse(args) && process(); return parse(args) && process();
...@@ -128,9 +136,22 @@ public class JadxCLIArgs implements IJadxArgs { ...@@ -128,9 +136,22 @@ public class JadxCLIArgs implements IJadxArgs {
if (input.size() > 1) { if (input.size() > 1) {
throw new JadxException("Only one input file is supported"); throw new JadxException("Only one input file is supported");
} }
if(outDirNameSrc != null) {
outputDirSrc = new File(outDirNameSrc);
}
if(outDirNameRes != null) {
outputDirRes = new File(outDirNameRes);
}
if (outDirName != null) { if (outDirName != null) {
outputDir = new File(outDirName); outputDir = new File(outDirName);
if(outputDirSrc == null) {
outputDirSrc = new File(outputDir, "source");
} }
if(outputDirRes == null) {
outputDirRes = new File(outputDir, "res");
}
}
if (isVerbose()) { if (isVerbose()) {
ch.qos.logback.classic.Logger rootLogger = ch.qos.logback.classic.Logger rootLogger =
(ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
...@@ -207,6 +228,16 @@ public class JadxCLIArgs implements IJadxArgs { ...@@ -207,6 +228,16 @@ public class JadxCLIArgs implements IJadxArgs {
return outputDir; return outputDir;
} }
@Override
public File getOutDirSrc() {
return outputDirSrc;
}
@Override
public File getOutDirRes() {
return outputDirRes;
}
public void setOutputDir(File outputDir) { public void setOutputDir(File outputDir) {
this.outputDir = outputDir; this.outputDir = outputDir;
} }
......
...@@ -5,6 +5,10 @@ import java.io.File; ...@@ -5,6 +5,10 @@ import java.io.File;
public interface IJadxArgs { public interface IJadxArgs {
File getOutDir(); File getOutDir();
File getOutDirSrc();
File getOutDirRes();
int getThreadsCount(); int getThreadsCount();
boolean isCFGOutput(); boolean isCFGOutput();
......
...@@ -5,6 +5,8 @@ import java.io.File; ...@@ -5,6 +5,8 @@ import java.io.File;
public class JadxArgs implements IJadxArgs { public class JadxArgs implements IJadxArgs {
private File outDir = new File("jadx-output"); private File outDir = new File("jadx-output");
private File outDirSrc = new File(outDir, "source");
private File outDirRes = new File(outDir, "res");
private int threadsCount = Math.max(1, Runtime.getRuntime().availableProcessors() - 1); private int threadsCount = Math.max(1, Runtime.getRuntime().availableProcessors() - 1);
private boolean cfgOutput = false; private boolean cfgOutput = false;
...@@ -40,6 +42,24 @@ public class JadxArgs implements IJadxArgs { ...@@ -40,6 +42,24 @@ public class JadxArgs implements IJadxArgs {
} }
@Override @Override
public File getOutDirSrc() {
return outDirSrc;
}
public void setOutDirSrc(File outDirSrc) {
this.outDirSrc = outDirSrc;
}
@Override
public File getOutDirRes() {
return outDirRes;
}
public void setOutDirRes(File outDirRes) {
this.outDirRes = outDirRes;
}
@Override
public int getThreadsCount() { public int getThreadsCount() {
return threadsCount; return threadsCount;
} }
......
...@@ -11,7 +11,6 @@ import jadx.core.dex.nodes.RootNode; ...@@ -11,7 +11,6 @@ import jadx.core.dex.nodes.RootNode;
import jadx.core.dex.visitors.IDexTreeVisitor; import jadx.core.dex.visitors.IDexTreeVisitor;
import jadx.core.dex.visitors.SaveCode; import jadx.core.dex.visitors.SaveCode;
import jadx.core.export.ExportGradleProject; import jadx.core.export.ExportGradleProject;
import jadx.core.utils.exceptions.DecodeException;
import jadx.core.utils.exceptions.JadxException; import jadx.core.utils.exceptions.JadxException;
import jadx.core.utils.exceptions.JadxRuntimeException; import jadx.core.utils.exceptions.JadxRuntimeException;
import jadx.core.utils.files.InputFile; import jadx.core.utils.files.InputFile;
...@@ -57,6 +56,8 @@ public final class JadxDecompiler { ...@@ -57,6 +56,8 @@ public final class JadxDecompiler {
private final List<InputFile> inputFiles = new ArrayList<>(); private final List<InputFile> inputFiles = new ArrayList<>();
private File outDir; private File outDir;
private File outDirRes;
private File outDirSrc;
private RootNode root; private RootNode root;
private List<IDexTreeVisitor> passes; private List<IDexTreeVisitor> passes;
...@@ -71,26 +72,52 @@ public final class JadxDecompiler { ...@@ -71,26 +72,52 @@ public final class JadxDecompiler {
private Map<MethodNode, JavaMethod> methodsMap = new ConcurrentHashMap<>(); private Map<MethodNode, JavaMethod> methodsMap = new ConcurrentHashMap<>();
private Map<FieldNode, JavaField> fieldsMap = new ConcurrentHashMap<>(); private Map<FieldNode, JavaField> fieldsMap = new ConcurrentHashMap<>();
public JadxDecompiler() { public JadxDecompiler() throws JadxException {
this(new JadxArgs()); this(new JadxArgs());
} }
public JadxDecompiler(IJadxArgs jadxArgs) { public JadxDecompiler(IJadxArgs jadxArgs) throws JadxException {
this.args = jadxArgs; this.args = jadxArgs;
this.outDir = jadxArgs.getOutDir(); this.outDir = jadxArgs.getOutDir();
this.outDirSrc = jadxArgs.getOutDirSrc();
this.outDirRes = jadxArgs.getOutDirRes();
reset(); reset();
init(); init();
} }
public void setOutputDir(File outDir) { public void setOutputDir(File outDir) throws JadxException {
this.outDir = outDir; this.outDir = outDir;
init(); init();
} }
void init() { public void setOutputDirSrc(File outDirSrc) throws JadxException {
this.outDirSrc = outDirSrc;
init();
}
public void setOutputDirRes(File outDirRes) throws JadxException {
this.outDirRes = outDirRes;
init();
}
void init() throws JadxException {
if(outDir == null && outDirSrc == null) {
outDirSrc = new JadxArgs().getOutDirSrc();
}
if(outDir == null && outDirRes == null) {
outDirRes = new JadxArgs().getOutDirRes();
}
if (outDir == null) { if (outDir == null) {
outDir = new JadxArgs().getOutDir(); outDir = new JadxArgs().getOutDir();
} }
else {
if(outDirSrc == null && outDirRes != null && !args.isSkipSources()) {
throw new JadxException("--output-dir-src must be specified");
}
if(outDirSrc != null && outDirRes == null && !args.isSkipResources()) {
throw new JadxException("--output-dir-res must be specified");
}
}
this.passes = Jadx.getPassesList(args, outDir); this.passes = Jadx.getPassesList(args, outDir);
this.codeGen = new CodeGen(args); this.codeGen = new CodeGen(args);
} }
...@@ -172,8 +199,8 @@ public final class JadxDecompiler { ...@@ -172,8 +199,8 @@ public final class JadxDecompiler {
sourcesOutDir = export.getSrcOutDir(); sourcesOutDir = export.getSrcOutDir();
resOutDir = export.getResOutDir(); resOutDir = export.getResOutDir();
} else { } else {
sourcesOutDir = outDir; sourcesOutDir = outDirSrc;
resOutDir = outDir; resOutDir = outDirRes;
} }
if (saveSources) { if (saveSources) {
appendSourcesSave(executor, sourcesOutDir); appendSourcesSave(executor, sourcesOutDir);
...@@ -267,7 +294,7 @@ public final class JadxDecompiler { ...@@ -267,7 +294,7 @@ public final class JadxDecompiler {
root.getErrorsCounter().printReport(); root.getErrorsCounter().printReport();
} }
void parse() throws DecodeException { void parse() throws JadxException {
reset(); reset();
init(); init();
......
...@@ -83,8 +83,9 @@ public abstract class IntegrationTest extends TestUtils { ...@@ -83,8 +83,9 @@ public abstract class IntegrationTest extends TestUtils {
} }
public ClassNode getClassNodeFromFile(File file, String clsName) { public ClassNode getClassNodeFromFile(File file, String clsName) {
JadxDecompiler d = new JadxDecompiler(args); JadxDecompiler d = null;
try { try {
d = new JadxDecompiler(args);
d.loadFile(file); d.loadFile(file);
} catch (JadxException e) { } catch (JadxException e) {
e.printStackTrace(); e.printStackTrace();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment