Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
HolographicHat committed Aug 8, 2024
1 parent add41e1 commit a9bc60d
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 33 deletions.
29 changes: 17 additions & 12 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'org.jetbrains.kotlin.plugin.serialization'
}

android {

namespace 'hat.holo.token'
compileSdk 33
compileSdk 34

defaultConfig {
applicationId "hat.holo.token"
minSdk 28
targetSdk 33
targetSdk 34
versionCode 1
versionName "1.0"
vectorDrawables {
Expand Down Expand Up @@ -42,6 +43,9 @@ android {
}
kotlinOptions {
jvmTarget = '1.8'
freeCompilerArgs += [
"-Xcontext-receivers"
]
}
buildFeatures {
compose true
Expand All @@ -58,17 +62,18 @@ android {

dependencies {

implementation "androidx.core:core-ktx:1.9.0"
implementation "androidx.appcompat:appcompat:1.5.1"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.5.1"
implementation "androidx.compose.ui:ui:1.3.1"
implementation "androidx.compose.material:material:1.3.1"
implementation "androidx.activity:activity-compose:1.6.1"
implementation "androidx.core:core-ktx:1.13.0"
implementation "androidx.appcompat:appcompat:1.6.1"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.7.0"
implementation "androidx.compose.ui:ui:1.6.6"
implementation "androidx.compose.material:material:1.6.6"
implementation "androidx.activity:activity-compose:1.9.0"
implementation "androidx.constraintlayout:constraintlayout-compose:1.0.1"
implementation "com.google.accompanist:accompanist-systemuicontroller:0.27.1"
implementation "com.google.code.gson:gson:2.10"
implementation "com.squareup.okhttp3:okhttp:5.0.0-alpha.2"
implementation "com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.2"
implementation "com.google.accompanist:accompanist-systemuicontroller:0.34.0"
implementation "com.squareup.okhttp3:okhttp:5.0.0-alpha.14"
implementation "com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.14"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.1"
compileOnly files("libs/api-82.jar")

}
21 changes: 6 additions & 15 deletions app/src/main/java/hat/holo/token/ModuleMain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,18 @@ class ModuleMain : IXposedHookLoadPackage, IXposedHookZygoteInit {
appendToClassPath(app.applicationContext)
}
})
val u = loadClass("com.mihoyo.hyperion.user_profile.UserProfileFragment")
val rng = loadClass("rn.g") // FragmentUserProfileBinding.java
findAndHookMethod(u, "onViewCreated", android.view.View::class.java, android.os.Bundle::class.java, object : XC_MethodHook() {
val fragmentKlass = loadClass("com.mihoyo.hyperion.user_profile.UserProfileFragment")
findAndHookMethod(fragmentKlass, "onViewCreated", android.view.View::class.java, android.os.Bundle::class.java, object : XC_MethodHook() {
override fun afterHookedMethod(p: MethodHookParam) {
val getBinding = u.getDeclaredMethod("getBinding")
getBinding.isAccessible = true
val bindingInstance = getBinding.invoke(p.thisObject)
val getLinearLayout = rng.getDeclaredField("b")
getLinearLayout.isAccessible = true
val linearLayout = getLinearLayout.get(bindingInstance) as LinearLayout
val fragmentBinding = p.thisObject.invokeMethod<Any>("getBinding")
val linearLayout = fragmentBinding.visitField<LinearLayout>("b")
val ctx = linearLayout.context
val getScanButton = rng.getDeclaredField("w")
getScanButton.isAccessible = true
val scanButton = getScanButton.get(bindingInstance) as ImageView

val tokenBtn = ImageView(ctx)
tokenBtn.id = XResources.getFakeResId("getTokenIv")
tokenBtn.setImageDrawable(Res.iconToken)
val size = Dimension.convertDpToPixel(32f, ctx).roundToInt()
tokenBtn.layoutParams = ViewGroup.LayoutParams(size, size)
tokenBtn.setPadding(10, 6, 0, 6)
tokenBtn.setPadding(20, 6, 0, 6)
tokenBtn.scaleType = ImageView.ScaleType.FIT_XY
tokenBtn.setOnClickListener {
if (AccountManager.isLogin) {
Expand All @@ -91,7 +82,7 @@ class ModuleMain : IXposedHookLoadPackage, IXposedHookZygoteInit {
AppUtils.showToast("未登录")
}
}

val scanButton = fragmentBinding.visitField<ImageView>("w")
linearLayout.addView(tokenBtn, linearLayout.indexOfChild(scanButton) + 1)
for (i in 0 until linearLayout.childCount) {
val view = linearLayout.getChildAt(i)
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/hat/holo/token/utils/ReflectUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,17 @@ import java.lang.reflect.AccessibleObject
fun <T : AccessibleObject> T.setAccess() = apply {
isAccessible = true
}

@Suppress("UNCHECKED_CAST")
fun <R> Any.invokeMethod(methodName: String, vararg args: Any?) : R {
val method = this.javaClass.getDeclaredMethod(methodName)
method.isAccessible = true
return method.invoke(this, *args) as R
}

@Suppress("UNCHECKED_CAST")
fun <T> Any.visitField(fieldName: String) : T {
val field = this.javaClass.getDeclaredField(fieldName)
field.isAccessible = true
return field.get(this) as T
}
Loading

0 comments on commit a9bc60d

Please sign in to comment.