换机精灵 v2.5.2版本的 MD5 值为:469dcb6202646d6ec40973ea20c8c14b
以下内容为反编译后的 b.java 源代码,内容仅作参考
package com.cx.module.huanji.a;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.NetworkInfo;
import android.net.wifi.ScanResult;
import android.net.wifi.SupplicantState;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Handler;
import com.cx.tools.i.k;
import com.umeng.socialize.common.SocializeConstants;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Stack;
public class b {
private Method i;
private Method j;
private Method k;
private Context l;
private WifiManager m;
private boolean n;
private int o;
private h s;
private BroadcastReceiver t;
private IntentFilter u;
private Handler w;
private static final String h = b.class.getSimpleName();
public static int f3757a = -1;
public static int f3758b = 0;
public static int f3759c = 1;
public static int d = 2;
public static int e = 3;
public static int f = 4;
public static String g = "wifi_state";
private boolean p = false;
private List q = new ArrayList();
private List r = new ArrayList();
private g v = null;
private Stack x = new Stack();
private Object y = new Object();
private f z = new f(this);
public b(Context context) {
this.w = null;
this.l = context;
this.w = new Handler(this.l.getMainLooper());
new Thread(this.z).start();
k();
c(0);
}
private WifiConfiguration a(WifiConfiguration wifiConfiguration, String str, int i, String str2) {
com.cx.tools.e.a.c(h, "createWifiConfiguration enter.");
if (wifiConfiguration == null) {
wifiConfiguration = new WifiConfiguration();
}
wifiConfiguration.SSID = str;
WifiInfo connectionInfo = this.m.getConnectionInfo();
if (connectionInfo != null) {
wifiConfiguration.BSSID = connectionInfo.getMacAddress();
}
wifiConfiguration.allowedAuthAlgorithms.clear();
wifiConfiguration.allowedAuthAlgorithms.set(0);
wifiConfiguration.allowedProtocols.clear();
wifiConfiguration.allowedProtocols.set(0);
wifiConfiguration.allowedProtocols.set(1);
wifiConfiguration.allowedKeyManagement.clear();
wifiConfiguration.allowedKeyManagement.set(0);
wifiConfiguration.allowedPairwiseCiphers.clear();
wifiConfiguration.allowedPairwiseCiphers.set(1);
wifiConfiguration.allowedPairwiseCiphers.set(2);
wifiConfiguration.allowedGroupCiphers.clear();
wifiConfiguration.allowedGroupCiphers.set(2);
wifiConfiguration.allowedGroupCiphers.set(3);
wifiConfiguration.hiddenSSID = false;
if (i == 2) {
}
a(wifiConfiguration);
return wifiConfiguration;
}
public static String a(int i) {
return (i & 255) + "." + ((i >> 8) & 255) + "." + ((i >> 16) & 255) + "." + ((i >> 24) & 255);
}
public void a(Intent intent) {
String action = intent.getAction();
com.cx.tools.e.a.c(h, "handleEvent action=" + action);
if ("android.net.wifi.WIFI_STATE_CHANGED".equals(action)) {
d(intent.getIntExtra("wifi_state", 4));
return;
}
if ("android.net.wifi.SCAN_RESULTS".equals(action)) {
c(1);
return;
}
if ("android.net.wifi.NETWORK_IDS_CHANGED".equals(action)) {
c(0);
return;
}
if ("android.net.wifi.supplicant.STATE_CHANGE".equals(action)) {
a(WifiInfo.getDetailedStateOf((SupplicantState) intent.getParcelableExtra("newState")));
} else if ("android.net.wifi.STATE_CHANGE".equals(action)) {
a(((NetworkInfo) intent.getParcelableExtra("networkInfo")).getDetailedState());
} else if ("android.net.wifi.RSSI_CHANGED".equals(action)) {
a((NetworkInfo.DetailedState) null);
}
}
private void a(NetworkInfo.DetailedState detailedState) {
if (this.s == null) {
return;
}
if (!this.m.isWifiEnabled()) {
this.s.b();
return;
}
if (detailedState == NetworkInfo.DetailedState.OBTAINING_IPADDR) {
this.s.b();
} else {
this.s.a();
}
if (this.p) {
if (detailedState == NetworkInfo.DetailedState.CONNECTED || detailedState == NetworkInfo.DetailedState.DISCONNECTED || detailedState == NetworkInfo.DetailedState.FAILED) {
c(2);
}
}
}
private static void a(WifiConfiguration wifiConfiguration) {
try {
Field declaredField = wifiConfiguration.getClass().getDeclaredField("max_scb");
declaredField.setAccessible(true);
declaredField.setInt(wifiConfiguration, 8);
declaredField.setAccessible(false);
} catch (Exception e2) {
com.cx.tools.e.a.d(h, "checked max_scb.", e2);
}
try {
Class<?> cls = wifiConfiguration.getClass();
Field declaredField2 = cls.getDeclaredField("dhcp_start_addr");
declaredField2.setAccessible(true);
declaredField2.set(wifiConfiguration, "192.168.43.2");
declaredField2.setAccessible(false);
Field declaredField3 = cls.getDeclaredField("dhcp_end_addr");
declaredField3.setAccessible(true);
declaredField3.set(wifiConfiguration, "192.168.43.254");
declaredField3.setAccessible(false);
Field declaredField4 = cls.getDeclaredField("wifi_ap_gateway");
declaredField4.setAccessible(true);
declaredField4.set(wifiConfiguration, "192.168.43.1");
declaredField4.setAccessible(false);
} catch (Exception e3) {
com.cx.tools.e.a.d(h, "checked dhcp_start_addr/dhcp_end_addr/wifi_ap_gateway.", e3);
}
try {
Object obj = wifiConfiguration.getClass().getField("linkProperties").get(wifiConfiguration);
Object newInstance = Class.forName("android.net.RouteInfo").getConstructor(InetAddress.class).newInstance(InetAddress.getByName("192.168.43.1"));
obj.getClass().getDeclaredFields();
Field declaredField5 = obj.getClass().getDeclaredField("mRoutes");
declaredField5.setAccessible(true);
ArrayList arrayList = (ArrayList) declaredField5.get(obj);
arrayList.clear();
arrayList.add(newInstance);
declaredField5.setAccessible(false);
} catch (Exception e4) {
com.cx.tools.e.a.d(h, "checked linkProperties.", e4);
}
try {
Field declaredField6 = WifiConfiguration.class.getDeclaredField("mWifiApProfile");
declaredField6.setAccessible(true);
Object obj2 = declaredField6.get(wifiConfiguration);
declaredField6.setAccessible(false);
if (obj2 != null) {
Class<?> cls2 = obj2.getClass();
Field declaredField7 = cls2.getDeclaredField("SSID");
declaredField7.setAccessible(true);
declaredField7.set(obj2, wifiConfiguration.SSID);
declaredField7.setAccessible(false);
Field declaredField8 = cls2.getDeclaredField("BSSID");
declaredField8.setAccessible(true);
declaredField8.set(obj2, wifiConfiguration.BSSID);
declaredField8.setAccessible(false);
Field declaredField9 = cls2.getDeclaredField("secureType");
declaredField9.setAccessible(true);
declaredField9.set(obj2, "open");
declaredField9.setAccessible(false);
Field declaredField10 = cls2.getDeclaredField("dhcpEnable");
declaredField10.setAccessible(true);
declaredField10.setInt(obj2, 1);
declaredField10.setAccessible(false);
Field declaredField11 = cls2.getDeclaredField("maxConns");
declaredField11.setAccessible(true);
declaredField11.setInt(obj2, 8);
declaredField11.setAccessible(false);
Field declaredField12 = cls2.getDeclaredField("maxDhcpClients");
declaredField12.setAccessible(true);
declaredField12.setInt(obj2, 8);
declaredField12.setAccessible(false);
Field declaredField13 = cls2.getDeclaredField("ipAddress");
declaredField13.setAccessible(true);
declaredField13.set(obj2, "192.168.1.1");
declaredField13.setAccessible(false);
Field declaredField14 = cls2.getDeclaredField("startingIP");
declaredField14.setAccessible(true);
declaredField14.set(obj2, "192.168.1.2");
declaredField14.setAccessible(false);
Field declaredField15 = cls2.getDeclaredField("dhcpSubnetMask");
declaredField15.setAccessible(true);
declaredField15.set(obj2, "255.255.255.0");
declaredField15.setAccessible(false);
Field declaredField16 = cls2.getDeclaredField("hiddenSSID");
declaredField16.setAccessible(true);
declaredField16.setBoolean(obj2, false);
declaredField16.setAccessible(false);
}
} catch (Exception e5) {
com.cx.tools.e.a.d(h, "checked mWifiApProfile.", e5);
}
}
public void a(List list) {
com.cx.tools.e.a.c(h, "updateAccessPoints ConfiguredNetworks");
this.r.clear();
this.q.clear();
com.cx.tools.e.a.c(h, "updateAccessPoints " + this.m.getWifiState() + "," + this.m.isWifiEnabled() + "," + a());
com.cx.tools.e.a.c(h, "updateAccessPoints configs.size=" + (list == null ? "0" : Integer.valueOf(list.size())));
if (list != null) {
this.o = 0;
Iterator it = list.iterator();
while (it.hasNext()) {
WifiConfiguration wifiConfiguration = (WifiConfiguration) it.next();
if (wifiConfiguration.priority > this.o) {
this.o = wifiConfiguration.priority;
}
if (wifiConfiguration.status == 0) {
wifiConfiguration.status = 2;
} else if (this.p && wifiConfiguration.status == 1) {
wifiConfiguration.status = 0;
}
this.q.add(new a(this.l, wifiConfiguration));
}
}
List<ScanResult> scanResults = this.m.getScanResults();
com.cx.tools.e.a.c(h, "updateAccessPoints results.size=" + (scanResults == null ? "0" : Integer.valueOf(scanResults.size())));
if (scanResults != null) {
for (ScanResult scanResult : scanResults) {
if (scanResult.SSID != null && scanResult.SSID.length() != 0 && !scanResult.capabilities.contains("[IBSS]")) {
boolean z = false;
for (a aVar : this.q) {
if (aVar.a(scanResult)) {
z = true;
}
if (a(aVar.a())) {
b(aVar);
}
}
if (!z) {
a aVar2 = new a(this.l, scanResult);
this.q.add(aVar2);
if (a(aVar2.a())) {
this.r.add(aVar2);
if (this.v != null) {
this.v.a(null);
}
}
}
}
}
}
com.cx.tools.e.a.c(h, "updateAccessPoints finish");
}
public static boolean a(String str) {
boolean b2 = b(str);
return (b2 || str == null) ? b2 : str.endsWith(" iPhone");
}
public static boolean a(String str, String str2) {
boolean b2 = b(str);
if (!b2 || str2 == null || str2.length() <= 0) {
return b2;
}
if (str2.length() > 8) {
str2 = str2.substring(0, 8);
}
return str.contains(str2);
}
private void b(a aVar) {
if (aVar.b() == -1 || this.r.contains(aVar)) {
return;
}
this.r.add(aVar);
if (this.v != null) {
this.v.a(null);
}
}
private boolean b(int i) {
com.cx.tools.e.a.c(h, "connect networkId=" + i);
if (i == -1) {
return false;
}
int l = l();
WifiConfiguration wifiConfiguration = new WifiConfiguration();
wifiConfiguration.networkId = i;
wifiConfiguration.priority = l + 1;
this.m.updateNetwork(wifiConfiguration);
j();
this.m.enableNetwork(i, true);
com.cx.tools.e.a.c(h, "connect will reconnect.");
boolean reconnect = this.m.reconnect();
com.cx.tools.e.a.c(h, "connect finished. result = " + reconnect);
return reconnect;
}
private boolean b(a aVar, String str) {
if (aVar == null) {
return false;
}
WifiConfiguration wifiConfiguration = new WifiConfiguration();
wifiConfiguration.SSID = "\"" + aVar.a() + "\"";
wifiConfiguration.preSharedKey = "\"" + str + "\"";
wifiConfiguration.hiddenSSID = false;
wifiConfiguration.status = 2;
return b(this.m.addNetwork(wifiConfiguration));
}
public static boolean b(String str) {
return str != null && str.startsWith("hj");
}
private void c(int i) {
new Thread(new d(this, i)).start();
}
private void d(int i) {
com.cx.tools.e.a.c(h, "updateWifiState state=" + i);
if (i == 3) {
if (this.s != null) {
this.s.a();
}
c(0);
} else {
if (this.s != null) {
this.s.b();
}
this.q.clear();
}
}
private void j() {
this.m.saveConfiguration();
c(0);
}
private void k() {
this.m = (WifiManager) this.l.getSystemService("wifi");
try {
this.i = WifiManager.class.getMethod("getWifiApState", new Class[0]);
this.j = WifiManager.class.getMethod("setWifiApEnabled", WifiConfiguration.class, Boolean.TYPE);
this.k = WifiManager.class.getMethod("getWifiApConfiguration", new Class[0]);
f3758b = WifiManager.class.getField("WIFI_AP_STATE_DISABLING").getInt(this.m);
f3759c = WifiManager.class.getField("WIFI_AP_STATE_DISABLED").getInt(this.m);
d = WifiManager.class.getField("WIFI_AP_STATE_ENABLING").getInt(this.m);
e = WifiManager.class.getField("WIFI_AP_STATE_ENABLED").getInt(this.m);
f = WifiManager.class.getField("WIFI_AP_STATE_FAILED").getInt(this.m);
g = (String) WifiManager.class.getField("EXTRA_WIFI_AP_STATE").get(this.m);
} catch (Exception e2) {
e2.printStackTrace();
}
}
private int l() {
int i = 0;
List<WifiConfiguration> configuredNetworks = this.m.getConfiguredNetworks();
if (configuredNetworks == null) {
return 0;
}
Iterator<WifiConfiguration> it = configuredNetworks.iterator();
while (true) {
int i2 = i;
if (!it.hasNext()) {
return i2;
}
WifiConfiguration next = it.next();
if (next != null && next.status != 2 && next.priority > i2) {
i2 = next.priority;
}
i = i2;
}
}
public int a() {
int i = f3757a;
try {
return ((Integer) this.i.invoke(this.m, new Object[0])).intValue();
} catch (Exception e2) {
e2.printStackTrace();
return i;
}
}
public void a(a aVar) {
if (aVar.f3756c == -1) {
return;
}
this.m.removeNetwork(aVar.f3756c);
this.m.saveConfiguration();
c(0);
}
public void a(g gVar, int i, int i2) {
if (this.t == null) {
this.u = new IntentFilter();
this.u.addAction("android.net.wifi.WIFI_STATE_CHANGED");
this.u.addAction("android.net.wifi.SCAN_RESULTS");
this.u.addAction("android.net.wifi.NETWORK_IDS_CHANGED");
this.u.addAction("android.net.wifi.supplicant.STATE_CHANGE");
this.u.addAction("android.net.wifi.STATE_CHANGE");
this.u.addAction("android.net.wifi.RSSI_CHANGED");
this.t = new c(this);
}
if (this.s == null) {
this.s = new h(this, i, i2);
}
this.l.registerReceiver(this.t, this.u);
if (this.m.isWifiEnabled()) {
this.s.a(i, i2);
}
this.v = gVar;
}
public boolean a(a aVar, String str) {
if (aVar == null) {
com.cx.tools.e.a.c(h, "connectAp ap=null");
return false;
}
String str2 = aVar.f3754a;
com.cx.tools.e.a.c(h, "connectAp wifi-status:" + this.m.getWifiState());
if (this.m.getWifiState() == 3) {
if (str2.equals(this.m.getConnectionInfo().getSSID())) {
return true;
}
} else if (this.m.getWifiState() == 1 || this.m.getWifiState() == 0) {
com.cx.tools.e.a.c(h, "connectAp wifi is DISABLED.");
return false;
}
int i = aVar.f3756c;
com.cx.tools.e.a.c(h, "connectAp 001.");
if (aVar.f3755b != 0) {
if (!k.a(str)) {
com.cx.tools.e.a.c(h, "connectAp 006.");
return b(aVar, str);
}
WifiConfiguration c2 = aVar.c();
if (i == -1) {
i = this.m.addNetwork(c2);
}
return b(i);
}
if (i != -1) {
a(aVar);
}
com.cx.tools.e.a.c(h, "connectAp 002.");
WifiConfiguration wifiConfiguration = new WifiConfiguration();
wifiConfiguration.SSID = a.b(str2);
wifiConfiguration.wepKeys[0] = "\"\"";
wifiConfiguration.allowedKeyManagement.set(0);
wifiConfiguration.wepTxKeyIndex = 0;
int addNetwork = this.m.addNetwork(wifiConfiguration);
com.cx.tools.e.a.c(h, "connectAp 003. networkId=" + addNetwork);
return b(addNetwork);
}
public boolean a(boolean z) {
return a(z, (String) null);
}
public synchronized boolean a(boolean z, String str) {
boolean z2;
WifiConfiguration wifiConfiguration;
String[] c2;
String str2 = null;
boolean z3 = false;
synchronized (this) {
int wifiState = this.m.getWifiState();
com.cx.tools.e.a.c(h, "enableAP wifiState=" + wifiState + ",enable=" + z);
if (z && (wifiState == 2 || wifiState == 3 || wifiState == 1)) {
try {
this.m.setWifiEnabled(false);
this.n = true;
z2 = true;
} catch (Exception e2) {
com.cx.tools.e.a.d(h, "", e2);
}
} else {
z2 = false;
}
int a2 = a();
com.cx.tools.e.a.c(h, "enableAP apState=" + a2);
if (z) {
try {
} catch (Exception e3) {
com.cx.tools.e.a.d(h, "", e3);
}
if (a2 != e && a2 != d) {
wifiConfiguration = (WifiConfiguration) this.k.invoke(this.m, new Object[0]);
if (wifiConfiguration != null && (c2 = c()) != null) {
str2 = c2[0];
}
if (!a(str2, str)) {
String str3 = "hj" + new SimpleDateFormat("hhmmss").format(new Date()) + SocializeConstants.OP_DIVIDER_MINUS + Build.MODEL;
if (str != null && str.length() > 0) {
if (str.length() > 8) {
str = str.substring(0, 8);
}
str3 = str3 + str;
}
wifiConfiguration = a(wifiConfiguration, str3, 0, null);
}
this.j.invoke(this.m, wifiConfiguration, Boolean.valueOf(z));
com.cx.tools.e.a.c(h, "enableAP enable=" + z + ", mOldWifiEnabled=" + this.n);
if (!z && this.n) {
try {
this.m.setWifiEnabled(true);
this.n = false;
z3 = true;
} catch (Exception e4) {
com.cx.tools.e.a.d(h, "", e4);
}
}
z3 = z2;
}
}
wifiConfiguration = null;
this.j.invoke(this.m, wifiConfiguration, Boolean.valueOf(z));
com.cx.tools.e.a.c(h, "enableAP enable=" + z + ", mOldWifiEnabled=" + this.n);
if (!z) {
this.m.setWifiEnabled(true);
this.n = false;
z3 = true;
}
z3 = z2;
}
return z3;
}
public WifiInfo b() {
return this.m.getConnectionInfo();
}
public void b(boolean z) {
this.x.push(Boolean.valueOf(z));
}
public String[] c() {
WifiConfiguration wifiConfiguration;
String str;
Exception e2;
String str2;
String str3;
String str4;
Object obj;
try {
wifiConfiguration = (WifiConfiguration) this.k.invoke(this.m, new Object[0]);
} catch (Exception e3) {
e3.printStackTrace();
wifiConfiguration = null;
}
if (wifiConfiguration == null) {
return null;
}
String[] strArr = {null, null, null};
String str5 = wifiConfiguration.SSID;
String str6 = a.a(wifiConfiguration) != 0 ? wifiConfiguration.preSharedKey : null;
try {
Object obj2 = wifiConfiguration.getClass().getDeclaredField("linkProperties").get(wifiConfiguration);
Field declaredField = obj2.getClass().getDeclaredField("mRoutes");
declaredField.setAccessible(true);
ArrayList arrayList = (ArrayList) declaredField.get(obj2);
if (arrayList.size() > 0) {
Object obj3 = arrayList.get(0);
Field declaredField2 = obj3.getClass().getDeclaredField("mGateway");
declaredField2.setAccessible(true);
InetAddress inetAddress = (InetAddress) declaredField2.get(obj3);
declaredField2.setAccessible(false);
str = inetAddress.getHostAddress();
} else {
str = null;
}
try {
declaredField.setAccessible(false);
} catch (Exception e4) {
e2 = e4;
com.cx.tools.e.a.d(h, "getAPSsidAndKey", e2);
com.cx.tools.e.a.c(h, "getAPSsidAndKey ip=" + str);
if (str != null) {
}
if (str5 == null) {
}
str2 = r3;
str3 = str5;
str4 = str6;
strArr[0] = str3;
strArr[1] = str4;
strArr[2] = str2;
return strArr;
}
} catch (Exception e5) {
str = null;
e2 = e5;
}
com.cx.tools.e.a.c(h, "getAPSsidAndKey ip=" + str);
String str7 = str != null ? "192.168.43.1" : str;
if (str5 == null) {
try {
Field declaredField3 = WifiConfiguration.class.getDeclaredField("mWifiApProfile");
declaredField3.setAccessible(true);
obj = declaredField3.get(wifiConfiguration);
declaredField3.setAccessible(false);
} catch (Exception e6) {
str2 = str7;
str3 = str5;
str4 = str6;
}
if (obj != null) {
Class<?> cls = obj.getClass();
Field declaredField4 = cls.getDeclaredField("SSID");
declaredField4.setAccessible(true);
str3 = (String) declaredField4.get(obj);
try {
declaredField4.setAccessible(false);
Field declaredField5 = cls.getDeclaredField("secureType");
declaredField5.setAccessible(true);
String str8 = (String) declaredField5.get(obj);
declaredField5.setAccessible(false);
Field declaredField6 = cls.getDeclaredField("ipAddress");
declaredField6.setAccessible(true);
str2 = (String) declaredField6.get(obj);
try {
declaredField6.setAccessible(false);
if ("open".endsWith(str8)) {
str4 = str6;
} else {
Field declaredField7 = cls.getDeclaredField("key");
declaredField7.setAccessible(true);
str4 = (String) declaredField7.get(obj);
try {
declaredField7.setAccessible(false);
} catch (Exception e7) {
}
}
} catch (Exception e8) {
str4 = str6;
}
} catch (Exception e9) {
str2 = str7;
str4 = str6;
}
strArr[0] = str3;
strArr[1] = str4;
strArr[2] = str2;
return strArr;
}
}
str2 = str7;
str3 = str5;
str4 = str6;
strArr[0] = str3;
strArr[1] = str4;
strArr[2] = str2;
return strArr;
}
public void d() {
if (this.m == null) {
this.m = (WifiManager) this.l.getSystemService("wifi");
}
if (this.m.isWifiEnabled()) {
return;
}
try {
com.cx.tools.e.a.c(h, "setWifiEnabled true.");
this.m.setWifiEnabled(true);
} catch (Exception e2) {
com.cx.tools.e.a.d(h, "setWifiEnabled", e2);
}
}
public void e() {
if (this.t != null) {
this.l.unregisterReceiver(this.t);
this.t = null;
}
this.v = null;
if (this.s != null) {
this.s.b();
this.s = null;
}
}
public List f() {
return this.r;
}
public List g() {
return this.q;
}
public void h() {
this.z.a();
}
}