adb_shell.adb_message module

Functions and an AdbMessage class for packing and unpacking ADB messages.

Contents

class adb_shell.adb_message.AdbMessage(command, arg0, arg1, data=b'')[source]

Bases: object

A helper class for packing ADB messages.

Parameters:
arg0

Usually the local ID, but connect() and connect() provide adb_shell.constants.VERSION, adb_shell.constants.AUTH_SIGNATURE, and adb_shell.constants.AUTH_RSAPUBLICKEY

Type:

int

arg1

Usually the remote ID, but connect() and connect() provide adb_shell.constants.MAX_ADB_DATA

Type:

int

command

The input parameter command converted to an integer via adb_shell.constants.ID_TO_WIRE

Type:

int

data

The data that will be sent

Type:

bytes

magic

self.command with its bits flipped; in other words, self.command + self.magic == 2**32 - 1

Type:

int

property checksum

Return checksum(self.data)

Returns:

The checksum of self.data

Return type:

int

pack()[source]

Returns this message in an over-the-wire format.

Returns:

The message packed into the format required by ADB

Return type:

bytes

adb_shell.adb_message.checksum(data)[source]

Calculate the checksum of the provided data.

Parameters:

data (bytearray, bytes, str) – The data

Returns:

The checksum

Return type:

int

adb_shell.adb_message.int_to_cmd(n)[source]

Convert from an integer (4 bytes) to an ADB command.

Parameters:

n (int) – The integer that will be converted to an ADB command

Returns:

The ADB command (e.g., 'CNXN')

Return type:

str

adb_shell.adb_message.unpack(message)[source]

Unpack a received ADB message.

Parameters:

message (bytes) – The received message

Returns:

  • cmd (int) – The ADB command

  • arg0 (int) – TODO

  • arg1 (int) – TODO

  • data_length (int) – The length of the message’s data

  • data_checksum (int) – The checksum of the message’s data

Raises:

ValueError – Unable to unpack the ADB command.