smallworld.state.memory.code¶
- class smallworld.state.memory.code.Executable(address: int, size: int, *args, **kwargs)¶
An execuable piece of code.
- entrypoint: int | None = None¶
Entry point address.
Note
This is not used by Emulators - but is available for reference from file parsing, if supported.
- apply(emulator: Emulator) None¶
Apply state to an emulator.
- Parameters:
emulator – The emulator to which state should applied.
- extract(emulator: Emulator) None¶
Load state from an emulator.
- Parameters:
emulator – The emulator from which to load
- classmethod from_elf(file: BinaryIO, address: int | None = None, platform: Platform | None = None, ignore_platform: bool = False, page_size: int = 4096)¶
Load an ELF executable from an open file-like object.
- Parameters:
file – The open file-like object from which to read.
address – The address where this executable should be loaded.
platform – Optional platform for header verification
ignore_platform – Skip platform ID and verification
page_size – Page size in bytes
- Returns:
An Executable parsed from the given ELF file-like object.
- classmethod from_elf_core(file: BinaryIO, address: int | None = None, platform: Platform | None = None, ignore_platform: bool = False)¶
Load an ELF core dump (ET_CORE) from an open file-like object.
- Parameters:
file – The open file-like object from which to read.
address – The address where this core dump should be loaded.
platform – Optional platform for header verification
ignore_platform – Skip platform ID and verification
- Returns:
An Executable (specifically ElfCoreFile) parsed from the given core dump.
- classmethod from_pe(file: BinaryIO, address: int | None = None, platform: Platform | None = None, ignore_platform: bool = False)¶
Load an PE executable from an open file-like object.
- Parameters:
file – The open file-like object from which to read.
address – The address where this executable should be loaded.
- Returns:
An Executable parsed from the given PE file-like object.
- classmethod from_vxworks(file: BinaryIO, address: int | None = None, platform: Platform | None = None, ignore_platform: bool = False)¶
Load a VXWorks executable from a firmware capture. :param file: The open file-like object from which to read. :param address: The address where this executable should be loaded.
- Returns:
An Executable parsed from the given VXWorks image.
- classmethod from_bndb(path: str, address: int | None = None, platform: Platform | None = None, ignore_platform: bool = False)¶
Load an executable from a Binary Ninja database (.bndb) or any file that Binary Ninja can open.
- Parameters:
path – Filesystem path to a
.bndbfile (or raw binary / ELF / PE / Mach-O / etc.).address – Optional base address override. When None the base recorded in the BinaryView is used.
platform – Optional platform; when given the detected platform is verified against it.
ignore_platform – Skip platform identification and verification.
- Returns:
An Executable parsed from the given Binary Ninja database.
- classmethod from_bytes(bytes: bytes, address: int)¶
Load from a byte array.
- Parameters:
bytes – The bytes of the memory.
address – The address where this memory should be loaded into an emulator’s memory.
- Returns:
A RawMemory contstructed from the given bytes.
- classmethod from_file(file: BinaryIO, address: int, label: str | None = None)¶
Load from an open file-like object.
- Parameters:
file – The open file-like object from which to load data.
address – The address where this memory should be loaded into an emulator’s memory.
- Returns:
A RawMemory from the given file-like object.
- classmethod from_filepath(path: str, address: int)¶
Load from a file.
- Parameters:
path – The path to the file.
address – The address where this memory should be loaded into an emulator’s memory.
- Returns:
A RawMemory parsed from the given file path.
- get_capacity() int¶
Gets the total number of bytes this memory region can store. :returns: The total number of bytes this memory region can store.
- get_used() int¶
Gets the number of bytes written to this memory region.
- Returns:
The number of bytes written to this memory region.
- read_bytes(address: int, size: int) bytes¶
Read part of this memory region. This will fail if any sub-region of the memory requested is symbolic or uninitialized.
- Parameters:
address – The address to read from.
size – The number of bytes to read.
- Returns:
The bytes in the requested memory region.
- read_int(address: int, size: Literal[1, 2, 4, 8], byteorder: Byteorder) int¶
Read and interpret as an integer. This will fail if any sub-region of the memory requested is symbolic or uninitialized.
- Parameters:
address – The address to read from.
size – The size of the integer in bytes.
endianness – The byteorder of the platform.
- Returns:
The integer read from memory.
- to_bytes() bytes¶
Convert this memory region into a byte string.
Missing/undefined space will be filled with zeros.
- Parameters:
byteorder – Byteorder for conversion to raw bytes.
- Returns:
Bytes for this object with the given byteorder.
- write_bytes(address: int, data: bytes) None¶
Overwrite part of this memory region with specific bytes. This will fail if any sub-region of the existing memory is symbolic.
- Parameters:
address – The address to write to.
data – The bytes to write.
- write_int(address: int, value: int, size: Literal[1, 2, 4, 8], byteorder: Byteorder) None¶
Write an integer to memory. This will fail if any sub-region of the existing memory is symbolic.
- Parameters:
address – The address to write to.
value – The integer value to write.
size – The size of the integer in bytes.
endianness – The byteorder of the platform.
- address: int¶
The start address of this memory region.
- size: int¶
The size address of this memory region.