当前位置:   article > 正文

Android11系统 adb添加访问密码_adb 密码

adb 密码

Android11上,通过命令行访问adb的时候增加密码。

修改以后,直接访问adb会报错,需要使用<adb shell 密码>来输入密码鉴权,默认密码为admin,即输入adb shell admin以后可以正常访问adb。

详细修改如下:

1、修改system/core/adb/adb.cpp

此处主要通过重置accept_shell的值,让adb断开以后需要重新输入密码进行访问 

  1. diff --git a/system/core/adb/adb.cpp b/system/core/adb/adb.cpp
  2. index c3e9731a30..990dec445b 100644
  3. --- a/system/core/adb/adb.cpp
  4. +++ b/system/core/adb/adb.cpp
  5. @@ -100,6 +100,11 @@ apacket* get_apacket(void)
  6. return p;
  7. }
  8. +
  9. +#if !ADB_HOST
  10. +int accept_shell;
  11. +#endif
  12. +
  13. void put_apacket(apacket *p)
  14. {
  15. delete p;
  16. @@ -110,6 +115,9 @@ void handle_online(atransport *t)
  17. D("adb: online");
  18. t->online = 1;
  19. t->SetConnectionEstablished(true);
  20. + #if !ADB_HOST
  21. + accept_shell = 0;
  22. + #endif
  23. }
  24. void handle_offline(atransport *t)
  25. @@ -126,6 +134,9 @@ void handle_offline(atransport *t)
  26. // Close the associated usb
  27. t->online = 0;
  28. + #if !ADB_HOST
  29. + accept_shell = 0;
  30. + #endif
  31. // This is necessary to avoid a race condition that occurred when a transport closes
  32. // while a client socket is still active.
  33. close_all_sockets(t)
2、修改system/core/adb/services.cpp

访问密码通过读取property(persist.otg.passwd)的值获取, 默认为admin

  1. diff --git a/system/core/adb/services.cpp b/system/core/adb/services.cpp
  2. index 853d658976..c1544f6ac6 100644
  3. --- a/system/core/adb/services.cpp
  4. +++ b/system/core/adb/services.cpp
  5. @@ -27,6 +27,7 @@
  6. #include <cstring>
  7. #include <thread>
  8. +#include <android-base/properties.h>
  9. #include <android-base/stringprintf.h>
  10. #include <android-base/strings.h>
  11. #include <cutils/sockets.h>
  12. @@ -74,9 +75,41 @@ unique_fd create_service_thread(const char* service_name, std::function<void(uni
  13. return unique_fd(s[0]);
  14. }
  15. +#if !ADB_HOST
  16. +extern int accept_shell;
  17. +static void accept_shell_success(unique_fd fd) {
  18. + WriteFdExactly(fd, "success\n");
  19. +}
  20. +
  21. +static void accept_shell_fail(unique_fd fd) {
  22. + WriteFdExactly(fd, "failed\n");
  23. +}
  24. +#endif
  25. +
  26. unique_fd service_to_fd(std::string_view name, atransport* transport) {
  27. unique_fd ret;
  28. +#if !ADB_HOST
  29. + // login
  30. + char* temp;
  31. + temp = (char*)strstr(name.data(), "raw");
  32. + if (accept_shell == 0) {
  33. + if (temp != NULL) {
  34. + std::string passwd = android::base::GetProperty("persist.otg.passwd", "admin");
  35. + if (!strncmp(temp + 4, passwd.c_str(), passwd.length())) {
  36. + accept_shell = 1;
  37. + ret = create_service_thread("accept_shell_success", accept_shell_success);
  38. + } else {
  39. + accept_shell = 0;
  40. + ret = create_service_thread("accept_shell_fail", accept_shell_fail);
  41. + }
  42. + if (ret >= 0) {
  43. + close_on_exec(ret);
  44. + }
  45. + }
  46. + return ret;
  47. + }
  48. +#endif
  49. if (is_socket_spec(name)) {
  50. std::string error;
  51. if (!socket_spec_connect(&ret, name, nullptr, nullptr, &error)) {

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/886528
推荐阅读
相关标签
  

闽ICP备14008679号