fix: hide-get-premium patch is broken in latest version

This commit is contained in:
inotia00 2023-02-05 12:37:44 +09:00
parent 17f21ba9bf
commit 835a14a2d5
3 changed files with 68 additions and 49 deletions

View File

@ -10,10 +10,13 @@ object HideGetPremiumFingerprint : MethodFingerprint(
access = AccessFlags.PUBLIC or AccessFlags.FINAL, access = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf(), parameters = listOf(),
opcodes = listOf( opcodes = listOf(
Opcode.IF_NEZ, Opcode.IGET_BOOLEAN,
Opcode.CONST_16, Opcode.CONST_4,
Opcode.GOTO, Opcode.IF_EQZ,
Opcode.NOP, Opcode.IGET_OBJECT,
Opcode.INVOKE_VIRTUAL Opcode.INVOKE_VIRTUAL,
) Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_STATIC
),
listOf("FEmusic_history")
) )

View File

@ -1,22 +0,0 @@
package app.revanced.patches.music.layout.premium.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode
object HideGetPremiumParentFingerprint : MethodFingerprint(
returnType = "V",
access = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf(),
opcodes = listOf(
Opcode.IGET_BOOLEAN,
Opcode.CONST_4,
Opcode.IF_EQZ,
Opcode.IGET_OBJECT,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_STATIC
),
listOf("FEmusic_history"),
)

View File

@ -4,47 +4,85 @@ import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.extensions.addInstruction
import app.revanced.patcher.extensions.replaceInstruction import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve
import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patches.music.layout.premium.fingerprints.HideGetPremiumFingerprint import app.revanced.patches.music.layout.premium.fingerprints.HideGetPremiumFingerprint
import app.revanced.patches.music.layout.premium.fingerprints.HideGetPremiumParentFingerprint import app.revanced.patches.music.misc.integrations.patch.MusicIntegrationsPatch
import app.revanced.shared.annotation.YouTubeMusicCompatibility import app.revanced.shared.annotation.YouTubeMusicCompatibility
import app.revanced.shared.extensions.findMutableMethodOf
import app.revanced.shared.extensions.toErrorResult
import app.revanced.shared.patches.mapping.ResourceMappingPatch
import app.revanced.shared.util.integrations.Constants.INTEGRATIONS_PATH
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.formats.Instruction22c
import org.jf.dexlib2.iface.instruction.formats.Instruction31i
import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction
@Patch @Patch
@DependsOn([MusicIntegrationsPatch::class])
@Name("hide-get-premium") @Name("hide-get-premium")
@Description("Removes all \"Get Premium\" evidences from the avatar menu.") @Description("Removes all \"Get Premium\" evidences from the avatar menu.")
@YouTubeMusicCompatibility @YouTubeMusicCompatibility
@Version("0.0.1") @Version("0.0.1")
class HideGetPremiumPatch : BytecodePatch( class HideGetPremiumPatch : BytecodePatch(
listOf( listOf(
HideGetPremiumParentFingerprint HideGetPremiumFingerprint
) )
) { ) {
// list of resource names to get the id of
private val resourceIds = arrayOf(
"unlimited_panel"
).map { name ->
ResourceMappingPatch.resourceMappings.single { it.name == name }.id
}
override fun execute(context: BytecodeContext): PatchResult { override fun execute(context: BytecodeContext): PatchResult {
val parentResult = HideGetPremiumParentFingerprint.result!!
HideGetPremiumFingerprint.resolve(context, parentResult.classDef)
val startIndex = parentResult.scanResult.patternScanResult!!.startIndex HideGetPremiumFingerprint.result?.let {
with (it.mutableMethod) {
val insertIndex = it.scanResult.patternScanResult!!.startIndex
val register = (implementation!!.instructions[insertIndex] as TwoRegisterInstruction).registerA
val parentMethod = parentResult.mutableMethod addInstruction(
parentMethod.replaceInstruction( insertIndex + 1,
startIndex, """ "const/4 v$register, 0x0"
const/4 v1, 0x0 )
""" }
) } ?: return HideGetPremiumFingerprint.toErrorResult()
val result = HideGetPremiumFingerprint.result!! context.classes.forEach { classDef ->
val method = result.mutableMethod classDef.methods.forEach { method ->
method.addInstructions( with(method.implementation) {
startIndex, """ this?.instructions?.forEachIndexed { index, instruction ->
const/16 v0, 0x8 when (instruction.opcode) {
""" Opcode.CONST -> {
) when ((instruction as Instruction31i).wideLiteral) {
resourceIds[0] -> {
val insertIndex = index + 3
val iPutInstruction = instructions.elementAt(insertIndex)
if (iPutInstruction.opcode != Opcode.IPUT_OBJECT) return@forEachIndexed
val mutableMethod = context.proxy(classDef).mutableClass.findMutableMethodOf(method)
val viewRegister = (iPutInstruction as Instruction22c).registerA
mutableMethod.addInstruction(
insertIndex,
"invoke-static {v$viewRegister}, $INTEGRATIONS_PATH/adremover/AdRemoverAPI;->HideViewWithLayout1dp(Landroid/view/View;)V"
)
}
}
}
else -> return@forEachIndexed
}
}
}
}
}
return PatchResultSuccess() return PatchResultSuccess()
} }