GeezerVison is showing github.com — Update V3 · 550cc/linuxKernelRoot@af1c6c5
File treeExpand file treeCollapse file tree Open diff view settings PermissionManager/app/src/main java/com/linux/permissionmanager
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: PermissionManager/app/src/main/cpp/root.cpp +40-8Lines changed: 40 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -144,7 +144,8 @@ Java_com_linux_permissionmanager_MainActivity_installSuTools( | 144 | 144 | jobject /* this */, | 145 | 145 | jlong rootKey, | 146 | 146 | jstring basePath, | 147 | | - jstring suToolsFilePath) { | | 147 | + jstring suToolsFilePath, | | 148 | + jstring suToolsFileFolderHeadFlags) { | 148 | 149 |
| 149 | 150 | const char *str1 = env->GetStringUTFChars(basePath, 0); | 150 | 151 | string strBasePath= str1; | @@ -154,11 +155,15 @@ Java_com_linux_permissionmanager_MainActivity_installSuTools( | 154 | 155 | string strSuFilePath= str1; | 155 | 156 | env->ReleaseStringUTFChars(suToolsFilePath, str1); | 156 | 157 |
| | 158 | + str1 = env->GetStringUTFChars(suToolsFileFolderHeadFlags, 0); | | 159 | + string strSuToolsFileFolderHeadFlags= str1; | | 160 | + env->ReleaseStringUTFChars(suToolsFileFolderHeadFlags, str1); | | 161 | + | 157 | 162 | stringstream sstr; | 158 | 163 |
| 159 | 164 | //安装su工具套件 | 160 | 165 | std::string su_hidden_path; | 161 | | - int install_su_tools_ret = safe_install_su_tools(rootKey, strBasePath.c_str(), su_hidden_path); | | 166 | + int install_su_tools_ret = safe_install_su_tools(rootKey, strBasePath.c_str(), su_hidden_path, strSuToolsFileFolderHeadFlags.c_str()); | 162 | 167 | sstr << "install_su_tools ret val:" << install_su_tools_ret<<", su_hidden_path:" << su_hidden_path << std::endl; | 163 | 168 |
| 164 | 169 | if (install_su_tools_ret == -504) { | @@ -169,7 +174,7 @@ Java_com_linux_permissionmanager_MainActivity_installSuTools( | 169 | 174 | sstr << "safe_run_normal_cmd cp_ret val:" <<cp_ret; | 170 | 175 | return env->NewStringUTF(sstr.str().c_str()); | 171 | 176 | } | 172 | | - install_su_tools_ret = safe_install_su_tools(rootKey, strBasePath.c_str(), su_hidden_path); | | 177 | + install_su_tools_ret = safe_install_su_tools(rootKey, strBasePath.c_str(), su_hidden_path, strSuToolsFileFolderHeadFlags.c_str()); | 173 | 178 | sstr << "install_su_tools ret val:" << install_su_tools_ret<<", su_hidden_path:" << su_hidden_path << std::endl; | 174 | 179 | } | 175 | 180 | if (install_su_tools_ret != 0) { | @@ -183,15 +188,20 @@ Java_com_linux_permissionmanager_MainActivity_uninstallSuTools( | 183 | 188 | JNIEnv* env, | 184 | 189 | jobject /* this */, | 185 | 190 | jlong rootKey, | 186 | | - jstring basePath) { | | 191 | + jstring basePath, | | 192 | + jstring suToolsFileFolderHeadFlags) { | 187 | 193 |
| 188 | 194 | const char *str1 = env->GetStringUTFChars(basePath, 0); | 189 | 195 | string strBasePath= str1; | 190 | 196 | env->ReleaseStringUTFChars(basePath, str1); | 191 | 197 |
| | 198 | + str1 = env->GetStringUTFChars(suToolsFileFolderHeadFlags, 0); | | 199 | + string strSuToolsFileFolderHeadFlags= str1; | | 200 | + env->ReleaseStringUTFChars(suToolsFileFolderHeadFlags, str1); | | 201 | + | 192 | 202 | stringstream sstr; | 193 | 203 |
| 194 | | - int uninstall_su_tools_ret = safe_uninstall_su_tools(rootKey, strBasePath.c_str()); | | 204 | + int uninstall_su_tools_ret = safe_uninstall_su_tools(rootKey, strBasePath.c_str(), strSuToolsFileFolderHeadFlags.c_str()); | 195 | 205 | sstr << "uninstallSuTools ret val:" << uninstall_su_tools_ret << std::endl; | 196 | 206 |
| 197 | 207 | if (uninstall_su_tools_ret != 0) { | @@ -201,12 +211,28 @@ Java_com_linux_permissionmanager_MainActivity_uninstallSuTools( | 201 | 211 | return env->NewStringUTF(sstr.str().c_str()); | 202 | 212 | } | 203 | 213 | extern "C" JNIEXPORT jstring JNICALL | | 214 | +Java_com_linux_permissionmanager_MainActivity_killAdbdProcess( | | 215 | + JNIEnv* env, | | 216 | + jobject /* this */, | | 217 | + jlong rootKey) { | | 218 | + | | 219 | + stringstream sstr; | | 220 | + int kill_adbd = safe_kill_adbd_process(rootKey); | | 221 | + sstr << "kill_adbd ret val:" << kill_adbd << std::endl; | | 222 | + if (kill_adbd != 0) { | | 223 | + return env->NewStringUTF(sstr.str().c_str()); | | 224 | + } | | 225 | + sstr << "killAdbdProcess done."; | | 226 | + return env->NewStringUTF(sstr.str().c_str()); | | 227 | +} | | 228 | +extern "C" JNIEXPORT jstring JNICALL | 204 | 229 | Java_com_linux_permissionmanager_MainActivity_autoSuEnvInject( | 205 | 230 | JNIEnv* env, | 206 | 231 | jobject /* this */, | 207 | 232 | jlong rootKey, | 208 | 233 | jstring targetProcessCmdline, | 209 | | - jstring basePath) { | | 234 | + jstring basePath, | | 235 | + jstring suToolsFileFolderHeadFlags) { | 210 | 236 |
| 211 | 237 | const char *str1 = env->GetStringUTFChars(targetProcessCmdline, 0); | 212 | 238 | string strTargetProcessCmdline= str1; | @@ -216,6 +242,12 @@ Java_com_linux_permissionmanager_MainActivity_autoSuEnvInject( | 216 | 242 | string strBasePath= str1; | 217 | 243 | env->ReleaseStringUTFChars(basePath, str1); | 218 | 244 |
| | 245 | + | | 246 | + str1 = env->GetStringUTFChars(suToolsFileFolderHeadFlags, 0); | | 247 | + string strSuToolsFileFolderHeadFlags= str1; | | 248 | + env->ReleaseStringUTFChars(suToolsFileFolderHeadFlags, str1); | | 249 | + | | 250 | + | 219 | 251 | stringstream sstr; | 220 | 252 |
| 221 | 253 | //杀光所有历史进程 | @@ -231,15 +263,15 @@ Java_com_linux_permissionmanager_MainActivity_autoSuEnvInject( | 231 | 263 | kill_cmd += std::to_string(t); | 232 | 264 | kill_cmd += ";"; | 233 | 265 | } | 234 | | - int kill_ret = run_normal_cmd(rootKey, kill_cmd.c_str()); | | 266 | + int kill_ret = safe_run_normal_cmd(rootKey, kill_cmd.c_str()); | 235 | 267 | sstr << "kill_ret ret val:"<< kill_ret << std::endl; | 236 | 268 | if (kill_ret != 0) { | 237 | 269 | return env->NewStringUTF(sstr.str().c_str()); | 238 | 270 | } | 239 | 271 |
| 240 | 272 | //注入su环境变量到指定进程 | 241 | 273 | std::string su_hidden_path; | 242 | | - int install_su_tools_ret = safe_install_su_tools(rootKey, strBasePath.c_str(), su_hidden_path); | | 274 | + int install_su_tools_ret = safe_install_su_tools(rootKey, strBasePath.c_str(), su_hidden_path, strSuToolsFileFolderHeadFlags.c_str()); | 243 | 275 | sstr << "install_su_tools ret val:" << install_su_tools_ret<<", su_hidden_path:" << su_hidden_path << std::endl; | 244 | 276 | if (install_su_tools_ret != 0) { | 245 | 277 | return env->NewStringUTF(sstr.str().c_str()); | |
Collapse file Copy file name to clipboardExpand all lines: PermissionManager/app/src/main/java/com/linux/permissionmanager/MainActivity.java +49-20Lines changed: 49 additions & 20 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 44 | 44 | public class MainActivity extends AppCompatActivity { | 45 | 45 |
| 46 | 46 | private long rootKey = 0x7F6766F8; | 47 | | - | 48 | 47 | private String suBasePath = "/data/local/tmp"; | 49 | 48 |
| 50 | 49 | //保存的本地配置信息 | @@ -193,26 +192,51 @@ public void onClick(View v) { | 193 | 192 | } | 194 | 193 | }); | 195 | 194 |
| 196 | | - Button su_env_inject_btn = findViewById(R.id.su_env_inject_btn); | 197 | | - su_env_inject_btn.setOnClickListener(new View.OnClickListener() { | | 195 | + Button su_env_inject_btn1 = findViewById(R.id.su_env_inject_btn1); | | 196 | + su_env_inject_btn1.setOnClickListener(new View.OnClickListener() { | | 197 | + @Override | | 198 | + public void onClick(View v) { | | 199 | + if (!guideOpenUsbDebugSwitch()) { | | 200 | + return; | | 201 | + } | | 202 | + //1.获取su工具文件路径 | | 203 | + String suToolsFilePath = WirteSuToolsFilePath("simple_su", MainActivity.this); | | 204 | + showConsoleMsg(suToolsFilePath); | | 205 | + | | 206 | + //2.安装su工具 | | 207 | + String suFolderHeadFlag = "su_ver1"; | | 208 | + String insRet = installSuTools(rootKey, suBasePath, suToolsFilePath, suFolderHeadFlag); | | 209 | + showConsoleMsg(insRet); | | 210 | + if(insRet.indexOf("installSuTools done.") == -1) { | | 211 | + return; | | 212 | + } | | 213 | + | | 214 | + //3.选择APP进程 | | 215 | + showSelectAppWindow(suFolderHeadFlag); | | 216 | + | | 217 | + } | | 218 | + }); | | 219 | + Button su_env_inject_btn2 = findViewById(R.id.su_env_inject_btn2); | | 220 | + su_env_inject_btn2.setOnClickListener(new View.OnClickListener() { | 198 | 221 | @Override | 199 | 222 | public void onClick(View v) { | 200 | 223 | if (!guideOpenUsbDebugSwitch()) { | 201 | 224 | return; | 202 | 225 | } | 203 | 226 | //1.获取su工具文件路径 | 204 | | - String suToolsFilePath = WirteSuToolsFilePath(MainActivity.this); | | 227 | + String suToolsFilePath = WirteSuToolsFilePath("su", MainActivity.this); | 205 | 228 | showConsoleMsg(suToolsFilePath); | 206 | 229 |
| 207 | 230 | //2.安装su工具 | 208 | | - String insRet = installSuTools(rootKey, suBasePath, suToolsFilePath); | | 231 | + String suFolderHeadFlag = "su_ver2"; | | 232 | + String insRet = installSuTools(rootKey, suBasePath, suToolsFilePath,suFolderHeadFlag); | 209 | 233 | showConsoleMsg(insRet); | 210 | 234 | if(insRet.indexOf("installSuTools done.") == -1) { | 211 | 235 | return; | 212 | 236 | } | 213 | 237 |
| 214 | 238 | //3.选择APP进程 | 215 | | - showSelectAppWindow(); | | 239 | + showSelectAppWindow(suFolderHeadFlag); | 216 | 240 |
| 217 | 241 | } | 218 | 242 | }); | @@ -221,7 +245,9 @@ public void onClick(View v) { | 221 | 245 | clean_su_btn.setOnClickListener(new View.OnClickListener() { | 222 | 246 | @Override | 223 | 247 | public void onClick(View v) { | 224 | | - showConsoleMsg(uninstallSuTools(rootKey,suBasePath)); | | 248 | + //让adbd自我重启 | | 249 | + showConsoleMsg(killAdbdProcess(rootKey)); | | 250 | + showConsoleMsg(uninstallSuTools(rootKey,suBasePath, "su")); | 225 | 251 | } | 226 | 252 | }); | 227 | 253 |
| @@ -279,7 +305,7 @@ public boolean guideOpenUsbDebugSwitch() { | 279 | 305 | AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this) | 280 | 306 | .setTitle("提示") | 281 | 307 | .setCancelable(false) | 282 | | - .setMessage("请先到开发者选项页面里打开【USB调试】开关(提示:在手机关于页面里连续点击系统版本号可启用开发者选项页面)") | | 308 | + .setMessage("请先到开发者选项页面里【打开USB调试】开关(提示:在手机关于页面里连续点击系统版本号可启用开发者选项页面)") | 283 | 309 | .setOnDismissListener(new DialogInterface.OnDismissListener() { | 284 | 310 | @Override | 285 | 311 | public void onDismiss(DialogInterface dialog) { | @@ -311,7 +337,7 @@ public boolean guideCloseUsbDebugSwitch() { | 311 | 337 | AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this) | 312 | 338 | .setTitle("提示") | 313 | 339 | .setCancelable(false) | 314 | | - .setMessage("请先到开发者选项页面里关闭【USB调试】开关") | | 340 | + .setMessage("请先到开发者选项页面里【关闭USB调试】开关") | 315 | 341 | .setOnDismissListener(new DialogInterface.OnDismissListener() { | 316 | 342 | @Override | 317 | 343 | public void onDismiss(DialogInterface dialog) { | @@ -352,7 +378,7 @@ public void handleMessage(@NonNull Message msg) { | 352 | 378 |
| 353 | 379 | new Thread() { | 354 | 380 | public void run() { | 355 | | - String ret = autoSuEnvInject(rootKey, appItem.getPackageName(), suBasePath); | | 381 | + String ret = autoSuEnvInject(rootKey, appItem.getPackageName(), suBasePath, appItem.getSuFolderHeadFlag()); | 356 | 382 | runOnUiThread(new Runnable() { | 357 | 383 | public void run() { | 358 | 384 | showConsoleMsg(ret); | @@ -388,7 +414,7 @@ public void onClick(DialogInterface dialog, int which) { | 388 | 414 | }; | 389 | 415 |
| 390 | 416 | //显示选择应用程序窗口 | 391 | | - public void showSelectAppWindow() { | | 417 | + public void showSelectAppWindow(String suFolderHeadFlag) { | 392 | 418 | final PopupWindow popupWindow = new PopupWindow(this); | 393 | 419 |
| 394 | 420 | View view = View.inflate(this, R.layout.select_app_wnd, null); | @@ -456,7 +482,8 @@ public void onDismiss() { //窗口即将关闭 | 456 | 482 | appList.add(new SelectAppRecyclerItem( | 457 | 483 | icon, | 458 | 484 | showName, | 459 | | - packageName)); | | 485 | + packageName, | | 486 | + suFolderHeadFlag)); | 460 | 487 | } | 461 | 488 | for (int i = 0; i < packages.size(); i++) { | 462 | 489 | PackageInfo packageInfo = packages.get(i); | @@ -476,7 +503,8 @@ public void onDismiss() { //窗口即将关闭 | 476 | 503 | appList.add(new SelectAppRecyclerItem( | 477 | 504 | icon, | 478 | 505 | showName, | 479 | | - packageName)); | | 506 | + packageName, | | 507 | + suFolderHeadFlag)); | 480 | 508 | } | 481 | 509 |
| 482 | 510 | SelectAppRecyclerAdapter adapter = new SelectAppRecyclerAdapter( | @@ -491,18 +519,17 @@ public void onDismiss() { //窗口即将关闭 | 491 | 519 |
| 492 | 520 | } | 493 | 521 |
| 494 | | - public static String WirteSuToolsFilePath(Context context) { | 495 | | - String suFileName = "su"; | | 522 | + public static String WirteSuToolsFilePath(String suName, Context context) { | 496 | 523 | String suFilePath = ""; | 497 | 524 | try { | 498 | | - suFilePath = context.getFilesDir().getPath() + "/" + suFileName; | | 525 | + suFilePath = context.getFilesDir().getPath() + "/" + suName; | 499 | 526 | File file = new File(suFilePath); | 500 | 527 | if (!file.exists()) { | 501 | 528 | if (!file.getParentFile().exists()) file.getParentFile().mkdirs(); | 502 | 529 | file.createNewFile(); | 503 | 530 | } | 504 | 531 | if (file.exists()) { | 505 | | - InputStream inputStream = context.getAssets().open(suFileName); | | 532 | + InputStream inputStream = context.getAssets().open(suName); | 506 | 533 | FileOutputStream outputStream = new FileOutputStream(file); | 507 | 534 | byte[] content = new byte[1024]; | 508 | 535 | while (inputStream.read(content) > 0) { | @@ -532,9 +559,11 @@ public static String WirteSuToolsFilePath(Context context) { | 532 | 559 |
| 533 | 560 | public native String adbRoot(long rootKey); | 534 | 561 |
| 535 | | - public native String installSuTools(long rootKey, String basePath, String suToolsFilePath); | | 562 | + public native String installSuTools(long rootKey, String basePath, String suToolsFilePath, String suToolsFileFolderHeadFlags); | | 563 | + | | 564 | + public native String uninstallSuTools(long rootKey, String basePath, String suToolsFileFolderHeadFlags); | 536 | 565 |
| 537 | | - public native String uninstallSuTools(long rootKey, String basePath); | | 566 | + public native String killAdbdProcess(long rootKey); | 538 | 567 |
| 539 | | - public native String autoSuEnvInject(long rootKey, String targetProcessCmdline, String basePath); | | 568 | + public native String autoSuEnvInject(long rootKey, String targetProcessCmdline, String basePath, String suToolsFileFolderHeadFlags); | 540 | 569 | } |
Collapse file Copy file name to clipboardExpand all lines: PermissionManager/app/src/main/java/com/linux/permissionmanager/Model/SelectAppRecyclerItem.java +11-1Lines changed: 11 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -6,11 +6,13 @@ public class SelectAppRecyclerItem { | 6 | 6 | private Drawable icon=null; | 7 | 7 | private String showName; | 8 | 8 | private String packageName; | | 9 | + private String suFolderHeadFlag; | 9 | 10 |
| 10 | | - public SelectAppRecyclerItem(Drawable icon, String showName, String packageName){ | | 11 | + public SelectAppRecyclerItem(Drawable icon, String showName, String packageName, String suFolderHeadFlag){ | 11 | 12 | this.icon=icon; | 12 | 13 | this.showName = showName; | 13 | 14 | this.packageName = packageName; | | 15 | + this.suFolderHeadFlag = suFolderHeadFlag; | 14 | 16 | } | 15 | 17 |
| 16 | 18 | public Drawable getIcon() { | @@ -33,6 +35,14 @@ public String getPackageName() { | 33 | 35 | return packageName; | 34 | 36 | } | 35 | 37 |
| | 38 | + public void setSuFolderHeadFlag(String suFolderHeadFlag) { | | 39 | + this.showName = showName; | | 40 | + } | | 41 | + | | 42 | + public String getSuFolderHeadFlag() { | | 43 | + return suFolderHeadFlag; | | 44 | + } | | 45 | + | 36 | 46 | public void setPackageName(String packageName) { | 37 | 47 | this.packageName = packageName; | 38 | 48 | } | |
Collapse file Copy file name to clipboardExpand all lines: PermissionManager/app/src/main/res/layout/activity_main.xml +10-2Lines changed: 10 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 110 | 110 |
| 111 | 111 | <Button | 112 | 112 | android:layout_marginTop="5dp" | 113 | | - android:id="@+id/su_env_inject_btn" | | 113 | + android:id="@+id/su_env_inject_btn1" | 114 | 114 | android:layout_width="wrap_content" | 115 | 115 | android:layout_height="wrap_content" | 116 | | - android:text="8.授权ROOT到其他APP" | | 116 | + android:text="8.授权ROOT到其他APP-[1]" | | 117 | + /> | | 118 | + | | 119 | + <Button | | 120 | + android:layout_marginTop="5dp" | | 121 | + android:id="@+id/su_env_inject_btn2" | | 122 | + android:layout_width="wrap_content" | | 123 | + android:layout_height="wrap_content" | | 124 | + android:text="8.授权ROOT到其他APP-[2]" | 117 | 125 | /> | 118 | 126 |
| 119 | 127 | <Button | |
Collapse file Copy file name to clipboardExpand all lines: su/jni/Android.mk +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -9,3 +9,5 @@ LOCAL_DISABLE_FATAL_LINKER_WARNINGS := true | 9 | 9 | LOCAL_MODULE := su | 10 | 10 | LOCAL_SRC_FILES := ../su.cpp ../base64.cpp ../../testRoot/adb64_helper.cpp ../../testRoot/process64_inject.cpp ../../testRoot/ptrace_arm64_utils.cpp | 11 | 11 | include $(BUILD_EXECUTABLE) | | 12 | + | | 13 | +include $(LOCAL_PATH)/simple_su/Android.mk |
Collapse file Copy file name to clipboard +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +LOCAL_PATH := $(call my-dir) | | 2 | + | | 3 | +include $(CLEAR_VARS) | | 4 | +LOCAL_CPPFLAGS += -std=c++17 | | 5 | +LOCAL_CFLAGS += -fPIE | | 6 | +LOCAL_CFLAGS += -fvisibility=hidden | | 7 | +LOCAL_LDFLAGS += -fPIE -pie | | 8 | +LOCAL_DISABLE_FATAL_LINKER_WARNINGS := true | | 9 | +LOCAL_MODULE := simple_su | | 10 | +LOCAL_SRC_FILES := ../../simple_su.cpp ../../base64.cpp ../../../testRoot/adb64_helper.cpp ../../../testRoot/process64_inject.cpp ../../../testRoot/ptrace_arm64_utils.cpp | | 11 | +include $(BUILD_EXECUTABLE) |
Collapse file Copy file name to clipboardExpand all lines: su/root_key_helper.h +2-4Lines changed: 2 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -8,13 +8,11 @@ static inline unsigned int get_tmp_root_key(const char* myself_path) { | 8 | 8 |
| 9 | 9 | //1.取路径尾巴 | 10 | 10 | unsigned int key = 0; | 11 | | - const char* head_flag = "/su_"; | 12 | | - size_t len = strlen(head_flag); | 13 | | - char *pstart = strstr((char*)myself_path, head_flag); | | 11 | + char *pstart = strrchr((char*)myself_path, '_'); | 14 | 12 | if (!pstart) { | 15 | 13 | return 0; | 16 | 14 | } | 17 | | - pstart += len; | | 15 | + pstart ++; | 18 | 16 |
| 19 | 17 | size_t copy_len; | 20 | 18 | char *pend = strstr(pstart, "/"); | |
|