【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
}
相关推荐
好的佩奇7 小时前
蓝牙之无线电与通信距离
android·flutter·蓝牙
vilya7 小时前
我把一套完整的 Python Agent 运行时塞进手机 APK:依赖闭包、Rust 轮子和三个真机坑
android
灵晔君8 小时前
【MySQL】数据库基础
数据库·mysql·adb
呆呆敲代码的小Y9 小时前
【实战精选面试题】C# 面试题详细解答,按难易程度排序
android·java·游戏·c#·游戏开发·unity面试题·c#面试题
思想觉悟11 小时前
SEAndroid实战
android·linux·c++
思想觉悟11 小时前
Aosp开发磨刀石之ADB速查
android·c++
在多学一点12 小时前
MySQL_DDL的基本命令
数据库·mysql·adb
应用市场13 小时前
用本机跑的开源音乐模型,给安卓小游戏做 20 秒无缝循环背景音乐
android·python·游戏开发·soundpool·音频处理
企业数字化笔记13 小时前
表单发布前怎么验收?版本引用、字段兼容和历史数据回归
android·数据挖掘·回归
生信分析笔记13 小时前
Nature 正刊 GPN-Star 基因组语言模型
android