fix: partial ad blockage in tiktok-ads patch (#420)

This commit is contained in:
d4rkk3y 2022-09-02 00:12:16 +07:00 committed by GitHub
parent 3c33a63cec
commit bc6d192059
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 17 deletions

View File

@ -0,0 +1,21 @@
package app.revanced.patches.tiktok.ad.fingerprints
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.fingerprint.method.annotation.MatchingMethod
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patches.tiktok.ad.annotations.TiktokAdsCompatibility
@Name("convert-help-v2-feeditemlist-fingerprint")
@MatchingMethod(
"Lbeancopy/ConvertHelp;",
"com${'$'}ss${'$'}ugc${'$'}aweme${'$'}proto${'$'}aweme_v2_feed_response${'$'}${'$'}com${'$'}ss${'$'}android${'$'}ugc${'$'}aweme${'$'}feed${'$'}model${'$'}FeedItemList",
)
@TiktokAdsCompatibility
@Version("0.0.1")
object ConvertHelpFeedItemListFingerprint : MethodFingerprint(
customFingerprint = { methodDef ->
methodDef.definingClass.endsWith("/ConvertHelp;") &&
methodDef.name.endsWith("${'$'}FeedItemList")
}
)

View File

@ -11,6 +11,7 @@ import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.patch.impl.BytecodePatch import app.revanced.patcher.patch.impl.BytecodePatch
import app.revanced.patches.tiktok.ad.annotations.TiktokAdsCompatibility import app.revanced.patches.tiktok.ad.annotations.TiktokAdsCompatibility
import app.revanced.patches.tiktok.ad.fingerprints.ConvertHelpFeedItemListFingerprint
import app.revanced.patches.tiktok.ad.fingerprints.FeedItemListCloneFingerprint import app.revanced.patches.tiktok.ad.fingerprints.FeedItemListCloneFingerprint
import org.jf.dexlib2.Opcode import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.ReferenceInstruction import org.jf.dexlib2.iface.instruction.ReferenceInstruction
@ -23,26 +24,34 @@ import org.jf.dexlib2.iface.reference.FieldReference
@TiktokAdsCompatibility @TiktokAdsCompatibility
@Version("0.0.1") @Version("0.0.1")
class TiktokAdsPatch : BytecodePatch( class TiktokAdsPatch : BytecodePatch(
listOf(FeedItemListCloneFingerprint) listOf(
FeedItemListCloneFingerprint,
ConvertHelpFeedItemListFingerprint
)
) { ) {
override fun execute(data: BytecodeData): PatchResult { override fun execute(data: BytecodeData): PatchResult {
val method = FeedItemListCloneFingerprint.result!!.mutableMethod listOf(
FeedItemListCloneFingerprint,
ConvertHelpFeedItemListFingerprint
).forEach { fingerprint ->
val method = fingerprint.result!!.mutableMethod
// iterate all instructions in the clone method // iterate all instructions in the clone method
for ((index, instruction) in method.implementation!!.instructions.withIndex()) { for ((index, instruction) in method.implementation!!.instructions.withIndex()) {
// conditions for the instruction we need // conditions for the instruction we need
if (instruction.opcode.ordinal != Opcode.IPUT_OBJECT.ordinal) continue if (instruction.opcode.ordinal != Opcode.IPUT_OBJECT.ordinal) continue
val clonePreloadAdsFieldInstruction = (instruction as? ReferenceInstruction) val preloadAdsFieldInstruction = (instruction as? ReferenceInstruction)
if ((clonePreloadAdsFieldInstruction?.reference as? FieldReference)?.name != "preloadAds") continue if ((preloadAdsFieldInstruction?.reference as? FieldReference)?.name != "preloadAds") continue
// set null instead of the field "preloadAds" // set null instead of the field "preloadAds"
val overrideRegister = (clonePreloadAdsFieldInstruction as TwoRegisterInstruction).registerA val overrideRegister = (preloadAdsFieldInstruction as TwoRegisterInstruction).registerA
method.addInstruction( method.addInstruction(
index, index,
"const/4 v$overrideRegister, 0x0" "const/4 v$overrideRegister, 0x0"
) )
return@forEach
}
return PatchResultError("Can not find required instruction.")
}
return PatchResultSuccess() return PatchResultSuccess()
} }
return PatchResultError("Could not find required instruction.")
}
} }