Skip to main content

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 rscompile that 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_elf function to parse a byte stream into an ELF object.
  • The populate_from_elf function that can be used to load the program sections of an ELF object into the simulator.
  • The asm_preable and asm_stop_sim functions that return some boilerplate asm code to setup a global label and raise the internal interrupt to stop the simulation respectively.
  • elf_add_trampoline function 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

raspsim-0.1.0.3.tar.gz (4.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

raspsim-0.1.0.3-py3-none-any.whl (4.0 MB view details)

Uploaded Python 3

File details

Details for the file raspsim-0.1.0.3.tar.gz.

File metadata

  • Download URL: raspsim-0.1.0.3.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

Hashes for raspsim-0.1.0.3.tar.gz
Algorithm Hash digest
SHA256 51dd44ba92548d6eb4395e3316b962fd2f256e5b4ed6bdadbdb19ebea76e46ea
MD5 8e722a86d7a3afff73f38696671051c8
BLAKE2b-256 c5b146fce1c931f012a8caee18655e1706ddfce595eda9e5f21f1cd232cdb112

See more details on using hashes here.

File details

Details for the file raspsim-0.1.0.3-py3-none-any.whl.

File metadata

  • Download URL: raspsim-0.1.0.3-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

Hashes for raspsim-0.1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4b8aeaa960c268c1f1bd62bf7401ed6b25538f7fe94576be6564b7e86150537c
MD5 9b01be755e76feb7a3c94122c01a5887
BLAKE2b-256 1bd1da09667641e83fbcd163b961d5a3315f940a5642889d258c2c789ddfdefc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page