【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 小时前
DeepAgents--01--Agent和OpenClaw的相关概念
android·数据库
汪海游龙3 小时前
告别 Play Console 手动上传:从模拟器截图到自动发版的完整流水线
android·ci/cd·github
weixin_440784113 小时前
【IntentSeivice实现原理】
android·java·开发语言·intentservice
delta_hell3 小时前
【阅读源码--Android】动画之ValueAnimator--2
android·源码·valueanimator
delta_hell3 小时前
【阅读源码--Android】动画之辅助类
android·源码·animator
delta_hell7 小时前
【阅读源码--Android】动画之ValueAnimator--1
android·源码·valueanimator
消失的旧时光-19437 小时前
第 2 篇:Android 控制屏为什么与机器人主控使用 TCP 长连接?
android·tcp/ip·机器人
小Ti客栈8 小时前
MySQL查询原理:从Server到InnoDB
android·mysql·adb
纪念 2299 小时前
MySQL(题目讲解二)
android·数据库·mysql
你听得到119 小时前
排查 App 问题:别只盯着报错,把前后发生的事情串起来
android·前端·flutter