diff --git a/jadx-core/src/main/java/jadx/api/JavaPackage.java b/jadx-core/src/main/java/jadx/api/JavaPackage.java index 5bb0e6293..03f9dc71b 100644 --- a/jadx-core/src/main/java/jadx/api/JavaPackage.java +++ b/jadx-core/src/main/java/jadx/api/JavaPackage.java @@ -26,11 +26,14 @@ public final class JavaPackage implements Comparable { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } JavaPackage that = (JavaPackage) o; - if (!name.equals(that.name)) return false; - return true; + return name.equals(that.name); } @Override diff --git a/jadx-core/src/main/java/jadx/core/Jadx.java b/jadx-core/src/main/java/jadx/core/Jadx.java index ad9ff48aa..01d93d862 100644 --- a/jadx-core/src/main/java/jadx/core/Jadx.java +++ b/jadx-core/src/main/java/jadx/core/Jadx.java @@ -37,10 +37,12 @@ public class Jadx { private static final Logger LOG = LoggerFactory.getLogger(Jadx.class); static { - if (Consts.DEBUG) + if (Consts.DEBUG) { LOG.info("debug enabled"); - if (Jadx.class.desiredAssertionStatus()) + } + if (Jadx.class.desiredAssertionStatus()) { LOG.info("assertions enabled"); + } } public static List getPassesList(IJadxArgs args, File outDir) { @@ -52,8 +54,9 @@ public class Jadx { passes.add(new TypeResolver()); - if (args.isRawCFGOutput()) + if (args.isRawCFGOutput()) { passes.add(new DotGraphVisitor(outDir, false, true)); + } passes.add(new ConstInlinerVisitor()); passes.add(new FinishTypeResolver()); @@ -61,8 +64,9 @@ public class Jadx { passes.add(new ModVisitor()); passes.add(new EnumVisitor()); - if (args.isCFGOutput()) + if (args.isCFGOutput()) { passes.add(new DotGraphVisitor(outDir, false)); + } passes.add(new RegionMakerVisitor()); passes.add(new PostRegionVisitor()); @@ -71,8 +75,10 @@ public class Jadx { passes.add(new SimplifyVisitor()); passes.add(new ProcessVariables()); passes.add(new CheckRegions()); - if (args.isCFGOutput()) + + if (args.isCFGOutput()) { passes.add(new DotGraphVisitor(outDir, true)); + } passes.add(new MethodInlinerVisitor()); passes.add(new ClassModifier()); @@ -88,8 +94,9 @@ public class Jadx { while (resources.hasMoreElements()) { Manifest manifest = new Manifest(resources.nextElement().openStream()); String ver = manifest.getMainAttributes().getValue("jadx-version"); - if (ver != null) + if (ver != null) { return ver; + } } } catch (IOException e) { LOG.error("Can't get manifest file", e); diff --git a/jadx-core/src/main/java/jadx/core/clsp/ClspGraph.java b/jadx-core/src/main/java/jadx/core/clsp/ClspGraph.java index 9795f0c17..609d01acc 100644 --- a/jadx-core/src/main/java/jadx/core/clsp/ClspGraph.java +++ b/jadx-core/src/main/java/jadx/core/clsp/ClspGraph.java @@ -82,8 +82,9 @@ public class ClspGraph { return name; } else { String r = searchCommonParent(anc, p); - if (r != null) + if (r != null) { return r; + } } } return null; diff --git a/jadx-core/src/main/java/jadx/core/clsp/NClass.java b/jadx-core/src/main/java/jadx/core/clsp/NClass.java index 5f3487b1a..f7049f97d 100644 --- a/jadx-core/src/main/java/jadx/core/clsp/NClass.java +++ b/jadx-core/src/main/java/jadx/core/clsp/NClass.java @@ -41,11 +41,14 @@ public class NClass { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } NClass nClass = (NClass) o; - if (!name.equals(nClass.name)) return false; - return true; + return name.equals(nClass.name); } @Override diff --git a/jadx-core/src/main/java/jadx/core/codegen/AnnotationGen.java b/jadx-core/src/main/java/jadx/core/codegen/AnnotationGen.java index a9cb78996..d3d99f05d 100644 --- a/jadx-core/src/main/java/jadx/core/codegen/AnnotationGen.java +++ b/jadx-core/src/main/java/jadx/core/codegen/AnnotationGen.java @@ -43,9 +43,9 @@ public class AnnotationGen { public void addForParameter(CodeWriter code, MethodParameters paramsAnnotations, int n) { AnnotationsList aList = paramsAnnotations.getParamList().get(n); - if (aList == null || aList.size() == 0) + if (aList == null || aList.size() == 0) { return; - + } for (Annotation a : aList.getAll()) { code.add(formatAnnotation(a)); code.add(' '); @@ -54,9 +54,9 @@ public class AnnotationGen { private void add(IAttributeNode node, CodeWriter code) { AnnotationsList aList = (AnnotationsList) node.getAttributes().get(AttributeType.ANNOTATION_LIST); - if (aList == null || aList.size() == 0) + if (aList == null || aList.size() == 0) { return; - + } for (Annotation a : aList.getAll()) { String aCls = a.getAnnotationClass(); if (aCls.startsWith(Consts.DALVIK_ANNOTATION_PKG)) { @@ -86,8 +86,9 @@ public class AnnotationGen { code.add(e.getKey()); code.add(" = "); code.add(encValueToString(e.getValue())); - if (it.hasNext()) + if (it.hasNext()) { code.add(", "); + } } } code.add(')'); @@ -104,8 +105,9 @@ public class AnnotationGen { for (Iterator it = ((List) exs).iterator(); it.hasNext(); ) { ArgType ex = it.next(); code.add(TypeGen.translate(classGen, ex)); - if (it.hasNext()) + if (it.hasNext()) { code.add(", "); + } } } } @@ -122,31 +124,39 @@ public class AnnotationGen { // TODO: refactor this boilerplate code @SuppressWarnings("unchecked") public String encValueToString(Object val) { - if (val == null) + if (val == null) { return "null"; - - if (val instanceof String) + } + if (val instanceof String) { return StringUtils.unescapeString((String) val); - if (val instanceof Integer) + } + if (val instanceof Integer) { return TypeGen.formatInteger((Integer) val); - if (val instanceof Character) + } + if (val instanceof Character) { return StringUtils.unescapeChar((Character) val); - if (val instanceof Boolean) + } + if (val instanceof Boolean) { return Boolean.TRUE.equals(val) ? "true" : "false"; - if (val instanceof Float) + } + if (val instanceof Float) { return TypeGen.formatFloat((Float) val); - if (val instanceof Double) + } + if (val instanceof Double) { return TypeGen.formatDouble((Double) val); - if (val instanceof Long) + } + if (val instanceof Long) { return TypeGen.formatLong((Long) val); - if (val instanceof Short) + } + if (val instanceof Short) { return TypeGen.formatShort((Short) val); - if (val instanceof Byte) + } + if (val instanceof Byte) { return TypeGen.formatByte((Byte) val); - - if (val instanceof ArgType) + } + if (val instanceof ArgType) { return TypeGen.translate(classGen, (ArgType) val) + ".class"; - + } if (val instanceof FieldInfo) { // must be a static field FieldInfo field = (FieldInfo) val; @@ -158,7 +168,6 @@ public class AnnotationGen { return classGen.useClass(field.getDeclClass()) + '.' + field.getName(); } } - if (val instanceof List) { StringBuilder str = new StringBuilder(); str.append('{'); @@ -166,19 +175,17 @@ public class AnnotationGen { for (Iterator it = list.iterator(); it.hasNext(); ) { Object obj = it.next(); str.append(encValueToString(obj)); - if (it.hasNext()) + if (it.hasNext()) { str.append(", "); + } } str.append('}'); return str.toString(); } - if (val instanceof Annotation) { return formatAnnotation((Annotation) val).toString(); } - // TODO: also can be method values - throw new JadxRuntimeException("Can't decode value: " + val + " (" + val.getClass() + ")"); } } diff --git a/jadx-core/src/main/java/jadx/core/codegen/ClassGen.java b/jadx-core/src/main/java/jadx/core/codegen/ClassGen.java index 8fb30f853..b2f4021c5 100644 --- a/jadx-core/src/main/java/jadx/core/codegen/ClassGen.java +++ b/jadx-core/src/main/java/jadx/core/codegen/ClassGen.java @@ -90,12 +90,12 @@ public class ClassGen { } public void addClassCode(CodeWriter code) throws CodegenException { - if (cls.getAttributes().contains(AttributeFlag.DONT_GENERATE)) + if (cls.getAttributes().contains(AttributeFlag.DONT_GENERATE)) { return; - - if (cls.getAttributes().contains(AttributeFlag.INCONSISTENT_CODE)) + } + if (cls.getAttributes().contains(AttributeFlag.INCONSISTENT_CODE)) { code.startLine("// jadx: inconsistent code"); - + } makeClassDeclaration(code); makeClassBody(code); code.newLine(); @@ -113,8 +113,9 @@ public class ClassGen { insertSourceFileInfo(clsCode, cls); clsCode.startLine(af.makeString()); if (af.isInterface()) { - if (af.isAnnotation()) + if (af.isAnnotation()) { clsCode.add('@'); + } clsCode.add("interface "); } else if (af.isEnum()) { clsCode.add("enum "); @@ -134,28 +135,30 @@ public class ClassGen { } if (cls.getInterfaces().size() > 0 && !af.isAnnotation()) { - if (cls.getAccessFlags().isInterface()) + if (cls.getAccessFlags().isInterface()) { clsCode.add("extends "); - else + } else { clsCode.add("implements "); - + } for (Iterator it = cls.getInterfaces().iterator(); it.hasNext(); ) { ClassInfo interf = it.next(); clsCode.add(useClass(interf)); - if (it.hasNext()) + if (it.hasNext()) { clsCode.add(", "); + } } - if (!cls.getInterfaces().isEmpty()) + if (!cls.getInterfaces().isEmpty()) { clsCode.add(' '); + } } clsCode.attachAnnotation(cls); } public boolean makeGenericMap(CodeWriter code, Map> gmap) { - if (gmap == null || gmap.isEmpty()) + if (gmap == null || gmap.isEmpty()) { return false; - + } code.add('<'); int i = 0; for (Entry> e : gmap.entrySet()) { @@ -186,14 +189,15 @@ public class ClassGen { CodeWriter mthsCode = makeMethods(clsCode, cls.getMethods()); CodeWriter fieldsCode = makeFields(clsCode, cls, cls.getFields()); clsCode.add(fieldsCode); - if (fieldsCode.notEmpty() && mthsCode.notEmpty()) + if (fieldsCode.notEmpty() && mthsCode.notEmpty()) { clsCode.newLine(); - + } // insert inner classes code if (cls.getInnerClasses().size() != 0) { clsCode.add(makeInnerClasses(cls, clsCode.getIndent())); - if (mthsCode.notEmpty()) + if (mthsCode.notEmpty()) { clsCode.newLine(); + } } clsCode.add(mthsCode); clsCode.startLine('}'); @@ -202,12 +206,11 @@ public class ClassGen { private CodeWriter makeInnerClasses(ClassNode cls, int indent) throws CodegenException { CodeWriter innerClsCode = new CodeWriter(indent + 1); for (ClassNode inCls : cls.getInnerClasses()) { - if (inCls.isAnonymous()) - continue; - - ClassGen inClGen = new ClassGen(inCls, parentGen == null ? this : parentGen, fallback); - inClGen.addClassCode(innerClsCode); - imports.addAll(inClGen.getImports()); + if (!inCls.isAnonymous()) { + ClassGen inClGen = new ClassGen(inCls, parentGen == null ? this : parentGen, fallback); + inClGen.addClassCode(innerClsCode); + imports.addAll(inClGen.getImports()); + } } return innerClsCode; } @@ -276,26 +279,28 @@ public class ClassGen { igen = new InsnGen(mthGen, enumFields.getStaticMethod(), false); } code.add(igen.arg(arg)); - if (aIt.hasNext()) + if (aIt.hasNext()) { code.add(", "); + } } code.add(')'); } if (f.getCls() != null) { new ClassGen(f.getCls(), this, fallback).makeClassBody(code); } - if (it.hasNext()) + if (it.hasNext()) { code.add(','); + } } - if (enumFields.getFields().isEmpty()) + if (enumFields.getFields().isEmpty()) { code.startLine(); - + } code.add(';'); code.newLine(); } for (FieldNode f : fields) { - if(f.getAttributes().contains(AttributeFlag.DONT_GENERATE)) { + if (f.getAttributes().contains(AttributeFlag.DONT_GENERATE)) { continue; } annotationGen.addForField(code, f); @@ -338,10 +343,11 @@ public class ClassGen { sb.append(", "); } ArgType gt = generics[i]; - if (gt.isTypeKnown()) + if (gt.isTypeKnown()) { sb.append(TypeGen.translate(this, gt)); - else + } else { sb.append('?'); + } } sb.append('>'); return sb.toString(); diff --git a/jadx-core/src/main/java/jadx/core/codegen/CodeWriter.java b/jadx-core/src/main/java/jadx/core/codegen/CodeWriter.java index ff52e7c59..4242fcb44 100644 --- a/jadx-core/src/main/java/jadx/core/codegen/CodeWriter.java +++ b/jadx-core/src/main/java/jadx/core/codegen/CodeWriter.java @@ -59,8 +59,9 @@ public class CodeWriter { public CodeWriter startLine(int ind, String str) { addLine(); buf.append(indentStr); - for (int i = 0; i < ind; i++) + for (int i = 0; i < ind; i++) { buf.append(INDENT); + } buf.append(str); return this; } @@ -209,10 +210,11 @@ public class CodeWriter { if (name.length() > MAX_FILENAME_LENGTH) { int dotIndex = name.indexOf('.'); int cutAt = MAX_FILENAME_LENGTH - name.length() + dotIndex - 1; - if (cutAt <= 0) + if (cutAt <= 0) { name = name.substring(0, MAX_FILENAME_LENGTH - 1); - else + } else { name = name.substring(0, cutAt) + name.substring(dotIndex); + } file = new File(file.getParentFile(), name); } @@ -226,8 +228,9 @@ public class CodeWriter { } catch (Exception e) { LOG.error("Save file error", e); } finally { - if (out != null) + if (out != null) { out.close(); + } } } diff --git a/jadx-core/src/main/java/jadx/core/codegen/MethodGen.java b/jadx-core/src/main/java/jadx/core/codegen/MethodGen.java index 6d320a076..fc1a6148c 100644 --- a/jadx-core/src/main/java/jadx/core/codegen/MethodGen.java +++ b/jadx-core/src/main/java/jadx/core/codegen/MethodGen.java @@ -127,9 +127,9 @@ public class MethodGen { RegisterArg arg = it.next(); // add argument annotation - if (paramsAnnotation != null) + if (paramsAnnotation != null) { annotationGen.addForParameter(argsCode, paramsAnnotation, i); - + } if (!it.hasNext() && mth.getAccessFlags().isVarArgs()) { // change last array argument to varargs ArgType type = arg.getType(); @@ -148,8 +148,9 @@ public class MethodGen { argsCode.add(makeArgName(arg)); i++; - if (it.hasNext()) + if (it.hasNext()) { argsCode.add(", "); + } } return argsCode; } @@ -163,24 +164,27 @@ public class MethodGen { String name = arg.getTypedVar().getName(); String base = "r" + arg.getRegNum(); if (fallback) { - if (name != null) + if (name != null) { return base + "_" + name; - else + } else { return base; + } } else { if (name != null) { - if (name.equals("this")) + if (name.equals("this")) { return name; - else if (Consts.DEBUG) + } else if (Consts.DEBUG) { return name + "_" + base; - else + } else { return name; + } } else { ArgType type = arg.getType(); - if (type.isPrimitive()) + if (type.isPrimitive()) { return base + type.getPrimitiveType().getShortName().toLowerCase(); - else + } else { return base + "_" + Utils.escape(TypeGen.translate(classGen, arg.getType())); + } } } } @@ -193,9 +197,9 @@ public class MethodGen { */ public String assignArg(RegisterArg arg) { String name = makeArgName(arg); - if (varNames.add(name) || fallback) + if (varNames.add(name) || fallback) { return name; - + } name = getUniqVarName(name); arg.getTypedVar().setName(name); return name; @@ -203,9 +207,9 @@ public class MethodGen { public String assignNamedArg(NamedArg arg) { String name = arg.getName(); - if (varNames.add(name) || fallback) + if (varNames.add(name) || fallback) { return name; - + } name = getUniqVarName(name); arg.setName(name); return name; @@ -298,8 +302,9 @@ public class MethodGen { try { if (insnGen.makeInsn(insn, code)) { CatchAttr catchAttr = (CatchAttr) attrs.get(AttributeType.CATCH_BLOCK); - if (catchAttr != null) + if (catchAttr != null) { code.add("\t //" + catchAttr); + } } } catch (CodegenException e) { code.startLine("// error: " + insn); diff --git a/jadx-core/src/main/java/jadx/core/codegen/TypeGen.java b/jadx-core/src/main/java/jadx/core/codegen/TypeGen.java index 3d143c758..6fbab4770 100644 --- a/jadx-core/src/main/java/jadx/core/codegen/TypeGen.java +++ b/jadx-core/src/main/java/jadx/core/codegen/TypeGen.java @@ -10,9 +10,9 @@ public class TypeGen { public static String translate(ClassGen clsGen, ArgType type) { final PrimitiveType stype = type.getPrimitiveType(); - if (stype == null) + if (stype == null) { return type.toString(); - + } if (stype == PrimitiveType.OBJECT) { return clsGen.useClass(type); } @@ -69,8 +69,9 @@ public class TypeGen { case OBJECT: case ARRAY: - if (lit != 0) + if (lit != 0) { throw new JadxRuntimeException("Wrong object literal: " + type + " = " + lit); + } return "null"; default: @@ -100,8 +101,9 @@ public class TypeGen { public static String formatLong(long lit) { String l = Long.toString(lit); - if (lit == Long.MIN_VALUE || Math.abs(lit) >= Integer.MAX_VALUE) + if (lit == Long.MIN_VALUE || Math.abs(lit) >= Integer.MAX_VALUE) { l += "L"; + } return wrapNegNum(lit < 0, l); } @@ -109,6 +111,6 @@ public class TypeGen { // if (lz) // return "(" + str + ")"; // else - return str; + return str; } } diff --git a/jadx-core/src/main/java/jadx/core/dex/attributes/AttrNode.java b/jadx-core/src/main/java/jadx/core/dex/attributes/AttrNode.java index 47e134d9a..2f1942ae2 100644 --- a/jadx-core/src/main/java/jadx/core/dex/attributes/AttrNode.java +++ b/jadx-core/src/main/java/jadx/core/dex/attributes/AttrNode.java @@ -6,8 +6,9 @@ public abstract class AttrNode implements IAttributeNode { @Override public AttributesList getAttributes() { - if (attributesList == null) + if (attributesList == null) { attributesList = new AttributesList(); + } return attributesList; } diff --git a/jadx-core/src/main/java/jadx/core/dex/attributes/AttributeType.java b/jadx-core/src/main/java/jadx/core/dex/attributes/AttributeType.java index 5933f76cc..c81947abe 100644 --- a/jadx-core/src/main/java/jadx/core/dex/attributes/AttributeType.java +++ b/jadx-core/src/main/java/jadx/core/dex/attributes/AttributeType.java @@ -38,8 +38,9 @@ public enum AttributeType { AttributeType[] vals = AttributeType.values(); for (int i = 0; i < vals.length; i++) { AttributeType type = vals[i]; - if (type.notUniq()) + if (type.notUniq()) { last = i; + } } NOT_UNIQ_COUNT = last + 1; } diff --git a/jadx-core/src/main/java/jadx/core/dex/attributes/AttributesList.java b/jadx-core/src/main/java/jadx/core/dex/attributes/AttributesList.java index ec4893094..cad8821f4 100644 --- a/jadx-core/src/main/java/jadx/core/dex/attributes/AttributesList.java +++ b/jadx-core/src/main/java/jadx/core/dex/attributes/AttributesList.java @@ -52,10 +52,11 @@ public final class AttributesList { // Attributes public void add(IAttribute attr) { - if (attr.getType().isUniq()) + if (attr.getType().isUniq()) { uniqAttr.put(attr.getType(), attr); - else + } else { addMultiAttribute(attr); + } } private void addMultiAttribute(IAttribute attr) { @@ -70,15 +71,17 @@ public final class AttributesList { public void addAll(AttributesList otherList) { flags.addAll(otherList.flags); uniqAttr.putAll(otherList.uniqAttr); - for (IAttribute attr : otherList.attributes) + for (IAttribute attr : otherList.attributes) { addMultiAttribute(attr); + } } public boolean contains(AttributeType type) { - if (type.isUniq()) + if (type.isUniq()) { return uniqAttr.containsKey(type); - else + } else { return getMultiCountInternal(type) != 0; + } } public IAttribute get(AttributeType type) { @@ -86,9 +89,11 @@ public final class AttributesList { return uniqAttr.get(type); } else { if (getMultiCountInternal(type) != 0) { - for (IAttribute attr : attributes) - if (attr.getType() == type) + for (IAttribute attr : attributes) { + if (attr.getType() == type) { return attr; + } + } } return null; } @@ -104,9 +109,9 @@ public final class AttributesList { public Annotation getAnnotation(String cls) { AnnotationsList aList = (AnnotationsList) get(AttributeType.ANNOTATION_LIST); - if (aList == null || aList.size() == 0) + if (aList == null || aList.size() == 0) { return null; - + } return aList.get(cls); } @@ -119,8 +124,9 @@ public final class AttributesList { } else { List attrs = new ArrayList(count); for (IAttribute attr : attributes) { - if (attr.getType() == type) + if (attr.getType() == type) { attrs.add(attr); + } } return attrs; } @@ -132,8 +138,9 @@ public final class AttributesList { } else { for (Iterator it = attributes.iterator(); it.hasNext(); ) { IAttribute attr = it.next(); - if (attr.getType() == type) + if (attr.getType() == type) { it.remove(); + } } attrCount[type.ordinal()] = 0; } @@ -143,11 +150,13 @@ public final class AttributesList { AttributeType type = attr.getType(); if (type.isUniq()) { IAttribute a = uniqAttr.get(type); - if (a == attr) + if (a == attr) { uniqAttr.remove(type); + } } else { - if (getMultiCountInternal(type) == 0) + if (getMultiCountInternal(type) == 0) { return; + } for (Iterator it = attributes.iterator(); it.hasNext(); ) { IAttribute a = it.next(); @@ -168,25 +177,28 @@ public final class AttributesList { public List getAttributeStrings() { int size = flags.size() + uniqAttr.size() + attributes.size(); - if (size == 0) + if (size == 0) { return Collections.emptyList(); - + } List list = new ArrayList(size); - for (AttributeFlag a : flags) + for (AttributeFlag a : flags) { list.add(a.toString()); - for (IAttribute a : uniqAttr.values()) + } + for (IAttribute a : uniqAttr.values()) { list.add(a.toString()); - for (IAttribute a : attributes) + } + for (IAttribute a : attributes) { list.add(a.toString()); + } return list; } @Override public String toString() { List list = getAttributeStrings(); - if (list.isEmpty()) + if (list.isEmpty()) { return ""; - + } return "A:{" + Utils.listToString(list) + "}"; } diff --git a/jadx-core/src/main/java/jadx/core/dex/attributes/BlockRegState.java b/jadx-core/src/main/java/jadx/core/dex/attributes/BlockRegState.java index 3f4060887..9a3e6f593 100644 --- a/jadx-core/src/main/java/jadx/core/dex/attributes/BlockRegState.java +++ b/jadx-core/src/main/java/jadx/core/dex/attributes/BlockRegState.java @@ -45,8 +45,9 @@ public final class BlockRegState { StringBuilder str = new StringBuilder(); for (RegisterArg reg : regs) { if (reg.getTypedVar() != null) { - if (str.length() != 0) + if (str.length() != 0) { str.append(", "); + } str.append(reg.toString()); } } diff --git a/jadx-core/src/main/java/jadx/core/dex/attributes/DeclareVariableAttr.java b/jadx-core/src/main/java/jadx/core/dex/attributes/DeclareVariableAttr.java index 2a500d455..c1b67678d 100644 --- a/jadx-core/src/main/java/jadx/core/dex/attributes/DeclareVariableAttr.java +++ b/jadx-core/src/main/java/jadx/core/dex/attributes/DeclareVariableAttr.java @@ -24,8 +24,9 @@ public class DeclareVariableAttr implements IAttribute { public void addVar(RegisterArg arg) { int i; if ((i = vars.indexOf(arg)) != -1) { - if (vars.get(i).getType().equals(arg.getType())) + if (vars.get(i).getType().equals(arg.getType())) { return; + } } vars.add(arg); } diff --git a/jadx-core/src/main/java/jadx/core/dex/attributes/EnumClassAttr.java b/jadx-core/src/main/java/jadx/core/dex/attributes/EnumClassAttr.java index 353fc5115..464363843 100644 --- a/jadx-core/src/main/java/jadx/core/dex/attributes/EnumClassAttr.java +++ b/jadx-core/src/main/java/jadx/core/dex/attributes/EnumClassAttr.java @@ -18,10 +18,11 @@ public class EnumClassAttr implements IAttribute { public EnumField(String name, int argsCount) { this.name = name; - if (argsCount != 0) + if (argsCount != 0) { this.args = new ArrayList(argsCount); - else + } else { this.args = Collections.emptyList(); + } } public String getName() { diff --git a/jadx-core/src/main/java/jadx/core/dex/attributes/JumpAttribute.java b/jadx-core/src/main/java/jadx/core/dex/attributes/JumpAttribute.java index ff9fb0e81..710a52231 100644 --- a/jadx-core/src/main/java/jadx/core/dex/attributes/JumpAttribute.java +++ b/jadx-core/src/main/java/jadx/core/dex/attributes/JumpAttribute.java @@ -41,9 +41,15 @@ public class JumpAttribute implements IAttribute { @Override public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (getClass() != obj.getClass()) return false; + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } JumpAttribute other = (JumpAttribute) obj; return dest == other.dest && src == other.src; } diff --git a/jadx-core/src/main/java/jadx/core/dex/attributes/LoopAttr.java b/jadx-core/src/main/java/jadx/core/dex/attributes/LoopAttr.java index fe1e60398..ed17523da 100644 --- a/jadx-core/src/main/java/jadx/core/dex/attributes/LoopAttr.java +++ b/jadx-core/src/main/java/jadx/core/dex/attributes/LoopAttr.java @@ -45,9 +45,11 @@ public class LoopAttr implements IAttribute { Set inloop = getLoopBlocks(); for (BlockNode block : inloop) { // exit: successor node not from this loop, (don't change to getCleanSuccessors) - for (BlockNode s : block.getSuccessors()) - if (!inloop.contains(s) && !s.getAttributes().contains(AttributeType.EXC_HANDLER)) + for (BlockNode s : block.getSuccessors()) { + if (!inloop.contains(s) && !s.getAttributes().contains(AttributeType.EXC_HANDLER)) { nodes.add(block); + } + } } return nodes; } diff --git a/jadx-core/src/main/java/jadx/core/dex/info/AccessInfo.java b/jadx-core/src/main/java/jadx/core/dex/info/AccessInfo.java index 3ad74245f..a2f51a927 100644 --- a/jadx-core/src/main/java/jadx/core/dex/info/AccessInfo.java +++ b/jadx-core/src/main/java/jadx/core/dex/info/AccessInfo.java @@ -24,10 +24,11 @@ public class AccessInfo { } public AccessInfo remove(int flag) { - if (containsFlag(flag)) + if (containsFlag(flag)) { return new AccessInfo(accFlags - flag, type); - else + } else { return this; + } } public AccessInfo getVisibility() { @@ -111,71 +112,73 @@ public class AccessInfo { public String makeString() { StringBuilder code = new StringBuilder(); - if (isPublic()) + if (isPublic()) { code.append("public "); - - if (isPrivate()) + } + if (isPrivate()) { code.append("private "); - - if (isProtected()) + } + if (isProtected()) { code.append("protected "); - - if (isStatic()) + } + if (isStatic()) { code.append("static "); - - if (isFinal()) + } + if (isFinal()) { code.append("final "); - - if (isAbstract()) + } + if (isAbstract()) { code.append("abstract "); - - if (isNative()) + } + if (isNative()) { code.append("native "); - + } switch (type) { case METHOD: - if (isSynchronized()) + if (isSynchronized()) { code.append("synchronized "); - - if (isBridge()) + } + if (isBridge()) { code.append("/* bridge */ "); - + } if (Consts.DEBUG) { - if (isVarArgs()) + if (isVarArgs()) { code.append("/* varargs */ "); + } } break; case FIELD: - if (isVolatile()) + if (isVolatile()) { code.append("volatile "); - - if (isTransient()) + } + if (isTransient()) { code.append("transient "); + } break; case CLASS: - if ((accFlags & AccessFlags.ACC_STRICT) != 0) + if ((accFlags & AccessFlags.ACC_STRICT) != 0) { code.append("strict "); - + } if (Consts.DEBUG) { - if ((accFlags & AccessFlags.ACC_SUPER) != 0) + if ((accFlags & AccessFlags.ACC_SUPER) != 0) { code.append("/* super */ "); - - if ((accFlags & AccessFlags.ACC_ENUM) != 0) + } + if ((accFlags & AccessFlags.ACC_ENUM) != 0) { code.append("/* enum */ "); + } } break; } - - if (isSynthetic()) + if (isSynthetic()) { code.append("/* synthetic */ "); - + } return code.toString(); } public String rawString() { - switch (type){ + switch (type) { case CLASS: return AccessFlags.classString(accFlags); case FIELD: 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 9c08678a7..eadd08de8 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 @@ -14,13 +14,13 @@ public final class ClassInfo { private static final Map CLASSINFO_CACHE = new WeakHashMap(); public static ClassInfo fromDex(DexNode dex, int clsIndex) { - if (clsIndex == DexNode.NO_INDEX) + if (clsIndex == DexNode.NO_INDEX) { return null; - + } ArgType type = dex.getType(clsIndex); - if (type.isArray()) + if (type.isArray()) { type = ArgType.OBJECT; - + } return fromType(type); } @@ -153,7 +153,9 @@ public final class ClassInfo { @Override public boolean equals(Object obj) { - if (this == obj) return true; + if (this == obj) { + return true; + } if (obj instanceof ClassInfo) { ClassInfo other = (ClassInfo) obj; return this.getFullName().equals(other.getFullName()); diff --git a/jadx-core/src/main/java/jadx/core/dex/info/FieldInfo.java b/jadx-core/src/main/java/jadx/core/dex/info/FieldInfo.java index f8c752379..2d5ae1d6d 100644 --- a/jadx-core/src/main/java/jadx/core/dex/info/FieldInfo.java +++ b/jadx-core/src/main/java/jadx/core/dex/info/FieldInfo.java @@ -41,13 +41,22 @@ public class FieldInfo { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } FieldInfo fieldInfo = (FieldInfo) o; - if (!name.equals(fieldInfo.name)) return false; - if (!type.equals(fieldInfo.type)) return false; - if (!declClass.equals(fieldInfo.declClass)) return false; + if (!name.equals(fieldInfo.name)) { + return false; + } + if (!type.equals(fieldInfo.type)) { + return false; + } + if (!declClass.equals(fieldInfo.declClass)) { + return false; + } return true; } diff --git a/jadx-core/src/main/java/jadx/core/dex/info/MethodInfo.java b/jadx-core/src/main/java/jadx/core/dex/info/MethodInfo.java index 22065c41d..20a61f6ce 100644 --- a/jadx-core/src/main/java/jadx/core/dex/info/MethodInfo.java +++ b/jadx-core/src/main/java/jadx/core/dex/info/MethodInfo.java @@ -98,13 +98,25 @@ public final class MethodInfo { @Override public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (getClass() != obj.getClass()) return false; + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } MethodInfo other = (MethodInfo) obj; - if (!shortId.equals(other.shortId)) return false; - if (!retType.equals(other.retType)) return false; - if (!declClass.equals(other.declClass)) return false; + if (!shortId.equals(other.shortId)) { + return false; + } + if (!retType.equals(other.retType)) { + return false; + } + if (!declClass.equals(other.declClass)) { + return false; + } return true; } 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 e99a31f7e..9655c7ac0 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 @@ -578,14 +578,16 @@ public class InsnDecoder { targets = ps.getTargets(); keys = new Object[targets.length]; int k = ps.getFirstKey(); - for (int i = 0; i < keys.length; i++) + for (int i = 0; i < keys.length; i++) { keys[i] = k++; + } } else { SparseSwitchPayloadDecodedInstruction ss = (SparseSwitchPayloadDecodedInstruction) payload; targets = ss.getTargets(); keys = new Object[targets.length]; - for (int i = 0; i < keys.length; i++) + for (int i = 0; i < keys.length; i++) { keys[i] = ss.getKeys()[i]; + } } // convert from relative to absolute offsets for (int i = 0; i < targets.length; i++) { @@ -612,8 +614,9 @@ public class InsnDecoder { r++; } } else { - for (int i = 0; i < insn.getRegisterCount(); i++) + for (int i = 0; i < insn.getRegisterCount(); i++) { regs[i] = InsnArg.reg(insn, i, elType); + } } return insn(InsnType.FILLED_NEW_ARRAY, resReg == -1 ? null : InsnArg.reg(resReg, arrType), @@ -689,8 +692,9 @@ public class InsnDecoder { InsnNode node = new InsnNode(type, args == null ? 0 : args.length); node.setResult(res); if (args != null) { - for (InsnArg arg : args) + for (InsnArg arg : args) { node.addArg(arg); + } } return node; } @@ -711,19 +715,23 @@ public class InsnDecoder { public static int getPrevInsnOffset(Object[] insnArr, int offset) { int i = offset - 1; - while (i >= 0 && insnArr[i] == null) + while (i >= 0 && insnArr[i] == null) { i--; - if (i < 0) + } + if (i < 0) { return -1; + } return i; } public static int getNextInsnOffset(Object[] insnArr, int offset) { int i = offset + 1; - while (i < insnArr.length && insnArr[i] == null) + while (i < insnArr.length && insnArr[i] == null) { i++; - if (i >= insnArr.length) + } + if (i >= insnArr.length) { return -1; + } return i; } } diff --git a/jadx-core/src/main/java/jadx/core/dex/instructions/InvokeNode.java b/jadx-core/src/main/java/jadx/core/dex/instructions/InvokeNode.java index 0339dab7b..e653d7d1e 100644 --- a/jadx-core/src/main/java/jadx/core/dex/instructions/InvokeNode.java +++ b/jadx-core/src/main/java/jadx/core/dex/instructions/InvokeNode.java @@ -19,8 +19,9 @@ public class InvokeNode extends InsnNode { this.mth = mth; this.type = type; - if (resReg >= 0) + if (resReg >= 0) { setResult(InsnArg.reg(resReg, mth.getReturnType())); + } int k = isRange ? insn.getA() : 0; if (type != InvokeType.STATIC) { diff --git a/jadx-core/src/main/java/jadx/core/dex/instructions/SwitchNode.java b/jadx-core/src/main/java/jadx/core/dex/instructions/SwitchNode.java index d68be5854..3afbc794b 100644 --- a/jadx-core/src/main/java/jadx/core/dex/instructions/SwitchNode.java +++ b/jadx-core/src/main/java/jadx/core/dex/instructions/SwitchNode.java @@ -42,8 +42,9 @@ public class SwitchNode extends InsnNode { targ.append('['); for (int i = 0; i < targets.length; i++) { targ.append(InsnUtils.formatOffset(targets[i])); - if (i < targets.length - 1) + if (i < targets.length - 1) { targ.append(", "); + } } targ.append(']'); return super.toString() + " k:" + Arrays.toString(keys) + " t:" + targ; diff --git a/jadx-core/src/main/java/jadx/core/dex/instructions/args/PrimitiveType.java b/jadx-core/src/main/java/jadx/core/dex/instructions/args/PrimitiveType.java index a43549bfd..f11f5fbfe 100644 --- a/jadx-core/src/main/java/jadx/core/dex/instructions/args/PrimitiveType.java +++ b/jadx-core/src/main/java/jadx/core/dex/instructions/args/PrimitiveType.java @@ -30,17 +30,19 @@ public enum PrimitiveType { } public static PrimitiveType getWidest(PrimitiveType a, PrimitiveType b) { - if (a.ordinal() > b.ordinal()) + if (a.ordinal() > b.ordinal()) { return a; - else + } else { return b; + } } public static PrimitiveType getSmaller(PrimitiveType a, PrimitiveType b) { - if (a.ordinal() < b.ordinal()) + if (a.ordinal() < b.ordinal()) { return a; - else + } else { return b; + } } @Override 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 2451b1ae7..f23475386 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 @@ -40,12 +40,13 @@ public class RegisterArg extends InsnArg { public InsnNode getAssignInsn() { for (InsnArg arg : getTypedVar().getUseList()) { InsnNode assignInsn = arg.getParentInsn(); - if (assignInsn == null) + if (assignInsn == null) { // assign as function argument return null; - else if (assignInsn.getResult() != null - && assignInsn.getResult().getRegNum() == regNum) + } else if (assignInsn.getResult() != null + && assignInsn.getResult().getRegNum() == regNum) { return assignInsn; + } } return null; } @@ -109,12 +110,22 @@ public class RegisterArg extends InsnArg { @Override public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (getClass() != obj.getClass()) return false; + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } RegisterArg other = (RegisterArg) obj; - if (regNum != other.regNum) return false; - if (!typedVar.equals(other.typedVar)) return false; + if (regNum != other.regNum) { + return false; + } + if (!typedVar.equals(other.typedVar)) { + return false; + } return true; } diff --git a/jadx-core/src/main/java/jadx/core/dex/instructions/args/TypedVar.java b/jadx-core/src/main/java/jadx/core/dex/instructions/args/TypedVar.java index 78ad8e11c..76732a950 100644 --- a/jadx-core/src/main/java/jadx/core/dex/instructions/args/TypedVar.java +++ b/jadx-core/src/main/java/jadx/core/dex/instructions/args/TypedVar.java @@ -70,13 +70,23 @@ public class TypedVar { @Override public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (!(obj instanceof TypedVar)) return false; + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof TypedVar)) { + return false; + } TypedVar other = (TypedVar) obj; - if (!type.equals(other.type)) return false; + if (!type.equals(other.type)) { + return false; + } if (name == null) { - if (other.name != null) return false; + if (other.name != null) { + return false; + } } else if (!name.equals(other.name)) { return false; } @@ -86,8 +96,9 @@ public class TypedVar { @Override public String toString() { StringBuilder sb = new StringBuilder(); - if (name != null) + if (name != null) { sb.append('\'').append(name).append("' "); + } sb.append(type); return sb.toString(); } diff --git a/jadx-core/src/main/java/jadx/core/dex/nodes/BlockNode.java b/jadx-core/src/main/java/jadx/core/dex/nodes/BlockNode.java index 4e69512cf..da9e2fd5e 100644 --- a/jadx-core/src/main/java/jadx/core/dex/nodes/BlockNode.java +++ b/jadx-core/src/main/java/jadx/core/dex/nodes/BlockNode.java @@ -72,15 +72,17 @@ public class BlockNode extends AttrNode implements IBlock { LoopAttr loop = (LoopAttr) block.getAttributes().get(AttributeType.LOOP); if (loop == null) { for (BlockNode b : sucList) { - if (!b.getAttributes().contains(AttributeType.EXC_HANDLER)) + if (!b.getAttributes().contains(AttributeType.EXC_HANDLER)) { nodes.add(b); + } } } else { for (BlockNode b : sucList) { if (!b.getAttributes().contains(AttributeType.EXC_HANDLER)) { // don't follow back edge - if (loop.getStart() == b && loop.getEnd() == block) + if (loop.getStart() == b && loop.getEnd() == block) { continue; + } nodes.add(b); } } @@ -153,13 +155,25 @@ public class BlockNode extends AttrNode implements IBlock { @Override public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (hashCode() != obj.hashCode()) return false; - if (!(obj instanceof BlockNode)) return false; + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (hashCode() != obj.hashCode()) { + return false; + } + if (!(obj instanceof BlockNode)) { + return false; + } BlockNode other = (BlockNode) obj; - if (id != other.id) return false; - if (startOffset != other.startOffset) return false; + if (id != other.id) { + return false; + } + if (startOffset != other.startOffset) { + return false; + } return true; } diff --git a/jadx-core/src/main/java/jadx/core/dex/nodes/FieldNode.java b/jadx-core/src/main/java/jadx/core/dex/nodes/FieldNode.java index c013e0b15..4be3cfa8e 100644 --- a/jadx-core/src/main/java/jadx/core/dex/nodes/FieldNode.java +++ b/jadx-core/src/main/java/jadx/core/dex/nodes/FieldNode.java @@ -48,8 +48,12 @@ public class FieldNode extends LineAttrNode { @Override public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } FieldNode other = (FieldNode) obj; return fieldInfo.equals(other.fieldInfo); } diff --git a/jadx-core/src/main/java/jadx/core/dex/nodes/InsnNode.java b/jadx-core/src/main/java/jadx/core/dex/nodes/InsnNode.java index 69e478d7d..896100a7e 100644 --- a/jadx-core/src/main/java/jadx/core/dex/nodes/InsnNode.java +++ b/jadx-core/src/main/java/jadx/core/dex/nodes/InsnNode.java @@ -32,15 +32,17 @@ public class InsnNode extends LineAttrNode { this.insnType = type; this.offset = -1; - if (argsCount == 0) + if (argsCount == 0) { this.arguments = Collections.emptyList(); - else + } else { this.arguments = new ArrayList(argsCount); + } } public void setResult(RegisterArg res) { - if (res != null) + if (res != null) { res.setParentInsn(this); + } this.result = res; } @@ -71,8 +73,9 @@ public class InsnNode extends LineAttrNode { public boolean containsArg(RegisterArg arg) { for (InsnArg a : arguments) { - if (a == arg || (a.isRegister() && ((RegisterArg) a).getRegNum() == arg.getRegNum())) + if (a == arg || (a.isRegister() && ((RegisterArg) a).getRegNum() == arg.getRegNum())) { return true; + } } return false; } @@ -92,8 +95,9 @@ public class InsnNode extends LineAttrNode { setArg(i, to); return true; } else if (arg.isInsnWrap()) { - if (((InsnWrapArg) arg).getWrapInsn().replaceArg(from, to)) + if (((InsnWrapArg) arg).getWrapInsn().replaceArg(from, to)) { return true; + } } } return false; @@ -176,14 +180,25 @@ public class InsnNode extends LineAttrNode { @Override public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (hashCode() != obj.hashCode()) return false; - if (!(obj instanceof InsnNode)) return false; - + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (hashCode() != obj.hashCode()) { + return false; + } + if (!(obj instanceof InsnNode)) { + return false; + } InsnNode other = (InsnNode) obj; - if (insnType != other.insnType) return false; - if (arguments.size() != other.arguments.size()) return false; + if (insnType != other.insnType) { + return false; + } + if (arguments.size() != other.arguments.size()) { + return false; + } // TODO !!! finish equals return true; diff --git a/jadx-core/src/main/java/jadx/core/dex/nodes/MethodNode.java b/jadx-core/src/main/java/jadx/core/dex/nodes/MethodNode.java index c5f020f5c..7c4465310 100644 --- a/jadx-core/src/main/java/jadx/core/dex/nodes/MethodNode.java +++ b/jadx-core/src/main/java/jadx/core/dex/nodes/MethodNode.java @@ -90,8 +90,9 @@ public class MethodNode extends LineAttrNode implements ILoadable { InsnNode[] insnByOffset = decoder.run(); instructions = new ArrayList(); for (InsnNode insn : insnByOffset) { - if (insn != null) + if (insn != null) { instructions.add(insn); + } } ((ArrayList) instructions).trimToSize(); @@ -127,18 +128,23 @@ public class MethodNode extends LineAttrNode implements ILoadable { if (noCode) { return; } - if (instructions != null) instructions.clear(); + if (instructions != null) { + instructions.clear(); + } blocks = null; exitBlocks = null; - if (exceptionHandlers != null) exceptionHandlers.clear(); + if (exceptionHandlers != null) { + exceptionHandlers.clear(); + } noCode = true; } @SuppressWarnings("unchecked") private boolean parseSignature() { Annotation a = getAttributes().getAnnotation(Consts.DALVIK_SIGNATURE); - if (a == null) + if (a == null) { return false; + } String sign = Utils.mergeSignature((List) a.getDefaultValue()); @@ -162,8 +168,9 @@ public class MethodNode extends LineAttrNode implements ILoadable { } List argsTypes = ArgType.parseSignatureList(argsTypesStr); - if (argsTypes == null) + if (argsTypes == null) { return false; + } List mthArgs = mthInfo.getArgumentsTypes(); if (argsTypes.size() != mthArgs.size()) { @@ -197,8 +204,9 @@ public class MethodNode extends LineAttrNode implements ILoadable { pos = 1; } else { pos = regsCount; - for (ArgType arg : args) + for (ArgType arg : args) { pos -= arg.getRegCount(); + } } if (accFlags.isStatic()) { thisArg = null; @@ -289,11 +297,15 @@ public class MethodNode extends LineAttrNode implements ILoadable { // resolve nested try blocks: // inner block contains all handlers from outer block => remove these handlers from inner block // each handler must be only in one try/catch block - for (TryCatchBlock ct1 : catches) - for (TryCatchBlock ct2 : catches) - if (ct1 != ct2 && ct2.getHandlers().containsAll(ct1.getHandlers())) - for (ExceptionHandler h : ct1.getHandlers()) + for (TryCatchBlock ct1 : catches) { + for (TryCatchBlock ct2 : catches) { + if (ct1 != ct2 && ct2.getHandlers().containsAll(ct1.getHandlers())) { + for (ExceptionHandler h : ct1.getHandlers()) { ct2.removeHandler(this, h); + } + } + } + } } // attach EXC_HANDLER attributes to instructions @@ -319,8 +331,9 @@ public class MethodNode extends LineAttrNode implements ILoadable { block.addInsn(insnByOffset[offset]); offset = InsnDecoder.getNextInsnOffset(insnByOffset, offset); } - if (insnByOffset[end] != null) + if (insnByOffset[end] != null) { insnByOffset[end].getAttributes().add(AttributeFlag.TRY_LEAVE); + } } } @@ -335,15 +348,17 @@ public class MethodNode extends LineAttrNode implements ILoadable { } // default case int next = InsnDecoder.getNextInsnOffset(insnByOffset, offset); - if (next != -1) + if (next != -1) { addJump(insnByOffset, offset, next); + } break; } case IF: int next = InsnDecoder.getNextInsnOffset(insnByOffset, offset); - if (next != -1) + if (next != -1) { addJump(insnByOffset, offset, next); + } addJump(insnByOffset, offset, ((IfNode) insn).getTarget()); break; @@ -363,10 +378,11 @@ public class MethodNode extends LineAttrNode implements ILoadable { public String getName() { String name = mthInfo.getName(); - if (name.equals(parentClass.getShortName())) + if (name.equals(parentClass.getShortName())) { return name + "_"; - else + } else { return name; + } } public ClassNode getParentClass() { @@ -397,8 +413,9 @@ public class MethodNode extends LineAttrNode implements ILoadable { blocks = Collections.unmodifiableList(blocks); exitBlocks = Collections.unmodifiableList(exitBlocks); - for (BlockNode block : blocks) + for (BlockNode block : blocks) { block.lock(); + } } public List getBasicBlocks() { @@ -430,8 +447,9 @@ public class MethodNode extends LineAttrNode implements ILoadable { public LoopAttr getLoopForBlock(BlockNode block) { for (LoopAttr loop : loops) { - if (loop.getLoopBlocks().contains(block)) + if (loop.getLoopBlocks().contains(block)) { return loop; + } } return null; } @@ -445,8 +463,9 @@ public class MethodNode extends LineAttrNode implements ILoadable { exceptionHandlers = new ArrayList(2); } else { for (ExceptionHandler h : exceptionHandlers) { - if (h == handler || h.getHandleOffset() == handler.getHandleOffset()) + if (h == handler || h.getHandleOffset() == handler.getHandleOffset()) { return h; + } } } exceptionHandlers.add(handler); @@ -471,8 +490,9 @@ public class MethodNode extends LineAttrNode implements ILoadable { for (MethodNode method : methods) { if (this != method && method.getName().equals(name) - && method.mthInfo.getArgumentsTypes().size() == argsCount) + && method.mthInfo.getArgumentsTypes().size() == argsCount) { return true; + } } return false; } @@ -508,8 +528,12 @@ public class MethodNode extends LineAttrNode implements ILoadable { @Override public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } MethodNode other = (MethodNode) obj; return mthInfo.equals(other.mthInfo); } diff --git a/jadx-core/src/main/java/jadx/core/dex/nodes/RootNode.java b/jadx-core/src/main/java/jadx/core/dex/nodes/RootNode.java index 6ee79fada..e44eca252 100644 --- a/jadx-core/src/main/java/jadx/core/dex/nodes/RootNode.java +++ b/jadx-core/src/main/java/jadx/core/dex/nodes/RootNode.java @@ -59,8 +59,9 @@ public class RootNode { // move inner classes List inner = new ArrayList(); for (ClassNode cls : classes) { - if (cls.getClassInfo().isInner()) + if (cls.getClassInfo().isInner()) { inner.add(cls); + } } for (ClassNode cls : inner) { ClassNode parent = resolveClass(cls.getClassInfo().getParentClass()); @@ -81,8 +82,9 @@ public class RootNode { if (includeInner) { classes.add(cls); } else { - if (!cls.getClassInfo().isInner()) + if (!cls.getClassInfo().isInner()) { classes.add(cls); + } } } } diff --git a/jadx-core/src/main/java/jadx/core/dex/nodes/parser/AnnotationsParser.java b/jadx-core/src/main/java/jadx/core/dex/nodes/parser/AnnotationsParser.java index c826fe57f..c3f172f2f 100644 --- a/jadx-core/src/main/java/jadx/core/dex/nodes/parser/AnnotationsParser.java +++ b/jadx-core/src/main/java/jadx/core/dex/nodes/parser/AnnotationsParser.java @@ -61,8 +61,6 @@ public class AnnotationsParser { private AnnotationsList readAnnotationSet(int offset) throws DecodeException { Section section = dex.openSection(offset); int size = section.readInt(); - if (size > 100) - section.toString(); List list = new ArrayList(size); for (int i = 0; i < size; i++) { Section anSection = dex.openSection(section.readInt()); diff --git a/jadx-core/src/main/java/jadx/core/dex/nodes/parser/DebugInfoParser.java b/jadx-core/src/main/java/jadx/core/dex/nodes/parser/DebugInfoParser.java index 287f0eb07..e1d82dabb 100644 --- a/jadx-core/src/main/java/jadx/core/dex/nodes/parser/DebugInfoParser.java +++ b/jadx-core/src/main/java/jadx/core/dex/nodes/parser/DebugInfoParser.java @@ -162,18 +162,19 @@ public class DebugInfoParser { int newAddr = addr + addrInc; for (int i = addr + 1; i <= newAddr; i++) { InsnNode insn = insnByOffset[i]; - if (insn == null) + if (insn == null) { continue; - + } insn.setSourceLine(line); - for (InsnArg arg : insn.getArguments()) + for (InsnArg arg : insn.getArguments()) { if (arg.isRegister()) { activeRegisters[((RegisterArg) arg).getRegNum()] = arg; } - + } RegisterArg res = insn.getResult(); - if (res != null) + if (res != null) { activeRegisters[res.getRegNum()] = res; + } } return newAddr; } @@ -195,18 +196,20 @@ public class DebugInfoParser { for (int i = start; i <= end; i++) { InsnNode insn = insnByOffset[i]; - if (insn != null) + if (insn != null) { fillLocals(insn, var); + } } merge(activeRegisters[var.getRegNum()], var); } private static void fillLocals(InsnNode insn, LocalVar var) { - if (insn.getResult() != null) + if (insn.getResult() != null) { merge(insn.getResult(), var); - - for (InsnArg arg : insn.getArguments()) + } + for (InsnArg arg : insn.getArguments()) { merge(arg, var); + } } private static void merge(InsnArg arg, LocalVar var) { diff --git a/jadx-core/src/main/java/jadx/core/dex/regions/IfCondition.java b/jadx-core/src/main/java/jadx/core/dex/regions/IfCondition.java index a6fd11d37..fa85584c9 100644 --- a/jadx-core/src/main/java/jadx/core/dex/regions/IfCondition.java +++ b/jadx-core/src/main/java/jadx/core/dex/regions/IfCondition.java @@ -53,11 +53,13 @@ public final class IfCondition { } public InsnArg getB() { - if (insn.isZeroCmp()) + if (insn.isZeroCmp()) { return InsnArg.lit(0, getA().getType()); - else + } else { return insn.getArg(1); + } } + public Compare invert() { insn.invertCondition(); return this; diff --git a/jadx-core/src/main/java/jadx/core/dex/regions/IfRegion.java b/jadx-core/src/main/java/jadx/core/dex/regions/IfRegion.java index 0fcff075e..52f413721 100644 --- a/jadx-core/src/main/java/jadx/core/dex/regions/IfRegion.java +++ b/jadx-core/src/main/java/jadx/core/dex/regions/IfRegion.java @@ -51,10 +51,12 @@ public final class IfRegion extends AbstractRegion { public List getSubBlocks() { ArrayList all = new ArrayList(3); all.add(header); - if (thenRegion != null) + if (thenRegion != null) { all.add(thenRegion); - if (elseRegion != null) + } + if (elseRegion != null) { all.add(elseRegion); + } return Collections.unmodifiableList(all); } diff --git a/jadx-core/src/main/java/jadx/core/dex/regions/LoopRegion.java b/jadx-core/src/main/java/jadx/core/dex/regions/LoopRegion.java index bb94a900e..b66c3b24f 100644 --- a/jadx-core/src/main/java/jadx/core/dex/regions/LoopRegion.java +++ b/jadx-core/src/main/java/jadx/core/dex/regions/LoopRegion.java @@ -68,9 +68,9 @@ public final class LoopRegion extends AbstractRegion { */ public boolean checkPreCondition() { List insns = preCondition.getInstructions(); - if (insns.isEmpty()) + if (insns.isEmpty()) { return true; - + } IfNode ifInsn = getIfInsn(); int size = insns.size(); for (int i = 0; i < size; i++) { @@ -79,21 +79,23 @@ public final class LoopRegion extends AbstractRegion { return false; } else { RegisterArg res = insn.getResult(); - if (res.getTypedVar().getUseList().size() > 2) + if (res.getTypedVar().getUseList().size() > 2) { return false; - + } boolean found = false; // search result arg in other insns for (int j = i + 1; j < size; j++) { - if (insns.get(i).containsArg(res)) + if (insns.get(i).containsArg(res)) { found = true; + } } // or in if insn - if (!found && ifInsn.containsArg(res)) + if (!found && ifInsn.containsArg(res)) { found = true; - - if (!found) + } + if (!found) { return false; + } } } return true; @@ -117,10 +119,12 @@ public final class LoopRegion extends AbstractRegion { @Override public List getSubBlocks() { List all = new ArrayList(3); - if (preCondition != null) + if (preCondition != null) { all.add(preCondition); - if (conditionBlock != null) + } + if (conditionBlock != null) { all.add(conditionBlock); + } all.add(body); return Collections.unmodifiableList(all); } diff --git a/jadx-core/src/main/java/jadx/core/dex/regions/Region.java b/jadx-core/src/main/java/jadx/core/dex/regions/Region.java index daae71eb4..421edae3b 100644 --- a/jadx-core/src/main/java/jadx/core/dex/regions/Region.java +++ b/jadx-core/src/main/java/jadx/core/dex/regions/Region.java @@ -28,8 +28,9 @@ public final class Region extends AbstractRegion { sb.append(blocks.size()); if (blocks.size() != 0) { for (IContainer cont : blocks) { - if (cont instanceof BlockNode) + if (cont instanceof BlockNode) { sb.append(((BlockNode) cont).getId()); + } } } return sb.toString(); diff --git a/jadx-core/src/main/java/jadx/core/dex/regions/SwitchRegion.java b/jadx-core/src/main/java/jadx/core/dex/regions/SwitchRegion.java index debd0434d..8ec121bc2 100644 --- a/jadx-core/src/main/java/jadx/core/dex/regions/SwitchRegion.java +++ b/jadx-core/src/main/java/jadx/core/dex/regions/SwitchRegion.java @@ -53,8 +53,9 @@ public final class SwitchRegion extends AbstractRegion { List all = new ArrayList(cases.size() + 2); all.add(header); all.addAll(cases); - if (defCase != null) + if (defCase != null) { all.add(defCase); + } return Collections.unmodifiableList(all); } diff --git a/jadx-core/src/main/java/jadx/core/dex/trycatch/ExceptionHandler.java b/jadx-core/src/main/java/jadx/core/dex/trycatch/ExceptionHandler.java index 83f76685f..0a1b0d92d 100644 --- a/jadx-core/src/main/java/jadx/core/dex/trycatch/ExceptionHandler.java +++ b/jadx-core/src/main/java/jadx/core/dex/trycatch/ExceptionHandler.java @@ -86,13 +86,23 @@ public class ExceptionHandler { @Override public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null) return false; - if (getClass() != obj.getClass()) return false; + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } ExceptionHandler other = (ExceptionHandler) obj; if (catchType == null) { - if (other.catchType != null) return false; - } else if (!catchType.equals(other.catchType)) return false; + if (other.catchType != null) { + return false; + } + } else if (!catchType.equals(other.catchType)) { + return false; + } return handleOffset == other.handleOffset; } diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/ConstInlinerVisitor.java b/jadx-core/src/main/java/jadx/core/dex/visitors/ConstInlinerVisitor.java index 4b3f2c44e..58943074d 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/ConstInlinerVisitor.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/ConstInlinerVisitor.java @@ -22,14 +22,15 @@ public class ConstInlinerVisitor extends AbstractVisitor { @Override public void visit(MethodNode mth) throws JadxException { - if (mth.isNoCode()) + if (mth.isNoCode()) { return; - + } for (BlockNode block : mth.getBasicBlocks()) { for (Iterator it = block.getInstructions().iterator(); it.hasNext(); ) { InsnNode insn = it.next(); - if (checkInsn(mth, block, insn)) + if (checkInsn(mth, block, insn)) { it.remove(); + } } } } @@ -57,9 +58,9 @@ public class ConstInlinerVisitor extends AbstractVisitor { int replace = 0; for (InsnArg arg : use) { InsnNode useInsn = arg.getParentInsn(); - if (useInsn == null) + if (useInsn == null) { continue; - + } BlockNode useBlock = BlockUtils.getBlockByInsn(mth, useInsn); if (useBlock == block || useBlock.isDominator(block)) { if (arg != insn.getResult() && !registerReassignOnPath(block, useBlock, insn)) { @@ -77,9 +78,9 @@ public class ConstInlinerVisitor extends AbstractVisitor { } private static boolean registerReassignOnPath(BlockNode block, BlockNode useBlock, InsnNode assignInsn) { - if (block == useBlock) + if (block == useBlock) { return false; - + } Set blocks = BlockUtils.getAllPathsBlocks(block, useBlock); // TODO store list of assign insn for each register int regNum = assignInsn.getResult().getRegNum(); @@ -87,8 +88,9 @@ public class ConstInlinerVisitor extends AbstractVisitor { for (InsnNode insn : b.getInstructions()) { if (insn.getResult() != null && insn != assignInsn - && insn.getResult().getRegNum() == regNum) + && insn.getResult().getRegNum() == regNum) { return true; + } } } return false; @@ -156,10 +158,11 @@ public class ConstInlinerVisitor extends AbstractVisitor { InsnArg arg = insn.getArg(i); if (!arg.getType().isTypeKnown()) { ArgType type; - if (k >= 0) + if (k >= 0) { type = types.get(k); - else + } else { type = mth.getParentClass().getClassInfo().getType(); + } arg.merge(type); } k++; diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/DepthTraverser.java b/jadx-core/src/main/java/jadx/core/dex/visitors/DepthTraverser.java index 59fabc535..8c4496a92 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/DepthTraverser.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/DepthTraverser.java @@ -9,10 +9,12 @@ public class DepthTraverser { public static void visit(IDexTreeVisitor visitor, ClassNode cls) { try { if (visitor.visit(cls)) { - for (ClassNode inCls : cls.getInnerClasses()) + for (ClassNode inCls : cls.getInnerClasses()) { visit(visitor, inCls); - for (MethodNode mth : cls.getMethods()) + } + for (MethodNode mth : cls.getMethods()) { visit(visitor, mth); + } } } catch (Throwable e) { ErrorsCounter.classError(cls, diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/DotGraphVisitor.java b/jadx-core/src/main/java/jadx/core/dex/visitors/DotGraphVisitor.java index 880df4bdc..5ceba8210 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/DotGraphVisitor.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/DotGraphVisitor.java @@ -36,9 +36,9 @@ public class DotGraphVisitor extends AbstractVisitor { @Override public void visit(MethodNode mth) { - if (mth.isNoCode()) + if (mth.isNoCode()) { return; - + } CodeWriter dot = new CodeWriter(); CodeWriter conn = new CodeWriter(); @@ -47,18 +47,22 @@ public class DotGraphVisitor extends AbstractVisitor { + "\" {"); if (useRegions) { - if (mth.getRegion() == null) + if (mth.getRegion() == null) { return; + } processRegion(mth, mth.getRegion(), dot, conn); if (mth.getExceptionHandlers() != null) { - for (ExceptionHandler h : mth.getExceptionHandlers()) - if (h.getHandlerRegion() != null) + for (ExceptionHandler h : mth.getExceptionHandlers()) { + if (h.getHandlerRegion() != null) { processRegion(mth, h.getHandlerRegion(), dot, conn); + } + } } } else { - for (BlockNode block : mth.getBasicBlocks()) + for (BlockNode block : mth.getBasicBlocks()) { processBlock(mth, block, dot, conn); + } } String attrs = attributesString(mth); @@ -109,8 +113,9 @@ public class DotGraphVisitor extends AbstractVisitor { String attrs = attributesString(block); if (PRINT_REGISTERS_STATES) { if (block.getStartState() != null) { - if (attrs.length() != 0) + if (attrs.length() != 0) { attrs += "|"; + } attrs += escape("RS: " + block.getStartState()) + NL; attrs += escape("RE: " + block.getEndState()) + NL; } @@ -125,16 +130,17 @@ public class DotGraphVisitor extends AbstractVisitor { + (insns.length() == 0 ? "" : "|" + insns) + "}\"];"); - for (BlockNode next : block.getSuccessors()) + for (BlockNode next : block.getSuccessors()) { conn.startLine(makeName(block) + " -> " + makeName(next) + ";"); - - for (BlockNode next : block.getDominatesOn()) + } + for (BlockNode next : block.getDominatesOn()) { conn.startLine(makeName(block) + " -> " + makeName(next) + "[style=dotted];"); - + } // add all dominators connections if (false) { - for (BlockNode next : BlockUtils.bitsetToBlocks(mth, block.getDoms())) + for (BlockNode next : BlockUtils.bitsetToBlocks(mth, block.getDoms())) { conn.startLine(makeName(block) + " -> " + makeName(next) + "[style=dotted, color=green];"); + } } } @@ -168,8 +174,9 @@ public class DotGraphVisitor extends AbstractVisitor { CodeWriter code = new CodeWriter(0); MethodGen.makeFallbackInsns(code, mth, block.getInstructions(), false); String str = escape(code.newLine().toString()); - if (str.startsWith(NL)) + if (str.startsWith(NL)) { str = str.substring(NL.length()); + } return str; } } diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/FallbackModeVisitor.java b/jadx-core/src/main/java/jadx/core/dex/visitors/FallbackModeVisitor.java index b4f0d58fc..d6599e3c6 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/FallbackModeVisitor.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/FallbackModeVisitor.java @@ -10,9 +10,9 @@ public class FallbackModeVisitor extends AbstractVisitor { @Override public void visit(MethodNode mth) throws JadxException { - if (mth.isNoCode()) + if (mth.isNoCode()) { return; - + } for (InsnNode insn : mth.getInstructions()) { // remove 'exception catch' for instruction which don't throw any exceptions CatchAttr catchAttr = (CatchAttr) insn.getAttributes().get(AttributeType.CATCH_BLOCK); diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/regions/CheckRegions.java b/jadx-core/src/main/java/jadx/core/dex/visitors/regions/CheckRegions.java index a28dee782..7cfb7eff0 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/regions/CheckRegions.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/regions/CheckRegions.java @@ -22,18 +22,20 @@ public class CheckRegions extends AbstractVisitor { @Override public void visit(MethodNode mth) throws JadxException { - if (mth.isNoCode() || mth.getBasicBlocks().size() == 0) + if (mth.isNoCode() || mth.getBasicBlocks().size() == 0) { return; + } // check if all blocks included in regions final Set blocksInRegions = new HashSet(); IRegionVisitor collectBlocks = new AbstractRegionVisitor() { @Override public void processBlock(MethodNode mth, IBlock container) { - if (container instanceof BlockNode) + if (container instanceof BlockNode) { blocksInRegions.add((BlockNode) container); - else + } else { LOG.warn("Not block node : " + container.getClass().getSimpleName()); + } } }; DepthRegionTraverser.traverseAll(mth, collectBlocks); @@ -44,10 +46,11 @@ public class CheckRegions extends AbstractVisitor { if (!block.getInstructions().isEmpty() && !block.getAttributes().contains(AttributeFlag.SKIP)) { mth.getAttributes().add(AttributeFlag.INCONSISTENT_CODE); - if (Consts.DEBUG) + if (Consts.DEBUG) { LOG.debug(" Missing block: {} in {}", block, mth); - else + } else { break; + } } } } diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/regions/CleanRegions.java b/jadx-core/src/main/java/jadx/core/dex/visitors/regions/CleanRegions.java index 45d5243f9..c09cdbdb4 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/regions/CleanRegions.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/regions/CleanRegions.java @@ -18,14 +18,15 @@ public class CleanRegions extends AbstractVisitor { @Override public void visit(MethodNode mth) throws JadxException { - if (mth.isNoCode() || mth.getBasicBlocks().size() == 0) + if (mth.isNoCode() || mth.getBasicBlocks().size() == 0) { return; - + } IRegionVisitor removeEmptyBlocks = new AbstractRegionVisitor() { @Override public void enterRegion(MethodNode mth, IRegion region) { - if (!(region instanceof Region)) + if (!(region instanceof Region)) { return; + } for (Iterator it = region.getSubBlocks().iterator(); it.hasNext(); ) { IContainer container = it.next(); @@ -44,6 +45,5 @@ public class CleanRegions extends AbstractVisitor { } }; DepthRegionTraverser.traverseAll(mth, removeEmptyBlocks); - } } diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/regions/DepthRegionTraverser.java b/jadx-core/src/main/java/jadx/core/dex/visitors/regions/DepthRegionTraverser.java index 142bade2f..da51c2723 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/regions/DepthRegionTraverser.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/regions/DepthRegionTraverser.java @@ -25,8 +25,9 @@ public class DepthRegionTraverser { traverse(mth, visitor, mth.getRegion()); if (mth.getExceptionHandlers() != null) { - for (ExceptionHandler h : mth.getExceptionHandlers()) + for (ExceptionHandler h : mth.getExceptionHandlers()) { traverse(mth, visitor, h.getHandlerRegion()); + } } } } diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/regions/ProcessVariables.java b/jadx-core/src/main/java/jadx/core/dex/visitors/regions/ProcessVariables.java index 7f1c7f0b5..d945512be 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/regions/ProcessVariables.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/regions/ProcessVariables.java @@ -141,12 +141,13 @@ public class ProcessVariables extends AbstractVisitor { for (Iterator it = set.iterator(); it.hasNext(); ) { IRegion r = it.next(); IRegion parent = r.getParent(); - if (parent != null && set.contains(parent)) + if (parent != null && set.contains(parent)) { it.remove(); + } } - if (set.isEmpty()) + if (set.isEmpty()) { continue; - + } IRegion region = set.iterator().next(); IRegion parent = region; boolean declare = false; @@ -178,12 +179,14 @@ public class ProcessVariables extends AbstractVisitor { private boolean canDeclareInRegion(Usage u, IRegion region) { for (IRegion r : u.getAssigns()) { - if (!RegionUtils.isRegionContainsRegion(region, r)) + if (!RegionUtils.isRegionContainsRegion(region, r)) { return false; + } } for (IRegion r : u.getUseRegions()) { - if (!RegionUtils.isRegionContainsRegion(region, r)) + if (!RegionUtils.isRegionContainsRegion(region, r)) { return false; + } } return true; } diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/regions/RegionMakerVisitor.java b/jadx-core/src/main/java/jadx/core/dex/visitors/regions/RegionMakerVisitor.java index 12a291abb..6add59e37 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/regions/RegionMakerVisitor.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/regions/RegionMakerVisitor.java @@ -12,9 +12,9 @@ public class RegionMakerVisitor extends AbstractVisitor { @Override public void visit(MethodNode mth) throws JadxException { - if (mth.isNoCode()) + if (mth.isNoCode()) { return; - + } RegionMaker rm = new RegionMaker(mth); RegionStack state = new RegionStack(mth); diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/regions/RegionStack.java b/jadx-core/src/main/java/jadx/core/dex/visitors/regions/RegionStack.java index d64e490b7..79a2bbf44 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/regions/RegionStack.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/regions/RegionStack.java @@ -17,8 +17,9 @@ final class RegionStack { private static final boolean DEBUG = false; static { - if (DEBUG) + if (DEBUG) { LOG.debug("Debug enabled for {}", RegionStack.class); + } } private static final class State { @@ -47,27 +48,30 @@ final class RegionStack { private State curState; public RegionStack(MethodNode mth) { - if (DEBUG) + if (DEBUG) { LOG.debug("New RegionStack: {}", mth); + } this.stack = new ArrayDeque(); this.curState = new State(); } public void push(IRegion region) { stack.push(curState); - if (stack.size() > 1000) + if (stack.size() > 1000) { throw new StackOverflowError("Deep code hierarchy"); - + } curState = curState.copy(); curState.region = region; - if (DEBUG) + if (DEBUG) { LOG.debug("Stack push: {}: {}", size(), curState); + } } public void pop() { curState = stack.pop(); - if (DEBUG) + if (DEBUG) { LOG.debug("Stack pop: {}: {}", size(), curState); + } } /** @@ -76,8 +80,9 @@ final class RegionStack { * @param exit boundary node, null will be ignored */ public void addExit(BlockNode exit) { - if (exit != null) + if (exit != null) { curState.exits.add(exit); + } } public boolean containsExit(BlockNode exit) { diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/typeresolver/FinishTypeResolver.java b/jadx-core/src/main/java/jadx/core/dex/visitors/typeresolver/FinishTypeResolver.java index 3c7f1693a..77a27f7ed 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/typeresolver/FinishTypeResolver.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/typeresolver/FinishTypeResolver.java @@ -12,31 +12,39 @@ public class FinishTypeResolver extends AbstractVisitor { @Override public void visit(MethodNode mth) { - if (mth.isNoCode()) + if (mth.isNoCode()) { return; + } boolean change; int i = 0; do { change = false; for (BlockNode block : mth.getBasicBlocks()) { - for (InsnNode insn : block.getInstructions()) - if (PostTypeResolver.visit(mth, insn)) + for (InsnNode insn : block.getInstructions()) { + if (PostTypeResolver.visit(mth, insn)) { change = true; + } + } } i++; - if (i > 1000) + if (i > 1000) { break; + } } while (change); // last chance to set correct value (just use first type from 'possible' list) - for (BlockNode block : mth.getBasicBlocks()) - for (InsnNode insn : block.getInstructions()) + for (BlockNode block : mth.getBasicBlocks()) { + for (InsnNode insn : block.getInstructions()) { SelectTypeVisitor.visit(insn); + } + } // check - for (BlockNode block : mth.getBasicBlocks()) - for (InsnNode insn : block.getInstructions()) + for (BlockNode block : mth.getBasicBlocks()) { + for (InsnNode insn : block.getInstructions()) { CheckTypeVisitor.visit(mth, insn); + } + } } } diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/typeresolver/TypeResolver.java b/jadx-core/src/main/java/jadx/core/dex/visitors/typeresolver/TypeResolver.java index 723c2a8fe..ec58a7875 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/typeresolver/TypeResolver.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/typeresolver/TypeResolver.java @@ -16,9 +16,9 @@ public class TypeResolver extends AbstractVisitor { @Override public void visit(MethodNode mth) { - if (mth.isNoCode()) + if (mth.isNoCode()) { return; - + } prepare(mth); visitBlocks(mth); @@ -60,11 +60,13 @@ public class TypeResolver extends AbstractVisitor { for (InsnNode insn : block.getInstructions()) { for (InsnArg arg : insn.getArguments()) { - if (arg.isRegister()) + if (arg.isRegister()) { state.use((RegisterArg) arg); + } } - if (insn.getResult() != null) + if (insn.getResult() != null) { state.assignReg(insn.getResult()); + } } block.setEndState(new BlockRegState(state)); @@ -78,8 +80,9 @@ public class TypeResolver extends AbstractVisitor { changed = false; for (BlockNode block : preds) { for (BlockNode pred : block.getPredecessors()) { - if (connectEdges(mth, pred, block, true)) + if (connectEdges(mth, pred, block, true)) { changed = true; + } } } } while (changed); diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/typeresolver/finish/PostTypeResolver.java b/jadx-core/src/main/java/jadx/core/dex/visitors/typeresolver/finish/PostTypeResolver.java index f6192f5c1..ae416efc8 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/typeresolver/finish/PostTypeResolver.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/typeresolver/finish/PostTypeResolver.java @@ -39,10 +39,12 @@ public class PostTypeResolver { case MOVE: { boolean change = false; - if (insn.getResult().merge(insn.getArg(0))) + if (insn.getResult().merge(insn.getArg(0))) { change = true; - if (insn.getArg(0).merge(insn.getResult())) + } + if (insn.getArg(0).merge(insn.getResult())) { change = true; + } return change; } @@ -56,10 +58,12 @@ public class PostTypeResolver { boolean change = false; IfNode ifnode = (IfNode) insn; if (!ifnode.isZeroCmp()) { - if (insn.getArg(1).merge(insn.getArg(0))) + if (insn.getArg(1).merge(insn.getArg(0))) { change = true; - if (insn.getArg(0).merge(insn.getArg(1))) + } + if (insn.getArg(0).merge(insn.getArg(1))) { change = true; + } } return change; } @@ -94,10 +98,12 @@ public class PostTypeResolver { private static boolean fixArrayTypes(InsnArg array, InsnArg elem) { boolean change = false; - if (!elem.getType().isTypeKnown() && elem.merge(array.getType().getArrayElement())) + if (!elem.getType().isTypeKnown() && elem.merge(array.getType().getArrayElement())) { change = true; - if (!array.getType().isTypeKnown() && array.merge(ArgType.array(elem.getType()))) + } + if (!array.getType().isTypeKnown() && array.merge(ArgType.array(elem.getType()))) { change = true; + } return change; } } diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/typeresolver/finish/SelectTypeVisitor.java b/jadx-core/src/main/java/jadx/core/dex/visitors/typeresolver/finish/SelectTypeVisitor.java index 4031c688b..bbeb637fb 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/typeresolver/finish/SelectTypeVisitor.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/typeresolver/finish/SelectTypeVisitor.java @@ -13,8 +13,9 @@ public class SelectTypeVisitor { } for (InsnArg arg : insn.getArguments()) { - if (!arg.getType().isTypeKnown()) + if (!arg.getType().isTypeKnown()) { selectType(arg); + } } } diff --git a/jadx-core/src/main/java/jadx/core/utils/BlockUtils.java b/jadx-core/src/main/java/jadx/core/utils/BlockUtils.java index 84b124f38..9acd815f9 100644 --- a/jadx-core/src/main/java/jadx/core/utils/BlockUtils.java +++ b/jadx-core/src/main/java/jadx/core/utils/BlockUtils.java @@ -33,25 +33,27 @@ public class BlockUtils { } assert list.size() == 2 : "too many nodes for selectOther: " + node + " in " + list; BlockNode first = list.get(0); - if (first != node) + if (first != node) { return first; - else + } else { return list.get(1); + } } private static List cleanBlockList(List list) { List ret = new ArrayList(list.size()); for (BlockNode block : list) { - if (!block.getAttributes().contains(AttributeType.EXC_HANDLER)) + if (!block.getAttributes().contains(AttributeType.EXC_HANDLER)) { ret.add(block); + } } return ret; } public static boolean isBackEdge(BlockNode from, BlockNode to) { - if (from.getCleanSuccessors().contains(to)) + if (from.getCleanSuccessors().contains(to)) { return false; // already checked - + } return from.getSuccessors().contains(to); } @@ -61,8 +63,9 @@ public class BlockUtils { public static void cleanBitSet(MethodNode mth, BitSet bs) { for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) { BlockNode block = mth.getBasicBlocks().get(i); - if (block.getAttributes().contains(AttributeType.EXC_HANDLER)) + if (block.getAttributes().contains(AttributeType.EXC_HANDLER)) { bs.clear(i); + } } } @@ -81,17 +84,18 @@ public class BlockUtils { */ public static boolean blockContains(BlockNode block, InsnNode insn) { for (InsnNode bi : block.getInstructions()) { - if (bi == insn) + if (bi == insn) { return true; + } } return false; } public static boolean lastInsnType(BlockNode block, InsnType type) { List insns = block.getInstructions(); - if (insns.isEmpty()) + if (insns.isEmpty()) { return false; - + } InsnNode insn = insns.get(insns.size() - 1); return insn.getType() == type; } @@ -99,8 +103,9 @@ public class BlockUtils { public static BlockNode getBlockByInsn(MethodNode mth, InsnNode insn) { assert insn != null; for (BlockNode bn : mth.getBasicBlocks()) { - if (blockContains(bn, insn)) + if (blockContains(bn, insn)) { return bn; + } } return null; } @@ -136,8 +141,9 @@ public class BlockUtils { public static Set getAllPathsBlocks(BlockNode start, BlockNode end) { Set set = new HashSet(); set.add(start); - if (start != end) + if (start != end) { addPredcessors(set, end, start); + } return set; } @@ -152,29 +158,29 @@ public class BlockUtils { private static boolean traverseSuccessorsUntil(BlockNode from, BlockNode until, Set checked) { for (BlockNode s : from.getCleanSuccessors()) { - if (s == until) + if (s == until) { return true; - + } if (!checked.contains(s)) { checked.add(s); - - if (until.isDominator(s)) + if (until.isDominator(s)) { return true; - - if (traverseSuccessorsUntil(s, until, checked)) + } + if (traverseSuccessorsUntil(s, until, checked)) { return true; + } } } return false; } public static boolean isPathExists(BlockNode start, BlockNode end) { - if (start == end) + if (start == end) { return true; - - if (end.isDominator(start)) + } + if (end.isDominator(start)) { return true; - + } return traverseSuccessorsUntil(start, end, new HashSet()); } @@ -203,8 +209,9 @@ public class BlockUtils { return node; } else { BlockNode out = traverseWhileDominates(block, node); - if (out != null) + if (out != null) { return out; + } } } return null; diff --git a/jadx-core/src/main/java/jadx/core/utils/ErrorsCounter.java b/jadx-core/src/main/java/jadx/core/utils/ErrorsCounter.java index b6d09ad60..1471e22aa 100644 --- a/jadx-core/src/main/java/jadx/core/utils/ErrorsCounter.java +++ b/jadx-core/src/main/java/jadx/core/utils/ErrorsCounter.java @@ -81,10 +81,11 @@ public class ErrorsCounter { } private static String formatException(Throwable e) { - if (e == null || e.getMessage() == null) + if (e == null || e.getMessage() == null) { return ""; - else + } else { return "\n error: " + e.getMessage(); + } } public static String formatErrorMsg(ClassNode cls, String msg, Throwable e) { diff --git a/jadx-core/src/main/java/jadx/core/utils/InsnUtils.java b/jadx-core/src/main/java/jadx/core/utils/InsnUtils.java index 58e240c9d..1e0442305 100644 --- a/jadx-core/src/main/java/jadx/core/utils/InsnUtils.java +++ b/jadx-core/src/main/java/jadx/core/utils/InsnUtils.java @@ -40,12 +40,13 @@ public class InsnUtils { } public static String indexToString(Object index) { - if (index == null) + if (index == null) { return ""; - - if (index instanceof String) + } + if (index instanceof String) { return "\"" + index + "\""; - else + } else { return " " + index.toString(); + } } } diff --git a/jadx-core/src/main/java/jadx/core/utils/InstructionRemover.java b/jadx-core/src/main/java/jadx/core/utils/InstructionRemover.java index 8a4ddef25..1a00ece81 100644 --- a/jadx-core/src/main/java/jadx/core/utils/InstructionRemover.java +++ b/jadx-core/src/main/java/jadx/core/utils/InstructionRemover.java @@ -32,8 +32,9 @@ public class InstructionRemover { } public static void unbindInsnList(List unbind) { - for (InsnNode rem : unbind) + for (InsnNode rem : unbind) { unbindInsn(rem); + } } public static void unbindInsn(InsnNode insn) { @@ -56,8 +57,9 @@ public class InstructionRemover { // and here can be several instructions with same content public static void removeAll(List insns, List toRemove) { if (insns == toRemove) { - for (InsnNode rem : toRemove) + for (InsnNode rem : toRemove) { unbindInsn(rem); + } return; } diff --git a/jadx-core/src/main/java/jadx/core/utils/RegionUtils.java b/jadx-core/src/main/java/jadx/core/utils/RegionUtils.java index 2c659b2da..57cec2cde 100644 --- a/jadx-core/src/main/java/jadx/core/utils/RegionUtils.java +++ b/jadx-core/src/main/java/jadx/core/utils/RegionUtils.java @@ -19,8 +19,9 @@ public class RegionUtils { } else if (container instanceof IRegion) { IRegion region = (IRegion) container; List blocks = region.getSubBlocks(); - if (blocks.isEmpty()) + if (blocks.isEmpty()) { return false; + } return hasExitEdge(blocks.get(blocks.size() - 1)); } else { throw new JadxRuntimeException("Unknown container type: " + container.getClass()); @@ -33,8 +34,9 @@ public class RegionUtils { } else if (container instanceof IRegion) { IRegion region = (IRegion) container; for (IContainer block : region.getSubBlocks()) { - if (notEmpty(block)) + if (notEmpty(block)) { return true; + } } return false; } else { @@ -61,8 +63,9 @@ public class RegionUtils { } else if (container instanceof IRegion) { IRegion region = (IRegion) container; for (IContainer b : region.getSubBlocks()) { - if (isRegionContainsBlock(b, block)) + if (isRegionContainsBlock(b, block)) { return true; + } } return false; } else { @@ -71,8 +74,9 @@ public class RegionUtils { } private static boolean isRegionContainsExcHandlerRegion(IContainer container, IRegion region) { - if (container == region) + if (container == region) { return true; + } if (container instanceof IRegion) { IRegion r = (IRegion) container; @@ -84,16 +88,19 @@ public class RegionUtils { if (cb != null && (b instanceof IRegion)) { TryCatchBlock tb = cb.getTryBlock(); for (ExceptionHandler eh : tb.getHandlers()) { - if (isRegionContainsRegion(eh.getHandlerRegion(), region)) + if (isRegionContainsRegion(eh.getHandlerRegion(), region)) { return true; + } } if (tb.getFinalBlock() != null) { - if (isRegionContainsRegion(tb.getFinalBlock(), region)) + if (isRegionContainsRegion(tb.getFinalBlock(), region)) { return true; + } } } - if (isRegionContainsRegion(b, region)) + if (isRegionContainsRegion(b, region)) { return true; + } } } return false; @@ -105,16 +112,20 @@ public class RegionUtils { * otherwise run recursive search because exception handlers can have several parents */ public static boolean isRegionContainsRegion(IContainer container, IRegion region) { - if (container == region) return true; - if (region == null) return false; - + if (container == region) { + return true; + } + if (region == null) { + return false; + } IRegion parent = region.getParent(); while (container != parent) { if (parent == null) { - if (region.getAttributes().contains(AttributeType.EXC_HANDLER)) + if (region.getAttributes().contains(AttributeType.EXC_HANDLER)) { return isRegionContainsExcHandlerRegion(container, region); - else + } else { return false; + } } region = parent; parent = region.getParent(); @@ -123,11 +134,9 @@ public class RegionUtils { } public static boolean isDominaterBy(BlockNode dom, IContainer cont) { - assert cont != null; - - if (dom == cont) + if (dom == cont) { return true; - + } if (cont instanceof BlockNode) { BlockNode block = (BlockNode) cont; return block.isDominator(dom); @@ -145,16 +154,17 @@ public class RegionUtils { } public static boolean hasPathThruBlock(BlockNode block, IContainer cont) { - if (block == cont) + if (block == cont) { return true; - + } if (cont instanceof BlockNode) { return BlockUtils.isPathExists(block, (BlockNode) cont); } else if (cont instanceof IRegion) { IRegion region = (IRegion) cont; for (IContainer c : region.getSubBlocks()) { - if (!hasPathThruBlock(block, c)) + if (!hasPathThruBlock(block, c)) { return false; + } } return true; } else { diff --git a/jadx-core/src/main/java/jadx/core/utils/StringUtils.java b/jadx-core/src/main/java/jadx/core/utils/StringUtils.java index b427629aa..2f1511be1 100644 --- a/jadx-core/src/main/java/jadx/core/utils/StringUtils.java +++ b/jadx-core/src/main/java/jadx/core/utils/StringUtils.java @@ -14,9 +14,9 @@ public class StringUtils { } public static String unescapeChar(char ch) { - if (ch == '\'') + if (ch == '\'') { return "'\\\''"; - + } StringBuilder res = new StringBuilder(); processChar(ch, res); return '\'' + res.toString() + '\''; diff --git a/jadx-core/src/main/java/jadx/core/utils/Utils.java b/jadx-core/src/main/java/jadx/core/utils/Utils.java index f1bf28e0d..0b224141f 100644 --- a/jadx-core/src/main/java/jadx/core/utils/Utils.java +++ b/jadx-core/src/main/java/jadx/core/utils/Utils.java @@ -16,10 +16,11 @@ public class Utils { public static String cleanObjectName(String obj) { int last = obj.length() - 1; - if (obj.charAt(0) == 'L' && obj.charAt(last) == ';') + if (obj.charAt(0) == 'L' && obj.charAt(last) == ';') { return obj.substring(1, last).replace('/', '.'); - else + } else { return obj; + } } public static String makeQualifiedObjectName(String obj) { @@ -61,27 +62,29 @@ public class Utils { } public static String listToString(Iterable list) { - if (list == null) + if (list == null) { return ""; - + } StringBuilder str = new StringBuilder(); for (Iterator it = list.iterator(); it.hasNext(); ) { Object o = it.next(); str.append(o); - if (it.hasNext()) + if (it.hasNext()) { str.append(", "); + } } return str.toString(); } public static String arrayToString(Object[] array) { - if (array == null) + if (array == null) { return ""; - + } StringBuilder sb = new StringBuilder(); for (int i = 0; i < array.length; i++) { - if (i != 0) + if (i != 0) { sb.append(", "); + } sb.append(array[i]); } return sb.toString(); @@ -108,11 +111,11 @@ public class Utils { int pair = 1; for (int pos = 1; pos < sign.length(); pos++) { char c = sign.charAt(pos); - if (c == '<') + if (c == '<') { pair++; - else if (c == '>') + } else if (c == '>') { pair--; - + } if (pair == 0) { end = pos; break; @@ -127,8 +130,9 @@ public class Utils { if (!dir.exists()) { // if directory already created in other thread mkdirs will return false, // so check dir existence again - if (!dir.mkdirs() && !dir.exists()) + if (!dir.mkdirs() && !dir.exists()) { throw new JadxRuntimeException("Can't create directory " + dir); + } } } } diff --git a/jadx-core/src/main/java/jadx/core/utils/files/InputFile.java b/jadx-core/src/main/java/jadx/core/utils/files/InputFile.java index e46e1bcf2..354a1bb08 100644 --- a/jadx-core/src/main/java/jadx/core/utils/files/InputFile.java +++ b/jadx-core/src/main/java/jadx/core/utils/files/InputFile.java @@ -26,7 +26,6 @@ public class InputFile { if (!file.exists()) { throw new IOException("File not found: " + file.getAbsolutePath()); } - String fileName = file.getName(); if (fileName.endsWith(".dex")) { @@ -49,8 +48,9 @@ public class InputFile { throw new DecodeException( "java class to dex conversion error:\n " + e.getMessage(), e); } - } else + } else { throw new DecodeException("Unsupported input file: " + file); + } } private byte[] openDexFromApk(File file) throws IOException { diff --git a/jadx-core/src/test/java/jadx/tests/internal/TestStringBuilderElimination.java b/jadx-core/src/test/java/jadx/tests/internal/TestStringBuilderElimination.java index 8d82eb655..4132c81bc 100644 --- a/jadx-core/src/test/java/jadx/tests/internal/TestStringBuilderElimination.java +++ b/jadx-core/src/test/java/jadx/tests/internal/TestStringBuilderElimination.java @@ -29,8 +29,8 @@ public class TestStringBuilderElimination extends InternalJadxTest { String code = cls.getCode().toString(); System.out.println(code); - assertThat(code, containsString("MyException(String str, Exception e) {")); - assertThat(code, containsString("super(\"msg:\" + str, e);")); + assertThat(code, containsString("MyException(String str, Exception e) {")); + assertThat(code, containsString("super(\"msg:\" + str, e);")); assertThat(code, not(containsString("new StringBuilder"))); assertThat(code, containsString("System.out.println(\"k=\" + k);")); diff --git a/jadx-core/src/test/java/jadx/tests/internal/TestSwitchLabels.java b/jadx-core/src/test/java/jadx/tests/internal/TestSwitchLabels.java index e88df5539..124a33a47 100644 --- a/jadx-core/src/test/java/jadx/tests/internal/TestSwitchLabels.java +++ b/jadx-core/src/test/java/jadx/tests/internal/TestSwitchLabels.java @@ -6,9 +6,7 @@ import jadx.core.dex.nodes.ClassNode; import org.junit.Test; import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.not; import static org.junit.Assert.assertThat; -import static org.mockito.AdditionalMatchers.or; public class TestSwitchLabels extends InternalJadxTest { public static class TestCls { @@ -17,6 +15,7 @@ public class TestSwitchLabels extends InternalJadxTest { public static class Inner { private static final int CONST_CDE_PRIVATE = 0xCDE; + public int f1(int arg0) { switch (arg0) { case CONST_CDE_PRIVATE: diff --git a/jadx-core/src/test/java/jadx/tests/internal/inline/TestInline3.java b/jadx-core/src/test/java/jadx/tests/internal/inline/TestInline3.java index 227e13a3c..f1d03613c 100644 --- a/jadx-core/src/test/java/jadx/tests/internal/inline/TestInline3.java +++ b/jadx-core/src/test/java/jadx/tests/internal/inline/TestInline3.java @@ -19,7 +19,7 @@ public class TestInline3 extends InternalJadxTest { public TestCls(int a1, int a2, int a3, int a4, int a5) { } - public class A extends TestCls{ + public class A extends TestCls { public A(int a) { super(a, a); }