shell - adb shell 直接命令在 telnet 上不起作用

标签 shell adb telnet

我正在尝试通过直接连接使用 adb,即通过端口 5037 与 telnet,诸如“host:devices”之类的基本命令返回与等效 adb 命令相同的答案:

C:\adb>adb devices
List of devices attached
4d009c06c8459000        device
C:\adb>telnet localhost 5037
Connecting to localhost...
Sent: 000Chost:devices
Received: OKAY00184d009c06c8459000  device

但是当我尝试像“shell”这样的“设备”命令时,我得到一个错误:
C:\adb>adb shell ls
acct
cache
charger
config
...
...
C:\adb>telnet localhost 5037
Connecting to localhost...
Sent: 0008shell:ls
Received: FAIL0012device offline (x)

怎么了?

最佳答案

您对 adb 的理解协议(protocol)工作是错误的。要么阅读规范,要么只查看运行任何 adb shell 时真正发生的交换。命令:

C:\>set ADB_TRACE=1

C:\>adb shell date
system/core/adb/adb.c::main():Handling commandline()
system/core/adb/commandline.c::adb_commandline():interactive shell loop. buff=shell:date
system/core/adb/adb_client.c::_adb_connect():_adb_connect: host:version
system/core/adb/sysdeps_win32.c::socket_loopback_client():socket_loopback_client: port 5037 type tcp => fd 100
system/core/adb/transport.c::writex():writex: fd=100 len=4: 30303063 000c
system/core/adb/transport.c::writex():writex: fd=100 len=12: 686f73743a76657273696f6e host:version
system/core/adb/transport.c::readx():readx: fd=100 wanted=4
system/core/adb/transport.c::readx():readx: fd=100 wanted=4 got=4
4f4b4159 OKAY
system/core/adb/adb_client.c::_adb_connect():_adb_connect: return fd 100
system/core/adb/adb_client.c::adb_connect():adb_connect: service shell:date
system/core/adb/transport.c::readx():readx: fd=100 wanted=4
system/core/adb/transport.c::readx():readx: fd=100 wanted=4 got=4
30303034 0004
system/core/adb/transport.c::readx():readx: fd=100 wanted=4
system/core/adb/transport.c::readx():readx: fd=100 wanted=4 got=4
30303230 0020
system/core/adb/sysdeps_win32.c::adb_close():adb_close: 100(lo-client:5037)
system/core/adb/adb_client.c::_adb_connect():_adb_connect: shell:date
system/core/adb/sysdeps_win32.c::socket_loopback_client():socket_loopback_client: port 5037 type tcp => fd 101
system/core/adb/transport.c::writex():writex: fd=101 len=4: 30303132 0012
system/core/adb/transport.c::writex():writex: fd=101 len=18: 686f73743a7472616e73706f72742d61 host:transport-a
system/core/adb/adb_client.c::switch_socket_transport():Switch transport in progress
system/core/adb/transport.c::readx():readx: fd=101 wanted=4
system/core/adb/transport.c::readx():readx: fd=101 wanted=4 got=4
4f4b4159 OKAY
system/core/adb/adb_client.c::switch_socket_transport():Switch transport success
system/core/adb/transport.c::writex():writex: fd=101 len=4: 30303061 000a
system/core/adb/transport.c::writex():writex: fd=101 len=10: 7368656c6c3a64617465 shell:date
system/core/adb/transport.c::readx():readx: fd=101 wanted=4
system/core/adb/transport.c::readx():readx: fd=101 wanted=4 got=4
4f4b4159 OKAY
system/core/adb/adb_client.c::_adb_connect():_adb_connect: return fd 101
system/core/adb/adb_client.c::adb_connect():adb_connect: return fd 101
system/core/adb/commandline.c::adb_commandline():about to read_and_dump(fd=101)
system/core/adb/commandline.c::read_and_dump():read_and_dump(): pre adb_read(fd=101)
system/core/adb/commandline.c::read_and_dump():read_and_dump(): post adb_read(fd=101): len=30
Thu Mar 26 06:51:49 GMT 1970
system/core/adb/commandline.c::read_and_dump():read_and_dump(): pre adb_read(fd=101)
system/core/adb/commandline.c::read_and_dump():read_and_dump(): post adb_read(fd=101): len=0
system/core/adb/commandline.c::adb_commandline():read_and_dump() done.
system/core/adb/sysdeps_win32.c::adb_close():adb_close: 101(lo-client:5037)
system/core/adb/commandline.c::adb_commandline():interactive shell loop. return r=0

关于shell - adb shell 直接命令在 telnet 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28155081/

相关文章:

linux - Bash 方法返回值总是以 256 为模

bash - 使用shell脚本登录监控并发送邮件

ruby-on-rails - Docker - 无法转发交互式 shell 的端口

shell - 想要在双引号内使用双引号

python - 使用 python 在 telnet 连接的交换机上运行命令

javascript - Websocket 错误 : ERR_INVALID_HTTP_RESPONSE

linux - 用于在文件中生成任意大小的随机内容的命令

android - 无法在 Eclipse 中连接 Samsung Galaxy S3 Mini

android - adb disconnect <ip-address >,断开两个用户使用的同一服务器上同一设备的连接

android - LG Revolution 和 Android 开发