@Override public String getSignature() { return ReferenceUtil.getFieldDescriptor(field); }
@Override public String getSignature() { return ReferenceUtil.getMethodDescriptor(method); }
@Override protected void annotateItem(@Nonnull AnnotatedBytes out, int itemIndex, @Nullable String itemIdentity) { int itemType = dexFile.readUshort(out.getCursor()); out.annotate(2, "type = 0x%x: %s", itemType, ItemType.getItemTypeName(itemType)); out.annotate(2, "unused"); int size = dexFile.readSmallUint(out.getCursor()); out.annotate(4, "size = %d", size); int offset = dexFile.readSmallUint(out.getCursor()); out.annotate(4, "offset = 0x%x", offset); }
private void testForExpectedInstruction(String register0, String expectedClassName) { ExecutionGraphManipulator manipulator = getOptimizedGraph(METHOD_NAME, 0, register0, "Ljava/lang/String;"); BuilderInstruction21c instruction = (BuilderInstruction21c) manipulator.getInstruction(ADDRESS); assertEquals(Opcode.CONST_CLASS, instruction.getOpcode()); assertEquals(0, instruction.getRegisterA()); String actualClassName = ReferenceUtil.getReferenceString(instruction.getReference()); assertEquals(expectedClassName, actualClassName); } }
private static String baksmali(DexBackedClassDef def) throws IOException { baksmaliOptions opts = new baksmaliOptions(); opts.outputDebugInfo = false; opts.syntheticAccessorResolver = new SyntheticAccessorResolver(Collections.EMPTY_LIST); ClassDefinition classDefinition = new ClassDefinition(opts, def); StringWriter bufWriter = new StringWriter(); IndentingWriter writer = new IndentingWriter(bufWriter); classDefinition.writeTo((IndentingWriter) writer); writer.flush(); return bufWriter.toString(); } }
private void propagateParameterTypes(int parameterStartRegister) { int i=0; for (MethodParameter parameter: method.getParameters()) { if (TypeUtils.isWideType(parameter)) { setPostRegisterTypeAndPropagateChanges(startOfMethod, parameterStartRegister + i++, RegisterType.getWideRegisterType(parameter, true)); setPostRegisterTypeAndPropagateChanges(startOfMethod, parameterStartRegister + i++, RegisterType.getWideRegisterType(parameter, false)); } else { setPostRegisterTypeAndPropagateChanges(startOfMethod, parameterStartRegister + i++, RegisterType.getRegisterType(classPath, parameter)); } } }
public void writeAnnotations(@Nonnull Writer out, @Nonnull AnnotatedBytes annotatedBytes) throws IOException { // TODO: need to pass in the offset annotatedBytes.writeAnnotations(out, getBuf()); } }
protected ImmutableInstruction(@Nonnull Opcode opcode) { Preconditions.checkFormat(opcode, getFormat()); this.opcode = opcode; }
private int findMethodIndexInVtable(@Nonnull List<Method> vtable, MethodReference method) { for (int i=0; i<vtable.size(); i++) { Method candidate = vtable.get(i); if (MethodUtil.methodSignaturesMatch(candidate, method)) { if (!classPath.shouldCheckPackagePrivateAccess() || AnalyzedMethodUtil.canAccess(this, candidate, true, false, false)) { return i; } } } return -1; }
@Nonnull public static DexBackedDexFile fromInputStream(@Nullable Opcodes opcodes, @Nonnull InputStream is) throws IOException { DexUtil.verifyDexHeader(is); byte[] buf = ByteStreams.toByteArray(is); return new DexBackedDexFile(opcodes, buf, 0, false); }
@Nonnull public List<String> getMethodReferences() { List<String> methodReferences = Lists.newArrayList(); for (Entry<? extends MethodRefKey, Integer> methodReference: methodSection.getItems()) { methodReferences.add(ReferenceUtil.getMethodDescriptor(methodReference.getKey())); } return methodReferences; }
@Override public String toString() { return getName() + " r" + valueRegister + ", " + ReferenceUtil .getFieldDescriptor(fieldReference); }
private int findMethodIndexInVtableReverse(@Nonnull List<Method> vtable, MethodReference method) { for (int i=vtable.size() - 1; i>=0; i--) { Method candidate = vtable.get(i); if (MethodUtil.methodSignaturesMatch(candidate, method)) { if (!classPath.shouldCheckPackagePrivateAccess() || AnalyzedMethodUtil.canAccess(this, candidate, true, false, false)) { return i; } } } return -1; }
private void visitEnclosingMethod(BuilderEncodedValues.BuilderMethodEncodedValue value, ClassWriter classWriter) { BuilderMethodReference methodRef = value.getValue(); String owner = stripName(methodRef.getDefiningClass()); String name = methodRef.getName(); String descriptor = ReferenceUtil.getMethodDescriptor(methodRef).split("->")[1]; String desc = descriptor.substring(descriptor.indexOf('(')); classWriter.visitOuterClass(owner, name, desc); }
@Override public String toString() { return getName() + " r" + destRegister + ", " + ReferenceUtil.getFieldDescriptor(fieldReference); }
@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); }
@Nonnull public List<String> getFieldReferences() { List<String> fieldReferences = Lists.newArrayList(); for (Entry<? extends FieldRefKey, Integer> fieldReference: fieldSection.getItems()) { fieldReferences.add(ReferenceUtil.getFieldDescriptor(fieldReference.getKey())); } return fieldReferences; }
@Override public Op create(MethodLocation location, TIntObjectMap<MethodLocation> addressToLocation, VirtualMachine vm) { MethodLocation child = Utils.getNextLocation(location, addressToLocation); Instruction22c instr = (Instruction22c) location.getInstruction(); int destRegister = instr.getRegisterA(); int instanceRegister = instr.getRegisterB(); FieldReference reference = (FieldReference) instr.getReference(); String fieldDescriptor = ReferenceUtil.getFieldDescriptor(reference); return new IGetOp(location, child, destRegister, instanceRegister, fieldDescriptor, vm); }
@Override public Op create(MethodLocation location, TIntObjectMap<MethodLocation> addressToLocation, VirtualMachine vm) { MethodLocation child = Utils.getNextLocation(location, addressToLocation); Instruction22c instr = (Instruction22c) location.getInstruction(); int valueRegister = instr.getRegisterA(); int instanceRegister = instr.getRegisterB(); FieldReference reference = (FieldReference) instr.getReference(); String fieldDescriptor = ReferenceUtil.getFieldDescriptor(reference); return new IPutOp(location, child, valueRegister, instanceRegister, fieldDescriptor, vm); }