Skip to content

Commit 250cc7c

Browse files
epireynoSumAtrIX
andauthored
feat: Add Hide mock location patch (#3417)
Co-authored-by: oSumAtrIX <[email protected]>
1 parent 1af65de commit 250cc7c

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

api/revanced-patches.api

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ public final class app/revanced/patches/all/interaction/gestures/PredictiveBackG
2222
public fun execute (Lapp/revanced/patcher/data/ResourceContext;)V
2323
}
2424

25+
public final class app/revanced/patches/all/location/hide/HideMockLocationPatch : app/revanced/patches/all/misc/transformation/BaseTransformInstructionsPatch {
26+
public static final field INSTANCE Lapp/revanced/patches/all/location/hide/HideMockLocationPatch;
27+
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;
28+
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;
29+
public synthetic fun transform (Lapp/revanced/patcher/util/proxy/mutableTypes/MutableMethod;Ljava/lang/Object;)V
30+
public fun transform (Lapp/revanced/patcher/util/proxy/mutableTypes/MutableMethod;Lkotlin/Pair;)V
31+
}
32+
2533
public final class app/revanced/patches/all/misc/debugging/EnableAndroidDebuggingPatch : app/revanced/patcher/patch/ResourcePatch {
2634
public static final field INSTANCE Lapp/revanced/patches/all/misc/debugging/EnableAndroidDebuggingPatch;
2735
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
@file:Suppress("unused")
2+
3+
package app.revanced.patches.all.location.hide
4+
5+
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
6+
import app.revanced.patcher.patch.annotation.Patch
7+
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
8+
import app.revanced.patches.all.misc.transformation.BaseTransformInstructionsPatch
9+
import app.revanced.patches.all.misc.transformation.IMethodCall
10+
import app.revanced.patches.all.misc.transformation.fromMethodReference
11+
import app.revanced.util.getReference
12+
import com.android.tools.smali.dexlib2.iface.ClassDef
13+
import com.android.tools.smali.dexlib2.iface.Method
14+
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
15+
import com.android.tools.smali.dexlib2.iface.instruction.Instruction
16+
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
17+
18+
@Patch(
19+
name = "Hide mock location",
20+
description = "Prevents the app from knowing the device location is being mocked by a third party app.",
21+
use = false
22+
)
23+
object HideMockLocationPatch : BaseTransformInstructionsPatch<Pair<Instruction, Int>>() {
24+
override fun filterMap(
25+
classDef: ClassDef,
26+
method: Method,
27+
instruction: Instruction,
28+
instructionIndex: Int
29+
): Pair<Instruction, Int>? {
30+
val reference = instruction.getReference<MethodReference>() ?: return null
31+
if (fromMethodReference<MethodCall>(reference) == null) return null
32+
33+
return instruction to instructionIndex
34+
}
35+
36+
override fun transform(mutableMethod: MutableMethod, entry: Pair<Instruction, Int>) {
37+
val (instruction, index) = entry
38+
instruction as FiveRegisterInstruction
39+
40+
// Replace return value with a constant `false` boolean.
41+
mutableMethod.replaceInstruction(
42+
index + 1,
43+
"const/4 v${instruction.registerC}, 0x0"
44+
)
45+
}
46+
}
47+
48+
private enum class MethodCall(
49+
override val definedClassName: String,
50+
override val methodName: String,
51+
override val methodParams: Array<String>,
52+
override val returnType: String
53+
) : IMethodCall {
54+
IsMock("Landroid/location/Location;", "isMock", emptyArray(), "Z"),
55+
IsFromMockProvider("Landroid/location/Location;", "isFromMockProvider", emptyArray(), "Z")
56+
}

0 commit comments

Comments
 (0)