Skip to content

Commit

Permalink
cli: refactor hilda remote usage
Browse files Browse the repository at this point in the history
  • Loading branch information
doronz88 committed Jan 14, 2024
1 parent 389a045 commit b580e66
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 33 deletions.
14 changes: 2 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,14 @@ Please note the following:

From this point the flow diverges into 2 flows:

### The connected device is connected to the network via `internet sharing` with your computer
### The connected device is connected via network

Run the following command:

```shell
hilda remote PROCESS_NAME SSH_PORT
hilda remote HOSTNAME PORT
```

### The connected device is connected via Wi-Fi

For this to work, you will need to make sure of the following:

* Find your cellphone IP address (Settings -> Wi-Fi -> network info -> IP Address).
* Once you found it, run the following command:
```shell
hilda remote PROCESS_NAME SSH_PORT --hostname <DEVICE_IP_ADDRESS>
```

## Usage

Upon starting Hilda shell, you are greeted with:
Expand Down
28 changes: 7 additions & 21 deletions hilda/launch_lldb.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
import os
import time
from pathlib import Path
from typing import Optional

Expand All @@ -19,10 +18,6 @@ def disable_logs() -> None:
logging.getLogger('blib2to3.pgen2.driver').disabled = True


def tunnel_local_port(port: int) -> None:
execute(f'python3 -m pymobiledevice3 usbmux forward {port} {port} -d')


def execute(cmd: str) -> None:
logging.debug(f'executing: {cmd}')
return os.system(cmd)
Expand All @@ -33,16 +28,9 @@ def cli():
pass


def start_remote(debug_port: int, ssh_port: int, process: str, hostname: str, rc_script: str) -> None:
tunnel_local_port(debug_port)
assert not execute(
f'ssh -i ~/.ssh/id_rsa -p {ssh_port} root@{hostname} "debugserver 0.0.0.0:{debug_port} --attach={process}"&')

# wait for it to load
time.sleep(1)

def start_remote(hostname: str, port: int, rc_script: str) -> None:
# connect local LLDB client
commands = [f'process connect connect://{hostname}:{debug_port}',
commands = [f'process connect connect://{hostname}:{port}',
f'command script import {rc_script}']
commands = '\n'.join(commands)
execute(f'lldb --one-line "{commands}"')
Expand All @@ -68,13 +56,11 @@ def attach(name: Optional[str] = None, pid: Optional[int] = None, rc_script: Opt


@cli.command('remote')
@click.argument('process')
@click.argument('ssh_port', type=click.INT)
@click.option('--debug-port', type=click.INT, default=1234)
@click.option('--hostname', default='localhost')
def remote(process, ssh_port, debug_port, hostname):
""" Start debugserver at remote device and connect using lldb """
start_remote(debug_port, ssh_port, process, hostname, Path(__file__).resolve().parent / 'lldb_entrypoint.py')
@click.argument('hostname', default='localhost')
@click.argument('port', type=click.INT, default=1234)
def remote(hostname: str, port: int) -> None:
""" Connect to remote debugserver at given address """
start_remote(hostname, port, Path(__file__).resolve().parent / 'lldb_entrypoint.py')


@cli.command('bare')
Expand Down

0 comments on commit b580e66

Please sign in to comment.