Files
Abdurrahman Kaan DikeçandClaude Opus 5.5 1b6b1fab8d tools/adbd: a static adbd for Linux, USB only, keys always required
AOSP's adbd (platform-tools 34.0.5, the sources nmeum/android-tools vendors, SHA-256
pinned), built for adbd alone and static against musl in Alpine: one aarch64 binary of
2.49 MB for Ubuntu and OpenWrt alike, in under two minutes.

Debian's/Ubuntu's adbd package (26.04 only) is no option: it is patched to require no
authorisation on Linux and listens on TCP 5555 without FunctionFS. mu300-adbd.patch:
- auth_required = true on Linux, always; keys from /etc/mu300/adb_keys and
  /root/.android/adb_keys only, never Android's framework socket (an environment variable)
- FunctionFS on Linux and no TCP or vsock listener at all; no FunctionFS: exit
- umask 022, pushed files without group/other write, the login shell for adb shell
- musl: StopWorker waited for pthread_kill(t, 0) == ESRCH, which musl never returns for an
  exited thread that is not joined - adbd hung at the end of every USB connection
JDWP, adb over Wi-Fi (pairing) and mDNS are stubbed out, and protobuf with them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DqKKtBQZCfxYnHuBCuDqqn
2026-10-11 21:11:02 +03:00

37 lines
1.4 KiB
C++

// MU300 Linux adbd: the Android-only services that are left out of this build.
// JDWP (debugging Java processes: there are none), adb over Wi-Fi with pairing (needs Android's framework and
// would open a network port) and mDNS. Leaving them out also leaves out protobuf.
#include <string.h>
#include <memory>
#include <openssl/base64.h>
#include "adb_unique_fd.h"
#include "adb_wifi.h"
#include "daemon/jdwp_service.h"
#include "daemon/mdns.h"
#include "socket.h"
int init_jdwp(void) { return 0; }
asocket* create_jdwp_service_socket() { return nullptr; }
asocket* create_jdwp_tracker_service_socket() { return nullptr; }
asocket* create_app_tracker_service_socket() { return nullptr; }
unique_fd create_jdwp_connection_fd(int) { return unique_fd{}; }
void adbd_wifi_init(AdbdAuthContext*) {}
void adbd_wifi_secure_connect(atransport*) {}
void setup_mdns(int) {}
// musl has no b64_pton (mu300_compat.h); the keys in adb_keys are "BASE64 comment" lines, split before this
int b64_pton(const char* src, unsigned char* target, size_t targsize) {
size_t len = strlen(src), max = 0, out = 0;
if (!EVP_DecodedLength(&max, len)) return -1;
std::unique_ptr<uint8_t[]> buf(new uint8_t[max + 1]);
if (!EVP_DecodeBase64(buf.get(), &out, max, reinterpret_cast<const uint8_t*>(src), len)) return -1;
if (out > targsize) return -1;
memcpy(target, buf.get(), out);
return static_cast<int>(out);
}