Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Commit

Permalink
Overall cleanup and React DevTools (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
redstonekasi authored Jan 9, 2023
1 parent be58d7a commit fff95e0
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 28 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ android {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
namespace = "com.vendetta.xposed"
}

dependencies {
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vendetta.xposed">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
Expand Down
46 changes: 46 additions & 0 deletions app/src/main/assets/js/devtools.js

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions app/src/main/assets/js/modules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const oldObjectCreate = this.Object.create;
const win = this;
win.Object.create = (...args) => {
const obj = oldObjectCreate.apply(win.Object, args);
if (args[0] === null) {
win.modules = obj;
win.Object.create = oldObjectCreate;
}
return obj;
};
44 changes: 19 additions & 25 deletions app/src/main/java/com/vendetta/xposed/Main.kt
Original file line number Diff line number Diff line change
@@ -1,37 +1,25 @@
package com.vendetta.xposed

import com.vendetta.xposed.BuildConfig
import android.annotation.SuppressLint
import android.content.res.AssetManager
import android.content.pm.ApplicationInfo
import android.content.res.XModuleResources
import de.robv.android.xposed.IXposedHookLoadPackage
import de.robv.android.xposed.IXposedHookZygoteInit
import de.robv.android.xposed.XC_MethodHook
import de.robv.android.xposed.XposedBridge
import de.robv.android.xposed.callbacks.XC_LoadPackage
import java.io.File
import java.net.URL

class Main : IXposedHookLoadPackage {
@SuppressLint("PrivateApi", "BlockedPrivateApi")
class Main : IXposedHookZygoteInit, IXposedHookLoadPackage {
private lateinit var modResources: XModuleResources

override fun initZygote(startupParam: IXposedHookZygoteInit.StartupParam) {
modResources = XModuleResources.createInstance(startupParam.modulePath, null)
}

override fun handleLoadPackage(param: XC_LoadPackage.LoadPackageParam) {
if (param.packageName != "com.discord") return

val cache = File(param.appInfo.dataDir, "cache")
val modules = File(cache, "modules.js")
modules.parentFile?.mkdirs()
modules.writeText("""
const oldObjectCreate = this.Object.create;
const win = this;
win.Object.create = (...args) => {
const obj = oldObjectCreate.apply(win.Object, args);
if (args[0] === null) {
win.modules = obj;
win.Object.create = oldObjectCreate;
}
return obj;
};
""".trimIndent())

val catalystInstanceImpl = param.classLoader.loadClass("com.facebook.react.bridge.CatalystInstanceImpl")

val loadScriptFromAssets = catalystInstanceImpl.getDeclaredMethod(
Expand All @@ -48,20 +36,26 @@ class Main : IXposedHookLoadPackage {
Boolean::class.javaPrimitiveType
).apply { isAccessible = true }

val cache = File(param.appInfo.dataDir, "cache").also { it.mkdirs() }
val vendetta = File(cache, "vendetta.js")

XposedBridge.hookMethod(loadScriptFromAssets, object : XC_MethodHook() {
override fun beforeHookedMethod(param: MethodHookParam) {
try {
vendetta.writeBytes(URL(if (BuildConfig.BUILD_TYPE.equals("debug")) "http://localhost:4040/vendetta.js" else "https://raw.githubusercontent.com/vendetta-mod/builds/master/vendetta.js").readBytes())
} catch(e: Exception) {}
loadScriptFromFile.invoke(param.thisObject, modules.absolutePath, modules.absolutePath, param.args[2])
vendetta.writeBytes(URL(if (BuildConfig.BUILD_TYPE == "debug") "http://localhost:4040/vendetta.js" else "https://raw.githubusercontent.com/vendetta-mod/builds/master/vendetta.js").readBytes())
} catch(_: Exception) {}

modResources.assets.list("js")?.forEach {
// The last `true` signifies that this is loaded synchronously, this is
// important since these scripts need to load before Discord.
XposedBridge.invokeOriginalMethod(loadScriptFromAssets, param.thisObject, arrayOf(modResources.assets, "assets://js/$it", true))
}
}

override fun afterHookedMethod(param: MethodHookParam) {
try {
loadScriptFromFile.invoke(param.thisObject, vendetta.absolutePath, vendetta.absolutePath, param.args[2])
} catch(e: Exception) {}
} catch(_: Exception) {}
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:7.1.3")
classpath("com.android.tools.build:gradle:7.3.1")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10")

// NOTE: Do not place your application dependencies here; they belong
Expand Down

0 comments on commit fff95e0

Please sign in to comment.