ReVanced / revanced-patches

🧩 Patches for ReVanced
https://revanced.app
GNU General Public License v3.0
2.3k stars 268 forks source link

feat: Hide Mock Location Universal Patch #3389

Closed KotlinNight closed 1 month ago

KotlinNight commented 3 months ago

Feature description

A universal patch to hide mock location. In Android the user can set the gps location by using "mock locations". However, an App can check if this is the real location or not by checking [isMock()](https://developer.android.com/reference/android/location/Location#isMock()) (API >= 31) or [isFromMockProvider](https://developer.android.com/reference/android/location/Location#isFromMockProvider()) (API < 31). This behavior could be change by making these functions always return false.

Motivation

This feature could let the user change gps location in apps that don't allow it. It could also enhance user privacy, by letting the user set a random location as the "real" location. In some cases it could also help circumvent geo filtering.

Acknowledgements

epireyn commented 3 months ago

Hello!

Thank you for your request. Would you have any app to test the patch?

Thank you.

KotlinNight commented 2 months ago

Hello!

Thank you for your request. Would you have any app to test the patch?

Thank you.

@epireyn

Yes here's a quick and easy app to test it with without creating any accounts. I have checked the behaviour of the app is as expected, it can detect mock/no mock accurately.

https://apkpure.com/mock-location-root-detector/com.check.mock/download

epireyn commented 2 months ago

Thank you for your answer.

Unfortunately, it confirms what I thought: the method is inside the core library of android, and therefore not compiled with the app (it is shared by all apps and integrated to the OS). The only solution I see would be to recompile the whole lib (and therefore the OS), which is not possible with Revanced.

Since I started retro-engineering android a couple weeks ago, I keep this issue open until someone more experienced can confirm or deny my statement.

oSumAtrIX commented 2 months ago

Can you please explain why it would not be possible? The API may be in the OS but the return value can be changed.

epireyn commented 2 months ago

The returned value can be changed, but it would be app-specific, and not universal. Since the package android.location is not implemented inside the app(s) package, but is a compile only dependency (unless I'm wrong), Revanced should parse the dependency, which seems to be part of Android OS.

A solution would be to hook the method during runtime, but it isn't what Revanced is made for.

oSumAtrIX commented 2 months ago

You can filter for all references to that API and spoof the call's return value. Besides, if your initial assumption was that the code would be in the app itself, it would be even less possible to create a universal patch. Refer to https://github.com/ReVanced/revanced-patches/blob/main/src/main/kotlin/app/revanced/patches/all/connectivity/wifi/spoof/SpoofWifiPatch.kt for an example on how to spoof the return value of an API call part of the OS.

Hooking at runtime is possible via ReVanced.

epireyn commented 2 months ago

Thank for that precious information. I still have a great deal to learn! I made two PR, one on integrations and the other here.