Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(Tumblr): Use a common filter patch #3018

Merged
merged 7 commits into from
Oct 1, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,25 @@ object TimelineFilterPatch : BytecodePatch(
internal lateinit var addObjectTypeFilter: (typeName: String) -> Unit private set

override fun execute(context: BytecodeContext) {

TimelineFilterIntegrationFingerprint.result?.let { integration ->
val filterInsertIndex = integration.scanResult.patternScanResult!!.startIndex

integration.mutableMethod.apply {
// This is the List.add call from the dummy object type filter
val instr = getInstruction<BuilderInstruction35c>(filterInsertIndex + 1)

if (instr.registerCount != 2) throw TimelineFilterIntegrationFingerprint.exception
val addInstruction = getInstruction<BuilderInstruction35c>(filterInsertIndex + 1)
if (addInstruction.registerCount != 2) throw TimelineFilterIntegrationFingerprint.exception

// From the dummy filter call, we can get the 2 registers we need to add more filters
val listRegister = instr.registerC
val stringRegister = instr.registerD
val filterListRegister = addInstruction.registerC
val stringRegister = addInstruction.registerD

// Remove "BLOCKED_OBJECT_DUMMY" object type filter
// Remove "BLOCKED_OBJECT_DUMMY"
removeInstructions(filterInsertIndex, 2)

addObjectTypeFilter = { typeName ->
// The java equivalent of this is
// blockedObjectTypes.add({typeName})
// blockedObjectTypes.add({typeName})
addInstructionsWithLabels(
filterInsertIndex, """
const-string v$stringRegister, "$typeName"
invoke-interface { v$listRegister, v$stringRegister }, Ljava/util/List;->add(Ljava/lang/Object;)Z
oSumAtrIX marked this conversation as resolved.
Show resolved Hide resolved
invoke-interface { v$filterListRegister, v$stringRegister }, Ljava/util/HashSet;->add(Ljava/lang/Object;)Z
"""
)
}
Expand All @@ -61,10 +56,11 @@ object TimelineFilterPatch : BytecodePatch(
mapOf(
TimelineConstructorFingerprint to 1,
PostsResponseConstructorFingerprint to 2
).forEach { (fingerprint, paramRegister) ->
).forEach { (fingerprint, timelineObjectsRegister) ->
fingerprint.result?.mutableMethod?.addInstructions(
0,
"invoke-static {p$paramRegister}, Lapp/revanced/tumblr/patches/TimelineFilterPatch;->" +
"invoke-static {p$timelineObjectsRegister}, " +
"Lapp/revanced/tumblr/patches/TimelineFilterPatch;->" +
"filterTimeline(Ljava/util/List;)V"
) ?: throw fingerprint.exception
}
Expand Down