请教 adb 加密的提示问题

135 天前
 yhm2046

目前需要在 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)) {

2978 次点击
所在节点    Android
2 条回复
yhm2046
130 天前
yhm2046
130 天前
[img][/img]

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1003539

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX