Skip to content

Commit

Permalink
重构目录
Browse files Browse the repository at this point in the history
  • Loading branch information
zkw committed Oct 22, 2021
1 parent 93eb343 commit db0f887
Show file tree
Hide file tree
Showing 78 changed files with 28 additions and 25 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group 'com.zhihu'
version '1.1'
version '1.1.2'

repositories {
mavenCentral()
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions src/main/kotlin/com/zhihu/walker/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.zhihu.walker

import com.beust.jcommander.JCommander
import com.zhihu.walker.ext_walker.*
import com.zhihu.walker.utils.Log
import org.json.JSONArray
import org.json.JSONObject
import java.io.File
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/zhihu/walker/ext_walker/Walker.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.zhihu.walker.ext_walker

import com.zhihu.walker.Log
import com.zhihu.walker.utils.Log
import java.io.File

abstract class Walker {
Expand Down
5 changes: 0 additions & 5 deletions src/main/kotlin/com/zhihu/walker/ext_walker/WalkerForD2J.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package com.zhihu.walker.ext_walker

import com.zhihu.walker.visitor.DexFileRootVisitor
import com.zhihu.walker.visitor.GetStaticVisitor
import com.zhihu.walker.visitor.InvokeSpecialVisitor
import com.zhihu.walker.visitor.InvokeVirtualVisitor
import d2j.api.visitors.DexFileVisitor
import d2j.reader.DexFileReader
import org.objectweb.asm.ClassReader
import org.objectweb.asm.ClassVisitor
import java.io.File
import java.io.InputStream

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.zhihu.walker
package com.zhihu.walker.utils

class Log {

Expand Down
15 changes: 15 additions & 0 deletions src/main/kotlin/com/zhihu/walker/utils/StrUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.zhihu.walker.utils

class StrUtils {

companion object {

/**
* Ljava/lang/Object; => java/lang/Object
*/
@JvmStatic
fun trimClassName(name: String): String {
return name.substring(1 - name.length - 1)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package com.zhihu.walker.visitor

import com.zhihu.walker.utils.StrUtils.Companion.trimClassName
import d2j.api.visitors.DexClassVisitor
import d2j.api.visitors.DexFileVisitor
import java.io.File

class DexFileRootVisitor(val file: File) : DexFileVisitor() {

override fun visit(
access_flags: Int,
className: String,
superClass: String?,
interfaceNames: Array<out String>?
): DexClassVisitor {
val cv = super.visit(access_flags, className, superClass, interfaceNames)
return InvokeVirtualDexVisitor(file, className, cv)
return InvokeVirtualDexVisitor(file, trimClassName(className), cv)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.zhihu.walker.visitor

import com.zhihu.walker.Context
import com.zhihu.walker.Log
import com.zhihu.walker.Policy
import org.json.JSONArray
import org.objectweb.asm.ClassVisitor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.zhihu.walker.visitor

import com.zhihu.walker.Context
import com.zhihu.walker.Log
import com.zhihu.walker.Policy
import org.json.JSONArray
import org.objectweb.asm.ClassVisitor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
package com.zhihu.walker.visitor

import com.zhihu.walker.Context
import com.zhihu.walker.Log
import com.zhihu.walker.utils.Log
import com.zhihu.walker.Policy
import com.zhihu.walker.utils.StrUtils.Companion.trimClassName
import d2j.api.Method
import d2j.api.MethodHandle
import d2j.api.Proto
import d2j.api.reader.Op
import d2j.api.visitors.DexClassVisitor
import d2j.api.visitors.DexCodeVisitor
import d2j.api.visitors.DexFileVisitor
import d2j.api.visitors.DexMethodVisitor
import org.json.JSONArray
import org.objectweb.asm.ClassVisitor
import org.objectweb.asm.MethodVisitor
import org.objectweb.asm.Opcodes
import org.objectweb.asm.Opcodes.ASM9
import java.io.File

class InvokeVirtualDexVisitor(val file: File, val className: String, cv: DexClassVisitor? = null) :
Expand All @@ -25,9 +19,6 @@ class InvokeVirtualDexVisitor(val file: File, val className: String, cv: DexClas
it.instruct.toUpperCase() == "INVOKEVIRTUAL"
}

private lateinit var currentClassName: String


override fun visitMethod(
access: Int,
method: Method
Expand Down Expand Up @@ -63,8 +54,10 @@ class InvokeVirtualDexVisitor(val file: File, val className: String, cv: DexClas
super.visitMethodStmt(op, args, method)
return
}
val owner = method.owner
// method.owner = Ljava/lang/Object;
val owner = trimClassName(method.owner)
val name = method.name
Log.i("found!!! ${owner}.${method.name}")

policyList.filter {
owner == it.className
Expand All @@ -73,7 +66,7 @@ class InvokeVirtualDexVisitor(val file: File, val className: String, cv: DexClas
}.forEach {
val array = Context.outputJson[it.key] as JSONArray
array.put(
"文件 ${file.name} 中的 $currentClassName.$parentMethod() 方法调用了" +
"文件 ${file.name} 中的 $className.${parentMethod.name}() 方法调用了" +
" ${owner.substringAfterLast('/')}.$name(),${it.desc}"
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.zhihu.walker.visitor

import com.zhihu.walker.Context
import com.zhihu.walker.Log
import com.zhihu.walker.Policy
import org.json.JSONArray
import org.objectweb.asm.ClassVisitor
Expand Down

0 comments on commit db0f887

Please sign in to comment.