diff --git a/build.gradle b/build.gradle
index 5eb11fdffbb0954e95663524e4af17790b8f0f45..bd08e4af7dd8d3281b1f184e5daa2d31b2ffead1 100644
--- a/build.gradle
+++ b/build.gradle
@@ -35,20 +35,20 @@ subprojects {
}
}
-task copyArtifacts (type: Sync, dependsOn: ['jadx-cli:installApp', 'jadx-gui:installApp']) {
+task copyArtifacts(type: Sync, dependsOn: ['jadx-cli:installApp', 'jadx-gui:installApp']) {
destinationDir file("$buildDir/jadx")
['jadx-cli', 'jadx-gui'].each {
from tasks.getByPath(":${it}:installApp").destinationDir
}
}
-task pack (type: Zip, dependsOn: copyArtifacts) {
+task pack(type: Zip, dependsOn: copyArtifacts) {
destinationDir buildDir
archiveName "jadx-${jadxVersion}.zip"
from copyArtifacts.destinationDir
}
-task build (dependsOn: pack) {
+task build(dependsOn: pack) {
description = 'Build jadx distribution zip'
}
diff --git a/jadx-cli/src/main/java/jadx/cli/JadxCLI.java b/jadx-cli/src/main/java/jadx/cli/JadxCLI.java
index 35205e1fb4ca2006726768cbac78a2b1e3965271..11dabc01f5b37039bfad1619c76a86de667543e2 100644
--- a/jadx-cli/src/main/java/jadx/cli/JadxCLI.java
+++ b/jadx-cli/src/main/java/jadx/cli/JadxCLI.java
@@ -2,7 +2,6 @@ package jadx.cli;
import jadx.api.Decompiler;
import jadx.core.utils.ErrorsCounter;
-import jadx.core.utils.exceptions.JadxException;
import java.io.File;
@@ -17,7 +16,7 @@ public class JadxCLI {
JadxCLIArgs jadxArgs = new JadxCLIArgs(args);
checkArgs(jadxArgs);
processAndSave(jadxArgs);
- } catch (JadxException e) {
+ } catch (Exception e) {
LOG.error(e.getMessage());
System.exit(1);
}
@@ -40,26 +39,29 @@ public class JadxCLI {
System.exit(errorsCount);
}
- private static void checkArgs(JadxCLIArgs jadxArgs) throws JadxException {
- if (jadxArgs.getInput().isEmpty())
- throw new JadxException("Please specify input file");
-
+ private static void checkArgs(JadxCLIArgs jadxArgs) throws Exception {
+ if (jadxArgs.getInput().isEmpty()) {
+ LOG.error("Please specify input file");
+ jadxArgs.printUsage();
+ System.exit(1);
+ }
File outputDir = jadxArgs.getOutDir();
if (outputDir == null) {
String outDirName;
File file = jadxArgs.getInput().get(0);
String name = file.getName();
int pos = name.lastIndexOf('.');
- if (pos != -1)
+ if (pos != -1) {
outDirName = name.substring(0, pos);
- else
+ } else {
outDirName = name + "-jadx-out";
-
+ }
LOG.info("output directory: " + outDirName);
outputDir = new File(outDirName);
jadxArgs.setOutputDir(outputDir);
}
- if (outputDir.exists() && !outputDir.isDirectory())
- throw new JadxException("Output directory exists as file " + outputDir);
+ if (outputDir.exists() && !outputDir.isDirectory()) {
+ throw new Exception("Output directory exists as file " + outputDir);
+ }
}
}
diff --git a/jadx-cli/src/main/java/jadx/cli/JadxCLIArgs.java b/jadx-cli/src/main/java/jadx/cli/JadxCLIArgs.java
index 999826cedf5433ff8a3ae4978d09ad3a652b4858..065720b07896b26bc6771d13d703c9e3d80fb45f 100644
--- a/jadx-cli/src/main/java/jadx/cli/JadxCLIArgs.java
+++ b/jadx-cli/src/main/java/jadx/cli/JadxCLIArgs.java
@@ -20,7 +20,7 @@ import com.beust.jcommander.ParameterException;
public final class JadxCLIArgs implements IJadxArgs {
- @Parameter(description = " (.dex, .apk, .jar or .class)")
+ @Parameter(description = " (.dex, .apk or .jar)")
protected List files;
@Parameter(names = {"-d", "--output-dir"}, description = "output directory")
@@ -32,7 +32,7 @@ public final class JadxCLIArgs implements IJadxArgs {
@Parameter(names = {"-f", "--fallback"}, description = "make simple dump (using goto instead of 'if', 'for', etc)", help = true)
protected boolean fallbackMode = false;
- @Parameter(names = {"--cfg"}, description = "save methods control flow graph")
+ @Parameter(names = {"--cfg"}, description = "save methods control flow graph to dot file")
protected boolean cfgOutput = false;
@Parameter(names = {"--raw-cfg"}, description = "save methods control flow graph (use raw instructions)")
diff --git a/jadx-core/src/main/resources/logback.xml b/jadx-cli/src/main/resources/logback.xml
similarity index 79%
rename from jadx-core/src/main/resources/logback.xml
rename to jadx-cli/src/main/resources/logback.xml
index ec2224bac5a52aaff0b2d2dadd6840871680e4f7..6f8e7d5eb866d5abc0441318ae0f1f63b087a0ef 100644
--- a/jadx-core/src/main/resources/logback.xml
+++ b/jadx-cli/src/main/resources/logback.xml
@@ -2,7 +2,7 @@
- %d{HH:mm:ss} %-5level - %msg%n
+ %-5level - %msg%n
diff --git a/jadx-core/src/main/java/jadx/core/codegen/InsnGen.java b/jadx-core/src/main/java/jadx/core/codegen/InsnGen.java
index 9adfceb3202390354f76b1013b3b4c0945d01e17..b8a696467e180916b4c6aa06095388e4e46867cb 100644
--- a/jadx-core/src/main/java/jadx/core/codegen/InsnGen.java
+++ b/jadx-core/src/main/java/jadx/core/codegen/InsnGen.java
@@ -8,9 +8,9 @@ import jadx.core.dex.info.FieldInfo;
import jadx.core.dex.info.MethodInfo;
import jadx.core.dex.instructions.ArithNode;
import jadx.core.dex.instructions.ArithOp;
-import jadx.core.dex.instructions.ConstClassInsn;
-import jadx.core.dex.instructions.ConstStringInsn;
-import jadx.core.dex.instructions.FillArrayOp;
+import jadx.core.dex.instructions.ConstClassNode;
+import jadx.core.dex.instructions.ConstStringNode;
+import jadx.core.dex.instructions.FillArrayNode;
import jadx.core.dex.instructions.GotoNode;
import jadx.core.dex.instructions.IfNode;
import jadx.core.dex.instructions.IndexInsnNode;
@@ -209,12 +209,12 @@ public class InsnGen {
private void makeInsnBody(CodeWriter code, InsnNode insn, EnumSet state) throws CodegenException {
switch (insn.getType()) {
case CONST_STR:
- String str = ((ConstStringInsn) insn).getString();
+ String str = ((ConstStringNode) insn).getString();
code.add(StringUtils.unescapeString(str));
break;
case CONST_CLASS:
- ArgType clsType = ((ConstClassInsn) insn).getClsType();
+ ArgType clsType = ((ConstClassNode) insn).getClsType();
code.add(useType(clsType)).add(".class");
break;
@@ -311,7 +311,7 @@ public class InsnGen {
break;
case FILL_ARRAY:
- fillArray((FillArrayOp) insn, code);
+ fillArray((FillArrayNode) insn, code);
break;
case FILLED_NEW_ARRAY:
@@ -449,7 +449,7 @@ public class InsnGen {
code.add('}');
}
- private void fillArray(FillArrayOp insn, CodeWriter code) throws CodegenException {
+ private void fillArray(FillArrayNode insn, CodeWriter code) throws CodegenException {
ArgType elType = insn.getResult().getType().getArrayElement();
if (elType.getPrimitiveType() == null) {
elType = elType.selectFirst();
diff --git a/jadx-core/src/main/java/jadx/core/dex/info/ClassInfo.java b/jadx-core/src/main/java/jadx/core/dex/info/ClassInfo.java
index e2e88504efb4a691c25f82679c99dbe3cb9d0805..6587151845dd581992bd8cd095d59fe18e116459 100644
--- a/jadx-core/src/main/java/jadx/core/dex/info/ClassInfo.java
+++ b/jadx-core/src/main/java/jadx/core/dex/info/ClassInfo.java
@@ -80,7 +80,7 @@ public final class ClassInfo {
char firstChar = name.charAt(0);
if (Character.isDigit(firstChar)) {
- name = "InnerClass_" + name;
+ name = "AnonymousClass_" + name;
} else if (firstChar == '$') {
name = "_" + name;
}
diff --git a/jadx-core/src/main/java/jadx/core/dex/instructions/ConstClassInsn.java b/jadx-core/src/main/java/jadx/core/dex/instructions/ConstClassNode.java
similarity index 80%
rename from jadx-core/src/main/java/jadx/core/dex/instructions/ConstClassInsn.java
rename to jadx-core/src/main/java/jadx/core/dex/instructions/ConstClassNode.java
index 6b14ff00539e8de28240b451337f2c480753b8c0..0a2cfb290765db18cfa2a32ec854bc3c07d13ed1 100644
--- a/jadx-core/src/main/java/jadx/core/dex/instructions/ConstClassInsn.java
+++ b/jadx-core/src/main/java/jadx/core/dex/instructions/ConstClassNode.java
@@ -3,11 +3,11 @@ package jadx.core.dex.instructions;
import jadx.core.dex.instructions.args.ArgType;
import jadx.core.dex.nodes.InsnNode;
-public class ConstClassInsn extends InsnNode {
+public class ConstClassNode extends InsnNode {
private final ArgType clsType;
- public ConstClassInsn(ArgType clsType) {
+ public ConstClassNode(ArgType clsType) {
super(InsnType.CONST_CLASS, 0);
this.clsType = clsType;
}
diff --git a/jadx-core/src/main/java/jadx/core/dex/instructions/ConstStringInsn.java b/jadx-core/src/main/java/jadx/core/dex/instructions/ConstStringNode.java
similarity index 77%
rename from jadx-core/src/main/java/jadx/core/dex/instructions/ConstStringInsn.java
rename to jadx-core/src/main/java/jadx/core/dex/instructions/ConstStringNode.java
index a8ffe9d940b04050b8a7389b6b05f4efb0475394..0c191017cf3d46f01b617579599e13c4944f0c9c 100644
--- a/jadx-core/src/main/java/jadx/core/dex/instructions/ConstStringInsn.java
+++ b/jadx-core/src/main/java/jadx/core/dex/instructions/ConstStringNode.java
@@ -2,11 +2,11 @@ package jadx.core.dex.instructions;
import jadx.core.dex.nodes.InsnNode;
-public class ConstStringInsn extends InsnNode {
+public class ConstStringNode extends InsnNode {
private final String str;
- public ConstStringInsn(String str) {
+ public ConstStringNode(String str) {
super(InsnType.CONST_STR, 0);
this.str = str;
}
diff --git a/jadx-core/src/main/java/jadx/core/dex/instructions/FillArrayOp.java b/jadx-core/src/main/java/jadx/core/dex/instructions/FillArrayNode.java
similarity index 88%
rename from jadx-core/src/main/java/jadx/core/dex/instructions/FillArrayOp.java
rename to jadx-core/src/main/java/jadx/core/dex/instructions/FillArrayNode.java
index 48959ba79b2acb12ea5073d92828d1f160401720..4b104efaed49de67c21278530e346576229b7b1d 100644
--- a/jadx-core/src/main/java/jadx/core/dex/instructions/FillArrayOp.java
+++ b/jadx-core/src/main/java/jadx/core/dex/instructions/FillArrayNode.java
@@ -7,11 +7,11 @@ import jadx.core.dex.nodes.InsnNode;
import com.android.dx.io.instructions.FillArrayDataPayloadDecodedInstruction;
-public class FillArrayOp extends InsnNode {
+public class FillArrayNode extends InsnNode {
private final Object data;
- public FillArrayOp(int resReg, FillArrayDataPayloadDecodedInstruction payload) {
+ public FillArrayNode(int resReg, FillArrayDataPayloadDecodedInstruction payload) {
super(InsnType.FILL_ARRAY, 0);
this.data = payload.getData();
diff --git a/jadx-core/src/main/java/jadx/core/dex/instructions/InsnDecoder.java b/jadx-core/src/main/java/jadx/core/dex/instructions/InsnDecoder.java
index b052e8e0ad09ea35933541fa2c09e358a66642c3..99d038d1d060264555b4899288c1be0292a82ae6 100644
--- a/jadx-core/src/main/java/jadx/core/dex/instructions/InsnDecoder.java
+++ b/jadx-core/src/main/java/jadx/core/dex/instructions/InsnDecoder.java
@@ -96,13 +96,13 @@ public class InsnDecoder {
case Opcodes.CONST_STRING:
case Opcodes.CONST_STRING_JUMBO: {
- InsnNode node = new ConstStringInsn(dex.getString(insn.getIndex()));
+ InsnNode node = new ConstStringNode(dex.getString(insn.getIndex()));
node.setResult(InsnArg.reg(insn, 0, ArgType.STRING));
return node;
}
case Opcodes.CONST_CLASS: {
- InsnNode node = new ConstClassInsn(dex.getType(insn.getIndex()));
+ InsnNode node = new ConstClassNode(dex.getType(insn.getIndex()));
node.setResult(InsnArg.reg(insn, 0, ArgType.CLASS));
return node;
}
@@ -595,7 +595,7 @@ public class InsnDecoder {
private InsnNode fillArray(DecodedInstruction insn) {
DecodedInstruction payload = insnArr[insn.getTarget()];
- return new FillArrayOp(insn.getA(), (FillArrayDataPayloadDecodedInstruction) payload);
+ return new FillArrayNode(insn.getA(), (FillArrayDataPayloadDecodedInstruction) payload);
}
private InsnNode filledNewArray(DecodedInstruction insn, int offset, boolean isRange) {
diff --git a/jadx-core/src/main/java/jadx/core/dex/instructions/args/InsnArg.java b/jadx-core/src/main/java/jadx/core/dex/instructions/args/InsnArg.java
index f609d5d6e4534ccd01836a0d2d1ad775ff7c7fd8..362bb3bf1b7feedfe9822f4bf2818e85c8b6bbfa 100644
--- a/jadx-core/src/main/java/jadx/core/dex/instructions/args/InsnArg.java
+++ b/jadx-core/src/main/java/jadx/core/dex/instructions/args/InsnArg.java
@@ -1,6 +1,5 @@
package jadx.core.dex.instructions.args;
-import jadx.core.dex.instructions.InsnType;
import jadx.core.dex.nodes.InsnNode;
import jadx.core.utils.InsnUtils;
@@ -63,40 +62,45 @@ public abstract class InsnArg extends Typed {
}
public InsnArg wrapInstruction(InsnNode insn) {
- assert parentInsn != insn : "Can't wrap instruction info itself";
- int count = parentInsn.getArgsCount();
+ InsnNode parent = parentInsn;
+ assert parent != insn : "Can't wrap instruction info itself";
+ int count = parent.getArgsCount();
for (int i = 0; i < count; i++) {
- if (parentInsn.getArg(i) == this) {
- InsnArg arg;
- InsnType insnType = insn.getType();
- switch (insnType) {
- case MOVE:
- case CONST:
- arg = insn.getArg(0);
- String name = insn.getResult().getTypedVar().getName();
- if (name != null) {
- arg.getTypedVar().setName(name);
- }
- break;
- case CONST_STR:
- arg = wrap(insn);
- arg.getTypedVar().forceSetType(ArgType.STRING);
- break;
- case CONST_CLASS:
- arg = wrap(insn);
- arg.getTypedVar().forceSetType(ArgType.CLASS);
- break;
- default:
- arg = wrap(insn);
- break;
- }
- parentInsn.setArg(i, arg);
+ if (parent.getArg(i) == this) {
+ InsnArg arg = wrapArg(insn);
+ parent.setArg(i, arg);
return arg;
}
}
return null;
}
+ private static InsnArg wrapArg(InsnNode insn) {
+ InsnArg arg;
+ switch (insn.getType()) {
+ case MOVE:
+ case CONST:
+ arg = insn.getArg(0);
+ String name = insn.getResult().getTypedVar().getName();
+ if (name != null) {
+ arg.getTypedVar().setName(name);
+ }
+ break;
+ case CONST_STR:
+ arg = wrap(insn);
+ arg.getTypedVar().forceSetType(ArgType.STRING);
+ break;
+ case CONST_CLASS:
+ arg = wrap(insn);
+ arg.getTypedVar().forceSetType(ArgType.CLASS);
+ break;
+ default:
+ arg = wrap(insn);
+ break;
+ }
+ return arg;
+ }
+
public boolean isThis() {
// must be implemented in RegisterArg
return false;
diff --git a/jadx-core/src/main/java/jadx/core/dex/instructions/args/RegisterArg.java b/jadx-core/src/main/java/jadx/core/dex/instructions/args/RegisterArg.java
index 70be3f88ee29f82bd2236359e2e205a3bda25bcb..bf353903711cdae4384cc4b47a81785d8569fbed 100644
--- a/jadx-core/src/main/java/jadx/core/dex/instructions/args/RegisterArg.java
+++ b/jadx-core/src/main/java/jadx/core/dex/instructions/args/RegisterArg.java
@@ -1,7 +1,7 @@
package jadx.core.dex.instructions.args;
-import jadx.core.dex.instructions.ConstClassInsn;
-import jadx.core.dex.instructions.ConstStringInsn;
+import jadx.core.dex.instructions.ConstClassNode;
+import jadx.core.dex.instructions.ConstStringNode;
import jadx.core.dex.instructions.InsnType;
import jadx.core.dex.nodes.InsnNode;
import jadx.core.dex.visitors.InstructionRemover;
@@ -53,9 +53,9 @@ public class RegisterArg extends InsnArg {
case CONST:
return parInsn.getArg(0);
case CONST_STR:
- return ((ConstStringInsn) parInsn).getString();
+ return ((ConstStringNode) parInsn).getString();
case CONST_CLASS:
- return ((ConstClassInsn) parInsn).getClsType();
+ return ((ConstClassNode) parInsn).getClsType();
}
}
return null;
diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/ModVisitor.java b/jadx-core/src/main/java/jadx/core/dex/visitors/ModVisitor.java
index d5a0b0c8a84c09cb07471094bad0c2749ad022f1..8abc7d8dbc960ba2adac5141f534acd62692b025 100644
--- a/jadx-core/src/main/java/jadx/core/dex/visitors/ModVisitor.java
+++ b/jadx-core/src/main/java/jadx/core/dex/visitors/ModVisitor.java
@@ -3,8 +3,8 @@ package jadx.core.dex.visitors;
import jadx.core.deobf.NameMapper;
import jadx.core.dex.attributes.AttributeType;
import jadx.core.dex.info.MethodInfo;
-import jadx.core.dex.instructions.ConstClassInsn;
-import jadx.core.dex.instructions.ConstStringInsn;
+import jadx.core.dex.instructions.ConstClassNode;
+import jadx.core.dex.instructions.ConstStringNode;
import jadx.core.dex.instructions.IndexInsnNode;
import jadx.core.dex.instructions.InsnType;
import jadx.core.dex.instructions.InvokeNode;
@@ -104,10 +104,10 @@ public class ModVisitor extends AbstractVisitor {
ClassNode parentClass = mth.getParentClass();
FieldNode f = null;
if (insn.getType() == InsnType.CONST_STR) {
- String s = ((ConstStringInsn) insn).getString();
+ String s = ((ConstStringNode) insn).getString();
f = parentClass.getConstField(s);
} else if (insn.getType() == InsnType.CONST_CLASS) {
- ArgType t = ((ConstClassInsn) insn).getClsType();
+ ArgType t = ((ConstClassNode) insn).getClsType();
f = parentClass.getConstField(t);
} else {
LiteralArg arg = (LiteralArg) insn.getArg(0);
diff --git a/jadx-samples/build.gradle b/jadx-samples/build.gradle
index cbc7dbb9c7b9155eb71789863461f7a74e739811..f21e0c0707952082336f4381411ae05635f6b93b 100644
--- a/jadx-samples/build.gradle
+++ b/jadx-samples/build.gradle
@@ -40,10 +40,10 @@ task samplesJadxRun(type: JavaExec, dependsOn: samplesJadxCompile) {
main = mainSamplesClass
}
-task samples (dependsOn: samplesJadxRun) {
+task samples(dependsOn: samplesJadxRun) {
}
-task cleanGeneratedFiles (type: Delete) {
+task cleanGeneratedFiles(type: Delete) {
delete samplesJadxSrcDir
delete samplesJadxOutDir
}