Skip to content

Commit

Permalink
1.1.1版本更新
Browse files Browse the repository at this point in the history
  • Loading branch information
wp committed Jul 16, 2020
1 parent f23e323 commit 3b35ac3
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,5 @@ lint/tmp/
repo/
*/.DS_Store
.DS_Store

.idea/*
24 changes: 23 additions & 1 deletion plugin/pushMaven.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apply plugin: 'signing'



version = '1.0.2'
version = '1.1.1'


def maven_artifactId = "analysys-allgro-plugin"
Expand All @@ -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'
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ class AnalysysASMTransform extends Transform {

// 执行最原来这个jar元素的字节码修改
byte[] modifiedClassBytes = null

if (entryName.endsWith(".class")) {
// 匹配以.class结尾的jar元素
String classFullName = entryName.replace("/", ".")
Expand All @@ -212,6 +213,7 @@ class AnalysysASMTransform extends Transform {
}
}


// 如果没有修改,就使用原来的元素
if (modifiedClassBytes == null) {
modifiedClassBytes = sourceClassBytes
Expand Down Expand Up @@ -239,6 +241,8 @@ class AnalysysASMTransform extends Transform {
* @return
*/
static File modifyClassFile(File dir, File classFile, File tempDir) {


File modified = null
try {
// 将path统一转换为命名空间方式
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -78,12 +78,25 @@ class AnalysysMethodCell implements Opcodes {
}

void hookMethod(MethodVisitor mv, List<Integer> 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<Integer> 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)
Expand All @@ -105,6 +118,12 @@ class AnalysysMethodCell implements Opcodes {


void hookLambdaMethod(MethodVisitor mv, boolean isStaticMethod, int paramStart, Type[] lambdaTypes, List<Integer> 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++) {
Expand All @@ -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)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,23 @@ class AnalysysMethodVisitor extends AdviceAdapter {
return super.visitAnnotation(s, b)
}

private static final Map<Integer, int[]> 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) {
Expand All @@ -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))
Expand All @@ -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
}
}
Expand All @@ -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') {
Expand Down

0 comments on commit 3b35ac3

Please sign in to comment.