slightly better patch method

This commit is contained in:
inotia00
2023-01-08 01:10:42 +09:00
parent a1a74e7c51
commit 500055e046
12 changed files with 82 additions and 31 deletions

View File

@ -5,11 +5,11 @@ import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.shared.annotation.YouTubeCompatibility
import app.revanced.shared.extensions.findMutableMethodOf
import app.revanced.shared.extensions.injectHideCall
import app.revanced.shared.extensions.toResult
import app.revanced.shared.patches.mapping.ResourceMappingPatch
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.formats.Instruction22c
@ -27,6 +27,7 @@ class CrowdfundingBoxBytecodePatch : BytecodePatch() {
).map { name ->
ResourceMappingPatch.resourceMappings.single { it.name == name }.id
}
private var patchSuccessArray = Array(resourceIds.size) {false}
override fun execute(context: BytecodeContext): PatchResult {
context.classes.forEach { classDef ->
@ -45,6 +46,7 @@ class CrowdfundingBoxBytecodePatch : BytecodePatch() {
val viewRegister = (iPutInstruction as Instruction22c).registerA
mutableMethod.implementation!!.injectHideCall(insertIndex, viewRegister, "layout/GeneralLayoutPatch", "hideCrowdfundingBox")
patchSuccessArray[0] = true;
}
}
}
@ -54,6 +56,6 @@ class CrowdfundingBoxBytecodePatch : BytecodePatch() {
}
}
}
return PatchResultSuccess()
return toResult(patchSuccessArray.indexOf(false))
}
}

View File

@ -6,10 +6,10 @@ import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.shared.annotation.YouTubeCompatibility
import app.revanced.shared.extensions.findMutableMethodOf
import app.revanced.shared.extensions.toResult
import app.revanced.shared.patches.mapping.ResourceMappingPatch
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.formats.Instruction31i
@ -26,6 +26,7 @@ class HeaderSwitchBytecodePatch : BytecodePatch() {
).map { name ->
ResourceMappingPatch.resourceMappings.single { it.name == name }.id
}
private var patchSuccessArray = Array(resourceIds.size) {false}
override fun execute(context: BytecodeContext): PatchResult {
context.classes.forEach { classDef ->
@ -48,6 +49,8 @@ class HeaderSwitchBytecodePatch : BytecodePatch() {
move-result v$viewRegister
"""
)
patchSuccessArray[0] = true;
}
}
}
@ -57,6 +60,6 @@ class HeaderSwitchBytecodePatch : BytecodePatch() {
}
}
}
return PatchResultSuccess()
return toResult(patchSuccessArray.indexOf(false))
}
}

View File

@ -6,6 +6,7 @@ import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultError
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.shared.extensions.findMutableMethodOf
import app.revanced.shared.extensions.injectHideCall
@ -31,6 +32,7 @@ class ShortsComponentBytecodePatch : BytecodePatch() {
).map { name ->
ResourceMappingPatch.resourceMappings.single { it.name == name }.id
}
private var patchSuccessArray = Array(resourceIds.size) {false}
override fun execute(context: BytecodeContext): PatchResult {
context.classes.forEach { classDef ->
@ -49,6 +51,8 @@ class ShortsComponentBytecodePatch : BytecodePatch() {
val viewRegister = (instructions.elementAt(index + 3) as OneRegisterInstruction).registerA
mutableMethod.implementation!!.injectHideCall(index + 4, viewRegister, "layout/GeneralLayoutPatch", "hideShortsPlayerCommentsButton")
patchSuccessArray[0] = true;
}
resourceIds[1] -> { // shorts player remix
@ -60,6 +64,8 @@ class ShortsComponentBytecodePatch : BytecodePatch() {
val viewRegister = (invokeInstruction as Instruction21c).registerA
mutableMethod.implementation!!.injectHideCall(index - 1, viewRegister, "layout/GeneralLayoutPatch", "hideShortsPlayerRemixButton")
patchSuccessArray[1] = true;
}
resourceIds[2] -> { // shorts player subscriptions banner
@ -71,6 +77,8 @@ class ShortsComponentBytecodePatch : BytecodePatch() {
val viewRegister = (invokeInstruction as Instruction21c).registerA
mutableMethod.implementation!!.injectHideCall(insertIndex, viewRegister, "layout/GeneralLayoutPatch", "hideShortsPlayerSubscriptionsButton")
patchSuccessArray[2] = true;
}
}
}
@ -80,9 +88,11 @@ class ShortsComponentBytecodePatch : BytecodePatch() {
}
}
}
BytecodeHelper.patchStatus(context, "ShortsComponent")
return PatchResultSuccess()
val errorIndex = patchSuccessArray.indexOf(false)
return if (errorIndex == -1) {
BytecodeHelper.patchStatus(context, "ShortsComponent")
PatchResultSuccess()
} else
PatchResultError("Instruction not found: $errorIndex")
}
}

View File

@ -5,11 +5,11 @@ import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.shared.annotation.YouTubeCompatibility
import app.revanced.shared.extensions.findMutableMethodOf
import app.revanced.shared.extensions.injectHideCall
import app.revanced.shared.extensions.toResult
import app.revanced.shared.patches.mapping.ResourceMappingPatch
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.formats.Instruction22c
@ -28,6 +28,7 @@ class HideStoriesBytecodePatch : BytecodePatch() {
).map { name ->
ResourceMappingPatch.resourceMappings.single { it.name == name }.id
}
private var patchSuccessArray = Array(resourceIds.size) {false}
override fun execute(context: BytecodeContext): PatchResult {
context.classes.forEach { classDef ->
@ -46,6 +47,9 @@ class HideStoriesBytecodePatch : BytecodePatch() {
val viewRegister = (iPutInstruction as Instruction22c).registerA
mutableMethod.implementation!!.injectHideCall(insertIndex, viewRegister, "layout/GeneralLayoutPatch", "hideStoriesShelf")
patchSuccessArray[0] = true;
patchSuccessArray[1] = true;
}
}
}
@ -55,6 +59,6 @@ class HideStoriesBytecodePatch : BytecodePatch() {
}
}
}
return PatchResultSuccess()
return toResult(patchSuccessArray.indexOf(false))
}
}