Skip to main content

Python bindings for BochsCPU.

Project description

bochscpu-python

Python 3.8+ Downloads Code style: black Licence MIT Builds

Python bindings for @yrp's BochsCPU using FFI to easily and accurately emulate x86 code.

Install

bochscpu-python requires a Python environment of 3.8 or more recent only.

Via PyPI (preferred)

By far the simplest way to get things up and running is using the stable packaged version on PyPI

python -m pip install bochscpu-python

Via the generated builds

Download the latest working artifact from the repository Github Actions tab. Extract the ZIP file, install the .whl file you'll find inside the wheel folder.

python -m pip install wheel/bochscpu-$version-$os-$arch.whl

From the source repository

Fairly straight forward:

python -m pip install .

Or without cloning

python -m pip install git+https://github.com/hugsy/bochscpu-python.git#egg=bochscpu-python

Note that this approach will require you to have all the building tools necessary installed (as described below)

Build

Requirements

  • Python 3.8+ (with development kit)
  • cmake
  • pip
  • a C++20 compatible compiler (tested cl for Windows, clang++ for MacOS and g++ Linux)

Steps

  • Build BochsCPU, BochsCPU-FFI, and BochsCPU-Build following the instructions on their respective pages
  • ... Alternatively BochsCPU-FFI for Windows & Linux libraries object files can be downloaded from the build Github Actions
  • Move the *.lib in bochscpu/lib/<BuildType> (where BuildType can be Debug, Release, RelWithDebInfo, etc.)
  • Install the requirements: python -m pip install -r requirements.txt
  • Build with cmake This will generate the bochscpu pyd file (and its PDB) which you can import from a Python session with import bochscpu.
  • ... Alternatively you can also generate a .whl from the root of the project:
python -m pip wheel .

Usage

Just import the bochscpu module and let the fun begin! Installing the package will also install interface files, allowing modern IDEs (VSCode, PyCharm, etc.) to offer useful completion.

Some Examples

Emulate a Fibonascii sequence in x64 long mode

https://github.com/hugsy/bochscpu-python/assets/590234/adc5ac5a-a8eb-4982-9537-5ece3f32f8f8

Code

Emulate code from a Windows 11 x64 memory dump

image

Code

Emulate a print("hello world")-like assembly code in 16 bit real mode

https://github.com/hugsy/bochscpu-python/assets/590234/eb06af06-4b10-490e-ae40-a1d0aed333ca

Code

Emulate Linux Glibc's rand() function on x64

https://github.com/hugsy/bochscpu-python/assets/590234/2486adbc-0878-46f5-83ed-3bcf9774fd26

Code

Enjoy 🍻

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

bochscpu_python-0.3.1-cp312-abi3-win_amd64.whl (1.2 MB view hashes)

Uploaded CPython 3.12+ Windows x86-64

bochscpu_python-0.3.1-cp312-abi3-manylinux_2_35_x86_64.whl (1.9 MB view hashes)

Uploaded CPython 3.12+ manylinux: glibc 2.35+ x86-64

bochscpu_python-0.3.1-cp312-abi3-macosx_12_0_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.12+ macOS 12.0+ x86-64

bochscpu_python-0.3.1-cp311-cp311-win_amd64.whl (1.2 MB view hashes)

Uploaded CPython 3.11 Windows x86-64

bochscpu_python-0.3.1-cp311-cp311-manylinux_2_35_x86_64.whl (1.9 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.35+ x86-64

bochscpu_python-0.3.1-cp311-cp311-macosx_12_0_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.11 macOS 12.0+ x86-64

bochscpu_python-0.3.1-cp310-cp310-win_amd64.whl (1.2 MB view hashes)

Uploaded CPython 3.10 Windows x86-64

bochscpu_python-0.3.1-cp310-cp310-manylinux_2_35_x86_64.whl (1.9 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.35+ x86-64

bochscpu_python-0.3.1-cp310-cp310-macosx_12_0_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.10 macOS 12.0+ x86-64

bochscpu_python-0.3.1-cp39-cp39-win_amd64.whl (1.2 MB view hashes)

Uploaded CPython 3.9 Windows x86-64

bochscpu_python-0.3.1-cp39-cp39-manylinux_2_35_x86_64.whl (1.9 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.35+ x86-64

bochscpu_python-0.3.1-cp39-cp39-macosx_12_0_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.9 macOS 12.0+ x86-64

bochscpu_python-0.3.1-cp38-cp38-win_amd64.whl (1.2 MB view hashes)

Uploaded CPython 3.8 Windows x86-64

bochscpu_python-0.3.1-cp38-cp38-manylinux_2_35_x86_64.whl (1.9 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.35+ x86-64

bochscpu_python-0.3.1-cp38-cp38-macosx_12_0_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.8 macOS 12.0+ x86-64

Supported by

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