mirror of
https://github.com/revanced/revanced-patches
synced 2024-11-10 15:39:23 +01:00
refactor: MicroGPatch
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
parent
91474ba073
commit
af0b16482f
@ -11,4 +11,12 @@ internal fun MutableMethodImplementation.injectHideCall(
|
|||||||
index,
|
index,
|
||||||
"invoke-static { v$register }, Lfi/razerman/youtube/XAdRemover;->HideView(Landroid/view/View;)V".toInstruction()
|
"invoke-static { v$register }, Lfi/razerman/youtube/XAdRemover;->HideView(Landroid/view/View;)V".toInstruction()
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun String.startsWithAny(vararg prefix: String): Boolean {
|
||||||
|
for (_prefix in prefix)
|
||||||
|
if (this.startsWith(_prefix))
|
||||||
|
return true
|
||||||
|
|
||||||
|
return false
|
||||||
}
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package app.revanced.patches.misc
|
package app.revanced.patches.misc
|
||||||
|
|
||||||
|
import app.revanced.extensions.startsWithAny
|
||||||
import app.revanced.patcher.PatcherData
|
import app.revanced.patcher.PatcherData
|
||||||
import app.revanced.patcher.extensions.addInstructions
|
import app.revanced.patcher.extensions.addInstructions
|
||||||
import app.revanced.patcher.extensions.or
|
import app.revanced.patcher.extensions.or
|
||||||
@ -385,47 +386,27 @@ class MicroGPatch : Patch(
|
|||||||
override fun execute(patcherData: PatcherData): PatchResult {
|
override fun execute(patcherData: PatcherData): PatchResult {
|
||||||
// smali patches
|
// smali patches
|
||||||
disablePlayServiceChecks()
|
disablePlayServiceChecks()
|
||||||
for (classDef in patcherData.classes) {
|
patcherData.classes.forEach { classDef ->
|
||||||
methodLoop@ for (method in classDef.methods) {
|
classDef.methods.forEach methodLoop@{ method ->
|
||||||
val implementation = method.implementation ?: continue@methodLoop
|
val implementation = method.implementation ?: return@methodLoop
|
||||||
|
|
||||||
implementation.instructions.forEachIndexed { i, instruction ->
|
implementation.instructions.forEachIndexed { i, instruction ->
|
||||||
if (instruction.opcode == Opcode.CONST_STRING) {
|
if (instruction.opcode == Opcode.CONST_STRING) {
|
||||||
|
val instructionString = ((instruction as Instruction21c).reference as StringReference).string
|
||||||
val reference = ((instruction as Instruction21c).reference as StringReference).string
|
patcherData
|
||||||
|
.proxy(classDef)
|
||||||
val newString =
|
.resolve()
|
||||||
if (reference == "com.google") {
|
.methods
|
||||||
BASE_MICROG_PACKAGE_NAME
|
.first { it.name == method.name }
|
||||||
} else if (
|
.implementation!!
|
||||||
// https://github.com/TeamVanced/VancedMicroG/pull/139/file
|
.replaceInstruction(
|
||||||
!reference.startsWith("com.google.android.gms.chimera.container") &&
|
i,
|
||||||
reference.startsWith("com.google.iid") ||
|
BuilderInstruction21c(
|
||||||
reference.startsWith("com.google.android.gms.chimera") ||
|
Opcode.CONST_STRING,
|
||||||
reference.startsWith("com.google.android.c2dm") ||
|
instruction.registerA,
|
||||||
//reference.startsWith("com.google.android.gms.phenotype") || TODO: implement when we replace references below
|
ImmutableStringReference(instructionString.replacePackageName())
|
||||||
reference.startsWith("com.google.android.gms.auth.accounts") ||
|
|
||||||
reference.startsWith("com.google.android.c2dm") ||
|
|
||||||
reference.startsWith("com.google.android.gsf") ||
|
|
||||||
reference.startsWith("com.google.android.c2dm") ||
|
|
||||||
reference.startsWith("content://com.google.settings")
|
|
||||||
) {
|
|
||||||
reference.replace("com.google", BASE_MICROG_PACKAGE_NAME)
|
|
||||||
} else if (
|
|
||||||
reference.startsWith("com.google.android.youtube.SuggestionsProvider") || // TODO: also in resources & manifest
|
|
||||||
reference.startsWith("com.google.android.youtube.fileprovider") // TODO: also in resources & manifest
|
|
||||||
) {
|
|
||||||
reference.replace("com.google.android.youtube", BASE_REVANCED_PACKAGE_NAME)
|
|
||||||
} else {
|
|
||||||
reference
|
|
||||||
}
|
|
||||||
patcherData.proxy(classDef)
|
|
||||||
.resolve().methods.first { it.name == method.name }.implementation!!.replaceInstruction(
|
|
||||||
i, BuilderInstruction21c(
|
|
||||||
Opcode.CONST_STRING, instruction.registerA, ImmutableStringReference(newString)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: phenotype reference -> microg reference
|
// TODO: phenotype reference -> microg reference
|
||||||
@ -500,9 +481,35 @@ class MicroGPatch : Patch(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// allow GC to clean unused/ replaced immutable class definitions
|
||||||
|
patcherData.classes.applyProxies()
|
||||||
|
|
||||||
|
// TODO: resource patches
|
||||||
return PatchResultSuccess()
|
return PatchResultSuccess()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun String.replacePackageName(): String {
|
||||||
|
return if (this == "com.google") BASE_MICROG_PACKAGE_NAME
|
||||||
|
else if (!this.startsWith("com.google.android.gms.chimera.container") && // https://github.com/TeamVanced/VancedMicroG/pull/139/file
|
||||||
|
this.startsWithAny(
|
||||||
|
"com.google.android.gms.auth.accounts",
|
||||||
|
"com.google.android.gms.chimera",
|
||||||
|
"com.google.android.c2dm",
|
||||||
|
"com.google.android.c2dm",
|
||||||
|
"com.google.android.gsf",
|
||||||
|
"com.google.android.c2dm",
|
||||||
|
"com.google.iid",
|
||||||
|
"content://com.google.settings",
|
||||||
|
// "com.google.android.gms.phenotype" TODO: implement when we replace references below
|
||||||
|
)
|
||||||
|
) this.replace("com.google", BASE_MICROG_PACKAGE_NAME)
|
||||||
|
else if (this.startsWithAny(
|
||||||
|
"com.google.android.youtube.SuggestionsProvider", "com.google.android.youtube.fileprovider"
|
||||||
|
)
|
||||||
|
) this.replace("com.google.android.youtube", BASE_REVANCED_PACKAGE_NAME)
|
||||||
|
else this
|
||||||
|
}
|
||||||
|
|
||||||
private fun disablePlayServiceChecks() {
|
private fun disablePlayServiceChecks() {
|
||||||
for (i in 0 until signatures.count() - 1) {
|
for (i in 0 until signatures.count() - 1) {
|
||||||
val result = signatures.elementAt(i).result!!
|
val result = signatures.elementAt(i).result!!
|
||||||
@ -523,18 +530,28 @@ class MicroGPatch : Patch(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val implementation = signatures.last().result!!.method.implementation!!
|
val implementation = signatures
|
||||||
|
.last()
|
||||||
|
.result!!
|
||||||
|
.method
|
||||||
|
.implementation!!
|
||||||
|
|
||||||
var register = 2
|
var register = 2
|
||||||
val index = implementation.instructions.indexOfFirst {
|
val index = implementation
|
||||||
return@indexOfFirst if (it.opcode == Opcode.CONST_STRING && ((it as Instruction21c).reference as StringReference).string == "com.google.android.youtube") {
|
.instructions
|
||||||
|
.indexOfFirst {
|
||||||
|
if (it.opcode != Opcode.CONST_STRING) return@indexOfFirst false
|
||||||
|
|
||||||
|
val instructionString = ((it as Instruction21c).reference as StringReference).string
|
||||||
|
if (instructionString != "com.google.android.youtube") return@indexOfFirst false
|
||||||
|
|
||||||
register = it.registerA
|
register = it.registerA
|
||||||
true
|
return@indexOfFirst true
|
||||||
} else false
|
}
|
||||||
|
|
||||||
}
|
implementation.replaceInstruction(
|
||||||
|
index,
|
||||||
signatures.last().result!!.method.implementation!!.replaceInstruction(
|
"const-string v$register, \"$BASE_REVANCED_PACKAGE_NAME\"".toInstruction()
|
||||||
index, "const-string v$register, \"$BASE_REVANCED_PACKAGE_NAME\"".toInstruction()
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user