android 反射強行設置開啟系統(tǒng)權限

發(fā)現(xiàn)小米 6 安全管家,即使我關閉了某些權限,但我一打開應用后,應用自己開啟了權限,遂,反編譯之,得以下反射強行設置權限代碼。。

理論上手動開啟權限也是使用以下的代碼進行,因此只有系統(tǒng)應用可以使用。(但不排除某些廠商定制rom的過程中,漏掉了關鍵的驗證,調(diào)用只有有可能是可行的)

AppOpsManager appOpsManager = mContext.getSystemService(AppOpsManager.class);
HashMap<String, Integer> map = (HashMap<String, Integer>) ClazzUtils.getObjectFieldObject(appOpsManager,"sOpStrToOp");
Method method = appOpsManager.getClass().getMethod("setMode",int.class,int.class,String.class,int.class);
int code = map.get(AppOpsManager.OPSTR_GET_USAGE_STATS);
int uid = Binder.getCallingUid();
String pkn = mContext.getPackageName();
int mode = AppOpsManager.MODE_ALLOWED;
method.invoke(appOpsManager,code,uid,pkn,mode);

再附上一個反編譯小米安全管家設置權限的代碼:

Object mAppOpsManager = context.getSystemService("appops");
ClazzUtils.invokeObjectMethod(mAppOpsManager, "setUserRestriction", new Class[]{Integer.TYPE, Boolean.TYPE, IBinder.class}, new Object[]{Integer.valueOf(24), Boolean.valueOf(true), new Binder()});
ClazzUtils.invokeObjectMethod(mAppOpsManager, "setUserRestriction", new Class[]{Integer.TYPE, Boolean.TYPE, IBinder.class}, new Object[]{Integer.valueOf(45), Boolean.valueOf(true), new Binder()});
最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內(nèi)容