diff --git a/.gitignore b/.gitignore index 3de4078..b529e47 100644 --- a/.gitignore +++ b/.gitignore @@ -89,3 +89,5 @@ lint/tmp/ repo/ */.DS_Store .DS_Store + +.idea/* diff --git a/plugin/pushMaven.gradle b/plugin/pushMaven.gradle index b469c71..33ee9cf 100644 --- a/plugin/pushMaven.gradle +++ b/plugin/pushMaven.gradle @@ -4,7 +4,7 @@ apply plugin: 'signing' -version = '1.0.2' +version = '1.1.1' def maven_artifactId = "analysys-allgro-plugin" @@ -22,6 +22,28 @@ uploadArchives { groupId maven_groupId artifactId maven_artifactId packaging 'aar' + + url 'https://github.com/analysys/ans-allgro-plugin' + description maven_artifactId + licenses { + license { + name 'The Apache Software License, Version 2.0' + url 'http://www.apache.org/licenses/LICENSE-2.0.txt' + } + } + developers { + developer { + name 'analysys' + email 'analysys@analysys.com.cn' + url 'https://ark.analysys.cn' + } + } + + scm { + connection 'https://github.com/analysys/ans-allgro-plugin' + developerConnection 'https://github.com/analysys/ans-allgro-plugin' + url 'https://github.com/analysys/ans-allgro-plugin' + } } } } diff --git a/plugin/src/main/groovy/com/analysys/plugin/allgro/AnalysysASMTransform.groovy b/plugin/src/main/groovy/com/analysys/plugin/allgro/AnalysysASMTransform.groovy index 0af5cd9..63353a8 100644 --- a/plugin/src/main/groovy/com/analysys/plugin/allgro/AnalysysASMTransform.groovy +++ b/plugin/src/main/groovy/com/analysys/plugin/allgro/AnalysysASMTransform.groovy @@ -201,6 +201,7 @@ class AnalysysASMTransform extends Transform { // 执行最原来这个jar元素的字节码修改 byte[] modifiedClassBytes = null + if (entryName.endsWith(".class")) { // 匹配以.class结尾的jar元素 String classFullName = entryName.replace("/", ".") @@ -212,6 +213,7 @@ class AnalysysASMTransform extends Transform { } } + // 如果没有修改,就使用原来的元素 if (modifiedClassBytes == null) { modifiedClassBytes = sourceClassBytes @@ -239,6 +241,8 @@ class AnalysysASMTransform extends Transform { * @return */ static File modifyClassFile(File dir, File classFile, File tempDir) { + + File modified = null try { // 将path统一转换为命名空间方式 diff --git a/plugin/src/main/groovy/com/analysys/plugin/allgro/ClassChecker.groovy b/plugin/src/main/groovy/com/analysys/plugin/allgro/ClassChecker.groovy index 436ba26..65e7fd2 100755 --- a/plugin/src/main/groovy/com/analysys/plugin/allgro/ClassChecker.groovy +++ b/plugin/src/main/groovy/com/analysys/plugin/allgro/ClassChecker.groovy @@ -24,7 +24,8 @@ class ClassChecker { 'androidx', 'android.arch', 'com.google.android', - 'com.bumptech.glide.manager.SupportRequestManagerFragment'] + 'com.bumptech.glide.manager.SupportRequestManagerFragment', + 'com.unionpay'] private static final String ANALYSYS_API = 'com.analysys.AnalysysAgent.class' diff --git a/plugin/src/main/groovy/com/analysys/plugin/allgro/asm/AnalysysHookConfig.groovy b/plugin/src/main/groovy/com/analysys/plugin/allgro/asm/AnalysysHookConfig.groovy index c5b5587..bb64668 100644 --- a/plugin/src/main/groovy/com/analysys/plugin/allgro/asm/AnalysysHookConfig.groovy +++ b/plugin/src/main/groovy/com/analysys/plugin/allgro/asm/AnalysysHookConfig.groovy @@ -64,6 +64,13 @@ class AnalysysHookConfig { 1, [Opcodes.ALOAD], 'trackViewOnClick', '(Landroid/view/View;Z)V')) + CLICK_HOOK.add(new AnalysysMethodCell( + 'Landroid/view/View$AccessibilityDelegate;', + 'sendAccessibilityEvent', + '(Landroid/view/View;I)V', + 1, [Opcodes.ALOAD, Opcodes.ILOAD], + 'trackSendAccessibilityEvent', + '(Landroid/view/View;IZ)V')) CLICK_HOOK.add(new AnalysysMethodCell( 'Landroid/widget/CompoundButton$OnCheckedChangeListener;', 'onCheckedChanged', diff --git a/plugin/src/main/groovy/com/analysys/plugin/allgro/asm/AnalysysMethodCell.groovy b/plugin/src/main/groovy/com/analysys/plugin/allgro/asm/AnalysysMethodCell.groovy index b673f92..970786d 100644 --- a/plugin/src/main/groovy/com/analysys/plugin/allgro/asm/AnalysysMethodCell.groovy +++ b/plugin/src/main/groovy/com/analysys/plugin/allgro/asm/AnalysysMethodCell.groovy @@ -1,7 +1,7 @@ package com.analysys.plugin.allgro.asm - import org.objectweb.asm.ClassVisitor +import org.objectweb.asm.Label import org.objectweb.asm.MethodVisitor import org.objectweb.asm.Opcodes import org.objectweb.asm.Type @@ -78,12 +78,25 @@ class AnalysysMethodCell implements Opcodes { } void hookMethod(MethodVisitor mv, List agentOpcodeExt) { + Label l0 = new Label() + Label l1 = new Label() + Label l2 = new Label() + mv.visitTryCatchBlock(l0, l1, l2, "java/lang/Throwable") + mv.visitLabel(l0) + String owner = AnalysysHookConfig.ASM_PROBE_HELP mv.visitMethodInsn(INVOKESTATIC, owner, "getInstance", "()L${owner};", false) List agentOpcodes = new ArrayList<>(mOpcodes) agentOpcodes.addAll(agentOpcodeExt) visitMethodWithLoadedParams(mv, INVOKEVIRTUAL, owner, mAgentName, mAgentDesc, mParamsStart, agentOpcodes) + mv.visitLabel(l1) + Label l3 = new Label() + mv.visitJumpInsn(Opcodes.GOTO, l3) + mv.visitLabel(l2) + mv.visitVarInsn(Opcodes.ASTORE, 1) + mv.visitLabel(l3) + // mv.visitMethodInsn(INVOKESTATIC, owner, "getInstance", "()L${owner};", false) // mv.visitVarInsn(ALOAD, 0) // mv.visitVarInsn(ALOAD, 1) @@ -105,6 +118,12 @@ class AnalysysMethodCell implements Opcodes { void hookLambdaMethod(MethodVisitor mv, boolean isStaticMethod, int paramStart, Type[] lambdaTypes, List agentOpcodeExt) { + Label l0 = new Label() + Label l1 = new Label() + Label l2 = new Label() + mv.visitTryCatchBlock(l0, l1, l2, "java/lang/Throwable") + mv.visitLabel(l0) + String owner = AnalysysHookConfig.ASM_PROBE_HELP mv.visitMethodInsn(INVOKESTATIC, owner, "getInstance", "()L${owner};", false) for (int i = paramStart; i < paramStart + mOpcodes.size(); i++) { @@ -114,6 +133,13 @@ class AnalysysMethodCell implements Opcodes { mv.visitInsn(agentOpcodeExt[i]) } mv.visitMethodInsn(INVOKEVIRTUAL, owner, mAgentName, mAgentDesc, false) + + mv.visitLabel(l1) + Label l3 = new Label() + mv.visitJumpInsn(Opcodes.GOTO, l3) + mv.visitLabel(l2) + mv.visitInsn(POP); + mv.visitLabel(l3) } /** diff --git a/plugin/src/main/groovy/com/analysys/plugin/allgro/asm/visitor/AnalysysClassVisitor.groovy b/plugin/src/main/groovy/com/analysys/plugin/allgro/asm/visitor/AnalysysClassVisitor.groovy index 52c4a6e..4491edf 100644 --- a/plugin/src/main/groovy/com/analysys/plugin/allgro/asm/visitor/AnalysysClassVisitor.groovy +++ b/plugin/src/main/groovy/com/analysys/plugin/allgro/asm/visitor/AnalysysClassVisitor.groovy @@ -57,7 +57,6 @@ class AnalysysClassVisitor extends ClassVisitor implements Opcodes { mClassName = name mSuperName = superName mInterfaces = interfaces - super.visit(version, access, name, signature, superName, interfaces) isFragmentClass = ClassChecker.isFragment(mSuperName) if (isFragmentClass) { mFragmentMethods.putAll(AnalysysHookConfig.PV_METHODS) diff --git a/plugin/src/main/groovy/com/analysys/plugin/allgro/asm/visitor/AnalysysMethodVisitor.groovy b/plugin/src/main/groovy/com/analysys/plugin/allgro/asm/visitor/AnalysysMethodVisitor.groovy index 884edd5..21f3adb 100644 --- a/plugin/src/main/groovy/com/analysys/plugin/allgro/asm/visitor/AnalysysMethodVisitor.groovy +++ b/plugin/src/main/groovy/com/analysys/plugin/allgro/asm/visitor/AnalysysMethodVisitor.groovy @@ -99,11 +99,23 @@ class AnalysysMethodVisitor extends AdviceAdapter { return super.visitAnnotation(s, b) } + private static final Map RET_OPT_CODE = new HashMap<>() + static { + RET_OPT_CODE.put(IRETURN, [ISTORE,ILOAD]) + RET_OPT_CODE.put(LRETURN, [LSTORE,LLOAD]) + RET_OPT_CODE.put(FRETURN, [FSTORE,FLOAD]) + RET_OPT_CODE.put(DRETURN, [DSTORE,DLOAD]) + RET_OPT_CODE.put(ARETURN, [ASTORE,ALOAD]) + RET_OPT_CODE.put(RETURN, null) + } @Override protected void onMethodExit(int opcode) { super.onMethodExit(opcode) - + if (!RET_OPT_CODE.containsKey(opcode)) { + return + } + int[] retOptCode = RET_OPT_CODE.get(opcode) if (ClassChecker.mExtension.lambdaEnabled) { AnalysysMethodCell methodCell = mCv.mLambdaMethodCells.get(mNameDesc) if (methodCell != null) { @@ -124,7 +136,15 @@ class AnalysysMethodVisitor extends AdviceAdapter { } boolean isStaticMethod = ClassChecker.isStatic(mAccess) if (methodCell.mOwner) { + int nl = -1 + if (retOptCode != null) { + nl = nextLocal + mv.visitVarInsn(retOptCode[0], nl) + } methodCell.hookLambdaMethod(mv, isStaticMethod, paramStart, lambdaTypes, [clickAnn]) + if (retOptCode != null) { + mv.visitVarInsn(retOptCode[1], nl) + } } else if (methodCell.mDesc == '(Landroid/view/MenuItem;)Z') { // mv.visitVarInsn(ALOAD, 0) // mv.visitVarInsn(ALOAD, AnalysysMethodCell.getVisitPosition(lambdaTypes, paramStart, isStaticMethod)) @@ -145,7 +165,15 @@ class AnalysysMethodVisitor extends AdviceAdapter { if (methodCell != null) { mCv.mFragmentMethods.remove(mNameDesc) def pvAnn = mCv.hasTrackPvAnn ? ICONST_1 : ICONST_0 + int nl = -1 + if (retOptCode != null) { + nl = nextLocal + mv.visitVarInsn(retOptCode[0], nl) + } methodCell.hookMethod(mv, [pvAnn]) + if (retOptCode != null) { + mv.visitVarInsn(retOptCode[1], nl) + } return } } @@ -154,7 +182,15 @@ class AnalysysMethodVisitor extends AdviceAdapter { AnalysysMethodCell methodCell = AnalysysHookConfig.CLICK_METHODS.get(mNameDesc) def clickAnn = mCv.hasTrackClickAnnOnClass || hasTrackClickAnnOnMethod ? ICONST_1 : ICONST_0 if (methodCell != null) { + int nl = -1 + if (retOptCode != null) { + nl = nextLocal + mv.visitVarInsn(retOptCode[0], nl) + } methodCell.hookMethod(mv, [clickAnn]) + if (retOptCode != null) { + mv.visitVarInsn(retOptCode[1], nl) + } } else { if (mNameDesc == 'onDrawerOpened(Landroid/view/View;)V' || mNameDesc == 'onDrawerClosed(Landroid/view/View;)V') {