V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
yhm2046
V2EX  ›  Android

请教 adb 加密的提示问题

  •  
  •   yhm2046 · 330 天前 · 6850 次点击
    这是一个创建于 330 天前的主题,其中的信息可能已经有所发展或是发生改变。

    目前需要在 android11 上加入 adb 加密功能,已经实现了如下 Imgur

    现在需要完善加入一个提示词 Login 类似如下效果,参考了网上博客和 gpt 都是各种报错,附上修改代码,请教一下有啥方法可以实现,谢谢 Imgur

    system/core$
    diff --git a/adb/adb.cpp b/adb/adb.cpp 
    old mode 100644
    new mode 100755
    index c3e9731a3..ce1ed0b21
    --- a/adb/adb.cpp
    +++ b/adb/adb.cpp
    @@ -99,7 +99,11 @@ apacket* get_apacket(void)
         memset(&p->msg, 0, sizeof(p->msg));
         return p;
     }
    -
    +//evan add
    +#if !ADB_HOST
    +int accept_shell;
    +#endif
    +//evan end
     void put_apacket(apacket *p)
     {
         delete p;
    @@ -107,13 +111,20 @@ void put_apacket(apacket *p)
     
     void handle_online(atransport *t)
     {
    +//evan add
         D("adb: online");
    +	LOG(INFO) << "handle_online xwg";
         t->online = 1;
         t->SetConnectionEstablished(true);
    +	#if !ADB_HOST
    +	accept_shell=0;
    +	#endif
    +//evan end
     }
     
     void handle_offline(atransport *t)
     {
    +//evan add
         if (t->GetConnectionState() == kCsOffline) {
             LOG(INFO) << t->serial_name() << ": already offline";
             return;
    @@ -125,7 +136,10 @@ void handle_offline(atransport *t)
     
         // Close the associated usb
         t->online = 0;
    -
    +	#if !ADB_HOST
    +	accept_shell=0;
    +	#endif
    +//evan end
         // This is necessary to avoid a race condition that occurred when a transport closes
         // while a client socket is still active.
         close_all_sockets(t);
    @@ -329,8 +343,12 @@ static void handle_new_connection(atransport* t, apacket* p) {
             send_tls_request(t);
         } else if (!auth_required) {
             LOG(INFO) << "authentication not required";
    +		//evan add
             handle_online(t);
    +		LOG(INFO) << "authentication 22222222 xwg";
             send_connect(t);
    +		LOG(INFO) << "authentication 33333333333 xwg";
    +		//evan end
         } else {
             send_auth_request(t);
         }
    diff --git a/adb/services.cpp b/adb/services.cpp
    index 853d65897..b10c9ced9 100644
    --- a/adb/services.cpp
    +++ b/adb/services.cpp
    @@ -15,7 +15,9 @@
      */
     
     #define TRACE_TAG SERVICES
    -
    +//evan add
    +#include <android/log.h>
    +//evan end
     #include "sysdeps.h"
     
     #include <errno.h>
    @@ -50,7 +52,7 @@ void service_bootstrap_func(std::string service_name, std::function<void(unique_
     }
     
     }  // namespace
    -
    +//evan add
     unique_fd create_service_thread(const char* service_name, std::function<void(unique_fd)> func) {
         int s[2];
         if (adb_socketpair(s)) {
    @@ -73,10 +75,58 @@ unique_fd create_service_thread(const char* service_name, std::function<void(uni
         D("service thread started, %d:%d", s[0], s[1]);
         return unique_fd(s[0]);
     }
    +//evan add
    +#if !ADB_HOST
    +extern int accept_shell;
    +static void accept_shell_success(unique_fd fd) {
    +	LOG(INFO) << "accept_shell_success fd xwg" << fd.get();
    +	WriteFdExactly(fd, "success xwg\n");
    +	//adb_close(fd);
    +}
    +
    +static void accept_shell_fail(unique_fd fd) {
    +	LOG(INFO) << "accept_shell_fail fd " << fd.get();
    +	WriteFdExactly(fd, "failed xwg\n");
    +//	adb_close(fd);
    +}
    +
    +#endif
    +//evan end
     
     unique_fd service_to_fd(std::string_view name, atransport* transport) {
         unique_fd ret;
    +//evan add
     
    +#if !ADB_HOST
    +	//login
    +	__android_log_print(ANDROID_LOG_INFO, "xwg--", "Login in"); 
    +	LOG(INFO) << "1service_to_fd " << name ;
    +	char* temp;
    +	temp =(char*) strstr(name.data(),"raw");
    +	LOG(INFO) << "2service_to_fd " << (temp==NULL?"0":temp) ;
    +	LOG(INFO) << "3service_to_fd " << accept_shell ;
    +	printf("Login:");
    +	if(accept_shell==0){
    +		if(temp!=NULL){
    +			if(!strncmp(temp+4, "admin", 5)) {
    +				LOG(INFO) << "4service_to_fd success" ;
    +				accept_shell=1;
    +				ret = create_service_thread("accept_shell_success",accept_shell_success);
    +			}else{
    +				accept_shell=0;
    +				ret = create_service_thread("accept_shell_fail",accept_shell_fail);
    +			}
    +			if (ret >= 0) {
    +			    close_on_exec(ret);
    +			}
    +		}
    +		return ret;
    +	}
    +#endif	
    +//evan end
         if (is_socket_spec(name)) {
             std::string error;
             if (!socket_spec_connect(&ret, name, nullptr, nullptr, &error)) {
    
    
    2 条回复
    yhm2046
        1
    yhm2046  
    OP
       325 天前
    yhm2046
        2
    yhm2046  
    OP
       325 天前
    [img][/img]
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3980 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 10:23 · PVG 18:23 · LAX 02:23 · JFK 05:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.