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; }
private static void initTryCatches(MethodNode mth, Code mthCode, InsnNode[] insnByOffset) { CatchHandler[] catchBlocks = mthCode.getCatchHandlers(); Try[] tries = mthCode.getTries(); if (catchBlocks.length == 0 && tries.length == 0) { return;
@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); } }
codeOut.assertFourByteAligned(); codeOut.writeUnsignedShort(code.getRegistersSize()); codeOut.writeUnsignedShort(code.getInsSize()); codeOut.writeUnsignedShort(code.getOutsSize()); Code.Try[] tries = code.getTries(); Code.CatchHandler[] catchHandlers = code.getCatchHandlers(); codeOut.writeUnsignedShort(tries.length); int debugInfoOffset = code.getDebugInfoOffset(); if (debugInfoOffset != 0) { codeOut.writeInt(debugInfoOut.getPosition()); short[] instructions = code.getInstructions(); short[] newInstructions = instructionTransformer.transform(indexMap, instructions); codeOut.writeInt(newInstructions.length);
private Code readCode() { int registersSize = readUnsignedShort(); int insSize = readUnsignedShort(); int outsSize = readUnsignedShort(); int triesSize = readUnsignedShort(); int debugInfoOffset = readInt(); int instructionsSize = readInt(); short[] instructions = readShortArray(instructionsSize); Try[] tries; CatchHandler[] catchHandlers; if (triesSize > 0) { if (instructions.length % 2 == 1) { readShort(); // padding } /* * We can't read the tries until we've read the catch handlers. * Unfortunately they're in the opposite order in the dex file * so we need to read them out-of-order. */ Section triesSection = open(data.position()); skip(triesSize * SizeOf.TRY_ITEM); catchHandlers = readCatchHandlers(); tries = triesSection.readTries(triesSize, catchHandlers); } else { tries = new Try[0]; catchHandlers = new CatchHandler[0]; } return new Code(registersSize, insSize, outsSize, debugInfoOffset, instructions, tries, catchHandlers); }
codeOut.assertFourByteAligned(); codeOut.writeUnsignedShort(code.getRegistersSize()); codeOut.writeUnsignedShort(code.getInsSize()); codeOut.writeUnsignedShort(code.getOutsSize()); Code.Try[] tries = code.getTries(); Code.CatchHandler[] catchHandlers = code.getCatchHandlers(); codeOut.writeUnsignedShort(tries.length); int debugInfoOffset = code.getDebugInfoOffset(); if (debugInfoOffset != 0) { codeOut.writeInt(debugInfoOut.getPosition()); short[] instructions = code.getInstructions(); short[] newInstructions = instructionTransformer.transform(indexMap, instructions); codeOut.writeInt(newInstructions.length);
private Code readCode() { int registersSize = readUnsignedShort(); int insSize = readUnsignedShort(); int outsSize = readUnsignedShort(); int triesSize = readUnsignedShort(); int debugInfoOffset = readInt(); int instructionsSize = readInt(); short[] instructions = readShortArray(instructionsSize); Try[] tries; CatchHandler[] catchHandlers; if (triesSize > 0) { if (instructions.length % 2 == 1) { readShort(); // padding } /* * We can't read the tries until we've read the catch handlers. * Unfortunately they're in the opposite order in the dex file * so we need to read them out-of-order. */ Section triesSection = open(data.position()); skip(triesSize * SizeOf.TRY_ITEM); catchHandlers = readCatchHandlers(); tries = triesSection.readTries(triesSize, catchHandlers); } else { tries = new Try[0]; catchHandlers = new CatchHandler[0]; } return new Code(registersSize, insSize, outsSize, debugInfoOffset, instructions, tries, catchHandlers); }
codeOut.assertFourByteAligned(); codeOut.writeUnsignedShort(code.getRegistersSize()); codeOut.writeUnsignedShort(code.getInsSize()); codeOut.writeUnsignedShort(code.getOutsSize()); Code.Try[] tries = code.getTries(); Code.CatchHandler[] catchHandlers = code.getCatchHandlers(); codeOut.writeUnsignedShort(tries.length); int debugInfoOffset = code.getDebugInfoOffset(); if (debugInfoOffset != 0) { codeOut.writeInt(debugInfoOut.getPosition()); short[] instructions = code.getInstructions(); InstructionTransformer transformer = (in == dexA) ? aInstructionTransformer
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; } }
private Code readCode() { int registersSize = readUnsignedShort(); int insSize = readUnsignedShort(); int outsSize = readUnsignedShort(); int triesSize = readUnsignedShort(); int debugInfoOffset = readInt(); int instructionsSize = readInt(); short[] instructions = readShortArray(instructionsSize); Try[] tries; CatchHandler[] catchHandlers; if (triesSize > 0) { if (instructions.length % 2 == 1) { readShort(); // padding } /* * We can't read the tries until we've read the catch handlers. * Unfortunately they're in the opposite order in the dex file * so we need to read them out-of-order. */ Section triesSection = open(data.position()); skip(triesSize * SizeOf.TRY_ITEM); catchHandlers = readCatchHandlers(); tries = triesSection.readTries(triesSize, catchHandlers); } else { tries = new Try[0]; catchHandlers = new CatchHandler[0]; } return new Code(registersSize, insSize, outsSize, debugInfoOffset, instructions, tries, catchHandlers); }
codeReader.visitAll(dex.readCode(method).getInstructions());
codeReader.visitAll(dex.readCode(method).getInstructions());
codeReader.visitAll(dex.readCode(method).getInstructions());
/** * Prints usages to out. Returns the number of matches found. */ public int grep() { for (ClassDef classDef : dex.classDefs()) { currentClass = classDef; currentMethod = null; if (classDef.getClassDataOffset() == 0) { continue; } ClassData classData = dex.readClassData(classDef); // find the strings in encoded constants int staticValuesOffset = classDef.getStaticValuesOffset(); if (staticValuesOffset != 0) { readArray(new EncodedValueReader(dex.open(staticValuesOffset))); } // find the strings in method bodies for (ClassData.Method method : classData.allMethods()) { currentMethod = method; if (method.getCodeOffset() != 0) { codeReader.visitAll(dex.readCode(method).getInstructions()); } } } currentClass = null; currentMethod = null; return count; }
/** * Prints usages to out. Returns the number of matches found. */ public int grep() { for (ClassDef classDef : dex.classDefs()) { currentClass = classDef; currentMethod = null; if (classDef.getClassDataOffset() == 0) { continue; } ClassData classData = dex.readClassData(classDef); // find the strings in encoded constants int staticValuesOffset = classDef.getStaticValuesOffset(); if (staticValuesOffset != 0) { readArray(new EncodedValueReader(dex.open(staticValuesOffset))); } // find the strings in method bodies for (ClassData.Method method : classData.allMethods()) { currentMethod = method; if (method.getCodeOffset() != 0) { codeReader.visitAll(dex.readCode(method).getInstructions()); } } } currentClass = null; currentMethod = null; return count; }
/** * Prints usages to out. Returns the number of matches found. */ public int grep() { for (ClassDef classDef : dex.classDefs()) { currentClass = classDef; currentMethod = null; if (classDef.getClassDataOffset() == 0) { continue; } ClassData classData = dex.readClassData(classDef); // find the strings in encoded constants int staticValuesOffset = classDef.getStaticValuesOffset(); if (staticValuesOffset != 0) { readArray(new EncodedValueReader(dex.open(staticValuesOffset))); } // find the strings in method bodies for (ClassData.Method method : classData.allMethods()) { currentMethod = method; if (method.getCodeOffset() != 0) { codeReader.visitAll(dex.readCode(method).getInstructions()); } } } currentClass = null; currentMethod = null; return count; }