android更改暗码

本文深入探讨了在Contact应用程序下SpecialCharSequenceMgr.java类中秘密代码处理的方法,包括如何通过特定模式识别秘密代码并进行相应的广播操作。
在Contact应用程序下的SpecialCharSequenceMgr.java下的

static boolean handleSecretCode(Context context, String input) {
// Secret codes are in the form *#*#<code>#*#*
int len = input.length();
if (len > 8 && input.startsWith("*#*#") && input.endsWith("#*#*")) {
Intent intent = new Intent(Intents.SECRET_CODE_ACTION,
Uri.parse("android_secret_code://" + input.substring(4, len - 4)));
context.sendBroadcast(intent);
return true;
}else if (input.equals("*998#"))
{
Intent intent2 = new Intent();
intent2.setAction("com.android.phone.ACTION_FACTORY_MODE");
context.sendBroadcast(intent2);
return true;
}

return false;
}
### 实现 ADB Shell 输入密码的方式 在标准的 Android 系统中,`adb shell` 命令默认以 root 权限运行,不涉及密码输入机制。若需要在执行 `adb shell` 时引入密码验证流程,需通过修改系统源码实现自定义逻辑。 一种实现方式是在 `adb` 的初始化阶段控制访问权限,例如在 `system/core/adb/adb.cpp` 中引入一个全局变量 `accept_shell`,当设备断开连接后将其重置为 0,使得下次连接时需要重新验证身份。这一机制可通过如下代码实现: ```cpp int accept_shell; void handle_online(atransport *t) { t->online = 1; t->SetConnectionEstablished(true); accept_shell = 0; } void handle_offline(atransport *t) { t->online = 0; accept_shell = 0; } ``` 上述代码确保了每次 `adb` 断开连接后,系统会将 `accept_shell` 重置为 0,从而在下一次尝试执行 `adb shell` 时触发身份验证逻辑[^1]。 此外,若希望在 `adb shell su` 时引入密码验证机制,可在 `system/extras/su/su.cpp` 中修改源码,通过 `property_get` 获取系统属性中预设的密码,并与用户输入进行比对。例如: ```cpp char newpasswd[50] = {0}; char in_passwd[50] = {0}; property_get("presist.su.passwd", newpasswd, "-1"); while (1) { char *ret = fgets(in_passwd, sizeof(in_passwd), stdin); if (ret != NULL && strncmp(ret, newpasswd, strlen(newpasswd)) == 0) { break; } fprintf(stdout, "input passwd sucess \n"); } ``` 该段代码通过 `presist.su.passwd` 属性设置密码,并在执行 `su` 命令时要求用户输入匹配的密码才能切换至 root 权限[^2]。 --- ### 使用方式示例 1. 设置密码属性: ```shell setprop presist.su.passwd "123456" ``` 2. 通过 `adb shell` 登录后执行 `su` 并输入密码: ```shell adb shell su 123456 ``` 如输入正确,将获得 root 权限,否则拒绝访问。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值