【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 分钟前
php自动加载
android·php·android studio
警醒与鞭策15 分钟前
Cursor Agent Skill 原理及LLM , Agent, MCP ,Skill区别
android·unity·ai·cursor
TheNextByte137 分钟前
如何将通话记录从Android传输到PC
android
灵感菇_40 分钟前
Android Fragment全面解析
android·生命周期·fragment
web_Hsir44 分钟前
uniapp + vue2 + pfdjs + web-view 实现安卓、iOS App PDF预览
android·前端·uni-app
一起养小猫1 小时前
Flutter for OpenHarmony 实战:Container与Padding布局完全指南
android·flutter·harmonyos
HeDongDong-1 小时前
详解Kotlin的各种类(使用场景导向)
android·开发语言·kotlin
Whisper_Sy9 小时前
Flutter for OpenHarmony移动数据使用监管助手App实战 - 网络状态实现
android·java·开发语言·javascript·网络·flutter·php
小句10 小时前
MySQL慢查询日志详细使用指南
数据库·mysql·adb
ujainu10 小时前
Flutter + OpenHarmony 网格布局:GridView 与 SliverGrid 在鸿蒙设备内容展示中的应用
android·flutter·组件