本文整理汇总了Java中org.jf.dexlib2.iface.ClassDef.getMethods方法的典型用法代码示例。如果您正苦于以下问题:Java ClassDef.getMethods方法的具体用法?Java ClassDef.getMethods怎么用?Java ClassDef.getMethods使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jf.dexlib2.iface.ClassDef
的用法示例。
在下文中一共展示了ClassDef.getMethods方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test1
import org.jf.dexlib2.iface.ClassDef; //导入方法依赖的package包/类
public static void test1(String argv[]){
try{
DexBackedDexFile dexFile = DexFileFactory.loadDexFile(search_path, 16);
for (ClassDef classDef: dexFile.getClasses()){
if (classDef.getType().startsWith("Landroid") ||
classDef.getType().startsWith("Ljava") ||
classDef.getType().startsWith("Ldalvik")) {
continue;
}
for (Method method: classDef.getMethods()){
// if (method.getDefiningClass().equals("Lcom/cc/test/MainActivity;")
// && method.getName().equals("onCreate")){
if (method.getImplementation() == null)
continue;
Grapher grapher = new Grapher(method.getImplementation());
grapher.visitConstant();
grapher.search();
// grapher.printInfo();
// }
}
}
MethodConfig.printInfo();
} catch (Exception e){
e.printStackTrace();
}
}
示例2: getAnnotatedMethods
import org.jf.dexlib2.iface.ClassDef; //导入方法依赖的package包/类
private Set<MethodAnnotationPair> getAnnotatedMethods(Set<ClassDef> classes) {
Set<MethodAnnotationPair> result = new HashSet<>();
for (ClassDef classDef : classes)
for (Method method : classDef.getMethods())
for (Annotation a : method.getAnnotations()) {
if (a.getType().equals(METHOD_PERMISSION_ANNOTATION)) {
final int flags = method.getAccessFlags();
boolean isPublic = AccessFlags.PUBLIC.isSet(flags);
boolean isStatic = AccessFlags.STATIC.isSet(flags);
if (isPublic && isStatic)
result.add(new MethodAnnotationPair(method, a));
else
PrintWarning("ignoring method " + method.getDefiningClass() + "." + method.getName() + " " +
"because is not static and public");
break;
}
}
return result;
}
示例3: fillFromDex
import org.jf.dexlib2.iface.ClassDef; //导入方法依赖的package包/类
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);
}
}
示例4: getMethod
import org.jf.dexlib2.iface.ClassDef; //导入方法依赖的package包/类
public static Method getMethod(DexBackedDexFile dexfile, String className, String methodName){
for (ClassDef classDef: dexfile.getClasses()){
if (classDef.getType().equals(className)) {
System.out.println("Find the class");
for (Method method: classDef.getMethods()){
if (method.getName().equals(methodName)) {
return method;
}
}
}
}
return null;
}
示例5: getMethodRef
import org.jf.dexlib2.iface.ClassDef; //导入方法依赖的package包/类
public static MethodReference getMethodRef(DexFile dexfile, String className, String methodName) {
for (ClassDef classDef : dexfile.getClasses()) {
if (!classDef.getType().equals(className))
continue;
for (Method method : classDef.getMethods())
if (method.getName().equals(methodName))
return method;
}
return null;
}
示例6: search
import org.jf.dexlib2.iface.ClassDef; //导入方法依赖的package包/类
private static void search(Options options){
try{
for (Packer packer: options.getPacker()){
for (MethodConfig config: packer.getMethod()){
MethodConfig.addtoCollection(config);
}
}
DexBackedDexFile dexFile = DexFileFactory.loadDexFile(search_path, 16);
for (ClassDef classDef: dexFile.getClasses()){
if (classDef.getType().startsWith("Landroid") ||
classDef.getType().startsWith("Ljava") ||
classDef.getType().startsWith("Ldalvik")) {
continue;
}
for (Method method: classDef.getMethods()){
if (method.getImplementation() == null)
continue;
Grapher grapher = new Grapher(method.getImplementation());
grapher.visitConstant();
grapher.search();
}
}
MethodConfig.printInfo();
} catch (Exception e){
e.printStackTrace();
}
}
示例7: getMethod
import org.jf.dexlib2.iface.ClassDef; //导入方法依赖的package包/类
public static Method getMethod(DexBackedDexFile dexfile, String className, String methodName){
for (ClassDef classDef: dexfile.getClasses()){
if (classDef.getType().equals(className)) {
System.out.println("Find the class");
for (Method method: classDef.getMethods()){
if (method.getName().equals(methodName)) {
return method;
}
}
}
}
return null;
}
示例8: customizeClass
import org.jf.dexlib2.iface.ClassDef; //导入方法依赖的package包/类
private ClassDef customizeClass(ClassDef classDef) {
List<Method> methods = new ArrayList<>();
boolean modifiedMethod = false;
for (Method method : classDef.getMethods()) {
MethodImplementation implementation = method.getImplementation();
if (implementation == null) {
methods.add(method);
continue;
}
MethodImplementation customImpl = searchAndReplaceInvocations(implementation);
if (customImpl==implementation) {
methods.add(method);
continue;
}
modifiedMethod = true;
final ImmutableMethod newMethod = new ImmutableMethod(method.getDefiningClass(),
method.getName(),
method.getParameters(),
method.getReturnType(),
method.getAccessFlags(),
method.getAnnotations(),
customImpl);
methods.add(newMethod);
}
if (!modifiedMethod)
return classDef;
return new ImmutableClassDef(classDef.getType(),
classDef.getAccessFlags(),
classDef.getSuperclass(),
classDef.getInterfaces(),
classDef.getSourceFile(),
classDef.getAnnotations(),
classDef.getFields(),
methods);
}
示例9: reClassDef
import org.jf.dexlib2.iface.ClassDef; //导入方法依赖的package包/类
@Override
public ClassDef reClassDef(ClassDef classDef) {
Iterable<? extends Method> methods = classDef.getMethods();
LinkedHashSet<Method> newMethods = new LinkedHashSet<Method>();
Iterable<? extends Field> fields = classDef.getFields();
LinkedHashSet<Field>newFields = new LinkedHashSet<Field>();
Set<? extends Annotation> annotations = classDef.getAnnotations();
Set<String>interfaces = classDef.getInterfaces();
Set<String>newInterfaces = new HashSet<String>();
Set<Annotation>immutableAnnotations = new HashSet<Annotation>();
String type = classDef.getType();
reType = reType(type);
String superClass = classDef.getSuperclass();
for (String inter:interfaces){
newInterfaces.add(reInterface(inter));
}
String reSuperClass = reSuperClass(superClass);
for (Annotation annotation:annotations){
immutableAnnotations.add(reAnnotation(annotation));
}
for (Field field:fields){
newFields.add(reField(field));
}
for (Method method:methods){
if (method.getName().equals("<cinit>")||method.getName().equals("<init>")){
newMethods.add(reMethod(method));
continue;
}
// if (method.getName().equals("getArchiveFile")) {
newMethods.add(reMethod(method));
// }
}
return new ImmutableClassDef(
reType,
classDef.getAccessFlags(),
reSuperClass,
newInterfaces,
classDef.getSourceFile(),
immutableAnnotations,
newFields,
newMethods);
}
示例10: modifyMethod
import org.jf.dexlib2.iface.ClassDef; //导入方法依赖的package包/类
public static void modifyMethod(String srcDexFile, String outDexFile, boolean isAndFix) throws IOException {
DexFile dexFile = DexFileFactory.loadDexFile(srcDexFile, 15, true);
final Set<ClassDef> classes = Sets.newConcurrentHashSet();
for (ClassDef classDef : dexFile.getClasses()) {
Set<Method> methods = Sets.newConcurrentHashSet();
boolean modifiedMethod = false;
for (Method method : classDef.getMethods()) {
MethodImplementation implementation = method.getImplementation();
if (implementation != null&&(methodNeedsModification(classDef, method, isAndFix))) {
modifiedMethod = true;
methods.add(new ImmutableMethod(
method.getDefiningClass(),
method.getName(),
method.getParameters(),
method.getReturnType(),
method.getAccessFlags(),
method.getAnnotations(),
isAndFix ?
modifyMethodAndFix(implementation, method) : modifyMethodTpatch(implementation, method)));
} else {
methods.add(method);
}
}
if (!modifiedMethod) {
classes.add(classDef);
} else {
classes.add(new ImmutableClassDef(
classDef.getType(),
classDef.getAccessFlags(),
classDef.getSuperclass(),
classDef.getInterfaces(),
classDef.getSourceFile(),
classDef.getAnnotations(),
classDef.getFields(),
methods));
}
}
DexFileFactory.writeDexFile(outDexFile, new DexFile() {
@Nonnull
@Override
public Set<? extends ClassDef> getClasses() {
return new AbstractSet<ClassDef>() {
@Nonnull
@Override
public Iterator<ClassDef> iterator() {
return classes.iterator();
}
@Override
public int size() {
return classes.size();
}
};
}
});
}
示例11: getAccessedMember
import org.jf.dexlib2.iface.ClassDef; //导入方法依赖的package包/类
@Nullable
public AccessedMember getAccessedMember(@Nonnull MethodReference methodReference) {
String methodDescriptor = ReferenceUtil.getMethodDescriptor(methodReference);
AccessedMember accessedMember = resolvedAccessors.get(methodDescriptor);
if (accessedMember != null) {
return accessedMember;
}
String type = methodReference.getDefiningClass();
ClassDef classDef = classDefMap.get(type);
if (classDef == null) {
return null;
}
Method matchedMethod = null;
MethodImplementation matchedMethodImpl = null;
for (Method method: classDef.getMethods()) {
MethodImplementation methodImpl = method.getImplementation();
if (methodImpl != null) {
if (methodReferenceEquals(method, methodReference)) {
matchedMethod = method;
matchedMethodImpl = methodImpl;
break;
}
}
}
if (matchedMethod == null) {
return null;
}
//A synthetic accessor will be marked synthetic
if (!AccessFlags.SYNTHETIC.isSet(matchedMethod.getAccessFlags())) {
return null;
}
List<Instruction> instructions = ImmutableList.copyOf(matchedMethodImpl.getInstructions());
int accessType = SyntheticAccessorFSM.test(instructions);
if (accessType >= 0) {
AccessedMember member =
new AccessedMember(accessType, ((ReferenceInstruction)instructions.get(0)).getReference());
resolvedAccessors.put(methodDescriptor, member);
return member;
}
return null;
}
示例12: getAccessedMember
import org.jf.dexlib2.iface.ClassDef; //导入方法依赖的package包/类
public AccessedMember getAccessedMember( MethodReference methodReference) {
String methodDescriptor = ReferenceUtil.getMethodDescriptor(methodReference);
AccessedMember accessedMember = resolvedAccessors.get(methodDescriptor);
if (accessedMember != null) {
return accessedMember;
}
String type = methodReference.getDefiningClass();
ClassDef classDef = classDefMap.get(type);
if (classDef == null) {
return null;
}
Method matchedMethod = null;
MethodImplementation matchedMethodImpl = null;
for (Method method: classDef.getMethods()) {
MethodImplementation methodImpl = method.getImplementation();
if (methodImpl != null) {
if (methodReferenceEquals(method, methodReference)) {
matchedMethod = method;
matchedMethodImpl = methodImpl;
break;
}
}
}
if (matchedMethod == null) {
return null;
}
//A synthetic accessor will be marked synthetic
if (!AccessFlags.SYNTHETIC.isSet(matchedMethod.getAccessFlags())) {
return null;
}
List<Instruction> instructions = ImmutableList.copyOf(matchedMethodImpl.getInstructions());
int accessType = syntheticAccessorFSM.test(instructions);
if (accessType >= 0) {
AccessedMember member =
new AccessedMember(accessType, ((ReferenceInstruction)instructions.get(0)).getReference());
resolvedAccessors.put(methodDescriptor, member);
return member;
}
return null;
}
示例13: getAccessedMember
import org.jf.dexlib2.iface.ClassDef; //导入方法依赖的package包/类
@Nullable
public AccessedMember getAccessedMember(@Nonnull MethodReference methodReference) {
String methodDescriptor = ReferenceUtil.getMethodDescriptor(methodReference);
AccessedMember accessedMember = resolvedAccessors.get(methodDescriptor);
if (accessedMember != null) {
return accessedMember;
}
String type = methodReference.getDefiningClass();
ClassDef classDef = classDefMap.get(type);
if (classDef == null) {
return null;
}
Method matchedMethod = null;
MethodImplementation matchedMethodImpl = null;
for (Method method: classDef.getMethods()) {
MethodImplementation methodImpl = method.getImplementation();
if (methodImpl != null) {
if (methodReferenceEquals(method, methodReference)) {
matchedMethod = method;
matchedMethodImpl = methodImpl;
break;
}
}
}
if (matchedMethod == null) {
return null;
}
//A synthetic accessor will be marked synthetic
if (!AccessFlags.SYNTHETIC.isSet(matchedMethod.getAccessFlags())) {
return null;
}
List<Instruction> instructions = ImmutableList.copyOf(matchedMethodImpl.getInstructions());
int accessType = syntheticAccessorFSM.test(instructions);
if (accessType >= 0) {
AccessedMember member =
new AccessedMember(accessType, ((ReferenceInstruction)instructions.get(0)).getReference());
resolvedAccessors.put(methodDescriptor, member);
return member;
}
return null;
}
示例14: getAccessedMember
import org.jf.dexlib2.iface.ClassDef; //导入方法依赖的package包/类
@Nullable
public AccessedMember getAccessedMember(@Nonnull MethodReference methodReference) {
String methodDescriptor = ReferenceUtil.getMethodDescriptor(methodReference);
AccessedMember accessedMember = resolvedAccessors.get(methodDescriptor);
if (accessedMember != null) {
return accessedMember;
}
String type = methodReference.getDefiningClass();
ClassDef classDef = classDefMap.get(type);
if (classDef == null) {
return null;
}
Method matchedMethod = null;
MethodImplementation matchedMethodImpl = null;
for (Method method : classDef.getMethods()) {
MethodImplementation methodImpl = method.getImplementation();
if (methodImpl != null) {
if (methodReferenceEquals(method, methodReference)) {
matchedMethod = method;
matchedMethodImpl = methodImpl;
break;
}
}
}
if (matchedMethod == null) {
return null;
}
//A synthetic accessor will be marked synthetic
if (!AccessFlags.SYNTHETIC.isSet(matchedMethod.getAccessFlags())) {
return null;
}
List<Instruction> instructions = ImmutableList.copyOf(matchedMethodImpl.getInstructions());
int accessType = SyntheticAccessorFSM.test(instructions);
if (accessType >= 0) {
AccessedMember member =
new AccessedMember(accessType, ((ReferenceInstruction) instructions.get(0)).getReference());
resolvedAccessors.put(methodDescriptor, member);
return member;
}
return null;
}
示例15: test
import org.jf.dexlib2.iface.ClassDef; //导入方法依赖的package包/类
public static void test(String argv[]){
try {
DexBackedDexFile dexFile = DexFileFactory.loadDexFile(search_path, 16);
for (ClassDef classdef: dexFile.getClasses()){
for (Method method: classdef.getMethods()){
MethodImplementation impl = method.getImplementation();
if (impl == null) {
continue;
}
// System.out.println(method.getDefiningClass() + "->" + method.getName());
for (Instruction instruction: impl.getInstructions()){
Opcode opcode = instruction.getOpcode();
if (opcode.referenceType == ReferenceType.METHOD){
ReferenceInstruction ref = (ReferenceInstruction)instruction;
MethodReference methodRef = (MethodReference)ref.getReference();
if (methodRef.getName().equals("d") &&
methodRef.getDefiningClass().equals("Lcom/baidu/protect/A;")) {
List<? extends CharSequence> params = methodRef.getParameterTypes();
if (params.size() == paramsList.size()) {
boolean flag = true;
int index = 0;
for(CharSequence param: params){
if (!param.equals(paramsList.get(index))) {
flag = false;
break;
}
index++;
}
if (flag && "V".equals(methodRef.getReturnType())) {
}
}
}
// System.out.println(methodRef.getName() + " " + methodRef.getDefiningClass());
}
}
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}