Skip to content

Commit

Permalink
change back to old ways forward
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed May 9, 2024
1 parent 3106ba8 commit 4cc083c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 23 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -543,10 +543,12 @@ gh-md-toc --insert README.md
- [swind pure-python-adb](https://github.com/Swind/pure-python-adb)
- [openstf/adbkit](https://github.com/openstf/adbkit)
- [ADB Source Code](https://android.googlesource.com/platform/system/core/+/android-4.4_r1/adb/adb.c)
- ADB Protocols [OVERVIEW.TXT](https://cs.android.com/android/platform/superproject/+/master:packages/modules/adb/OVERVIEW.TXT) [SERVICES.TXT](https://cs.android.com/android/platform/superproject/+/master:packages/modules/adb/SERVICES.TXT) [SYNC.TXT](https://cs.android.com/android/platform/superproject/+/master:packages/modules/adb/SYNC.TXT)
- [Awesome ADB](https://github.com/mzlogin/awesome-adb)
- [JakeWharton/pidcat](https://github.com/JakeWharton/pidcat)

# Develop
[PROTOCOL.md](docs/PROTOCOL.md)

# Alternative
- https://github.com/Swind/pure-python-adb

Expand Down
6 changes: 1 addition & 5 deletions adbutils/_adb.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,6 @@ def forward_list(self, serial: Union[None, str] = None) -> List[ForwardItem]:
items.append(ForwardItem(*parts))
return items

@deprecated(deprecated_in="0.15.0",
removed_in="1.0.0",
details="use Device.forward instead",
current_version=__version__)
def forward(self, serial, local, remote, norebind=False):
"""
Args:
Expand All @@ -357,7 +353,7 @@ def forward(self, serial, local, remote, norebind=False):
AdbError
"""
with self.make_connection() as c:
cmds = ["host-serial", serial, "forward"]
cmds = ["host-serial", serial, "forward"] # host-prefix:forward:norebind:<local>;<remote>
if norebind:
cmds.append("norebind")
cmds.append(local + ";" + remote)
Expand Down
12 changes: 1 addition & 11 deletions adbutils/_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,17 +235,7 @@ def shell2(
return ShellReturn(command=cmdargs, returncode=returncoode, output=output)

def forward(self, local: str, remote: str, norebind: bool = False):
c = self.open_transport()
args = ["host:forward"]
if norebind:
args.append("norebind")
args.append(local + ";" + remote)
c.send_command(":".join(args))
c.check_okay() # this OKAY means message was received
c.check_okay() # check reponse
# when successfully forwarded, port string will response, eg: "00041237"
# here we just read it and ignore
c.read_until_close()
self._client.forward(self._serial, local, remote, norebind)

def forward_port(self, remote: Union[int, str]) -> int:
"""forward remote port to local random port"""
Expand Down
20 changes: 14 additions & 6 deletions docs/PROTOCOL.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ TCP Local(5555) -> Remote(localhost:5037)

execute adb command, e.g. `adb -P 5555 devices`, now data should be seen in charles.

ADB Protocols from Android Source Code

- [OVERVIEW.TXT](https://cs.android.com/android/platform/superproject/+/main:packages/modules/adb/OVERVIEW.TXT)
- [SERVICES.TXT](https://cs.android.com/android/platform/superproject/+/main:packages/modules/adb/SERVICES.TXT)
- [SYNC.TXT](https://cs.android.com/android/platform/superproject/+/main:packages/modules/adb/SYNC.TXT)

## host version
```
```bash
>send
000chost:version

Expand All @@ -21,7 +27,7 @@ execute adb command, e.g. `adb -P 5555 devices`, now data should be seen in char
```

## host tport device not found
```
```bash
>send
0026host:tport:serial:GBG5T197110027690014

Expand All @@ -32,7 +38,7 @@ execute adb command, e.g. `adb -P 5555 devices`, now data should be seen in char
```

## forward
```
```bash
$ adb forward --list
>send
0011host:list-forward
Expand All @@ -42,15 +48,17 @@ OKAY0020emulator-5554 tcp:5678 tcp:8765

$ adb forward --remove-all
>send
000ehost:tport:any0014host:killforward-all
000ehost:tport:any
0014host:killforward-all

<recv
00000000 4f 4b 41 59 08 00 00 00 00 00 00 00 4f 4b 41 59 OKAY OKAY
00000010 4f 4b 41 59 OKAY

$ adb -s emulator-5554 forward tcp:1234 tcp:4321
>send
001fhost:tport:serial:emulator-5554001ehost:forward:tcp:1234;tcp:4321
001fhost:tport:serial:emulator-5554
001ehost:forward:tcp:1234;tcp:4321

<recv
00000000 4f 4b 41 59 08 00 00 00 00 00 00 00 4f 4b 41 59 OKAY OKAY
Expand All @@ -71,7 +79,7 @@ reverse --list list all reverse socket connections from device
reverse --remove-all remove all reverse socket connections from device
```

```
```bash
$ adb reverse --list
>send
0022host:tport:serial:GBG5T197110027690014
Expand Down

0 comments on commit 4cc083c

Please sign in to comment.