【Android】【root & remount】adb su如何添加密码校验

前言

客户想在user版本添加su 权限,并实现user版本的root remount功能。

当前思路时执行su时添加密码,如果密码正确设置 sys.变量为true。adb root时判断sys变量为true时,执行root动作。

su 添加密码实现

su.cpp 添加密码部分:

bash 复制代码
int main(int argc, char** argv) {
......

    // The default user is root.
    uid_t uid = 0;
    gid_t gid = 0;
    //add start
    std::string build_type = android::base::GetProperty("ro.build.type", "");
    if(build_type == "user") {
        std::string password;
        std::cout << "Enter password: "<<std::endl;
        std::cin >> password;
        std::cout << "Your password: "<<password<<std::endl;

        if(password == "1234"){
            std::cout << "Password verify succes!"<<std::endl;
            android::base::SetProperty("sys.root.enable", "1");
        } else {
            std::cout << "Password verify fail !"<<std::endl;
            android::base::SetProperty("sys.root.enable", "0");
            return 1;
        }
    }
    //add end
}
相关推荐
程序员煊子20 小时前
用 Cursor 从零搭一个 Compose 本地记账 App:实战记录与源码解析
android·kotlin·compose·cursor
alexhilton1 天前
面向Android开发者的Google I/O 2026
android·kotlin·android jetpack
私人珍藏库1 天前
【Android】豆图助手-永久HY-模拟微X~zfb各种截图
android·app·工具·软件·多功能
程序员陆业聪1 天前
Shadow实战接入与生产落地:从零搭建到稳定运行
android
程序员陆业聪1 天前
Shadow Transform:编译期的魔法——字节码替换实战
android
ᰔᩚ. 一怀明月ꦿ1 天前
MySQL 学习目标
学习·mysql·adb
imuliuliang1 天前
Laravel6.x核心特性全解析
android·php·laravel
idingzhi1 天前
A股量化策略日报(2026年05月22日)
android·开发语言·python·kotlin
测试员周周1 天前
【Appium 系列】第14节-断言与验证 — Validator 的设计
android·人工智能·python·功能测试·ios·单元测试·appium
赏金术士1 天前
Android 动画对比指南:View 系统 vs Jetpack Compose
android·kotlin·compose