Compare commits
52 Commits
v2.0.6
...
up-session
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
849f7807a9 | ||
|
|
39a7f0a8cf | ||
|
|
4129d9d218 | ||
|
|
c23dca61d7 | ||
|
|
2bc338fdf5 | ||
|
|
728fb7da95 | ||
|
|
2e762400e5 | ||
|
|
c85c76228d | ||
|
|
e91a35b3ff | ||
|
|
8f979eff91 | ||
|
|
af51584736 | ||
|
|
864bde01f6 | ||
|
|
8361a0fe06 | ||
|
|
218ec3d679 | ||
|
|
4b817c0435 | ||
|
|
2dd30931f2 | ||
|
|
8b4602c62f | ||
|
|
e917a45670 | ||
|
|
b0303ad544 | ||
|
|
f3f95d92c2 | ||
|
|
886adfa392 | ||
|
|
cdf062c3e1 | ||
|
|
b8e3d02311 | ||
|
|
1b7efc1cc6 | ||
|
|
ad064a9f41 | ||
|
|
d0e0f46571 | ||
|
|
727f3a3eb4 | ||
|
|
ab77db5cc8 | ||
|
|
1255f2b5d6 | ||
|
|
eb04f9064c | ||
|
|
69107e2333 | ||
|
|
17bb77a472 | ||
|
|
f211023b24 | ||
|
|
728d9603dc | ||
|
|
00c387d85c | ||
|
|
79d96d4c76 | ||
|
|
dc909ceda6 | ||
|
|
cbba912483 | ||
|
|
38d8384b98 | ||
|
|
39591b6a0a | ||
|
|
775b2421ec | ||
|
|
62d16b70fb | ||
|
|
466d00e68a | ||
|
|
144072ba1b | ||
|
|
331ef95530 | ||
|
|
61408cb470 | ||
|
|
c54942f25d | ||
|
|
3feda38cc3 | ||
|
|
9002ecc0c8 | ||
|
|
5a3ac68fce | ||
|
|
5dfd30cc5b | ||
|
|
66d124475d |
38
.github/workflows/python-build.yml
vendored
Normal file
38
.github/workflows/python-build.yml
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
name: Python - Build packages & Release
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
release:
|
||||
types: [created]
|
||||
|
||||
jobs:
|
||||
build-python-packages:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Build Python stubs
|
||||
run: cargo run --bin stub_gen
|
||||
|
||||
- name: Install Python build dependencies
|
||||
run: pip install maturin==1.8.2
|
||||
|
||||
- name: Build Python packages
|
||||
run: maturin build --sdist --release -m pyadb_client/Cargo.toml
|
||||
|
||||
- name: Publish Python packages
|
||||
if: github.event_name == 'release' && github.event.action == 'created'
|
||||
run: maturin publish -m pyadb_client/Cargo.toml --non-interactive
|
||||
env:
|
||||
MATURIN_PYPI_TOKEN: ${{ secrets.MATURIN_PYPI_TOKEN }}
|
||||
|
||||
- name: "Publish GitHub artefacts"
|
||||
if: github.event_name == 'release' && github.event.action == 'created'
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
files: |
|
||||
target/wheels/pyadb_client*.whl
|
||||
target/wheels/pyadb_client*.tar.gz
|
||||
16
.github/workflows/rust-build.yml
vendored
16
.github/workflows/rust-build.yml
vendored
@@ -1,14 +1,22 @@
|
||||
name: Rust - Build
|
||||
|
||||
on: [push, pull_request]
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
jobs:
|
||||
build-release:
|
||||
name: "build-release"
|
||||
runs-on: ubuntu-latest
|
||||
build:
|
||||
name: "Build on ${{ matrix.os }}"
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Build project
|
||||
|
||||
6
.github/workflows/rust-quality.yml
vendored
6
.github/workflows/rust-quality.yml
vendored
@@ -1,6 +1,10 @@
|
||||
name: Rust - Quality
|
||||
|
||||
on: [push, pull_request]
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
86
.github/workflows/rust-release.yml
vendored
86
.github/workflows/rust-release.yml
vendored
@@ -4,47 +4,101 @@ on:
|
||||
release:
|
||||
types: [created]
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
jobs:
|
||||
create-release:
|
||||
release-linux:
|
||||
name: Linux - Build and Publish
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: "Checkout repository"
|
||||
uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: "Set up Rust"
|
||||
- name: Set up Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
override: true
|
||||
|
||||
- name: "Install dependencies"
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt update
|
||||
sudo apt install -y rpm
|
||||
cargo install cargo-deb
|
||||
cargo install cargo-generate-rpm
|
||||
|
||||
- name: "build-release"
|
||||
- name: Publish crates
|
||||
run: |
|
||||
cargo publish -p adb_client --token ${CRATES_IO_TOKEN}
|
||||
cargo publish -p adb_cli --token ${CRATES_IO_TOKEN}
|
||||
env:
|
||||
CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
|
||||
|
||||
- name: Build release
|
||||
run: cargo build --all-features --release
|
||||
|
||||
- name: "Build DEB package"
|
||||
- name: Rename binary
|
||||
run: mv target/release/adb_cli target/release/adb_cli-linux
|
||||
|
||||
- name: Build DEB package
|
||||
run: cargo deb -p adb_cli
|
||||
|
||||
- name: "Build RPM package"
|
||||
- name: Build RPM package
|
||||
run: cargo generate-rpm -p adb_cli
|
||||
|
||||
- name: "Publish GitHub artefacts"
|
||||
- name: Upload Linux artifacts
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
files: |
|
||||
target/debian/*.deb
|
||||
target/generate-rpm/*.rpm
|
||||
target/release/adb_cli
|
||||
target/release/adb_cli-linux
|
||||
|
||||
- name: "Publish crates"
|
||||
run: |
|
||||
cargo publish -p adb_client --token ${CRATES_IO_TOKEN}
|
||||
cargo publish -p adb_cli --token ${CRATES_IO_TOKEN}
|
||||
env:
|
||||
CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
|
||||
release-macos:
|
||||
name: macOS - Build Binary
|
||||
runs-on: macos-13
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
override: true
|
||||
|
||||
- name: Build release
|
||||
run: cargo build --all-features --release
|
||||
|
||||
- name: Rename binary
|
||||
run: mv target/release/adb_cli target/release/adb_cli-macos
|
||||
|
||||
- name: Upload macOS binary
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
files: target/release/adb_cli-macos
|
||||
|
||||
release-windows:
|
||||
name: Windows - Build Binary
|
||||
runs-on: windows-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
override: true
|
||||
|
||||
- name: Build release
|
||||
run: cargo build --all-features --release
|
||||
|
||||
- name: Rename binary
|
||||
run: Rename-Item -Path target/release/adb_cli.exe -NewName adb_cli-windows.exe
|
||||
|
||||
- name: Upload Windows binary
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
files: target/release/adb_cli-windows.exe
|
||||
|
||||
7
.gitignore
vendored
7
.gitignore
vendored
@@ -1,3 +1,6 @@
|
||||
target
|
||||
Cargo.lock
|
||||
.vscode
|
||||
/Cargo.lock
|
||||
/.vscode
|
||||
venv
|
||||
/.mypy_cache
|
||||
pyadb_client/pyadb_client.pyi
|
||||
@@ -1,15 +1,15 @@
|
||||
[workspace]
|
||||
members = ["adb_cli", "adb_client"]
|
||||
members = ["adb_cli", "adb_client", "pyadb_client"]
|
||||
resolver = "2"
|
||||
|
||||
[workspace.package]
|
||||
authors = ["Corentin LIAUD"]
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
homepage = "https://github.com/cocool97/adb_client"
|
||||
keywords = ["adb", "android", "tcp", "usb"]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/cocool97/adb_client"
|
||||
version = "2.0.6"
|
||||
version = "2.1.13"
|
||||
|
||||
# To build locally when working on a new release
|
||||
[patch.crates-io]
|
||||
|
||||
10
README.md
10
README.md
@@ -30,6 +30,7 @@ Main features of this library:
|
||||
- Over **TCP/IP**
|
||||
- Implements hidden `adb` features, like `framebuffer`
|
||||
- Highly configurable
|
||||
- Provides wrappers to use directly from Python code
|
||||
- Easy to use !
|
||||
|
||||
## adb_client
|
||||
@@ -41,12 +42,19 @@ Improved documentation available [here](./adb_client/README.md).
|
||||
## adb_cli
|
||||
|
||||
Rust binary providing an improved version of Google's official `adb` CLI, by using `adb_client` library.
|
||||
Provides an usage example of the library.
|
||||
Provides a "real-world" usage example of this library.
|
||||
|
||||
Improved documentation available [here](./adb_cli/README.md).
|
||||
|
||||
## pyadb_client
|
||||
|
||||
Python wrapper using `adb_client` library to export classes usable directly from a Python environment.
|
||||
|
||||
Improved documentation available [here](./pyadb_client/README.md)
|
||||
|
||||
## Related publications
|
||||
|
||||
- [Diving into ADB protocol internals (1/2)](https://www.synacktiv.com/publications/diving-into-adb-protocol-internals-12)
|
||||
- [Diving into ADB protocol internals (2/2)](https://www.synacktiv.com/publications/diving-into-adb-protocol-internals-22)
|
||||
|
||||
Some features may still be missing, all pull requests are welcome !
|
||||
|
||||
@@ -10,11 +10,11 @@ repository.workspace = true
|
||||
version.workspace = true
|
||||
|
||||
[dependencies]
|
||||
adb_client = { version = "2.0.5" }
|
||||
anyhow = { version = "1.0.89" }
|
||||
clap = { version = "4.5.18", features = ["derive"] }
|
||||
adb_client = { version = "^2.0.0" }
|
||||
anyhow = { version = "1.0.94" }
|
||||
clap = { version = "4.5.23", features = ["derive"] }
|
||||
env_logger = { version = "0.11.5" }
|
||||
log = { version = "0.4.22" }
|
||||
log = { version = "0.4.26" }
|
||||
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
termios = { version = "0.3.3" }
|
||||
|
||||
@@ -18,38 +18,29 @@ Usage is quite simple, and tends to look like `adb`:
|
||||
- To use ADB server as a proxy:
|
||||
|
||||
```bash
|
||||
user@laptop ~/adb_client (main)> adb_cli --help
|
||||
Rust ADB (Android Debug Bridge) CLI
|
||||
user@laptop ~/adb_client (main)> adb_cli local --help
|
||||
Device related commands using server
|
||||
|
||||
Usage: adb_cli [OPTIONS] <COMMAND>
|
||||
Usage: adb_cli local [OPTIONS] <COMMAND>
|
||||
|
||||
Commands:
|
||||
host-features List available server features
|
||||
push Push a file on device
|
||||
pull Pull a file from device
|
||||
list List a directory on device
|
||||
stat Stat a file specified on device
|
||||
shell Spawn an interactive shell or run a list of commands on the device
|
||||
pull Pull a file from device
|
||||
push Push a file on device
|
||||
stat Stat a file on device
|
||||
run Run an activity on device specified by the intent
|
||||
reboot Reboot the device
|
||||
install Install an APK on device
|
||||
framebuffer Dump framebuffer of device
|
||||
host-features List available server features
|
||||
list List a directory on device
|
||||
logcat Get logs of device
|
||||
version Print current ADB version
|
||||
kill Ask ADB server to quit immediately
|
||||
devices List connected devices
|
||||
track-devices Track new devices showing up
|
||||
pair Pair device with a given code
|
||||
connect Connect device over WI-FI
|
||||
disconnect Disconnect device over WI-FI
|
||||
sms Send a SMS with given phone number and given content
|
||||
rotate Rotate device screen from 90°
|
||||
help Print this message or the help of the given subcommand(s)
|
||||
|
||||
Options:
|
||||
-d, --debug
|
||||
-a, --address <ADDRESS> [default: 127.0.0.1:5037]
|
||||
-s, --serial <SERIAL> Serial id of a specific device. Every request will be sent to this device
|
||||
-h, --help Print help
|
||||
-V, --version Print version
|
||||
```
|
||||
|
||||
- To interact directly with end devices
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use std::os::unix::prelude::{AsRawFd, RawFd};
|
||||
|
||||
use termios::{tcsetattr, Termios, TCSANOW, VMIN, VTIME};
|
||||
use termios::{TCSANOW, Termios, VMIN, VTIME, tcsetattr};
|
||||
|
||||
use crate::Result;
|
||||
|
||||
@@ -36,7 +36,7 @@ impl Drop for ADBTermios {
|
||||
fn drop(&mut self) {
|
||||
// Custom drop implementation, restores previous termios structure.
|
||||
if let Err(e) = tcsetattr(self.fd, TCSANOW, &self.old_termios) {
|
||||
log::error!("Error while droping ADBTermios: {e}")
|
||||
log::error!("Error while dropping ADBTermios: {e}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
use clap::Parser;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
pub enum EmuCommand {
|
||||
/// Send a SMS with given phone number and given content
|
||||
Sms {
|
||||
phone_number: String,
|
||||
content: String,
|
||||
},
|
||||
/// Rotate device screen from 90°
|
||||
Rotate,
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
use clap::Parser;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::models::RebootTypeCommand;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
pub enum LocalCommand {
|
||||
/// List available server features.
|
||||
HostFeatures,
|
||||
/// Push a file on device
|
||||
Push { filename: String, path: String },
|
||||
/// Pull a file from device
|
||||
Pull { path: String, filename: String },
|
||||
/// List a directory on device
|
||||
List { path: String },
|
||||
/// Stat a file specified on device
|
||||
Stat { path: String },
|
||||
/// Spawn an interactive shell or run a list of commands on the device
|
||||
Shell { commands: Vec<String> },
|
||||
/// Run an activity on device specified by the intent
|
||||
Run {
|
||||
/// The package whose activity is to be invoked
|
||||
#[clap(short = 'p', long = "package")]
|
||||
package: String,
|
||||
/// The activity to be invoked itself, Usually it is MainActivity
|
||||
#[clap(short = 'a', long = "activity")]
|
||||
activity: String,
|
||||
},
|
||||
/// Reboot the device
|
||||
Reboot {
|
||||
#[clap(subcommand)]
|
||||
reboot_type: RebootTypeCommand,
|
||||
},
|
||||
/// Dump framebuffer of device
|
||||
Framebuffer { path: String },
|
||||
/// Get logs of device
|
||||
Logcat {
|
||||
/// Path to output file (created if not exists)
|
||||
path: Option<String>,
|
||||
},
|
||||
/// Install an APK on device
|
||||
Install {
|
||||
/// Path to APK file. Extension must be ".apk"
|
||||
path: PathBuf,
|
||||
},
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
mod emu;
|
||||
mod host;
|
||||
mod local;
|
||||
mod tcp;
|
||||
mod usb;
|
||||
|
||||
pub use emu::EmuCommand;
|
||||
pub use host::{HostCommand, MdnsCommand};
|
||||
pub use local::LocalCommand;
|
||||
pub use tcp::{TcpCommand, TcpCommands};
|
||||
pub use usb::{UsbCommand, UsbCommands};
|
||||
@@ -1,56 +0,0 @@
|
||||
use std::num::ParseIntError;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use clap::Parser;
|
||||
|
||||
use crate::models::RebootTypeCommand;
|
||||
|
||||
fn parse_hex_id(id: &str) -> Result<u16, ParseIntError> {
|
||||
u16::from_str_radix(id, 16)
|
||||
}
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
pub struct UsbCommand {
|
||||
/// Hexadecimal vendor id of this USB device
|
||||
#[clap(short = 'v', long = "vendor-id", value_parser=parse_hex_id, value_name="VID")]
|
||||
pub vendor_id: Option<u16>,
|
||||
/// Hexadecimal product id of this USB device
|
||||
#[clap(short = 'p', long = "product-id", value_parser=parse_hex_id, value_name="PID")]
|
||||
pub product_id: Option<u16>,
|
||||
/// Path to a custom private key to use for authentication
|
||||
#[clap(short = 'k', long = "private-key")]
|
||||
pub path_to_private_key: Option<PathBuf>,
|
||||
#[clap(subcommand)]
|
||||
pub commands: UsbCommands,
|
||||
}
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
pub enum UsbCommands {
|
||||
/// Spawn an interactive shell or run a list of commands on the device
|
||||
Shell { commands: Vec<String> },
|
||||
/// Pull a file from device
|
||||
Pull { source: String, destination: String },
|
||||
/// Push a file on device
|
||||
Push { filename: String, path: String },
|
||||
/// Stat a file on device
|
||||
Stat { path: String },
|
||||
/// Run an activity on device specified by the intent
|
||||
Run {
|
||||
/// The package whose activity is to be invoked
|
||||
#[clap(short = 'p', long = "package")]
|
||||
package: String,
|
||||
/// The activity to be invoked itself, Usually it is MainActivity
|
||||
#[clap(short = 'a', long = "activity")]
|
||||
activity: String,
|
||||
},
|
||||
/// Reboot the device
|
||||
Reboot {
|
||||
#[clap(subcommand)]
|
||||
reboot_type: RebootTypeCommand,
|
||||
},
|
||||
/// Install an APK on device
|
||||
Install {
|
||||
/// Path to APK file. Extension must be ".apk"
|
||||
path: PathBuf,
|
||||
},
|
||||
}
|
||||
20
adb_cli/src/handlers/emulator_commands.rs
Normal file
20
adb_cli/src/handlers/emulator_commands.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
use adb_client::ADBEmulatorDevice;
|
||||
|
||||
use crate::models::{EmuCommand, EmulatorCommand};
|
||||
|
||||
pub fn handle_emulator_commands(emulator_command: EmulatorCommand) -> anyhow::Result<()> {
|
||||
let mut emulator = ADBEmulatorDevice::new(emulator_command.serial, None)?;
|
||||
|
||||
match emulator_command.command {
|
||||
EmuCommand::Sms {
|
||||
phone_number,
|
||||
content,
|
||||
} => {
|
||||
emulator.send_sms(&phone_number, &content)?;
|
||||
log::info!("SMS sent to {phone_number}");
|
||||
}
|
||||
EmuCommand::Rotate => emulator.rotate()?,
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
82
adb_cli/src/handlers/host_commands.rs
Normal file
82
adb_cli/src/handlers/host_commands.rs
Normal file
@@ -0,0 +1,82 @@
|
||||
use adb_client::{ADBServer, DeviceShort, MDNSBackend, Result, WaitForDeviceState};
|
||||
|
||||
use crate::models::{HostCommand, MdnsCommand, ServerCommand};
|
||||
|
||||
pub fn handle_host_commands(server_command: ServerCommand<HostCommand>) -> Result<()> {
|
||||
let mut adb_server = ADBServer::new(server_command.address);
|
||||
|
||||
match server_command.command {
|
||||
HostCommand::Version => {
|
||||
let version = adb_server.version()?;
|
||||
log::info!("Android Debug Bridge version {}", version);
|
||||
log::info!("Package version {}-rust", std::env!("CARGO_PKG_VERSION"));
|
||||
}
|
||||
HostCommand::Kill => {
|
||||
adb_server.kill()?;
|
||||
}
|
||||
HostCommand::Devices { long } => {
|
||||
if long {
|
||||
log::info!("List of devices attached (extended)");
|
||||
for device in adb_server.devices_long()? {
|
||||
log::info!("{}", device);
|
||||
}
|
||||
} else {
|
||||
log::info!("List of devices attached");
|
||||
for device in adb_server.devices()? {
|
||||
log::info!("{}", device);
|
||||
}
|
||||
}
|
||||
}
|
||||
HostCommand::TrackDevices => {
|
||||
let callback = |device: DeviceShort| {
|
||||
log::info!("{}", device);
|
||||
Ok(())
|
||||
};
|
||||
log::info!("Live list of devices attached");
|
||||
adb_server.track_devices(callback)?;
|
||||
}
|
||||
HostCommand::Pair { address, code } => {
|
||||
adb_server.pair(address, code)?;
|
||||
log::info!("Paired device {address}");
|
||||
}
|
||||
HostCommand::Connect { address } => {
|
||||
adb_server.connect_device(address)?;
|
||||
log::info!("Connected to {address}");
|
||||
}
|
||||
HostCommand::Disconnect { address } => {
|
||||
adb_server.disconnect_device(address)?;
|
||||
log::info!("Disconnected {address}");
|
||||
}
|
||||
HostCommand::Mdns { subcommand } => match subcommand {
|
||||
MdnsCommand::Check => {
|
||||
let check = adb_server.mdns_check()?;
|
||||
let server_status = adb_server.server_status()?;
|
||||
match server_status.mdns_backend {
|
||||
MDNSBackend::Unknown => log::info!("unknown mdns backend..."),
|
||||
MDNSBackend::Bonjour => match check {
|
||||
true => log::info!("mdns daemon version [Bonjour]"),
|
||||
false => log::info!("ERROR: mdns daemon unavailable"),
|
||||
},
|
||||
MDNSBackend::OpenScreen => {
|
||||
log::info!("mdns daemon version [Openscreen discovery 0.0.0]")
|
||||
}
|
||||
}
|
||||
}
|
||||
MdnsCommand::Services => {
|
||||
log::info!("List of discovered mdns services");
|
||||
for service in adb_server.mdns_services()? {
|
||||
log::info!("{}", service);
|
||||
}
|
||||
}
|
||||
},
|
||||
HostCommand::ServerStatus => {
|
||||
log::info!("{}", adb_server.server_status()?);
|
||||
}
|
||||
HostCommand::WaitForDevice { transport } => {
|
||||
log::info!("waiting for device to be connected...");
|
||||
adb_server.wait_for_device(WaitForDeviceState::Device, transport)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
35
adb_cli/src/handlers/local_commands.rs
Normal file
35
adb_cli/src/handlers/local_commands.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
use std::{fs::File, io::Write};
|
||||
|
||||
use adb_client::ADBServerDevice;
|
||||
use anyhow::{Result, anyhow};
|
||||
|
||||
use crate::models::LocalDeviceCommand;
|
||||
|
||||
pub fn handle_local_commands(
|
||||
mut device: ADBServerDevice,
|
||||
local_device_commands: LocalDeviceCommand,
|
||||
) -> Result<()> {
|
||||
match local_device_commands {
|
||||
LocalDeviceCommand::HostFeatures => {
|
||||
let features = device
|
||||
.host_features()?
|
||||
.iter()
|
||||
.map(|v| v.to_string())
|
||||
.reduce(|a, b| format!("{a},{b}"))
|
||||
.ok_or(anyhow!("cannot list features"))?;
|
||||
log::info!("Available host features: {features}");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
LocalDeviceCommand::List { path } => Ok(device.list(path)?),
|
||||
LocalDeviceCommand::Logcat { path } => {
|
||||
let writer: Box<dyn Write> = if let Some(path) = path {
|
||||
let f = File::create(path)?;
|
||||
Box::new(f)
|
||||
} else {
|
||||
Box::new(std::io::stdout())
|
||||
};
|
||||
Ok(device.get_logs(writer)?)
|
||||
}
|
||||
}
|
||||
}
|
||||
7
adb_cli/src/handlers/mod.rs
Normal file
7
adb_cli/src/handlers/mod.rs
Normal file
@@ -0,0 +1,7 @@
|
||||
mod emulator_commands;
|
||||
mod host_commands;
|
||||
mod local_commands;
|
||||
|
||||
pub use emulator_commands::handle_emulator_commands;
|
||||
pub use host_commands::handle_host_commands;
|
||||
pub use local_commands::handle_local_commands;
|
||||
@@ -3,334 +3,86 @@
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
mod adb_termios;
|
||||
|
||||
mod commands;
|
||||
mod handlers;
|
||||
mod models;
|
||||
mod utils;
|
||||
|
||||
use adb_client::{
|
||||
ADBDeviceExt, ADBEmulatorDevice, ADBServer, ADBTcpDevice, ADBUSBDevice, DeviceShort,
|
||||
MDNSBackend, MDNSDiscoveryService,
|
||||
ADBDeviceExt, ADBServer, ADBServerDevice, ADBTcpDevice, ADBUSBDevice, MDNSDiscoveryService,
|
||||
};
|
||||
use anyhow::{anyhow, Result};
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
use adb_termios::ADBTermios;
|
||||
|
||||
use anyhow::Result;
|
||||
use clap::Parser;
|
||||
use commands::{EmuCommand, HostCommand, LocalCommand, MdnsCommand, TcpCommands, UsbCommands};
|
||||
use models::{Command, Opts};
|
||||
use handlers::{handle_emulator_commands, handle_host_commands, handle_local_commands};
|
||||
use models::{DeviceCommands, LocalCommand, MainCommand, Opts};
|
||||
use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
use utils::setup_logger;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
// This depends on `clap`
|
||||
let opts = Opts::parse();
|
||||
|
||||
// RUST_LOG variable has more priority then "--debug" flag
|
||||
if std::env::var("RUST_LOG").is_err() {
|
||||
let level = match opts.debug {
|
||||
true => "trace",
|
||||
false => "info",
|
||||
};
|
||||
// SAFETY:
|
||||
// We are assuming the entire process is single-threaded
|
||||
// at this point.
|
||||
// This seems true for the current version of `clap`,
|
||||
// but there's no guarantee for future updates
|
||||
unsafe { setup_logger(opts.debug) };
|
||||
|
||||
std::env::set_var("RUST_LOG", level);
|
||||
}
|
||||
// Directly handling methods / commands that aren't linked to [`ADBDeviceExt`] trait.
|
||||
// Other methods just have to create a concrete [`ADBDeviceExt`] instance, and return it.
|
||||
// This instance will then be used to execute desired command.
|
||||
let (mut device, commands) = match opts.command {
|
||||
MainCommand::Host(server_command) => return Ok(handle_host_commands(server_command)?),
|
||||
MainCommand::Emu(emulator_command) => return handle_emulator_commands(emulator_command),
|
||||
MainCommand::Local(server_command) => {
|
||||
// Must start server to communicate with device, but only if this is a local one.
|
||||
let server_address_ip = server_command.address.ip();
|
||||
if server_address_ip.is_loopback() || server_address_ip.is_unspecified() {
|
||||
ADBServer::start(&HashMap::default(), &None);
|
||||
}
|
||||
|
||||
// Setting default log level as "info" if not set
|
||||
if std::env::var("RUST_LOG").is_err() {
|
||||
std::env::set_var("RUST_LOG", "info");
|
||||
}
|
||||
env_logger::init();
|
||||
|
||||
match opts.command {
|
||||
Command::Local(local) => {
|
||||
let mut adb_server = ADBServer::new(opts.address);
|
||||
|
||||
let mut device = match opts.serial {
|
||||
Some(serial) => adb_server.get_device_by_name(&serial)?,
|
||||
None => adb_server.get_device()?,
|
||||
let device = match server_command.serial {
|
||||
Some(serial) => ADBServerDevice::new(serial, Some(server_command.address)),
|
||||
None => ADBServerDevice::autodetect(Some(server_command.address)),
|
||||
};
|
||||
|
||||
match local {
|
||||
LocalCommand::Pull { path, filename } => {
|
||||
let mut output = File::create(Path::new(&filename))?;
|
||||
device.pull(&path, &mut output)?;
|
||||
log::info!("Downloaded {path} as {filename}");
|
||||
}
|
||||
LocalCommand::Push { filename, path } => {
|
||||
let mut input = File::open(Path::new(&filename))?;
|
||||
device.push(&mut input, &path)?;
|
||||
log::info!("Uploaded {filename} to {path}");
|
||||
}
|
||||
LocalCommand::List { path } => {
|
||||
device.list(path)?;
|
||||
}
|
||||
LocalCommand::Stat { path } => {
|
||||
let stat_response = device.stat(path)?;
|
||||
println!("{}", stat_response);
|
||||
}
|
||||
LocalCommand::Shell { commands } => {
|
||||
if commands.is_empty() {
|
||||
// Need to duplicate some code here as ADBTermios [Drop] implementation resets terminal state.
|
||||
// Using a scope here would call drop() too early..
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
{
|
||||
let mut adb_termios = adb_termios::ADBTermios::new(std::io::stdin())?;
|
||||
adb_termios.set_adb_termios()?;
|
||||
device.shell(std::io::stdin(), std::io::stdout())?;
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
|
||||
{
|
||||
device.shell(std::io::stdin(), std::io::stdout())?;
|
||||
}
|
||||
} else {
|
||||
device.shell_command(commands, std::io::stdout())?;
|
||||
}
|
||||
}
|
||||
LocalCommand::Run { package, activity } => {
|
||||
let output = device.run_activity(&package, &activity)?;
|
||||
std::io::stdout().write_all(&output)?;
|
||||
}
|
||||
LocalCommand::HostFeatures => {
|
||||
let features = device
|
||||
.host_features()?
|
||||
.iter()
|
||||
.map(|v| v.to_string())
|
||||
.reduce(|a, b| format!("{a},{b}"))
|
||||
.ok_or(anyhow!("cannot list features"))?;
|
||||
log::info!("Available host features: {features}");
|
||||
}
|
||||
LocalCommand::Reboot { reboot_type } => {
|
||||
log::info!("Reboots device in mode {:?}", reboot_type);
|
||||
device.reboot(reboot_type.into())?
|
||||
}
|
||||
LocalCommand::Framebuffer { path } => {
|
||||
device.framebuffer(&path)?;
|
||||
log::info!("Framebuffer dropped: {path}");
|
||||
}
|
||||
LocalCommand::Logcat { path } => {
|
||||
let writer: Box<dyn Write> = if let Some(path) = path {
|
||||
let f = File::create(path)?;
|
||||
Box::new(f)
|
||||
} else {
|
||||
Box::new(std::io::stdout())
|
||||
};
|
||||
device.get_logs(writer)?;
|
||||
}
|
||||
LocalCommand::Install { path } => {
|
||||
log::info!("Starting installation of APK {}...", path.display());
|
||||
device.install(path)?;
|
||||
match server_command.command {
|
||||
LocalCommand::DeviceCommands(device_commands) => (device.boxed(), device_commands),
|
||||
LocalCommand::LocalDeviceCommand(local_device_command) => {
|
||||
return handle_local_commands(device, local_device_command);
|
||||
}
|
||||
}
|
||||
}
|
||||
Command::Host(host) => {
|
||||
let mut adb_server = ADBServer::new(opts.address);
|
||||
|
||||
match host {
|
||||
HostCommand::Version => {
|
||||
let version = adb_server.version()?;
|
||||
log::info!("Android Debug Bridge version {}", version);
|
||||
log::info!("Package version {}-rust", std::env!("CARGO_PKG_VERSION"));
|
||||
}
|
||||
HostCommand::Kill => {
|
||||
adb_server.kill()?;
|
||||
}
|
||||
HostCommand::Devices { long } => {
|
||||
if long {
|
||||
log::info!("List of devices attached (extended)");
|
||||
for device in adb_server.devices_long()? {
|
||||
log::info!("{}", device);
|
||||
}
|
||||
} else {
|
||||
log::info!("List of devices attached");
|
||||
for device in adb_server.devices()? {
|
||||
log::info!("{}", device);
|
||||
}
|
||||
}
|
||||
}
|
||||
HostCommand::TrackDevices => {
|
||||
let callback = |device: DeviceShort| {
|
||||
log::info!("{}", device);
|
||||
Ok(())
|
||||
};
|
||||
log::info!("Live list of devices attached");
|
||||
adb_server.track_devices(callback)?;
|
||||
}
|
||||
HostCommand::Pair { address, code } => {
|
||||
adb_server.pair(address, code)?;
|
||||
log::info!("Paired device {address}");
|
||||
}
|
||||
HostCommand::Connect { address } => {
|
||||
adb_server.connect_device(address)?;
|
||||
log::info!("Connected to {address}");
|
||||
}
|
||||
HostCommand::Disconnect { address } => {
|
||||
adb_server.disconnect_device(address)?;
|
||||
log::info!("Disconnected {address}");
|
||||
}
|
||||
HostCommand::Mdns { subcommand } => match subcommand {
|
||||
MdnsCommand::Check => {
|
||||
let check = adb_server.mdns_check()?;
|
||||
let server_status = adb_server.server_status()?;
|
||||
match server_status.mdns_backend {
|
||||
MDNSBackend::Unknown => log::info!("unknown mdns backend..."),
|
||||
MDNSBackend::Bonjour => match check {
|
||||
true => log::info!("mdns daemon version [Bonjour]"),
|
||||
false => log::info!("ERROR: mdns daemon unavailable"),
|
||||
},
|
||||
MDNSBackend::OpenScreen => {
|
||||
log::info!("mdns daemon version [Openscreen discovery 0.0.0]")
|
||||
}
|
||||
}
|
||||
}
|
||||
MdnsCommand::Services => {
|
||||
log::info!("List of discovered mdns services");
|
||||
for service in adb_server.mdns_services()? {
|
||||
log::info!("{}", service);
|
||||
}
|
||||
}
|
||||
},
|
||||
HostCommand::ServerStatus => {
|
||||
log::info!("{}", adb_server.server_status()?);
|
||||
}
|
||||
}
|
||||
}
|
||||
Command::Emu(emu) => {
|
||||
let mut emulator = match opts.serial {
|
||||
Some(serial) => ADBEmulatorDevice::new(serial, None)?,
|
||||
None => return Err(anyhow!("Serial must be set to use emulators !")),
|
||||
};
|
||||
|
||||
match emu {
|
||||
EmuCommand::Sms {
|
||||
phone_number,
|
||||
content,
|
||||
} => {
|
||||
emulator.send_sms(&phone_number, &content)?;
|
||||
log::info!("SMS sent to {phone_number}");
|
||||
}
|
||||
EmuCommand::Rotate => emulator.rotate()?,
|
||||
}
|
||||
}
|
||||
Command::Usb(usb) => {
|
||||
let mut device = match (usb.vendor_id, usb.product_id) {
|
||||
(Some(vid), Some(pid)) => match usb.path_to_private_key {
|
||||
MainCommand::Usb(usb_command) => {
|
||||
let device = match (usb_command.vendor_id, usb_command.product_id) {
|
||||
(Some(vid), Some(pid)) => match usb_command.path_to_private_key {
|
||||
Some(pk) => ADBUSBDevice::new_with_custom_private_key(vid, pid, pk)?,
|
||||
None => ADBUSBDevice::new(vid, pid)?,
|
||||
},
|
||||
|
||||
(None, None) => match usb.path_to_private_key {
|
||||
(None, None) => match usb_command.path_to_private_key {
|
||||
Some(pk) => ADBUSBDevice::autodetect_with_custom_private_key(pk)?,
|
||||
None => ADBUSBDevice::autodetect()?,
|
||||
},
|
||||
|
||||
_ => {
|
||||
anyhow::bail!("please either supply values for both the --vendor-id and --product-id flags or none.");
|
||||
anyhow::bail!(
|
||||
"please either supply values for both the --vendor-id and --product-id flags or none."
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
match usb.commands {
|
||||
UsbCommands::Shell { commands } => {
|
||||
if commands.is_empty() {
|
||||
// Need to duplicate some code here as ADBTermios [Drop] implementation resets terminal state.
|
||||
// Using a scope here would call drop() too early..
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
{
|
||||
let mut adb_termios = adb_termios::ADBTermios::new(std::io::stdin())?;
|
||||
adb_termios.set_adb_termios()?;
|
||||
device.shell(std::io::stdin(), std::io::stdout())?;
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
|
||||
{
|
||||
device.shell(std::io::stdin(), std::io::stdout())?;
|
||||
}
|
||||
} else {
|
||||
device.shell_command(commands, std::io::stdout())?;
|
||||
}
|
||||
}
|
||||
UsbCommands::Pull {
|
||||
source,
|
||||
destination,
|
||||
} => {
|
||||
let mut output = File::create(Path::new(&destination))?;
|
||||
device.pull(&source, &mut output)?;
|
||||
log::info!("Downloaded {source} as {destination}");
|
||||
}
|
||||
UsbCommands::Stat { path } => {
|
||||
let stat_response = device.stat(&path)?;
|
||||
println!("{}", stat_response);
|
||||
}
|
||||
UsbCommands::Reboot { reboot_type } => {
|
||||
log::info!("Reboots device in mode {:?}", reboot_type);
|
||||
device.reboot(reboot_type.into())?
|
||||
}
|
||||
UsbCommands::Push { filename, path } => {
|
||||
let mut input = File::open(Path::new(&filename))?;
|
||||
device.push(&mut input, &path)?;
|
||||
log::info!("Uploaded {filename} to {path}");
|
||||
}
|
||||
UsbCommands::Run { package, activity } => {
|
||||
let output = device.run_activity(&package, &activity)?;
|
||||
std::io::stdout().write_all(&output)?;
|
||||
}
|
||||
UsbCommands::Install { path } => {
|
||||
log::info!("Starting installation of APK {}...", path.display());
|
||||
device.install(path)?;
|
||||
}
|
||||
}
|
||||
(device.boxed(), usb_command.commands)
|
||||
}
|
||||
Command::Tcp(tcp) => {
|
||||
let mut device = ADBTcpDevice::new(tcp.address)?;
|
||||
|
||||
match tcp.commands {
|
||||
TcpCommands::Shell { commands } => {
|
||||
if commands.is_empty() {
|
||||
// Need to duplicate some code here as ADBTermios [Drop] implementation resets terminal state.
|
||||
// Using a scope here would call drop() too early..
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
{
|
||||
let mut adb_termios = adb_termios::ADBTermios::new(std::io::stdin())?;
|
||||
adb_termios.set_adb_termios()?;
|
||||
device.shell(std::io::stdin(), std::io::stdout())?;
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
|
||||
{
|
||||
device.shell(std::io::stdin(), std::io::stdout())?;
|
||||
}
|
||||
} else {
|
||||
device.shell_command(commands, std::io::stdout())?;
|
||||
}
|
||||
}
|
||||
TcpCommands::Pull {
|
||||
source,
|
||||
destination,
|
||||
} => {
|
||||
let mut output = File::create(Path::new(&destination))?;
|
||||
device.pull(&source, &mut output)?;
|
||||
log::info!("Downloaded {source} as {destination}");
|
||||
}
|
||||
TcpCommands::Stat { path } => {
|
||||
let stat_response = device.stat(&path)?;
|
||||
println!("{}", stat_response);
|
||||
}
|
||||
TcpCommands::Reboot { reboot_type } => {
|
||||
log::info!("Reboots device in mode {:?}", reboot_type);
|
||||
device.reboot(reboot_type.into())?
|
||||
}
|
||||
TcpCommands::Push { filename, path } => {
|
||||
let mut input = File::open(Path::new(&filename))?;
|
||||
device.push(&mut input, &path)?;
|
||||
log::info!("Uploaded {filename} to {path}");
|
||||
}
|
||||
TcpCommands::Run { package, activity } => {
|
||||
let output = device.run_activity(&package, &activity)?;
|
||||
std::io::stdout().write_all(&output)?;
|
||||
}
|
||||
TcpCommands::Install { path } => {
|
||||
log::info!("Starting installation of APK {}...", path.display());
|
||||
device.install(path)?;
|
||||
}
|
||||
}
|
||||
MainCommand::Tcp(tcp_command) => {
|
||||
let device = ADBTcpDevice::new(tcp_command.address)?;
|
||||
(device.boxed(), tcp_command.commands)
|
||||
}
|
||||
Command::MdnsDiscovery => {
|
||||
MainCommand::Mdns => {
|
||||
let mut service = MDNSDiscoveryService::new()?;
|
||||
|
||||
let (tx, rx) = std::sync::mpsc::channel();
|
||||
@@ -345,7 +97,67 @@ fn main() -> Result<()> {
|
||||
)
|
||||
}
|
||||
|
||||
service.shutdown()?;
|
||||
return Ok(service.shutdown()?);
|
||||
}
|
||||
};
|
||||
|
||||
match commands {
|
||||
DeviceCommands::Shell { commands } => {
|
||||
if commands.is_empty() {
|
||||
// Need to duplicate some code here as ADBTermios [Drop] implementation resets terminal state.
|
||||
// Using a scope here would call drop() too early..
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
{
|
||||
let mut adb_termios = ADBTermios::new(std::io::stdin())?;
|
||||
adb_termios.set_adb_termios()?;
|
||||
device.shell(&mut std::io::stdin(), Box::new(std::io::stdout()))?;
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
|
||||
{
|
||||
device.shell(&mut std::io::stdin(), Box::new(std::io::stdout()))?;
|
||||
}
|
||||
} else {
|
||||
let commands: Vec<&str> = commands.iter().map(|v| v.as_str()).collect();
|
||||
device.shell_command(&commands, &mut std::io::stdout())?;
|
||||
}
|
||||
}
|
||||
DeviceCommands::Pull {
|
||||
source,
|
||||
destination,
|
||||
} => {
|
||||
let mut output = File::create(Path::new(&destination))?;
|
||||
device.pull(&source, &mut output)?;
|
||||
log::info!("Downloaded {source} as {destination}");
|
||||
}
|
||||
DeviceCommands::Stat { path } => {
|
||||
let stat_response = device.stat(&path)?;
|
||||
println!("{}", stat_response);
|
||||
}
|
||||
DeviceCommands::Reboot { reboot_type } => {
|
||||
log::info!("Reboots device in mode {:?}", reboot_type);
|
||||
device.reboot(reboot_type.into())?
|
||||
}
|
||||
DeviceCommands::Push { filename, path } => {
|
||||
let mut input = File::open(Path::new(&filename))?;
|
||||
device.push(&mut input, &path)?;
|
||||
log::info!("Uploaded {filename} to {path}");
|
||||
}
|
||||
DeviceCommands::Run { package, activity } => {
|
||||
let output = device.run_activity(&package, &activity)?;
|
||||
std::io::stdout().write_all(&output)?;
|
||||
}
|
||||
DeviceCommands::Install { path } => {
|
||||
log::info!("Starting installation of APK {}...", path.display());
|
||||
device.install(&path)?;
|
||||
}
|
||||
DeviceCommands::Uninstall { package } => {
|
||||
log::info!("Uninstalling the package {}...", package);
|
||||
device.uninstall(&package)?;
|
||||
}
|
||||
DeviceCommands::Framebuffer { path } => {
|
||||
device.framebuffer(&path)?;
|
||||
log::info!("Successfully dumped framebuffer at path {path}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,11 @@
|
||||
use std::net::SocketAddr;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use clap::Parser;
|
||||
|
||||
use crate::models::RebootTypeCommand;
|
||||
use super::RebootTypeCommand;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
pub struct TcpCommand {
|
||||
pub address: SocketAddr,
|
||||
#[clap(subcommand)]
|
||||
pub commands: TcpCommands,
|
||||
}
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
pub enum TcpCommands {
|
||||
pub enum DeviceCommands {
|
||||
/// Spawn an interactive shell or run a list of commands on the device
|
||||
Shell { commands: Vec<String> },
|
||||
/// Pull a file from device
|
||||
@@ -41,4 +33,14 @@ pub enum TcpCommands {
|
||||
/// Path to APK file. Extension must be ".apk"
|
||||
path: PathBuf,
|
||||
},
|
||||
/// Uninstall a package from the device
|
||||
Uninstall {
|
||||
/// Name of the package to uninstall
|
||||
package: String,
|
||||
},
|
||||
/// Dump framebuffer of device
|
||||
Framebuffer {
|
||||
/// Framebuffer image destination path
|
||||
path: String,
|
||||
},
|
||||
}
|
||||
20
adb_cli/src/models/emu.rs
Normal file
20
adb_cli/src/models/emu.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
use clap::{Parser, Subcommand};
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct EmulatorCommand {
|
||||
#[clap(short = 's', long = "serial")]
|
||||
pub serial: String,
|
||||
#[clap(subcommand)]
|
||||
pub command: EmuCommand,
|
||||
}
|
||||
|
||||
#[derive(Debug, Subcommand)]
|
||||
pub enum EmuCommand {
|
||||
/// Send a SMS with given phone number and given content
|
||||
Sms {
|
||||
phone_number: String,
|
||||
content: String,
|
||||
},
|
||||
/// Rotate device screen from 90°
|
||||
Rotate,
|
||||
}
|
||||
@@ -1,7 +1,14 @@
|
||||
use std::net::SocketAddrV4;
|
||||
|
||||
use adb_client::{RustADBError, WaitForDeviceTransport};
|
||||
use clap::Parser;
|
||||
|
||||
fn parse_wait_for_device_device_transport(
|
||||
value: &str,
|
||||
) -> Result<WaitForDeviceTransport, RustADBError> {
|
||||
WaitForDeviceTransport::try_from(value)
|
||||
}
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
pub enum HostCommand {
|
||||
/// Print current ADB version.
|
||||
@@ -28,6 +35,12 @@ pub enum HostCommand {
|
||||
},
|
||||
/// Display server status
|
||||
ServerStatus,
|
||||
/// Wait for a device, on optionally given transport
|
||||
WaitForDevice {
|
||||
/// Transport on which wait for devices
|
||||
#[clap(short = 't', long = "transport", value_parser = parse_wait_for_device_device_transport)]
|
||||
transport: Option<WaitForDeviceTransport>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
24
adb_cli/src/models/local.rs
Normal file
24
adb_cli/src/models/local.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
use clap::Parser;
|
||||
|
||||
use super::DeviceCommands;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
pub enum LocalCommand {
|
||||
#[clap(flatten)]
|
||||
DeviceCommands(DeviceCommands),
|
||||
#[clap(flatten)]
|
||||
LocalDeviceCommand(LocalDeviceCommand),
|
||||
}
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
pub enum LocalDeviceCommand {
|
||||
/// List available server features.
|
||||
HostFeatures,
|
||||
/// List a directory on device
|
||||
List { path: String },
|
||||
/// Get logs of device
|
||||
Logcat {
|
||||
/// Path to output file (created if not exists)
|
||||
path: Option<String>,
|
||||
},
|
||||
}
|
||||
@@ -1,5 +1,17 @@
|
||||
mod device;
|
||||
mod emu;
|
||||
mod host;
|
||||
mod local;
|
||||
mod opts;
|
||||
mod reboot_type;
|
||||
mod tcp;
|
||||
mod usb;
|
||||
|
||||
pub use opts::{Command, Opts};
|
||||
pub use device::DeviceCommands;
|
||||
pub use emu::{EmuCommand, EmulatorCommand};
|
||||
pub use host::{HostCommand, MdnsCommand};
|
||||
pub use local::{LocalCommand, LocalDeviceCommand};
|
||||
pub use opts::{MainCommand, Opts, ServerCommand};
|
||||
pub use reboot_type::RebootTypeCommand;
|
||||
pub use tcp::TcpCommand;
|
||||
pub use usb::UsbCommand;
|
||||
|
||||
@@ -1,36 +1,41 @@
|
||||
use std::net::SocketAddrV4;
|
||||
|
||||
use clap::Parser;
|
||||
use clap::{Parser, Subcommand};
|
||||
|
||||
use crate::commands::{EmuCommand, HostCommand, LocalCommand, TcpCommand, UsbCommand};
|
||||
use super::{EmulatorCommand, HostCommand, LocalCommand, TcpCommand, UsbCommand};
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[derive(Debug, Parser)]
|
||||
#[clap(about, version, author)]
|
||||
pub struct Opts {
|
||||
#[clap(long = "debug")]
|
||||
pub debug: bool,
|
||||
#[clap(subcommand)]
|
||||
pub command: MainCommand,
|
||||
}
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
pub enum MainCommand {
|
||||
/// Server related commands
|
||||
Host(ServerCommand<HostCommand>),
|
||||
/// Device related commands using server
|
||||
Local(ServerCommand<LocalCommand>),
|
||||
/// Emulator related commands
|
||||
Emu(EmulatorCommand),
|
||||
/// USB device related commands
|
||||
Usb(UsbCommand),
|
||||
/// TCP device related commands
|
||||
Tcp(TcpCommand),
|
||||
/// MDNS discovery related commands
|
||||
Mdns,
|
||||
}
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct ServerCommand<T: Subcommand> {
|
||||
#[clap(short = 'a', long = "address", default_value = "127.0.0.1:5037")]
|
||||
pub address: SocketAddrV4,
|
||||
/// Serial id of a specific device. Every request will be sent to this device.
|
||||
#[clap(short = 's', long = "serial")]
|
||||
pub serial: Option<String>,
|
||||
#[clap(subcommand)]
|
||||
pub command: Command,
|
||||
}
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
pub enum Command {
|
||||
#[clap(flatten)]
|
||||
Local(LocalCommand),
|
||||
#[clap(flatten)]
|
||||
Host(HostCommand),
|
||||
/// Emulator specific commands
|
||||
#[clap(subcommand)]
|
||||
Emu(EmuCommand),
|
||||
/// Device commands via USB, no server needed
|
||||
Usb(UsbCommand),
|
||||
/// Device commands via TCP, no server needed
|
||||
Tcp(TcpCommand),
|
||||
/// Discover devices over MDNS without using adb-server
|
||||
MdnsDiscovery,
|
||||
pub command: T,
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ pub enum RebootTypeCommand {
|
||||
Recovery,
|
||||
Sideload,
|
||||
SideloadAutoReboot,
|
||||
Fastboot,
|
||||
}
|
||||
|
||||
impl From<RebootTypeCommand> for RebootType {
|
||||
@@ -18,6 +19,7 @@ impl From<RebootTypeCommand> for RebootType {
|
||||
RebootTypeCommand::Recovery => RebootType::Recovery,
|
||||
RebootTypeCommand::Sideload => RebootType::Sideload,
|
||||
RebootTypeCommand::SideloadAutoReboot => RebootType::SideloadAutoReboot,
|
||||
RebootTypeCommand::Fastboot => RebootType::Fastboot,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
11
adb_cli/src/models/tcp.rs
Normal file
11
adb_cli/src/models/tcp.rs
Normal file
@@ -0,0 +1,11 @@
|
||||
use clap::Parser;
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use super::DeviceCommands;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
pub struct TcpCommand {
|
||||
pub address: SocketAddr,
|
||||
#[clap(subcommand)]
|
||||
pub commands: DeviceCommands,
|
||||
}
|
||||
25
adb_cli/src/models/usb.rs
Normal file
25
adb_cli/src/models/usb.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
use std::num::ParseIntError;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use clap::Parser;
|
||||
|
||||
use super::DeviceCommands;
|
||||
|
||||
fn parse_hex_id(id: &str) -> Result<u16, ParseIntError> {
|
||||
u16::from_str_radix(id, 16)
|
||||
}
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
pub struct UsbCommand {
|
||||
/// Hexadecimal vendor id of this USB device
|
||||
#[clap(short = 'v', long = "vendor-id", value_parser=parse_hex_id, value_name="VID")]
|
||||
pub vendor_id: Option<u16>,
|
||||
/// Hexadecimal product id of this USB device
|
||||
#[clap(short = 'p', long = "product-id", value_parser=parse_hex_id, value_name="PID")]
|
||||
pub product_id: Option<u16>,
|
||||
/// Path to a custom private key to use for authentication
|
||||
#[clap(short = 'k', long = "private-key")]
|
||||
pub path_to_private_key: Option<PathBuf>,
|
||||
#[clap(subcommand)]
|
||||
pub commands: DeviceCommands,
|
||||
}
|
||||
17
adb_cli/src/utils.rs
Normal file
17
adb_cli/src/utils.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
/// # Safety
|
||||
///
|
||||
/// This conditionally mutates the process' environment.
|
||||
/// See [`std::env::set_var`] for more info.
|
||||
pub unsafe fn setup_logger(debug: bool) {
|
||||
// RUST_LOG variable has more priority then "--debug" flag
|
||||
if std::env::var("RUST_LOG").is_err() {
|
||||
let level = match debug {
|
||||
true => "trace",
|
||||
false => "info",
|
||||
};
|
||||
|
||||
unsafe { std::env::set_var("RUST_LOG", level) };
|
||||
}
|
||||
|
||||
env_logger::init();
|
||||
}
|
||||
@@ -13,30 +13,34 @@ version.workspace = true
|
||||
base64 = { version = "0.22.1" }
|
||||
bincode = { version = "1.3.3" }
|
||||
byteorder = { version = "1.5.0" }
|
||||
chrono = { version = "0.4.38" }
|
||||
chrono = { version = "0.4.40", default-features = false, features = ["std"] }
|
||||
homedir = { version = "0.3.4" }
|
||||
image = { version = "0.25.5" }
|
||||
lazy_static = { version = "1.5.0" }
|
||||
log = { version = "0.4.22" }
|
||||
mdns-sd = { version = "0.12.0" }
|
||||
image = { version = "0.25.5", default-features = false }
|
||||
log = { version = "0.4.26" }
|
||||
mdns-sd = { version = "0.13.9", default-features = false, features = [
|
||||
"logging",
|
||||
] }
|
||||
num-bigint = { version = "0.8.4", package = "num-bigint-dig" }
|
||||
num-traits = { version = "0.2.19" }
|
||||
quick-protobuf = { version = "0.8.1" }
|
||||
rand = { version = "0.8.5" }
|
||||
rcgen = { version = "0.13.1" }
|
||||
regex = { version = "1.11.0", features = ["perf", "std", "unicode"] }
|
||||
rand = { version = "0.9.0" }
|
||||
rcgen = { version = "0.13.1", default-features = false, features = [
|
||||
"aws_lc_rs",
|
||||
"pem",
|
||||
] }
|
||||
regex = { version = "1.11.1", features = ["perf", "std", "unicode"] }
|
||||
rsa = { version = "0.9.7" }
|
||||
rusb = { version = "0.9.4", features = ["vendored"] }
|
||||
rustls = { version = "0.23.18" }
|
||||
rustls-pki-types = "1.10.0"
|
||||
serde = { version = "1.0.210", features = ["derive"] }
|
||||
rustls = { version = "0.23.27" }
|
||||
rustls-pki-types = { version = "1.11.0" }
|
||||
serde = { version = "1.0.216", features = ["derive"] }
|
||||
serde_repr = { version = "0.1.19" }
|
||||
sha1 = { version = "0.10.6", features = ["oid"] }
|
||||
thiserror = { version = "2.0.1" }
|
||||
thiserror = { version = "2.0.7" }
|
||||
|
||||
[dev-dependencies]
|
||||
anyhow = { version = "1.0.93" }
|
||||
criterion = { version = "0.5.1" } # Used for benchmarks
|
||||
criterion = { version = "0.6.0" } # Used for benchmarks
|
||||
|
||||
[[bench]]
|
||||
harness = false
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
[](./LICENSE-MIT)
|
||||
[](https://docs.rs/adb_client)
|
||||

|
||||
[](https://crates.io/crates/adb_client)
|
||||
|
||||
Rust library implementing ADB protocol.
|
||||
|
||||
@@ -15,6 +15,20 @@ Add `adb_client` crate as a dependency by simply adding it to your `Cargo.toml`:
|
||||
adb_client = "*"
|
||||
```
|
||||
|
||||
## Benchmarks
|
||||
|
||||
Benchmarks run on `v2.0.6`, on a **Samsung S10 SM-G973F** device and an **Intel i7-1265U** CPU laptop
|
||||
|
||||
### `ADBServerDevice` push vs `adb push`
|
||||
|
||||
`ADBServerDevice` performs all operations by using adb server as a bridge.
|
||||
|
||||
|File size|Sample size|`ADBServerDevice`|`adb`|Difference|
|
||||
|:-------:|:---------:|:----------:|:---:|:-----:|
|
||||
|10 MB|100|350,79 ms|356,30 ms|<div style="color:green">-1,57 %</div>|
|
||||
|500 MB|50|15,60 s|15,64 s|<div style="color:green">-0,25 %</div>|
|
||||
|1 GB|20|31,09 s|31,12 s|<div style="color:green">-0,10 %</div>|
|
||||
|
||||
## Examples
|
||||
|
||||
### Get available ADB devices
|
||||
@@ -40,7 +54,7 @@ use adb_client::{ADBServer, ADBDeviceExt};
|
||||
|
||||
let mut server = ADBServer::default();
|
||||
let mut device = server.get_device().expect("cannot get device");
|
||||
device.shell_command(["df", "-h"],std::io::stdout());
|
||||
device.shell_command(&["df", "-h"], &mut std::io::stdout());
|
||||
```
|
||||
|
||||
#### Push a file to the device
|
||||
@@ -67,7 +81,7 @@ use adb_client::{ADBUSBDevice, ADBDeviceExt};
|
||||
let vendor_id = 0x04e8;
|
||||
let product_id = 0x6860;
|
||||
let mut device = ADBUSBDevice::new(vendor_id, product_id).expect("cannot find device");
|
||||
device.shell_command(["df", "-h"],std::io::stdout());
|
||||
device.shell_command(&["df", "-h"], &mut std::io::stdout());
|
||||
```
|
||||
|
||||
#### (USB) Push a file to the device
|
||||
@@ -81,10 +95,10 @@ let vendor_id = 0x04e8;
|
||||
let product_id = 0x6860;
|
||||
let mut device = ADBUSBDevice::new(vendor_id, product_id).expect("cannot find device");
|
||||
let mut input = File::open(Path::new("/tmp/f")).expect("Cannot open file");
|
||||
device.push(&mut input, "/data/local/tmp");
|
||||
device.push(&mut input, &"/data/local/tmp");
|
||||
```
|
||||
|
||||
### (TCP) Get a shell from device
|
||||
#### (TCP) Get a shell from device
|
||||
|
||||
```rust no_run
|
||||
use std::net::{SocketAddr, IpAddr, Ipv4Addr};
|
||||
@@ -93,5 +107,5 @@ use adb_client::{ADBTcpDevice, ADBDeviceExt};
|
||||
let device_ip = IpAddr::V4(Ipv4Addr::new(192, 168, 0, 10));
|
||||
let device_port = 43210;
|
||||
let mut device = ADBTcpDevice::new(SocketAddr::new(device_ip, device_port)).expect("cannot find device");
|
||||
device.shell(std::io::stdin(), std::io::stdout());
|
||||
device.shell(&mut std::io::stdin(), Box::new(std::io::stdout()));
|
||||
```
|
||||
|
||||
@@ -1,31 +1,28 @@
|
||||
use std::io::{Read, Write};
|
||||
use std::io::{Cursor, Read, Write};
|
||||
use std::path::Path;
|
||||
|
||||
use image::{ImageBuffer, ImageFormat, Rgba};
|
||||
|
||||
use crate::models::AdbStatResponse;
|
||||
use crate::{RebootType, Result};
|
||||
|
||||
/// Trait representing all features available on both [`crate::ADBServerDevice`] and [`crate::ADBUSBDevice`]
|
||||
pub trait ADBDeviceExt {
|
||||
/// Runs command in a shell on the device, and write its output and error streams into output.
|
||||
fn shell_command<S: ToString, W: Write>(
|
||||
&mut self,
|
||||
command: impl IntoIterator<Item = S>,
|
||||
output: W,
|
||||
) -> Result<()>;
|
||||
fn shell_command(&mut self, command: &[&str], output: &mut dyn Write) -> Result<()>;
|
||||
|
||||
/// Starts an interactive shell session on the device.
|
||||
/// Input data is read from reader and write to writer.
|
||||
/// W has a 'static bound as it is internally used in a thread.
|
||||
fn shell<R: Read, W: Write + Send + 'static>(&mut self, reader: R, writer: W) -> Result<()>;
|
||||
fn shell(&mut self, reader: &mut dyn Read, writer: Box<(dyn Write + Send)>) -> Result<()>;
|
||||
|
||||
/// Display the stat information for a remote file
|
||||
fn stat(&mut self, remote_path: &str) -> Result<AdbStatResponse>;
|
||||
|
||||
/// Pull the remote file pointed to by `source` and write its contents into `output`
|
||||
fn pull<A: AsRef<str>, W: Write>(&mut self, source: A, output: W) -> Result<()>;
|
||||
fn pull(&mut self, source: &dyn AsRef<str>, output: &mut dyn Write) -> Result<()>;
|
||||
|
||||
/// Push `stream` to `path` on the device.
|
||||
fn push<R: Read, A: AsRef<str>>(&mut self, stream: R, path: A) -> Result<()>;
|
||||
fn push(&mut self, stream: &mut dyn Read, path: &dyn AsRef<str>) -> Result<()>;
|
||||
|
||||
/// Reboot the device using given reboot type
|
||||
fn reboot(&mut self, reboot_type: RebootType) -> Result<()>;
|
||||
@@ -34,7 +31,7 @@ pub trait ADBDeviceExt {
|
||||
fn run_activity(&mut self, package: &str, activity: &str) -> Result<Vec<u8>> {
|
||||
let mut output = Vec::new();
|
||||
self.shell_command(
|
||||
["am", "start", &format!("{package}/{package}.{activity}")],
|
||||
&["am", "start", &format!("{package}/{package}.{activity}")],
|
||||
&mut output,
|
||||
)?;
|
||||
|
||||
@@ -42,5 +39,38 @@ pub trait ADBDeviceExt {
|
||||
}
|
||||
|
||||
/// Install an APK pointed to by `apk_path` on device.
|
||||
fn install<P: AsRef<Path>>(&mut self, apk_path: P) -> Result<()>;
|
||||
fn install(&mut self, apk_path: &dyn AsRef<Path>) -> Result<()>;
|
||||
|
||||
/// Uninstall the package `package` from device.
|
||||
fn uninstall(&mut self, package: &str) -> Result<()>;
|
||||
|
||||
/// Inner method requesting framebuffer from an Android device
|
||||
fn framebuffer_inner(&mut self) -> Result<ImageBuffer<Rgba<u8>, Vec<u8>>>;
|
||||
|
||||
/// Dump framebuffer of this device into given path
|
||||
fn framebuffer(&mut self, path: &dyn AsRef<Path>) -> Result<()> {
|
||||
// Big help from AOSP source code (<https://android.googlesource.com/platform/system/adb/+/refs/heads/main/framebuffer_service.cpp>)
|
||||
let img = self.framebuffer_inner()?;
|
||||
Ok(img.save(path.as_ref())?)
|
||||
}
|
||||
|
||||
/// Dump framebuffer of this device and return corresponding bytes.
|
||||
///
|
||||
/// Output data format is currently only `PNG`.
|
||||
fn framebuffer_bytes(&mut self) -> Result<Vec<u8>> {
|
||||
let img = self.framebuffer_inner()?;
|
||||
let mut vec = Cursor::new(Vec::new());
|
||||
img.write_to(&mut vec, ImageFormat::Png)?;
|
||||
|
||||
Ok(vec.into_inner())
|
||||
}
|
||||
|
||||
/// Return a boxed instance representing this trait
|
||||
fn boxed(self) -> Box<dyn ADBDeviceExt>
|
||||
where
|
||||
Self: Sized,
|
||||
Self: 'static,
|
||||
{
|
||||
Box::new(self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@ use byteorder::{LittleEndian, ReadBytesExt};
|
||||
use rand::Rng;
|
||||
use std::io::{Cursor, Read, Seek};
|
||||
|
||||
use crate::{constants::BUFFER_SIZE, ADBMessageTransport, AdbStatResponse, Result, RustADBError};
|
||||
use crate::{ADBMessageTransport, AdbStatResponse, Result, RustADBError, constants::BUFFER_SIZE};
|
||||
|
||||
use super::{models::MessageSubcommand, ADBTransportMessage, MessageCommand};
|
||||
use super::{ADBTransportMessage, MessageCommand, models::MessageSubcommand};
|
||||
|
||||
/// Generic structure representing an ADB device reachable over an [`ADBMessageTransport`].
|
||||
/// Structure is totally agnostic over which transport is truly used.
|
||||
@@ -13,6 +13,12 @@ pub struct ADBMessageDevice<T: ADBMessageTransport> {
|
||||
transport: T,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct ADBSession {
|
||||
pub local_id: u32,
|
||||
pub remote_id: u32,
|
||||
}
|
||||
|
||||
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
/// Instantiate a new [`ADBMessageTransport`]
|
||||
pub fn new(transport: T) -> Self {
|
||||
@@ -30,15 +36,14 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
/// Receive a message and acknowledge it by replying with an `OKAY` command
|
||||
pub(crate) fn recv_and_reply_okay(
|
||||
&mut self,
|
||||
local_id: u32,
|
||||
remote_id: u32,
|
||||
session: ADBSession,
|
||||
) -> Result<ADBTransportMessage> {
|
||||
let message = self.transport.read_message()?;
|
||||
self.transport.write_message(ADBTransportMessage::new(
|
||||
MessageCommand::Okay,
|
||||
local_id,
|
||||
remote_id,
|
||||
"".into(),
|
||||
session.local_id,
|
||||
session.remote_id,
|
||||
&[],
|
||||
))?;
|
||||
Ok(message)
|
||||
}
|
||||
@@ -49,28 +54,21 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
message: ADBTransportMessage,
|
||||
) -> Result<ADBTransportMessage> {
|
||||
self.transport.write_message(message)?;
|
||||
let message = self.transport.read_message()?;
|
||||
let received_command = message.header().command();
|
||||
if received_command != MessageCommand::Okay {
|
||||
return Err(RustADBError::ADBRequestFailed(format!(
|
||||
"expected command OKAY after message, got {}",
|
||||
received_command
|
||||
)));
|
||||
}
|
||||
Ok(message)
|
||||
|
||||
self.transport.read_message().and_then(|message| {
|
||||
message.assert_command(MessageCommand::Okay)?;
|
||||
Ok(message)
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn recv_file<W: std::io::Write>(
|
||||
&mut self,
|
||||
local_id: u32,
|
||||
remote_id: u32,
|
||||
session: ADBSession,
|
||||
mut output: W,
|
||||
) -> std::result::Result<(), RustADBError> {
|
||||
let mut len: Option<u64> = None;
|
||||
loop {
|
||||
let payload = self
|
||||
.recv_and_reply_okay(local_id, remote_id)?
|
||||
.into_payload();
|
||||
let payload = self.recv_and_reply_okay(session)?.into_payload();
|
||||
let mut rdr = Cursor::new(&payload);
|
||||
while rdr.position() != payload.len() as u64 {
|
||||
match len.take() {
|
||||
@@ -103,8 +101,7 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
|
||||
pub(crate) fn push_file<R: std::io::Read>(
|
||||
&mut self,
|
||||
local_id: u32,
|
||||
remote_id: u32,
|
||||
session: ADBSession,
|
||||
mut reader: R,
|
||||
) -> std::result::Result<(), RustADBError> {
|
||||
let mut buffer = [0; BUFFER_SIZE];
|
||||
@@ -117,9 +114,9 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
|
||||
let message = ADBTransportMessage::new(
|
||||
MessageCommand::Write,
|
||||
local_id,
|
||||
remote_id,
|
||||
serialized_message,
|
||||
session.local_id,
|
||||
session.remote_id,
|
||||
&serialized_message,
|
||||
);
|
||||
|
||||
self.send_and_expect_okay(message)?;
|
||||
@@ -137,9 +134,9 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
|
||||
let message = ADBTransportMessage::new(
|
||||
MessageCommand::Write,
|
||||
local_id,
|
||||
remote_id,
|
||||
serialized_message,
|
||||
session.local_id,
|
||||
session.remote_id,
|
||||
&serialized_message,
|
||||
);
|
||||
|
||||
self.send_and_expect_okay(message)?;
|
||||
@@ -152,7 +149,7 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
return Err(RustADBError::ADBRequestFailed(format!(
|
||||
"Wrong command received {}",
|
||||
c
|
||||
)))
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -165,9 +162,9 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
|
||||
let message = ADBTransportMessage::new(
|
||||
MessageCommand::Write,
|
||||
local_id,
|
||||
remote_id,
|
||||
serialized_message,
|
||||
session.local_id,
|
||||
session.remote_id,
|
||||
&serialized_message,
|
||||
);
|
||||
|
||||
self.send_and_expect_okay(message)?;
|
||||
@@ -179,41 +176,28 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn begin_synchronization(&mut self) -> Result<(u32, u32)> {
|
||||
let sync_directive = "sync:\0";
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
let message = ADBTransportMessage::new(
|
||||
MessageCommand::Open,
|
||||
rng.gen(), /* Our 'local-id' */
|
||||
0,
|
||||
sync_directive.into(),
|
||||
);
|
||||
let message = self.send_and_expect_okay(message)?;
|
||||
let local_id = message.header().arg1();
|
||||
let remote_id = message.header().arg0();
|
||||
Ok((local_id, remote_id))
|
||||
pub(crate) fn begin_synchronization(&mut self) -> Result<ADBSession> {
|
||||
self.open_session(b"sync:\0")
|
||||
}
|
||||
|
||||
pub(crate) fn stat_with_explicit_ids(
|
||||
&mut self,
|
||||
session: ADBSession,
|
||||
remote_path: &str,
|
||||
local_id: u32,
|
||||
remote_id: u32,
|
||||
) -> Result<AdbStatResponse> {
|
||||
let stat_buffer = MessageSubcommand::Stat.with_arg(remote_path.len() as u32);
|
||||
let message = ADBTransportMessage::new(
|
||||
MessageCommand::Write,
|
||||
local_id,
|
||||
remote_id,
|
||||
bincode::serialize(&stat_buffer).map_err(|_e| RustADBError::ConversionError)?,
|
||||
session.local_id,
|
||||
session.remote_id,
|
||||
&bincode::serialize(&stat_buffer).map_err(|_e| RustADBError::ConversionError)?,
|
||||
);
|
||||
self.send_and_expect_okay(message)?;
|
||||
self.send_and_expect_okay(ADBTransportMessage::new(
|
||||
MessageCommand::Write,
|
||||
local_id,
|
||||
remote_id,
|
||||
remote_path.into(),
|
||||
session.local_id,
|
||||
session.remote_id,
|
||||
remote_path.as_bytes(),
|
||||
))?;
|
||||
let response = self.transport.read_message()?;
|
||||
// Skip first 4 bytes as this is the literal "STAT".
|
||||
@@ -222,15 +206,51 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
.map_err(|_e| RustADBError::ConversionError)
|
||||
}
|
||||
|
||||
pub(crate) fn end_transaction(&mut self, local_id: u32, remote_id: u32) -> Result<()> {
|
||||
pub(crate) fn end_transaction(&mut self, session: ADBSession) -> Result<()> {
|
||||
let quit_buffer = MessageSubcommand::Quit.with_arg(0u32);
|
||||
self.send_and_expect_okay(ADBTransportMessage::new(
|
||||
MessageCommand::Write,
|
||||
local_id,
|
||||
remote_id,
|
||||
bincode::serialize(&quit_buffer).map_err(|_e| RustADBError::ConversionError)?,
|
||||
session.local_id,
|
||||
session.remote_id,
|
||||
&bincode::serialize(&quit_buffer).map_err(|_e| RustADBError::ConversionError)?,
|
||||
))?;
|
||||
let _discard_close = self.transport.read_message()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn open_session(&mut self, data: &[u8]) -> Result<ADBSession> {
|
||||
let mut rng = rand::rng();
|
||||
let local_id: u32 = rng.random();
|
||||
|
||||
let message = ADBTransportMessage::new(
|
||||
MessageCommand::Open,
|
||||
local_id, // Our 'local-id'
|
||||
0,
|
||||
data,
|
||||
);
|
||||
self.get_transport_mut().write_message(message)?;
|
||||
|
||||
let response = self.get_transport_mut().read_message()?;
|
||||
|
||||
if response.header().command() != MessageCommand::Okay {
|
||||
return Err(RustADBError::ADBRequestFailed(format!(
|
||||
"Open session failed: got {} in respone instead of OKAY",
|
||||
response.header().command()
|
||||
)));
|
||||
}
|
||||
|
||||
if response.header().arg1() != local_id {
|
||||
return Err(RustADBError::ADBRequestFailed(format!(
|
||||
"Open session failed: respones used {} for our local_id instead of {local_id}",
|
||||
response.header().arg1()
|
||||
)));
|
||||
}
|
||||
|
||||
let session = ADBSession {
|
||||
local_id,
|
||||
remote_id: response.header().arg0(),
|
||||
};
|
||||
|
||||
Ok(session)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
use crate::{models::AdbStatResponse, ADBDeviceExt, ADBMessageTransport, RebootType, Result};
|
||||
use std::io::{Read, Write};
|
||||
use crate::{ADBDeviceExt, ADBMessageTransport, RebootType, Result, models::AdbStatResponse};
|
||||
use std::{
|
||||
io::{Read, Write},
|
||||
path::Path,
|
||||
};
|
||||
|
||||
use super::ADBMessageDevice;
|
||||
|
||||
impl<T: ADBMessageTransport> ADBDeviceExt for ADBMessageDevice<T> {
|
||||
fn shell_command<S: ToString, W: Write>(
|
||||
&mut self,
|
||||
command: impl IntoIterator<Item = S>,
|
||||
output: W,
|
||||
) -> Result<()> {
|
||||
fn shell_command(&mut self, command: &[&str], output: &mut dyn Write) -> Result<()> {
|
||||
self.shell_command(command, output)
|
||||
}
|
||||
|
||||
fn shell<R: Read, W: Write + Send + 'static>(&mut self, reader: R, writer: W) -> Result<()> {
|
||||
fn shell(&mut self, reader: &mut dyn Read, writer: Box<(dyn Write + Send)>) -> Result<()> {
|
||||
self.shell(reader, writer)
|
||||
}
|
||||
|
||||
@@ -20,11 +19,11 @@ impl<T: ADBMessageTransport> ADBDeviceExt for ADBMessageDevice<T> {
|
||||
self.stat(remote_path)
|
||||
}
|
||||
|
||||
fn pull<A: AsRef<str>, W: Write>(&mut self, source: A, output: W) -> Result<()> {
|
||||
fn pull(&mut self, source: &dyn AsRef<str>, output: &mut dyn Write) -> Result<()> {
|
||||
self.pull(source, output)
|
||||
}
|
||||
|
||||
fn push<R: Read, A: AsRef<str>>(&mut self, stream: R, path: A) -> Result<()> {
|
||||
fn push(&mut self, stream: &mut dyn Read, path: &dyn AsRef<str>) -> Result<()> {
|
||||
self.push(stream, path)
|
||||
}
|
||||
|
||||
@@ -32,7 +31,15 @@ impl<T: ADBMessageTransport> ADBDeviceExt for ADBMessageDevice<T> {
|
||||
self.reboot(reboot_type)
|
||||
}
|
||||
|
||||
fn install<P: AsRef<std::path::Path>>(&mut self, apk_path: P) -> Result<()> {
|
||||
fn install(&mut self, apk_path: &dyn AsRef<Path>) -> Result<()> {
|
||||
self.install(apk_path)
|
||||
}
|
||||
|
||||
fn uninstall(&mut self, package: &str) -> Result<()> {
|
||||
self.uninstall(package)
|
||||
}
|
||||
|
||||
fn framebuffer_inner(&mut self) -> Result<image::ImageBuffer<image::Rgba<u8>, Vec<u8>>> {
|
||||
self.framebuffer_inner()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
use std::net::SocketAddr;
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
use std::{io::Read, net::SocketAddr};
|
||||
|
||||
use super::ADBTransportMessage;
|
||||
use super::adb_message_device::ADBMessageDevice;
|
||||
use super::models::MessageCommand;
|
||||
use super::ADBTransportMessage;
|
||||
use crate::{ADBDeviceExt, ADBMessageTransport, ADBTransport, Result, RustADBError, TcpTransport};
|
||||
use crate::{ADBDeviceExt, ADBMessageTransport, ADBTransport, Result, TcpTransport};
|
||||
|
||||
/// Represent a device reached and available over USB.
|
||||
#[derive(Debug)]
|
||||
@@ -32,76 +33,86 @@ impl ADBTcpDevice {
|
||||
MessageCommand::Cnxn,
|
||||
0x01000000,
|
||||
1048576,
|
||||
format!("host::{}\0", env!("CARGO_PKG_NAME"))
|
||||
.as_bytes()
|
||||
.to_vec(),
|
||||
format!("host::{}\0", env!("CARGO_PKG_NAME")).as_bytes(),
|
||||
);
|
||||
|
||||
self.get_transport_mut().write_message(message)?;
|
||||
|
||||
let message = self.get_transport_mut().read_message()?;
|
||||
|
||||
// At this point, we should have received a STLS message
|
||||
if message.header().command() != MessageCommand::Stls {
|
||||
return Err(RustADBError::ADBRequestFailed(format!(
|
||||
"Wrong command received {}",
|
||||
message.header().command()
|
||||
)));
|
||||
};
|
||||
|
||||
let message = ADBTransportMessage::new(MessageCommand::Stls, 1, 0, vec![]);
|
||||
|
||||
self.get_transport_mut().write_message(message)?;
|
||||
|
||||
// Upgrade TCP connection to TLS
|
||||
self.get_transport_mut().upgrade_connection()?;
|
||||
|
||||
log::debug!("Connection successfully upgraded from TCP to TLS");
|
||||
// Check if client is requesting a secure connection and upgrade it if necessary
|
||||
match message.header().command() {
|
||||
MessageCommand::Stls => {
|
||||
self.get_transport_mut()
|
||||
.write_message(ADBTransportMessage::new(MessageCommand::Stls, 1, 0, &[]))?;
|
||||
self.get_transport_mut().upgrade_connection()?;
|
||||
log::debug!("Connection successfully upgraded from TCP to TLS");
|
||||
}
|
||||
MessageCommand::Cnxn => {
|
||||
log::debug!("Unencrypted connection established");
|
||||
}
|
||||
_ => {
|
||||
return Err(crate::RustADBError::WrongResponseReceived(
|
||||
"Expected CNXN or STLS command".to_string(),
|
||||
message.header().command().to_string(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_transport_mut(&mut self) -> &mut TcpTransport {
|
||||
self.inner.get_transport_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl ADBDeviceExt for ADBTcpDevice {
|
||||
fn shell_command<S: ToString, W: std::io::Write>(
|
||||
&mut self,
|
||||
command: impl IntoIterator<Item = S>,
|
||||
output: W,
|
||||
) -> Result<()> {
|
||||
#[inline]
|
||||
fn shell_command(&mut self, command: &[&str], output: &mut dyn Write) -> Result<()> {
|
||||
self.inner.shell_command(command, output)
|
||||
}
|
||||
|
||||
fn shell<R: std::io::Read, W: std::io::Write + Send + 'static>(
|
||||
&mut self,
|
||||
reader: R,
|
||||
writer: W,
|
||||
) -> Result<()> {
|
||||
#[inline]
|
||||
fn shell(&mut self, reader: &mut dyn Read, writer: Box<(dyn Write + Send)>) -> Result<()> {
|
||||
self.inner.shell(reader, writer)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn stat(&mut self, remote_path: &str) -> Result<crate::AdbStatResponse> {
|
||||
self.inner.stat(remote_path)
|
||||
}
|
||||
|
||||
fn pull<A: AsRef<str>, W: std::io::Write>(&mut self, source: A, output: W) -> Result<()> {
|
||||
#[inline]
|
||||
fn pull(&mut self, source: &dyn AsRef<str>, output: &mut dyn Write) -> Result<()> {
|
||||
self.inner.pull(source, output)
|
||||
}
|
||||
|
||||
fn push<R: std::io::Read, A: AsRef<str>>(&mut self, stream: R, path: A) -> Result<()> {
|
||||
#[inline]
|
||||
fn push(&mut self, stream: &mut dyn Read, path: &dyn AsRef<str>) -> Result<()> {
|
||||
self.inner.push(stream, path)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn reboot(&mut self, reboot_type: crate::RebootType) -> Result<()> {
|
||||
self.inner.reboot(reboot_type)
|
||||
}
|
||||
|
||||
fn install<P: AsRef<Path>>(&mut self, apk_path: P) -> Result<()> {
|
||||
#[inline]
|
||||
fn install(&mut self, apk_path: &dyn AsRef<Path>) -> Result<()> {
|
||||
self.inner.install(apk_path)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn uninstall(&mut self, package: &str) -> Result<()> {
|
||||
self.inner.uninstall(package)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn framebuffer_inner(&mut self) -> Result<image::ImageBuffer<image::Rgba<u8>, Vec<u8>>> {
|
||||
self.inner.framebuffer_inner()
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for ADBTcpDevice {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::RustADBError;
|
||||
use crate::{Result, RustADBError};
|
||||
|
||||
use super::models::MessageCommand;
|
||||
|
||||
@@ -66,16 +66,16 @@ impl ADBTransportMessageHeader {
|
||||
command_u32 ^ 0xFFFFFFFF
|
||||
}
|
||||
|
||||
pub fn as_bytes(&self) -> Result<Vec<u8>, RustADBError> {
|
||||
pub fn as_bytes(&self) -> Result<Vec<u8>> {
|
||||
bincode::serialize(&self).map_err(|_e| RustADBError::ConversionError)
|
||||
}
|
||||
}
|
||||
|
||||
impl ADBTransportMessage {
|
||||
pub fn new(command: MessageCommand, arg0: u32, arg1: u32, data: Vec<u8>) -> Self {
|
||||
pub fn new(command: MessageCommand, arg0: u32, arg1: u32, data: &[u8]) -> Self {
|
||||
Self {
|
||||
header: ADBTransportMessageHeader::new(command, arg0, arg1, &data),
|
||||
payload: data,
|
||||
header: ADBTransportMessageHeader::new(command, arg0, arg1, data),
|
||||
payload: data.to_vec(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,6 +88,18 @@ impl ADBTransportMessage {
|
||||
&& ADBTransportMessageHeader::compute_crc32(&self.payload) == self.header.data_crc32
|
||||
}
|
||||
|
||||
pub fn assert_command(&self, expected_command: MessageCommand) -> Result<()> {
|
||||
let our_command = self.header().command();
|
||||
if expected_command == our_command {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
Err(RustADBError::WrongResponseReceived(
|
||||
our_command.to_string(),
|
||||
expected_command.to_string(),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn header(&self) -> &ADBTransportMessageHeader {
|
||||
&self.header
|
||||
}
|
||||
@@ -104,7 +116,7 @@ impl ADBTransportMessage {
|
||||
impl TryFrom<[u8; 24]> for ADBTransportMessageHeader {
|
||||
type Error = RustADBError;
|
||||
|
||||
fn try_from(value: [u8; 24]) -> Result<Self, Self::Error> {
|
||||
fn try_from(value: [u8; 24]) -> Result<Self> {
|
||||
bincode::deserialize(&value).map_err(|_e| RustADBError::ConversionError)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
use rusb::Device;
|
||||
use rusb::DeviceDescriptor;
|
||||
use rusb::UsbContext;
|
||||
use rusb::constants::LIBUSB_CLASS_VENDOR_SPEC;
|
||||
use std::fs::read_to_string;
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::time::Duration;
|
||||
@@ -9,10 +12,10 @@ use std::time::Duration;
|
||||
use super::adb_message_device::ADBMessageDevice;
|
||||
use super::models::MessageCommand;
|
||||
use super::{ADBRsaKey, ADBTransportMessage};
|
||||
use crate::device::adb_transport_message::{AUTH_RSAPUBLICKEY, AUTH_SIGNATURE, AUTH_TOKEN};
|
||||
use crate::ADBDeviceExt;
|
||||
use crate::ADBMessageTransport;
|
||||
use crate::ADBTransport;
|
||||
use crate::device::adb_transport_message::{AUTH_RSAPUBLICKEY, AUTH_SIGNATURE, AUTH_TOKEN};
|
||||
use crate::{Result, RustADBError, USBTransport};
|
||||
|
||||
pub fn read_adb_private_key<P: AsRef<Path>>(private_key_path: P) -> Result<Option<ADBRsaKey>> {
|
||||
@@ -55,8 +58,6 @@ fn search_adb_devices() -> Result<Option<(u16, u16)>> {
|
||||
}
|
||||
|
||||
fn is_adb_device<T: UsbContext>(device: &Device<T>, des: &DeviceDescriptor) -> bool {
|
||||
const ADB_CLASS: u8 = 0xff;
|
||||
|
||||
const ADB_SUBCLASS: u8 = 0x42;
|
||||
const ADB_PROTOCOL: u8 = 0x1;
|
||||
|
||||
@@ -75,7 +76,7 @@ fn is_adb_device<T: UsbContext>(device: &Device<T>, des: &DeviceDescriptor) -> b
|
||||
let class = interface_des.class_code();
|
||||
let subcl = interface_des.sub_class_code();
|
||||
if proto == ADB_PROTOCOL
|
||||
&& ((class == ADB_CLASS && subcl == ADB_SUBCLASS)
|
||||
&& ((class == LIBUSB_CLASS_VENDOR_SPEC && subcl == ADB_SUBCLASS)
|
||||
|| (class == BULK_CLASS && subcl == BULK_ADB_SUBCLASS))
|
||||
{
|
||||
return true;
|
||||
@@ -173,36 +174,27 @@ impl ADBUSBDevice {
|
||||
MessageCommand::Cnxn,
|
||||
0x01000000,
|
||||
1048576,
|
||||
format!("host::{}\0", env!("CARGO_PKG_NAME"))
|
||||
.as_bytes()
|
||||
.to_vec(),
|
||||
format!("host::{}\0", env!("CARGO_PKG_NAME")).as_bytes(),
|
||||
);
|
||||
|
||||
self.get_transport_mut().write_message(message)?;
|
||||
|
||||
let message = self.get_transport_mut().read_message()?;
|
||||
message.assert_command(MessageCommand::Auth)?;
|
||||
|
||||
// At this point, we should have received either:
|
||||
// - an AUTH message with arg0 == 1
|
||||
// - a CNXN message
|
||||
let auth_message = match message.header().command() {
|
||||
MessageCommand::Auth if message.header().arg0() == AUTH_TOKEN => message,
|
||||
MessageCommand::Auth if message.header().arg0() != AUTH_TOKEN => {
|
||||
return Err(RustADBError::ADBRequestFailed(
|
||||
"Received AUTH message with type != 1".into(),
|
||||
))
|
||||
}
|
||||
c => {
|
||||
// At this point, we should have receive an AUTH message with arg0 == 1
|
||||
let auth_message = match message.header().arg0() {
|
||||
AUTH_TOKEN => message,
|
||||
v => {
|
||||
return Err(RustADBError::ADBRequestFailed(format!(
|
||||
"Wrong command received {}",
|
||||
c
|
||||
)))
|
||||
"Received AUTH message with type != 1 ({v})"
|
||||
)));
|
||||
}
|
||||
};
|
||||
|
||||
let sign = self.private_key.sign(auth_message.into_payload())?;
|
||||
|
||||
let message = ADBTransportMessage::new(MessageCommand::Auth, AUTH_SIGNATURE, 0, sign);
|
||||
let message = ADBTransportMessage::new(MessageCommand::Auth, AUTH_SIGNATURE, 0, &sign);
|
||||
|
||||
self.get_transport_mut().write_message(message)?;
|
||||
|
||||
@@ -219,71 +211,77 @@ impl ADBUSBDevice {
|
||||
let mut pubkey = self.private_key.android_pubkey_encode()?.into_bytes();
|
||||
pubkey.push(b'\0');
|
||||
|
||||
let message = ADBTransportMessage::new(MessageCommand::Auth, AUTH_RSAPUBLICKEY, 0, pubkey);
|
||||
let message = ADBTransportMessage::new(MessageCommand::Auth, AUTH_RSAPUBLICKEY, 0, &pubkey);
|
||||
|
||||
self.get_transport_mut().write_message(message)?;
|
||||
|
||||
let response = self
|
||||
.get_transport_mut()
|
||||
.read_message_with_timeout(Duration::from_secs(10))?;
|
||||
.read_message_with_timeout(Duration::from_secs(10))
|
||||
.and_then(|message| {
|
||||
message.assert_command(MessageCommand::Cnxn)?;
|
||||
Ok(message)
|
||||
})?;
|
||||
|
||||
match response.header().command() {
|
||||
MessageCommand::Cnxn => log::info!(
|
||||
"Authentication OK, device info {}",
|
||||
String::from_utf8(response.into_payload())?
|
||||
),
|
||||
_ => {
|
||||
return Err(RustADBError::ADBRequestFailed(format!(
|
||||
"wrong response {}",
|
||||
response.header().command()
|
||||
)))
|
||||
}
|
||||
}
|
||||
log::info!(
|
||||
"Authentication OK, device info {}",
|
||||
String::from_utf8(response.into_payload())?
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_transport_mut(&mut self) -> &mut USBTransport {
|
||||
self.inner.get_transport_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl ADBDeviceExt for ADBUSBDevice {
|
||||
fn shell_command<S: ToString, W: std::io::Write>(
|
||||
&mut self,
|
||||
command: impl IntoIterator<Item = S>,
|
||||
output: W,
|
||||
) -> Result<()> {
|
||||
#[inline]
|
||||
fn shell_command(&mut self, command: &[&str], output: &mut dyn Write) -> Result<()> {
|
||||
self.inner.shell_command(command, output)
|
||||
}
|
||||
|
||||
fn shell<R: std::io::Read, W: std::io::Write + Send + 'static>(
|
||||
&mut self,
|
||||
reader: R,
|
||||
writer: W,
|
||||
) -> Result<()> {
|
||||
#[inline]
|
||||
fn shell<'a>(&mut self, reader: &mut dyn Read, writer: Box<(dyn Write + Send)>) -> Result<()> {
|
||||
self.inner.shell(reader, writer)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn stat(&mut self, remote_path: &str) -> Result<crate::AdbStatResponse> {
|
||||
self.inner.stat(remote_path)
|
||||
}
|
||||
|
||||
fn pull<A: AsRef<str>, W: std::io::Write>(&mut self, source: A, output: W) -> Result<()> {
|
||||
#[inline]
|
||||
fn pull(&mut self, source: &dyn AsRef<str>, output: &mut dyn Write) -> Result<()> {
|
||||
self.inner.pull(source, output)
|
||||
}
|
||||
|
||||
fn push<R: std::io::Read, A: AsRef<str>>(&mut self, stream: R, path: A) -> Result<()> {
|
||||
#[inline]
|
||||
fn push(&mut self, stream: &mut dyn Read, path: &dyn AsRef<str>) -> Result<()> {
|
||||
self.inner.push(stream, path)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn reboot(&mut self, reboot_type: crate::RebootType) -> Result<()> {
|
||||
self.inner.reboot(reboot_type)
|
||||
}
|
||||
|
||||
fn install<P: AsRef<Path>>(&mut self, apk_path: P) -> Result<()> {
|
||||
#[inline]
|
||||
fn install(&mut self, apk_path: &dyn AsRef<Path>) -> Result<()> {
|
||||
self.inner.install(apk_path)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn uninstall(&mut self, package: &str) -> Result<()> {
|
||||
self.inner.uninstall(package)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn framebuffer_inner(&mut self) -> Result<image::ImageBuffer<image::Rgba<u8>, Vec<u8>>> {
|
||||
self.inner.framebuffer_inner()
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for ADBUSBDevice {
|
||||
|
||||
98
adb_client/src/device/commands/framebuffer.rs
Normal file
98
adb_client/src/device/commands/framebuffer.rs
Normal file
@@ -0,0 +1,98 @@
|
||||
use std::io::{Cursor, Read};
|
||||
|
||||
use byteorder::{LittleEndian, ReadBytesExt};
|
||||
use image::{ImageBuffer, Rgba};
|
||||
|
||||
use crate::{
|
||||
ADBMessageTransport, Result, RustADBError,
|
||||
device::{MessageCommand, adb_message_device::ADBMessageDevice},
|
||||
models::{FrameBufferInfoV1, FrameBufferInfoV2},
|
||||
};
|
||||
|
||||
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
pub(crate) fn framebuffer_inner(&mut self) -> Result<ImageBuffer<Rgba<u8>, Vec<u8>>> {
|
||||
let session = self.open_session(b"framebuffer:\0")?;
|
||||
|
||||
let response = self.recv_and_reply_okay(session)?;
|
||||
|
||||
let mut payload_cursor = Cursor::new(response.payload());
|
||||
|
||||
let version = payload_cursor.read_u32::<LittleEndian>()?;
|
||||
|
||||
let img = match version {
|
||||
// RGBA_8888
|
||||
1 => {
|
||||
let mut buf = [0u8; std::mem::size_of::<FrameBufferInfoV1>()];
|
||||
|
||||
payload_cursor.read_exact(&mut buf)?;
|
||||
|
||||
let framebuffer_info: FrameBufferInfoV1 = buf.try_into()?;
|
||||
|
||||
let mut framebuffer_data = Vec::new();
|
||||
payload_cursor.read_to_end(&mut framebuffer_data)?;
|
||||
|
||||
loop {
|
||||
if framebuffer_data.len() as u32 == framebuffer_info.size {
|
||||
break;
|
||||
}
|
||||
|
||||
let response = self.recv_and_reply_okay(session)?;
|
||||
|
||||
framebuffer_data.extend_from_slice(&response.into_payload());
|
||||
|
||||
log::debug!(
|
||||
"received framebuffer data. new size {}",
|
||||
framebuffer_data.len()
|
||||
);
|
||||
}
|
||||
|
||||
ImageBuffer::<Rgba<u8>, Vec<u8>>::from_vec(
|
||||
framebuffer_info.width,
|
||||
framebuffer_info.height,
|
||||
framebuffer_data,
|
||||
)
|
||||
.ok_or_else(|| RustADBError::FramebufferConversionError)?
|
||||
}
|
||||
// RGBX_8888
|
||||
2 => {
|
||||
let mut buf = [0u8; std::mem::size_of::<FrameBufferInfoV2>()];
|
||||
|
||||
payload_cursor.read_exact(&mut buf)?;
|
||||
|
||||
let framebuffer_info: FrameBufferInfoV2 = buf.try_into()?;
|
||||
|
||||
let mut framebuffer_data = Vec::new();
|
||||
payload_cursor.read_to_end(&mut framebuffer_data)?;
|
||||
|
||||
loop {
|
||||
if framebuffer_data.len() as u32 == framebuffer_info.size {
|
||||
break;
|
||||
}
|
||||
|
||||
let response = self.recv_and_reply_okay(session)?;
|
||||
|
||||
framebuffer_data.extend_from_slice(&response.into_payload());
|
||||
|
||||
log::debug!(
|
||||
"received framebuffer data. new size {}",
|
||||
framebuffer_data.len()
|
||||
);
|
||||
}
|
||||
|
||||
ImageBuffer::<Rgba<u8>, Vec<u8>>::from_vec(
|
||||
framebuffer_info.width,
|
||||
framebuffer_info.height,
|
||||
framebuffer_data,
|
||||
)
|
||||
.ok_or_else(|| RustADBError::FramebufferConversionError)?
|
||||
}
|
||||
v => return Err(RustADBError::UnimplementedFramebufferImageVersion(v)),
|
||||
};
|
||||
|
||||
self.get_transport_mut()
|
||||
.read_message()
|
||||
.and_then(|message| message.assert_command(MessageCommand::Clse))?;
|
||||
|
||||
Ok(img)
|
||||
}
|
||||
}
|
||||
@@ -1,43 +1,25 @@
|
||||
use std::fs::File;
|
||||
|
||||
use rand::Rng;
|
||||
use std::{fs::File, path::Path};
|
||||
|
||||
use crate::{
|
||||
device::{
|
||||
adb_message_device::ADBMessageDevice, ADBTransportMessage, MessageCommand, MessageWriter,
|
||||
},
|
||||
utils::check_extension_is_apk,
|
||||
ADBMessageTransport, Result,
|
||||
device::{MessageWriter, adb_message_device::ADBMessageDevice},
|
||||
utils::check_extension_is_apk,
|
||||
};
|
||||
|
||||
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
pub(crate) fn install<P: AsRef<std::path::Path>>(&mut self, apk_path: P) -> Result<()> {
|
||||
let mut apk_file = File::open(&apk_path)?;
|
||||
pub(crate) fn install(&mut self, apk_path: &dyn AsRef<Path>) -> Result<()> {
|
||||
let mut apk_file = File::open(apk_path)?;
|
||||
|
||||
check_extension_is_apk(&apk_path)?;
|
||||
check_extension_is_apk(apk_path)?;
|
||||
|
||||
let file_size = apk_file.metadata()?.len();
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let local_id = rng.gen();
|
||||
|
||||
let message = ADBTransportMessage::new(
|
||||
MessageCommand::Open,
|
||||
local_id,
|
||||
0,
|
||||
format!("exec:cmd package 'install' -S {}\0", file_size)
|
||||
.as_bytes()
|
||||
.to_vec(),
|
||||
);
|
||||
self.get_transport_mut().write_message(message)?;
|
||||
|
||||
let response = self.get_transport_mut().read_message()?;
|
||||
let remote_id = response.header().arg0();
|
||||
let session =
|
||||
self.open_session(format!("exec:cmd package 'install' -S {}\0", file_size).as_bytes())?;
|
||||
|
||||
let transport = self.get_transport().clone();
|
||||
|
||||
let mut writer = MessageWriter::new(transport, local_id, remote_id);
|
||||
let mut writer = MessageWriter::new(transport, session.local_id, session.remote_id);
|
||||
|
||||
std::io::copy(&mut apk_file, &mut writer)?;
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
mod framebuffer;
|
||||
mod install;
|
||||
mod pull;
|
||||
mod push;
|
||||
mod reboot;
|
||||
mod shell;
|
||||
mod stat;
|
||||
mod uninstall;
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
use std::io::Write;
|
||||
|
||||
use crate::{
|
||||
device::{
|
||||
adb_message_device::ADBMessageDevice, models::MessageSubcommand, ADBTransportMessage,
|
||||
MessageCommand,
|
||||
},
|
||||
ADBMessageTransport, Result, RustADBError,
|
||||
device::{
|
||||
ADBTransportMessage, MessageCommand, adb_message_device::ADBMessageDevice,
|
||||
models::MessageSubcommand,
|
||||
},
|
||||
};
|
||||
|
||||
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
pub(crate) fn pull<A: AsRef<str>, W: Write>(&mut self, source: A, output: W) -> Result<()> {
|
||||
let (local_id, remote_id) = self.begin_synchronization()?;
|
||||
let session = self.begin_synchronization()?;
|
||||
let source = source.as_ref();
|
||||
|
||||
let adb_stat_response = self.stat_with_explicit_ids(source, local_id, remote_id)?;
|
||||
let adb_stat_response = self.stat_with_explicit_ids(session, source)?;
|
||||
|
||||
if adb_stat_response.file_perm == 0 {
|
||||
return Err(RustADBError::UnknownResponseType(
|
||||
@@ -22,7 +22,12 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
}
|
||||
|
||||
self.get_transport_mut().write_message_with_timeout(
|
||||
ADBTransportMessage::new(MessageCommand::Okay, local_id, remote_id, "".into()),
|
||||
ADBTransportMessage::new(
|
||||
MessageCommand::Okay,
|
||||
session.local_id,
|
||||
session.remote_id,
|
||||
&[],
|
||||
),
|
||||
std::time::Duration::from_secs(4),
|
||||
)?;
|
||||
|
||||
@@ -31,19 +36,19 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
bincode::serialize(&recv_buffer).map_err(|_e| RustADBError::ConversionError)?;
|
||||
self.send_and_expect_okay(ADBTransportMessage::new(
|
||||
MessageCommand::Write,
|
||||
local_id,
|
||||
remote_id,
|
||||
recv_buffer,
|
||||
session.local_id,
|
||||
session.remote_id,
|
||||
&recv_buffer,
|
||||
))?;
|
||||
self.send_and_expect_okay(ADBTransportMessage::new(
|
||||
MessageCommand::Write,
|
||||
local_id,
|
||||
remote_id,
|
||||
source.into(),
|
||||
session.local_id,
|
||||
session.remote_id,
|
||||
source.as_bytes(),
|
||||
))?;
|
||||
|
||||
self.recv_file(local_id, remote_id, output)?;
|
||||
self.end_transaction(local_id, remote_id)?;
|
||||
self.recv_file(session, output)?;
|
||||
self.end_transaction(session)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
use std::io::Read;
|
||||
|
||||
use crate::{
|
||||
device::{
|
||||
adb_message_device::ADBMessageDevice, ADBTransportMessage, MessageCommand,
|
||||
MessageSubcommand,
|
||||
},
|
||||
ADBMessageTransport, Result, RustADBError,
|
||||
device::{
|
||||
ADBTransportMessage, MessageCommand, MessageSubcommand,
|
||||
adb_message_device::ADBMessageDevice,
|
||||
},
|
||||
};
|
||||
|
||||
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
pub(crate) fn push<R: Read, A: AsRef<str>>(&mut self, stream: R, path: A) -> Result<()> {
|
||||
let (local_id, remote_id) = self.begin_synchronization()?;
|
||||
let session = self.begin_synchronization()?;
|
||||
|
||||
let path_header = format!("{},0777", path.as_ref());
|
||||
|
||||
@@ -21,14 +21,13 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
|
||||
self.send_and_expect_okay(ADBTransportMessage::new(
|
||||
MessageCommand::Write,
|
||||
local_id,
|
||||
remote_id,
|
||||
send_buffer,
|
||||
session.local_id,
|
||||
session.remote_id,
|
||||
&send_buffer,
|
||||
))?;
|
||||
|
||||
self.push_file(local_id, remote_id, stream)?;
|
||||
|
||||
self.end_transaction(local_id, remote_id)?;
|
||||
self.push_file(session, stream)?;
|
||||
self.end_transaction(session)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,28 +1,14 @@
|
||||
use rand::Rng;
|
||||
|
||||
use crate::{
|
||||
device::{adb_message_device::ADBMessageDevice, ADBTransportMessage, MessageCommand},
|
||||
ADBMessageTransport, RebootType, Result, RustADBError,
|
||||
ADBMessageTransport, RebootType, Result,
|
||||
device::{MessageCommand, adb_message_device::ADBMessageDevice},
|
||||
};
|
||||
|
||||
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
pub(crate) fn reboot(&mut self, reboot_type: RebootType) -> Result<()> {
|
||||
let mut rng = rand::thread_rng();
|
||||
self.open_session(format!("reboot:{}\0", reboot_type).as_bytes())?;
|
||||
|
||||
let message = ADBTransportMessage::new(
|
||||
MessageCommand::Open,
|
||||
rng.gen(), // Our 'local-id'
|
||||
0,
|
||||
format!("reboot:{}\0", reboot_type).as_bytes().to_vec(),
|
||||
);
|
||||
self.get_transport_mut().write_message(message)?;
|
||||
|
||||
let message = self.get_transport_mut().read_message()?;
|
||||
|
||||
if message.header().command() != MessageCommand::Okay {
|
||||
return Err(RustADBError::ADBShellNotSupported);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
self.get_transport_mut()
|
||||
.read_message()
|
||||
.and_then(|message| message.assert_command(MessageCommand::Okay))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,44 +1,16 @@
|
||||
use rand::Rng;
|
||||
use std::io::{Read, Write};
|
||||
use std::io::{ErrorKind, Read, Write};
|
||||
|
||||
use crate::device::ShellMessageWriter;
|
||||
use crate::Result;
|
||||
use crate::device::ShellMessageWriter;
|
||||
use crate::{
|
||||
device::{ADBMessageDevice, ADBTransportMessage, MessageCommand},
|
||||
ADBMessageTransport, RustADBError,
|
||||
device::{ADBMessageDevice, ADBTransportMessage, MessageCommand},
|
||||
};
|
||||
|
||||
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
/// Runs 'command' in a shell on the device, and write its output and error streams into [`output`].
|
||||
pub(crate) fn shell_command<S: ToString, W: Write>(
|
||||
&mut self,
|
||||
command: impl IntoIterator<Item = S>,
|
||||
mut output: W,
|
||||
) -> Result<()> {
|
||||
let message = ADBTransportMessage::new(
|
||||
MessageCommand::Open,
|
||||
1,
|
||||
0,
|
||||
format!(
|
||||
"shell:{}\0",
|
||||
command
|
||||
.into_iter()
|
||||
.map(|v| v.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join(" "),
|
||||
)
|
||||
.as_bytes()
|
||||
.to_vec(),
|
||||
);
|
||||
self.get_transport_mut().write_message(message)?;
|
||||
|
||||
let response = self.get_transport_mut().read_message()?;
|
||||
if response.header().command() != MessageCommand::Okay {
|
||||
return Err(RustADBError::ADBRequestFailed(format!(
|
||||
"wrong command {}",
|
||||
response.header().command()
|
||||
)));
|
||||
}
|
||||
/// Runs 'command' in a shell on the device, and write its output and error streams into output.
|
||||
pub(crate) fn shell_command(&mut self, command: &[&str], output: &mut dyn Write) -> Result<()> {
|
||||
let session = self.open_session(format!("shell:{}\0", command.join(" "),).as_bytes())?;
|
||||
|
||||
loop {
|
||||
let response = self.get_transport_mut().read_message()?;
|
||||
@@ -54,24 +26,12 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
|
||||
/// Starts an interactive shell session on the device.
|
||||
/// Input data is read from [reader] and write to [writer].
|
||||
/// [W] has a 'static bound as it is internally used in a thread.
|
||||
pub(crate) fn shell<R: Read, W: Write + Send + 'static>(
|
||||
pub(crate) fn shell(
|
||||
&mut self,
|
||||
mut reader: R,
|
||||
mut writer: W,
|
||||
mut reader: &mut dyn Read,
|
||||
mut writer: Box<(dyn Write + Send)>,
|
||||
) -> Result<()> {
|
||||
let sync_directive = "shell:\0";
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
let message = ADBTransportMessage::new(
|
||||
MessageCommand::Open,
|
||||
rng.gen(), /* Our 'local-id' */
|
||||
0,
|
||||
sync_directive.into(),
|
||||
);
|
||||
let message = self.send_and_expect_okay(message)?;
|
||||
let local_id = message.header().arg1();
|
||||
let remote_id = message.header().arg0();
|
||||
let session = self.open_session(b"shell:\0")?;
|
||||
|
||||
let mut transport = self.get_transport().clone();
|
||||
|
||||
@@ -81,28 +41,33 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
let message = transport.read_message()?;
|
||||
|
||||
// Acknowledge for more data
|
||||
let response =
|
||||
ADBTransportMessage::new(MessageCommand::Okay, local_id, remote_id, vec![]);
|
||||
let response = ADBTransportMessage::new(
|
||||
MessageCommand::Okay,
|
||||
session.local_id,
|
||||
session.remote_id,
|
||||
&[],
|
||||
);
|
||||
transport.write_message(response)?;
|
||||
|
||||
match message.header().command() {
|
||||
MessageCommand::Write => {}
|
||||
MessageCommand::Write => {
|
||||
writer.write_all(&message.into_payload())?;
|
||||
writer.flush()?;
|
||||
}
|
||||
MessageCommand::Okay => continue,
|
||||
_ => return Err(RustADBError::ADBShellNotSupported),
|
||||
}
|
||||
|
||||
writer.write_all(&message.into_payload())?;
|
||||
writer.flush()?;
|
||||
}
|
||||
});
|
||||
|
||||
let transport = self.get_transport().clone();
|
||||
let mut shell_writer = ShellMessageWriter::new(transport, local_id, remote_id);
|
||||
let mut shell_writer =
|
||||
ShellMessageWriter::new(transport, session.local_id, session.remote_id);
|
||||
|
||||
// Read from given reader (that could be stdin e.g), and write content to device adbd
|
||||
if let Err(e) = std::io::copy(&mut reader, &mut shell_writer) {
|
||||
match e.kind() {
|
||||
std::io::ErrorKind::BrokenPipe => return Ok(()),
|
||||
ErrorKind::BrokenPipe => return Ok(()),
|
||||
_ => return Err(RustADBError::IOError(e)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
use crate::{
|
||||
device::adb_message_device::ADBMessageDevice, ADBMessageTransport, AdbStatResponse, Result,
|
||||
ADBMessageTransport, AdbStatResponse, Result, device::adb_message_device::ADBMessageDevice,
|
||||
};
|
||||
|
||||
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
pub(crate) fn stat(&mut self, remote_path: &str) -> Result<AdbStatResponse> {
|
||||
let (local_id, remote_id) = self.begin_synchronization()?;
|
||||
let adb_stat_response = self.stat_with_explicit_ids(remote_path, local_id, remote_id)?;
|
||||
self.end_transaction(local_id, remote_id)?;
|
||||
let session = self.begin_synchronization()?;
|
||||
let adb_stat_response = self.stat_with_explicit_ids(session, remote_path)?;
|
||||
self.end_transaction(session)?;
|
||||
Ok(adb_stat_response)
|
||||
}
|
||||
}
|
||||
|
||||
19
adb_client/src/device/commands/uninstall.rs
Normal file
19
adb_client/src/device/commands/uninstall.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
use crate::{ADBMessageTransport, Result, device::adb_message_device::ADBMessageDevice};
|
||||
|
||||
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
pub(crate) fn uninstall(&mut self, package_name: &str) -> Result<()> {
|
||||
self.open_session(format!("exec:cmd package 'uninstall' {}\0", package_name).as_bytes())?;
|
||||
|
||||
let final_status = self.get_transport_mut().read_message()?;
|
||||
|
||||
match final_status.into_payload().as_slice() {
|
||||
b"Success\n" => {
|
||||
log::info!("Package {} successfully uninstalled", package_name);
|
||||
Ok(())
|
||||
}
|
||||
d => Err(crate::RustADBError::ADBRequestFailed(String::from_utf8(
|
||||
d.to_vec(),
|
||||
)?)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::io::{ErrorKind, Write};
|
||||
use std::io::{Error, ErrorKind, Result, Write};
|
||||
|
||||
use crate::ADBMessageTransport;
|
||||
|
||||
@@ -24,30 +24,25 @@ impl<T: ADBMessageTransport> MessageWriter<T> {
|
||||
}
|
||||
|
||||
impl<T: ADBMessageTransport> Write for MessageWriter<T> {
|
||||
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
|
||||
let message = ADBTransportMessage::new(
|
||||
MessageCommand::Write,
|
||||
self.local_id,
|
||||
self.remote_id,
|
||||
buf.to_vec(),
|
||||
);
|
||||
fn write(&mut self, buf: &[u8]) -> Result<usize> {
|
||||
let message =
|
||||
ADBTransportMessage::new(MessageCommand::Write, self.local_id, self.remote_id, buf);
|
||||
self.transport
|
||||
.write_message(message)
|
||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))?;
|
||||
.map_err(|e| Error::new(ErrorKind::InvalidData, e))?;
|
||||
|
||||
match self.transport.read_message() {
|
||||
Ok(response) => match response.header().command() {
|
||||
MessageCommand::Okay => Ok(buf.len()),
|
||||
c => Err(std::io::Error::new(
|
||||
ErrorKind::Other,
|
||||
format!("wrong response received: {c}"),
|
||||
)),
|
||||
},
|
||||
Err(e) => Err(std::io::Error::new(ErrorKind::Other, e)),
|
||||
Ok(response) => {
|
||||
response
|
||||
.assert_command(MessageCommand::Okay)
|
||||
.map_err(|e| Error::new(ErrorKind::Other, e))?;
|
||||
Ok(buf.len())
|
||||
}
|
||||
Err(e) => Err(Error::new(ErrorKind::Other, e)),
|
||||
}
|
||||
}
|
||||
|
||||
fn flush(&mut self) -> std::io::Result<()> {
|
||||
fn flush(&mut self) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ mod shell_message_writer;
|
||||
use adb_message_device::ADBMessageDevice;
|
||||
pub use adb_tcp_device::ADBTcpDevice;
|
||||
pub use adb_transport_message::{ADBTransportMessage, ADBTransportMessageHeader};
|
||||
pub use adb_usb_device::{get_default_adb_key_path, ADBUSBDevice};
|
||||
pub use adb_usb_device::{ADBUSBDevice, get_default_adb_key_path};
|
||||
pub use message_writer::MessageWriter;
|
||||
pub use models::{ADBRsaKey, MessageCommand, MessageSubcommand};
|
||||
pub use shell_message_writer::ShellMessageWriter;
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
use crate::{Result, RustADBError};
|
||||
use base64::{engine::general_purpose::STANDARD, Engine};
|
||||
use base64::{Engine, engine::general_purpose::STANDARD};
|
||||
use num_bigint::{BigUint, ModInverse};
|
||||
use num_traits::cast::ToPrimitive;
|
||||
use num_traits::FromPrimitive;
|
||||
use rand::rngs::OsRng;
|
||||
use num_traits::cast::ToPrimitive;
|
||||
use rsa::pkcs8::DecodePrivateKey;
|
||||
use rsa::traits::PublicKeyParts;
|
||||
use rsa::{Pkcs1v15Sign, RsaPrivateKey};
|
||||
@@ -52,7 +51,7 @@ pub struct ADBRsaKey {
|
||||
impl ADBRsaKey {
|
||||
pub fn new_random() -> Result<Self> {
|
||||
Ok(Self {
|
||||
private_key: RsaPrivateKey::new(&mut OsRng, ADB_PRIVATE_KEY_SIZE)?,
|
||||
private_key: RsaPrivateKey::new(&mut rsa::rand_core::OsRng, ADB_PRIVATE_KEY_SIZE)?,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -6,18 +6,17 @@ use std::fmt::Display;
|
||||
#[repr(u32)]
|
||||
pub enum MessageCommand {
|
||||
/// Connect to a device
|
||||
Cnxn = 0x4e584e43,
|
||||
Cnxn = 0x4E584E43,
|
||||
/// Close connection to a device
|
||||
Clse = 0x45534c43,
|
||||
Clse = 0x45534C43,
|
||||
/// Device ask for authentication
|
||||
Auth = 0x48545541,
|
||||
/// Open a data connection
|
||||
Open = 0x4e45504f,
|
||||
Open = 0x4E45504F,
|
||||
/// Write data to connection
|
||||
Write = 0x45545257,
|
||||
/// Server understood the message
|
||||
Okay = 0x59414b4f,
|
||||
// Sync 0x434e5953
|
||||
Okay = 0x59414B4F,
|
||||
/// Start a connection using TLS
|
||||
Stls = 0x534C5453,
|
||||
}
|
||||
@@ -29,10 +28,10 @@ pub enum MessageSubcommand {
|
||||
Send = 0x444E4553,
|
||||
Recv = 0x56434552,
|
||||
Quit = 0x54495551,
|
||||
Fail = 0x4c494146,
|
||||
Done = 0x454e4f44,
|
||||
Fail = 0x4C494146,
|
||||
Done = 0x454E4F44,
|
||||
Data = 0x41544144,
|
||||
List = 0x5453494c,
|
||||
List = 0x5453494C,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
|
||||
@@ -2,7 +2,7 @@ use std::io::Write;
|
||||
|
||||
use crate::ADBMessageTransport;
|
||||
|
||||
use super::{models::MessageCommand, ADBTransportMessage};
|
||||
use super::{ADBTransportMessage, models::MessageCommand};
|
||||
|
||||
/// [`Write`] trait implementation to hide underlying ADB protocol write logic for shell commands.
|
||||
pub struct ShellMessageWriter<T: ADBMessageTransport> {
|
||||
@@ -23,12 +23,8 @@ impl<T: ADBMessageTransport> ShellMessageWriter<T> {
|
||||
|
||||
impl<T: ADBMessageTransport> Write for ShellMessageWriter<T> {
|
||||
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
|
||||
let message = ADBTransportMessage::new(
|
||||
MessageCommand::Write,
|
||||
self.local_id,
|
||||
self.remote_id,
|
||||
buf.to_vec(),
|
||||
);
|
||||
let message =
|
||||
ADBTransportMessage::new(MessageCommand::Write, self.local_id, self.remote_id, buf);
|
||||
self.transport
|
||||
.write_message(message)
|
||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))?;
|
||||
|
||||
@@ -65,10 +65,15 @@ impl TryFrom<ADBServerDevice> for ADBEmulatorDevice {
|
||||
type Error = RustADBError;
|
||||
|
||||
fn try_from(value: ADBServerDevice) -> std::result::Result<Self, Self::Error> {
|
||||
ADBEmulatorDevice::new(
|
||||
value.identifier.clone(),
|
||||
Some(*value.get_transport().get_socketaddr().ip()),
|
||||
)
|
||||
match &value.identifier {
|
||||
Some(device_identifier) => ADBEmulatorDevice::new(
|
||||
device_identifier.clone(),
|
||||
Some(*value.transport.get_socketaddr().ip()),
|
||||
),
|
||||
None => Err(RustADBError::DeviceNotFound(
|
||||
"cannot connect to an emulator device without knowing its identifier".to_string(),
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
use crate::{models::ADBEmulatorCommand, ADBEmulatorDevice, Result};
|
||||
use crate::{ADBEmulatorDevice, Result, emulator_device::ADBEmulatorCommand};
|
||||
|
||||
impl ADBEmulatorDevice {
|
||||
/// Send a SMS to this emulator with given content with given phone number
|
||||
pub fn rotate(&mut self) -> Result<()> {
|
||||
let transport = self.connect()?;
|
||||
transport.send_command(ADBEmulatorCommand::Rotate)?;
|
||||
Ok(())
|
||||
self.connect()?.send_command(ADBEmulatorCommand::Rotate)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
use crate::{models::ADBEmulatorCommand, ADBEmulatorDevice, Result};
|
||||
use crate::{ADBEmulatorDevice, Result, emulator_device::ADBEmulatorCommand};
|
||||
|
||||
impl ADBEmulatorDevice {
|
||||
/// Send a SMS to this emulator with given content with given phone number
|
||||
pub fn send_sms(&mut self, phone_number: &str, content: &str) -> Result<()> {
|
||||
let transport = self.connect()?;
|
||||
transport.send_command(ADBEmulatorCommand::Sms(
|
||||
self.connect()?.send_command(ADBEmulatorCommand::Sms(
|
||||
phone_number.to_string(),
|
||||
content.to_string(),
|
||||
))?;
|
||||
Ok(())
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
mod adb_emulator_device;
|
||||
mod commands;
|
||||
mod models;
|
||||
pub use adb_emulator_device::ADBEmulatorDevice;
|
||||
pub(crate) use models::ADBEmulatorCommand;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
pub(crate) enum ADBEmulatorCommand {
|
||||
pub enum ADBEmulatorCommand {
|
||||
Authenticate(String),
|
||||
Sms(String, String),
|
||||
Rotate,
|
||||
2
adb_client/src/emulator_device/models/mod.rs
Normal file
2
adb_client/src/emulator_device/models/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
mod adb_emulator_command;
|
||||
pub use adb_emulator_command::ADBEmulatorCommand;
|
||||
@@ -15,6 +15,9 @@ pub enum RustADBError {
|
||||
/// Indicates that ADB server responded an unknown response type.
|
||||
#[error("Unknown response type {0}")]
|
||||
UnknownResponseType(String),
|
||||
/// Indicated that an unexpected command has been received
|
||||
#[error("Wrong response command received: {0}. Expected {1}")]
|
||||
WrongResponseReceived(String, String),
|
||||
/// Indicates that ADB server responses an unknown device state.
|
||||
#[error("Unknown device state {0}")]
|
||||
UnknownDeviceState(String),
|
||||
@@ -64,7 +67,7 @@ pub enum RustADBError {
|
||||
#[error("Cannot get home directory")]
|
||||
NoHomeDirectory,
|
||||
/// Generic USB error
|
||||
#[error(transparent)]
|
||||
#[error("USB Error: {0}")]
|
||||
UsbError(#[from] rusb::Error),
|
||||
/// USB device not found
|
||||
#[error("USB Device not found: {0} {1}")]
|
||||
@@ -114,6 +117,9 @@ pub enum RustADBError {
|
||||
/// An error occurred while sending data to channel
|
||||
#[error(transparent)]
|
||||
SendError(#[from] std::sync::mpsc::SendError<crate::MDNSDevice>),
|
||||
/// An unknown transport has been provided
|
||||
#[error("unknown transport: {0}")]
|
||||
UnknownTransport(String),
|
||||
}
|
||||
|
||||
impl<T> From<std::sync::PoisonError<T>> for RustADBError {
|
||||
|
||||
@@ -21,9 +21,7 @@ pub use device::{ADBTcpDevice, ADBUSBDevice};
|
||||
pub use emulator_device::ADBEmulatorDevice;
|
||||
pub use error::{Result, RustADBError};
|
||||
pub use mdns::*;
|
||||
pub use models::{
|
||||
AdbStatResponse, AdbVersion, DeviceLong, DeviceShort, DeviceState, MDNSBackend, RebootType,
|
||||
};
|
||||
pub use models::{AdbStatResponse, RebootType};
|
||||
pub use server::*;
|
||||
pub use server_device::ADBServerDevice;
|
||||
pub use transports::*;
|
||||
|
||||
@@ -33,19 +33,21 @@ impl MDNSDiscoveryService {
|
||||
pub fn start(&mut self, sender: Sender<MDNSDevice>) -> Result<()> {
|
||||
let receiver = self.daemon.browse(ADB_SERVICE_NAME)?;
|
||||
|
||||
let handle: JoinHandle<Result<()>> = std::thread::spawn(move || loop {
|
||||
while let Ok(event) = receiver.recv() {
|
||||
match event {
|
||||
ServiceEvent::SearchStarted(_)
|
||||
| ServiceEvent::ServiceRemoved(_, _)
|
||||
| ServiceEvent::ServiceFound(_, _)
|
||||
| ServiceEvent::SearchStopped(_) => {
|
||||
// Ignoring these events. We are only interesting in found devices
|
||||
continue;
|
||||
}
|
||||
ServiceEvent::ServiceResolved(service_info) => {
|
||||
if let Err(e) = sender.send(MDNSDevice::from(service_info)) {
|
||||
return Err(e.into());
|
||||
let handle: JoinHandle<Result<()>> = std::thread::spawn(move || {
|
||||
loop {
|
||||
while let Ok(event) = receiver.recv() {
|
||||
match event {
|
||||
ServiceEvent::SearchStarted(_)
|
||||
| ServiceEvent::ServiceRemoved(_, _)
|
||||
| ServiceEvent::ServiceFound(_, _)
|
||||
| ServiceEvent::SearchStopped(_) => {
|
||||
// Ignoring these events. We are only interesting in found devices
|
||||
continue;
|
||||
}
|
||||
ServiceEvent::ServiceResolved(service_info) => {
|
||||
if let Err(e) = sender.send(MDNSDevice::from(service_info)) {
|
||||
return Err(e.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
use crate::{WaitForDeviceState, WaitForDeviceTransport};
|
||||
|
||||
use super::RebootType;
|
||||
use std::net::SocketAddrV4;
|
||||
|
||||
@@ -20,7 +22,9 @@ pub(crate) enum AdbServerCommand {
|
||||
MDNSServices,
|
||||
ServerStatus,
|
||||
ReconnectOffline,
|
||||
Uninstall(String),
|
||||
Install(u64),
|
||||
WaitForDevice(WaitForDeviceState, WaitForDeviceTransport),
|
||||
// Local commands
|
||||
ShellCommand(String),
|
||||
Shell,
|
||||
@@ -83,6 +87,15 @@ impl Display for AdbServerCommand {
|
||||
}
|
||||
AdbServerCommand::Usb => write!(f, "usb:"),
|
||||
AdbServerCommand::Install(size) => write!(f, "exec:cmd package 'install' -S {size}"),
|
||||
AdbServerCommand::Uninstall(package) => {
|
||||
write!(f, "exec:cmd package 'uninstall' {package}")
|
||||
}
|
||||
AdbServerCommand::WaitForDevice(wait_for_device_state, wait_for_device_transport) => {
|
||||
write!(
|
||||
f,
|
||||
"host:wait-for-{wait_for_device_transport}-{wait_for_device_state}"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
97
adb_client/src/models/framebuffer_info.rs
Normal file
97
adb_client/src/models/framebuffer_info.rs
Normal file
@@ -0,0 +1,97 @@
|
||||
use std::{iter::Map, slice::ChunksExact};
|
||||
|
||||
use byteorder::{ByteOrder, LittleEndian};
|
||||
|
||||
use crate::{Result, RustADBError};
|
||||
|
||||
type U32ChunkIter<'a> = Map<ChunksExact<'a, u8>, fn(&[u8]) -> Result<u32>>;
|
||||
|
||||
fn read_next(chunks: &mut U32ChunkIter) -> Result<u32> {
|
||||
chunks
|
||||
.next()
|
||||
.ok_or(RustADBError::FramebufferConversionError)?
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct FrameBufferInfoV1 {
|
||||
pub _bpp: u32,
|
||||
pub size: u32,
|
||||
pub width: u32,
|
||||
pub height: u32,
|
||||
pub _red_offset: u32,
|
||||
pub _red_length: u32,
|
||||
pub _blue_offset: u32,
|
||||
pub _blue_length: u32,
|
||||
pub _green_offset: u32,
|
||||
pub _green_length: u32,
|
||||
pub _alpha_offset: u32,
|
||||
pub _alpha_length: u32,
|
||||
}
|
||||
|
||||
impl TryFrom<[u8; std::mem::size_of::<Self>()]> for FrameBufferInfoV1 {
|
||||
type Error = RustADBError;
|
||||
|
||||
fn try_from(
|
||||
value: [u8; std::mem::size_of::<Self>()],
|
||||
) -> std::result::Result<Self, Self::Error> {
|
||||
let mut chunks: U32ChunkIter = value.chunks_exact(4).map(|v| Ok(LittleEndian::read_u32(v)));
|
||||
|
||||
Ok(Self {
|
||||
_bpp: read_next(&mut chunks)?,
|
||||
size: read_next(&mut chunks)?,
|
||||
width: read_next(&mut chunks)?,
|
||||
height: read_next(&mut chunks)?,
|
||||
_red_offset: read_next(&mut chunks)?,
|
||||
_red_length: read_next(&mut chunks)?,
|
||||
_blue_offset: read_next(&mut chunks)?,
|
||||
_blue_length: read_next(&mut chunks)?,
|
||||
_green_offset: read_next(&mut chunks)?,
|
||||
_green_length: read_next(&mut chunks)?,
|
||||
_alpha_offset: read_next(&mut chunks)?,
|
||||
_alpha_length: read_next(&mut chunks)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct FrameBufferInfoV2 {
|
||||
pub _bpp: u32,
|
||||
pub _color_space: u32,
|
||||
pub size: u32,
|
||||
pub width: u32,
|
||||
pub height: u32,
|
||||
pub _red_offset: u32,
|
||||
pub _red_length: u32,
|
||||
pub _blue_offset: u32,
|
||||
pub _blue_length: u32,
|
||||
pub _green_offset: u32,
|
||||
pub _green_length: u32,
|
||||
pub _alpha_offset: u32,
|
||||
pub _alpha_length: u32,
|
||||
}
|
||||
|
||||
impl TryFrom<[u8; std::mem::size_of::<Self>()]> for FrameBufferInfoV2 {
|
||||
type Error = RustADBError;
|
||||
|
||||
fn try_from(
|
||||
value: [u8; std::mem::size_of::<Self>()],
|
||||
) -> std::result::Result<Self, Self::Error> {
|
||||
let mut chunks: U32ChunkIter = value.chunks_exact(4).map(|v| Ok(LittleEndian::read_u32(v)));
|
||||
|
||||
Ok(Self {
|
||||
_bpp: read_next(&mut chunks)?,
|
||||
_color_space: read_next(&mut chunks)?,
|
||||
size: read_next(&mut chunks)?,
|
||||
width: read_next(&mut chunks)?,
|
||||
height: read_next(&mut chunks)?,
|
||||
_red_offset: read_next(&mut chunks)?,
|
||||
_red_length: read_next(&mut chunks)?,
|
||||
_blue_offset: read_next(&mut chunks)?,
|
||||
_blue_length: read_next(&mut chunks)?,
|
||||
_green_offset: read_next(&mut chunks)?,
|
||||
_green_length: read_next(&mut chunks)?,
|
||||
_alpha_offset: read_next(&mut chunks)?,
|
||||
_alpha_length: read_next(&mut chunks)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,15 @@
|
||||
mod adb_emulator_command;
|
||||
mod adb_request_status;
|
||||
mod adb_server_command;
|
||||
mod adb_stat_response;
|
||||
mod adb_version;
|
||||
mod device_long;
|
||||
mod device_short;
|
||||
mod device_state;
|
||||
mod framebuffer_info;
|
||||
mod host_features;
|
||||
mod mdns_services;
|
||||
mod reboot_type;
|
||||
mod server_status;
|
||||
mod sync_command;
|
||||
|
||||
pub(crate) use adb_emulator_command::ADBEmulatorCommand;
|
||||
pub use adb_request_status::AdbRequestStatus;
|
||||
pub(crate) use adb_server_command::AdbServerCommand;
|
||||
pub use adb_stat_response::AdbStatResponse;
|
||||
pub use adb_version::AdbVersion;
|
||||
pub use device_long::DeviceLong;
|
||||
pub use device_short::DeviceShort;
|
||||
pub use device_state::DeviceState;
|
||||
pub(crate) use framebuffer_info::{FrameBufferInfoV1, FrameBufferInfoV2};
|
||||
pub use host_features::HostFeatures;
|
||||
pub use mdns_services::MDNSServices;
|
||||
pub use reboot_type::RebootType;
|
||||
pub use server_status::MDNSBackend;
|
||||
pub use server_status::ServerStatus;
|
||||
pub use sync_command::SyncCommand;
|
||||
|
||||
@@ -13,6 +13,8 @@ pub enum RebootType {
|
||||
Sideload,
|
||||
/// Same as `Sideload` but reboots after sideloading
|
||||
SideloadAutoReboot,
|
||||
/// Reboots to fastboot
|
||||
Fastboot,
|
||||
}
|
||||
|
||||
impl Display for RebootType {
|
||||
@@ -23,6 +25,7 @@ impl Display for RebootType {
|
||||
RebootType::Recovery => write!(f, "recovery"),
|
||||
RebootType::Sideload => write!(f, "sideload"),
|
||||
RebootType::SideloadAutoReboot => write!(f, "sideload-auto-reboot"),
|
||||
RebootType::Fastboot => write!(f, "fastboot"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,9 @@ pub struct ADBServer {
|
||||
pub(crate) socket_addr: Option<SocketAddrV4>,
|
||||
/// adb-server start envs
|
||||
pub(crate) envs: HashMap<String, String>,
|
||||
/// Path to adb binary
|
||||
/// If not set, will use adb from PATH
|
||||
pub(crate) adb_path: Option<String>,
|
||||
}
|
||||
|
||||
impl ADBServer {
|
||||
@@ -24,6 +27,44 @@ impl ADBServer {
|
||||
transport: None,
|
||||
socket_addr: Some(address),
|
||||
envs: HashMap::new(),
|
||||
adb_path: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Instantiates a new [ADBServer] with a custom adb path
|
||||
pub fn new_from_path(address: SocketAddrV4, adb_path: Option<String>) -> Self {
|
||||
Self {
|
||||
transport: None,
|
||||
socket_addr: Some(address),
|
||||
envs: HashMap::new(),
|
||||
adb_path,
|
||||
}
|
||||
}
|
||||
|
||||
/// Start an instance of `adb-server`
|
||||
pub fn start(envs: &HashMap<String, String>, adb_path: &Option<String>) {
|
||||
// ADB Server is local, we start it if not already running
|
||||
let mut command = Command::new(adb_path.as_deref().unwrap_or("adb"));
|
||||
command.arg("start-server");
|
||||
for (env_k, env_v) in envs.iter() {
|
||||
command.env(env_k, env_v);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
use std::os::windows::process::CommandExt;
|
||||
// Do not show a prompt on Windows
|
||||
command.creation_flags(0x08000000);
|
||||
}
|
||||
|
||||
let child = command.spawn();
|
||||
match child {
|
||||
Ok(mut child) => {
|
||||
if let Err(e) = child.wait() {
|
||||
log::error!("error while starting adb server: {e}")
|
||||
}
|
||||
}
|
||||
Err(e) => log::error!("error while starting adb server: {e}"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,22 +93,7 @@ impl ADBServer {
|
||||
};
|
||||
|
||||
if is_local_ip {
|
||||
// ADB Server is local, we start it if not already running
|
||||
let mut command = Command::new("adb");
|
||||
command.arg("start-server");
|
||||
for (env_k, env_v) in self.envs.iter() {
|
||||
command.env(env_k, env_v);
|
||||
}
|
||||
|
||||
let child = command.spawn();
|
||||
match child {
|
||||
Ok(mut child) => {
|
||||
if let Err(e) = child.wait() {
|
||||
log::error!("error while starting adb server: {e}")
|
||||
}
|
||||
}
|
||||
Err(e) => log::error!("error while starting adb server: {e}"),
|
||||
}
|
||||
Self::start(&self.envs, &self.adb_path);
|
||||
}
|
||||
|
||||
transport.connect()?;
|
||||
@@ -79,7 +105,7 @@ impl ADBServer {
|
||||
|
||||
impl Drop for ADBServer {
|
||||
fn drop(&mut self) {
|
||||
if let Some(ref mut transport) = &mut self.transport {
|
||||
if let Some(transport) = &mut self.transport {
|
||||
let _ = transport.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::{models::AdbServerCommand, ADBServer, Result, RustADBError};
|
||||
use crate::{ADBServer, Result, RustADBError, models::AdbServerCommand};
|
||||
use std::net::SocketAddrV4;
|
||||
|
||||
impl ADBServer {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use std::io::Read;
|
||||
|
||||
use crate::{
|
||||
models::{AdbServerCommand, DeviceShort},
|
||||
ADBEmulatorDevice, ADBServer, ADBServerDevice, DeviceLong, Result, RustADBError,
|
||||
ADBEmulatorDevice, ADBServer, ADBServerDevice, DeviceLong, DeviceShort, Result, RustADBError,
|
||||
models::AdbServerCommand,
|
||||
};
|
||||
|
||||
impl ADBServer {
|
||||
@@ -36,7 +36,7 @@ impl ADBServer {
|
||||
break;
|
||||
}
|
||||
|
||||
vec_devices.push(DeviceLong::try_from(device.to_vec())?);
|
||||
vec_devices.push(DeviceLong::try_from(device)?);
|
||||
}
|
||||
|
||||
Ok(vec_devices)
|
||||
@@ -97,7 +97,12 @@ impl ADBServer {
|
||||
.get_raw_connection()?
|
||||
.read_exact(&mut body)?;
|
||||
|
||||
callback(DeviceShort::try_from(body)?)?;
|
||||
for device in body.split(|x| x.eq(&b'\n')) {
|
||||
if device.is_empty() {
|
||||
break;
|
||||
}
|
||||
callback(DeviceShort::try_from(device.to_vec())?)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::{models::AdbServerCommand, ADBServer, Result, RustADBError};
|
||||
use crate::{ADBServer, Result, RustADBError, models::AdbServerCommand};
|
||||
use std::net::SocketAddrV4;
|
||||
|
||||
impl ADBServer {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::{models::AdbServerCommand, ADBServer, Result};
|
||||
use crate::{ADBServer, Result, models::AdbServerCommand};
|
||||
|
||||
impl ADBServer {
|
||||
/// Asks the ADB server to quit immediately.
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
use std::io::BufRead;
|
||||
|
||||
use crate::{
|
||||
models::{AdbServerCommand, MDNSBackend, MDNSServices},
|
||||
ADBServer, Result,
|
||||
ADBServer, MDNSServices, Result, models::AdbServerCommand, server::models::MDNSBackend,
|
||||
};
|
||||
|
||||
const OPENSCREEN_MDNS_BACKEND: &str = "ADB_MDNS_OPENSCREEN";
|
||||
|
||||
@@ -7,3 +7,4 @@ mod pair;
|
||||
mod reconnect;
|
||||
mod server_status;
|
||||
mod version;
|
||||
mod wait_for_device;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::{models::AdbServerCommand, ADBServer, Result};
|
||||
use crate::{ADBServer, Result, models::AdbServerCommand};
|
||||
|
||||
impl ADBServer {
|
||||
/// Reconnect the device
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
use crate::{
|
||||
models::{AdbServerCommand, ServerStatus},
|
||||
ADBServer, Result,
|
||||
};
|
||||
use crate::{ADBServer, Result, models::AdbServerCommand, server::models::ServerStatus};
|
||||
|
||||
impl ADBServer {
|
||||
/// Check ADB server status
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::{models::AdbServerCommand, ADBServer, AdbVersion, Result};
|
||||
use crate::{ADBServer, AdbVersion, Result, models::AdbServerCommand};
|
||||
|
||||
impl ADBServer {
|
||||
/// Gets server's internal version number.
|
||||
|
||||
20
adb_client/src/server/commands/wait_for_device.rs
Normal file
20
adb_client/src/server/commands/wait_for_device.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
use crate::{
|
||||
ADBServer, Result, WaitForDeviceState, WaitForDeviceTransport, models::AdbServerCommand,
|
||||
};
|
||||
|
||||
impl ADBServer {
|
||||
/// Wait for a device in a given state to be connected
|
||||
pub fn wait_for_device(
|
||||
&mut self,
|
||||
state: WaitForDeviceState,
|
||||
transport: Option<WaitForDeviceTransport>,
|
||||
) -> Result<()> {
|
||||
let transport = transport.unwrap_or_default();
|
||||
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::WaitForDevice(state, transport))?;
|
||||
|
||||
// Server should respond with an "OKAY" response
|
||||
self.get_transport()?.read_adb_response()
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
mod adb_server;
|
||||
mod commands;
|
||||
mod models;
|
||||
|
||||
pub use adb_server::ADBServer;
|
||||
pub use models::*;
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::{DeviceState, RustADBError};
|
||||
use regex::bytes::Regex;
|
||||
|
||||
static DEVICES_LONG_REGEX: LazyLock<Regex> = LazyLock::new(|| {
|
||||
Regex::new("^(?P<identifier>\\S+)\\s+(?P<state>\\w+) ((usb:(?P<usb1>.*)|(?P<usb2>\\d-\\d)) )?(product:(?P<product>\\w+) model:(?P<model>\\w+) device:(?P<device>\\w+) )?transport_id:(?P<transport_id>\\d+)$").expect("cannot build devices long regex")
|
||||
Regex::new(r"^(?P<identifier>\S+)\s+(?P<state>\w+)\s+(usb:(?P<usb1>\S+)|(?P<usb2>\S+))?\s*(product:(?P<product>\S+)\s+model:(?P<model>\w+)\s+device:(?P<device>\S+)\s+)?transport_id:(?P<transport_id>\d+)$").expect("cannot build devices long regex")
|
||||
});
|
||||
|
||||
/// Represents a new device with more informations.
|
||||
@@ -44,12 +44,12 @@ impl Display for DeviceLong {
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Vec<u8>> for DeviceLong {
|
||||
impl TryFrom<&[u8]> for DeviceLong {
|
||||
type Error = RustADBError;
|
||||
|
||||
fn try_from(value: Vec<u8>) -> Result<Self, Self::Error> {
|
||||
fn try_from(value: &[u8]) -> Result<Self, Self::Error> {
|
||||
let groups = DEVICES_LONG_REGEX
|
||||
.captures(&value)
|
||||
.captures(value)
|
||||
.ok_or(RustADBError::RegexParsingError)?;
|
||||
|
||||
Ok(DeviceLong {
|
||||
@@ -98,3 +98,17 @@ impl TryFrom<Vec<u8>> for DeviceLong {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_static_devices_long() {
|
||||
let inputs = [
|
||||
"7a5158f05122195aa device 1-5 product:gts210vewifixx model:SM_T813 device:gts210vewifi transport_id:4",
|
||||
"n311r05e device usb:0-1.5 product:alioth model:M2012K11AC device:alioth transport_id:58",
|
||||
"192.168.100.192:5555 device product:alioth model:M2012K11AC device:alioth transport_id:97",
|
||||
"emulator-5554 device product:sdk_gphone64_arm64 model:sdk_gphone64_arm64 device:emu64a transport_id:101",
|
||||
"QQ20131020250511 device 20-4 product:NOH-AN00 model:NOH_AN00 device:HWNOH transport_id:3",
|
||||
];
|
||||
for input in inputs {
|
||||
DeviceLong::try_from(input.as_bytes()).expect(&format!("cannot parse input: '{input}'"));
|
||||
}
|
||||
}
|
||||
15
adb_client/src/server/models/mod.rs
Normal file
15
adb_client/src/server/models/mod.rs
Normal file
@@ -0,0 +1,15 @@
|
||||
mod adb_version;
|
||||
mod device_long;
|
||||
mod device_short;
|
||||
mod device_state;
|
||||
mod mdns_services;
|
||||
mod server_status;
|
||||
mod wait_for_device;
|
||||
|
||||
pub use adb_version::AdbVersion;
|
||||
pub use device_long::DeviceLong;
|
||||
pub use device_short::DeviceShort;
|
||||
pub use device_state::DeviceState;
|
||||
pub use mdns_services::MDNSServices;
|
||||
pub use server_status::{MDNSBackend, ServerStatus};
|
||||
pub use wait_for_device::{WaitForDeviceState, WaitForDeviceTransport};
|
||||
@@ -91,14 +91,23 @@ impl Display for MDNSBackend {
|
||||
/// Structure representing current server status
|
||||
#[derive(Debug, Clone, Default, PartialEq)]
|
||||
pub struct ServerStatus {
|
||||
/// Currently active USB backend
|
||||
pub usb_backend: UsbBackend,
|
||||
/// Is USB backend forced ?
|
||||
pub usb_backend_forced: bool,
|
||||
/// Currently active MDNS backend
|
||||
pub mdns_backend: MDNSBackend,
|
||||
/// Is MDNS backend forced ?
|
||||
pub mdns_backend_forced: bool,
|
||||
/// Server version
|
||||
pub version: String,
|
||||
/// Server build information
|
||||
pub build: String,
|
||||
/// Server executable absolute path
|
||||
pub executable_absolute_path: String,
|
||||
/// Server logs absolute path
|
||||
pub log_absolute_path: String,
|
||||
/// OS server is running on
|
||||
pub os: String,
|
||||
}
|
||||
|
||||
67
adb_client/src/server/models/wait_for_device.rs
Normal file
67
adb_client/src/server/models/wait_for_device.rs
Normal file
@@ -0,0 +1,67 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
use crate::RustADBError;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
/// List of available transports to wait for.
|
||||
pub enum WaitForDeviceTransport {
|
||||
/// USB transport
|
||||
Usb,
|
||||
/// Local transport
|
||||
Local,
|
||||
/// Any transport (default value)
|
||||
Any,
|
||||
}
|
||||
|
||||
impl Default for WaitForDeviceTransport {
|
||||
fn default() -> Self {
|
||||
Self::Any
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for WaitForDeviceTransport {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
WaitForDeviceTransport::Usb => write!(f, "usb"),
|
||||
WaitForDeviceTransport::Local => write!(f, "local"),
|
||||
WaitForDeviceTransport::Any => write!(f, "any"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<&str> for WaitForDeviceTransport {
|
||||
type Error = RustADBError;
|
||||
|
||||
fn try_from(value: &str) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
"usb" => Ok(Self::Usb),
|
||||
"local" => Ok(Self::Local),
|
||||
"any" => Ok(Self::Any),
|
||||
t => Err(RustADBError::UnknownTransport(t.to_string())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
/// List of available states to wait for.
|
||||
pub enum WaitForDeviceState {
|
||||
/// Device in "device" state
|
||||
Device,
|
||||
/// Device in "recovery" state
|
||||
Recovery,
|
||||
/// Device in "sideload" state
|
||||
Sideload,
|
||||
/// Device in "bootloader" state
|
||||
Bootloader,
|
||||
}
|
||||
|
||||
impl Display for WaitForDeviceState {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
WaitForDeviceState::Device => write!(f, "device"),
|
||||
WaitForDeviceState::Recovery => write!(f, "recovery"),
|
||||
WaitForDeviceState::Sideload => write!(f, "sideload"),
|
||||
WaitForDeviceState::Bootloader => write!(f, "bootloader"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,43 +1,54 @@
|
||||
use crate::{ADBTransport, Result, TCPServerTransport};
|
||||
use crate::{ADBTransport, Result, TCPServerTransport, models::AdbServerCommand};
|
||||
use std::net::SocketAddrV4;
|
||||
|
||||
/// Represents a device connected to the ADB server.
|
||||
#[derive(Debug)]
|
||||
pub struct ADBServerDevice {
|
||||
/// Unique device identifier.
|
||||
pub identifier: String,
|
||||
pub identifier: Option<String>,
|
||||
/// Internal [TCPServerTransport]
|
||||
transport: TCPServerTransport,
|
||||
pub(crate) transport: TCPServerTransport,
|
||||
}
|
||||
|
||||
impl ADBServerDevice {
|
||||
/// Instantiates a new [ADBServerDevice]
|
||||
pub fn new(identifier: String, socket_addr: Option<SocketAddrV4>) -> Self {
|
||||
let transport = if let Some(addr) = socket_addr {
|
||||
TCPServerTransport::new(addr)
|
||||
} else {
|
||||
TCPServerTransport::default()
|
||||
};
|
||||
/// Instantiates a new [ADBServerDevice], knowing its ADB identifier (as returned by `adb devices` command).
|
||||
pub fn new(identifier: String, server_addr: Option<SocketAddrV4>) -> Self {
|
||||
let transport = TCPServerTransport::new_or_default(server_addr);
|
||||
|
||||
Self {
|
||||
identifier,
|
||||
identifier: Some(identifier),
|
||||
transport,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn get_transport(&self) -> &TCPServerTransport {
|
||||
&self.transport
|
||||
}
|
||||
/// Instantiates a new [ADBServerDevice], assuming only one is currently connected.
|
||||
pub fn autodetect(server_addr: Option<SocketAddrV4>) -> Self {
|
||||
let transport = TCPServerTransport::new_or_default(server_addr);
|
||||
|
||||
pub(crate) fn get_transport_mut(&mut self) -> &mut TCPServerTransport {
|
||||
&mut self.transport
|
||||
Self {
|
||||
identifier: None,
|
||||
transport,
|
||||
}
|
||||
}
|
||||
|
||||
/// Connect to underlying transport
|
||||
pub(crate) fn connect(&mut self) -> Result<&mut TCPServerTransport> {
|
||||
self.transport.connect()?;
|
||||
|
||||
Ok(self.get_transport_mut())
|
||||
Ok(&mut self.transport)
|
||||
}
|
||||
|
||||
/// Set device connection to use serial transport
|
||||
pub(crate) fn set_serial_transport(&mut self) -> Result<()> {
|
||||
let identifier = self.identifier.clone();
|
||||
let transport = self.connect()?;
|
||||
if let Some(serial) = identifier {
|
||||
transport.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
||||
} else {
|
||||
transport.send_adb_request(AdbServerCommand::TransportAny)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +1,18 @@
|
||||
use std::{
|
||||
io::{Read, Write},
|
||||
io::{ErrorKind, Read, Write},
|
||||
path::Path,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
ADBDeviceExt, Result, RustADBError,
|
||||
constants::BUFFER_SIZE,
|
||||
models::{AdbServerCommand, AdbStatResponse, HostFeatures},
|
||||
ADBDeviceExt, Result, RustADBError,
|
||||
};
|
||||
|
||||
use super::ADBServerDevice;
|
||||
|
||||
impl ADBDeviceExt for ADBServerDevice {
|
||||
fn shell_command<S: ToString, W: Write>(
|
||||
&mut self,
|
||||
command: impl IntoIterator<Item = S>,
|
||||
mut output: W,
|
||||
) -> Result<()> {
|
||||
fn shell_command(&mut self, command: &[&str], output: &mut dyn Write) -> Result<()> {
|
||||
let supported_features = self.host_features()?;
|
||||
if !supported_features.contains(&HostFeatures::ShellV2)
|
||||
&& !supported_features.contains(&HostFeatures::Cmd)
|
||||
@@ -24,26 +20,14 @@ impl ADBDeviceExt for ADBServerDevice {
|
||||
return Err(RustADBError::ADBShellNotSupported);
|
||||
}
|
||||
|
||||
let serial = self.identifier.clone();
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
||||
self.get_transport_mut()
|
||||
.send_adb_request(AdbServerCommand::ShellCommand(
|
||||
command
|
||||
.into_iter()
|
||||
.map(|v| v.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join(" "),
|
||||
))?;
|
||||
self.set_serial_transport()?;
|
||||
|
||||
self.transport
|
||||
.send_adb_request(AdbServerCommand::ShellCommand(command.join(" ")))?;
|
||||
|
||||
const BUFFER_SIZE: usize = 4096;
|
||||
loop {
|
||||
let mut buffer = [0; BUFFER_SIZE];
|
||||
match self
|
||||
.get_transport_mut()
|
||||
.get_raw_connection()?
|
||||
.read(&mut buffer)
|
||||
{
|
||||
match self.transport.get_raw_connection()?.read(&mut buffer) {
|
||||
Ok(size) => {
|
||||
if size == 0 {
|
||||
return Ok(());
|
||||
@@ -62,10 +46,10 @@ impl ADBDeviceExt for ADBServerDevice {
|
||||
self.stat(remote_path)
|
||||
}
|
||||
|
||||
fn shell<R: Read, W: Write + Send + 'static>(
|
||||
fn shell(
|
||||
&mut self,
|
||||
mut reader: R,
|
||||
mut writer: W,
|
||||
mut reader: &mut dyn Read,
|
||||
mut writer: Box<(dyn Write + Send)>,
|
||||
) -> Result<()> {
|
||||
let supported_features = self.host_features()?;
|
||||
if !supported_features.contains(&HostFeatures::ShellV2)
|
||||
@@ -74,13 +58,10 @@ impl ADBDeviceExt for ADBServerDevice {
|
||||
return Err(RustADBError::ADBShellNotSupported);
|
||||
}
|
||||
|
||||
let serial = self.identifier.clone();
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
||||
self.get_transport_mut()
|
||||
.send_adb_request(AdbServerCommand::Shell)?;
|
||||
self.set_serial_transport()?;
|
||||
self.transport.send_adb_request(AdbServerCommand::Shell)?;
|
||||
|
||||
let mut read_stream = self.get_transport_mut().get_raw_connection()?.try_clone()?;
|
||||
let mut read_stream = self.transport.get_raw_connection()?.try_clone()?;
|
||||
|
||||
let mut write_stream = read_stream.try_clone()?;
|
||||
|
||||
@@ -107,7 +88,7 @@ impl ADBDeviceExt for ADBServerDevice {
|
||||
// Read from given reader (that could be stdin e.g), and write content to server socket
|
||||
if let Err(e) = std::io::copy(&mut reader, &mut write_stream) {
|
||||
match e.kind() {
|
||||
std::io::ErrorKind::BrokenPipe => return Ok(()),
|
||||
ErrorKind::BrokenPipe => return Ok(()),
|
||||
_ => return Err(RustADBError::IOError(e)),
|
||||
}
|
||||
}
|
||||
@@ -115,7 +96,7 @@ impl ADBDeviceExt for ADBServerDevice {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn pull<A: AsRef<str>, W: Write>(&mut self, source: A, mut output: W) -> Result<()> {
|
||||
fn pull(&mut self, source: &dyn AsRef<str>, mut output: &mut dyn Write) -> Result<()> {
|
||||
self.pull(source, &mut output)
|
||||
}
|
||||
|
||||
@@ -123,11 +104,19 @@ impl ADBDeviceExt for ADBServerDevice {
|
||||
self.reboot(reboot_type)
|
||||
}
|
||||
|
||||
fn push<R: Read, A: AsRef<str>>(&mut self, stream: R, path: A) -> Result<()> {
|
||||
fn push(&mut self, stream: &mut dyn Read, path: &dyn AsRef<str>) -> Result<()> {
|
||||
self.push(stream, path)
|
||||
}
|
||||
|
||||
fn install<P: AsRef<Path>>(&mut self, apk_path: P) -> Result<()> {
|
||||
fn install(&mut self, apk_path: &dyn AsRef<Path>) -> Result<()> {
|
||||
self.install(apk_path)
|
||||
}
|
||||
|
||||
fn uninstall(&mut self, package: &str) -> Result<()> {
|
||||
self.uninstall(package)
|
||||
}
|
||||
|
||||
fn framebuffer_inner(&mut self) -> Result<image::ImageBuffer<image::Rgba<u8>, Vec<u8>>> {
|
||||
self.framebuffer_inner()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,20 @@
|
||||
use crate::{models::AdbServerCommand, ADBServerDevice, Result};
|
||||
use crate::{ADBServerDevice, Result, models::AdbServerCommand};
|
||||
|
||||
impl ADBServerDevice {
|
||||
/// Forward socket connection
|
||||
pub fn forward(&mut self, remote: String, local: String) -> Result<()> {
|
||||
let serial = self.identifier.clone();
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::TransportSerial(serial.clone()))?;
|
||||
self.set_serial_transport()?;
|
||||
|
||||
self.get_transport_mut()
|
||||
self.transport
|
||||
.proxy_connection(AdbServerCommand::Forward(remote, local), false)
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
/// Remove all previously applied forward rules
|
||||
pub fn forward_remove_all(&mut self) -> Result<()> {
|
||||
let serial = self.identifier.clone();
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::TransportSerial(serial.clone()))?;
|
||||
self.set_serial_transport()?;
|
||||
|
||||
self.get_transport_mut()
|
||||
self.transport
|
||||
.proxy_connection(AdbServerCommand::ForwardRemoveAll, false)
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
@@ -1,134 +1,23 @@
|
||||
use std::{
|
||||
io::{Read, Seek, Write},
|
||||
iter::Map,
|
||||
path::Path,
|
||||
slice::ChunksExact,
|
||||
};
|
||||
use std::io::Read;
|
||||
|
||||
use byteorder::{LittleEndian, ReadBytesExt};
|
||||
use image::{ImageBuffer, ImageFormat, Rgba};
|
||||
use image::{ImageBuffer, Rgba};
|
||||
|
||||
use crate::{models::AdbServerCommand, utils, ADBServerDevice, Result, RustADBError};
|
||||
|
||||
type U32ChunkIter<'a> = Map<ChunksExact<'a, u8>, fn(&[u8]) -> Result<u32>>;
|
||||
|
||||
fn read_next(chunks: &mut U32ChunkIter) -> Result<u32> {
|
||||
chunks
|
||||
.next()
|
||||
.ok_or(RustADBError::FramebufferConversionError)?
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct FrameBufferInfoV1 {
|
||||
pub _bpp: u32,
|
||||
pub size: u32,
|
||||
pub width: u32,
|
||||
pub height: u32,
|
||||
pub _red_offset: u32,
|
||||
pub _red_length: u32,
|
||||
pub _blue_offset: u32,
|
||||
pub _blue_length: u32,
|
||||
pub _green_offset: u32,
|
||||
pub _green_length: u32,
|
||||
pub _alpha_offset: u32,
|
||||
pub _alpha_length: u32,
|
||||
}
|
||||
|
||||
impl TryFrom<[u8; std::mem::size_of::<Self>()]> for FrameBufferInfoV1 {
|
||||
type Error = RustADBError;
|
||||
|
||||
fn try_from(
|
||||
value: [u8; std::mem::size_of::<Self>()],
|
||||
) -> std::result::Result<Self, Self::Error> {
|
||||
let mut chunks: U32ChunkIter = value.chunks_exact(4).map(utils::u32_from_le);
|
||||
|
||||
Ok(Self {
|
||||
_bpp: read_next(&mut chunks)?,
|
||||
size: read_next(&mut chunks)?,
|
||||
width: read_next(&mut chunks)?,
|
||||
height: read_next(&mut chunks)?,
|
||||
_red_offset: read_next(&mut chunks)?,
|
||||
_red_length: read_next(&mut chunks)?,
|
||||
_blue_offset: read_next(&mut chunks)?,
|
||||
_blue_length: read_next(&mut chunks)?,
|
||||
_green_offset: read_next(&mut chunks)?,
|
||||
_green_length: read_next(&mut chunks)?,
|
||||
_alpha_offset: read_next(&mut chunks)?,
|
||||
_alpha_length: read_next(&mut chunks)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct FrameBufferInfoV2 {
|
||||
pub _bpp: u32,
|
||||
pub _color_space: u32,
|
||||
pub size: u32,
|
||||
pub width: u32,
|
||||
pub height: u32,
|
||||
pub _red_offset: u32,
|
||||
pub _red_length: u32,
|
||||
pub _blue_offset: u32,
|
||||
pub _blue_length: u32,
|
||||
pub _green_offset: u32,
|
||||
pub _green_length: u32,
|
||||
pub _alpha_offset: u32,
|
||||
pub _alpha_length: u32,
|
||||
}
|
||||
|
||||
impl TryFrom<[u8; std::mem::size_of::<Self>()]> for FrameBufferInfoV2 {
|
||||
type Error = RustADBError;
|
||||
|
||||
fn try_from(
|
||||
value: [u8; std::mem::size_of::<Self>()],
|
||||
) -> std::result::Result<Self, Self::Error> {
|
||||
let mut chunks: U32ChunkIter = value.chunks_exact(4).map(utils::u32_from_le);
|
||||
|
||||
Ok(Self {
|
||||
_bpp: read_next(&mut chunks)?,
|
||||
_color_space: read_next(&mut chunks)?,
|
||||
size: read_next(&mut chunks)?,
|
||||
width: read_next(&mut chunks)?,
|
||||
height: read_next(&mut chunks)?,
|
||||
_red_offset: read_next(&mut chunks)?,
|
||||
_red_length: read_next(&mut chunks)?,
|
||||
_blue_offset: read_next(&mut chunks)?,
|
||||
_blue_length: read_next(&mut chunks)?,
|
||||
_green_offset: read_next(&mut chunks)?,
|
||||
_green_length: read_next(&mut chunks)?,
|
||||
_alpha_offset: read_next(&mut chunks)?,
|
||||
_alpha_length: read_next(&mut chunks)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
use crate::{
|
||||
ADBServerDevice, Result, RustADBError,
|
||||
models::{AdbServerCommand, FrameBufferInfoV1, FrameBufferInfoV2},
|
||||
};
|
||||
|
||||
impl ADBServerDevice {
|
||||
/// Dump framebuffer of this device into given ['path']
|
||||
/// Big help from source code (<https://android.googlesource.com/platform/system/adb/+/refs/heads/main/framebuffer_service.cpp>)
|
||||
pub fn framebuffer<P: AsRef<Path>>(&mut self, path: P) -> Result<()> {
|
||||
let img = self.framebuffer_inner()?;
|
||||
Ok(img.save(path.as_ref())?)
|
||||
}
|
||||
|
||||
/// Dump framebuffer of this device and return corresponding bytes.
|
||||
///
|
||||
/// Output data format is currently only `PNG`.
|
||||
pub fn framebuffer_bytes<W: Write + Seek>(&mut self, mut writer: W) -> Result<()> {
|
||||
let img = self.framebuffer_inner()?;
|
||||
Ok(img.write_to(&mut writer, ImageFormat::Png)?)
|
||||
}
|
||||
|
||||
/// Inner method requesting framebuffer from Android device
|
||||
fn framebuffer_inner(&mut self) -> Result<ImageBuffer<Rgba<u8>, Vec<u8>>> {
|
||||
let serial: String = self.identifier.clone();
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
||||
pub(crate) fn framebuffer_inner(&mut self) -> Result<ImageBuffer<Rgba<u8>, Vec<u8>>> {
|
||||
self.set_serial_transport()?;
|
||||
|
||||
self.get_transport_mut()
|
||||
self.transport
|
||||
.send_adb_request(AdbServerCommand::FrameBuffer)?;
|
||||
|
||||
let version = self
|
||||
.get_transport_mut()
|
||||
.transport
|
||||
.get_raw_connection()?
|
||||
.read_u32::<LittleEndian>()?;
|
||||
|
||||
@@ -137,51 +26,49 @@ impl ADBServerDevice {
|
||||
1 => {
|
||||
let mut buf = [0u8; std::mem::size_of::<FrameBufferInfoV1>()];
|
||||
|
||||
self.get_transport_mut()
|
||||
.get_raw_connection()?
|
||||
.read_exact(&mut buf)?;
|
||||
self.transport.get_raw_connection()?.read_exact(&mut buf)?;
|
||||
|
||||
let h: FrameBufferInfoV1 = buf.try_into()?;
|
||||
let framebuffer_info: FrameBufferInfoV1 = buf.try_into()?;
|
||||
|
||||
let mut data = vec![
|
||||
0_u8;
|
||||
h.size
|
||||
framebuffer_info
|
||||
.size
|
||||
.try_into()
|
||||
.map_err(|_| RustADBError::ConversionError)?
|
||||
];
|
||||
self.get_transport_mut()
|
||||
.get_raw_connection()?
|
||||
.read_exact(&mut data)?;
|
||||
self.transport.get_raw_connection()?.read_exact(&mut data)?;
|
||||
|
||||
Ok(
|
||||
ImageBuffer::<Rgba<u8>, Vec<u8>>::from_vec(h.width, h.height, data)
|
||||
.ok_or_else(|| RustADBError::FramebufferConversionError)?,
|
||||
Ok(ImageBuffer::<Rgba<u8>, Vec<u8>>::from_vec(
|
||||
framebuffer_info.width,
|
||||
framebuffer_info.height,
|
||||
data,
|
||||
)
|
||||
.ok_or_else(|| RustADBError::FramebufferConversionError)?)
|
||||
}
|
||||
// RGBX_8888
|
||||
2 => {
|
||||
let mut buf = [0u8; std::mem::size_of::<FrameBufferInfoV2>()];
|
||||
|
||||
self.get_transport_mut()
|
||||
.get_raw_connection()?
|
||||
.read_exact(&mut buf)?;
|
||||
self.transport.get_raw_connection()?.read_exact(&mut buf)?;
|
||||
|
||||
let h: FrameBufferInfoV2 = buf.try_into()?;
|
||||
let framebuffer_info: FrameBufferInfoV2 = buf.try_into()?;
|
||||
|
||||
let mut data = vec![
|
||||
0_u8;
|
||||
h.size
|
||||
framebuffer_info
|
||||
.size
|
||||
.try_into()
|
||||
.map_err(|_| RustADBError::ConversionError)?
|
||||
];
|
||||
self.get_transport_mut()
|
||||
.get_raw_connection()?
|
||||
.read_exact(&mut data)?;
|
||||
self.transport.get_raw_connection()?.read_exact(&mut data)?;
|
||||
|
||||
Ok(
|
||||
ImageBuffer::<Rgba<u8>, Vec<u8>>::from_vec(h.width, h.height, data)
|
||||
.ok_or_else(|| RustADBError::FramebufferConversionError)?,
|
||||
Ok(ImageBuffer::<Rgba<u8>, Vec<u8>>::from_vec(
|
||||
framebuffer_info.width,
|
||||
framebuffer_info.height,
|
||||
data,
|
||||
)
|
||||
.ok_or_else(|| RustADBError::FramebufferConversionError)?)
|
||||
}
|
||||
v => Err(RustADBError::UnimplementedFramebufferImageVersion(v)),
|
||||
}
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
use crate::{
|
||||
models::{AdbServerCommand, HostFeatures},
|
||||
ADBServerDevice, Result,
|
||||
models::{AdbServerCommand, HostFeatures},
|
||||
};
|
||||
|
||||
impl ADBServerDevice {
|
||||
/// Lists available ADB server features.
|
||||
pub fn host_features(&mut self) -> Result<Vec<HostFeatures>> {
|
||||
let serial = self.identifier.clone();
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
||||
self.set_serial_transport()?;
|
||||
|
||||
let features = self
|
||||
.get_transport_mut()
|
||||
.transport
|
||||
.proxy_connection(AdbServerCommand::HostFeatures, true)?;
|
||||
|
||||
Ok(features
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::{fs::File, io::Read, path::Path};
|
||||
|
||||
use crate::{
|
||||
models::AdbServerCommand, server_device::ADBServerDevice, utils::check_extension_is_apk, Result,
|
||||
Result, models::AdbServerCommand, server_device::ADBServerDevice, utils::check_extension_is_apk,
|
||||
};
|
||||
|
||||
impl ADBServerDevice {
|
||||
@@ -13,19 +13,17 @@ impl ADBServerDevice {
|
||||
|
||||
let file_size = apk_file.metadata()?.len();
|
||||
|
||||
let serial: String = self.identifier.clone();
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
||||
self.set_serial_transport()?;
|
||||
|
||||
self.get_transport_mut()
|
||||
self.transport
|
||||
.send_adb_request(AdbServerCommand::Install(file_size))?;
|
||||
|
||||
let mut raw_connection = self.get_transport_mut().get_raw_connection()?;
|
||||
let mut raw_connection = self.transport.get_raw_connection()?;
|
||||
|
||||
std::io::copy(&mut apk_file, &mut raw_connection)?;
|
||||
|
||||
let mut data = [0; 1024];
|
||||
let read_amount = self.get_transport().get_raw_connection()?.read(&mut data)?;
|
||||
let read_amount = self.transport.get_raw_connection()?.read(&mut data)?;
|
||||
|
||||
match &data[0..read_amount] {
|
||||
b"Success\n" => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
models::{AdbServerCommand, SyncCommand},
|
||||
ADBServerDevice, Result,
|
||||
models::{AdbServerCommand, SyncCommand},
|
||||
};
|
||||
use byteorder::{ByteOrder, LittleEndian};
|
||||
use std::{
|
||||
@@ -11,17 +11,13 @@ use std::{
|
||||
impl ADBServerDevice {
|
||||
/// Lists files in path on the device.
|
||||
pub fn list<A: AsRef<str>>(&mut self, path: A) -> Result<()> {
|
||||
let serial = self.identifier.clone();
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
||||
self.set_serial_transport()?;
|
||||
|
||||
// Set device in SYNC mode
|
||||
self.get_transport_mut()
|
||||
.send_adb_request(AdbServerCommand::Sync)?;
|
||||
self.transport.send_adb_request(AdbServerCommand::Sync)?;
|
||||
|
||||
// Send a list command
|
||||
self.get_transport_mut()
|
||||
.send_sync_request(SyncCommand::List)?;
|
||||
self.transport.send_sync_request(SyncCommand::List)?;
|
||||
|
||||
self.handle_list_command(path)
|
||||
}
|
||||
@@ -33,19 +29,17 @@ impl ADBServerDevice {
|
||||
LittleEndian::write_u32(&mut len_buf, path.as_ref().len() as u32);
|
||||
|
||||
// 4 bytes of command name is already sent by send_sync_request
|
||||
self.get_transport_mut()
|
||||
.get_raw_connection()?
|
||||
.write_all(&len_buf)?;
|
||||
self.transport.get_raw_connection()?.write_all(&len_buf)?;
|
||||
|
||||
// List send the string of the directory to list, and then the server send a list of files
|
||||
self.get_transport_mut()
|
||||
self.transport
|
||||
.get_raw_connection()?
|
||||
.write_all(path.as_ref().to_string().as_bytes())?;
|
||||
|
||||
// Reads returned status code from ADB server
|
||||
let mut response = [0_u8; 4];
|
||||
loop {
|
||||
self.get_transport_mut()
|
||||
self.transport
|
||||
.get_raw_connection()?
|
||||
.read_exact(&mut response)?;
|
||||
match str::from_utf8(response.as_ref())? {
|
||||
@@ -57,7 +51,7 @@ impl ADBServerDevice {
|
||||
let mut mod_time = [0_u8; 4];
|
||||
let mut name_len = [0_u8; 4];
|
||||
|
||||
let mut connection = self.get_transport_mut().get_raw_connection()?;
|
||||
let mut connection = self.transport.get_raw_connection()?;
|
||||
connection.read_exact(&mut file_mod)?;
|
||||
connection.read_exact(&mut file_size)?;
|
||||
connection.read_exact(&mut mod_time)?;
|
||||
|
||||
@@ -51,6 +51,6 @@ impl<W: Write> Write for LogFilter<W> {
|
||||
impl ADBServerDevice {
|
||||
/// Get logs from device
|
||||
pub fn get_logs<W: Write>(&mut self, output: W) -> Result<()> {
|
||||
self.shell_command(["exec logcat"], LogFilter::new(output))
|
||||
self.shell_command(&["exec logcat"], &mut LogFilter::new(output))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,4 +12,5 @@ mod send;
|
||||
mod stat;
|
||||
mod tcpip;
|
||||
mod transport;
|
||||
mod uninstall;
|
||||
mod usb;
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
use crate::{
|
||||
models::{AdbServerCommand, RebootType},
|
||||
ADBServerDevice, Result,
|
||||
models::{AdbServerCommand, RebootType},
|
||||
};
|
||||
|
||||
impl ADBServerDevice {
|
||||
/// Reboots the device
|
||||
pub fn reboot(&mut self, reboot_type: RebootType) -> Result<()> {
|
||||
let serial = self.identifier.clone();
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
||||
self.set_serial_transport()?;
|
||||
|
||||
self.get_transport_mut()
|
||||
self.transport
|
||||
.proxy_connection(AdbServerCommand::Reboot(reboot_type), false)
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
use crate::{models::AdbServerCommand, ADBServerDevice, Result};
|
||||
use crate::{ADBServerDevice, Result, models::AdbServerCommand};
|
||||
|
||||
impl ADBServerDevice {
|
||||
/// Reconnect device
|
||||
pub fn reconnect(&mut self) -> Result<()> {
|
||||
let serial = self.identifier.clone();
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
||||
self.set_serial_transport()?;
|
||||
|
||||
self.get_transport_mut()
|
||||
self.transport
|
||||
.proxy_connection(AdbServerCommand::Reconnect, false)
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use crate::{
|
||||
constants,
|
||||
ADBServerDevice, Result, constants,
|
||||
models::{AdbServerCommand, SyncCommand},
|
||||
ADBServerDevice, Result,
|
||||
};
|
||||
use byteorder::{LittleEndian, ReadBytesExt};
|
||||
use std::io::{BufReader, BufWriter, Read, Write};
|
||||
@@ -70,18 +69,14 @@ impl<R: Read> Read for ADBRecvCommandReader<R> {
|
||||
|
||||
impl ADBServerDevice {
|
||||
/// Receives path to stream from the device.
|
||||
pub fn pull<A: AsRef<str>>(&mut self, path: A, stream: &mut dyn Write) -> Result<()> {
|
||||
let serial = self.identifier.clone();
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
||||
pub fn pull(&mut self, path: &dyn AsRef<str>, stream: &mut dyn Write) -> Result<()> {
|
||||
self.set_serial_transport()?;
|
||||
|
||||
// Set device in SYNC mode
|
||||
self.get_transport_mut()
|
||||
.send_adb_request(AdbServerCommand::Sync)?;
|
||||
self.transport.send_adb_request(AdbServerCommand::Sync)?;
|
||||
|
||||
// Send a recv command
|
||||
self.get_transport_mut()
|
||||
.send_sync_request(SyncCommand::Recv)?;
|
||||
self.transport.send_sync_request(SyncCommand::Recv)?;
|
||||
|
||||
self.handle_recv_command(path, stream)
|
||||
}
|
||||
@@ -91,7 +86,7 @@ impl ADBServerDevice {
|
||||
from: S,
|
||||
output: &mut dyn Write,
|
||||
) -> Result<()> {
|
||||
let mut raw_connection = self.get_transport().get_raw_connection()?;
|
||||
let mut raw_connection = self.transport.get_raw_connection()?;
|
||||
|
||||
let from_as_bytes = from.as_ref().as_bytes();
|
||||
let mut buffer = Vec::with_capacity(4 + from_as_bytes.len());
|
||||
|
||||
@@ -1,24 +1,20 @@
|
||||
use crate::{models::AdbServerCommand, ADBServerDevice, Result};
|
||||
use crate::{ADBServerDevice, Result, models::AdbServerCommand};
|
||||
|
||||
impl ADBServerDevice {
|
||||
/// Reverse socket connection
|
||||
pub fn reverse(&mut self, remote: String, local: String) -> Result<()> {
|
||||
let serial = self.identifier.clone();
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
||||
self.set_serial_transport()?;
|
||||
|
||||
self.get_transport_mut()
|
||||
self.transport
|
||||
.proxy_connection(AdbServerCommand::Reverse(remote, local), false)
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
/// Remove all reverse rules
|
||||
pub fn reverse_remove_all(&mut self) -> Result<()> {
|
||||
let serial = self.identifier.clone();
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::TransportSerial(serial.clone()))?;
|
||||
self.set_serial_transport()?;
|
||||
|
||||
self.get_transport_mut()
|
||||
self.transport
|
||||
.proxy_connection(AdbServerCommand::ReverseRemoveAll, false)
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use crate::{
|
||||
constants,
|
||||
ADBServerDevice, Result, RustADBError, constants,
|
||||
models::{AdbRequestStatus, AdbServerCommand, SyncCommand},
|
||||
ADBServerDevice, Result, RustADBError,
|
||||
};
|
||||
use std::{
|
||||
convert::TryInto,
|
||||
@@ -45,17 +44,13 @@ impl ADBServerDevice {
|
||||
/// Send stream to path on the device.
|
||||
pub fn push<R: Read, A: AsRef<str>>(&mut self, stream: R, path: A) -> Result<()> {
|
||||
log::info!("Sending data to {}", path.as_ref());
|
||||
let serial = self.identifier.clone();
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
||||
self.set_serial_transport()?;
|
||||
|
||||
// Set device in SYNC mode
|
||||
self.get_transport_mut()
|
||||
.send_adb_request(AdbServerCommand::Sync)?;
|
||||
self.transport.send_adb_request(AdbServerCommand::Sync)?;
|
||||
|
||||
// Send a send command
|
||||
self.get_transport_mut()
|
||||
.send_sync_request(SyncCommand::Send)?;
|
||||
self.transport.send_sync_request(SyncCommand::Send)?;
|
||||
|
||||
self.handle_send_command(stream, path)
|
||||
}
|
||||
@@ -64,7 +59,7 @@ impl ADBServerDevice {
|
||||
// Append the permission flags to the filename
|
||||
let to = to.as_ref().to_string() + ",0777";
|
||||
|
||||
let mut raw_connection = self.get_transport_mut().get_raw_connection()?;
|
||||
let mut raw_connection = self.transport.get_raw_connection()?;
|
||||
|
||||
// The name of the command is already sent by get_transport()?.send_sync_request
|
||||
let to_as_bytes = to.as_bytes();
|
||||
@@ -99,7 +94,7 @@ impl ADBServerDevice {
|
||||
match AdbRequestStatus::from_str(str::from_utf8(&request_status)?)? {
|
||||
AdbRequestStatus::Fail => {
|
||||
// We can keep reading to get further details
|
||||
let length = self.get_transport_mut().get_body_length()?;
|
||||
let length = self.transport.get_body_length()?;
|
||||
|
||||
let mut body = vec![
|
||||
0;
|
||||
@@ -108,9 +103,7 @@ impl ADBServerDevice {
|
||||
.map_err(|_| RustADBError::ConversionError)?
|
||||
];
|
||||
if length > 0 {
|
||||
self.get_transport()
|
||||
.get_raw_connection()?
|
||||
.read_exact(&mut body)?;
|
||||
self.transport.get_raw_connection()?.read_exact(&mut body)?;
|
||||
}
|
||||
|
||||
Err(RustADBError::ADBRequestFailed(String::from_utf8(body)?))
|
||||
|
||||
@@ -3,8 +3,8 @@ use std::io::{Read, Write};
|
||||
use byteorder::{ByteOrder, LittleEndian};
|
||||
|
||||
use crate::{
|
||||
models::{AdbServerCommand, AdbStatResponse, SyncCommand},
|
||||
ADBServerDevice, Result, RustADBError,
|
||||
models::{AdbServerCommand, AdbStatResponse, SyncCommand},
|
||||
};
|
||||
|
||||
impl ADBServerDevice {
|
||||
@@ -13,24 +13,20 @@ impl ADBServerDevice {
|
||||
LittleEndian::write_u32(&mut len_buf, path.as_ref().len() as u32);
|
||||
|
||||
// 4 bytes of command name is already sent by send_sync_request
|
||||
self.get_transport_mut()
|
||||
.get_raw_connection()?
|
||||
.write_all(&len_buf)?;
|
||||
self.get_transport_mut()
|
||||
self.transport.get_raw_connection()?.write_all(&len_buf)?;
|
||||
self.transport
|
||||
.get_raw_connection()?
|
||||
.write_all(path.as_ref().to_string().as_bytes())?;
|
||||
|
||||
// Reads returned status code from ADB server
|
||||
let mut response = [0_u8; 4];
|
||||
self.get_transport_mut()
|
||||
self.transport
|
||||
.get_raw_connection()?
|
||||
.read_exact(&mut response)?;
|
||||
match std::str::from_utf8(response.as_ref())? {
|
||||
"STAT" => {
|
||||
let mut data = [0_u8; 12];
|
||||
self.get_transport_mut()
|
||||
.get_raw_connection()?
|
||||
.read_exact(&mut data)?;
|
||||
self.transport.get_raw_connection()?.read_exact(&mut data)?;
|
||||
|
||||
Ok(data.into())
|
||||
}
|
||||
@@ -43,17 +39,13 @@ impl ADBServerDevice {
|
||||
|
||||
/// Stat file given as path on the device.
|
||||
pub fn stat<A: AsRef<str>>(&mut self, path: A) -> Result<AdbStatResponse> {
|
||||
let serial = self.identifier.clone();
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
||||
self.set_serial_transport()?;
|
||||
|
||||
// Set device in SYNC mode
|
||||
self.get_transport_mut()
|
||||
.send_adb_request(AdbServerCommand::Sync)?;
|
||||
self.transport.send_adb_request(AdbServerCommand::Sync)?;
|
||||
|
||||
// Send a "Stat" command
|
||||
self.get_transport_mut()
|
||||
.send_sync_request(SyncCommand::Stat)?;
|
||||
self.transport.send_sync_request(SyncCommand::Stat)?;
|
||||
|
||||
self.handle_stat_command(path)
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
use crate::{models::AdbServerCommand, ADBServerDevice, Result};
|
||||
use crate::{ADBServerDevice, Result, models::AdbServerCommand};
|
||||
|
||||
impl ADBServerDevice {
|
||||
/// Set adb daemon to tcp/ip mode
|
||||
pub fn tcpip(&mut self, port: u16) -> Result<()> {
|
||||
let serial = self.identifier.clone();
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
||||
self.set_serial_transport()?;
|
||||
|
||||
self.get_transport_mut()
|
||||
self.transport
|
||||
.proxy_connection(AdbServerCommand::TcpIp(port), false)
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user