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:
command (bytes) – A command; examples used in this package include
adb_shell.constants.AUTH
,adb_shell.constants.CNXN
,adb_shell.constants.CLSE
,adb_shell.constants.OPEN
, andadb_shell.constants.OKAY
arg0 (int) – Usually the local ID, but
connect()
andconnect()
provideadb_shell.constants.VERSION
,adb_shell.constants.AUTH_SIGNATURE
, andadb_shell.constants.AUTH_RSAPUBLICKEY
arg1 (int) – Usually the remote ID, but
connect()
andconnect()
provideadb_shell.constants.MAX_ADB_DATA
data (bytes) – The data that will be sent
- arg0
Usually the local ID, but
connect()
andconnect()
provideadb_shell.constants.VERSION
,adb_shell.constants.AUTH_SIGNATURE
, andadb_shell.constants.AUTH_RSAPUBLICKEY
- Type:
int
- arg1
Usually the remote ID, but
connect()
andconnect()
provideadb_shell.constants.MAX_ADB_DATA
- Type:
int
- command
The input parameter
command
converted to an integer viaadb_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
- 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.