Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyJingFish committed Aug 8, 2024
2 parents c1128a4 + f752278 commit a66378c
Show file tree
Hide file tree
Showing 14 changed files with 279 additions and 280 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
plugins {
//必须项 👇 apply 设置为 true 自动为所有module“预”配置debugMode,false则按下边步骤五的方式二
id "io.github.FlyJingFish.AndroidAop.android-aop" version "2.0.5" apply true
id "io.github.FlyJingFish.AndroidAop.android-aop" version "2.0.6" apply true
}
```

Expand All @@ -83,7 +83,7 @@ plugins {
buildscript {
dependencies {
//必须项 👇
classpath 'io.github.FlyJingFish.AndroidAop:android-aop-plugin:2.0.5'
classpath 'io.github.FlyJingFish.AndroidAop:android-aop-plugin:2.0.6'
}
}
// 👇加上这句自动为所有module“预”配置debugMode,不加则按下边步骤五的方式二
Expand Down Expand Up @@ -122,7 +122,7 @@ apply plugin: 'android.aop' //最好放在最后一行
//必须项 👇
plugins {
...
id "io.github.FlyJingFish.AndroidAop.android-aop" version "2.0.5"//最好放在最后一行
id "io.github.FlyJingFish.AndroidAop.android-aop" version "2.0.6"//最好放在最后一行
}
```

Expand All @@ -148,17 +148,17 @@ plugins {
dependencies {
//必须项 👇
implementation 'io.github.FlyJingFish.AndroidAop:android-aop-core:2.0.5'
implementation 'io.github.FlyJingFish.AndroidAop:android-aop-annotation:2.0.5'
implementation 'io.github.FlyJingFish.AndroidAop:android-aop-core:2.0.6'
implementation 'io.github.FlyJingFish.AndroidAop:android-aop-annotation:2.0.6'
//必须项 👇如果您项目内已经有了这项不用加也可以
implementation 'androidx.appcompat:appcompat:1.3.0' // 至少在1.3.0及以上
//非必须项 👇,如果你想自定义切面需要用到,⚠️支持Java和Kotlin代码写的切面
ksp 'io.github.FlyJingFish.AndroidAop:android-aop-ksp:2.0.5'
ksp 'io.github.FlyJingFish.AndroidAop:android-aop-ksp:2.0.6'
//非必须项 👇,如果你想自定义切面需要用到,⚠️只适用于Java代码写的切面
annotationProcessor 'io.github.FlyJingFish.AndroidAop:android-aop-processor:2.0.5'
annotationProcessor 'io.github.FlyJingFish.AndroidAop:android-aop-processor:2.0.6'
//⚠️上边的 android-aop-ksp 和 android-aop-processor 二选一
}
```
Expand Down
14 changes: 7 additions & 7 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Using the **plugins DSL**:
plugins {
//Required item 👇 apply is set to true to automatically apply debugMode to all modules, if false, follow step 5 below.
id "io.github.FlyJingFish.AndroidAop.android-aop" version "2.0.5" apply true
id "io.github.FlyJingFish.AndroidAop.android-aop" version "2.0.6" apply true
}
```

Expand All @@ -80,7 +80,7 @@ plugins {
buildscript {
dependencies {
//Required items 👇
classpath 'io.github.FlyJingFish.AndroidAop:android-aop-plugin:2.0.5'
classpath 'io.github.FlyJingFish.AndroidAop:android-aop-plugin:2.0.6'
}
}
//👇Add this sentence to automatically apply debugMode to all modules. If not, follow step 5 below.
Expand Down Expand Up @@ -119,7 +119,7 @@ Add directly to ```build.gradle``` of **app**
//Required items 👇
plugins {
...
id "io.github.FlyJingFish.AndroidAop.android-aop" version "2.0.5"
id "io.github.FlyJingFish.AndroidAop.android-aop" version "2.0.6"
}
```

Expand Down Expand Up @@ -149,16 +149,16 @@ plugins {
dependencies {
//Required items 👇
implementation 'io.github.FlyJingFish.AndroidAop:android-aop-core:2.0.5'
implementation 'io.github.FlyJingFish.AndroidAop:android-aop-annotation:2.0.5'
implementation 'io.github.FlyJingFish.AndroidAop:android-aop-core:2.0.6'
implementation 'io.github.FlyJingFish.AndroidAop:android-aop-annotation:2.0.6'
//Required item 👇If you already have this item in your project, you don’t need to add it.
implementation 'androidx.appcompat:appcompat:1.3.0' // At least in 1.3.0 and above
//Optional 👇, if you want to customize aspects, you need to use them, ⚠️supports aspects written in Java and Kotlin code
ksp 'io.github.FlyJingFish.AndroidAop:android-aop-ksp:2.0.5'
ksp 'io.github.FlyJingFish.AndroidAop:android-aop-ksp:2.0.6'
//Optional 👇, if you want to customize aspects, you need to use them, ⚠️only applies to aspects written in Java code
annotationProcessor 'io.github.FlyJingFish.AndroidAop:android-aop-processor:2.0.5'
annotationProcessor 'io.github.FlyJingFish.AndroidAop:android-aop-processor:2.0.6'
//⚠️Choose one of the above android-aop-ksp and android-aop-processor
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ data class MethodRecord(
val descriptor: String,
val cutClassName:MutableSet<String> = mutableSetOf(),
val lambda: Boolean = false,
val cutInfo: MutableMap<String, CutInfo> = mutableMapOf(),
var multipleSuspendClass: Boolean = false
val cutInfo: MutableMap<String, CutInfo> = mutableMapOf()
) {
fun getKey(): String {
return methodName + descriptor + cutClassName + lambda
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.objectweb.asm.ClassReader
import org.objectweb.asm.tree.ClassNode
import org.objectweb.asm.tree.MethodNode
import java.util.Arrays
import kotlin.math.min


class MethodParamNamesScanner(inputStreamBytes: ByteArray) {
Expand Down Expand Up @@ -33,7 +34,7 @@ class MethodParamNamesScanner(inputStreamBytes: ByteArray) {
): List<String> {
val list: MutableList<String> = ArrayList()
for (i in methods.indices) {
val varNames: MutableList<LocalVariable> = ArrayList()
val varNames = mutableMapOf<Int,LocalVariable>()
val method = methods[i]
if (method.desc == desc && method.name == name) {
val localVariables = method.localVariables
Expand All @@ -42,12 +43,18 @@ class MethodParamNamesScanner(inputStreamBytes: ByteArray) {
// index-记录了正确的方法本地变量索引。(方法本地变量顺序可能会被打乱。而index记录了原始的顺序)
val index = localVariables[l].index
if ("this" != varName)
varNames.add(LocalVariable(index, varName))
varNames[index] = (LocalVariable(index, varName))
}
val tmpArr = varNames.toTypedArray()
// 根据index来重排序,以确保正确的顺序
Arrays.sort(tmpArr)
for (j in 0 until size) {

val sortedMap = varNames.entries.sortedBy { it.key }.associate { it.toPair() }

val tmpArr = mutableListOf<LocalVariable>()
for (entry in sortedMap.entries) {
tmpArr.add(entry.value)
}

val len = min(tmpArr.size , size)
for (j in 0 until len) {
list.add(tmpArr[j].name)
}
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@ package com.flyjingfish.android_aop_plugin.scanner_visitor

import org.objectweb.asm.AnnotationVisitor
import org.objectweb.asm.MethodVisitor
import org.objectweb.asm.Opcodes

class RemoveAnnotation(
methodVisitor: MethodVisitor?,
className: String,
methodDescriptor: String,
onResultListener : OnResultListener
) :
SearchSuspendClass(methodVisitor,className,methodDescriptor,onResultListener) {

methodVisitor: MethodVisitor?
) : MethodVisitor(Opcodes.ASM9, methodVisitor) {

override fun visitAnnotation(descriptor: String?, visible: Boolean): AnnotationVisitor? {
return null
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import java.util.regex.Matcher
import java.util.regex.Pattern

object WovenIntoCode {
const val METHOD_SUFFIX = "\$\$AndroidAOP"
@Throws(Exception::class)
fun modifyClass(
inputStreamBytes: ByteArray?,
Expand All @@ -66,9 +65,10 @@ object WovenIntoCode {
methodRecordHashMap.forEach { (_: String, value: MethodRecord) ->
val oldMethodName = value.methodName
val oldDescriptor = value.descriptor
val newMethodName = "$oldMethodName$$${(Utils.slashToDot(className)+descriptor).computeMD5()}$METHOD_SUFFIX"
val newMethodName = Utils.getTargetMethodName(oldMethodName, className, descriptor)
if (newMethodName == name && oldDescriptor == descriptor){
wovenRecord.add(value)
WovenInfoUtils.addAopMethodCutInnerClassInfoInvokeMethod(className,newMethodName,descriptor)
}
}

Expand Down Expand Up @@ -239,7 +239,7 @@ object WovenIntoCode {
}else{
ACC_PUBLIC + ACC_FINAL
}
val newMethodName = "$oldMethodName$$${(Utils.slashToDot(className)+descriptor).computeMD5()}$METHOD_SUFFIX"
val newMethodName = Utils.getTargetMethodName(oldMethodName, className, descriptor)
var mv: MethodVisitor? = super.visitMethod(
newAccess,
newMethodName,
Expand All @@ -252,11 +252,7 @@ object WovenIntoCode {
mv = MethodReplaceInvokeAdapter(className,"$name$descriptor",mv)
}
WovenInfoUtils.addAopMethodCutInnerClassInfoInvokeMethod(className,newMethodName,descriptor)
RemoveAnnotation(mv,className,descriptor,object :SearchSuspendClass.OnResultListener{
override fun onBack() {
value.multipleSuspendClass = true
}
})
RemoveAnnotation(mv)
} else {
null
}
Expand Down Expand Up @@ -288,7 +284,7 @@ object WovenIntoCode {
val targetClassName = ctClass.name
val oldMethodName = value.methodName
val oldDescriptor = value.descriptor
val targetMethodName = "$oldMethodName$$${(targetClassName+oldDescriptor).computeMD5()}$METHOD_SUFFIX"
val targetMethodName = Utils.getTargetMethodName(oldMethodName,targetClassName,oldDescriptor)
val cutClassNameArray = StringBuilder()
value.cutClassName.toList().forEachIndexed { index, item ->
cutClassNameArray.append("\"").append(item).append("\"")
Expand All @@ -301,16 +297,21 @@ object WovenIntoCode {
//// WovenInfoUtils.checkNoneInvokeClass(invokeClassName)
// return@forEach
// }
val newMethodBody : String ?= null
try {
val ctMethod =
getCtMethod(ctClass, oldMethodName, oldDescriptor)
val targetMethod =
getCtMethod(ctClass, targetMethodName, oldDescriptor)
if (ctMethod == null){
printLog("------ctMethod ${oldMethodName}${oldDescriptor} 方法找不到了-----")
if (!isSuspend){
printLog("------ctMethod ${targetClassName}${oldMethodName}${oldDescriptor} 方法找不到了-----")
}
return@forEach
}else if (targetMethod == null){
printLog("------targetMethod ${targetMethodName}${oldDescriptor} 方法找不到了-----")
if (!isSuspend){
printLog("------targetMethod ${targetClassName}${targetMethodName}${oldDescriptor} 方法找不到了-----")
}
return@forEach
}

Expand Down Expand Up @@ -412,7 +413,7 @@ object WovenIntoCode {
cp.importPackage(invokeClassName)
val argReflect = if (ClassFileUtils.reflectInvokeMethod) "" else ",new $invokeClassName()"
val constructor = "$targetClassName.class,${if(isStaticMethod)"null" else "\$0"},\"$oldMethodName\",\"$targetMethodName\""
val body =
val newMethodBody =
" {AndroidAopJoinPoint pointCut = new AndroidAopJoinPoint($constructor);\n"+
"String[] cutClassNames = new String[]{$cutClassNameArray};\n"+
"pointCut.setCutMatchClassNames(cutClassNames);\n"+
Expand All @@ -424,11 +425,13 @@ object WovenIntoCode {
(if (isHasArgs) " Object[] args = new Object[]{$argsBuffer};\n" else "") +
(if (isHasArgs) " pointCut.setArgs(args$argReflect);\n" else " pointCut.setArgs(null$argReflect);\n") +
" "+returnStr+";}"
ctMethod.setBody(body)
ctMethod.setBody(newMethodBody)
InitConfig.putCutInfo(value)
} catch (e: NotFoundException) {
throw RuntimeException(e)
} catch (e: CannotCompileException) {
printLog("newMethodBody=$newMethodBody")
ClassFileUtils.deleteInvokeClass(invokeClassName)
throw RuntimeException(e)
}
}
Expand Down
Loading

0 comments on commit a66378c

Please sign in to comment.