Java Code Examples for org.jf.dexlib2.iface.reference.MethodReference

The following examples show how to use org.jf.dexlib2.iface.reference.MethodReference. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: JAADAS   Author: flankerhqd   File: MethodInvocationInstruction.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Determine if register is used as floating point.
 *
 * Abstraction for static and non-static methods. Non-static methods need to ignore the first parameter (this)
 * @param isStatic if this method is static
 */
protected boolean isUsedAsFloatingPoint(DexBody body, int register, boolean isStatic) {
    MethodReference item = (MethodReference) ((ReferenceInstruction) instruction).getReference();
    List<? extends CharSequence> paramTypes = item.getParameterTypes();
    List<Integer> regs = getUsedRegistersNums();
    if (paramTypes == null)
        return false;

    for (int i = 0, j = 0; i < regs.size(); i++, j++) {
        if (!isStatic && i == 0) {
            j--;
            continue;
        }

        if (regs.get(i) == register && isFloatLike(DexType.toSoot(paramTypes.get(j).toString())))
            return true;
        if (DexType.isWide(paramTypes.get(j).toString()))
            i++;
    }
    return false;
}
 
Example #2
Source Project: atlas   Author: alibaba   File: ReferenceUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static String getMethodDescriptor(MethodReference methodReference, boolean useImplicitReference) {
    StringBuilder sb = new StringBuilder();
    if (!useImplicitReference) {
        String clazz = methodReference.getDefiningClass();//TypeGenUtil.newType(methodReference.getDefiningClass());
        sb.append(clazz);
        sb.append("->");
    }
    sb.append(methodReference.getName());
    sb.append('(');
    for (CharSequence paramType : methodReference.getParameterTypes()) {
        sb.append(paramType);
    }
    sb.append(')');
    sb.append(methodReference.getReturnType());
    return sb.toString();
}
 
Example #3
Source Project: HeyGirl   Author: mikusjelly   File: MethodAnalyzer.java    License: Apache License 2.0 6 votes vote down vote up
private void analyzeMoveResult(@Nonnull AnalyzedInstruction analyzedInstruction) {
    AnalyzedInstruction previousInstruction = analyzedInstructions.valueAt(analyzedInstruction.instructionIndex-1);
    if (!previousInstruction.instruction.getOpcode().setsResult()) {
        throw new AnalysisException(analyzedInstruction.instruction.getOpcode().name + " must occur after an " +
                "invoke-*/fill-new-array instruction");
    }

    RegisterType resultRegisterType;
    ReferenceInstruction invokeInstruction = (ReferenceInstruction)previousInstruction.instruction;
    Reference reference = invokeInstruction.getReference();

    if (reference instanceof MethodReference) {
        resultRegisterType = RegisterType.getRegisterType(classPath, ((MethodReference)reference).getReturnType());
    } else {
        resultRegisterType = RegisterType.getRegisterType(classPath, (TypeReference)reference);
    }

    setDestinationRegisterTypeAndPropagateChanges(analyzedInstruction, resultRegisterType);
}
 
Example #4
Source Project: zjdroid   Author: Miracle963   File: MethodAnalyzer.java    License: Apache License 2.0 6 votes vote down vote up
private void analyzeMoveResult(@Nonnull AnalyzedInstruction analyzedInstruction) {
    AnalyzedInstruction previousInstruction = analyzedInstructions.valueAt(analyzedInstruction.instructionIndex-1);
    if (!previousInstruction.instruction.getOpcode().setsResult()) {
        throw new AnalysisException(analyzedInstruction.instruction.getOpcode().name + " must occur after an " +
                "invoke-*/fill-new-array instruction");
    }

    RegisterType resultRegisterType;
    ReferenceInstruction invokeInstruction = (ReferenceInstruction)previousInstruction.instruction;
    Reference reference = invokeInstruction.getReference();

    if (reference instanceof MethodReference) {
        resultRegisterType = RegisterType.getRegisterType(classPath, ((MethodReference)reference).getReturnType());
    } else {
        resultRegisterType = RegisterType.getRegisterType(classPath, (TypeReference)reference);
    }

    setDestinationRegisterTypeAndPropagateChanges(analyzedInstruction, resultRegisterType);
}
 
Example #5
Source Project: ZjDroid   Author: KB5201314   File: BaseMethodReference.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(@Nullable Object o) {
    if (o != null && o instanceof MethodReference) {
        MethodReference other = (MethodReference)o;
        return getDefiningClass().equals(other.getDefiningClass()) &&
               getName().equals(other.getName()) &&
               getReturnType().equals(other.getReturnType()) &&
               CharSequenceUtils.listEquals(getParameterTypes(), other.getParameterTypes());
    }
    return false;
}
 
Example #6
Source Project: ZjDroid   Author: KB5201314   File: MethodPool.java    License: Apache License 2.0 5 votes vote down vote up
public void intern(@Nonnull MethodReference method) {
    Integer prev = internedItems.put(method, 0);
    if (prev == null) {
        typePool.intern(method.getDefiningClass());
        protoPool.intern(method);
        stringPool.intern(method.getName());
    }
}
 
Example #7
Source Project: HeyGirl   Author: mikusjelly   File: InstructionRewriter.java    License: Apache License 2.0 5 votes vote down vote up
@Override @Nonnull public Reference getReference() {
    switch (getReferenceType()) {
        case ReferenceType.TYPE:
            return RewriterUtils.rewriteTypeReference(rewriters.getTypeRewriter(),
                    (TypeReference)instruction.getReference());
        case ReferenceType.FIELD:
            return rewriters.getFieldReferenceRewriter().rewrite((FieldReference)instruction.getReference());
        case ReferenceType.METHOD:
            return rewriters.getMethodReferenceRewriter().rewrite((MethodReference)instruction.getReference());
        case ReferenceType.STRING:
            return instruction.getReference();
        default:
            throw new IllegalArgumentException();
    }
}
 
Example #8
Source Project: ZjDroid   Author: halfkiss   File: ImmutableMethodReference.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
public static ImmutableMethodReference of(@Nonnull MethodReference methodReference) {
    if (methodReference instanceof ImmutableMethodReference) {
        return (ImmutableMethodReference)methodReference;
    }
    return new ImmutableMethodReference(
            methodReference.getDefiningClass(),
            methodReference.getName(),
            methodReference.getParameterTypes(),
            methodReference.getReturnType());
}
 
Example #9
Source Project: JAADAS   Author: flankerhqd   File: MethodInvocationInstruction.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Return the SootMethodRef for the invoked method.
 *
 * @param invType The invocation type
 */
private SootMethodRef getSootMethodRef(InvocationType invType) {
	if (methodRef != null)
		return methodRef;
	
    MethodReference mItem = (MethodReference) ((ReferenceInstruction) instruction).getReference();
    String tItem = mItem.getDefiningClass();

    String className = tItem;
    Debug.printDbg("tItem: ", tItem ," class name: ", className);
      if (className.startsWith("[")) {
        className = "java.lang.Object";
      } else {
        className = dottedClassName (tItem);
      }

    SootClass sc = SootResolver.v().makeClassRef(className);
    if (invType == InvocationType.Interface && sc.isPhantom())
    	sc.setModifiers(sc.getModifiers() | Modifier.INTERFACE);
    String methodName = mItem.getName();

    Type returnType = DexType.toSoot(mItem.getReturnType());
    List<Type> parameterTypes = new ArrayList<Type>();
    List<? extends CharSequence> paramTypes = mItem.getParameterTypes();
    if (paramTypes != null)
        for (CharSequence type : paramTypes)
            parameterTypes.add(DexType.toSoot(type.toString()));

    Debug.printDbg("sc: ", sc);
    Debug.printDbg("methodName: ", methodName);
    Debug.printDbg("parameterTypes: ");
    for (Type t: parameterTypes)
      Debug.printDbg(" t: ", t);
    Debug.printDbg("returnType: ", returnType);
    Debug.printDbg("isStatic: ", invType == InvocationType.Static);
    methodRef = Scene.v().makeMethodRef(sc, methodName, parameterTypes, returnType,
    		invType == InvocationType.Static);
    
    return methodRef;
}
 
Example #10
Source Project: HeyGirl   Author: mikusjelly   File: BaseMethodReference.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(@Nullable Object o) {
    if (o != null && o instanceof MethodReference) {
        MethodReference other = (MethodReference)o;
        return getDefiningClass().equals(other.getDefiningClass()) &&
               getName().equals(other.getName()) &&
               getReturnType().equals(other.getReturnType()) &&
               CharSequenceUtils.listEquals(getParameterTypes(), other.getParameterTypes());
    }
    return false;
}
 
Example #11
Source Project: HeyGirl   Author: mikusjelly   File: ProtoPool.java    License: Apache License 2.0 5 votes vote down vote up
public void intern(@Nonnull MethodReference method) {
    // We can't use method directly, because it is likely a full MethodReference. We use a wrapper that computes
    // hashCode and equals based only on the prototype fields
    Key key = new Key(method);
    Integer prev = internedItems.put(key, 0);
    if (prev == null) {
        stringPool.intern(key.getShorty());
        typePool.intern(method.getReturnType());
        typeListPool.intern(method.getParameterTypes());
    }
}
 
Example #12
Source Project: HeyGirl   Author: mikusjelly   File: MethodPool.java    License: Apache License 2.0 5 votes vote down vote up
public void intern(@Nonnull MethodReference method) {
    Integer prev = internedItems.put(method, 0);
    if (prev == null) {
        typePool.intern(method.getDefiningClass());
        protoPool.intern(method);
        stringPool.intern(method.getName());
    }
}
 
Example #13
Source Project: atlas   Author: alibaba   File: DexDiffInfo.java    License: Apache License 2.0 5 votes vote down vote up
public static void addUsedMethods(MethodReference methodReference) {
        String className = methodReference.getDefiningClass();
//        if (Build.addClasses.contains(className.substring(1, className.length() - 1).replace('/', '.'))){
//            return;
//        }
        String method = methodReference.getName();
        String params;
        if (APatchTool.mappingMap == null) {
            params = methodReference.getParameterTypes().toString().replace(',', '|').replaceAll(" ", "");
        } else {
            params = getParamsType(methodReference.getParameterTypes());
        }


        System.out.println("add used method:" + className + "->" + method + ":" + params
                + " " + methodReference.getReturnType());

        String record = className.substring(1, className.length() - 1).replace('/', '.') + ":" +
                method + ":" + params + ":" + methodReference.getReturnType();
        if (Build.usedMethods.contains(record)) {
            return;
        }
        if (p.matcher(className).find()) {
            return;
        }
        Build.usedMethods.add(record);
    }
 
Example #14
Source Project: JAADAS   Author: flankerhqd   File: MethodInvocationInstruction.java    License: GNU General Public License v3.0 5 votes vote down vote up
public Set<Type> introducedTypes() {
    Set<Type> types = new HashSet<Type>();
    MethodReference method = (MethodReference) (((ReferenceInstruction) instruction).getReference());

    types.add(DexType.toSoot(method.getDefiningClass()));
    types.add(DexType.toSoot(method.getReturnType()));
    List<? extends CharSequence> paramTypes = method.getParameterTypes();
    if (paramTypes != null)
        for (CharSequence type : paramTypes)
            types.add(DexType.toSoot(type.toString()));

    return types;
}
 
Example #15
Source Project: HeyGirl   Author: mikusjelly   File: BaseMethodReference.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(@Nonnull MethodReference o) {
    int res = getDefiningClass().compareTo(o.getDefiningClass());
    if (res != 0) return res;
    res = getName().compareTo(o.getName());
    if (res != 0) return res;
    res = getReturnType().compareTo(o.getReturnType());
    if (res != 0) return res;
    return CollectionUtils.compareAsIterable(Ordering.usingToString(), getParameterTypes(), o.getParameterTypes());
}
 
Example #16
Source Project: atlas   Author: alibaba   File: ReferenceUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void writeMethodDescriptor(Writer writer, MethodReference methodReference,
                                         boolean useImplicitReference) throws IOException {
    if (!useImplicitReference) {
        String clazz = TypeGenUtil.newType(methodReference.getDefiningClass());
        writer.write(clazz);
        writer.write("->");
    }
    writer.write(methodReference.getName());
    writer.write('(');
    for (CharSequence paramType : methodReference.getParameterTypes()) {
        writer.write(paramType.toString());
    }
    writer.write(')');
    writer.write(methodReference.getReturnType());
}
 
Example #17
Source Project: ZjDroid   Author: halfkiss   File: BaseMethodReference.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(@Nonnull MethodReference o) {
    int res = getDefiningClass().compareTo(o.getDefiningClass());
    if (res != 0) return res;
    res = getName().compareTo(o.getName());
    if (res != 0) return res;
    res = getReturnType().compareTo(o.getReturnType());
    if (res != 0) return res;
    return CollectionUtils.compareAsIterable(Ordering.usingToString(), getParameterTypes(), o.getParameterTypes());
}
 
Example #18
Source Project: zjdroid   Author: Miracle963   File: BaseMethodReference.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(@Nonnull MethodReference o) {
    int res = getDefiningClass().compareTo(o.getDefiningClass());
    if (res != 0) return res;
    res = getName().compareTo(o.getName());
    if (res != 0) return res;
    res = getReturnType().compareTo(o.getReturnType());
    if (res != 0) return res;
    return CollectionUtils.compareAsIterable(Ordering.usingToString(), getParameterTypes(), o.getParameterTypes());
}
 
Example #19
Source Project: zjdroid   Author: Miracle963   File: InstructionWriter.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull static <StringRef extends StringReference, TypeRef extends TypeReference, FieldRefKey extends FieldReference, MethodRefKey extends MethodReference>
        InstructionWriter<StringRef, TypeRef, FieldRefKey, MethodRefKey>
        makeInstructionWriter(
            @Nonnull DexDataWriter writer,
            @Nonnull StringSection<?, StringRef> stringSection,
            @Nonnull TypeSection<?, ?, TypeRef> typeSection,
            @Nonnull FieldSection<?, ?, FieldRefKey, ?> fieldSection,
            @Nonnull MethodSection<?, ?, ?, MethodRefKey, ?> methodSection) {
    return new InstructionWriter<StringRef, TypeRef, FieldRefKey, MethodRefKey>(
            writer, stringSection, typeSection, fieldSection, methodSection);
}
 
Example #20
Source Project: zjdroid   Author: Miracle963   File: MethodPool.java    License: Apache License 2.0 5 votes vote down vote up
public void intern(@Nonnull MethodReference method) {
    Integer prev = internedItems.put(method, 0);
    if (prev == null) {
        typePool.intern(method.getDefiningClass());
        protoPool.intern(method);
        stringPool.intern(method.getName());
    }
}
 
Example #21
Source Project: HeyGirl   Author: mikusjelly   File: ClassProto.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public MethodReference getMethodByVtableIndex(int vtableIndex) {
    List<Method> vtable = getVtable();
    if (vtableIndex < 0 || vtableIndex >= vtable.size()) {
        return null;
    }

    return vtable.get(vtableIndex);
}
 
Example #22
Source Project: zjdroid   Author: Miracle963   File: ProtoPool.java    License: Apache License 2.0 5 votes vote down vote up
public void intern(@Nonnull MethodReference method) {
    // We can't use method directly, because it is likely a full MethodReference. We use a wrapper that computes
    // hashCode and equals based only on the prototype fields
    Key key = new Key(method);
    Integer prev = internedItems.put(key, 0);
    if (prev == null) {
        stringPool.intern(key.getShorty());
        typePool.intern(method.getReturnType());
        typeListPool.intern(method.getParameterTypes());
    }
}
 
Example #23
Source Project: zjdroid   Author: Miracle963   File: BuilderMethodPool.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull public BuilderMethodReference internMethod(@Nonnull MethodReference methodReference) {
    BuilderMethodReference ret = internedItems.get(methodReference);
    if (ret != null) {
        return ret;
    }

    BuilderMethodReference dexPoolMethodReference = new BuilderMethodReference(
            context.typePool.internType(methodReference.getDefiningClass()),
            context.stringPool.internString(methodReference.getName()),
            context.protoPool.internProto(methodReference));
    ret = internedItems.putIfAbsent(dexPoolMethodReference, dexPoolMethodReference);
    return ret==null?dexPoolMethodReference:ret;
}
 
Example #24
Source Project: zjdroid   Author: Miracle963   File: InstructionRewriter.java    License: Apache License 2.0 5 votes vote down vote up
@Override @Nonnull public Reference getReference() {
    switch (getReferenceType()) {
        case ReferenceType.TYPE:
            return RewriterUtils.rewriteTypeReference(rewriters.getTypeRewriter(),
                    (TypeReference)instruction.getReference());
        case ReferenceType.FIELD:
            return rewriters.getFieldReferenceRewriter().rewrite((FieldReference)instruction.getReference());
        case ReferenceType.METHOD:
            return rewriters.getMethodReferenceRewriter().rewrite((MethodReference)instruction.getReference());
        case ReferenceType.STRING:
            return instruction.getReference();
        default:
            throw new IllegalArgumentException();
    }
}
 
Example #25
Source Project: HeyGirl   Author: mikusjelly   File: ImmutableMethodReference.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
public static ImmutableMethodReference of(@Nonnull MethodReference methodReference) {
    if (methodReference instanceof ImmutableMethodReference) {
        return (ImmutableMethodReference)methodReference;
    }
    return new ImmutableMethodReference(
            methodReference.getDefiningClass(),
            methodReference.getName(),
            methodReference.getParameterTypes(),
            methodReference.getReturnType());
}
 
Example #26
Source Project: zjdroid   Author: Miracle963   File: ClassProto.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public MethodReference getMethodByVtableIndex(int vtableIndex) {
    List<Method> vtable = getVtable();
    if (vtableIndex < 0 || vtableIndex >= vtable.size()) {
        return null;
    }

    return vtable.get(vtableIndex);
}
 
Example #27
Source Project: ZjDroid   Author: halfkiss   File: BuilderMethodPool.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull public BuilderMethodReference internMethod(@Nonnull MethodReference methodReference) {
    BuilderMethodReference ret = internedItems.get(methodReference);
    if (ret != null) {
        return ret;
    }

    BuilderMethodReference dexPoolMethodReference = new BuilderMethodReference(
            context.typePool.internType(methodReference.getDefiningClass()),
            context.stringPool.internString(methodReference.getName()),
            context.protoPool.internProto(methodReference));
    ret = internedItems.putIfAbsent(dexPoolMethodReference, dexPoolMethodReference);
    return ret==null?dexPoolMethodReference:ret;
}
 
Example #28
Source Project: JAADAS   Author: flankerhqd   File: DexPrinter.java    License: GNU General Public License v3.0 5 votes vote down vote up
protected static BuilderMethodReference toMethodReference
(SootMethodRef m, DexBuilder belongingDexFile) {
 	List<String> parameters = new ArrayList<String>();
 	for (Type t : m.parameterTypes())
 		parameters.add(SootToDexUtils.getDexTypeDescriptor(t));
 	MethodReference methodRef = new ImmutableMethodReference
 			(SootToDexUtils.getDexClassName(m.declaringClass().getName()),
 			m.name(),
 			parameters,
 			SootToDexUtils.getDexTypeDescriptor(m.returnType()));
 	return belongingDexFile.internMethodReference(methodRef);
 }
 
Example #29
Source Project: ZjDroid   Author: KB5201314   File: ImmutableMethodEncodedValue.java    License: Apache License 2.0 4 votes vote down vote up
public ImmutableMethodEncodedValue(@Nonnull MethodReference value) {
    this.value = value;
}
 
Example #30
Source Project: ZjDroid   Author: halfkiss   File: PrimitiveProto.java    License: Apache License 2.0 4 votes vote down vote up
@Override
@Nullable
public MethodReference getMethodByVtableIndex(int vtableIndex) {
    return null;
}