Skip to content

Commit

Permalink
refactor/improve reliability
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Jul 13, 2024
1 parent affdb51 commit 17802c1
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 89 deletions.
8 changes: 4 additions & 4 deletions api/revanced-patches.api
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,14 @@ public final class app/revanced/patches/cieid/restrictions/root/BypassRootChecks
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
}

public final class app/revanced/patches/duolingo/ad/RemoveDuolingoAdsPatch : app/revanced/patcher/patch/BytecodePatch {
public static final field INSTANCE Lapp/revanced/patches/duolingo/ad/RemoveDuolingoAdsPatch;
public final class app/revanced/patches/duolingo/ad/DisableAdsPatch : app/revanced/patcher/patch/BytecodePatch {
public static final field INSTANCE Lapp/revanced/patches/duolingo/ad/DisableAdsPatch;
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
}

public final class app/revanced/patches/duolingo/debug/MakeDebugMenuAvailable : app/revanced/patcher/patch/BytecodePatch {
public static final field INSTANCE Lapp/revanced/patches/duolingo/debug/MakeDebugMenuAvailable;
public final class app/revanced/patches/duolingo/debug/EnableDebugMenuPatch : app/revanced/patcher/patch/BytecodePatch {
public static final field INSTANCE Lapp/revanced/patches/duolingo/debug/EnableDebugMenuPatch;
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package app.revanced.patches.duolingo.ad

import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstructions
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.duolingo.ad.fingerprints.InitializeMonetizationDebugSettingsFingerprint
import app.revanced.util.exception
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction22c

@Patch(
name = "Disable ads",
compatiblePackages = [CompatiblePackage("com.duolingo")]
)
@Suppress("unused")
object DisableAdsPatch : BytecodePatch(
setOf(InitializeMonetizationDebugSettingsFingerprint)
) {
override fun execute(context: BytecodeContext) {
// Couple approaches to remove ads exist:
//
// MonetizationDebugSettings has a boolean value for "disableAds".
// OnboardingState has a getter to check if the user has any "adFreeSessions".
// SharedPreferences has a debug boolean value with key "disable_ads", which maps to "DebugCategory.DISABLE_ADS".
//
// MonetizationDebugSettings seems to be the most general setting to work fine.
InitializeMonetizationDebugSettingsFingerprint.resultOrThrow().mutableMethod.apply {
val setDisableAdsIndex = getInstructions().firstOrNull {
it.opcode == Opcode.IPUT_BOOLEAN
} as? BuilderInstruction22c ?: throw InitializeMonetizationDebugSettingsFingerprint.exception

addInstructions(
setDisableAdsIndex.location.index,
"const/4 v${setDisableAdsIndex.registerA}, 0x1"
)
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags

internal object MonetizationDebugSettingsFingerprint : MethodFingerprint(
internal object InitializeMonetizationDebugSettingsFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
parameters = listOf(
Expand All @@ -14,4 +14,4 @@ internal object MonetizationDebugSettingsFingerprint : MethodFingerprint(
"Z", // alwaysShowSuperAds
"Lcom/duolingo/debug/FamilyQuestOverride;",
)
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package app.revanced.patches.duolingo.debug

import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstructions
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.duolingo.debug.fingerprints.InitializeBuildConfigProviderFingerprint
import app.revanced.util.exception
import app.revanced.util.resultOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction22c

@Patch(
name = "Enable debug menu",
compatiblePackages = [CompatiblePackage("com.duolingo")],
use = false
)
@Suppress("unused")
object EnableDebugMenuPatch : BytecodePatch(
setOf(InitializeBuildConfigProviderFingerprint)
) {
override fun execute(context: BytecodeContext) {
InitializeBuildConfigProviderFingerprint.resultOrThrow().mutableMethod.apply {
val setIsDebugBuildIndex = getInstructions().firstOrNull {
it.opcode == Opcode.IPUT_BOOLEAN
} as? BuilderInstruction22c ?: throw InitializeBuildConfigProviderFingerprint.exception

addInstructions(
setIsDebugBuildIndex.location.index,
"const/4 v${setIsDebugBuildIndex.registerA}, 0x1"
)
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags

// the `BuildConfigProvider` class has two bools:
// - `isChina`: (usually) compares "play" with "china"...except for builds in China
// - `isDebug`: compares "release" with "debug" <-- we want to force this to `true`
internal object BuildConfigProviderFingerprint : MethodFingerprint(
/**
* The `BuildConfigProvider` class has two booleans:
*
* - `isChina`: (usually) compares "play" with "china"...except for builds in China
* - `isDebug`: compares "release" with "debug" <-- we want to force this to `true`
*/
internal object InitializeBuildConfigProviderFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR,
strings = listOf(
"debug",
"release",
"china",
),
)
)

0 comments on commit 17802c1

Please sign in to comment.