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 details)

Uploaded CPython 3.12+ Windows x86-64

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

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 details)

Uploaded CPython 3.12+ macOS 12.0+ x86-64

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

Uploaded CPython 3.11 Windows x86-64

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

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 details)

Uploaded CPython 3.11 macOS 12.0+ x86-64

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

Uploaded CPython 3.10 Windows x86-64

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

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 details)

Uploaded CPython 3.10 macOS 12.0+ x86-64

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

Uploaded CPython 3.9 Windows x86-64

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

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 details)

Uploaded CPython 3.9 macOS 12.0+ x86-64

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

Uploaded CPython 3.8 Windows x86-64

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

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 details)

Uploaded CPython 3.8 macOS 12.0+ x86-64

File details

Details for the file bochscpu_python-0.3.1-cp312-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for bochscpu_python-0.3.1-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 78f35739a05bbb34ed30c7d09cca76e1ff0fc1fc3493bbe64c9f115c78b1a37d
MD5 c39a8351a2e818ed6496366be17dcd89
BLAKE2b-256 84bf0c2953b352ee724cd0d556a734633a0df40f82c41617baae4d7634f2413b

See more details on using hashes here.

File details

Details for the file bochscpu_python-0.3.1-cp312-abi3-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for bochscpu_python-0.3.1-cp312-abi3-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 41620c4f17a78d43086cfbe700a353fbce00461e33c8e52d1ab75f38aa6784fe
MD5 dd016d275e14d178e42a66724de9c996
BLAKE2b-256 2e1fce230eee828aae39c96a9c2c3e47fc73bbf134873b8d57ed91e3f2b04879

See more details on using hashes here.

File details

Details for the file bochscpu_python-0.3.1-cp312-abi3-macosx_12_0_x86_64.whl.

File metadata

File hashes

Hashes for bochscpu_python-0.3.1-cp312-abi3-macosx_12_0_x86_64.whl
Algorithm Hash digest
SHA256 7397e26c8bd097a2883c39e1c0feeadc7c6889f2381fa3f998b5cb6bfccde5ec
MD5 31dcc705c332de330b5a22d347c0b8b7
BLAKE2b-256 c7cf3d86703f2a906079d155c4867c8625f9fec134a1b19ad2df84666ad11a7a

See more details on using hashes here.

File details

Details for the file bochscpu_python-0.3.1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for bochscpu_python-0.3.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 12d3d2d5e697b35dc1a2baed543d8e7d0b86e559b62e8e00644b75e5cc6fe88b
MD5 b794f673cf7816efd4a945bf0aaef8ef
BLAKE2b-256 829fc284e215ff589154f5ee2fc486b6677528018759d4063d0406a674130005

See more details on using hashes here.

File details

Details for the file bochscpu_python-0.3.1-cp311-cp311-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for bochscpu_python-0.3.1-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 4b6d05410a27794dbdf087321444812a2a67529de22aa33c637628228e613929
MD5 94a27c01f6e747ba97db4c5757c1367a
BLAKE2b-256 5a2238bd5618eb0e2a1604d3d0bd65bba6c83572f8bea02b89425ce33e834adb

See more details on using hashes here.

File details

Details for the file bochscpu_python-0.3.1-cp311-cp311-macosx_12_0_x86_64.whl.

File metadata

File hashes

Hashes for bochscpu_python-0.3.1-cp311-cp311-macosx_12_0_x86_64.whl
Algorithm Hash digest
SHA256 123b0a345ba62bc557790f0a62a6a0e9ca50a8c14daf100269e828f780ffa542
MD5 b02f6cd6c1a8b153e322d8e2e3f9984f
BLAKE2b-256 17a5da1087f6ed27eeafaf9aa4072e3388767fd22c005fd5111472c6f28f38ad

See more details on using hashes here.

File details

Details for the file bochscpu_python-0.3.1-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for bochscpu_python-0.3.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 cde5d65bc7c96627e84a383e1c0a86855da061f50343a62f896f5c58ed5f3f52
MD5 e5368d82efc048fd4449da0b1e6abbb4
BLAKE2b-256 4a3ab3ce6fa16a90aee3bafb22ff052f04fffb3e55e7e7cdd9794b9091db3c80

See more details on using hashes here.

File details

Details for the file bochscpu_python-0.3.1-cp310-cp310-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for bochscpu_python-0.3.1-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 e22a891b0fc957ffb92b97054a901571c1c4b44d0ada9ee64dca8296c764de07
MD5 3463f3e0f30570c19b874afaaea98c11
BLAKE2b-256 c51c5b27e3df80fde679d1901d4963026746a3935d8ae4189d4bbbf36d733fe9

See more details on using hashes here.

File details

Details for the file bochscpu_python-0.3.1-cp310-cp310-macosx_12_0_x86_64.whl.

File metadata

File hashes

Hashes for bochscpu_python-0.3.1-cp310-cp310-macosx_12_0_x86_64.whl
Algorithm Hash digest
SHA256 740c470cada9327bf4b05b3074abd0d104cf1a42bafbf1612b6e3baf331b1bf8
MD5 cb92065f7dddfe5799d17953ba432f80
BLAKE2b-256 34fafb23ad899c89899718d3cda5631eede384f87127abc2a5622938e4f1f1af

See more details on using hashes here.

File details

Details for the file bochscpu_python-0.3.1-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for bochscpu_python-0.3.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 37f9592ea024994140bf9aab833e0d6a1c81bbfbd03865d1d5be43db25395e7b
MD5 e93109c1862e81d79c5f4e117a9667bc
BLAKE2b-256 c533add5f941552f3934c6174f908e851da2290016ddfd89afaa78d9afef7d6e

See more details on using hashes here.

File details

Details for the file bochscpu_python-0.3.1-cp39-cp39-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for bochscpu_python-0.3.1-cp39-cp39-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 49471aabf9a310fa941666c2ca8ec1b0351c92e0161be83edc2eef5478df5c15
MD5 3ae9236aa6311e56a54412db79c82c24
BLAKE2b-256 598cc37b4255673f4747d8cccdccdabd5179b9ec561e52b2fef14b220dcaa3d7

See more details on using hashes here.

File details

Details for the file bochscpu_python-0.3.1-cp39-cp39-macosx_12_0_x86_64.whl.

File metadata

File hashes

Hashes for bochscpu_python-0.3.1-cp39-cp39-macosx_12_0_x86_64.whl
Algorithm Hash digest
SHA256 5a076db6c9d5f1b87cb3aa49831fa589e82c97dc359ca0c75e4bb9eb376c3ac3
MD5 d7ec9b938a24b343144cf356cf5e579f
BLAKE2b-256 66026ed74b190c53ea226517d999db203709a8cad0c32b16580eb7d4a33842aa

See more details on using hashes here.

File details

Details for the file bochscpu_python-0.3.1-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for bochscpu_python-0.3.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 c669d4a48d5b8d03d7d084b57a6705c01c7ac8292616305789270c9c59e0a2a4
MD5 9bf619a4d3627e3f10a5d5129cf6de6f
BLAKE2b-256 33b46bf41743f33d72907b53c575e534c5ae9575eccb9f34697c2e158103e9e4

See more details on using hashes here.

File details

Details for the file bochscpu_python-0.3.1-cp38-cp38-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for bochscpu_python-0.3.1-cp38-cp38-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 7afcc739961d1fbccaf08ff3347a446c78a968845240ced75a39d9aedb5bfa13
MD5 c7ec87b72c466477df2ac857c0b32c09
BLAKE2b-256 552e3b556de54adde32a97dae4e971c7c682e93d39ebec309455d571a70a67f1

See more details on using hashes here.

File details

Details for the file bochscpu_python-0.3.1-cp38-cp38-macosx_12_0_x86_64.whl.

File metadata

File hashes

Hashes for bochscpu_python-0.3.1-cp38-cp38-macosx_12_0_x86_64.whl
Algorithm Hash digest
SHA256 b764b0b67db5797a4237badddebb89ef44090a16b47dc3809fa6ea43011d9dfa
MD5 e3287aaf24719c9896c51005028c893d
BLAKE2b-256 01f356c27f881ce446eac661c4b0f7e87774943dbcff7dac2f4fc25025729af4

See more details on using hashes here.

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