A pure Rust implementation of the Android Debug Bridge (ADB) protocol compiled to WebAssembly, enabling direct communication with Android devices from web browsers using WebUSB.
- Pure WebUSB: Direct USB communication without ADB server
- Zero Dependencies: No native ADB installation required
- Cross-Platform: Works in any WebUSB-compatible browser (Chrome, Edge, Opera)
- Full WASM: Compiled to WebAssembly for native performance in the browser
- Comprehensive ADB Protocol:
- Device authentication with RSA key pairs
- Shell command execution
- File operations (pull/push)
- Directory listing
- Bugreport generation and management
- Logcat viewing
- Device properties and information
- Rust toolchain (1.70+)
- wasm-pack (
cargo install wasm-pack) - A WebUSB-compatible browser (Chrome 61+, Edge 79+, Opera 48+)
- Android device with USB debugging enabled
# Clone the repository
cd rust-webadb
#Β install wasm-pack
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
# Build the code
wasm-pack build --dev --target web --features bugreport-analysis The compiled WASM module will be in the pkg/ directory.
-
Start a local web server:
python3 -m http.server 8000
-
Open in browser:
http://localhost:8000/bugreport.html -
Connect your Android device:
- Enable USB debugging on your Android device
- Click "Connect to Device" in the web interface
- Select your device from the WebUSB picker
- Accept the RSA key fingerprint on your device
- Android 4.2.2+ (API level 17+)
- Any device with USB debugging enabled
- Both rooted and non-rooted devices
The included web interface provides:
- Device Connection: WebUSB device selection and authentication
- Device Information: Model, Android version, serial number, battery status
- Bug Reports:
- Generate new bugreports (lite or full)
- List and download existing bugreports from device
- Real-time download progress with debug panel
- Logcat: View and download device logs
- File Browser: Navigate device filesystem and download files
- Shell: Execute shell commands
import init, { AdbClient } from './pkg/webadb_rs.js';
// Initialize WASM module
await init();
// Create client and connect
const client = await AdbClient.connect_usb();
// Execute shell commands
const output = await client.shell('ls -la /sdcard');
console.log(output);
// Get device properties
const props = await client.get_properties();
console.log('Android version:', props['ro.build.version.release']);
// Pull a file
const fileData = await client.pull_file('/sdcard/Download/file.txt');
// List directory
const entries = await client.list_directory('/sdcard');
entries.forEach(entry => {
console.log(`${entry.name} - ${entry.size} bytes`);
});
// Get logcat
const logs = await client.logcat(100);
// Disconnect
await client.disconnect();- Large File Downloads: Files >50MB may be slow due to WebUSB bandwidth limitations
- Safari Not Supported: WebUSB is not available in Safari
- Firefox Not Supported: WebUSB is experimental in Firefox (requires flag)
- Full Bugreport Generation: Takes 5-10 minutes (2-5 min device generation + 1-5 min download)
- Recommended: Use "List Available Bugreports" to download existing reports instantly
- Bugreports: Always use "List Available Bugreports" first - it's much faster than generating new ones
- Shell Commands: Most standard Unix commands work (ls, cat, grep, ps, etc.)
- File Paths: Use absolute paths (e.g.,
/sdcard/Download/file.txt) - Permissions: Some operations require root access
- Debug Panel: When downloading files, a debug panel shows real-time progress, speed, and logs
- Connection: USB bulk transfer endpoints
- Authentication: SHA1-signed RSA-2048 challenge-response
- Streams: Multiplexed bidirectional channels
- Messages: OPEN, OKAY, WRTE, CLSE commands
- Sync Protocol: Separate protocol for file operations (LIST, RECV, SEND, STAT)
| Command | Description |
|---|---|
| CNXN | Initial connection handshake |
| AUTH | Authentication challenge/response |
| OPEN | Open a new stream |
| OKAY | Acknowledgment / flow control |
| WRTE | Write data to stream |
| CLSE | Close stream |
The sync protocol is used for file operations over a sync: stream:
| Command | Description |
|---|---|
| LIST | List directory contents (returns DENT packets) |
| RECV | Receive file from device (returns DATA packets) |
| SEND | Send file to device |
| STAT | Get file statistics |
| DATA | File data chunk |
| DONE | Operation complete |
| FAIL | Operation failed |
| DENT | Directory entry |
wasm-pack build --target web --dev- Use browser DevTools Console for JavaScript errors
- Check Network tab for WebUSB communication
- Rust panics will show in console with detailed stack traces
- Enable the debug panel in bugreport.html for file transfer diagnostics
This project is open source. See LICENSE file for details.
- Inspired by webadb project
- WebUSB API
- ADB protocol reverse engineering by Google's Android team
- Reference implementation by Synacktiv Synacktiv ADB Client
