org.jf.dexlib2.iface.reference.MethodReference Java Examples
The following examples show how to use
org.jf.dexlib2.iface.reference.MethodReference.
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 File: ReferenceUtil.java From atlas with Apache License 2.0 | 6 votes |
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 #2
Source File: MethodAnalyzer.java From HeyGirl with Apache License 2.0 | 6 votes |
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 #3
Source File: MethodInvocationInstruction.java From JAADAS with GNU General Public License v3.0 | 6 votes |
/** * 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 #4
Source File: MethodAnalyzer.java From zjdroid with Apache License 2.0 | 6 votes |
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 File: BaseMethodReference.java From ZjDroid with Apache License 2.0 | 5 votes |
@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 #6
Source File: MethodInvocationInstruction.java From JAADAS with GNU General Public License v3.0 | 5 votes |
/** * 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 #7
Source File: InstructionRewriter.java From HeyGirl with Apache License 2.0 | 5 votes |
@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 File: BuilderMethodPool.java From ZjDroid with Apache License 2.0 | 5 votes |
@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 #9
Source File: MethodPool.java From ZjDroid with Apache License 2.0 | 5 votes |
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 #10
Source File: ClassProto.java From zjdroid with Apache License 2.0 | 5 votes |
@Override @Nullable public MethodReference getMethodByVtableIndex(int vtableIndex) { List<Method> vtable = getVtable(); if (vtableIndex < 0 || vtableIndex >= vtable.size()) { return null; } return vtable.get(vtableIndex); }
Example #11
Source File: BaseMethodReference.java From ZjDroid with Apache License 2.0 | 5 votes |
@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 #12
Source File: DexPrinter.java From JAADAS with GNU General Public License v3.0 | 5 votes |
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 #13
Source File: ImmutableMethodReference.java From ZjDroid with Apache License 2.0 | 5 votes |
@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 #14
Source File: BaseMethodReference.java From HeyGirl with Apache License 2.0 | 5 votes |
@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 #15
Source File: MethodPool.java From HeyGirl with Apache License 2.0 | 5 votes |
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 #16
Source File: ImmutableMethodReference.java From HeyGirl with Apache License 2.0 | 5 votes |
@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 #17
Source File: InstructionRewriter.java From zjdroid with Apache License 2.0 | 5 votes |
@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 #18
Source File: BuilderMethodPool.java From zjdroid with Apache License 2.0 | 5 votes |
@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 #19
Source File: ProtoPool.java From zjdroid with Apache License 2.0 | 5 votes |
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 #20
Source File: ClassProto.java From HeyGirl with Apache License 2.0 | 5 votes |
@Override @Nullable public MethodReference getMethodByVtableIndex(int vtableIndex) { List<Method> vtable = getVtable(); if (vtableIndex < 0 || vtableIndex >= vtable.size()) { return null; } return vtable.get(vtableIndex); }
Example #21
Source File: MethodPool.java From zjdroid with Apache License 2.0 | 5 votes |
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 #22
Source File: DexDiffInfo.java From atlas with Apache License 2.0 | 5 votes |
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 #23
Source File: MethodInvocationInstruction.java From JAADAS with GNU General Public License v3.0 | 5 votes |
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 #24
Source File: BaseMethodReference.java From HeyGirl with Apache License 2.0 | 5 votes |
@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 #25
Source File: ReferenceUtil.java From atlas with Apache License 2.0 | 5 votes |
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 #26
Source File: InstructionWriter.java From zjdroid with Apache License 2.0 | 5 votes |
@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 #27
Source File: BaseMethodReference.java From zjdroid with Apache License 2.0 | 5 votes |
@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 #28
Source File: ProtoPool.java From HeyGirl with Apache License 2.0 | 5 votes |
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 #29
Source File: MethodAnalyzer.java From ZjDroid with Apache License 2.0 | 4 votes |
private void analyzeInvokeDirectCommon(@Nonnull AnalyzedInstruction analyzedInstruction, int objectRegister) { //the only time that an invoke instruction changes a register type is when using invoke-direct on a //constructor (<init>) method, which changes the uninitialized reference (and any register that the same //uninit reference has been copied to) to an initialized reference ReferenceInstruction instruction = (ReferenceInstruction)analyzedInstruction.instruction; MethodReference methodReference = (MethodReference)instruction.getReference(); if (!methodReference.getName().equals("<init>")) { return; } RegisterType objectRegisterType = analyzedInstruction.getPreInstructionRegisterType(objectRegister); if (objectRegisterType.category != RegisterType.UNINIT_REF && objectRegisterType.category != RegisterType.UNINIT_THIS) { return; } setPostRegisterTypeAndPropagateChanges(analyzedInstruction, objectRegister, RegisterType.getRegisterType(RegisterType.REFERENCE, objectRegisterType.type)); for (int i=0; i<analyzedInstruction.postRegisterMap.length; i++) { RegisterType postInstructionRegisterType = analyzedInstruction.postRegisterMap[i]; if (postInstructionRegisterType.category == RegisterType.UNKNOWN) { RegisterType preInstructionRegisterType = analyzedInstruction.getPreInstructionRegisterType(i); if (preInstructionRegisterType.category == RegisterType.UNINIT_REF || preInstructionRegisterType.category == RegisterType.UNINIT_THIS) { RegisterType registerType; if (preInstructionRegisterType.equals(objectRegisterType)) { registerType = analyzedInstruction.postRegisterMap[objectRegister]; } else { registerType = preInstructionRegisterType; } setPostRegisterTypeAndPropagateChanges(analyzedInstruction, i, registerType); } } } }
Example #30
Source File: SyntheticAccessorResolver.java From zjdroid with Apache License 2.0 | 4 votes |
private static boolean methodReferenceEquals(@Nonnull MethodReference ref1, @Nonnull MethodReference ref2) { // we already know the containing class matches return ref1.getName().equals(ref2.getName()) && ref1.getReturnType().equals(ref2.getReturnType()) && ref1.getParameterTypes().equals(ref2.getParameterTypes()); }