Exceptions¶
- exception pydex.exc.InvalidDalvikHeader¶
Exception raised when the parser encounters an invalid Dalvik header.
A number of codes exist as class attributes in this class which represent the reason for the exception. These codes exist so that multiple exception classes don’t have to be created for each possible reason.
- INVALID_MAGIC_BYTES = 0¶
The magic bytes of the header are invalid.
- INVALID_CHECKSUM = 1¶
The checksum of the header does not match the calculated checksum.
- INVALID_ENDIAN_TAG = 2¶
The endian tag of the header representing byte order is invalid.
- INVALID_HEADER_SIZE = 3¶
The size of the header is not
0x70.
- INVALID_PROTOS_SIZE = 4¶
The
proto_ids_sizeis greater than or equal to0xFFFF.
- INVALID_TYPES_SIZE = 5¶
The
type_ids_sizeis greater than or equal to0xFFFF.
- INVALID_DATA_SIZE = 6¶
The
data_sizeis not divisible by the size of a word.
- __init__(message: str, code: int)¶
- message¶
The message of the exception.
- code¶
The code of the exception.
Containers¶
Containers refer to the different types of APK files that can be used to store one or more DEX files. Additionally, PyDex also supports the extraction of DEX files from container files which may contain one or more APK files within. PyDex supports the following container types:
zip:
ZipContainer|InMemoryZipContainerxapk:
XAPKContainer|InMemoryXAPKContainerapks:
APKSContainer|InMemoryAPKSContainerjar:
JarContainerapk:
APKContainer
You should use these classes when possible instead of directly using the DexFile
class. The container classes provide a more convenient way to work with DEX
files that come in groups (classes.dex, classes2.dex, etc.).
- class pydex.containers.Container¶
A class that represents a container file(zip, apk, xapk, apks, etc.) which contains either apk files or dex files.
- __init__(path: str)¶
- path: Path¶
The path to the container file.
- class pydex.containers.InMemoryContainer¶
A class that represents an in-memory container which contains either apk files or dex files.
- __init__(data: bytes)¶
- data: bytes¶
The data of the container file.
- class pydex.containers.DexContainer¶
Bases:
ContainerA class that represents a container file(zip, apk, jar) which contains dex files.
- __init__(path: str)¶
- enumerate_dex_files() Generator[str, None, None]¶
Enumerate the dex files in the container file.
- Returns:
A generator that yields the dex filepaths in the container file.
- get_dex_data(dex_file: str) bytes¶
Get the data of the dex file.
- Parameters:
dex_file (str) – The filepath of the dex file in the container file.
- Returns:
The data of the dex file within the container.
- fetch_dex_files() DexPool¶
Lazily load the dex files in the container file.
- Returns:
A DexPool object containing the dex files.
- async fetch_dex_files_async() DexPool¶
Lazily load the dex files in the container file asynchronously.
- Returns:
A DexPool object containing the dex files.
- path: Path¶
The path to the container file.
- class pydex.containers.InMemoryDexContainer¶
Bases:
InMemoryContainerA class that represents a container file(zip, apk, jar) which contains dex files.
- __init__(data: bytes)¶
- enumerate_dex_files() Generator[str, None, None]¶
Enumerate the dex files in the container file.
- Returns:
A generator that yields the dex filepaths in the container file.
- get_dex_data(dex_file: str) bytes¶
Get the data of the dex file.
- Parameters:
dex_file (str) – The filepath of the dex file in the container file.
- Returns:
The data of the dex file within the container.
- fetch_dex_files() DexPool¶
Lazily load the dex files in the container file.
- Returns:
A DexPool object containing the dex files.
- async fetch_dex_files_async() DexPool¶
Lazily load the dex files in the container file asynchronously.
- Returns:
A DexPool object containing the dex files.
- data: bytes¶
The data of the container file.
- class pydex.containers.InMemoryZipContainer¶
Bases:
InMemoryDexContainerA class that represents an in-memory zip file which contains one or more dex files.
- Parameters:
data (bytes) – The zip file data.
root_only (bool) – If True, only the root files in the archive will be considered.
- __init__(data: bytes, root_only: bool = False)¶
- enumerate_dex_files() Generator[str, None, None]¶
Enumerate the dex files in the container file.
- Returns:
A generator that yields the dex filepaths in the container file.
- get_dex_data(dex_file: str) bytes¶
Get the data of the dex file.
- Parameters:
dex_file (str) – The filepath of the dex file in the container file.
- Returns:
The data of the dex file within the container.
- fetch_dex_files() DexPool¶
Lazily load the dex files in the container file.
- Returns:
A DexPool object containing the dex files.
- async fetch_dex_files_async() DexPool¶
Lazily load the dex files in the container file asynchronously.
- Returns:
A DexPool object containing the dex files.
- data: bytes¶
The data of the container file.
- class pydex.containers.ZipContainer¶
Bases:
DexContainerA class that represents a zip file which contains one or more dex files.
- Parameters:
path (str) – The path to the zip file.
root_only (bool) – If True, only the root files in the archive will be considered.
- __init__(path: str, root_only: bool = False)¶
- enumerate_dex_files() Generator[str, None, None]¶
Enumerate the dex files in the container file.
- Returns:
A generator that yields the dex filepaths in the container file.
- get_dex_data(dex_file: str) bytes¶
Get the data of the dex file.
- Parameters:
dex_file (str) – The filepath of the dex file in the container file.
- Returns:
The data of the dex file within the container.
- fetch_dex_files() DexPool¶
Lazily load the dex files in the container file.
- Returns:
A DexPool object containing the dex files.
- async fetch_dex_files_async() DexPool¶
Lazily load the dex files in the container file asynchronously.
- Returns:
A DexPool object containing the dex files.
- path: Path¶
The path to the container file.
- class pydex.containers.InMemoryMultiAPKContainer¶
Bases:
InMemoryContainerA class that represents an in-memory apk container which contains one or more apk files.
- Parameters:
data (bytes) – The apk container file data.
- __init__(data: bytes)¶
- get_base_apk() bytes¶
Get the base apk file as a bytes object.
- Returns:
The file data of the base apk file in the container.
- fetch_dex_files(root_only: bool = False) DexPool¶
Lazily load the dex files in the base apk file.
- Parameters:
root_only (bool) – If True, only the root files in the archive will be considered.
- Returns:
A DexPool object containing the dex files.
- async fetch_dex_files_async(root_only: bool = False) DexPool¶
Lazily load the dex files in the base apk file asynchronously.
- Parameters:
root_only (bool) – If True, only the root files in the archive will be considered.
- Returns:
A DexPool object containing the dex files.
- data: bytes¶
The data of the container file.
- class pydex.containers.MultiAPKContainer¶
Bases:
ContainerA class that represents a container file which contains one or more apk files.
- Parameters:
path (str) – The path to the apk container file.
- __init__(path: str)¶
- get_base_apk() bytes¶
Get the base apk file as a bytes object.
- Returns:
The file data of the base apk file in the container
- fetch_dex_files(root_only: bool = False) DexPool¶
Lazily load the dex files in the base apk file.
- Parameters:
root_only (bool) – If True, only the root files in the archive will be considered.
- Returns:
A DexPool object containing the dex files.
- async fetch_dex_files_async(root_only: bool = False) DexPool¶
Lazily load the dex files in the base apk file asynchronously.
- Parameters:
root_only (bool) – If True, only the root files in the archive will be considered.
- Returns:
A DexPool object containing the dex files.
- path: Path¶
The path to the container file.
- class pydex.containers.InMemoryXAPKContainer¶
Bases:
InMemoryMultiAPKContainerA class that represents an in-memory xapk container file which contains one or more apk files. These conatiner files contain various apk files, whose purpose is noted in the
manifest.jsonfile. This class parses themanifest.jsonfile to determine the base apk file, which is annotated by thebasefield in thesplit_apksobject.- Parameters:
data (bytes) – The xapk container file data.
- __init__(data: bytes)¶
- get_base_apk() bytes¶
Get the base apk file as a bytes object.
- Returns:
The file data of the base apk file in the container.
- fetch_dex_files(root_only: bool = False) DexPool¶
Lazily load the dex files in the base apk file.
- Parameters:
root_only (bool) – If True, only the root files in the archive will be considered.
- Returns:
A DexPool object containing the dex files.
- async fetch_dex_files_async(root_only: bool = False) DexPool¶
Lazily load the dex files in the base apk file asynchronously.
- Parameters:
root_only (bool) – If True, only the root files in the archive will be considered.
- Returns:
A DexPool object containing the dex files.
- data: bytes¶
The data of the container file.
- class pydex.containers.XAPKContainer¶
Bases:
MultiAPKContainerA class that represents a xapk file which contains one or more apk files. These conatiner files contain various apk files, whose purpose is noted in the
manifest.jsonfile. This class parses themanifest.jsonfile to determine the base apk file, which is annotated by thebasefield in thesplit_apksobject.- Parameters:
path (str) – The path to the xapk file.
- __init__(path: str)¶
- get_base_apk() bytes¶
Get the base apk file as a bytes object.
- Returns:
The file data of the base apk file in the container
- fetch_dex_files(root_only: bool = False) DexPool¶
Lazily load the dex files in the base apk file.
- Parameters:
root_only (bool) – If True, only the root files in the archive will be considered.
- Returns:
A DexPool object containing the dex files.
- async fetch_dex_files_async(root_only: bool = False) DexPool¶
Lazily load the dex files in the base apk file asynchronously.
- Parameters:
root_only (bool) – If True, only the root files in the archive will be considered.
- Returns:
A DexPool object containing the dex files.
- path: Path¶
The path to the container file.
- class pydex.containers.InMemoryAPKSContainer¶
Bases:
InMemoryMultiAPKContainerA class that represents an in-memory apks container file which contains one or more apk files. This is also known as a split-apk. The base apk in these containers is usually named
base.apk.- Parameters:
data (bytes) – The apks container file data.
- __init__(data: bytes)¶
- get_base_apk() bytes¶
Get the base apk file as a bytes object.
- Returns:
The file data of the base apk file in the container.
- fetch_dex_files(root_only: bool = False) DexPool¶
Lazily load the dex files in the base apk file.
- Parameters:
root_only (bool) – If True, only the root files in the archive will be considered.
- Returns:
A DexPool object containing the dex files.
- async fetch_dex_files_async(root_only: bool = False) DexPool¶
Lazily load the dex files in the base apk file asynchronously.
- Parameters:
root_only (bool) – If True, only the root files in the archive will be considered.
- Returns:
A DexPool object containing the dex files.
- data: bytes¶
The data of the container file.
- class pydex.containers.APKSContainer¶
Bases:
MultiAPKContainerA class that represents an apks file which contains one or more apk files. This is also known as a split-apk. The base apk in these containers is usually named
base.apk.- Parameters:
path (str) – The path to the apks file.
- __init__(path: str)¶
- get_base_apk() bytes¶
Get the base apk file as a bytes object.
- Returns:
The file data of the base apk file in the container
- fetch_dex_files(root_only: bool = False) DexPool¶
Lazily load the dex files in the base apk file.
- Parameters:
root_only (bool) – If True, only the root files in the archive will be considered.
- Returns:
A DexPool object containing the dex files.
- async fetch_dex_files_async(root_only: bool = False) DexPool¶
Lazily load the dex files in the base apk file asynchronously.
- Parameters:
root_only (bool) – If True, only the root files in the archive will be considered.
- Returns:
A DexPool object containing the dex files.
- path: Path¶
The path to the container file.
- class pydex.containers.JarContainer¶
Bases:
ZipContainerA class that represents a jar file which contains one or more dex files.
- Parameters:
path (str) – The path to the jar file.
- __init__(path: str)¶
- enumerate_dex_files() Generator[str, None, None]¶
Enumerate the dex files in the container file.
- Returns:
A generator that yields the dex filepaths in the container file.
- fetch_dex_files() DexPool¶
Lazily load the dex files in the container file.
- Returns:
A DexPool object containing the dex files.
- async fetch_dex_files_async() DexPool¶
Lazily load the dex files in the container file asynchronously.
- Returns:
A DexPool object containing the dex files.
- get_dex_data(dex_file: str) bytes¶
Get the data of the dex file.
- Parameters:
dex_file (str) – The filepath of the dex file in the container file.
- Returns:
The data of the dex file within the container.
- path: Path¶
The path to the container file.
- class pydex.containers.APKContainer¶
Bases:
ZipContainerA class that represents an apk file which contains one or more dex files. Only the root files in the archive will be considered.
- Parameters:
path (str) – The path to the apk file.
- __init__(path: str)¶
- enumerate_dex_files() Generator[str, None, None]¶
Enumerate the dex files in the container file.
- Returns:
A generator that yields the dex filepaths in the container file.
- fetch_dex_files() DexPool¶
Lazily load the dex files in the container file.
- Returns:
A DexPool object containing the dex files.
- async fetch_dex_files_async() DexPool¶
Lazily load the dex files in the container file asynchronously.
- Returns:
A DexPool object containing the dex files.
- get_dex_data(dex_file: str) bytes¶
Get the data of the dex file.
- Parameters:
dex_file (str) – The filepath of the dex file in the container file.
- Returns:
The data of the dex file within the container.
- path: Path¶
The path to the container file.
Dalvik API¶
- class pydex.dalvik.DexPool¶
A container for managing a collection of DexFile instances.
This class provides a centralized structure for storing and managing multiple DexFile objects, allowing for operations that need to interact with or manipulate multiple dex files simultaneously. It is particularly useful in scenarios where dex files need to be aggregated for analysis, modification, or querying in a unified manner.
- class pydex.dalvik.DexFile¶
Represents a Dex file and provides methods to parse and manipulate it.
This class encapsulates the functionality required to parse and interact with the contents of a Dex (Dalvik Executable) file. It provides methods to parse the file both synchronously and asynchronously.
Certain flag constants exist in this class which let the parser know if a specific section has been parsed already. This prevents the parser from re-parsing the same section multiple times.
Note
This class allows you to parse individual sections of the DEX file. This is useful when you only need to interact with a specific section of the DEX file and don’t want to parse the entire file, for example, when you only need to access the strings in the DEX file:
>>> from pydex.dalvik import DexFile >>> dex = DexFile.from_path("path/to/dex/file.dex") >>> types = dex.parse_types() >>> for dalvik_type in types: ... type_str = str(dalvik_type) ... if type_str.startswith("Ljava/"): ... continue # skip standard Java types ... print(type_str)
If you wish to parse the entire DEX file, you can use the
parse_dex()method.- Parameters:
data – The raw bytes of the dex file.
no_lazy_load – A flag that indicates whether lazy loading should be disabled.
- FLAG_PARSED_HEADER: int = 1¶
Flag that indicates the header has been parsed.
- FLAG_PARSED_STRINGS: int = 2¶
Flag that indicates the strings have been parsed.
- FLAG_PARSED_TYPES: int = 4¶
Flag that indicates the types have been parsed.
- FLAG_PARSED_PROTOS: int = 8¶
Flag that indicates the protos have been parsed.
- FLAG_PARSED_FIELDS: int = 16¶
Flag that indicates the fields have been parsed.
- FLAG_PARSED_METHODS: int = 32¶
Flag that indicates the methods have been parsed.
- __init__(data: bytes, no_lazy_load: bool = False)¶
- data: bytes¶
The raw bytes of the dex file.
- no_lazy_load: bool¶
A flag that indicates whether lazy loading should be disabled.
- section_flags: int¶
The flags that indicate which sections have been parsed.
- stream: DeserializingStream¶
The stream used to read the dex file.
- header: DalvikHeaderItem¶
The header of the dex file.
- strings: list[LazyDalvikString | DalvikStringItem]¶
The list of dalvik string items in the dex file.
- types: list[DalvikTypeItem]¶
The list of dalvik type items in the dex file.
- protos: list[DalvikProtoIDItem]¶
The list of dalvik proto items in the dex file.
- fields: list[DalvikFieldItem]¶
The list of dalvik field items in the dex file.
- methods: list[DalvikMethodItem]¶
The list of dalvik method items in the dex file.
- classmethod from_path(path: str, no_lazy_load: bool = False) DexFile¶
Create a
DexFileobject from a file path.- Parameters:
path – The path to the dex file.
no_lazy_load – A flag that indicates whether lazy loading should be disabled.
- static requires_section(flags: int) Callable¶
Decorator that checks if a section has been parsed.
This decorator checks if a specific section has been parsed before executing the function. If the section has not yet been parsed, the function will parse it before executing the function.
- Parameters:
flags (int) – The flags that indicate which sections need to be parsed.
- parse_dex_prologue() Self¶
Helper function that does misc startup tasks for parsing the dex file.
- Raises:
InvalidDalvikHeader – If the endian tag is invalid.
- parse_dex() Self¶
Parse the DEX file.
This function will attempt to entirely parse this DEX file in one go and fill in all the uninitialized class attributes.
- parse_header() DalvikHeaderItem¶
Parse the header of the dex file.
- Raises:
InvalidDalvikHeader – If the parser encounters unexpected values in the header.
- async parse_header_async() DalvikHeaderItem¶
Parse the header of the dex file.
- Raises:
InvalidDalvikHeader – If the parser encounters unexpected values in the header.
- parse_strings() list[LazyDalvikString]¶
Collect all the dalvik string items.
This function collects all the dalvik string items in this DEX file and returns them as a list of
LazyDalvikString. A clone stream is used so to not alter the DEX file stream.
- async parse_strings_async() list[LazyDalvikString]¶
Collect all the dalvik string items.
This function collects all the dalvik string items in this DEX file and returns them as a list of
LazyDalvikString. A clone stream is used so to not alter the DEX file stream.
- parse_types() list[DalvikTypeItem]¶
Collect all the dalvik type items.
This function collects all the dalvik type items in this DEX file and returns them as a list of
DalvikTypeItem. A clone stream is used so to not alter the DEX file stream.
- async parse_types_async() list[DalvikTypeItem]¶
Collect all the dalvik type items asynchronously.
This function collects all the dalvik type items in this DEX file and returns them as a list of
DalvikTypeItem. A clone stream is used so to not alter the DEX file stream.
- parse_protos() list[DalvikProtoIDItem]¶
Collect all the dalvik proto items.
This function collects all the dalvik prototyoe items in this DEX file and returns them as a list of
DalvikProtoIDItem. A clone stream is used so to not alter the DEX file stream.
- async parse_protos_async() list[DalvikProtoIDItem]¶
Collect all the dalvik proto items asynchronously.
This function collects all the dalvik prototyoe items in this DEX file and returns them as a list of
DalvikProtoIDItem. A clone stream is used so to not alter the DEX file stream.
- parse_fields() list[DalvikFieldItem]¶
Collect all the dalvik field items.
This function collects all the dalvik field items in this DEX file and returns them as a list of
DalvikFieldItem. A clone stream is used so to not alter the DEX file stream.
- async parse_fields_async() list[DalvikFieldItem]¶
Collect all the dalvik field items asynchronously.
This function collects all the dalvik field items in this DEX file and returns them as a list of
DalvikFieldItem. A clone stream is used so to not alter the DEX file stream.
- parse_methods() list[DalvikMethodItem]¶
Collect all the dalvik method items.
This function collects all the dalvik method items in this DEX file and returns them as a list of
DalvikMethodItem. A clone stream is used so to not alter the DEX file stream.
- async parse_methods_async() list[DalvikMethodItem]¶
Collect all the dalvik method items asynchronously.
This function collects all the dalvik method items in this DEX file and returns them as a list of
DalvikMethodItem. A clone stream is used so to not alter the DEX file stream.
- load_all_strings() list[DalvikStringItem]¶
Load all the dalvik string items.
This function invokes the
load()function for all the lazy dalvik strings in thestringsattribute. It will also convert every model instringsto a loadedDalvikStringItemmodel.
- async load_all_strings_async() list[DalvikStringItem]¶
Load all the dalvik string items asynchronously.
This function invokes the
load_async()function for all the lazy dalvik strings in thestringsattribute. It will also convert every model instringsto a loadedDalvikStringItemmodel.
- get_string_by_id(string_id: int) LazyDalvikString¶
Get a dalvik string by its id.
Get a dalvik string by its id. The difference between this, and
dex.strings[id]is that this method does not require all the strings to be collected from the dex file. This method is useful when you only need a single string from the dex file and don’t want to load the entire dex file withparse_dex().- Parameters:
string_id – The id of the string to get. IDs are 0-indexed, and are assigned in the order they appear in the dex file.
Dalvik Model API¶
The Dalvik Model API provides a way to interact with the different parts of a DEX file. The Model API consists of low-level classes and high-level classes. The low-level classes closely follow the structure of the Dalvik executable format specification. The high-level classes provide a more convenient way to work with the different parts of a DEX file, abstracting away the complexity of the low-level classes.
- pydex.dalvik.models.dump_model_json(model: Any) str¶
Dump a model to a JSON string.
- Parameters:
model (Any) – The model to dump to a JSON string. Must be a dataclass.
- class pydex.dalvik.models.DalvikRawItem¶
A dataclass that represents a low-level item in a dex file.
- offset: int¶
The offset of the item in the dex file.
- size: int¶
The size of the item in the dex file.
- data: bytes¶
The raw data of the item.
- __init__(offset: int, size: int, data: bytes) None¶
- class pydex.dalvik.models.DalvikHeader¶
Bases:
DalvikRawItemA dataclass that represents the raw
header_itemof a dex file.Source
- magic: bytes¶
Magic value.
- checksum: int¶
Adler32 checksum of the rest of the file (everything but magic and this field). Used to detect file corruption.
- signature: bytes¶
SHA-1 hash of the rest of the file (everything but magic, checksum, and this field). Used to uniquely identify the file.
- file_size: int¶
Size of the entire file (including the header), in bytes.
- header_size: int¶
Header size in bytes. This value should be
0x70.
- endian_tag: int¶
Endian tag. The value should be either
0x12345678or0x78563412.
- link_size: int¶
Size of the link section.
- link_off: int¶
Offset from the start of the file to the link section.
- map_off: int¶
Offset from the start of the file to the map section.
- string_ids_size: int¶
Size of the string identifiers list.
- string_ids_off: int¶
Offset from the start of the file to the string identifiers list.
- type_ids_size: int¶
Size of the type identifiers list.
- type_ids_off: int¶
Offset from the start of the file to the type identifiers list.
- proto_ids_size: int¶
Size of the prototype identifiers list.
- proto_ids_off: int¶
Offset from the start of the file to the prototype identifiers list.
- field_ids_size: int¶
Size of the field identifiers list.
- field_ids_off: int¶
Offset from the start of the file to the field identifiers list.
- method_ids_size: int¶
Size of the method identifiers list.
- method_ids_off: int¶
Offset from the start of the file to the method identifiers list.
- class_defs_size: int¶
Size of the class definitions list.
- class_defs_off: int¶
Offset from the start of the file to the class definitions list.
- data_size: int¶
Size of the data section.
- data_off: int¶
Offset from the start of the file to the data section.
- __init__(offset: int, size: int, data: bytes, magic: bytes, checksum: int, signature: bytes, file_size: int, header_size: int, endian_tag: int, link_size: int, link_off: int, map_off: int, string_ids_size: int, string_ids_off: int, type_ids_size: int, type_ids_off: int, proto_ids_size: int, proto_ids_off: int, field_ids_size: int, field_ids_off: int, method_ids_size: int, method_ids_off: int, class_defs_size: int, class_defs_off: int, data_size: int, data_off: int) None¶
- class pydex.dalvik.models.DalvikHeaderItem¶
A dataclass that represents the high-level
header_itemof a dex file.- raw_item: DalvikHeader¶
The raw header item.
- version: int¶
The version of the dex file.
- checksum: int¶
The adler32 checksum of the dex file.
- signature: bytes¶
The unique SHA-1 fingerprint of the dex file.
- file_size: int¶
The size of the dex file in bytes.
- byte_order: ByteOrder¶
The byte order of the dex file.
- classmethod from_raw_item(raw_item: DalvikHeader) DalvikHeaderItem¶
Create a
DalvikHeaderItemfrom aDalvikHeader.- Parameters:
raw_item (DalvikHeader) – The
DalvikHeaderthat contains the primitive data for this item.- Raises:
InvalidDalvikHeader – If
endian_tagis invalid.
- __init__(raw_item: DalvikHeader, version: int, checksum: int, signature: bytes, file_size: int, byte_order: ByteOrder) None¶
- class pydex.dalvik.models.DalvikStringID¶
Bases:
DalvikRawItemA dataclass that represents a raw
string_id_itemin a dex file.Source
- string_data_off: int¶
Offset from the start of the file to the string data.
- id_number: int¶
The index of the string in the string table. This field is not part of the dex file format.
- __init__(offset: int, size: int, data: bytes, string_data_off: int, id_number: int) None¶
- class pydex.dalvik.models.DalvikStringData¶
Bases:
DalvikRawItemA dataclass that represents a raw
string_data_itemin a dex file.Source
- utf16_size: int¶
Size of the string in UTF-16 code units.
- string_data: bytes¶
The raw string data.
- __init__(offset: int, size: int, data: bytes, utf16_size: int, string_data: bytes) None¶
- class pydex.dalvik.models.DalvikStringItem¶
A dataclass that represents a high-level
string_data_itemin a dex file.- raw_item: DalvikStringData¶
The raw string data item.
- string_id: DalvikStringID¶
The raw string id item.
- classmethod from_raw_item(raw_item: DalvikStringData, string_id: DalvikStringID) DalvikStringItem¶
Create a
DalvikStringItemfrom aDalvikStringIDandDalvikStringData.- Parameters:
raw_item (DalvikStringData) – The
DalvikStringDatathat will contain the data of this item.string_id (DalvikStringID) – The
DalvikStringID.
- property value: str¶
Get the value of the string decoded as MUTF-8.
- Raises:
ValueError – If an invalid MUTF-8 sequence is encountered.
- Returns:
The MUTF-8 decoded string.
- async get_value_async() str¶
Get the value of the string decoded as MUTF-8 asynchronously.
- Returns:
The MUTF-8 decoded string.
- async set_value_async(value: str)¶
Set the value of the dalvik string encoded as MUTF-8 asynchronously.
- Parameters:
value (str) – The string value to set.
- __init__(raw_item: DalvikStringData, string_id: DalvikStringID, _value: str = '') None¶
- class pydex.dalvik.models.LazyDalvikString¶
A dataclass that represents a dalvik string which can be loaded at any time.
- load(stream: DeserializingStream) DalvikStringItem¶
Load the string from the stream.
- Parameters:
stream (DeserializingStream) – The
DeserializingStreamto read from.- Returns:
A loaded
DalvikStringItem.
- async load_async(stream: DeserializingStream) DalvikStringItem¶
Load the string from the stream asynchronously. :param DeserializingStream stream: The
DeserializingStreamto read from.Returns: A loaded
DalvikStringItem.
- __init__(string_id: DalvikStringID) None¶
- class pydex.dalvik.models.DalvikTypeID¶
Bases:
DalvikRawItemA dataclass that represents a raw
type_id_itemin a dex file.Source
- descriptor_idx: int¶
Index into the
string_idslist for the descriptor string of this type.
- id_number: int¶
The index number of this type. This field is not part of the dex file format.
- __init__(offset: int, size: int, data: bytes, descriptor_idx: int, id_number: int) None¶
- class pydex.dalvik.models.DalvikTypeItem¶
A dataclass that represents a high-level
type_id_itemin a dex file.- raw_item: DalvikTypeID¶
The raw type id item.
- descriptor: DalvikStringItem | LazyDalvikString¶
The raw string item.
- classmethod from_raw_item(raw_item: DalvikTypeID, strings: list[DalvikStringItem | LazyDalvikString]) DalvikTypeItem¶
Create a
DalvikTypeItemfrom aDalvikTypeID.- Parameters:
raw_item (DalvikTypeID) – The
DalvikTypeIDthat will contain the data of this item.strings (list[DalvikStringItem | LazyDalvikString]) – The list of string items.
- __init__(raw_item: DalvikTypeID, descriptor: DalvikStringItem | LazyDalvikString) None¶
- class pydex.dalvik.models.DalvikProtoID¶
Bases:
DalvikRawItemA dataclass that represents a
proto_id_itemfound in a dex file.Source
- shorty_idx: int¶
Index into the
string_ids listfor the short-form descriptor string of this prototype.
- return_type_idx: int¶
Index into the
type_idslist for the return type of this prototype.
- parameters_off: int¶
Offset from the start of the file to the list of parameter types for this prototype, or 0 if this prototype has no parameters.
- id_number: int¶
The index number of this prototype. This field is not part of the dex file format.
- __init__(offset: int, size: int, data: bytes, shorty_idx: int, return_type_idx: int, parameters_off: int, id_number: int) None¶
- class pydex.dalvik.models.DalvikProtoIDItem¶
A dataclass that represents a high-level
proto_id_itemin a dex file.- raw_item: DalvikProtoID¶
The raw prototype id item.
- shorty: DalvikStringItem | LazyDalvikString¶
The shorty string item.
- return_type: DalvikTypeItem¶
The return type of the prototype.
- parameters: DalvikTypeListItem | None¶
The list of parameter types for this prototype.
- parameter_list: list[str] | None¶
String list of parameters
- classmethod from_raw_item(raw_item: DalvikProtoID, shorty: DalvikStringItem | LazyDalvikString, return_type: DalvikTypeItem, parameters: DalvikTypeListItem | None) DalvikProtoIDItem¶
Create a
DalvikProtoIDItemfrom aDalvikProtoID.- Parameters:
raw_item (DalvikProto) – The
DalvikProtoIDinstance that will contain the data of this item.shorty (DalvikStringItem | LazyDalvikString) – The shorty string item.
return_type (DalvikTypeItem) – The return type item.
parameters (DalvikTypeListItem) – The list of parameter type items.
- __init__(raw_item: DalvikProtoID, shorty: DalvikStringItem | LazyDalvikString, return_type: DalvikTypeItem, parameters: DalvikTypeListItem | None, parameter_list: list[str] | None) None¶
- class pydex.dalvik.models.DalvikTypeList¶
Bases:
DalvikRawItemA dataclass that represents a
type_listitem found in a dex file.Source
- length: int¶
Size of the list, in entries. Renamed from
sizeto avoid shadowing.
- entries: list[DalvikTypeID]¶
Elements of the list. Renamed from
listto avoid shadowing.
- __init__(offset: int, size: int, data: bytes, length: int, entries: list[DalvikTypeID]) None¶
- class pydex.dalvik.models.DalvikTypeListItem¶
A dataclass that represents a high-level
type_listitem in a dex file.- raw_item: DalvikTypeList¶
The raw type list item.
- types: list[DalvikTypeItem]¶
The list of type items.
- classmethod from_raw_item(raw_item: DalvikTypeList, types: list[DalvikTypeItem]) DalvikTypeListItem¶
Create a
DalvikTypeListItemfrom aDalvikTypeList.- Parameters:
raw_item (DalvikTypeList) – The
DalvikTypeListinstance that will contain the data of this item.types (list[DalvikTypeItem]) – The complete list of types in the dex file.
- __init__(raw_item: DalvikTypeList, types: list[DalvikTypeItem]) None¶
- class pydex.dalvik.models.DalvikField¶
Bases:
DalvikRawItemA dataclass that represents a
field_id_itemin a dex file.Source
- class_idx: int¶
Index into the
type_idslist for the definer of this field.
- type_idx: int¶
Index into the
type_idslist for the type of this field.
- name_idx: int¶
Index into the
string_idslist for the name of this field.
- id_number: int¶
The index number of this field. This field is not part of the dex file format.
- __init__(offset: int, size: int, data: bytes, class_idx: int, type_idx: int, name_idx: int, id_number: int) None¶
- class pydex.dalvik.models.DalvikFieldItem¶
A dataclass that represents a high-level
field_id_itemin a dex file.- raw_item: DalvikField¶
The raw
field_id_item.
- class_def: DalvikTypeItem¶
The class this field belongs to.
- type: DalvikTypeItem¶
The type of the field.
- name: DalvikStringItem¶
The name of the field.
- classmethod from_raw_item(raw_item: DalvikField, types: list[DalvikTypeItem], strings: list[DalvikStringItem]) DalvikFieldItem¶
Create a
DalvikFieldItemfrom aDalvikField- Parameters:
raw_item (DalvikField) – The
DalvikFieldinstance that will contain the data of this item.types (list[DalvikTypeItem]) – The list of type items.
strings (list[DalvikStringItem]) – The list of string items.
- __init__(raw_item: DalvikField, class_def: DalvikTypeItem, type: DalvikTypeItem, name: DalvikStringItem) None¶
- class pydex.dalvik.models.DalvikMethod¶
Bases:
DalvikRawItemA dataclass that represents a
method_id_itemin a dex file.Source
- class_idx: int¶
Index into the
type_idslist for the definer of this method.
- proto_idx: int¶
Index into the
proto_idslist for the prototype of this method.
- name_idx: int¶
Index into the
string_idslist for the name of this method.
- id_number: int¶
The index number of this method. This field is not part of the dex file format.
- __init__(offset: int, size: int, data: bytes, class_idx: int, proto_idx: int, name_idx: int, id_number: int) None¶
- class pydex.dalvik.models.DalvikMethodItem¶
A dataclass that represents a high-level
method_id_itemin a dex file.- raw_item: DalvikMethod¶
The raw
method_id_item.
- class_def: DalvikTypeItem¶
The class this method belongs to.
- proto: DalvikProtoIDItem¶
The prototype of the method.
- name: DalvikStringItem¶
The name of the method.
- classmethod from_raw_item(raw_item: DalvikMethod, types: list[DalvikTypeItem], protos: list[DalvikProtoIDItem], strings: list[DalvikStringItem]) DalvikMethodItem¶
Create a
DalvikMethodItemfrom aDalvikMethod.- Parameters:
raw_item (DalvikMethod) – The
DalvikMethodinstance that will contain the data of this item.types (list[DalvikTypeItem]) – The list of type items.
protos (list[DalvikProtoIDItem]) – The list of prototype items.
strings (list[DalvikStringItem]) – The list of string items.
- __init__(raw_item: DalvikMethod, class_def: DalvikTypeItem, proto: DalvikProtoIDItem, name: DalvikStringItem) None¶