fix: bugfixes in microg

This commit is contained in:
oSumAtrIX 2022-05-26 03:47:11 +02:00
parent 7bc60943cb
commit a43b33bdbb
No known key found for this signature in database
GPG key ID: A9B3094ACDB604B4
2 changed files with 38 additions and 34 deletions

View file

@ -20,3 +20,11 @@ internal fun String.startsWithAny(vararg prefix: String): Boolean {
return false return false
} }
internal fun String.containsAny(vararg others: String): Boolean {
for (other in others)
if (this.contains(other))
return true
return false
}

View file

@ -1,5 +1,6 @@
package app.revanced.patches.youtube.misc.microg.patch.bytecode package app.revanced.patches.youtube.misc.microg.patch.bytecode
import app.revanced.extensions.containsAny
import app.revanced.extensions.startsWithAny import app.revanced.extensions.startsWithAny
import app.revanced.patcher.annotation.Description import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Name
@ -54,19 +55,20 @@ class MicroGBytecodePatch : BytecodePatch(
val implementation = method.implementation ?: return@methodLoop val implementation = method.implementation ?: return@methodLoop
var proxiedImplementation: MutableMethodImplementation? = null var proxiedImplementation: MutableMethodImplementation? = null
implementation.instructions.forEachIndexed { i, instruction -> implementation.instructions.forEachIndexed { i, instruction ->
if (instruction.opcode == Opcode.CONST_STRING) { if (instruction.opcode != Opcode.CONST_STRING) return@forEachIndexed
val stringValue = ((instruction as Instruction21c).reference as StringReference).string val stringValue = ((instruction as Instruction21c).reference as StringReference).string
val replaceMode = if (stringValue == "com.google" || stringValue.startsWithAny( val replaceMode =
"com.google.android.gms.auth.accounts", if (stringValue == "com.google" || stringValue == "com.google.android.gms" ||
stringValue.startsWithAny(
"com.google.iid",
"com.google.android.gms.chimera", "com.google.android.gms.chimera",
"com.google.android.c2dm", "com.google.android.c2dm",
"com.google.android.c2dm", ) || stringValue.containsAny(
"com.google.android.gms.auth.accounts",
"com.google.android.gsf", "com.google.android.gsf",
"com.google.android.c2dm",
"com.google.iid",
"content://com.google.settings" "content://com.google.settings"
) )
) { ) {
@ -83,7 +85,6 @@ class MicroGBytecodePatch : BytecodePatch(
StringReplaceMode.DO_NOT_REPLACE StringReplaceMode.DO_NOT_REPLACE
} }
if (replaceMode != StringReplaceMode.DO_NOT_REPLACE) { if (replaceMode != StringReplaceMode.DO_NOT_REPLACE) {
if (proxiedClass == null) { if (proxiedClass == null) {
proxiedClass = data.proxy(classDef).resolve() proxiedClass = data.proxy(classDef).resolve()
@ -95,8 +96,7 @@ class MicroGBytecodePatch : BytecodePatch(
}.implementation!! }.implementation!!
} }
val newString = val newString = if (replaceMode == StringReplaceMode.REPLACE_WITH_REVANCED) stringValue.replace(
if (replaceMode == StringReplaceMode.REPLACE_WITH_REVANCED) stringValue.replace(
"com.google.android.youtube", REVANCED_PACKAGE_NAME "com.google.android.youtube", REVANCED_PACKAGE_NAME
) )
else stringValue.replace("com.google", BASE_MICROG_PACKAGE_NAME) else stringValue.replace("com.google", BASE_MICROG_PACKAGE_NAME)
@ -110,7 +110,6 @@ class MicroGBytecodePatch : BytecodePatch(
} }
} }
} }
}
// replace string back // replace string back
@ -126,9 +125,6 @@ class MicroGBytecodePatch : BytecodePatch(
"const-string v0, \"com.google.android.gms\"".toInstruction() "const-string v0, \"com.google.android.gms\"".toInstruction()
) )
// allow GC to clean unused/ replaced immutable class definitions after this call
data.classes.applyProxies()
return PatchResultSuccess() return PatchResultSuccess()
} }