【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
}
相关推荐
牛哇网络工作室2 小时前
UnityHDRP写实数字人全流程基础5—语音输入和语音识别
android·unity·c#·游戏引擎·aigc·语音识别·xcode
一笑的小酒馆2 小时前
Androidiot蓝牙配网简单封装
android
愚公搬代码5 小时前
【愚公系列】《Android应用案例开发大全》016-LBS类应用掌上杭州(辅助工具类的开发)
android·前端
g10565591396 小时前
LAMP博客平台Wordpress实战
android·mysql·nginx·php
hunterandroid7 小时前
[Android 从零到一] Compose LazyColumn 性能优化:key、稳定性与重组治理
android·前端
pengyu7 小时前
【Kotlin 协程修仙录 · 元婴境 · 中阶】 | 操作符真解:Flow 中间操作符与数据流变幻术
android·kotlin
pengyu8 小时前
【Kotlin 协程修仙录 · 元婴境 · 初阶】 | 冷流初啼:Flow 的基础与响应式编程的入门
android·kotlin
wawo009 小时前
Kuikly实践-从Android compose迁移到kuikly compose
android
Carson带你学Android11 小时前
Android 版 MCP 正式登场:AppFunctions
android·ai编程·jetbrains
古法安卓14 小时前
Android-Direct Boot 阶段与 getFilesDir() 路径变更问题深度分析
android·java·android studio