Python bindings for the RaspSim C++ library, a cycle-accurate X86-64 simulator based on PTLSim.
Project description
RASPsim
RASPsim is a cycle-accurate x86-64 simulator, forked from PTLsim. This simulator allows you to configure the virtual address space and initial register values, start simulation, and retrieve the latest register state, requested memory dumps, and the number of cycles and instructions simulated.
Python Binding
raspsim includes a Python binding, allowing you to interface directly with the simulator. Below is an example of how to use the module directly:
python -m raspsim << EOF
.global _start
.intel_syntax noprefix
.text
_start:
mov rax, 1
int 0x80
EOF
Usage
The raspsim Python module provides a range of features to interact with the simulator:
- Raspsim Class: This is the main class used to interact with the simulator. It provides methods to map memory pages, run the simulation, and access various registers. Only one instance of this class can be used at a time due to the havy use of global state of PTLsim.
- Address Class: This class allows reading and writing data at a specific address.
- Prot Enum: This enumeration provides memory protection flags, such as READ, WRITE, and EXEC.
The python module also provides several utility functions that ease the use of the simulator:
i[8|16|32|64]classes that can be used to compare register values and store their values as an unsigned [8|16|32|64]-bit integer.- The contextmanager
rscompilethat can be used to compile code with the appropiate flags for the simulator. - The ELF dataclass that represents program sections of an elf file and
load_elffunction to parse a byte stream into an ELF object. - The
populate_from_elffunction that can be used to load the program sections of an ELF object into the simulator. - The
asm_preableandasm_stop_simfunctions that return some boilerplate asm code to setup a global label and raise the internal interrupt to stop the simulation respectively. elf_add_trampolinefunction that can be used to add a trampoline (a call to the original entry point follow by a stop-simulation interrupt) to an ELF object. This is useful to run the simulation until the end of the program and ensure that the original entry point returned gracefully.
Example:
code = asm_preable() + "mov rax, -1\n" + asm_stop_sim()
with rscompile(code) as f:
elf = load_elf(f)
sim = Raspsim()
populate_from_elf(sim, elf)
sim.run()
assert sim.rax == i64(-1) # Check if rax is -1, although registers return 64-bit unsigned values
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file raspsim-0.1.0.2.tar.gz.
File metadata
- Download URL: raspsim-0.1.0.2.tar.gz
- Upload date:
- Size: 4.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
97207ff128a882f967ae5ecdf2fa02a76854629cf8f128d1d03d48055fc6fe0a
|
|
| MD5 |
d7c752cbebaa7b09712e32f79cff2974
|
|
| BLAKE2b-256 |
b76c48fa89c735048afc5318f2e85a782298ad50d00ec16cff75fd31ecef35c5
|
File details
Details for the file raspsim-0.1.0.2-py3-none-any.whl.
File metadata
- Download URL: raspsim-0.1.0.2-py3-none-any.whl
- Upload date:
- Size: 4.0 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c31c84c449ee8cad70ce28e2260de9aebd1192e5a2402bdb850afcd2a43da502
|
|
| MD5 |
611bfd97ef683ae3dd956c991ca9dcb7
|
|
| BLAKE2b-256 |
e58765d5a90907dc3df4233b92260c4bae37fe61771f396b477ece265781c5b0
|