mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-06-12 21:27:43 +02:00
refactor: fix patch structure
This commit is contained in:
@ -25,6 +25,8 @@ import com.android.tools.smali.dexlib2.iface.reference.MethodReference
|
||||
import com.android.tools.smali.dexlib2.iface.reference.Reference
|
||||
import com.android.tools.smali.dexlib2.util.MethodUtil
|
||||
|
||||
fun MethodFingerprint.resultOrThrow() = result ?: throw exception
|
||||
|
||||
/**
|
||||
* The [PatchException] of failing to resolve a [MethodFingerprint].
|
||||
*
|
||||
@ -133,7 +135,7 @@ fun MethodFingerprint.literalInstructionViewHook(
|
||||
literal: Long,
|
||||
descriptor: String
|
||||
) {
|
||||
result?.mutableMethod?.apply {
|
||||
resultOrThrow().mutableMethod.apply {
|
||||
val literalIndex = getWideLiteralInstructionIndex(literal)
|
||||
val targetIndex = getTargetIndex(literalIndex, Opcode.MOVE_RESULT_OBJECT)
|
||||
val targetRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
|
||||
@ -142,7 +144,7 @@ fun MethodFingerprint.literalInstructionViewHook(
|
||||
targetIndex + 1,
|
||||
"invoke-static {v$targetRegister}, $descriptor"
|
||||
)
|
||||
} ?: throw exception
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -380,7 +382,7 @@ fun BytecodeContext.updatePatchStatus(
|
||||
fun List<MethodFingerprint>.returnEarly(bool: Boolean = false) {
|
||||
val const = if (bool) "0x1" else "0x0"
|
||||
this.forEach { fingerprint ->
|
||||
fingerprint.result?.let { result ->
|
||||
fingerprint.resultOrThrow().let { result ->
|
||||
val stringInstructions = when (result.method.returnType.first()) {
|
||||
'L' -> """
|
||||
const/4 v0, $const
|
||||
@ -395,6 +397,6 @@ fun List<MethodFingerprint>.returnEarly(bool: Boolean = false) {
|
||||
}
|
||||
|
||||
result.mutableMethod.addInstructions(0, stringInstructions)
|
||||
} ?: throw fingerprint.exception
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import app.revanced.patcher.data.ResourceContext
|
||||
import app.revanced.patcher.util.DomFileEditor
|
||||
import org.w3c.dom.Element
|
||||
import org.w3c.dom.Node
|
||||
import java.io.InputStream
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.StandardCopyOption
|
||||
|
||||
@ -49,12 +50,13 @@ fun String.startsWithAny(vararg prefixes: String): Boolean {
|
||||
|
||||
/**
|
||||
* Copy resources from the current class loader to the resource directory.
|
||||
*
|
||||
* @param sourceResourceDirectory The source resource directory name.
|
||||
* @param resources The resources to copy.
|
||||
*/
|
||||
fun ResourceContext.copyResources(
|
||||
sourceResourceDirectory: String,
|
||||
vararg resources: ResourceGroup
|
||||
vararg resources: ResourceGroup,
|
||||
) {
|
||||
val targetResourceDirectory = this["res"]
|
||||
|
||||
@ -62,14 +64,19 @@ fun ResourceContext.copyResources(
|
||||
resourceGroup.resources.forEach { resource ->
|
||||
val resourceFile = "${resourceGroup.resourceDirectoryName}/$resource"
|
||||
Files.copy(
|
||||
classLoader.getResourceAsStream("$sourceResourceDirectory/$resourceFile")!!,
|
||||
inputStreamFromBundledResource(sourceResourceDirectory, resourceFile)!!,
|
||||
targetResourceDirectory.resolve(resourceFile).toPath(),
|
||||
StandardCopyOption.REPLACE_EXISTING
|
||||
StandardCopyOption.REPLACE_EXISTING,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal fun inputStreamFromBundledResource(
|
||||
sourceResourceDirectory: String,
|
||||
resourceFile: String,
|
||||
): InputStream? = classLoader.getResourceAsStream("$sourceResourceDirectory/$resourceFile")
|
||||
|
||||
/**
|
||||
* Resource names mapped to their corresponding resource data.
|
||||
* @param resourceDirectoryName The name of the directory of the resource.
|
||||
@ -89,7 +96,7 @@ fun ResourceContext.copyXmlNode(
|
||||
elementTag: String
|
||||
) {
|
||||
val stringsResourceInputStream =
|
||||
classLoader.getResourceAsStream("$resourceDirectory/$targetResource")!!
|
||||
inputStreamFromBundledResource(resourceDirectory, targetResource)!!
|
||||
|
||||
// Copy nodes from the resources node to the real resource node
|
||||
elementTag.copyXmlNode(
|
||||
|
Reference in New Issue
Block a user