fix: support 307201+
Discord bumped React Native to 0.81.4 and script loader classes are now named differently.
This commit is contained in:
parent
a6c9e7ed0a
commit
113cb05e91
2 changed files with 8 additions and 4 deletions
|
|
@ -47,6 +47,7 @@ class HookScriptLoaderModule : Module() {
|
|||
mainScript = File(cacheDir, Constants.MAIN_SCRIPT_FILE).apply { asFile() }
|
||||
|
||||
listOf(
|
||||
"com.facebook.react.runtime.ReactInstance\$loadJSBundle$1",
|
||||
"com.facebook.react.runtime.ReactInstance$1",
|
||||
// TODO: Remove once Discord fully switches to Bridgeless
|
||||
"com.facebook.react.bridge.CatalystInstanceImpl"
|
||||
|
|
@ -54,7 +55,7 @@ class HookScriptLoaderModule : Module() {
|
|||
.forEach { hook(it) }
|
||||
}
|
||||
|
||||
private fun hook(instance: Class<*>) {
|
||||
private fun hook(instance: Class<*>) = runCatching {
|
||||
val loadScriptFromAssets = instance.method(
|
||||
"loadScriptFromAssets",
|
||||
AssetManager::class.java,
|
||||
|
|
@ -82,6 +83,8 @@ class HookScriptLoaderModule : Module() {
|
|||
runCustomScripts(loadScriptFromFile, loadScriptFromAssets)
|
||||
}
|
||||
}
|
||||
}.onFailure {
|
||||
Log.e("Failed to hook script loading methods in ${instance.name}:", it)
|
||||
}
|
||||
|
||||
private fun HookScope.runCustomScripts(loadScriptFromFile: Method, loadScriptFromAssets: Method) {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,8 @@ class PayloadGlobalModule(private val modules: List<Module>) : Module() {
|
|||
|
||||
override fun onLoad(packageParam: XC_LoadPackage.LoadPackageParam) = with(packageParam) {
|
||||
val catalystInstance = classLoader.safeLoadClass("com.facebook.react.bridge.CatalystInstanceImpl")
|
||||
val reactInstance = classLoader.safeLoadClass("com.facebook.react.runtime.ReactInstance$1")
|
||||
val scriptLoader = classLoader.safeLoadClass("com.facebook.react.runtime.ReactInstance\$loadJSBundle$1")
|
||||
?: classLoader.safeLoadClass("com.facebook.react.runtime.ReactInstance$1")
|
||||
|
||||
val setGlobalVariable: (XC_MethodHook.MethodHookParam, String, String) -> Unit = { param, key, json ->
|
||||
runCatching {
|
||||
|
|
@ -43,7 +44,7 @@ class PayloadGlobalModule(private val modules: List<Module>) : Module() {
|
|||
writeText("this[${JSON.encodeToString(key)}]=$json")
|
||||
|
||||
XposedBridge.invokeOriginalMethod(
|
||||
reactInstance!!.method(
|
||||
scriptLoader!!.method(
|
||||
"loadScriptFromFile",
|
||||
String::class.java,
|
||||
String::class.java,
|
||||
|
|
@ -64,7 +65,7 @@ class PayloadGlobalModule(private val modules: List<Module>) : Module() {
|
|||
build()
|
||||
}
|
||||
|
||||
listOf(catalystInstance, reactInstance).forEach { if (it != null) hook(it, hook) }
|
||||
listOf(catalystInstance, scriptLoader).forEach { if (it != null) hook(it, hook) }
|
||||
}
|
||||
|
||||
private fun hook(instance: Class<*>, hook: XC_MethodHook) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue