public void load(InputStream input) throws IOException, DecodeException { try (DataInputStream in = new DataInputStream(input)) { byte[] header = new byte[JADX_CLS_SET_HEADER.length()]; int readHeaderLength = in.read(header); int version = in.readByte(); 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(); classes = new NClass[count]; for (int i = 0; i < count; i++) { String name = readString(in); classes[i] = new NClass(name, i); } for (int i = 0; i < count; i++) { int pCount = in.readByte(); NClass[] parents = new NClass[pCount]; for (int j = 0; j < pCount; j++) { parents[j] = classes[in.readInt()]; } classes[i].setParents(parents); } } }
public void addFallbackMethodCode(CodeWriter code) { if (mth.getInstructions() == null) { // load original instructions try { mth.load(); DepthTraversal.visit(new FallbackModeVisitor(), mth); } catch (DecodeException e) { LOG.error("Error reload instructions in fallback mode:", e); code.startLine("// Can't load method instructions: " + e.getMessage()); return; } } InsnNode[] insnArr = mth.getInstructions(); if (insnArr == null) { code.startLine("// Can't load method instructions."); return; } if (mth.getThisArg() != null) { code.startLine(nameGen.useArg(mth.getThisArg())).add(" = this;"); } addFallbackInsns(code, mth, insnArr, true); }
private static Dex loadFromJar(File jarFile) throws DecodeException { JavaToDex j2d = new JavaToDex(); try { LOG.info("converting to dex: {} ...", jarFile.getName()); byte[] ba = j2d.convert(jarFile.getAbsolutePath()); if (ba.length == 0) { throw new JadxException("Empty dx output"); } return new Dex(ba); } catch (Exception e) { throw new DecodeException("java class to dex conversion error:\n " + e.getMessage(), e); } finally { if (j2d.isError()) { LOG.warn("dx message: {}", j2d.getDxErrors()); } } }
public void decodeInsns(Code mthCode) throws DecodeException { short[] encodedInstructions = mthCode.getInstructions(); int size = encodedInstructions.length; DecodedInstruction[] decoded = new DecodedInstruction[size]; ShortArrayCodeInput in = new ShortArrayCodeInput(encodedInstructions); try { while (in.hasMore()) { decoded[in.cursor()] = decodeRawInsn(in); } } catch (Exception e) { throw new DecodeException(method, e.getMessage(), e); } insnArr = decoded; }
throw new DecodeException("Unsupported input file format: " + file);
public static Annotation readAnnotation(DexNode dex, Section s, boolean readVisibility) throws DecodeException { EncValueParser parser = new EncValueParser(dex, s); Visibility visibility = null; if (readVisibility) { byte v = s.readByte(); visibility = VISIBILITIES[v]; } int typeIndex = s.readUleb128(); int size = s.readUleb128(); Map<String, Object> values = new LinkedHashMap<>(size); for (int i = 0; i < size; i++) { String name = dex.getString(s.readUleb128()); values.put(name, parser.parseValue()); } ArgType type = dex.getType(typeIndex); Annotation annotation = new Annotation(visibility, type, values); if (!type.isObject()) { throw new DecodeException("Incorrect type for annotation: " + annotation); } return annotation; } }
throw new DecodeException("Unknown encoded value type: 0x" + Integer.toHexString(type));
public void test(Code mthCode) throws DecodeException { short[] encodedInstructions = mthCode.getInstructions(); int size = encodedInstructions.length; DecodedInstruction[] decoded = new DecodedInstruction[size]; ShortArrayCodeInput in = new ShortArrayCodeInput(encodedInstructions); try { while (in.hasMore()) { decoded[in.cursor()] = DecodedInstruction.decode(in); } } catch (EOFException e) { throw new DecodeException(method, "", e); } insnArr = decoded; } }
@Override public void load() throws DecodeException { try { if (noCode) { regsCount = 0; codeSize = 0; initMethodTypes(); return; } DexNode dex = parentClass.dex(); Code mthCode = dex.readCode(methodData); this.regsCount = mthCode.getRegistersSize(); initMethodTypes(); InsnDecoder decoder = new InsnDecoder(this); decoder.decodeInsns(mthCode); this.instructions = decoder.process(); this.codeSize = instructions.length; initTryCatches(this, mthCode, instructions); initJumps(instructions); this.debugInfoOffset = mthCode.getDebugInfoOffset(); } catch (Exception e) { if (!noCode) { noCode = true; // load without code load(); noCode = false; } throw new DecodeException(this, "Load method exception: " + e.getMessage(), e); } }
setLine(addr, line); } else { throw new DecodeException("Unknown debug insn code: " + c);
throw new DecodeException("Unknown instruction: '" + OpcodeInfo.getName(insn.getOpcode()) + "'");