Skip to content

Commit

Permalink
improve ClassHunter
Browse files Browse the repository at this point in the history
  • Loading branch information
binarynoise committed Oct 20, 2024
1 parent 4f159e1 commit f9f5a42
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
1 change: 1 addition & 0 deletions ClassHunter/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/targetClass.txt
11 changes: 8 additions & 3 deletions ClassHunter/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ android {
minSdk = 26
targetSdk = 33

buildConfigField("String", "targetClass", """"..."""")
val file = File(projectDir, "targetClass.txt")
if (!file.exists()) {
file.createNewFile()
}
val classes = file.readLines().filterNot { it.startsWith("#") }
buildConfigField("String[]", "targetClass", classes.joinToString("\", \"", "{\"", "\"}"))
versionNameSuffix = classes.joinToString(", ", " (", ")")
}

buildFeatures {
buildConfig = true
}
}

dependencies {
}
dependencies {}
2 changes: 1 addition & 1 deletion ClassHunter/src/main/assets/xposed_init
Original file line number Diff line number Diff line change
@@ -1 +1 @@
de.binarynoise.ClassHunter.Hook
de.binarynoise.classHunter.Hook
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.binarynoise.ClassHunter
package de.binarynoise.classHunter

import android.util.Log
import de.binarynoise.ClassHunter.BuildConfig
import de.robv.android.xposed.IXposedHookLoadPackage
import de.robv.android.xposed.callbacks.XC_LoadPackage

Expand All @@ -10,7 +11,7 @@ class Hook : IXposedHookLoadPackage {
override fun handleLoadPackage(lpparam: XC_LoadPackage.LoadPackageParam) {
Log.i(TAG, "*".repeat(50))
Log.i(TAG, "loading package: ${lpparam.packageName}")
Log.i(TAG, "hunting for ${BuildConfig.targetClass}")
Log.i(TAG, "hunting for ${BuildConfig.targetClass.joinToString()}")

val classLoaders = mutableSetOf<ClassLoader>()

Expand All @@ -28,30 +29,31 @@ class Hook : IXposedHookLoadPackage {

Log.i(TAG, "currently known classloaders:")
classLoaders.forEach {
Log.d(TAG, "${it.toObjectString()}" + " - " + it.toString())
Log.v(TAG, "${it.toObjectString()} - $it")

try {
val cls = Class.forName(BuildConfig.targetClass, false, it)
Log.w(TAG, " - found class: ${cls.name}")

Log.i(TAG, " - methods:")
cls.declaredMethods.forEach {
Log.d(TAG, " - ${it.returnType.name} ${it.name}(${it.parameters.joinToString(", ") { it.name + " " + it.type.name }})")
BuildConfig.targetClass.forEach { className ->
try {
val cls = Class.forName(className, false, it)
Log.i(TAG, " - found class: ${cls.name} in package ${lpparam.packageName} by $it")

Log.i(TAG, " - methods:")
cls.declaredMethods.forEach { m ->
Log.v(TAG, " - ${m.returnType.name} ${m.name}(${m.parameters.joinToString(", ") { p -> p.name + " " + p.type.name }})")
}

Log.i(TAG, " - fields:")
cls.declaredFields.forEach { f ->
Log.d(TAG, " - ${f.type.name} ${f.name}")
}
} catch (_: Throwable) {
}

Log.i(TAG, " - fields:")
cls.declaredFields.forEach {
Log.d(TAG, " - ${it.type.name} ${it.name}")
}
} catch (_: Throwable) {

}
}
}

private fun collectParents(classLoader: ClassLoader, name: String, classLoaders: MutableSet<ClassLoader>) {
generateSequence(classLoader) { it.parent }.forEach {
Log.d(TAG, name + " - ${it.toObjectString()}")
Log.v(TAG, name + " - ${it.toObjectString()}")
classLoaders.add(it)
}
}
Expand Down

0 comments on commit f9f5a42

Please sign in to comment.