pwnlib.adb — Android Debug Bridge

Provides utilities for interacting with Android devices via the Android Debug Bridge.

class pwnlib.adb.AdbDevice(serial, type, port, product='unknown', model='unknown', device='unknown')[source]

Encapsulates information about a connected device.

pwnlib.adb.adb(argv, *a, **kw)[source]

Returns the output of an ADB subcommand.

pwnlib.adb.build()[source]

Returns the Build ID of the device.

pwnlib.adb.compile(source)[source]

Compile a source file or project with the Android NDK.

pwnlib.adb.devices(*a, **kw)[source]

Returns a list of Device objects corresponding to the connected devices.

pwnlib.adb.disable_verity()[source]

Disables dm-verity on the device.

pwnlib.adb.fastboot(args, *a, **kw)[source]

Executes a fastboot command.

Returns:The command output.
pwnlib.adb.find_ndk_project_root(source)[source]

Given a directory path, find the topmost project root.

tl;dr “foo/bar/jni/baz.cpp” ==> “foo/bar”

pwnlib.adb.fingerprint()[source]

Returns the device build fingerprint.

pwnlib.adb.forward(port)[source]

Sets up a port to forward to the device.

pwnlib.adb.getprop(name=None)[source]

Reads a properties from the system property store.

Parameters:name (str) – Optional, read a single property.
Returns:If name is not specified, a dict of all properties is returned. Otherwise, a string is returned with the contents of the named property.
pwnlib.adb.interactive(**kw)[source]

Spawns an interactive shell.

pwnlib.adb.listdir(directory='/')[source]

Returns a list containing the entries in the provided directory.

Note

Because adb shell is used to retrieve the listing, shell environment variable expansion and globbing are in effect.

pwnlib.adb.logcat(*a, **kw)[source]

Reads the system log file.

By default, causes logcat to exit after reading the file.

Parameters:stream (bool) – If True, the contents are streamed rather than read in a one-shot manner. Default is False.
Returns:If stream is False, returns a string containing the log data. Otherwise, it returns a tube connected to the log output.
pwnlib.adb.pidof(name)[source]

Returns a list of PIDs for the named process.

pwnlib.adb.proc_exe(pid)[source]

Returns the full path of the executable for the provided PID.

pwnlib.adb.process(argv, *a, **kw)[source]

Execute a process on the device.

See pwnlib.tubes.process.process documentation for more info.

Returns:A process tube.
pwnlib.adb.product()[source]

Returns the device product identifier.

pwnlib.adb.pull(remote_path, local_path=None)[source]

Download a file from the device.

Parameters:
  • remote_path (str) – Path or directory of the file on the device.
  • local_path (str) – Path to save the file to. Uses the file’s name by default.
pwnlib.adb.push(local_path, remote_path)[source]

Upload a file to the device.

Parameters:
  • local_path (str) – Path to the local file to push.
  • remote_path (str) – Path or directory to store the file on the device.
pwnlib.adb.read(*a, **kw)[source]

Download a file from the device, and extract its contents.

Parameters:
  • path (str) – Path to the file on the device.
  • target (str) – Optional, location to store the file. Uses a temporary file by default.
pwnlib.adb.reboot(wait=True)[source]

Reboots the device.

pwnlib.adb.reboot_bootloader()[source]

Reboots the device to the bootloader.

pwnlib.adb.remount()[source]

Remounts the filesystem as writable.

pwnlib.adb.root()[source]

Restarts adbd as root.

pwnlib.adb.setprop(name, value)[source]

Writes a property to the system property store.

pwnlib.adb.shell(**kw)[source]

Returns an interactive shell.

pwnlib.adb.unlock_bootloader()[source]

Unlocks the bootloader of the device.

Note

This requires physical interaction with the device.

pwnlib.adb.unroot()[source]

Restarts adbd as AID_SHELL.

pwnlib.adb.wait_for_device(*a, **kw)[source]

Waits for a device to be connected.

pwnlib.adb.which(*a, **kw)[source]

Retrieves the full path to a binary in PATH on the device

pwnlib.adb.write(*a, **kw)[source]

Create a file on the device with the provided contents.

Parameters:
  • path (str) – Path to the file on the device
  • data (str) – Contents to store in the file