Commit 6f973ca2 authored by Jan S's avatar Jan S Committed by skylot

feat(cli): decompile only a single class (PR #657)

parent 4b73d24d
......@@ -43,6 +43,9 @@ public class JadxCLIArgs {
@Parameter(names = { "-s", "--no-src" }, description = "do not decompile source code")
protected boolean skipSources = false;
@Parameter(names = { "--single-class" }, description = "decompile a single class")
protected String singleClass = null;
@Parameter(names = { "-e", "--export-gradle" }, description = "save as android gradle project")
protected boolean exportAsGradleProject = false;
......@@ -173,6 +176,9 @@ public class JadxCLIArgs {
args.setOutDirRes(FileUtils.toFile(outDirRes));
args.setThreadsCount(threadsCount);
args.setSkipSources(skipSources);
if (singleClass != null) {
args.setClassFilter((className) -> singleClass.equals(className));
}
args.setSkipResources(skipResources);
args.setFallbackMode(fallbackMode);
args.setShowInconsistentCode(showInconsistentCode);
......
......@@ -6,6 +6,7 @@ import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import java.util.function.Predicate;
public class JadxArgs {
......@@ -36,6 +37,11 @@ public class JadxArgs {
private boolean skipResources = false;
private boolean skipSources = false;
/**
* Predicate that allows to filter the classes to be process based on their full name
*/
private Predicate<String> classFilter = null;
private boolean deobfuscationOn = false;
private boolean deobfuscationForceSave = false;
private boolean useSourceNameAsClassAlias = false;
......@@ -182,6 +188,14 @@ public class JadxArgs {
this.skipSources = skipSources;
}
public Predicate<String> getClassFilter() {
return classFilter;
}
public void setClassFilter(Predicate<String> classFilter) {
this.classFilter = classFilter;
}
public boolean isDeobfuscationOn() {
return deobfuscationOn;
}
......
......@@ -13,6 +13,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import org.jf.baksmali.Adaptors.ClassDefinition;
import org.jf.baksmali.BaksmaliOptions;
......@@ -203,10 +204,14 @@ public final class JadxDecompiler {
}
private void appendSourcesSave(ExecutorService executor, File outDir) {
final Predicate<String> classFilter = args.getClassFilter();
for (JavaClass cls : getClasses()) {
if (cls.getClassNode().contains(AFlag.DONT_GENERATE)) {
continue;
}
if (classFilter != null && !classFilter.test(cls.getFullName())) {
continue;
}
executor.execute(() -> {
try {
cls.decompile();
......
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