Skip to content

Commit

Permalink
fix: hide-get-premium patch is broken in latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
inotia00 committed Feb 5, 2023
1 parent 17f21ba commit 835a14a
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ object HideGetPremiumFingerprint : MethodFingerprint(
access = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf(),
opcodes = listOf(
Opcode.IF_NEZ,
Opcode.CONST_16,
Opcode.GOTO,
Opcode.NOP,
Opcode.INVOKE_VIRTUAL
)
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")
)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,85 @@ import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
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.Companion.resolve
import app.revanced.patcher.extensions.addInstruction
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
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.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
@DependsOn([MusicIntegrationsPatch::class])
@Name("hide-get-premium")
@Description("Removes all \"Get Premium\" evidences from the avatar menu.")
@YouTubeMusicCompatibility
@Version("0.0.1")
class HideGetPremiumPatch : BytecodePatch(
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 {
val parentResult = HideGetPremiumParentFingerprint.result!!
HideGetPremiumFingerprint.resolve(context, parentResult.classDef)

val startIndex = parentResult.scanResult.patternScanResult!!.startIndex

val parentMethod = parentResult.mutableMethod
parentMethod.replaceInstruction(
startIndex, """
const/4 v1, 0x0
"""
)

val result = HideGetPremiumFingerprint.result!!
val method = result.mutableMethod
method.addInstructions(
startIndex, """
const/16 v0, 0x8
"""
)

HideGetPremiumFingerprint.result?.let {
with (it.mutableMethod) {
val insertIndex = it.scanResult.patternScanResult!!.startIndex
val register = (implementation!!.instructions[insertIndex] as TwoRegisterInstruction).registerA

addInstruction(
insertIndex + 1,
"const/4 v$register, 0x0"
)
}
} ?: return HideGetPremiumFingerprint.toErrorResult()

context.classes.forEach { classDef ->
classDef.methods.forEach { method ->
with(method.implementation) {
this?.instructions?.forEachIndexed { index, instruction ->
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()
}
Expand Down

0 comments on commit 835a14a

Please sign in to comment.