adb shell直接命令无法在telnet上运行

时间:2015-01-26 17:08:03

标签: 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)

出了什么问题?

1 个答案:

答案 0 :(得分:2)

您对adb协议如何工作的理解是错误的。您可以阅读规范,也可以在运行任何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