|
| 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