【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
}
相关推荐
月下的郁王子13 分钟前
进阶学习 PHP 中的二进制和位运算
android·学习·php
BrianGriffin14 分钟前
DcatAdmin框架小坑
android
Just_Paranoid2 小时前
【Settings】获取 SIM 卡信号强度 dBm 和 ASU
android·at·csq·dbm·asu
Q***f6352 小时前
Kotlin在Android性能优化中的工具
android·开发语言·kotlin
杨筱毅3 小时前
【底层机制】Android图形渲染体系深度解析:VSync信号机制
android·图形渲染·底层机制
江澎涌4 小时前
JHandler——一套简单易用的 C++ 事件循环机制
android·c++·harmonyos
心疼你的一切5 小时前
Unity开发Rokid应用之离线语音指令交互模型
android·开发语言·unity·游戏引擎·交互·lucene
2501_915909065 小时前
iOS APP 抓包全流程解析,HTTPS 调试、网络协议分析与多工具组合方案
android·ios·小程序·https·uni-app·iphone·webview
Propeller6 小时前
【Android】快速上手 Android 组件化开发
android·架构
jianglangyixiao6 小时前
adb 使用配对码配对
adb