Java Code Examples for org.jf.dexlib2.iface.MethodParameter

The following examples show how to use org.jf.dexlib2.iface.MethodParameter. 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: ZjDroid   Source File: DexBuilder.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull public BuilderMethod internMethod(@Nonnull String definingClass,
                                           @Nonnull String name,
                                           @Nullable List<? extends MethodParameter> parameters,
                                           @Nonnull String returnType,
                                           int accessFlags,
                                           @Nonnull Set<? extends Annotation> annotations,
                                           @Nullable MethodImplementation methodImplementation) {
    if (parameters == null) {
        parameters = ImmutableList.of();
    }
    return new BuilderMethod(context.methodPool.internMethod(definingClass, name, parameters, returnType),
            internMethodParameters(parameters),
            accessFlags,
            context.annotationSetPool.internAnnotationSet(annotations),
            methodImplementation);
}
 
Example 2
Source Project: ZjDroid   Source File: ReflectionConstructor.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull @Override public List<? extends MethodParameter> getParameters() {
    final Constructor method = this.constructor;
    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 3
Source Project: ZjDroid   Source File: ReflectionMethod.java    License: Apache License 2.0 6 votes vote down vote up
@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 4
Source Project: ZjDroid   Source File: DexBackedMethod.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public List<? extends MethodParameter> getParameters() {
    int parametersOffset = getParametersOffset();
    if (parametersOffset > 0) {
        final List<String> parameterTypes = getParameterTypes();

        return new AbstractForwardSequentialList<MethodParameter>() {
            @Nonnull @Override public Iterator<MethodParameter> iterator() {
                return new ParameterIterator(parameterTypes,
                        getParameterAnnotations(),
                        getParameterNames());
            }

            @Override public int size() {
                return parameterTypes.size();
            }
        };
    }
    return ImmutableList.of();
}
 
Example 5
Source Project: ZjDroid   Source File: ParameterIterator.java    License: Apache License 2.0 6 votes vote down vote up
@Override public MethodParameter next() {
    @Nonnull final String type = parameterTypes.next().toString();
    @Nonnull final Set<? extends Annotation> annotations;
    @Nullable final String name;

    if (parameterAnnotations.hasNext()) {
        annotations = parameterAnnotations.next();
    } else {
        annotations = ImmutableSet.of();
    }

    if (parameterNames.hasNext()) {
        name = parameterNames.next();
    } else {
        name = null;
    }

    return new BaseMethodParameter() {
        @Nonnull @Override public Set<? extends Annotation> getAnnotations() { return annotations; }
        @Nullable @Override public String getName() { return name; }
        @Nonnull @Override public String getType() { return type; }
    };
}
 
Example 6
Source Project: atlas   Source File: MethodImplReIClassDef.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected Iterable<? extends MethodParameter> reParameters(final List<? extends MethodParameter> paramters) {
    final List<ImmutableMethodParameter> list = new ArrayList<ImmutableMethodParameter>();
    for (MethodParameter methodParameter : paramters) {
        boolean isBasic = false;
        if (basicType.containsKey(methodParameter.getType())) {
            isBasic = true;
        }
        list.add(new ImmutableMethodParameter(
                isBasic ? methodParameter.getType() : DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(methodParameter.getType())).className,methodParameter.getType().startsWith("[")),
                methodParameter.getAnnotations(), methodParameter.getName()));
    }
    return new Iterable<ImmutableMethodParameter>() {
        @Override
        public Iterator<ImmutableMethodParameter> iterator() {
            return list.iterator();

        }
    };
}
 
Example 7
Source Project: zjdroid   Source File: DexBuilder.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull public BuilderMethod internMethod(@Nonnull String definingClass,
                                           @Nonnull String name,
                                           @Nullable List<? extends MethodParameter> parameters,
                                           @Nonnull String returnType,
                                           int accessFlags,
                                           @Nonnull Set<? extends Annotation> annotations,
                                           @Nullable MethodImplementation methodImplementation) {
    if (parameters == null) {
        parameters = ImmutableList.of();
    }
    return new BuilderMethod(context.methodPool.internMethod(definingClass, name, parameters, returnType),
            internMethodParameters(parameters),
            accessFlags,
            context.annotationSetPool.internAnnotationSet(annotations),
            methodImplementation);
}
 
Example 8
Source Project: zjdroid   Source File: ReflectionConstructor.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull @Override public List<? extends MethodParameter> getParameters() {
    final Constructor method = this.constructor;
    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 9
Source Project: zjdroid   Source File: ReflectionMethod.java    License: Apache License 2.0 6 votes vote down vote up
@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 10
Source Project: zjdroid   Source File: DexBackedMethod.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public List<? extends MethodParameter> getParameters() {
    int parametersOffset = getParametersOffset();
    if (parametersOffset > 0) {
        final List<String> parameterTypes = getParameterTypes();

        return new AbstractForwardSequentialList<MethodParameter>() {
            @Nonnull @Override public Iterator<MethodParameter> iterator() {
                return new ParameterIterator(parameterTypes,
                        getParameterAnnotations(),
                        getParameterNames());
            }

            @Override public int size() {
                return parameterTypes.size();
            }
        };
    }
    return ImmutableList.of();
}
 
Example 11
Source Project: ZjDroid   Source File: ParameterIterator.java    License: Apache License 2.0 6 votes vote down vote up
@Override public MethodParameter next() {
    @Nonnull final String type = parameterTypes.next().toString();
    @Nonnull final Set<? extends Annotation> annotations;
    @Nullable final String name;

    if (parameterAnnotations.hasNext()) {
        annotations = parameterAnnotations.next();
    } else {
        annotations = ImmutableSet.of();
    }

    if (parameterNames.hasNext()) {
        name = parameterNames.next();
    } else {
        name = null;
    }

    return new BaseMethodParameter() {
        @Nonnull @Override public Set<? extends Annotation> getAnnotations() { return annotations; }
        @Nullable @Override public String getName() { return name; }
        @Nonnull @Override public String getType() { return type; }
    };
}
 
Example 12
Source Project: HeyGirl   Source File: DexBuilder.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull public BuilderMethod internMethod(@Nonnull String definingClass,
                                           @Nonnull String name,
                                           @Nullable List<? extends MethodParameter> parameters,
                                           @Nonnull String returnType,
                                           int accessFlags,
                                           @Nonnull Set<? extends Annotation> annotations,
                                           @Nullable MethodImplementation methodImplementation) {
    if (parameters == null) {
        parameters = ImmutableList.of();
    }
    return new BuilderMethod(context.methodPool.internMethod(definingClass, name, parameters, returnType),
            internMethodParameters(parameters),
            accessFlags,
            context.annotationSetPool.internAnnotationSet(annotations),
            methodImplementation);
}
 
Example 13
Source Project: HeyGirl   Source File: ReflectionConstructor.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull @Override public List<? extends MethodParameter> getParameters() {
    final Constructor method = this.constructor;
    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 14
Source Project: HeyGirl   Source File: ReflectionMethod.java    License: Apache License 2.0 6 votes vote down vote up
@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 15
Source Project: HeyGirl   Source File: DexBackedMethod.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public List<? extends MethodParameter> getParameters() {
    int parametersOffset = getParametersOffset();
    if (parametersOffset > 0) {
        final List<String> parameterTypes = getParameterTypes();

        return new AbstractForwardSequentialList<MethodParameter>() {
            @Nonnull @Override public Iterator<MethodParameter> iterator() {
                return new ParameterIterator(parameterTypes,
                        getParameterAnnotations(),
                        getParameterNames());
            }

            @Override public int size() {
                return parameterTypes.size();
            }
        };
    }
    return ImmutableList.of();
}
 
Example 16
Source Project: HeyGirl   Source File: ParameterIterator.java    License: Apache License 2.0 6 votes vote down vote up
@Override public MethodParameter next() {
    @Nonnull final String type = parameterTypes.next().toString();
    @Nonnull final Set<? extends Annotation> annotations;
    @Nullable final String name;

    if (parameterAnnotations.hasNext()) {
        annotations = parameterAnnotations.next();
    } else {
        annotations = ImmutableSet.of();
    }

    if (parameterNames.hasNext()) {
        name = parameterNames.next();
    } else {
        name = null;
    }

    return new BaseMethodParameter() {
        @Nonnull @Override public Set<? extends Annotation> getAnnotations() { return annotations; }
        @Nullable @Override public String getName() { return name; }
        @Nonnull @Override public String getType() { return type; }
    };
}
 
Example 17
Source Project: ZjDroid   Source File: DexBuilder.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull public BuilderMethod internMethod(@Nonnull String definingClass,
                                           @Nonnull String name,
                                           @Nullable List<? extends MethodParameter> parameters,
                                           @Nonnull String returnType,
                                           int accessFlags,
                                           @Nonnull Set<? extends Annotation> annotations,
                                           @Nullable MethodImplementation methodImplementation) {
    if (parameters == null) {
        parameters = ImmutableList.of();
    }
    return new BuilderMethod(context.methodPool.internMethod(definingClass, name, parameters, returnType),
            internMethodParameters(parameters),
            accessFlags,
            context.annotationSetPool.internAnnotationSet(annotations),
            methodImplementation);
}
 
Example 18
Source Project: ZjDroid   Source File: ReflectionConstructor.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull @Override public List<? extends MethodParameter> getParameters() {
    final Constructor method = this.constructor;
    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 19
Source Project: ZjDroid   Source File: ReflectionMethod.java    License: Apache License 2.0 6 votes vote down vote up
@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 20
Source Project: ZjDroid   Source File: DexBackedMethod.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public List<? extends MethodParameter> getParameters() {
    int parametersOffset = getParametersOffset();
    if (parametersOffset > 0) {
        final List<String> parameterTypes = getParameterTypes();

        return new AbstractForwardSequentialList<MethodParameter>() {
            @Nonnull @Override public Iterator<MethodParameter> iterator() {
                return new ParameterIterator(parameterTypes,
                        getParameterAnnotations(),
                        getParameterNames());
            }

            @Override public int size() {
                return parameterTypes.size();
            }
        };
    }
    return ImmutableList.of();
}
 
Example 21
Source Project: ZjDroid   Source File: ImmutableMethod.java    License: Apache License 2.0 5 votes vote down vote up
public ImmutableMethod(@Nonnull String definingClass,
                       @Nonnull String name,
                       @Nullable Iterable<? extends MethodParameter> parameters,
                       @Nonnull String returnType,
                       int accessFlags,
                       @Nullable Set<? extends Annotation> annotations,
                       @Nullable MethodImplementation methodImplementation) {
    this.definingClass = definingClass;
    this.name = name;
    this.parameters = ImmutableMethodParameter.immutableListOf(parameters);
    this.returnType = returnType;
    this.accessFlags = accessFlags;
    this.annotations = ImmutableAnnotation.immutableSetOf(annotations);
    this.methodImplementation = ImmutableMethodImplementation.of(methodImplementation);
}
 
Example 22
Source Project: ZjDroid   Source File: ImmutableMethodParameter.java    License: Apache License 2.0 5 votes vote down vote up
public static ImmutableMethodParameter of(MethodParameter methodParameter) {
    if (methodParameter instanceof ImmutableMethodParameter) {
        return (ImmutableMethodParameter)methodParameter;
    }
    return new ImmutableMethodParameter(
            methodParameter.getType(),
            methodParameter.getAnnotations(),
            methodParameter.getName());
}
 
Example 23
Source Project: ZjDroid   Source File: DexBuilder.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull private List<BuilderMethodParameter> internMethodParameters(
        @Nullable List<? extends MethodParameter> methodParameters) {
    if (methodParameters == null) {
        return ImmutableList.of();
    }
    return ImmutableList.copyOf(Iterators.transform(methodParameters.iterator(),
            new Function<MethodParameter, BuilderMethodParameter>() {
                @Nullable @Override public BuilderMethodParameter apply(MethodParameter input) {
                    return internMethodParameter(input);
                }
            }));
}
 
Example 24
Source Project: ZjDroid   Source File: MethodRewriter.java    License: Apache License 2.0 5 votes vote down vote up
@Override @Nonnull public List<? extends MethodParameter> getParameters() {
    // We can't use the MethodReferenceRewriter to rewrite the parameters, because we would lose
    // parameter names and annotations. If a method rewrite involves changing parameters, it needs
    // to be handled here as well as in the MethodReferenceRewriter

    return RewriterUtils.rewriteList(rewriters.getMethodParameterRewriter(), method.getParameters());
}
 
Example 25
Source Project: ZjDroid   Source File: ReflectionConstructor.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull @Override public List<String> getParameterTypes() {
    return new AbstractList<String>() {
        private final List<? extends MethodParameter> parameters = getParameters();

        @Override public String get(int index) {
            return parameters.get(index).getType();
        }

        @Override public int size() {
            return parameters.size();
        }
    };
}
 
Example 26
Source Project: ZjDroid   Source File: ReflectionMethod.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull @Override public List<String> getParameterTypes() {
    return new AbstractList<String>() {
        private final List<? extends MethodParameter> parameters = getParameters();

        @Override public String get(int index) {
            return parameters.get(index).getType();
        }

        @Override public int size() {
            return parameters.size();
        }
    };
}
 
Example 27
Source Project: SimpleSmali   Source File: BackSmaliMain.java    License: Apache License 2.0 5 votes vote down vote up
private static String methodToString(DexBackedMethod dexBackedMethod, LocalInfo info) {
    String returnType = typeToString(dexBackedMethod.getReturnType());

    int insSize = getInsSize(dexBackedMethod);

    List<? extends MethodParameter> parameters =
            dexBackedMethod.getParameters();//被坑一笔这里的paramterssize不是inssize,是从debuginfo里获取来的,就是说这货在非静态方法下将this去掉了

    int argReg = getRegisterSize(dexBackedMethod) - insSize;//reg = resiter - ins
    //                        System.out.println("registerCount:" + methodImplementation.getRegisterCount());

    boolean isStatic = AccessFlags.STATIC.isSet(dexBackedMethod.getAccessFlags());

    if (!isStatic) {
        argReg++;
    }
    List<String> paramtersStr = new ArrayList<>();

    for (MethodParameter p : parameters) {
        int reg = argReg;

        if ("D".equals(p.getType()) || "J".equals(p.getType())) {
            argReg += 2;
        } else {
            argReg += 1;
        }
        paramtersStr.add(String.format("%s %s", typeToString(p.getType()), formatRegisterName(reg, info)));

    }

    return String.format("%s %s %s (%s)", AccessFlags.formatAccessFlagsForMethod(dexBackedMethod.getAccessFlags()),
            returnType, dexBackedMethod.getName(), String.join(",", paramtersStr));

}
 
Example 28
Source Project: atlas   Source File: MethodReIClassDef.java    License: Apache License 2.0 5 votes vote down vote up
private List<String> toTypes(List<? extends MethodParameter> paramters) {
    List<String>types = new ArrayList<>();
    for (MethodParameter methodParameter:paramters){
        types.add(methodParameter.getType());
    }
    return types;
}
 
Example 29
Source Project: zjdroid   Source File: ImmutableMethod.java    License: Apache License 2.0 5 votes vote down vote up
public ImmutableMethod(@Nonnull String definingClass,
                       @Nonnull String name,
                       @Nullable Iterable<? extends MethodParameter> parameters,
                       @Nonnull String returnType,
                       int accessFlags,
                       @Nullable Set<? extends Annotation> annotations,
                       @Nullable MethodImplementation methodImplementation) {
    this.definingClass = definingClass;
    this.name = name;
    this.parameters = ImmutableMethodParameter.immutableListOf(parameters);
    this.returnType = returnType;
    this.accessFlags = accessFlags;
    this.annotations = ImmutableAnnotation.immutableSetOf(annotations);
    this.methodImplementation = ImmutableMethodImplementation.of(methodImplementation);
}
 
Example 30
Source Project: zjdroid   Source File: ImmutableMethodParameter.java    License: Apache License 2.0 5 votes vote down vote up
public static ImmutableMethodParameter of(MethodParameter methodParameter) {
    if (methodParameter instanceof ImmutableMethodParameter) {
        return (ImmutableMethodParameter)methodParameter;
    }
    return new ImmutableMethodParameter(
            methodParameter.getType(),
            methodParameter.getAnnotations(),
            methodParameter.getName());
}