Skip to content

Commit

Permalink
feat(cli): decompile only a single class (PR #657)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpstotz authored and skylot committed May 8, 2019
1 parent 4b73d24 commit 6f973ca
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions jadx-cli/src/main/java/jadx/cli/JadxCLIArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -173,6 +176,9 @@ public JadxArgs toJadxArgs() {
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);
Expand Down
14 changes: 14 additions & 0 deletions jadx-core/src/main/java/jadx/api/JadxArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import java.util.function.Predicate;

public class JadxArgs {

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -182,6 +188,14 @@ public void setSkipSources(boolean skipSources) {
this.skipSources = skipSources;
}

public Predicate<String> getClassFilter() {
return classFilter;
}

public void setClassFilter(Predicate<String> classFilter) {
this.classFilter = classFilter;
}

public boolean isDeobfuscationOn() {
return deobfuscationOn;
}
Expand Down
5 changes: 5 additions & 0 deletions jadx-core/src/main/java/jadx/api/JadxDecompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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;
Expand Down Expand Up @@ -203,10 +204,14 @@ private void appendResourcesSave(ExecutorService executor, File outDir) {
}

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();
Expand Down

0 comments on commit 6f973ca

Please sign in to comment.