refactor: move the patch to the correct path

This commit is contained in:
inotia00
2023-06-18 23:09:08 +09:00
parent 03148b5c81
commit 5c99e9a16a
410 changed files with 3807 additions and 3505 deletions

View File

@ -14,6 +14,10 @@ fun Method.isWideLiteralExists(value: Long): Boolean {
return getWideLiteralIndex(value) != -1
}
fun Method.isWide32LiteralExists(value: Long): Boolean {
return getWide32LiteralIndex(value) != -1
}
fun Method.getNarrowLiteralIndex(value: Int): Int {
return implementation?.let {
it.instructions.indexOfFirst { instruction ->
@ -41,3 +45,12 @@ fun Method.getWideLiteralIndex(value: Long): Int {
} ?: -1
}
fun Method.getWide32LiteralIndex(value: Long): Int {
return implementation?.let {
it.instructions.indexOfFirst { instruction ->
instruction.opcode == Opcode.CONST_WIDE_32
&& (instruction as WideLiteralInstruction).wideLiteral == value
}
} ?: -1
}

View File

@ -1,6 +1,7 @@
package app.revanced.util.enum
internal enum class ResourceType(val value: String) {
ATTR("attr"),
BOOL("bool"),
COLOR("color"),
DIMEN("dimen"),

View File

@ -1,5 +1,6 @@
package app.revanced.util.microg
import app.revanced.extensions.toErrorResult
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
@ -53,23 +54,26 @@ internal object MicroGBytecodeHelper {
* Patch the prime method to accept the new package name.
*/
fun transformPrimeMethodPackageName() {
val primeMethod = primeMethodFingerprint.result!!.mutableMethod
val implementation = primeMethod.implementation!!
primeMethodFingerprint.result?.let {
var targetRegister = 2
var register = 2
val index = implementation.instructions.indexOfFirst {
if (it.opcode != Opcode.CONST_STRING) return@indexOfFirst false
it.mutableMethod.apply {
val targetIndex = implementation!!.instructions.indexOfFirst { instructions ->
if (instructions.opcode != Opcode.CONST_STRING) return@indexOfFirst false
val instructionString = ((it as Instruction21c).reference as StringReference).string
if (instructionString != fromPackageName) return@indexOfFirst false
val instructionString = ((instructions as Instruction21c).reference as StringReference).string
if (instructionString != fromPackageName) return@indexOfFirst false
register = it.registerA
return@indexOfFirst true
}
targetRegister = instructions.registerA
return@indexOfFirst true
}
primeMethod.replaceInstruction(
index, "const-string v$register, \"$toPackageName\""
)
replaceInstruction(
targetIndex,
"const-string v$targetRegister, \"$toPackageName\""
)
}
} ?: throw primeMethodFingerprint.toErrorResult()
}
}
@ -206,24 +210,27 @@ internal object MicroGBytecodeHelper {
*/
private fun List<MethodFingerprint>.returnEarly() {
this.forEach { fingerprint ->
val result = fingerprint.result!!
val stringInstructions = when (result.method.returnType.first()) {
'L' -> """
fingerprint.result?.let {
it.mutableMethod.apply {
val stringInstructions = when (it.method.returnType.first()) {
'L' -> """
const/4 v0, 0x0
return-object v0
"""
'V' -> "return-void"
'I' -> """
'V' -> "return-void"
'I' -> """
const/4 v0, 0x0
return v0
"""
else -> throw Exception("This case should never happen.")
}
result.mutableMethod.addInstructions(
0, stringInstructions
)
else -> throw Exception("This case should never happen.")
}
addInstructions(
0, stringInstructions
)
}
} ?: throw fingerprint.toErrorResult()
}
}
}

View File

@ -1,6 +1,7 @@
package app.revanced.util.resources
import app.revanced.patcher.data.ResourceContext
import org.w3c.dom.Element
import java.io.File
import java.nio.file.Files
import java.nio.file.Paths
@ -98,9 +99,7 @@ internal object IconHelper {
iconName
)
this["res/values-v31/styles.xml"].writeText(
this["res/values-v31/styles.xml"].readText().replace("<item name=\"android:windowSplashScreenAnimatedIcon\">@drawable/avd_anim</item>", "")
)
this.disableSplashAnimation()
}
internal fun ResourceContext.customIconMusic(iconName: String) {
@ -219,4 +218,15 @@ internal object IconHelper {
)
}
}
private fun ResourceContext.disableSplashAnimation() {
val targetPath = "res/values-v31/styles.xml"
xmlEditor[targetPath].use { editor ->
val tags = editor.file.getElementsByTagName("item")
List(tags.length) { tags.item(it) as Element }
.filter { it.getAttribute("name").contains("android:windowSplashScreenAnimatedIcon") }
.forEach { it.parentNode.removeChild(it) }
}
}
}