public class MethodASM implements IASM, Opcodes { private List<MethodSet> target = MethodSet.getHookingMethodSet(Configure.getInstance().hook_method); public boolean isTarget(String className) { if (target.size() == 0) return false; for (int i = 0; i < target.size(); i++) { MethodSet mset = target.get(i); if (mset.classMatch.include(className)) { return true; } } return false; } Configure conf = Configure.getInstance(); public ClassVisitor transform(ClassVisitor cv, String className, ClassDesc classDesc) { if (target.size() == 0) return cv; if (conf.isIgnoreMethodClass(className)) return cv; for (int i = 0; i < target.size(); i++) { MethodSet mset = target.get(i); if (mset.classMatch.include(className)) { return new MethodCV(cv, mset, className); } } return cv; } }
@Override public MethodVisitor visitMethod( int access, String name, String desc, String signature, String[] exceptions) { MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); if (mv == null || mset.isA(name, desc) == false) { return mv; } if (AsmUtil.isSpecial(name)) { return mv; } Configure conf = Configure.getInstance(); boolean isPublic = conf.hook_method_access_public; boolean isProtected = conf.hook_method_access_protected; boolean isPrivate = conf.hook_method_access_private; boolean isNone = conf.hook_method_access_none; switch (access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE)) { case Opcodes.ACC_PUBLIC: if (isPublic == false) return mv; break; case Opcodes.ACC_PROTECTED: if (isProtected == false) return mv; break; case Opcodes.ACC_PRIVATE: if (isPrivate == false) return mv; break; default: if (isNone == false) return mv; break; } // check prefix, to ignore simple method such as getter,setter if (conf.isIgnoreMethodPrefix(name)) return mv; String fullname = AsmUtil.add(className, name, desc); int fullname_hash = DataProxy.sendMethodName(fullname); return new MethodMV(access, desc, mv, fullname, fullname_hash); }