org.jf.dexlib2.iface.Method Java Examples
The following examples show how to use
org.jf.dexlib2.iface.Method.
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: InlineMethodResolver.java From ZjDroid with Apache License 2.0 | 6 votes |
public InlineMethodResolver_version35() { inlineMethods = new Method[] { inlineMethod(STATIC, "Lorg/apache/harmony/dalvik/NativeTestTarget;", "emptyInlineMethod", "", "V"), inlineMethod(VIRTUAL, "Ljava/lang/String;", "charAt", "I", "C"), inlineMethod(VIRTUAL, "Ljava/lang/String;", "compareTo", "Ljava/lang/String;", "I"), inlineMethod(VIRTUAL, "Ljava/lang/String;", "equals", "Ljava/lang/Object;", "Z"), inlineMethod(VIRTUAL, "Ljava/lang/String;", "length", "", "I"), inlineMethod(STATIC, "Ljava/lang/Math;", "abs", "I", "I"), inlineMethod(STATIC, "Ljava/lang/Math;", "abs", "J", "J"), inlineMethod(STATIC, "Ljava/lang/Math;", "abs", "F", "F"), inlineMethod(STATIC, "Ljava/lang/Math;", "abs", "D", "D"), inlineMethod(STATIC, "Ljava/lang/Math;", "min", "II", "I"), inlineMethod(STATIC, "Ljava/lang/Math;", "max", "II", "I"), inlineMethod(STATIC, "Ljava/lang/Math;", "sqrt", "D", "D"), inlineMethod(STATIC, "Ljava/lang/Math;", "cos", "D", "D"), inlineMethod(STATIC, "Ljava/lang/Math;", "sin", "D", "D") }; }
Example #2
Source File: MetaObjectDex.java From android-classyshark with Apache License 2.0 | 6 votes |
@Override public Iterable<? extends Method> getDirectMethods() { return new Iterable<Method>() { @Override public Iterator<Method> iterator() { return new Iterator<Method>() { @Override public boolean hasNext() { return false; } @Override public Method next() { return null; } @Override public void remove() { } }; } }; }
Example #3
Source File: InlineMethodResolver.java From ZjDroid with Apache License 2.0 | 6 votes |
public InlineMethodResolver_version35() { inlineMethods = new Method[] { inlineMethod(STATIC, "Lorg/apache/harmony/dalvik/NativeTestTarget;", "emptyInlineMethod", "", "V"), inlineMethod(VIRTUAL, "Ljava/lang/String;", "charAt", "I", "C"), inlineMethod(VIRTUAL, "Ljava/lang/String;", "compareTo", "Ljava/lang/String;", "I"), inlineMethod(VIRTUAL, "Ljava/lang/String;", "equals", "Ljava/lang/Object;", "Z"), inlineMethod(VIRTUAL, "Ljava/lang/String;", "length", "", "I"), inlineMethod(STATIC, "Ljava/lang/Math;", "abs", "I", "I"), inlineMethod(STATIC, "Ljava/lang/Math;", "abs", "J", "J"), inlineMethod(STATIC, "Ljava/lang/Math;", "abs", "F", "F"), inlineMethod(STATIC, "Ljava/lang/Math;", "abs", "D", "D"), inlineMethod(STATIC, "Ljava/lang/Math;", "min", "II", "I"), inlineMethod(STATIC, "Ljava/lang/Math;", "max", "II", "I"), inlineMethod(STATIC, "Ljava/lang/Math;", "sqrt", "D", "D"), inlineMethod(STATIC, "Ljava/lang/Math;", "cos", "D", "D"), inlineMethod(STATIC, "Ljava/lang/Math;", "sin", "D", "D") }; }
Example #4
Source File: InlineMethodResolver.java From zjdroid with Apache License 2.0 | 6 votes |
public InlineMethodResolver_version35() { inlineMethods = new Method[] { inlineMethod(STATIC, "Lorg/apache/harmony/dalvik/NativeTestTarget;", "emptyInlineMethod", "", "V"), inlineMethod(VIRTUAL, "Ljava/lang/String;", "charAt", "I", "C"), inlineMethod(VIRTUAL, "Ljava/lang/String;", "compareTo", "Ljava/lang/String;", "I"), inlineMethod(VIRTUAL, "Ljava/lang/String;", "equals", "Ljava/lang/Object;", "Z"), inlineMethod(VIRTUAL, "Ljava/lang/String;", "length", "", "I"), inlineMethod(STATIC, "Ljava/lang/Math;", "abs", "I", "I"), inlineMethod(STATIC, "Ljava/lang/Math;", "abs", "J", "J"), inlineMethod(STATIC, "Ljava/lang/Math;", "abs", "F", "F"), inlineMethod(STATIC, "Ljava/lang/Math;", "abs", "D", "D"), inlineMethod(STATIC, "Ljava/lang/Math;", "min", "II", "I"), inlineMethod(STATIC, "Ljava/lang/Math;", "max", "II", "I"), inlineMethod(STATIC, "Ljava/lang/Math;", "sqrt", "D", "D"), inlineMethod(STATIC, "Ljava/lang/Math;", "cos", "D", "D"), inlineMethod(STATIC, "Ljava/lang/Math;", "sin", "D", "D") }; }
Example #5
Source File: ReflectionMethod.java From ZjDroid with Apache License 2.0 | 6 votes |
@Nonnull @Override public List<? extends MethodParameter> getParameters() { final java.lang.reflect.Method method = this.method; return new AbstractList<MethodParameter>() { private final Class[] parameters = method.getParameterTypes(); @Override public MethodParameter get(final int index) { return new BaseMethodParameter() { @Nonnull @Override public Set<? extends Annotation> getAnnotations() { return ImmutableSet.of(); } @Nullable @Override public String getName() { return null; } @Nonnull @Override public String getType() { return ReflectionUtils.javaToDexName(parameters[index].getName()); } }; } @Override public int size() { return parameters.length; } }; }
Example #6
Source File: ReflectionMethod.java From zjdroid with Apache License 2.0 | 6 votes |
@Nonnull @Override public List<? extends MethodParameter> getParameters() { final java.lang.reflect.Method method = this.method; return new AbstractList<MethodParameter>() { private final Class[] parameters = method.getParameterTypes(); @Override public MethodParameter get(final int index) { return new BaseMethodParameter() { @Nonnull @Override public Set<? extends Annotation> getAnnotations() { return ImmutableSet.of(); } @Nullable @Override public String getName() { return null; } @Nonnull @Override public String getType() { return ReflectionUtils.javaToDexName(parameters[index].getName()); } }; } @Override public int size() { return parameters.length; } }; }
Example #7
Source File: RootBuilder.java From android-classyshark with Apache License 2.0 | 6 votes |
private void fillFromDex(File file, ClassNode rootNode) { try { DexFile dxFile = DexlibLoader.loadDexFile(file); Set<? extends ClassDef> classSet = dxFile.getClasses(); for (ClassDef o : classSet) { int methodCount = 0; for (Method method : o.getMethods()) { methodCount++; } String translatedClassName = o.getType().replaceAll("\\/", "\\.").substring(1, o.getType().length() - 1); ClassInfo classInfo = new ClassInfo(translatedClassName, methodCount); rootNode.add(classInfo); } } catch (Exception ex) { System.err.println("Error parsing Dexfile: " + file.getName() + ": " + ex.getMessage()); ex.printStackTrace(System.err); } }
Example #8
Source File: ImmutableClassDef.java From ZjDroid with Apache License 2.0 | 6 votes |
public ImmutableClassDef(@Nonnull String type, int accessFlags, @Nullable String superclass, @Nullable Collection<String> interfaces, @Nullable String sourceFile, @Nullable Collection<? extends Annotation> annotations, @Nullable Iterable<? extends Field> staticFields, @Nullable Iterable<? extends Field> instanceFields, @Nullable Iterable<? extends Method> directMethods, @Nullable Iterable<? extends Method> virtualMethods) { this.type = type; this.accessFlags = accessFlags; this.superclass = superclass; this.interfaces = interfaces==null ? ImmutableSet.<String>of() : ImmutableSet.copyOf(interfaces); this.sourceFile = sourceFile; this.annotations = ImmutableAnnotation.immutableSetOf(annotations); this.staticFields = ImmutableField.immutableSetOf(staticFields); this.instanceFields = ImmutableField.immutableSetOf(instanceFields); this.directMethods = ImmutableMethod.immutableSetOf(directMethods); this.virtualMethods = ImmutableMethod.immutableSetOf(virtualMethods); }
Example #9
Source File: ControlFlowGraph.java From CFGScanDroid with GNU General Public License v2.0 | 6 votes |
private static List<BasicBlockInstruction> getFlatMethod(Method method) { List<BasicBlockInstruction> flatMethod = new ArrayList<BasicBlockInstruction>(); MethodImplementation impl = method.getImplementation(); //List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks = null; if(impl != null) { int address = 0; for(Instruction instruction: impl.getInstructions()) { BasicBlockInstruction bbinsn = new BasicBlockInstruction(address, instruction); //System.out.print("\t" + address + "\t" + instruction.getOpcode() + "\t" + bbinsn.branch); address += instruction.getCodeUnits(); flatMethod.add(bbinsn); } //tryBlocks = impl.getTryBlocks(); } return flatMethod; }
Example #10
Source File: MetaObjectDex.java From android-classyshark with Apache License 2.0 | 6 votes |
@Override public Iterable<? extends Method> getVirtualMethods() { return new Iterable<Method>() { @Override public Iterator<Method> iterator() { return new Iterator<Method>() { @Override public boolean hasNext() { return false; } @Override public Method next() { return null; } @Override public void remove() { } }; } }; }
Example #11
Source File: ImmutableClassDef.java From zjdroid with Apache License 2.0 | 6 votes |
public ImmutableClassDef(@Nonnull String type, int accessFlags, @Nullable String superclass, @Nullable Collection<String> interfaces, @Nullable String sourceFile, @Nullable Collection<? extends Annotation> annotations, @Nullable Iterable<? extends Field> fields, @Nullable Iterable<? extends Method> methods) { if (fields == null) { fields = ImmutableList.of(); } if (methods == null) { methods = ImmutableList.of(); } this.type = type; this.accessFlags = accessFlags; this.superclass = superclass; this.interfaces = interfaces==null ? ImmutableSet.<String>of() : ImmutableSet.copyOf(interfaces); this.sourceFile = sourceFile; this.annotations = ImmutableAnnotation.immutableSetOf(annotations); this.staticFields = ImmutableField.immutableSetOf(Iterables.filter(fields, FieldUtil.FIELD_IS_STATIC)); this.instanceFields = ImmutableField.immutableSetOf(Iterables.filter(fields, FieldUtil.FIELD_IS_INSTANCE)); this.directMethods = ImmutableMethod.immutableSetOf(Iterables.filter(methods, MethodUtil.METHOD_IS_DIRECT)); this.virtualMethods = ImmutableMethod.immutableSetOf(Iterables.filter(methods, MethodUtil.METHOD_IS_VIRTUAL)); }
Example #12
Source File: ImmutableClassDef.java From zjdroid with Apache License 2.0 | 6 votes |
public ImmutableClassDef(@Nonnull String type, int accessFlags, @Nullable String superclass, @Nullable Collection<String> interfaces, @Nullable String sourceFile, @Nullable Collection<? extends Annotation> annotations, @Nullable Iterable<? extends Field> staticFields, @Nullable Iterable<? extends Field> instanceFields, @Nullable Iterable<? extends Method> directMethods, @Nullable Iterable<? extends Method> virtualMethods) { this.type = type; this.accessFlags = accessFlags; this.superclass = superclass; this.interfaces = interfaces==null ? ImmutableSet.<String>of() : ImmutableSet.copyOf(interfaces); this.sourceFile = sourceFile; this.annotations = ImmutableAnnotation.immutableSetOf(annotations); this.staticFields = ImmutableField.immutableSetOf(staticFields); this.instanceFields = ImmutableField.immutableSetOf(instanceFields); this.directMethods = ImmutableMethod.immutableSetOf(directMethods); this.virtualMethods = ImmutableMethod.immutableSetOf(virtualMethods); }
Example #13
Source File: ImmutableClassDef.java From ZjDroid with Apache License 2.0 | 6 votes |
public ImmutableClassDef(@Nonnull String type, int accessFlags, @Nullable String superclass, @Nullable Collection<String> interfaces, @Nullable String sourceFile, @Nullable Collection<? extends Annotation> annotations, @Nullable Iterable<? extends Field> fields, @Nullable Iterable<? extends Method> methods) { if (fields == null) { fields = ImmutableList.of(); } if (methods == null) { methods = ImmutableList.of(); } this.type = type; this.accessFlags = accessFlags; this.superclass = superclass; this.interfaces = interfaces==null ? ImmutableSet.<String>of() : ImmutableSet.copyOf(interfaces); this.sourceFile = sourceFile; this.annotations = ImmutableAnnotation.immutableSetOf(annotations); this.staticFields = ImmutableField.immutableSetOf(Iterables.filter(fields, FieldUtil.FIELD_IS_STATIC)); this.instanceFields = ImmutableField.immutableSetOf(Iterables.filter(fields, FieldUtil.FIELD_IS_INSTANCE)); this.directMethods = ImmutableMethod.immutableSetOf(Iterables.filter(methods, MethodUtil.METHOD_IS_DIRECT)); this.virtualMethods = ImmutableMethod.immutableSetOf(Iterables.filter(methods, MethodUtil.METHOD_IS_VIRTUAL)); }
Example #14
Source File: InlineMethodResolver.java From ZjDroid with Apache License 2.0 | 5 votes |
@Override @Nonnull public Method resolveExecuteInline(@Nonnull AnalyzedInstruction analyzedInstruction) { InlineIndexInstruction instruction = (InlineIndexInstruction)analyzedInstruction.instruction; int inlineIndex = instruction.getInlineIndex(); if (inlineIndex < 0 || inlineIndex >= inlineMethods.length) { throw new RuntimeException("Invalid inline index: " + inlineIndex); } return inlineMethods[inlineIndex]; }
Example #15
Source File: SmaliClassDetailLoader.java From PATDroid with Apache License 2.0 | 5 votes |
private MethodInfo translateMethod(ClassInfo ci, Method method, IdentityHashMap<MethodInfo, MethodImplementation> collector) { final ClassInfo retType = Dalvik.findOrCreateClass(ci.scope, method.getReturnType()); final ImmutableList<ClassInfo> paramTypes = findOrCreateClasses(ci.scope, method.getParameterTypes()); final MethodSignature signature = new MethodSignature(method.getName(), paramTypes); final FullMethodSignature fullSignature = new FullMethodSignature(retType, signature); final int accessFlags = translateAccessFlags(method.getAccessFlags()); final MethodInfo mi = new MethodInfo(ci, fullSignature, accessFlags, AccessFlags.SYNTHETIC.isSet(method.getAccessFlags())); Log.msg("Translating method: %s", mi.toString()); collector.put(mi, method.getImplementation()); return mi; }
Example #16
Source File: CustomInlineMethodResolver.java From zjdroid with Apache License 2.0 | 5 votes |
@Nonnull private Method parseAndResolveInlineMethod(@Nonnull String inlineMethod) { Matcher m = longMethodPattern.matcher(inlineMethod); if (!m.matches()) { assert false; throw new RuntimeException("Invalid method descriptor: " + inlineMethod); } String className = m.group(1); String methodName = m.group(2); Iterable<ImmutableMethodParameter> methodParams = ParamUtil.parseParamString(m.group(3)); String methodRet = m.group(4); ImmutableMethodReference methodRef = new ImmutableMethodReference(className, methodName, methodParams, methodRet); int accessFlags = 0; boolean resolved = false; TypeProto typeProto = classPath.getClass(className); if (typeProto instanceof ClassProto) { ClassDef classDef = ((ClassProto)typeProto).getClassDef(); for (Method method: classDef.getMethods()) { if (method.equals(methodRef)) { resolved = true; accessFlags = method.getAccessFlags(); break; } } } if (!resolved) { throw new RuntimeException("Cannot resolve inline method: " + inlineMethod); } return new ImmutableMethod(className, methodName, methodParams, methodRet, accessFlags, null, null); }
Example #17
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 #18
Source File: ClassDefRewriter.java From zjdroid with Apache License 2.0 | 5 votes |
@Nonnull @Override public Iterable<? extends Method> getMethods() { return new Iterable<Method>() { @Nonnull @Override public Iterator<Method> iterator() { return Iterators.concat(getDirectMethods().iterator(), getVirtualMethods().iterator()); } }; }
Example #19
Source File: ImmutableMethod.java From zjdroid with Apache License 2.0 | 5 votes |
public static ImmutableMethod of(Method method) { if (method instanceof ImmutableMethod) { return (ImmutableMethod)method; } return new ImmutableMethod( method.getDefiningClass(), method.getName(), method.getParameters(), method.getReturnType(), method.getAccessFlags(), method.getAnnotations(), method.getImplementation()); }
Example #20
Source File: CustomInlineMethodResolver.java From zjdroid with Apache License 2.0 | 5 votes |
public CustomInlineMethodResolver(@Nonnull ClassPath classPath, @Nonnull String inlineTable) { this.classPath = classPath; StringReader reader = new StringReader(inlineTable); List<String> lines = new ArrayList<String>(); BufferedReader br = new BufferedReader(reader); try { String line = br.readLine(); while (line != null) { if (line.length() > 0) { lines.add(line); } line = br.readLine(); } } catch (IOException ex) { throw new RuntimeException("Error while parsing inline table", ex); } inlineMethods = new Method[lines.size()]; for (int i=0; i<inlineMethods.length; i++) { inlineMethods[i] = parseAndResolveInlineMethod(lines.get(i)); } }
Example #21
Source File: CustomInlineMethodResolver.java From HeyGirl with Apache License 2.0 | 5 votes |
public CustomInlineMethodResolver(@Nonnull ClassPath classPath, @Nonnull String inlineTable) { this.classPath = classPath; StringReader reader = new StringReader(inlineTable); List<String> lines = new ArrayList<String>(); BufferedReader br = new BufferedReader(reader); try { String line = br.readLine(); while (line != null) { if (line.length() > 0) { lines.add(line); } line = br.readLine(); } } catch (IOException ex) { throw new RuntimeException("Error while parsing inline table", ex); } inlineMethods = new Method[lines.size()]; for (int i=0; i<inlineMethods.length; i++) { inlineMethods[i] = parseAndResolveInlineMethod(lines.get(i)); } }
Example #22
Source File: CustomInlineMethodResolver.java From ZjDroid with Apache License 2.0 | 5 votes |
@Override @Nonnull public Method resolveExecuteInline(@Nonnull AnalyzedInstruction analyzedInstruction) { InlineIndexInstruction instruction = (InlineIndexInstruction)analyzedInstruction.instruction; int methodIndex = instruction.getInlineIndex(); if (methodIndex < 0 || methodIndex >= inlineMethods.length) { throw new RuntimeException("Invalid method index: " + methodIndex); } return inlineMethods[methodIndex]; }
Example #23
Source File: CustomInlineMethodResolver.java From ZjDroid with Apache License 2.0 | 5 votes |
@Override @Nonnull public Method resolveExecuteInline(@Nonnull AnalyzedInstruction analyzedInstruction) { InlineIndexInstruction instruction = (InlineIndexInstruction)analyzedInstruction.instruction; int methodIndex = instruction.getInlineIndex(); if (methodIndex < 0 || methodIndex >= inlineMethods.length) { throw new RuntimeException("Invalid method index: " + methodIndex); } return inlineMethods[methodIndex]; }
Example #24
Source File: CustomInlineMethodResolver.java From ZjDroid with Apache License 2.0 | 5 votes |
@Nonnull private Method parseAndResolveInlineMethod(@Nonnull String inlineMethod) { Matcher m = longMethodPattern.matcher(inlineMethod); if (!m.matches()) { assert false; throw new RuntimeException("Invalid method descriptor: " + inlineMethod); } String className = m.group(1); String methodName = m.group(2); Iterable<ImmutableMethodParameter> methodParams = ParamUtil.parseParamString(m.group(3)); String methodRet = m.group(4); ImmutableMethodReference methodRef = new ImmutableMethodReference(className, methodName, methodParams, methodRet); int accessFlags = 0; boolean resolved = false; TypeProto typeProto = classPath.getClass(className); if (typeProto instanceof ClassProto) { ClassDef classDef = ((ClassProto)typeProto).getClassDef(); for (Method method: classDef.getMethods()) { if (method.equals(methodRef)) { resolved = true; accessFlags = method.getAccessFlags(); break; } } } if (!resolved) { throw new RuntimeException("Cannot resolve inline method: " + inlineMethod); } return new ImmutableMethod(className, methodName, methodParams, methodRet, accessFlags, null, null); }
Example #25
Source File: PatchMethodTool.java From atlas with Apache License 2.0 | 5 votes |
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; }
Example #26
Source File: PatchMethodTool.java From atlas with Apache License 2.0 | 5 votes |
private static boolean methodNeedsModification(@Nonnull ClassDef classDef, @Nonnull Method method, boolean isAndFix) { if (isAndFix) { return true; } else if (method.getName().equals("<init>")) { return true; } return false; }
Example #27
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 #28
Source File: ClassDefRewriter.java From ZjDroid with Apache License 2.0 | 5 votes |
@Nonnull @Override public Iterable<? extends Method> getMethods() { return new Iterable<Method>() { @Nonnull @Override public Iterator<Method> iterator() { return Iterators.concat(getDirectMethods().iterator(), getVirtualMethods().iterator()); } }; }
Example #29
Source File: ImmutableMethod.java From ZjDroid with Apache License 2.0 | 5 votes |
public static ImmutableMethod of(Method method) { if (method instanceof ImmutableMethod) { return (ImmutableMethod)method; } return new ImmutableMethod( method.getDefiningClass(), method.getName(), method.getParameters(), method.getReturnType(), method.getAccessFlags(), method.getAnnotations(), method.getImplementation()); }
Example #30
Source File: CustomInlineMethodResolver.java From HeyGirl with Apache License 2.0 | 5 votes |
@Nonnull private Method parseAndResolveInlineMethod(@Nonnull String inlineMethod) { Matcher m = longMethodPattern.matcher(inlineMethod); if (!m.matches()) { assert false; throw new RuntimeException("Invalid method descriptor: " + inlineMethod); } String className = m.group(1); String methodName = m.group(2); Iterable<ImmutableMethodParameter> methodParams = ParamUtil.parseParamString(m.group(3)); String methodRet = m.group(4); ImmutableMethodReference methodRef = new ImmutableMethodReference(className, methodName, methodParams, methodRet); int accessFlags = 0; boolean resolved = false; TypeProto typeProto = classPath.getClass(className); if (typeProto instanceof ClassProto) { ClassDef classDef = ((ClassProto)typeProto).getClassDef(); for (Method method: classDef.getMethods()) { if (method.equals(methodRef)) { resolved = true; accessFlags = method.getAccessFlags(); break; } } } if (!resolved) { throw new RuntimeException("Cannot resolve inline method: " + inlineMethod); } return new ImmutableMethod(className, methodName, methodParams, methodRet, accessFlags, null, null); }