use of org.jf.dexlib2.builder.instruction.BuilderInstruction21c in project atlas by alibaba.
the class PatchMethodTool method modifyMethodAndFix.
private static MethodImplementation modifyMethodAndFix(@Nonnull MethodImplementation implementation, Method method) {
MutableMethodImplementation mutableImplementation = new MutableMethodImplementation(implementation);
System.out.println(mutableImplementation.getRegisterCount());
List<BuilderInstruction> instructions = mutableImplementation.getInstructions();
mutableImplementation.addInstruction(0, new BuilderInstruction21c(Opcode.CONST_STRING, 0, new ImmutableStringReference("AndFix:" + method.getDefiningClass().replace("/", "."))));
mutableImplementation.addInstruction(1, new BuilderInstruction35c(Opcode.INVOKE_STATIC, 1, 0, 0, 0, 0, 0, new ImmutableMethodReference("Landroid/util/Log;", "e", Lists.newArrayList("Ljava/lang/String;", "Ljava/lang/String;"), "I")));
return mutableImplementation;
}
use of org.jf.dexlib2.builder.instruction.BuilderInstruction21c in project atlas by alibaba.
the class PatchMethodTool method modifyMethodTpatch.
private static MethodImplementation modifyMethodTpatch(@Nonnull MethodImplementation implementation, Method method) {
MutableMethodImplementation mutableImplementation = new MutableMethodImplementation(implementation);
System.out.println(mutableImplementation.getRegisterCount());
List<BuilderInstruction> instructions = mutableImplementation.getInstructions();
boolean isModified = false;
for (int i = 0; i < instructions.size(); i++) {
isModified = false;
if (instructions.get(i).getOpcode() == Opcode.INVOKE_DIRECT) {
if (!isModified) {
mutableImplementation.addInstruction(i++, new BuilderInstruction21c(Opcode.CONST_STRING, 0, new ImmutableStringReference("tpatch:" + method.getDefiningClass().replace("/", "."))));
mutableImplementation.addInstruction(i++, new BuilderInstruction35c(Opcode.INVOKE_STATIC, 1, 0, 0, 0, 0, 0, new ImmutableMethodReference("Landroid/util/Log;", "e", Lists.newArrayList("Ljava/lang/String;", "Ljava/lang/String;"), "I")));
isModified = true;
break;
}
}
// mutableImplementation.addInstruction(instructions.get(i));
}
return mutableImplementation;
}
use of org.jf.dexlib2.builder.instruction.BuilderInstruction21c in project atlas by alibaba.
the class PatchMethodTool method modifyMethodAndFix.
private static MethodImplementation modifyMethodAndFix(@Nonnull MethodImplementation implementation, Method method) {
MutableMethodImplementation mutableImplementation = new MutableMethodImplementation(implementation);
System.out.println(mutableImplementation.getRegisterCount());
List<BuilderInstruction> instructions = mutableImplementation.getInstructions();
mutableImplementation.addInstruction(0, new BuilderInstruction21c(Opcode.CONST_STRING, 0, new ImmutableStringReference("AndFix:" + method.getDefiningClass().replace("/", "."))));
mutableImplementation.addInstruction(1, new BuilderInstruction35c(Opcode.INVOKE_STATIC, 1, 0, 0, 0, 0, 0, new ImmutableMethodReference("Landroid/util/Log;", "e", Lists.newArrayList("Ljava/lang/String;", "Ljava/lang/String;"), "I")));
return mutableImplementation;
}
use of org.jf.dexlib2.builder.instruction.BuilderInstruction21c in project atlas by alibaba.
the class PatchMethodTool method modifyMethodTpatch.
private static MethodImplementation modifyMethodTpatch(@Nonnull MethodImplementation implementation, Method method) {
MutableMethodImplementation mutableImplementation = new MutableMethodImplementation(implementation);
System.out.println(mutableImplementation.getRegisterCount());
List<BuilderInstruction> instructions = mutableImplementation.getInstructions();
boolean isModified = false;
for (int i = 0; i < instructions.size(); i++) {
isModified = false;
if (instructions.get(i).getOpcode() == Opcode.INVOKE_DIRECT) {
if (!isModified) {
mutableImplementation.addInstruction(i++, new BuilderInstruction21c(Opcode.CONST_STRING, 0, new ImmutableStringReference("tpatch:" + method.getDefiningClass().replace("/", "."))));
mutableImplementation.addInstruction(i++, new BuilderInstruction35c(Opcode.INVOKE_STATIC, 1, 0, 0, 0, 0, 0, new ImmutableMethodReference("Landroid/util/Log;", "e", Lists.newArrayList("Ljava/lang/String;", "Ljava/lang/String;"), "I")));
isModified = true;
break;
}
}
// mutableImplementation.addInstruction(instructions.get(i));
}
return mutableImplementation;
}
use of org.jf.dexlib2.builder.instruction.BuilderInstruction21c in project smali by JesusFreke.
the class JumboStringConversionTest method testJumboStringConversion.
@Test
public void testJumboStringConversion() throws IOException {
DexBuilder dexBuilder = new DexBuilder(Opcodes.getDefault());
MethodImplementationBuilder methodBuilder = new MethodImplementationBuilder(1);
for (int i = 0; i < 66000; i++) {
methodBuilder.addInstruction(new BuilderInstruction21c(Opcode.CONST_STRING, 0, dexBuilder.internStringReference(String.format("%08d", i))));
}
methodBuilder.addInstruction(new BuilderInstruction10x(Opcode.RETURN_VOID));
dexBuilder.internClassDef("Ltest;", 0, "Ljava/lang/Object;", null, null, ImmutableSet.<Annotation>of(), null, ImmutableList.of(dexBuilder.internMethod("Ltest;", "test", null, "V", 0, ImmutableSet.<Annotation>of(), ImmutableSet.of(), methodBuilder.getMethodImplementation())));
MemoryDataStore dexStore = new MemoryDataStore();
dexBuilder.writeTo(dexStore);
DexBackedDexFile dexFile = new DexBackedDexFile(Opcodes.getDefault(), dexStore.getBuffer());
ClassDef classDef = Iterables.getFirst(dexFile.getClasses(), null);
Assert.assertNotNull(classDef);
Method method = Iterables.getFirst(classDef.getMethods(), null);
Assert.assertNotNull(method);
MethodImplementation impl = method.getImplementation();
Assert.assertNotNull(impl);
List<? extends Instruction> instructions = Lists.newArrayList(impl.getInstructions());
Assert.assertEquals(66001, instructions.size());
for (int i = 0; i < 65536; i++) {
Assert.assertEquals(Opcode.CONST_STRING, instructions.get(i).getOpcode());
Assert.assertEquals(String.format("%08d", i), ((StringReference) ((ReferenceInstruction) instructions.get(i)).getReference()).getString());
}
for (int i = 65536; i < 66000; i++) {
Assert.assertEquals(Opcode.CONST_STRING_JUMBO, instructions.get(i).getOpcode());
Assert.assertEquals(String.format("%08d", i), ((StringReference) ((ReferenceInstruction) instructions.get(i)).getReference()).getString());
}
Assert.assertEquals(Opcode.RETURN_VOID, instructions.get(66000).getOpcode());
}
Aggregations