diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index c038225..17835c5 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -19,5 +19,6 @@
+
\ No newline at end of file
diff --git a/plugin/src/main/groovy/com/peakmain/analytics/plugin/ext/MonitorConfig.groovy b/plugin/src/main/groovy/com/peakmain/analytics/plugin/ext/MonitorConfig.groovy
index 93ea467..ededb94 100644
--- a/plugin/src/main/groovy/com/peakmain/analytics/plugin/ext/MonitorConfig.groovy
+++ b/plugin/src/main/groovy/com/peakmain/analytics/plugin/ext/MonitorConfig.groovy
@@ -24,7 +24,7 @@ class MonitorConfig {
/**
* 隐私方法方法的状态
* @params 1 代表替换方法体
- * @params 其他都
+ * @params 其他都表示正常
*/
public int methodStatus = 0
private MethodFieldUtils.StatusEnum statusEnum = MethodFieldUtils.StatusEnum.METHOD_STATE_NORMAL
@@ -40,7 +40,7 @@ class MonitorConfig {
/**
* 拦截点击的包名前缀
*/
- public String interceptPackageName = ""
+ public String interceptPackageName = MethodFieldUtils.PACKAGE_NAME_PREXC
void convertConfig() {
for (String value : special) {
diff --git a/plugin/src/main/groovy/com/peakmain/analytics/plugin/utils/MethodFieldUtils.groovy b/plugin/src/main/groovy/com/peakmain/analytics/plugin/utils/MethodFieldUtils.groovy
index 6ddeb1c..2ec4258 100644
--- a/plugin/src/main/groovy/com/peakmain/analytics/plugin/utils/MethodFieldUtils.groovy
+++ b/plugin/src/main/groovy/com/peakmain/analytics/plugin/utils/MethodFieldUtils.groovy
@@ -17,7 +17,7 @@ class MethodFieldUtils {
return value
}
}
-
+ public static final String PACKAGE_NAME_PREXC="com.atour"
public static final String LOG_MANAGER = "com/peakmain/sdk/utils/LogManager"
public static final String NEW_METHOD_OWNER = "com/peakmain/sdk/utils/ReplaceMethodUtils"
diff --git a/plugin/src/main/groovy/com/peakmain/analytics/plugin/visitor/MonitorMethodCalledClearAdapter.groovy b/plugin/src/main/groovy/com/peakmain/analytics/plugin/visitor/MonitorMethodCalledClearAdapter.groovy
deleted file mode 100644
index 45c0f1b..0000000
--- a/plugin/src/main/groovy/com/peakmain/analytics/plugin/visitor/MonitorMethodCalledClearAdapter.groovy
+++ /dev/null
@@ -1,79 +0,0 @@
-package com.peakmain.analytics.plugin.visitor
-
-import com.peakmain.analytics.plugin.entity.MethodCalledBean
-import com.peakmain.analytics.plugin.ext.MonitorConfig
-import com.peakmain.analytics.plugin.ext.MonitorHookMethodConfig
-import com.peakmain.analytics.plugin.utils.OpcodesUtils
-import com.peakmain.analytics.plugin.visitor.base.MonitorDefalutMethodAdapter
-import org.objectweb.asm.MethodVisitor
-import org.objectweb.asm.Opcodes
-import org.objectweb.asm.Type
-
-/**
- * author :Peakmain
- * createTime:2022/4/1
- * mail:2726449200@qq.com
- * describe:方法被调用,然后清空被调用的方法
- */
-class MonitorMethodCalledClearAdapter extends MonitorDefalutMethodAdapter {
- private String mClassName
-
- private int mAccess
- private MonitorConfig monitorConfig
- private String mDesc
- /**
- * Constructs a new {@link MonitorMethodCalledClearAdapter}.
- *
- * @param mv
- * @param access the method's access flags (see {@link Opcodes}).
- * @param name the method's name.
- * @param desc
- */
- MonitorMethodCalledClearAdapter(MethodVisitor mv, int access, String name, String desc, String className, MonitorConfig monitorConfig) {
- super(mv, access, name, desc)
- mClassName = className
- mAccess = access
- mDesc = desc
- this.monitorConfig = monitorConfig
- }
-
- @Override
- void visitMethodInsn(int opcodeAndSource, String owner, String name, String descriptor, boolean isInterface) {
- HashMap methodCalledBeans = MonitorHookMethodConfig.methodCalledBeans
- if (!monitorConfig.whiteList.contains(mClassName) && !monitorConfig.exceptSet.contains(mClassName) && methodCalledBeans.containsKey(owner + name + descriptor)) {
- println("调用方法的class:" + mClassName + ",方法的名字:" + name + ",方法的描述符:" + descriptor)
- clearMethodBody(mv, mClassName, access, name, descriptor,mDesc)
- return
- }
- super.visitMethodInsn(opcodeAndSource, owner, name, descriptor, isInterface);
- }
-
-
- static void clearMethodBody(MethodVisitor mv, String className, int access, String name, String descriptor,String methodDescriptor) {
- Type type = Type.getType(descriptor)
- Type methodType = Type.getType(methodDescriptor)
- Type methodReturnType = methodType.getReturnType()
- Type[] argumentsType = type.getArgumentTypes()
- Type returnType = type.getReturnType()
- int stackSize = returnType.getSize()
- int localSize = OpcodesUtils.isStatic(access) ? 0 : 1
- for (Type argType : argumentsType) {
- localSize += argType.size
- }
- mv.visitCode()
- if (methodReturnType.getSort() == Type.VOID) {
- mv.visitInsn(RETURN)
- } else if (methodReturnType.getSort() >= Type.BOOLEAN && methodReturnType.getSort() <= Type.DOUBLE) {
- mv.visitInsn(methodReturnType.getOpcode(ICONST_1))
- mv.visitInsn(methodReturnType.getOpcode(IRETURN))
- } else if (methodReturnType.getInternalName() == "java/lang/String") {
- mv.visitLdcInsn("")
- mv.visitInsn(ARETURN)
- } else {
- mv.visitInsn(ACONST_NULL)
- mv.visitInsn(ARETURN)
- }
- mv.visitMaxs(stackSize, localSize)
- mv.visitEnd()
- }
-}
diff --git a/plugin/src/main/groovy/com/peakmain/analytics/plugin/visitor/MonitorMethodCalledReplaceAdapter.groovy b/plugin/src/main/groovy/com/peakmain/analytics/plugin/visitor/MonitorMethodCalledReplaceAdapter.groovy
index 76e328c..84ba726 100644
--- a/plugin/src/main/groovy/com/peakmain/analytics/plugin/visitor/MonitorMethodCalledReplaceAdapter.groovy
+++ b/plugin/src/main/groovy/com/peakmain/analytics/plugin/visitor/MonitorMethodCalledReplaceAdapter.groovy
@@ -39,7 +39,10 @@ class MonitorMethodCalledReplaceAdapter extends MonitorDefalutMethodAdapter {
void visitMethodInsn(int opcodeAndSource, String owner, String name, String descriptor, boolean isInterface) {
HashMap methodReplaceBeans = MonitorHookMethodConfig.methodCalledBeans
String desc = owner + name + descriptor
- if (!monitorConfig.whiteList.contains(mClassName) && !monitorConfig.exceptSet.contains(mClassName)&&methodReplaceBeans.containsKey(desc)) {
+ if (!monitorConfig.whiteList.contains(mClassName) &&
+ !monitorConfig.exceptSet.contains(mClassName) &&
+ methodReplaceBeans.containsKey(desc)
+ && (mClassName.contains('cn/jiguang/') || mClassName.contains('libcore/util/Jauns'))) {
println("调用方法的class:" + mClassName + ",方法的名字:" + name + ",方法的描述符:" + descriptor)
MethodCalledBean bean = methodReplaceBeans.get(desc)
super.visitMethodInsn(bean.newOpcode, bean.newMethodOwner, bean.newMethodName, bean.newMethodDescriptor.get(descriptor), false)
diff --git a/plugin/src/main/groovy/com/peakmain/analytics/plugin/visitor/MonitorMethodStackMapFrameAdapter.groovy b/plugin/src/main/groovy/com/peakmain/analytics/plugin/visitor/MonitorMethodStackMapFrameAdapter.groovy
deleted file mode 100644
index e598b16..0000000
--- a/plugin/src/main/groovy/com/peakmain/analytics/plugin/visitor/MonitorMethodStackMapFrameAdapter.groovy
+++ /dev/null
@@ -1,198 +0,0 @@
-package com.peakmain.analytics.plugin.visitor
-
-import com.peakmain.analytics.plugin.utils.MethodFieldUtils
-import com.peakmain.analytics.plugin.utils.OpcodesUtils
-import com.peakmain.analytics.plugin.utils.StringBuilderUtils
-import org.objectweb.asm.*
-import org.objectweb.asm.commons.AnalyzerAdapter
-
-/**
- * author :Peakmain
- * createTime:2022/4/5
- * mail:2726449200@qq.com
- * describe:打印Frame的方法
- */
-class MonitorMethodStackMapFrameAdapter extends AnalyzerAdapter {
- private String methodName
- private String methodDesc
- private int methodAccess
- private boolean isLogMethodStackMapFrame = false
- private StringBuilderUtils mStringBuilderUtils
-
- MonitorMethodStackMapFrameAdapter(String owner, int access, String name, String descriptor, MethodVisitor methodVisitor) {
- super(OpcodesUtils.ASM_VERSION, owner, access, name, descriptor, methodVisitor)
- this.methodName = name
- this.methodDesc = descriptor
- this.methodAccess = access
- mStringBuilderUtils = new StringBuilderUtils(methodVisitor)
- }
-
- @Override
- void visitCode() {
- super.visitCode()
- if (isLogMethodStackMapFrame&&!OpcodesUtils.isNative(methodAccess) && !OpcodesUtils.isAbstract(methodAccess) && !OpcodesUtils.isInitMethod(methodName)) {
- boolean isStatic = OpcodesUtils.isStatic(methodAccess)
- int slotIndex = isStatic ? 0 : 1
- Type methodType = Type.getType(methodDesc)
- Type[] argumentsTypes = methodType.getArgumentTypes()
- for (Type type : argumentsTypes) {
- slotIndex += type.size
- }
- mStringBuilderUtils.appendLdcString("Frame的方法:" + methodName + methodDesc)
- mv.visitVarInsn(Opcodes.ASTORE, slotIndex)
- mv.visitVarInsn(Opcodes.ALOAD, slotIndex)
- mv.visitMethodInsn(OpcodesUtils.INVOKESTATIC, MethodFieldUtils.LOG_MANAGER, "printlnStr", "(Ljava/lang/String;)V", false)
- }
- printStackMapFrame()
- }
-
- @Override
- void visitInsn(int opcode) {
- super.visitInsn(opcode)
- printStackMapFrame()
- }
-
- @Override
- void visitIntInsn(int opcode, int operand) {
- super.visitIntInsn(opcode, operand)
- printStackMapFrame()
- }
-
- @Override
- void visitVarInsn(int opcode, int var) {
- super.visitVarInsn(opcode, var)
- printStackMapFrame()
- }
-
- @Override
- void visitTypeInsn(int opcode, String type) {
- super.visitTypeInsn(opcode, type)
- printStackMapFrame()
- }
-
- @Override
- void visitFieldInsn(int opcode, String owner, String name, String descriptor) {
- super.visitFieldInsn(opcode, owner, name, descriptor)
- printStackMapFrame()
- }
-
- @Override
- void visitMethodInsn(int opcode, String owner, String name, String descriptor, boolean isInterface) {
- super.visitMethodInsn(opcode, owner, name, descriptor, isInterface)
- printStackMapFrame()
- }
-
- @Override
- void visitInvokeDynamicInsn(String name, String descriptor, Handle bootstrapMethodHandle, Object... bootstrapMethodArguments) {
- super.visitInvokeDynamicInsn(name, descriptor, bootstrapMethodHandle, bootstrapMethodArguments)
- printStackMapFrame()
- }
-
- @Override
- void visitJumpInsn(int opcode, Label label) {
- super.visitJumpInsn(opcode, label)
- printStackMapFrame()
- }
-
- @Override
- void visitLdcInsn(Object value) {
- super.visitLdcInsn(value)
- printStackMapFrame()
- }
-
- @Override
- void visitIincInsn(int var, int increment) {
- super.visitIincInsn(var, increment)
- printStackMapFrame()
- }
-
- @Override
- void visitTableSwitchInsn(int min, int max, Label dflt, Label... labels) {
- super.visitTableSwitchInsn(min, max, dflt, labels)
- printStackMapFrame()
- }
-
- @Override
- void visitLookupSwitchInsn(Label dflt, int[] keys, Label[] labels) {
- super.visitLookupSwitchInsn(dflt, keys, labels)
- printStackMapFrame()
- }
-
- @Override
- void visitMultiANewArrayInsn(String descriptor, int numDimensions) {
- super.visitMultiANewArrayInsn(descriptor, numDimensions)
- printStackMapFrame()
- }
-
- @Override
- void visitTryCatchBlock(Label start, Label end, Label handler, String type) {
- super.visitTryCatchBlock(start, end, handler, type)
- printStackMapFrame()
- }
-
- @Override
- AnnotationVisitor visitAnnotation(String descriptor, boolean visible) {
- if (descriptor == "Lcom/peakmain/sdk/annotation/LogFrameInfo;") {
- isLogMethodStackMapFrame = true
- }
- return super.visitAnnotation(descriptor, visible)
- }
-
- private void printStackMapFrame() {
- if (!isLogMethodStackMapFrame || OpcodesUtils.isInitMethod(methodName)) return
- //局部变量表
- String locals_str = locals == null ? "[]" : list2Str(locals)
- String stack_str = stack == null ? "[]" : list2Str(stack)
- String line = String.format("%s %s", locals_str, stack_str)
- int slotIndex = OpcodesUtils.isStatic(methodAccess) ? 0 : 1
- slotIndex += locals == null ? 0 : locals.size()
- mStringBuilderUtils.appendLdcString("Frame打印:" + line)
- mv.visitVarInsn(Opcodes.ASTORE, slotIndex)
- mv.visitVarInsn(Opcodes.ALOAD, slotIndex)
- mv.visitMethodInsn(OpcodesUtils.INVOKESTATIC, MethodFieldUtils.LOG_MANAGER, "printlnStr", "(Ljava/lang/String;)V", false)
- println("Frame打印:" + line)
- }
-
- private String list2Str(List