From e54b7645884cd852e4630eeda6f852e166059984 Mon Sep 17 00:00:00 2001 From: Skylot Date: Sat, 7 Dec 2013 16:11:12 +0400 Subject: [PATCH] fix code style issues reported by sonar --- .travis.yml | 3 +- jadx-cli/src/main/java/jadx/cli/JadxCLI.java | 5 +-- .../src/main/java/jadx/core/clsp/ClsSet.java | 31 +++++++++++++------ .../main/java/jadx/core/clsp/ClspGraph.java | 14 ++++----- .../java/jadx/core/codegen/CodeWriter.java | 2 +- .../java/jadx/core/codegen/MethodGen.java | 6 ++-- .../main/java/jadx/core/deobf/NameMapper.java | 4 +-- .../core/dex/attributes/AttributeType.java | 6 ++-- .../core/dex/instructions/InsnDecoder.java | 24 +++++++------- .../main/java/jadx/core/dex/nodes/IBlock.java | 2 +- .../java/jadx/core/dex/nodes/IContainer.java | 5 --- .../java/jadx/core/dex/nodes/ILoadable.java | 4 +-- .../java/jadx/core/dex/nodes/IRegion.java | 4 +-- .../java/jadx/core/dex/nodes/MethodNode.java | 22 ++++++------- .../java/jadx/core/dex/nodes/RootNode.java | 3 +- .../dex/nodes/parser/AnnotationsParser.java | 22 ++++++------- .../dex/nodes/parser/DebugInfoParser.java | 12 +++---- .../jadx/core/dex/regions/IfCondition.java | 3 +- .../core/dex/visitors/BlockMakerVisitor.java | 16 +++++----- .../dex/visitors/regions/IRegionVisitor.java | 6 ++-- .../java/jadx/core/utils/ErrorsCounter.java | 8 ++--- .../main/java/jadx/core/utils/InsnUtils.java | 3 +- .../java/jadx/core/utils/files/JavaToDex.java | 14 ++++----- .../main/java/jadx/gui/utils/OverlayIcon.java | 6 ++-- 24 files changed, 115 insertions(+), 110 deletions(-) diff --git a/.travis.yml b/.travis.yml index a4cd9f2ab..e38a36c70 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,8 @@ jdk: - openjdk6 before_install: - chmod +x gradlew -script: ./gradlew clean build dist +script: + - TERM=dumb ./gradlew clean build dist notifications: email: - skylot@gmail.com diff --git a/jadx-cli/src/main/java/jadx/cli/JadxCLI.java b/jadx-cli/src/main/java/jadx/cli/JadxCLI.java index 11dabc01f..72b13ee06 100644 --- a/jadx-cli/src/main/java/jadx/cli/JadxCLI.java +++ b/jadx-cli/src/main/java/jadx/cli/JadxCLI.java @@ -2,6 +2,7 @@ package jadx.cli; import jadx.api.Decompiler; import jadx.core.utils.ErrorsCounter; +import jadx.core.utils.exceptions.JadxException; import java.io.File; @@ -39,7 +40,7 @@ public class JadxCLI { System.exit(errorsCount); } - private static void checkArgs(JadxCLIArgs jadxArgs) throws Exception { + private static void checkArgs(JadxCLIArgs jadxArgs) throws JadxException { if (jadxArgs.getInput().isEmpty()) { LOG.error("Please specify input file"); jadxArgs.printUsage(); @@ -61,7 +62,7 @@ public class JadxCLI { jadxArgs.setOutputDir(outputDir); } if (outputDir.exists() && !outputDir.isDirectory()) { - throw new Exception("Output directory exists as file " + outputDir); + throw new JadxException("Output directory exists as file " + outputDir); } } } diff --git a/jadx-core/src/main/java/jadx/core/clsp/ClsSet.java b/jadx-core/src/main/java/jadx/core/clsp/ClsSet.java index 7b151a2af..d39672507 100644 --- a/jadx-core/src/main/java/jadx/core/clsp/ClsSet.java +++ b/jadx-core/src/main/java/jadx/core/clsp/ClsSet.java @@ -5,6 +5,7 @@ import jadx.core.dex.nodes.ClassNode; import jadx.core.dex.nodes.RootNode; import jadx.core.utils.Utils; import jadx.core.utils.exceptions.DecodeException; +import jadx.core.utils.exceptions.JadxRuntimeException; import java.io.BufferedOutputStream; import java.io.DataInputStream; @@ -39,6 +40,8 @@ public class ClsSet { private static final String JADX_CLS_SET_HEADER = "jadx-cst"; private static final int VERSION = 1; + private static final String STRING_CHARSET = "US-ASCII"; + private NClass[] classes; public void load(RootNode root) { @@ -50,7 +53,7 @@ public class ClsSet { if (cls.getAccessFlags().isPublic()) { NClass nClass = new NClass(clsRawName, k); if (names.put(clsRawName, nClass) != null) { - throw new RuntimeException("Duplicate class: " + clsRawName); + throw new JadxRuntimeException("Duplicate class: " + clsRawName); } k++; } else { @@ -113,7 +116,7 @@ public class ClsSet { outputStream.close(); } } else { - throw new RuntimeException("Unknown file format: " + outputName); + throw new JadxRuntimeException("Unknown file format: " + outputName); } } @@ -139,7 +142,7 @@ public class ClsSet { public void load() throws IOException, DecodeException { InputStream input = getClass().getResourceAsStream(CLST_FILENAME); if (input == null) { - throw new RuntimeException("Can't load classpath file: " + CLST_FILENAME); + throw new JadxRuntimeException("Can't load classpath file: " + CLST_FILENAME); } load(input); } @@ -163,16 +166,18 @@ public class ClsSet { in.close(); } } else { - throw new RuntimeException("Unknown file format: " + name); + throw new JadxRuntimeException("Unknown file format: " + name); } } public void load(InputStream input) throws IOException, DecodeException { DataInputStream in = new DataInputStream(input); byte[] header = new byte[JADX_CLS_SET_HEADER.length()]; - in.read(header); + int readHeaderLength = in.read(header); int version = in.readByte(); - if (!JADX_CLS_SET_HEADER.equals(new String(header)) || version != VERSION) { + if (readHeaderLength != JADX_CLS_SET_HEADER.length() + || !JADX_CLS_SET_HEADER.equals(new String(header, STRING_CHARSET)) + || version != VERSION) { throw new DecodeException("Wrong jadx class set header"); } int count = in.readInt(); @@ -192,7 +197,7 @@ public class ClsSet { } private void writeString(DataOutputStream out, String name) throws IOException { - byte[] bytes = name.getBytes(); + byte[] bytes = name.getBytes(STRING_CHARSET); out.writeByte(bytes.length); out.write(bytes); } @@ -209,10 +214,16 @@ public class ClsSet { count += res; } } - return new String(bytes); + return new String(bytes, STRING_CHARSET); } - public NClass[] getClasses() { - return classes; + public int getClassesCount() { + return classes.length; + } + + public void addToMap(Map nameMap) { + for (NClass cls : classes) { + nameMap.put(cls.getName(), cls); + } } } 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 50f27ba92..9795f0c17 100644 --- a/jadx-core/src/main/java/jadx/core/clsp/ClspGraph.java +++ b/jadx-core/src/main/java/jadx/core/clsp/ClspGraph.java @@ -2,6 +2,7 @@ package jadx.core.clsp; import jadx.core.dex.nodes.ClassNode; import jadx.core.utils.exceptions.DecodeException; +import jadx.core.utils.exceptions.JadxRuntimeException; import java.io.IOException; import java.util.HashMap; @@ -20,8 +21,8 @@ import org.slf4j.LoggerFactory; public class ClspGraph { private static final Logger LOG = LoggerFactory.getLogger(ClspGraph.class); + private final Map> ancestorCache = new WeakHashMap>(); private Map nameMap; - private Map> ancestorCache = new WeakHashMap>(); public void load() throws IOException, DecodeException { ClsSet set = new ClsSet(); @@ -30,20 +31,17 @@ public class ClspGraph { } public void addClasspath(ClsSet set) { - NClass[] arr = set.getClasses(); if (nameMap == null) { - nameMap = new HashMap(arr.length); - for (NClass cls : arr) { - nameMap.put(cls.getName(), cls); - } + nameMap = new HashMap(set.getClassesCount()); + set.addToMap(nameMap); } else { - throw new RuntimeException("Classpath already loaded"); + throw new JadxRuntimeException("Classpath already loaded"); } } public void addApp(List classes) { if (nameMap == null) { - throw new RuntimeException("Classpath must be loaded first"); + throw new JadxRuntimeException("Classpath must be loaded first"); } int size = classes.size(); NClass[] nClasses = new NClass[size]; 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 4e2880851..428a54825 100644 --- a/jadx-core/src/main/java/jadx/core/codegen/CodeWriter.java +++ b/jadx-core/src/main/java/jadx/core/codegen/CodeWriter.java @@ -19,7 +19,7 @@ public class CodeWriter { public static final String NL = System.getProperty("line.separator"); private static final String INDENT = "\t"; - private StringBuilder buf = new StringBuilder(); + private final StringBuilder buf = new StringBuilder(); private String indentStr; private int indent; 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 1f6990641..8ee62c40d 100644 --- a/jadx-core/src/main/java/jadx/core/codegen/MethodGen.java +++ b/jadx-core/src/main/java/jadx/core/codegen/MethodGen.java @@ -287,9 +287,9 @@ public class MethodGen { } try { if (insnGen.makeInsn(insn, code)) { - CatchAttr _catch = (CatchAttr) attrs.get(AttributeType.CATCH_BLOCK); - if (_catch != null) - code.add("\t //" + _catch); + CatchAttr catchAttr = (CatchAttr) attrs.get(AttributeType.CATCH_BLOCK); + if (catchAttr != null) + code.add("\t //" + catchAttr); } } catch (CodegenException e) { code.startLine("// error: " + insn); diff --git a/jadx-core/src/main/java/jadx/core/deobf/NameMapper.java b/jadx-core/src/main/java/jadx/core/deobf/NameMapper.java index 2e0830d1c..e354df8b1 100644 --- a/jadx-core/src/main/java/jadx/core/deobf/NameMapper.java +++ b/jadx-core/src/main/java/jadx/core/deobf/NameMapper.java @@ -6,7 +6,7 @@ import java.util.Set; public class NameMapper { - private static final Set reservedNames = new HashSet( + private static final Set RESERVED_NAMES = new HashSet( Arrays.asList(new String[]{ "abstract", "assert", @@ -64,7 +64,7 @@ public class NameMapper { })); public static boolean isReserved(String str) { - return reservedNames.contains(str); + return RESERVED_NAMES.contains(str); } } 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 dfea207c7..5933f76cc 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 @@ -29,7 +29,7 @@ public enum AttributeType { DECLARE_VARIABLE(true); - private static final int notUniqCount; + private static final int NOT_UNIQ_COUNT; private final boolean uniq; static { @@ -41,11 +41,11 @@ public enum AttributeType { if (type.notUniq()) last = i; } - notUniqCount = last + 1; + NOT_UNIQ_COUNT = last + 1; } public static int getNotUniqCount() { - return notUniqCount; + return NOT_UNIQ_COUNT; } private AttributeType(boolean isUniq) { 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 18815080f..e99a31f7e 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 @@ -146,7 +146,7 @@ public class InsnDecoder { case Opcodes.ADD_INT_LIT8: case Opcodes.ADD_INT_LIT16: - return arith_lit(insn, ArithOp.ADD, ArgType.INT); + return arithLit(insn, ArithOp.ADD, ArgType.INT); case Opcodes.SUB_INT: case Opcodes.SUB_INT_2ADDR: @@ -189,7 +189,7 @@ public class InsnDecoder { case Opcodes.MUL_INT_LIT8: case Opcodes.MUL_INT_LIT16: - return arith_lit(insn, ArithOp.MUL, ArgType.INT); + return arithLit(insn, ArithOp.MUL, ArgType.INT); case Opcodes.DIV_INT: case Opcodes.DIV_INT_2ADDR: @@ -225,11 +225,11 @@ public class InsnDecoder { case Opcodes.DIV_INT_LIT8: case Opcodes.DIV_INT_LIT16: - return arith_lit(insn, ArithOp.DIV, ArgType.INT); + return arithLit(insn, ArithOp.DIV, ArgType.INT); case Opcodes.REM_INT_LIT8: case Opcodes.REM_INT_LIT16: - return arith_lit(insn, ArithOp.REM, ArgType.INT); + return arithLit(insn, ArithOp.REM, ArgType.INT); case Opcodes.AND_INT: case Opcodes.AND_INT_2ADDR: @@ -237,11 +237,11 @@ public class InsnDecoder { case Opcodes.AND_INT_LIT8: case Opcodes.AND_INT_LIT16: - return arith_lit(insn, ArithOp.AND, ArgType.INT); + return arithLit(insn, ArithOp.AND, ArgType.INT); case Opcodes.XOR_INT_LIT8: case Opcodes.XOR_INT_LIT16: - return arith_lit(insn, ArithOp.XOR, ArgType.INT); + return arithLit(insn, ArithOp.XOR, ArgType.INT); case Opcodes.AND_LONG: case Opcodes.AND_LONG_2ADDR: @@ -253,7 +253,7 @@ public class InsnDecoder { case Opcodes.OR_INT_LIT8: case Opcodes.OR_INT_LIT16: - return arith_lit(insn, ArithOp.OR, ArgType.INT); + return arithLit(insn, ArithOp.OR, ArgType.INT); case Opcodes.XOR_INT: case Opcodes.XOR_INT_2ADDR: @@ -292,11 +292,11 @@ public class InsnDecoder { return arith(insn, ArithOp.SHR, ArgType.LONG); case Opcodes.SHL_INT_LIT8: - return arith_lit(insn, ArithOp.SHL, ArgType.INT); + return arithLit(insn, ArithOp.SHL, ArgType.INT); case Opcodes.SHR_INT_LIT8: - return arith_lit(insn, ArithOp.SHR, ArgType.INT); + return arithLit(insn, ArithOp.SHR, ArgType.INT); case Opcodes.USHR_INT_LIT8: - return arith_lit(insn, ArithOp.USHR, ArgType.INT); + return arithLit(insn, ArithOp.USHR, ArgType.INT); case Opcodes.NEG_INT: return neg(insn, ArgType.INT); @@ -585,7 +585,7 @@ public class InsnDecoder { targets = ss.getTargets(); keys = new Object[targets.length]; for (int i = 0; i < keys.length; i++) - keys[i] = ss.getKeys()[i]; + keys[i] = ss.getKeys()[i]; } // convert from relative to absolute offsets for (int i = 0; i < targets.length; i++) { @@ -661,7 +661,7 @@ public class InsnDecoder { return new ArithNode(insn, op, type, false); } - private InsnNode arith_lit(DecodedInstruction insn, ArithOp op, ArgType type) { + private InsnNode arithLit(DecodedInstruction insn, ArithOp op, ArgType type) { return new ArithNode(insn, op, type, true); } diff --git a/jadx-core/src/main/java/jadx/core/dex/nodes/IBlock.java b/jadx-core/src/main/java/jadx/core/dex/nodes/IBlock.java index 50d190ca4..9c53ed0ee 100644 --- a/jadx-core/src/main/java/jadx/core/dex/nodes/IBlock.java +++ b/jadx-core/src/main/java/jadx/core/dex/nodes/IBlock.java @@ -4,5 +4,5 @@ import java.util.List; public interface IBlock extends IContainer { - public List getInstructions(); + List getInstructions(); } diff --git a/jadx-core/src/main/java/jadx/core/dex/nodes/IContainer.java b/jadx-core/src/main/java/jadx/core/dex/nodes/IContainer.java index 076e5fe48..2f9987773 100644 --- a/jadx-core/src/main/java/jadx/core/dex/nodes/IContainer.java +++ b/jadx-core/src/main/java/jadx/core/dex/nodes/IContainer.java @@ -1,11 +1,6 @@ package jadx.core.dex.nodes; -import jadx.core.dex.attributes.AttributesList; import jadx.core.dex.attributes.IAttributeNode; public interface IContainer extends IAttributeNode { - - @Override - public AttributesList getAttributes(); - } diff --git a/jadx-core/src/main/java/jadx/core/dex/nodes/ILoadable.java b/jadx-core/src/main/java/jadx/core/dex/nodes/ILoadable.java index e7db40c33..2b883ecce 100644 --- a/jadx-core/src/main/java/jadx/core/dex/nodes/ILoadable.java +++ b/jadx-core/src/main/java/jadx/core/dex/nodes/ILoadable.java @@ -9,11 +9,11 @@ public interface ILoadable { * * @throws DecodeException */ - public void load() throws DecodeException; + void load() throws DecodeException; /** * Free resources */ - public void unload(); + void unload(); } diff --git a/jadx-core/src/main/java/jadx/core/dex/nodes/IRegion.java b/jadx-core/src/main/java/jadx/core/dex/nodes/IRegion.java index fba7129ad..91969e5cd 100644 --- a/jadx-core/src/main/java/jadx/core/dex/nodes/IRegion.java +++ b/jadx-core/src/main/java/jadx/core/dex/nodes/IRegion.java @@ -4,8 +4,8 @@ import java.util.List; public interface IRegion extends IContainer { - public IRegion getParent(); + IRegion getParent(); - public List getSubBlocks(); + List getSubBlocks(); } 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 7b678a107..c957b0f58 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 @@ -255,8 +255,8 @@ public class MethodNode extends LineAttrNode implements ILoadable { // and we don't need this mapping anymore, // but in maven repository still old version Set handlerSet = new HashSet(tries.length); - for (Try try_ : tries) { - handlerSet.add(try_.getHandlerOffset()); + for (Try aTry : tries) { + handlerSet.add(aTry.getHandlerOffset()); } List handlerList = new ArrayList(catchBlocks.length); handlerList.addAll(handlerSet); @@ -268,17 +268,17 @@ public class MethodNode extends LineAttrNode implements ILoadable { Set addrs = new HashSet(); List catches = new ArrayList(catchBlocks.length); - for (CatchHandler catch_ : catchBlocks) { + for (CatchHandler handler : catchBlocks) { TryCatchBlock tcBlock = new TryCatchBlock(); catches.add(tcBlock); - for (int i = 0; i < catch_.getAddresses().length; i++) { - int addr = catch_.getAddresses()[i]; - ClassInfo type = ClassInfo.fromDex(parentClass.dex(), catch_.getTypeIndexes()[i]); + for (int i = 0; i < handler.getAddresses().length; i++) { + int addr = handler.getAddresses()[i]; + ClassInfo type = ClassInfo.fromDex(parentClass.dex(), handler.getTypeIndexes()[i]); tcBlock.addHandler(this, addr, type); addrs.add(addr); hc++; } - int addr = catch_.getCatchAllAddress(); + int addr = handler.getCatchAllAddress(); if (addr >= 0) { tcBlock.addHandler(this, addr, null); addrs.add(addr); @@ -309,11 +309,11 @@ public class MethodNode extends LineAttrNode implements ILoadable { } // attach TRY_ENTER, TRY_LEAVE attributes to instructions - for (Try try_ : tries) { - int catchNum = handlerList.indexOf(try_.getHandlerOffset()); + for (Try aTry : tries) { + int catchNum = handlerList.indexOf(aTry.getHandlerOffset()); TryCatchBlock block = catches.get(catchNum); - int offset = try_.getStartAddress(); - int end = offset + try_.getInstructionCount() - 1; + int offset = aTry.getStartAddress(); + int end = offset + aTry.getInstructionCount() - 1; insnByOffset[offset].getAttributes().add(AttributeFlag.TRY_ENTER); while (offset <= end && offset >= 0) { 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 c3b7086a6..6ee79fada 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 @@ -15,7 +15,6 @@ import java.util.Map; public class RootNode { private final Map names = new HashMap(); private List dexNodes; - private ClspGraph clsp; public void load(List dexFiles) throws DecodeException { dexNodes = new ArrayList(dexFiles.size()); @@ -49,7 +48,7 @@ public class RootNode { } private void initClassPath(List classes) throws IOException, DecodeException { - clsp = new ClspGraph(); + ClspGraph clsp = new ClspGraph(); clsp.load(); clsp.addApp(classes); 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 21881c6f9..c826fe57f 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 @@ -26,26 +26,26 @@ public class AnnotationsParser { Section section = dex.openSection(offset); // TODO read as unsigned int - int class_annotations_off = section.readInt(); - int fields_size = section.readInt(); - int annotated_methods_size = section.readInt(); - int annotated_parameters_size = section.readInt(); + int classAnnotationsOffset = section.readInt(); + int fieldsCount = section.readInt(); + int annotatedMethodsCount = section.readInt(); + int annotatedParametersCount = section.readInt(); - if (class_annotations_off != 0) { - cls.getAttributes().add(readAnnotationSet(class_annotations_off)); + if (classAnnotationsOffset != 0) { + cls.getAttributes().add(readAnnotationSet(classAnnotationsOffset)); } - for (int i = 0; i < fields_size; i++) { + for (int i = 0; i < fieldsCount; i++) { FieldNode f = cls.searchFieldById(section.readInt()); f.getAttributes().add(readAnnotationSet(section.readInt())); } - for (int i = 0; i < annotated_methods_size; i++) { + for (int i = 0; i < annotatedMethodsCount; i++) { MethodNode m = cls.searchMethodById(section.readInt()); m.getAttributes().add(readAnnotationSet(section.readInt())); } - for (int i = 0; i < annotated_parameters_size; i++) { + for (int i = 0; i < annotatedParametersCount; i++) { MethodNode mth = cls.searchMethodById(section.readInt()); // read annotation ref list Section ss = dex.openSection(section.readInt()); @@ -72,7 +72,7 @@ public class AnnotationsParser { return new AnnotationsList(list); } - private static final Annotation.Visibility[] visibilities = new Annotation.Visibility[]{ + private static final Annotation.Visibility[] VISIBILITIES = new Annotation.Visibility[]{ Annotation.Visibility.BUILD, Annotation.Visibility.RUNTIME, Annotation.Visibility.SYSTEM @@ -82,7 +82,7 @@ public class AnnotationsParser { EncValueParser parser = new EncValueParser(dex, s); Visibility visibility = null; if (readVisibility) { - visibility = visibilities[s.readByte()]; + visibility = VISIBILITIES[s.readByte()]; } int typeIndex = s.readUleb128(); int size = s.readUleb128(); 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 5af846219..287f0eb07 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 @@ -51,11 +51,11 @@ public class DebugInfoParser { int addr = 0; int line = section.readUleb128(); - int param_size = section.readUleb128(); // exclude 'this' + int paramsCount = section.readUleb128(); // exclude 'this' List mthArgs = mth.getArguments(false); - assert param_size == mthArgs.size(); + assert paramsCount == mthArgs.size(); - for (int i = 0; i < param_size; i++) { + for (int i = 0; i < paramsCount; i++) { int id = section.readUleb128() - 1; if (id != DexNode.NO_INDEX) { String name = dex.getString(id); @@ -137,9 +137,9 @@ public class DebugInfoParser { default: { if (c >= DBG_FIRST_SPECIAL) { - int adjusted_opcode = c - DBG_FIRST_SPECIAL; - line += DBG_LINE_BASE + (adjusted_opcode % DBG_LINE_RANGE); - int addrInc = (adjusted_opcode / DBG_LINE_RANGE); + int adjustedOpcode = c - DBG_FIRST_SPECIAL; + line += DBG_LINE_BASE + (adjustedOpcode % DBG_LINE_RANGE); + int addrInc = (adjustedOpcode / DBG_LINE_RANGE); addr = addrChange(addr, addrInc, line); } else { throw new DecodeException("Unknown debug insn code: " + c); 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 2b21196c3..a6fd11d37 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 @@ -4,6 +4,7 @@ import jadx.core.dex.instructions.IfNode; import jadx.core.dex.instructions.IfOp; import jadx.core.dex.instructions.args.InsnArg; import jadx.core.dex.nodes.BlockNode; +import jadx.core.utils.exceptions.JadxRuntimeException; import java.util.ArrayList; import java.util.Arrays; @@ -131,7 +132,7 @@ public final class IfCondition { } return new IfCondition(mode == Mode.AND ? Mode.OR : Mode.AND, newArgs); } - throw new RuntimeException("Unknown mode for invert: " + mode); + throw new JadxRuntimeException("Unknown mode for invert: " + mode); } @Override diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/BlockMakerVisitor.java b/jadx-core/src/main/java/jadx/core/dex/visitors/BlockMakerVisitor.java index de1f42559..ced4b9390 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/BlockMakerVisitor.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/BlockMakerVisitor.java @@ -29,7 +29,7 @@ import java.util.Set; public class BlockMakerVisitor extends AbstractVisitor { // leave these instructions alone in block node - private static final Set separateInsns = EnumSet.of( + private static final Set SEPARATE_INSNS = EnumSet.of( InsnType.RETURN, InsnType.IF, InsnType.SWITCH, @@ -65,7 +65,7 @@ public class BlockMakerVisitor extends AbstractVisitor { if (type == InsnType.RETURN || type == InsnType.GOTO || type == InsnType.THROW - || separateInsns.contains(type)) { + || SEPARATE_INSNS.contains(type)) { if (type == InsnType.RETURN || type == InsnType.THROW) mth.addExitBlock(curBlock); @@ -77,7 +77,7 @@ public class BlockMakerVisitor extends AbstractVisitor { startNew = true; } else { type = insn.getType(); - startNew = separateInsns.contains(type); + startNew = SEPARATE_INSNS.contains(type); List pjumps = prevInsn.getAttributes().getAll(AttributeType.JUMP); if (pjumps.size() > 0) { @@ -371,10 +371,11 @@ public class BlockMakerVisitor extends AbstractVisitor { newRetBlock = startNewBlock(mth, block.getStartOffset()); newRetBlock.getAttributes().add(AttributeFlag.SYNTHETIC); - if (pred.getSuccessors().get(0) == block) { - pred.getSuccessors().set(0, newRetBlock); - } else if (pred.getSuccessors().get(1) == block){ - pred.getSuccessors().set(1, newRetBlock); + List successors = pred.getSuccessors(); + if (successors.get(0) == block) { + successors.set(0, newRetBlock); + } else if (successors.get(1) == block){ + successors.set(1, newRetBlock); } block.getPredecessors().remove(pred); newRetBlock.getPredecessors().add(pred); @@ -427,5 +428,4 @@ public class BlockMakerVisitor extends AbstractVisitor { block.getDominatesOn().clear(); } } - } diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/regions/IRegionVisitor.java b/jadx-core/src/main/java/jadx/core/dex/visitors/regions/IRegionVisitor.java index 6b1bdb81f..c586f6750 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/regions/IRegionVisitor.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/regions/IRegionVisitor.java @@ -6,10 +6,10 @@ import jadx.core.dex.nodes.MethodNode; public interface IRegionVisitor { - public void processBlock(MethodNode mth, IBlock container); + void processBlock(MethodNode mth, IBlock container); - public void enterRegion(MethodNode mth, IRegion region); + void enterRegion(MethodNode mth, IRegion region); - public void leaveRegion(MethodNode mth, IRegion region); + void leaveRegion(MethodNode mth, IRegion region); } 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 3f1a2988e..b6d09ad60 100644 --- a/jadx-core/src/main/java/jadx/core/utils/ErrorsCounter.java +++ b/jadx-core/src/main/java/jadx/core/utils/ErrorsCounter.java @@ -15,7 +15,7 @@ import org.slf4j.LoggerFactory; public class ErrorsCounter { private static final Logger LOG = LoggerFactory.getLogger(ErrorsCounter.class); - private static final Set errorNodes = new HashSet(); + private static final Set ERROR_NODES = new HashSet(); private static int errorsCount = 0; public static int getErrorCount() { @@ -23,12 +23,12 @@ public class ErrorsCounter { } public static void reset() { - errorNodes.clear(); + ERROR_NODES.clear(); errorsCount = 0; } private static void addError(IAttributeNode node, String msg, Throwable e) { - errorNodes.add(node); + ERROR_NODES.add(node); errorsCount++; if (e != null) { @@ -65,7 +65,7 @@ public class ErrorsCounter { public static void printReport() { if (getErrorCount() > 0) { LOG.error(getErrorCount() + " errors occured in following nodes:"); - for (Object node : errorNodes) { + for (Object node : ERROR_NODES) { LOG.error(" " + node.getClass().getSimpleName() + ": " + node); } // LOG.error("You can run jadx with '-f' option to view low level instructions"); 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 a263dede1..58e240c9d 100644 --- a/jadx-core/src/main/java/jadx/core/utils/InsnUtils.java +++ b/jadx-core/src/main/java/jadx/core/utils/InsnUtils.java @@ -1,6 +1,7 @@ package jadx.core.utils; import jadx.core.dex.instructions.InsnType; +import jadx.core.utils.exceptions.JadxRuntimeException; import com.android.dx.io.instructions.DecodedInstruction; @@ -19,7 +20,7 @@ public class InsnUtils { case 4: return insn.getE(); } - throw new RuntimeException("Wrong argument number: " + arg); + throw new JadxRuntimeException("Wrong argument number: " + arg); } public static String formatOffset(int offset) { diff --git a/jadx-core/src/main/java/jadx/core/utils/files/JavaToDex.java b/jadx-core/src/main/java/jadx/core/utils/files/JavaToDex.java index 831a3d14e..6d7d9301d 100644 --- a/jadx-core/src/main/java/jadx/core/utils/files/JavaToDex.java +++ b/jadx-core/src/main/java/jadx/core/utils/files/JavaToDex.java @@ -26,11 +26,10 @@ public class JavaToDex { private String dxErrors; public byte[] convert(String javaFile) throws JadxException { + ByteArrayOutputStream errOut = new ByteArrayOutputStream(); + DxConsole.err = new PrintStream(errOut); - ByteArrayOutputStream err_out = new ByteArrayOutputStream(); - DxConsole.err = new PrintStream(err_out); - - PrintStream old_out = System.out; + PrintStream oldOut = System.out; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { System.setOut(new PrintStream(baos)); @@ -40,11 +39,10 @@ public class JavaToDex { } catch (Throwable e) { throw new JadxException("dx exception: " + e.getMessage(), e); } finally { - System.setOut(old_out); + System.setOut(oldOut); } - - // err_out also contains warnings - dxErrors = err_out.toString(); + // errOut also contains warnings + dxErrors = errOut.toString(); return baos.toByteArray(); } diff --git a/jadx-gui/src/main/java/jadx/gui/utils/OverlayIcon.java b/jadx-gui/src/main/java/jadx/gui/utils/OverlayIcon.java index 2fd8b1eac..ddb6e0550 100644 --- a/jadx-gui/src/main/java/jadx/gui/utils/OverlayIcon.java +++ b/jadx-gui/src/main/java/jadx/gui/utils/OverlayIcon.java @@ -13,7 +13,7 @@ public class OverlayIcon implements Icon { private static final double A = 0.8; private static final double B = 0.2; - private static final double[] pos = new double[]{A, B, B, B, A, A, B, A}; + private static final double[] OVERLAY_POS = new double[]{A, B, B, B, A, A, B, A}; public OverlayIcon(Icon icon) { this.icon = icon; @@ -37,8 +37,8 @@ public class OverlayIcon implements Icon { icon.paintIcon(c, g, x, y); int k = 0; for (Icon icon : icons) { - int dx = (int) (pos[k++] * (w - icon.getIconWidth())); - int dy = (int) (pos[k++] * (h - icon.getIconHeight())); + int dx = (int) (OVERLAY_POS[k++] * (w - icon.getIconWidth())); + int dy = (int) (OVERLAY_POS[k++] * (h - icon.getIconHeight())); icon.paintIcon(c, g, x + dx, y + dy); } }