From 5f81b40e7d5567fb5689d08ccc9caeaa267c3143 Mon Sep 17 00:00:00 2001 From: epireyn <48213068+epireyn@users.noreply.github.com> Date: Sat, 20 Jul 2024 06:00:19 +0200 Subject: [PATCH] feat: Add `Hide mock location` patch (#3417) Co-authored-by: oSumAtrIX --- api/revanced-patches.api | 8 +++ .../location/hide/HideMockLocationPatch.kt | 56 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/all/location/hide/HideMockLocationPatch.kt diff --git a/api/revanced-patches.api b/api/revanced-patches.api index a93bca3da3..a602a5b4c5 100644 --- a/api/revanced-patches.api +++ b/api/revanced-patches.api @@ -22,6 +22,14 @@ public final class app/revanced/patches/all/interaction/gestures/PredictiveBackG public fun execute (Lapp/revanced/patcher/data/ResourceContext;)V } +public final class app/revanced/patches/all/location/hide/HideMockLocationPatch : app/revanced/patches/all/misc/transformation/BaseTransformInstructionsPatch { + public static final field INSTANCE Lapp/revanced/patches/all/location/hide/HideMockLocationPatch; + public synthetic fun filterMap (Lcom/android/tools/smali/dexlib2/iface/ClassDef;Lcom/android/tools/smali/dexlib2/iface/Method;Lcom/android/tools/smali/dexlib2/iface/instruction/Instruction;I)Ljava/lang/Object; + public fun filterMap (Lcom/android/tools/smali/dexlib2/iface/ClassDef;Lcom/android/tools/smali/dexlib2/iface/Method;Lcom/android/tools/smali/dexlib2/iface/instruction/Instruction;I)Lkotlin/Pair; + public synthetic fun transform (Lapp/revanced/patcher/util/proxy/mutableTypes/MutableMethod;Ljava/lang/Object;)V + public fun transform (Lapp/revanced/patcher/util/proxy/mutableTypes/MutableMethod;Lkotlin/Pair;)V +} + public final class app/revanced/patches/all/misc/debugging/EnableAndroidDebuggingPatch : app/revanced/patcher/patch/ResourcePatch { public static final field INSTANCE Lapp/revanced/patches/all/misc/debugging/EnableAndroidDebuggingPatch; public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V diff --git a/src/main/kotlin/app/revanced/patches/all/location/hide/HideMockLocationPatch.kt b/src/main/kotlin/app/revanced/patches/all/location/hide/HideMockLocationPatch.kt new file mode 100644 index 0000000000..235a3f7bf8 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/all/location/hide/HideMockLocationPatch.kt @@ -0,0 +1,56 @@ +@file:Suppress("unused") + +package app.revanced.patches.all.location.hide + +import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction +import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod +import app.revanced.patches.all.misc.transformation.BaseTransformInstructionsPatch +import app.revanced.patches.all.misc.transformation.IMethodCall +import app.revanced.patches.all.misc.transformation.fromMethodReference +import app.revanced.util.getReference +import com.android.tools.smali.dexlib2.iface.ClassDef +import com.android.tools.smali.dexlib2.iface.Method +import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction +import com.android.tools.smali.dexlib2.iface.instruction.Instruction +import com.android.tools.smali.dexlib2.iface.reference.MethodReference + +@Patch( + name = "Hide mock location", + description = "Prevents the app from knowing the device location is being mocked by a third party app.", + use = false +) +object HideMockLocationPatch : BaseTransformInstructionsPatch>() { + override fun filterMap( + classDef: ClassDef, + method: Method, + instruction: Instruction, + instructionIndex: Int + ): Pair? { + val reference = instruction.getReference() ?: return null + if (fromMethodReference(reference) == null) return null + + return instruction to instructionIndex + } + + override fun transform(mutableMethod: MutableMethod, entry: Pair) { + val (instruction, index) = entry + instruction as FiveRegisterInstruction + + // Replace return value with a constant `false` boolean. + mutableMethod.replaceInstruction( + index + 1, + "const/4 v${instruction.registerC}, 0x0" + ) + } +} + +private enum class MethodCall( + override val definedClassName: String, + override val methodName: String, + override val methodParams: Array, + override val returnType: String +) : IMethodCall { + IsMock("Landroid/location/Location;", "isMock", emptyArray(), "Z"), + IsFromMockProvider("Landroid/location/Location;", "isFromMockProvider", emptyArray(), "Z") +}