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.1.tar.gz (685.6 kB 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.1-py3-none-any.whl (690.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: raspsim-0.1.0.1.tar.gz
  • Upload date:
  • Size: 685.6 kB
  • 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.1.tar.gz
Algorithm Hash digest
SHA256 16b770e9d602d612064810d46588cf20cf88c67434aed9aa30291b43a9d606a9
MD5 f4e93f658d21aa3fc0a92e1bcf2e5a60
BLAKE2b-256 450321c3c51cbb9027861f5fd2b750ceaa53dc8ba5deaf773cc8d630e22032cb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: raspsim-0.1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 690.8 kB
  • 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e1a9ad349ebf80614526f894ba6c29829354186ff7bc74a95d641062cb8038cd
MD5 5e13c2b3ddee751ee615d41e75d56023
BLAKE2b-256 f180a1778315e5b57ac34a78921fb2830b368e52e3c76762e65523cbe7d11115

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