python bindings for ghidra's sleigh engine
Project description
psleigh
python bindings for ghidra's sleigh engine.
this library provides high level pythonic bindings for the sleigh engine, with a focus on ease of use and convenience.
instead of working with cumbersome ffi objects, this library provides pythonic dataclass objects that are much easier to work with.
installation
pip install psleigh
usage
here is a simple example of how to use this library to lift a single x86_64 instruction:
from psleigh import Sleigh, SleighArch, BufMemReader
# mov rax, 0x1234567890abcdef
code = bytes.fromhex("48 b8 ef cd ab 90 78 56 34 12")
sleigh = Sleigh(SleighArch.x86_64(), BufMemReader(code, 0))
# lift the instruction at address 0
res = sleigh.lift_one(0)
# print the lifted p-code
print(res.fmt_insns(sleigh))
this will output the following:
COPY RAX, 0x1234567890abcdef:8
some instructions translate to multiple p-code operations. for example, a push rax instruction on x86_64 will first decrement the stack pointer and then store the value of rax at the new stack pointer location:
from psleigh import Sleigh, SleighArch, BufMemReader
# push rax
code = bytes.fromhex("50")
sleigh = Sleigh(SleighArch.x86_64(), BufMemReader(code, 0))
res = sleigh.lift_one(0)
# print the lifted p-code
print(res.fmt_insns(sleigh))
this will output the following raw p-code. note that this is a direct, unsimplified representation of the instruction's operations. the exact addresses and unique ids may vary.
COPY unique[162944]:8, RAX
INT_SUB RSP, RSP, 0x8:8
STORE 0x1e68f670:8, RSP, unique[162944]:8
an example of lifting a mips instruction:
from psleigh import Sleigh, SleighArch, BufMemReader, Opcode
# sw $ra, 0x10($sp)
code = bytes.fromhex("af bf 00 10")
sleigh = Sleigh(SleighArch.mips32be(), BufMemReader(code, 0))
res = sleigh.lift_one(0)
# print the lifted p-code
print(res.fmt_insns(sleigh))
this will output the following raw p-code. the exact addresses and unique ids may vary.
INT_ADD unique[256]:4, sp, 0x10:4
COPY unique[384]:4, 0x0:4
COPY unique[384]:4, unique[256]:4
STORE 0x20339f70:8, unique[384]:4, ra
you can also manually construct all of the pcode related objects, which makes it easier to work with them.
for example, you can construct an Insn object and compare it to the results of a lift operation:
from psleigh import Sleigh, SleighArch, BufMemReader, Opcode, Insn, Vn, VnAddr, VnSpace
# li $v0, 1
code = bytes.fromhex("24 02 00 01")
reader = BufMemReader(code, 0)
sleigh = Sleigh(SleighArch.mips32be(), reader)
res = sleigh.lift_one(0)
# manually construct the expected Insn
expected_insn = Insn(
opcode=Opcode.COPY,
inputs=[Vn(addr=VnAddr(off=1, space=VnSpace.const()), size=4)],
output=Vn(addr=VnAddr(off=8, space=VnSpace.register()), size=4),
)
# compare the lifted instruction to the expected one
assert res.insns[0] == expected_insn
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
Built Distributions
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 psleigh-0.3.0.tar.gz.
File metadata
- Download URL: psleigh-0.3.0.tar.gz
- Upload date:
- Size: 18.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
251096d3e36ea3e4486abaecb319ae4e0036a68135a973549fc94abe50350c2d
|
|
| MD5 |
67d2c986fc26685c97bfa564d366ae51
|
|
| BLAKE2b-256 |
e02b122bd64aeecb69a238d190eac2f9581f3506c623e3a561693bd1a4c65efb
|
Provenance
The following attestation bundles were made for psleigh-0.3.0.tar.gz:
Publisher:
publish.yml on roeeshoshani/psleigh
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
psleigh-0.3.0.tar.gz -
Subject digest:
251096d3e36ea3e4486abaecb319ae4e0036a68135a973549fc94abe50350c2d - Sigstore transparency entry: 731603756
- Sigstore integration time:
-
Permalink:
roeeshoshani/psleigh@3a3cc62ee6ef5bab76f5f59fd2de2ab483b8771b -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/roeeshoshani
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3a3cc62ee6ef5bab76f5f59fd2de2ab483b8771b -
Trigger Event:
release
-
Statement type:
File details
Details for the file psleigh-0.3.0-cp312-cp312-musllinux_1_1_x86_64.whl.
File metadata
- Download URL: psleigh-0.3.0-cp312-cp312-musllinux_1_1_x86_64.whl
- Upload date:
- Size: 16.0 MB
- Tags: CPython 3.12, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c8a554d787152c5866ff620ade365bec378eeb7ff00cf7222fc8c90bc2ad6eb6
|
|
| MD5 |
bfc9f11016e295cb13cf518c3a31d763
|
|
| BLAKE2b-256 |
b59723194fd8987fec5dcfff2e5aee939828e1bec5d28832ba8e90870f60b37f
|
Provenance
The following attestation bundles were made for psleigh-0.3.0-cp312-cp312-musllinux_1_1_x86_64.whl:
Publisher:
publish.yml on roeeshoshani/psleigh
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
psleigh-0.3.0-cp312-cp312-musllinux_1_1_x86_64.whl -
Subject digest:
c8a554d787152c5866ff620ade365bec378eeb7ff00cf7222fc8c90bc2ad6eb6 - Sigstore transparency entry: 731603759
- Sigstore integration time:
-
Permalink:
roeeshoshani/psleigh@3a3cc62ee6ef5bab76f5f59fd2de2ab483b8771b -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/roeeshoshani
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3a3cc62ee6ef5bab76f5f59fd2de2ab483b8771b -
Trigger Event:
release
-
Statement type:
File details
Details for the file psleigh-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: psleigh-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 15.6 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
89c0d54242896d24d8290e308bb9eb48b4bf2c9440b831cf85dc2c186d616eb8
|
|
| MD5 |
bcaf803c9714ab958f89653368dddf40
|
|
| BLAKE2b-256 |
dc3386d7acfaa2f8ec2b154a7db500eb0cbe5adef9ba0ee3aa9706be4d8701bf
|
Provenance
The following attestation bundles were made for psleigh-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
publish.yml on roeeshoshani/psleigh
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
psleigh-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
89c0d54242896d24d8290e308bb9eb48b4bf2c9440b831cf85dc2c186d616eb8 - Sigstore transparency entry: 731603762
- Sigstore integration time:
-
Permalink:
roeeshoshani/psleigh@3a3cc62ee6ef5bab76f5f59fd2de2ab483b8771b -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/roeeshoshani
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3a3cc62ee6ef5bab76f5f59fd2de2ab483b8771b -
Trigger Event:
release
-
Statement type: