[Android Software/Hacking General [Developers Only]] mm11751:
My android device is android 11, rk3568

Currently, it is necessary to add adb encryption function on android11, which has been implemented as follows:

View attachment 6048168

Now we need to add a prompt word Login similar to the following effect. I refer to online blogs and ChatGPT and there are various error reports. Attached is the modified code. I would like to ask if there is any way to achieve it. Thank you.

View attachment 6048170

my code:

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)) {