use of org.jf.dexlib2.iface.instruction.Instruction in project smali by JesusFreke.
the class CustomMethodInlineTableTest method testCustomMethodInlineTable_Direct.
@Test
public void testCustomMethodInlineTable_Direct() throws IOException {
List<ImmutableInstruction> instructions = Lists.newArrayList(new ImmutableInstruction35mi(Opcode.EXECUTE_INLINE, 1, 0, 0, 0, 0, 0, 0), new ImmutableInstruction10x(Opcode.RETURN_VOID));
ImmutableMethodImplementation methodImpl = new ImmutableMethodImplementation(1, instructions, null, null);
ImmutableMethod method = new ImmutableMethod("Lblah;", "blah", null, "V", AccessFlags.PRIVATE.getValue(), null, methodImpl);
ClassDef classDef = new ImmutableClassDef("Lblah;", AccessFlags.PUBLIC.getValue(), "Ljava/lang/Object;", null, null, null, null, null, ImmutableList.of(method), null);
DexFile dexFile = new ImmutableDexFile(Opcodes.getDefault(), ImmutableList.of(classDef));
ClassPathResolver resolver = new ClassPathResolver(ImmutableList.<String>of(), ImmutableList.<String>of(), ImmutableList.<String>of(), dexFile);
ClassPath classPath = new ClassPath(resolver.getResolvedClassProviders(), false, ClassPath.NOT_ART);
InlineMethodResolver inlineMethodResolver = new CustomInlineMethodResolver(classPath, "Lblah;->blah()V");
MethodAnalyzer methodAnalyzer = new MethodAnalyzer(classPath, method, inlineMethodResolver, false);
Instruction deodexedInstruction = methodAnalyzer.getInstructions().get(0);
Assert.assertEquals(Opcode.INVOKE_DIRECT, deodexedInstruction.getOpcode());
MethodReference methodReference = (MethodReference) ((Instruction35c) deodexedInstruction).getReference();
Assert.assertEquals(method, methodReference);
}
use of org.jf.dexlib2.iface.instruction.Instruction in project smali by JesusFreke.
the class FixGotoTest method testFixGotoToGoto16.
@Test
public void testFixGotoToGoto16() {
MethodImplementationBuilder builder = new MethodImplementationBuilder(1);
Label gotoTarget = builder.getLabel("gotoTarget");
builder.addInstruction(new BuilderInstruction10t(Opcode.GOTO, gotoTarget));
for (int i = 0; i < 500; i++) {
builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
}
builder.addLabel("gotoTarget");
builder.addInstruction(new BuilderInstruction10x(Opcode.RETURN_VOID));
MethodImplementation impl = builder.getMethodImplementation();
List<? extends Instruction> instructions = Lists.newArrayList(impl.getInstructions());
Assert.assertEquals(502, instructions.size());
Assert.assertEquals(Opcode.GOTO_16, instructions.get(0).getOpcode());
Assert.assertEquals(502, ((OffsetInstruction) instructions.get(0)).getCodeOffset());
}
use of org.jf.dexlib2.iface.instruction.Instruction in project smali by JesusFreke.
the class FixGotoTest method testFixGoto16ToGoto32.
@Test
public void testFixGoto16ToGoto32() {
MethodImplementationBuilder builder = new MethodImplementationBuilder(1);
Label gotoTarget = builder.getLabel("gotoTarget");
builder.addInstruction(new BuilderInstruction20t(Opcode.GOTO_16, gotoTarget));
for (int i = 0; i < 70000; i++) {
builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
}
builder.addLabel("gotoTarget");
builder.addInstruction(new BuilderInstruction10x(Opcode.RETURN_VOID));
MethodImplementation impl = builder.getMethodImplementation();
List<? extends Instruction> instructions = Lists.newArrayList(impl.getInstructions());
Assert.assertEquals(70002, instructions.size());
Assert.assertEquals(Opcode.GOTO_32, instructions.get(0).getOpcode());
Assert.assertEquals(70003, ((OffsetInstruction) instructions.get(0)).getCodeOffset());
}
use of org.jf.dexlib2.iface.instruction.Instruction in project smali by JesusFreke.
the class FixGotoTest method testFixGotoToGoto32.
@Test
public void testFixGotoToGoto32() {
MethodImplementationBuilder builder = new MethodImplementationBuilder(1);
Label gotoTarget = builder.getLabel("gotoTarget");
builder.addInstruction(new BuilderInstruction10t(Opcode.GOTO, gotoTarget));
for (int i = 0; i < 70000; i++) {
builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
}
builder.addLabel("gotoTarget");
builder.addInstruction(new BuilderInstruction10x(Opcode.RETURN_VOID));
MethodImplementation impl = builder.getMethodImplementation();
List<? extends Instruction> instructions = Lists.newArrayList(impl.getInstructions());
Assert.assertEquals(70002, instructions.size());
Assert.assertEquals(Opcode.GOTO_32, instructions.get(0).getOpcode());
Assert.assertEquals(70003, ((OffsetInstruction) instructions.get(0)).getCodeOffset());
}
use of org.jf.dexlib2.iface.instruction.Instruction in project smali by JesusFreke.
the class FixGotoTest method testFixGotoCascading.
@Test
public void testFixGotoCascading() {
MethodImplementationBuilder builder = new MethodImplementationBuilder(1);
Label goto16Target = builder.getLabel("goto16Target");
builder.addInstruction(new BuilderInstruction20t(Opcode.GOTO_16, goto16Target));
for (int i = 0; i < 1000; i++) {
builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
}
Label gotoTarget = builder.getLabel("gotoTarget");
builder.addInstruction(new BuilderInstruction10t(Opcode.GOTO, gotoTarget));
for (int i = 0; i < 499; i++) {
builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
}
builder.addLabel("gotoTarget");
for (int i = 0; i < 31265; i++) {
builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
}
builder.addLabel("goto16Target");
builder.addInstruction(new BuilderInstruction10x(Opcode.RETURN_VOID));
MethodImplementation impl = builder.getMethodImplementation();
List<? extends Instruction> instructions = Lists.newArrayList(impl.getInstructions());
Assert.assertEquals(32767, instructions.size());
Assert.assertEquals(Opcode.GOTO_32, instructions.get(0).getOpcode());
Assert.assertEquals(32769, ((OffsetInstruction) instructions.get(0)).getCodeOffset());
}
Aggregations