mirror of
https://github.com/skylot/jadx.git
synced 2025-03-02 18:06:02 +00:00
fix code style issues reported by sonar
This commit is contained in:
parent
37f03bcf9e
commit
e54b764588
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<String, NClass> nameMap) {
|
||||
for (NClass cls : classes) {
|
||||
nameMap.put(cls.getName(), cls);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<String, Set<String>> ancestorCache = new WeakHashMap<String, Set<String>>();
|
||||
private Map<String, NClass> nameMap;
|
||||
private Map<String, Set<String>> ancestorCache = new WeakHashMap<String, Set<String>>();
|
||||
|
||||
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<String, NClass>(arr.length);
|
||||
for (NClass cls : arr) {
|
||||
nameMap.put(cls.getName(), cls);
|
||||
}
|
||||
nameMap = new HashMap<String, NClass>(set.getClassesCount());
|
||||
set.addToMap(nameMap);
|
||||
} else {
|
||||
throw new RuntimeException("Classpath already loaded");
|
||||
throw new JadxRuntimeException("Classpath already loaded");
|
||||
}
|
||||
}
|
||||
|
||||
public void addApp(List<ClassNode> 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];
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -6,7 +6,7 @@ import java.util.Set;
|
||||
|
||||
public class NameMapper {
|
||||
|
||||
private static final Set<String> reservedNames = new HashSet<String>(
|
||||
private static final Set<String> RESERVED_NAMES = new HashSet<String>(
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -4,5 +4,5 @@ import java.util.List;
|
||||
|
||||
public interface IBlock extends IContainer {
|
||||
|
||||
public List<InsnNode> getInstructions();
|
||||
List<InsnNode> getInstructions();
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
}
|
||||
|
@ -4,8 +4,8 @@ import java.util.List;
|
||||
|
||||
public interface IRegion extends IContainer {
|
||||
|
||||
public IRegion getParent();
|
||||
IRegion getParent();
|
||||
|
||||
public List<IContainer> getSubBlocks();
|
||||
List<IContainer> getSubBlocks();
|
||||
|
||||
}
|
||||
|
@ -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<Integer> handlerSet = new HashSet<Integer>(tries.length);
|
||||
for (Try try_ : tries) {
|
||||
handlerSet.add(try_.getHandlerOffset());
|
||||
for (Try aTry : tries) {
|
||||
handlerSet.add(aTry.getHandlerOffset());
|
||||
}
|
||||
List<Integer> handlerList = new ArrayList<Integer>(catchBlocks.length);
|
||||
handlerList.addAll(handlerSet);
|
||||
@ -268,17 +268,17 @@ public class MethodNode extends LineAttrNode implements ILoadable {
|
||||
Set<Integer> addrs = new HashSet<Integer>();
|
||||
List<TryCatchBlock> catches = new ArrayList<TryCatchBlock>(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) {
|
||||
|
@ -15,7 +15,6 @@ import java.util.Map;
|
||||
public class RootNode {
|
||||
private final Map<String, ClassNode> names = new HashMap<String, ClassNode>();
|
||||
private List<DexNode> dexNodes;
|
||||
private ClspGraph clsp;
|
||||
|
||||
public void load(List<InputFile> dexFiles) throws DecodeException {
|
||||
dexNodes = new ArrayList<DexNode>(dexFiles.size());
|
||||
@ -49,7 +48,7 @@ public class RootNode {
|
||||
}
|
||||
|
||||
private void initClassPath(List<ClassNode> classes) throws IOException, DecodeException {
|
||||
clsp = new ClspGraph();
|
||||
ClspGraph clsp = new ClspGraph();
|
||||
clsp.load();
|
||||
clsp.addApp(classes);
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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<RegisterArg> 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);
|
||||
|
@ -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
|
||||
|
@ -29,7 +29,7 @@ import java.util.Set;
|
||||
public class BlockMakerVisitor extends AbstractVisitor {
|
||||
|
||||
// leave these instructions alone in block node
|
||||
private static final Set<InsnType> separateInsns = EnumSet.of(
|
||||
private static final Set<InsnType> 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<IAttribute> 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<BlockNode> 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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ import org.slf4j.LoggerFactory;
|
||||
public class ErrorsCounter {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ErrorsCounter.class);
|
||||
|
||||
private static final Set<Object> errorNodes = new HashSet<Object>();
|
||||
private static final Set<Object> ERROR_NODES = new HashSet<Object>();
|
||||
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");
|
||||
|
@ -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) {
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user