Skip to content

Commit

Permalink
More hooks for prevent the detection of mock location
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Diaz committed Sep 27, 2016
1 parent 2d840b9 commit c865acd
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ private void onEncounter(PokemonData data, CaptureProbability probability) {

mEncounterNotification.show(
encounterPokemon.getNumber(),
encounterPokemon.getName(),
encounterPokemon.getIvPercentage(),
encounterPokemon.getIndividualAttack(),
encounterPokemon.getIndividualDefense(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ final class EncounterNotification {
}

@SuppressWarnings("deprecation")
void show(int pokemonNumber, String pokemonName, double iv, int attack, int defense, int stamina, int cp, double level, int hp, String move1, String move2, double pokeRate, double pokeBerryRate, double greatRate, double greatBerryRate, double ultraRate, double ultraBerryRate) {
void show(int pokemonNumber, double iv, int attack, int defense, int stamina, int cp, double level, int hp, String move1, String move2, double pokeRate, double pokeBerryRate, double greatRate, double greatBerryRate, double ultraRate, double ultraBerryRate) {
new Handler(Looper.getMainLooper()).post(() -> {

Notification notification = new NotificationCompat.Builder(mContext)
Expand Down
115 changes: 83 additions & 32 deletions app/src/main/java/com/icecream/snorlax/module/feature/mock/Mock.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import javax.inject.Singleton;

import android.content.ContentResolver;
import android.os.Bundle;
import android.provider.Settings;

import com.icecream.snorlax.module.feature.Feature;
Expand All @@ -28,16 +29,21 @@
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedHelpers;

import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;

@Singleton
public final class Mock implements Feature {

private final ClassLoader mClassLoader;
private final MockPreferences mPreferences;

private XC_MethodHook.Unhook mUnhookGetInt1;
private XC_MethodHook.Unhook mUnhookGetInt2;
private XC_MethodHook.Unhook mUnhookGetFloat1;
private XC_MethodHook.Unhook mUnhookGetFloat2;
private XC_MethodHook.Unhook mUnhookGetLong1;
private XC_MethodHook.Unhook mUnhookGetLong2;
private XC_MethodHook.Unhook mUnhookGetString;
private XC_MethodHook.Unhook mUnhookGetStringForUser;

private XC_MethodHook.Unhook mUnhookGms;
private XC_MethodHook.Unhook mUnhookMockProvider;

@Inject
Expand All @@ -60,57 +66,102 @@ public void subscribe() throws Exception {
return;
}

mUnhookGetString = findAndHookMethod(secure, "getString", ContentResolver.class, String.class, new XC_MethodHook() {
final XC_MethodHook hook = new XC_MethodHook() {
@Override
@SuppressWarnings("deprecation")
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (!mPreferences.isEnabled()) {
return;
}

String requested = (String) param.args[1];
if (requested.equals(Settings.Secure.ALLOW_MOCK_LOCATION)) {
param.setResult("0");
if (mPreferences.isEnabled()) {
String methodName = param.method.getName();
String setting = (String) param.args[1];
if (setting.equals(Settings.Secure.ALLOW_MOCK_LOCATION)) {
switch (methodName) {
case "getInt":
param.setResult(0);
break;
case "getString":
param.setResult("0");
break;
case "getFloat":
param.setResult(0.0f);
break;
case "getLong":
param.setResult(0L);
break;
default:
break;
}
}
}
}
});
};

mUnhookGetStringForUser = XposedHelpers.findAndHookMethod(secure, "getStringForUser", ContentResolver.class, String.class, Integer.TYPE, new XC_MethodHook() {
@Override
@SuppressWarnings("deprecation")
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (!mPreferences.isEnabled()) {
return;
}
mUnhookGetInt1 = XposedHelpers.findAndHookMethod(secure, "getInt", ContentResolver.class, String.class, hook);
mUnhookGetInt2 = XposedHelpers.findAndHookMethod(secure, "getInt", ContentResolver.class, String.class, int.class, hook);

mUnhookGetFloat1 = XposedHelpers.findAndHookMethod(secure, "getFloat", ContentResolver.class, String.class, hook);
mUnhookGetFloat2 = XposedHelpers.findAndHookMethod(secure, "getFloat", ContentResolver.class, String.class, float.class, hook);

mUnhookGetLong1 = XposedHelpers.findAndHookMethod(secure, "getLong", ContentResolver.class, String.class, hook);
mUnhookGetLong2 = XposedHelpers.findAndHookMethod(secure, "getLong", ContentResolver.class, String.class, long.class, hook);

String requested = (String) param.args[1];
if (requested.equals(Settings.Secure.ALLOW_MOCK_LOCATION)) {
param.setResult("0");
mUnhookGetString = XposedHelpers.findAndHookMethod(secure, "getString", ContentResolver.class, String.class, hook);

mUnhookGms = XposedHelpers.findAndHookMethod(location, "getExtras", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
final String GMS_MOCK_KEY = "mockLocation";
if (mPreferences.isEnabled()) {
Bundle extras = (Bundle) param.getResult();
if (extras != null && extras.getBoolean(GMS_MOCK_KEY)) {
extras.putBoolean(GMS_MOCK_KEY, false);
}
param.setResult(extras);
}
}
});

mUnhookMockProvider = findAndHookMethod(location, "isFromMockProvider",
new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (!mPreferences.isEnabled()) {
return;
}
mUnhookMockProvider = XposedHelpers.findAndHookMethod(location, "isFromMockProvider", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (mPreferences.isEnabled()) {
param.setResult(false);
}
}
);
});
}

@Override
public void unsubscribe() throws Exception {
if (mUnhookGetInt1 != null) {
mUnhookGetInt1.unhook();
}

if (mUnhookGetInt2 != null) {
mUnhookGetInt2.unhook();
}

if (mUnhookGetFloat1 != null) {
mUnhookGetFloat1.unhook();
}

if (mUnhookGetFloat2 != null) {
mUnhookGetFloat2.unhook();
}

if (mUnhookGetLong1 != null) {
mUnhookGetLong1.unhook();
}

if (mUnhookGetLong2 != null) {
mUnhookGetLong2.unhook();
}

if (mUnhookGetString != null) {
mUnhookGetString.unhook();
}

if (mUnhookGetStringForUser != null) {
mUnhookGetStringForUser.unhook();
if (mUnhookGms != null) {
mUnhookGms.unhook();
}

if (mUnhookMockProvider != null) {
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@

</PreferenceCategory>

<!--
<PreferenceCategory
android:title="@string/preference_hatch_notification">
android:title="@string/preference_hatch_notification"
>
<SwitchPreference
android:defaultValue="@bool/preference_hatch_notification_enable"
Expand All @@ -52,5 +54,6 @@
/>
</PreferenceCategory>
-->

</PreferenceScreen>

0 comments on commit c865acd

Please sign in to comment.