Skip to content
This repository has been archived by the owner on Sep 6, 2019. It is now read-only.

Commit

Permalink
Added settings for SSID
Browse files Browse the repository at this point in the history
Fixes #652
  • Loading branch information
M66B committed Nov 13, 2013
1 parent e14b5d9 commit 9f024c6
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Changelog
* Fixed setting global and randomize on boot settings
* Require Android 4.0.3 (minimum for Xposed)
* Added settings for Advertisement ID (including randomization) ([issue](https://github.com/M66B/XPrivacy/issues/738))
* Added settings for SSID (including randomization) ([issue](https://github.com/M66B/XPrivacy/issues/652))
* Option to randomize subscriber ID (IMSI) ([issue](https://github.com/M66B/XPrivacy/issues/690))
* Added traditional Chinese translation
* Updated German translation
Expand Down
13 changes: 13 additions & 0 deletions res/layout/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,19 @@
android:maxLength="15" />
</TableRow>

<TableRow>

<TextView
android:text="@string/settings_ssid"
android:textIsSelectable="false" />

<CheckBox android:id="@+id/cbSSID" />

<EditText
android:id="@+id/etSSID"
android:inputType="text|textNoSuggestions" />
</TableRow>

<TableRow>

<TextView
Expand Down
1 change: 1 addition & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ however it is impossible to guarantee it will work flawless on each and every de
<string name="settings_operator">Operator</string>
<string name="settings_iccid" translatable="false">ICC ID</string>
<string name="settings_subscriber">Subscriber ID</string>
<string name="settings_ssid" translatable="false">SSID</string>
<string name="settings_ua">User agent</string>
<string name="settings_usage">Android usage data (requires restart)</string>
<string name="settings_log">Debug log (requires restart)</string>
Expand Down
2 changes: 2 additions & 0 deletions src/biz/bokhorst/xprivacy/BootReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ private void randomizeSettings(Context context, int uid) {
PrivacyManager.getRandomProp("ISO3166"));
PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingSubscriber,
PrivacyManager.getRandomProp("SubscriberId"));
PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingSSID,
PrivacyManager.getRandomProp("SSID"));
}
}
}
24 changes: 15 additions & 9 deletions src/biz/bokhorst/xprivacy/PrivacyManager.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package biz.bokhorst.xprivacy;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.lang.reflect.Field;
Expand Down Expand Up @@ -89,6 +88,7 @@ public class PrivacyManager {
public final static String cSettingOperator = "Operator";
public final static String cSettingIccId = "ICC_ID";
public final static String cSettingSubscriber = "Subscriber";
public final static String cSettingSSID = "SSID";
public final static String cSettingUa = "UA";
public final static String cSettingFUsed = "FUsed";
public final static String cSettingFInternet = "FInternet";
Expand Down Expand Up @@ -781,14 +781,10 @@ public static Object getDefacedProp(int uid, String name) {
return (cValueRandom.equals(value) ? getRandomProp("SubscriberId") : value);
}

if (name.equals("SSID"))
return ""; // Hidden network
if (name.equals("WifiSsid.octets")) {
int size = 8;
ByteArrayOutputStream octets = new ByteArrayOutputStream(size);
for (int i = 0; i < size; i++)
octets.write(0);
return octets; // Hidden network
if (name.equals("SSID")) {
// Default hidden network
String value = getSetting(null, null, uid, cSettingSSID, "", true);
return (cValueRandom.equals(value) ? getRandomProp("SSID") : value);
}

// Google services framework ID
Expand Down Expand Up @@ -970,6 +966,16 @@ public static String getRandomProp(String name) {
return subscriber;
}

if (name.equals("SSID")) {
String ssid = "";
while (ssid.length() < 6)
ssid += (char) (r.nextInt(26) + 'A');

ssid += Character.forDigit(r.nextInt(10), 10);
ssid += Character.forDigit(r.nextInt(10), 10);
return ssid;
}

return "";
}

Expand Down
7 changes: 6 additions & 1 deletion src/biz/bokhorst/xprivacy/Requirements.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package biz.bokhorst.xprivacy;

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

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -174,8 +176,11 @@ public void onClick(DialogInterface dialog, int which) {
if (checkField(WifiInfo.class, "mWifiSsid"))
try {
Class<?> clazz = Class.forName("android.net.wifi.WifiSsid");
if (!checkField(clazz, "octets"))
try {
findMethodExact(clazz, "createFromAsciiEncoded", String.class);
} catch (NoSuchMethodError ex) {
reportClass(clazz, context);
}
} catch (Throwable ex) {
sendSupportInfo(ex.toString(), context);
}
Expand Down
19 changes: 19 additions & 0 deletions src/biz/bokhorst/xprivacy/SettingsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public static void edit(final Context context, ApplicationInfoEx appInfo) {
final EditText etOperator = (EditText) dlgSettings.findViewById(R.id.etOperator);
final EditText etIccId = (EditText) dlgSettings.findViewById(R.id.etIccId);
final EditText etSubscriber = (EditText) dlgSettings.findViewById(R.id.etSubscriber);
final EditText etSSID = (EditText) dlgSettings.findViewById(R.id.etSSID);
final EditText etUa = (EditText) dlgSettings.findViewById(R.id.etUa);
final CheckBox cbUsage = (CheckBox) dlgSettings.findViewById(R.id.cbUsage);
final CheckBox cbLog = (CheckBox) dlgSettings.findViewById(R.id.cbLog);
Expand All @@ -66,6 +67,7 @@ public static void edit(final Context context, ApplicationInfoEx appInfo) {
final CheckBox cbAdId = (CheckBox) dlgSettings.findViewById(R.id.cbAdId);
final CheckBox cbCountry = (CheckBox) dlgSettings.findViewById(R.id.cbCountry);
final CheckBox cbSubscriber = (CheckBox) dlgSettings.findViewById(R.id.cbSubscriber);
final CheckBox cbSSID = (CheckBox) dlgSettings.findViewById(R.id.cbSSID);

Button btnOk = (Button) dlgSettings.findViewById(R.id.btnOk);
Button btnClear = (Button) dlgSettings.findViewById(R.id.btnClear);
Expand Down Expand Up @@ -93,6 +95,7 @@ public static void edit(final Context context, ApplicationInfoEx appInfo) {
String adid = PrivacyManager.getSetting(null, context, uid, PrivacyManager.cSettingAdId, "", false);
String country = PrivacyManager.getSetting(null, context, uid, PrivacyManager.cSettingCountry, "", false);
String subscriber = PrivacyManager.getSetting(null, context, uid, PrivacyManager.cSettingSubscriber, "", false);
String ssid = PrivacyManager.getSetting(null, context, uid, PrivacyManager.cSettingSSID, "", false);

cbSerial.setChecked(serial.equals(PrivacyManager.cValueRandom));
cbLat.setChecked(lat.equals(PrivacyManager.cValueRandom));
Expand All @@ -105,6 +108,7 @@ public static void edit(final Context context, ApplicationInfoEx appInfo) {
cbAdId.setChecked(adid.equals(PrivacyManager.cValueRandom));
cbCountry.setChecked(country.equals(PrivacyManager.cValueRandom));
cbSubscriber.setChecked(subscriber.equals(PrivacyManager.cValueRandom));
cbSSID.setChecked(ssid.equals(PrivacyManager.cValueRandom));

etSerial.setText(cbSerial.isChecked() ? "" : serial);
etLat.setText(cbLat.isChecked() ? "" : lat);
Expand All @@ -117,6 +121,7 @@ public static void edit(final Context context, ApplicationInfoEx appInfo) {
etAdId.setText(cbAdId.isChecked() ? "" : adid);
etCountry.setText(cbCountry.isChecked() ? "" : country);
etSubscriber.setText(cbSubscriber.isChecked() ? "" : subscriber);
etSSID.setText(cbSSID.isChecked() ? "" : ssid);

etSerial.setEnabled(!cbSerial.isChecked());
etLat.setEnabled(!cbLat.isChecked());
Expand All @@ -129,6 +134,7 @@ public static void edit(final Context context, ApplicationInfoEx appInfo) {
etAdId.setEnabled(!cbAdId.isChecked());
etCountry.setEnabled(!cbCountry.isChecked());
etSubscriber.setEnabled(!cbSubscriber.isChecked());
etSSID.setEnabled(!cbSSID.isChecked());

cbSerial.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
Expand Down Expand Up @@ -196,6 +202,12 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
etSubscriber.setEnabled(!isChecked);
}
});
cbSSID.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
etSSID.setEnabled(!isChecked);
}
});

etIP.setText(PrivacyManager.getSetting(null, context, uid, PrivacyManager.cSettingIP, "", false));
etMcc.setText(PrivacyManager.getSetting(null, context, uid, PrivacyManager.cSettingMcc, "", false));
Expand Down Expand Up @@ -263,6 +275,7 @@ public void onClick(View view) {
etAdId.setText(PrivacyManager.getRandomProp("AdvertisingId"));
etCountry.setText(PrivacyManager.getRandomProp("ISO3166"));
etSubscriber.setText(PrivacyManager.getRandomProp("SubscriberId"));
etSSID.setText(PrivacyManager.getRandomProp("SSID"));
}
});

Expand All @@ -287,6 +300,7 @@ public void onClick(View view) {
etOperator.getText().toString().equals("") &&
etIccId.getText().toString().equals("") &&
!cbSubscriber.isChecked() && etSubscriber.getText().toString().equals("") &&
!cbSSID.isChecked() && etSSID.getText().toString().equals("") &&
etUa.getText().toString().equals("")) {
// @formatter:on

Expand All @@ -307,6 +321,7 @@ public void onClick(View view) {
PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingOperator, null);
PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingIccId, null);
PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingSubscriber, null);
PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingSSID, null);
PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingUa, null);
Util.log(null, Log.WARN, "Cleared all settings uid=" + uid);
} else {
Expand Down Expand Up @@ -364,6 +379,8 @@ public void onClick(View view) {
.toString());
PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingSubscriber,
cbSubscriber.isChecked() ? PrivacyManager.cValueRandom : etSubscriber.getText().toString());
PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingSSID,
cbSSID.isChecked() ? PrivacyManager.cValueRandom : etSSID.getText().toString());
PrivacyManager.setSetting(null, context, uid, PrivacyManager.cSettingUa, etUa.getText().toString());
}

Expand Down Expand Up @@ -403,6 +420,7 @@ public void onClick(View view) {
etOperator.setText("");
etIccId.setText("");
etSubscriber.setText("");
etSSID.setText("");
etUa.setText("");
if (uid == 0) {
cbUsage.setChecked(false);
Expand All @@ -421,6 +439,7 @@ public void onClick(View view) {
cbAdId.setChecked(false);
cbCountry.setChecked(false);
cbSubscriber.setChecked(false);
cbSSID.setChecked(false);
}
});

Expand Down
13 changes: 9 additions & 4 deletions src/biz/bokhorst/xprivacy/XWifiManager.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package biz.bokhorst.xprivacy;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -14,6 +15,7 @@

import de.robv.android.xposed.XC_MethodHook.MethodHookParam;
import static de.robv.android.xposed.XposedHelpers.findField;
import static de.robv.android.xposed.XposedHelpers.findMethodExact;

@SuppressWarnings("deprecation")
public class XWifiManager extends XHook {
Expand Down Expand Up @@ -101,17 +103,20 @@ protected void after(MethodHookParam param) throws Throwable {
}

// SSID
String ssid = (String) PrivacyManager.getDefacedProp(Binder.getCallingUid(), "SSID");
try {
Field fieldSSID = findField(WifiInfo.class, "mSSID");
fieldSSID.set(wInfo, PrivacyManager.getDefacedProp(Binder.getCallingUid(), "SSID"));
fieldSSID.set(wInfo, ssid);
} catch (Throwable ex) {
try {
Field fieldWifiSsid = findField(WifiInfo.class, "mWifiSsid");
Object mWifiSsid = fieldWifiSsid.get(wInfo);
if (mWifiSsid != null) {
Field octets = findField(mWifiSsid.getClass(), "octets");
octets.set(mWifiSsid,
PrivacyManager.getDefacedProp(Binder.getCallingUid(), "WifiSsid.octets"));
// public static WifiSsid
// createFromAsciiEncoded(String asciiEncoded)
Method methodCreateFromAsciiEncoded = findMethodExact(mWifiSsid.getClass(),
"createFromAsciiEncoded", String.class);
fieldWifiSsid.set(wInfo, methodCreateFromAsciiEncoded.invoke(null, ssid));
}
} catch (Throwable exex) {
Util.bug(this, exex);
Expand Down

0 comments on commit 9f024c6

Please sign in to comment.