Xposed使用小結,android Wifi代理,權限申請模擬點擊

?1.Xposed安裝器(5.0以上版本有一個,5.0以下有一個,兩個不同的apk包)

?2.Root權限(手機需要root才可以使用Xposed)


能下載到


wifi代理

/** * Created by peter.li on 2017/12/13. */?

public class HttpProxyUtil {?

private static HttpProxyUtil instance; public static HttpProxyUtil getInstance() {? ?? ?? ?if(instance == null){ instance = new HttpProxyUtil(); } return instance; } public static Object getField(Object obj, String name) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException{ Field f = obj.getClass().getField(name); Object out = f.get(obj); return out; } public static Object getDeclaredField(Object obj, String name) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { Field f = obj.getClass().getDeclaredField(name); f.setAccessible(true); Object out = f.get(obj); return out; } public static void setEnumField(Object obj, String value, String name) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException{ Field f = obj.getClass().getField(name); f.set(obj, Enum.valueOf((Class) f.getType(), value)); } public static void setProxySettings(String assign , WifiConfiguration wifiConf) throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException{ setEnumField(wifiConf, assign, "proxySettings"); } WifiConfiguration GetCurrentWifiConfiguration(WifiManager manager) { if (!manager.isWifiEnabled()) return null; List?configurationList = manager.getConfiguredNetworks(); WifiConfiguration configuration = null; int cur = manager.getConnectionInfo().getNetworkId(); for (int i = 0; i < configurationList.size(); ++i) { WifiConfiguration wifiConfiguration = configurationList.get(i); if (wifiConfiguration.networkId == cur) configuration = wifiConfiguration; } return configuration; } public void setWifiProxySettings(Context context,String ip,int port) { //get the current wifi configuration WifiManager manager = (WifiManager)context.getApplicationContext().getSystemService(Context.WIFI_SERVICE); WifiConfiguration config = GetCurrentWifiConfiguration(manager); if(null == config) return; try { //get the link properties from the wifi configuration Object linkProperties = getField(config, "linkProperties"); if(null == linkProperties) return; //get the setHttpProxy method for LinkProperties Class proxyPropertiesClass = Class.forName("android.net.ProxyProperties"); Class[] setHttpProxyParams = new Class[1]; setHttpProxyParams[0] = proxyPropertiesClass; Class lpClass = Class.forName("android.net.LinkProperties"); Method setHttpProxy = lpClass.getDeclaredMethod("setHttpProxy", setHttpProxyParams); setHttpProxy.setAccessible(true); //get ProxyProperties constructor Class[] proxyPropertiesCtorParamTypes = new Class[3]; proxyPropertiesCtorParamTypes[0] = String.class; proxyPropertiesCtorParamTypes[1] = int.class; proxyPropertiesCtorParamTypes[2] = String.class; Constructor proxyPropertiesCtor = proxyPropertiesClass.getConstructor(proxyPropertiesCtorParamTypes); //create the parameters for the constructor Object[] proxyPropertiesCtorParams = new Object[3]; proxyPropertiesCtorParams[0] = ip; proxyPropertiesCtorParams[1] = port; proxyPropertiesCtorParams[2] = null; //create a new object using the params Object proxySettings = proxyPropertiesCtor.newInstance(proxyPropertiesCtorParams); //pass the new object to setHttpProxy Object[] params = new Object[1]; params[0] = proxySettings; setHttpProxy.invoke(linkProperties, params); setProxySettings("STATIC", config); //save the settings manager.updateNetwork(config); manager.disconnect(); manager.reconnect(); } catch(Exception e) { } } public void unsetWifiProxySettings(Context context) { WifiManager manager = (WifiManager)context.getApplicationContext().getSystemService(Context.WIFI_SERVICE); WifiConfiguration config = GetCurrentWifiConfiguration(manager); if(null == config) return; try { //get the link properties from the wifi configuration Object linkProperties = getField(config, "linkProperties"); if(null == linkProperties) return; //get the setHttpProxy method for LinkProperties Class proxyPropertiesClass = Class.forName("android.net.ProxyProperties"); Class[] setHttpProxyParams = new Class[1]; setHttpProxyParams[0] = proxyPropertiesClass; Class lpClass = Class.forName("android.net.LinkProperties"); Method setHttpProxy = lpClass.getDeclaredMethod("setHttpProxy", setHttpProxyParams); setHttpProxy.setAccessible(true); //pass null as the proxy Object[] params = new Object[1]; params[0] = null; setHttpProxy.invoke(linkProperties, params); setProxySettings("NONE", config); //save the config manager.updateNetwork(config); manager.disconnect(); manager.reconnect(); } catch(Exception e) { } } }



/**

* Created by peter.li on 2017/12/13.

*/

public class HttpProxyUtilHigher {

private static HttpProxyUtilHigherinstance;

? ? public static HttpProxyUtilHighergetInstance() {

if(instance ==null){

instance =new HttpProxyUtilHigher();

? ? ? ? }

return instance;

? ? }

public static void setEnumField(Object obj, String value, String name)

throws SecurityException, NoSuchFieldException,IllegalArgumentException, IllegalAccessException{

Field f = obj.getClass().getField(name);

? ? ? ? f.set(obj, Enum.valueOf((Class) f.getType(), value));

? ? }

public static ObjectgetDeclaredFieldObject(Object obj, String name)

throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException{

Field f = obj.getClass().getDeclaredField(name);

? ? ? ? f.setAccessible(true);

? ? ? ? Object out = f.get(obj); return out;

? ? }

public static void setDeclardFildObject(Object obj,String name,Object object){

Field f =null;

? ? ? ? try {

f = obj.getClass().getDeclaredField(name);

? ? ? ? }catch (NoSuchFieldException e) {

e.printStackTrace();

? ? ? ? }

f.setAccessible(true);

? ? ? ? try {

f.set(obj,object);

? ? ? ? }catch (IllegalAccessException e) {

e.printStackTrace();

? ? ? ? }

}

// 獲取當前的Wifi連接

? ? public static WifiConfigurationgetCurrentWifiConfiguration(WifiManager wifiManager) {

if (!wifiManager.isWifiEnabled())

return null;

? ? ? ? List configurationList = wifiManager.getConfiguredNetworks();

? ? ? ? WifiConfiguration configuration =null;

? ? ? ? int cur = wifiManager.getConnectionInfo().getNetworkId();

? ? ? ? // Log.d("當前wifi連接信息",wifiManager.getConnectionInfo().toString());

? ? ? ? for (int i =0; i < configurationList.size(); ++i) {

WifiConfiguration wifiConfiguration = configurationList.get(i);

? ? ? ? ? ? if (wifiConfiguration.networkId == cur)

configuration = wifiConfiguration;

? ? ? ? }

return configuration;

? ? }

/**

? ? * 設置代理信息 exclList是添加不用代理的網址用的

? ? * */

? ? public void setHttpPorxySetting(Context context,String host, int port, List exclList)

throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException,

? ? ? ? ? ? IllegalAccessException, NoSuchFieldException {

WifiManager wifiManager =(WifiManager)context.getSystemService(Context.WIFI_SERVICE);

? ? ? ? WifiConfiguration config =getCurrentWifiConfiguration(wifiManager);

? ? ? ? ProxyInfo mInfo =null;

? ? ? ? if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){

mInfo = ProxyInfo.buildDirectProxy(host,port);

? ? ? ? }

if (config !=null){

Class clazz = Class.forName("android.net.wifi.WifiConfiguration");

? ? ? ? ? ? Class parmars = Class.forName("android.net.ProxyInfo");

? ? ? ? ? ? Method method = clazz.getMethod("setHttpProxy",parmars);

//? ? ? ? ? ? Method methodGetHttpProxy = clazz.getMethod("getHttpProxy",parmars);

? ? ? ? ? ? method.invoke(config,mInfo);

? ? ? ? ? ? Object mIpConfiguration =getDeclaredFieldObject(config,"mIpConfiguration");

? ? ? ? ? ? setEnumField(mIpConfiguration, "STATIC", "proxySettings");

? ? ? ? ? ? setDeclardFildObject(config,"mIpConfiguration",mIpConfiguration);

? ? ? ? ? ? //save the settings

? ? ? ? ? ? wifiManager.updateNetwork(config);

? ? ? ? ? ? wifiManager.disconnect();

? ? ? ? ? ? wifiManager.reconnect();

? ? ? ? ? ? Log.i("MainAcitivity","修改之后");

? ? ? ? }

}

/**

? ? * 取消代理設置

? ? * */

? ? public void unSetHttpProxy(Context context)

throws ClassNotFoundException, InvocationTargetException, IllegalAccessException,

? ? ? ? ? ? NoSuchFieldException, NoSuchMethodException {

WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);

? ? ? ? WifiConfiguration configuration =getCurrentWifiConfiguration(wifiManager);

? ? ? ? ProxyInfo mInfo =null;

? ? ? ? if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){

mInfo = ProxyInfo.buildDirectProxy(null,0);

? ? ? ? }

if (configuration !=null){

Class clazz = Class.forName("android.net.wifi.WifiConfiguration");

? ? ? ? ? ? Class parmars = Class.forName("android.net.ProxyInfo");

? ? ? ? ? ? Method method = clazz.getMethod("setHttpProxy",parmars);

? ? ? ? ? ? method.invoke(configuration,mInfo);

? ? ? ? ? ? Object mIpConfiguration =getDeclaredFieldObject(configuration,"mIpConfiguration");

? ? ? ? ? ? setEnumField(mIpConfiguration, "NONE", "proxySettings");

? ? ? ? ? ? setDeclardFildObject(configuration,"mIpConfiguration",mIpConfiguration);

? ? ? ? ? ? //保存設置

? ? ? ? ? ? wifiManager.updateNetwork(configuration);

? ? ? ? ? ? wifiManager.disconnect();

? ? ? ? ? ? wifiManager.reconnect();

? ? ? ? }

}

}


權限模擬點擊



if (loadPackageParam.packageName.equals("com.android.packageinstaller")) {

if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.M){

if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.N){

//7.0

? ? ? ? ? ? ? ? ? ? findAndHookMethod("com.android.packageinstaller.permission.ui.handheld.GrantPermissionsViewHandlerImpl",loadPackageParam.classLoader, "createView",new XC_MethodHook() {

@Override

? ? ? ? ? ? ? ? ? ? ? ? protected void afterHookedMethod(MethodHookParam param)

throws Throwable {

super.afterHookedMethod(param);

? ? ? ? ? ? ? ? ? ? ? ? ? ? ViewGroup viewGroup = (ViewGroup)param.getResult();

? ? ? ? ? ? ? ? ? ? ? ? ? ? LinearLayout linearLayouteanrLayout = (LinearLayout)viewGroup.getChildAt(0);

? ? ? ? ? ? ? ? ? ? ? ? ? ? LinearLayout linearLayouteanrLayout2 = (LinearLayout)linearLayouteanrLayout.getChildAt(1);

? ? ? ? ? ? ? ? ? ? ? ? ? ? LinearLayout buttonBarLayout = (LinearLayout)linearLayouteanrLayout2.getChildAt(1);

? ? ? ? ? ? ? ? ? ? ? ? ? ? final Button btnAllow = (Button)buttonBarLayout.getChildAt(3);

//? ? ? ? ? ? ? ? ? ? Log.i("Xposed", "Holk測試程序:btnAllow="+btnAllow.getText().toString());

? ? ? ? ? ? ? ? ? ? ? ? ? ? new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {

@Override

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? public void run() {

Log.i("Xposed", "Holk測試程序:btnAllow111="+btnAllow.getText().toString());

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? btnAllow.performClick();

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }

},2000l);

? ? ? ? ? ? ? ? ? ? ? ? }

});

? ? ? ? ? ? ? ? }else{

//6.0

? ? ? ? ? ? ? ? ? ? findAndHookMethod("com.android.packageinstaller.permission.ui.GrantPermissionsDefaultViewHandler",loadPackageParam.classLoader, "createView",new XC_MethodHook() {

@Override

? ? ? ? ? ? ? ? ? ? ? ? protected void afterHookedMethod(MethodHookParam param)

throws Throwable {

super.afterHookedMethod(param);

? ? ? ? ? ? ? ? ? ? ? ? ? ? ViewGroup viewGroup = (ViewGroup)param.getResult();

? ? ? ? ? ? ? ? ? ? ? ? ? ? LinearLayout linearLayouteanrLayout = (LinearLayout)viewGroup.getChildAt(0);

? ? ? ? ? ? ? ? ? ? ? ? ? ? LinearLayout linearLayouteanrLayout2 = (LinearLayout)linearLayouteanrLayout.getChildAt(2);

//? ? ? ? ? ? ? ? ? ? ? ? ? ? LinearLayout buttonBarLayout = (LinearLayout)linearLayouteanrLayout2.getChildAt(3);

? ? ? ? ? ? ? ? ? ? ? ? ? ? final Button btnAllow = (Button)linearLayouteanrLayout2.getChildAt(3);

? ? ? ? ? ? ? ? ? ? Log.i("Xposed", "Holk測試程序:btnAllow="+btnAllow.getText().toString());

? ? ? ? ? ? ? ? ? ? ? ? ? ? new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {

@Override

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? public void run() {

Log.i("Xposed", "Holk測試程序:btnAllow111="+btnAllow.getText().toString());

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? btnAllow.performClick();

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }

},2000l);

? ? ? ? ? ? ? ? ? ? ? ? }

});

? ? ? ? ? ? ? ? }

}

}

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • Spring Cloud為開發人員提供了快速構建分布式系統中一些常見模式的工具(例如配置管理,服務發現,斷路器,智...
    卡卡羅2017閱讀 134,881評論 18 139
  • 1. Java基礎部分 基礎部分的順序:基本語法,類相關的語法,內部類的語法,繼承相關的語法,異常的語法,線程的語...
    子非魚_t_閱讀 31,759評論 18 399
  • 轉至元數據結尾創建: 董瀟偉,最新修改于: 十二月 23, 2016 轉至元數據起始第一章:isa和Class一....
    40c0490e5268閱讀 1,762評論 0 9
  • ```java /* * Copyright (C) 2006 The Android Open Source P...
    mrganer閱讀 1,158評論 0 50
  • Correctness AdapterViewChildren Summary: AdapterViews can...
    MarcusMa閱讀 8,900評論 0 6