chore: migrate to new changes from the patcher

This commit is contained in:
oSumAtrIX
2022-10-05 04:03:10 +02:00
parent 06e1b44ba2
commit 2471f0363d
212 changed files with 513 additions and 1021 deletions

View File

@ -1,6 +1,6 @@
package app.revanced.util.microg
import app.revanced.patcher.data.impl.BytecodeData
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.replaceInstruction
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
@ -78,13 +78,13 @@ internal object MicroGBytecodeHelper {
* Note: this only handles string constants to gms (intent actions, authorities, ...).
* If the app employs additional checks to validate the installed gms package, you'll have to handle those in the app- specific patch
*
* @param data Bytecode data instance.
* @param context The context.
* @param additionalStringTransforms Additional transformations applied to all const-string references.
* @param primeMethodTransformationData Data to patch the prime method.
* @param earlyReturns List of [MethodFingerprint] to return the resolved methods early.
*/
fun patchBytecode(
data: BytecodeData,
context: BytecodeContext,
additionalStringTransforms: Array<(str: String) -> String?>,
primeMethodTransformationData: PrimeMethodTransformationData,
earlyReturns: List<MethodFingerprint>
@ -99,7 +99,7 @@ internal object MicroGBytecodeHelper {
)
// transform all strings using all provided transforms, first match wins
data.transformStringReferences transform@{
context.transformStringReferences transform@{
for (transformFn in allTransforms) {
val s = transformFn(it)
if (s != null) return@transform s
@ -160,7 +160,7 @@ internal object MicroGBytecodeHelper {
*
* @param transformFn string transformation function. if null, string is not changed.
*/
private fun BytecodeData.transformStringReferences(transformFn: (str: String) -> String?) {
private fun BytecodeContext.transformStringReferences(transformFn: (str: String) -> String?) {
classes.forEach { classDef ->
var mutableClass: MutableClass? = null
@ -179,7 +179,7 @@ internal object MicroGBytecodeHelper {
val transformedStr = transformFn(str)
if (transformedStr != null) {
// make class and method mutable, if not already
mutableClass = mutableClass ?: proxy(classDef).resolve()
mutableClass = mutableClass ?: proxy(classDef).mutableClass
mutableMethod = mutableMethod ?: mutableClass!!.methods.first {
it.name == methodDef.name && it.parameterTypes.containsAll(methodDef.parameterTypes)
}

View File

@ -1,6 +1,6 @@
package app.revanced.util.microg
import app.revanced.patcher.data.impl.ResourceData
import app.revanced.patcher.data.ResourceContext
import app.revanced.util.microg.Constants.META_GMS_PACKAGE_NAME
import app.revanced.util.microg.Constants.META_SPOOFED_PACKAGE_NAME
import app.revanced.util.microg.Constants.META_SPOOFED_PACKAGE_SIGNATURE
@ -17,16 +17,16 @@ internal object MicroGManifestHelper {
* Add manifest entries needed for package and signature spoofing when using MicroG.
* Note: this only adds metadata entries for signature spoofing, other changes may still be required to make a microG patch work.
*
* @param data Resource data.
* @param context Resource context.
* @param spoofedPackage The package to spoof.
* @param spoofedSignature The signature to spoof.
*/
fun addSpoofingMetadata(
data: ResourceData,
context: ResourceContext,
spoofedPackage: String,
spoofedSignature: String
) {
data.xmlEditor["AndroidManifest.xml"].use {
context.xmlEditor["AndroidManifest.xml"].use {
val applicationNode = it
.file
.getElementsByTagName("application")

View File

@ -1,6 +1,6 @@
package app.revanced.util.microg
import app.revanced.patcher.data.impl.ResourceData
import app.revanced.patcher.data.ResourceContext
/**
* Helper class for applying resource patches needed for the microg-support patches.
@ -9,19 +9,19 @@ internal object MicroGResourceHelper {
/**
* Patch the manifest to work with MicroG.
*
* @param data Bytecode data instance.
* @param context Bytecode context.
* @param fromPackageName Original package name.
* @param toPackageName The package name to accept.
* @param toName The new name of the app.
*/
fun patchManifest(
data: ResourceData,
context: ResourceContext,
fromPackageName: String,
toPackageName: String,
toName: String
) {
val manifest = data["AndroidManifest.xml"].readText()
data["AndroidManifest.xml"].writeText(
val manifest = context["AndroidManifest.xml"].readText()
context["AndroidManifest.xml"].writeText(
manifest.replace(
"package=\"$fromPackageName",
"package=\"$toPackageName"

View File

@ -1,7 +1,7 @@
package app.revanced.util.resources
import app.revanced.patcher.data.impl.DomFileEditor
import app.revanced.patcher.data.impl.ResourceData
import app.revanced.patcher.data.DomFileEditor
import app.revanced.patcher.data.ResourceContext
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
import app.revanced.patches.youtube.misc.settings.framework.components.impl.StringResource
import org.w3c.dom.Node
@ -18,7 +18,7 @@ internal object ResourceUtils {
* Merge strings. This handles [StringResource]s automatically.
* @param host The hosting xml resource. Needs to be a valid strings.xml resource.
*/
internal fun ResourceData.mergeStrings(host: String) {
internal fun ResourceContext.mergeStrings(host: String) {
this.iterateXmlNodeChildren(host, "resources") {
// TODO: figure out why this is needed
if (!it.hasAttributes()) return@iterateXmlNodeChildren
@ -39,7 +39,7 @@ internal object ResourceUtils {
* @param sourceResourceDirectory The source resource directory name.
* @param resources The resources to copy.
*/
internal fun ResourceData.copyResources(sourceResourceDirectory: String, vararg resources: ResourceGroup) {
internal fun ResourceContext.copyResources(sourceResourceDirectory: String, vararg resources: ResourceGroup) {
val classLoader = ResourceUtils.javaClass.classLoader
val targetResourceDirectory = this["res"]
@ -67,7 +67,11 @@ internal object ResourceUtils {
* @param targetTag The target xml node.
* @param callback The callback to call when iterating over the nodes.
*/
internal fun ResourceData.iterateXmlNodeChildren(resource: String, targetTag: String, callback: (node: Node) -> Unit) =
internal fun ResourceContext.iterateXmlNodeChildren(
resource: String,
targetTag: String,
callback: (node: Node) -> Unit
) =
xmlEditor[ResourceUtils.javaClass.classLoader.getResourceAsStream(resource)!!].use {
val stringsNode = it.file.getElementsByTagName(targetTag).item(0).childNodes
for (i in 1 until stringsNode.length - 1) callback(stringsNode.item(i))