@Nonnull private BuilderInstruction35c newBuilderInstruction35c(@Nonnull Instruction35c instruction) { return new BuilderInstruction35c( instruction.getOpcode(), instruction.getRegisterCount(), instruction.getRegisterC(), instruction.getRegisterD(), instruction.getRegisterE(), instruction.getRegisterF(), instruction.getRegisterG(), convertReference(instruction.getReference())); }
@Override boolean isUsedAsFloatingPoint(DexBody body, int register) { Instruction35c i = (Instruction35c) instruction; Type arrayType = DexType.toSoot((TypeReference) i.getReference()); return isRegisterUsed(register) && isFloatLike(arrayType); }
boolean canPeepStringInit(int address) { BuilderInstruction original = manipulator.getInstruction(address); if (original.getOpcode() != Opcode.INVOKE_DIRECT) { return false; } Instruction35c instr = (Instruction35c) original; MethodReference methodReference = (MethodReference) instr.getReference(); String methodDescriptor = ReferenceUtil.getMethodDescriptor(methodReference); if (!methodDescriptor.startsWith("Ljava/lang/String;-><init>(")) { return false; } int instanceRegister = instr.getRegisterC(); HeapItem item = manipulator.getRegisterConsensus(address, instanceRegister); if (!(item.getValue() instanceof String)) { return false; } return true; }
private void analyzeInvokeDirectEmpty(@Nonnull AnalyzedInstruction analyzedInstruction, boolean analyzeResult) { Instruction35c instruction = (Instruction35c)analyzedInstruction.instruction; Instruction35c deodexedInstruction = new ImmutableInstruction35c(Opcode.INVOKE_DIRECT, instruction.getRegisterCount(), instruction.getRegisterC(), instruction.getRegisterD(), instruction.getRegisterE(), instruction.getRegisterF(), instruction.getRegisterG(), instruction.getReference()); analyzedInstruction.setDeodexedInstruction(deodexedInstruction); if (analyzeResult) { analyzeInstruction(analyzedInstruction); } }
@Test public void invokeClassForNameForUnknownValueIsNotReplaced() { ExecutionGraphManipulator manipulator = getOptimizedGraph(METHOD_NAME, 0, new UnknownValue(), "Ljava/lang/String;"); Instruction35c instruction = (Instruction35c) manipulator.getInstruction(ADDRESS); String methodDescriptor = ReferenceUtil.getMethodDescriptor((MethodReference) instruction.getReference()); assertEquals("Ljava/lang/Class;->forName(Ljava/lang/String;)Ljava/lang/Class;", methodDescriptor); }
private boolean analyzeInvokeVirtual(@Nonnull AnalyzedInstruction analyzedInstruction, boolean isRange) { MethodReference targetMethod; if (!normalizeVirtualMethods) { return true; } if (isRange) { Instruction3rc instruction = (Instruction3rc)analyzedInstruction.instruction; targetMethod = (MethodReference)instruction.getReference(); } else { Instruction35c instruction = (Instruction35c)analyzedInstruction.instruction; targetMethod = (MethodReference)instruction.getReference(); } MethodReference replacementMethod = normalizeMethodReference(targetMethod); if (replacementMethod == null || replacementMethod.equals(targetMethod)) { return true; } Instruction deodexedInstruction; if (isRange) { Instruction3rc instruction = (Instruction3rc)analyzedInstruction.instruction; deodexedInstruction = new ImmutableInstruction3rc(instruction.getOpcode(), instruction.getStartRegister(), instruction.getRegisterCount(), replacementMethod); } else { Instruction35c instruction = (Instruction35c)analyzedInstruction.instruction; deodexedInstruction = new ImmutableInstruction35c(instruction.getOpcode(), instruction.getRegisterCount(), instruction.getRegisterC(), instruction.getRegisterD(), instruction.getRegisterE(), instruction.getRegisterF(), instruction.getRegisterG(), replacementMethod); } analyzedInstruction.setDeodexedInstruction(deodexedInstruction); return true; }
@Test public void stringInitWithUnknownValueIsNotReplaced() { VirtualType instanceType = vm.getClassManager().getVirtualType("Ljava/lang/String;"); ExecutionGraphManipulator manipulator = getOptimizedGraph(vm, METHOD_NAME, 0, new UninitializedInstance(instanceType), "Ljava/lang/String;", 1, new UnknownValue(), "[B"); Instruction35c instruction = (Instruction35c) manipulator.getInstruction(ADDRESS); String methodDescriptor = ReferenceUtil.getMethodDescriptor((MethodReference) instruction.getReference()); assertEquals("Ljava/lang/String;-><init>([B)V", methodDescriptor); }
Type t = DexType.toSoot((TypeReference) filledNewArrayInstr.getReference());
@Nonnull private BuilderInstruction35c newBuilderInstruction35c(@Nonnull Instruction35c instruction) { return new BuilderInstruction35c( instruction.getOpcode(), instruction.getRegisterCount(), instruction.getRegisterC(), instruction.getRegisterD(), instruction.getRegisterE(), instruction.getRegisterF(), instruction.getRegisterG(), instruction.getReference()); }
@Nonnull private BuilderInstruction35c newBuilderInstruction35c(@Nonnull Instruction35c instruction) { return new BuilderInstruction35c( instruction.getOpcode(), instruction.getRegisterCount(), instruction.getRegisterC(), instruction.getRegisterD(), instruction.getRegisterE(), instruction.getRegisterF(), instruction.getRegisterG(), instruction.getReference()); }
@Nonnull private BuilderInstruction35c newBuilderInstruction35c(@Nonnull Instruction35c instruction) { return new BuilderInstruction35c( instruction.getOpcode(), instruction.getRegisterCount(), instruction.getRegisterC(), instruction.getRegisterD(), instruction.getRegisterE(), instruction.getRegisterF(), instruction.getRegisterG(), instruction.getReference()); }
@Nonnull private BuilderInstruction35c newBuilderInstruction35c(@Nonnull Instruction35c instruction) { return new BuilderInstruction35c( instruction.getOpcode(), instruction.getRegisterCount(), instruction.getRegisterC(), instruction.getRegisterD(), instruction.getRegisterE(), instruction.getRegisterF(), instruction.getRegisterG(), convertReference(instruction.getReference())); }
private void analyzeInvokeDirectEmpty(@Nonnull AnalyzedInstruction analyzedInstruction, boolean analyzeResult) { Instruction35c instruction = (Instruction35c)analyzedInstruction.instruction; Instruction35c deodexedInstruction = new ImmutableInstruction35c(Opcode.INVOKE_DIRECT, instruction.getRegisterCount(), instruction.getRegisterC(), instruction.getRegisterD(), instruction.getRegisterE(), instruction.getRegisterF(), instruction.getRegisterG(), instruction.getReference()); analyzedInstruction.setDeodexedInstruction(deodexedInstruction); if (analyzeResult) { analyzeInstruction(analyzedInstruction); } }
private void analyzeInvokeDirectEmpty(@Nonnull AnalyzedInstruction analyzedInstruction, boolean analyzeResult) { Instruction35c instruction = (Instruction35c)analyzedInstruction.instruction; Instruction35c deodexedInstruction = new ImmutableInstruction35c(Opcode.INVOKE_DIRECT, instruction.getRegisterCount(), instruction.getRegisterC(), instruction.getRegisterD(), instruction.getRegisterE(), instruction.getRegisterF(), instruction.getRegisterG(), instruction.getReference()); analyzedInstruction.setDeodexedInstruction(deodexedInstruction); if (analyzeResult) { analyzeInstruction(analyzedInstruction); } }
public static ImmutableInstruction35c of(Instruction35c instruction) { if (instruction instanceof ImmutableInstruction35c) { return (ImmutableInstruction35c)instruction; } return new ImmutableInstruction35c( instruction.getOpcode(), instruction.getRegisterCount(), instruction.getRegisterC(), instruction.getRegisterD(), instruction.getRegisterE(), instruction.getRegisterF(), instruction.getRegisterG(), instruction.getReference()); }
public static ImmutableInstruction35c of(Instruction35c instruction) { if (instruction instanceof ImmutableInstruction35c) { return (ImmutableInstruction35c)instruction; } return new ImmutableInstruction35c( instruction.getOpcode(), instruction.getRegisterCount(), instruction.getRegisterC(), instruction.getRegisterD(), instruction.getRegisterE(), instruction.getRegisterF(), instruction.getRegisterG(), instruction.getReference()); }
private void verifyDexFile(DexFile dexFile) { Assert.assertEquals(1, dexFile.getClasses().size()); ClassDef cls = Lists.newArrayList(dexFile.getClasses()).get(0); Assert.assertEquals("Lcls1;", cls.getType()); Assert.assertEquals(1, Lists.newArrayList(cls.getMethods()).size()); Method method = Iterators.getNext(cls.getMethods().iterator(), null); Assert.assertEquals("method1", method.getName()); Assert.assertEquals(1, Lists.newArrayList(method.getImplementation().getInstructions()).size()); Instruction instruction = Lists.newArrayList(method.getImplementation().getInstructions().iterator()).get(0); Assert.assertEquals(Opcode.INVOKE_CUSTOM, instruction.getOpcode()); Assert.assertTrue(((Instruction35c) instruction).getReference() instanceof CallSiteReference); } }
public static ImmutableInstruction35c of(Instruction35c instruction) { if (instruction instanceof ImmutableInstruction35c) { return (ImmutableInstruction35c)instruction; } return new ImmutableInstruction35c( instruction.getOpcode(), instruction.getRegisterCount(), instruction.getRegisterC(), instruction.getRegisterD(), instruction.getRegisterE(), instruction.getRegisterF(), instruction.getRegisterG(), instruction.getReference()); }
@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); } }
@Test public void testCustomMethodInlineTable_Virtual() 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.PUBLIC.getValue(), null, methodImpl); ClassDef classDef = new ImmutableClassDef("Lblah;", AccessFlags.PUBLIC.getValue(), "Ljava/lang/Object;", null, null, null, null, null, null, ImmutableList.of(method)); 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_VIRTUAL, deodexedInstruction.getOpcode()); MethodReference methodReference = (MethodReference)((Instruction35c)deodexedInstruction).getReference(); Assert.assertEquals(method, methodReference); }