Skip to main content

A library for low-level abstract use to high-level.

Project description

🛠 pykasm

pykasm is a Python library for executing Assembly (ASM) code directly from Python scripts, allowing low-level integration with system calls and native libraries.

The goal is to provide a bridge between Python and Assembly, enabling developers to explore optimizations, manipulate memory, and execute machine instructions in a controlled manner.


📦 Installation

You can install via pip (after publication on PyPI):

pip install pykasm

💻 Examples

1️⃣ X86 Linux Example

##################################
#      X86 Linux Example         #
##################################

import pykasm
import ctypes

libc = ctypes.CDLL(None)
puts = libc.puts
puts.argtypes = [ctypes.c_char_p]
puts.restype = ctypes.c_int

msg_buf = ctypes.create_string_buffer(b"Hello, World")
msg_addr = ctypes.addressof(msg_buf)

puts_addr = ctypes.cast(puts, ctypes.c_void_p).value

asm_code = (
    f"mov rdi, {msg_addr};\n"
    f"mov rax, {puts_addr};\n"
    "call rax;\n"
    "ret"
)

pykasm.run_asm(asm_code)

2️⃣ X86 Windows Example

################################## 
#      X86 Windows Example       # 
##################################

import pykasm
import ctypes

msvcrt = ctypes.CDLL("msvcrt.dll")
puts = msvcrt.puts
puts.argtypes = [ctypes.c_char_p]
puts.restype = ctypes.c_int

kernel32 = ctypes.WinDLL("kernel32.dll")
ExitProcess = kernel32.ExitProcess
ExitProcess.argtypes = [ctypes.c_uint]
ExitProcess.restype = None

msg_buf = ctypes.create_string_buffer(b"Hello, World!\n")
msg_addr = ctypes.addressof(msg_buf)

puts_addr = ctypes.cast(puts, ctypes.c_void_p).value
exitprocess_addr = ctypes.cast(ExitProcess, ctypes.c_void_p).value

asm_code = (
    f"mov rcx, {msg_addr}; "
    f"mov rax, {puts_addr}; "
    "call rax; "
    "mov rcx, 0; "
    f"mov rax, {exitprocess_addr}; "
    "call rax; "
)

pykasm.run_asm(asm_code)

2️⃣ ARM64 Android Example


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

pykasm-0.0.6.tar.gz (44.5 MB view details)

Uploaded Source

Built Distribution

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

pykasm-0.0.6-py3-none-any.whl (44.7 MB view details)

Uploaded Python 3

File details

Details for the file pykasm-0.0.6.tar.gz.

File metadata

  • Download URL: pykasm-0.0.6.tar.gz
  • Upload date:
  • Size: 44.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for pykasm-0.0.6.tar.gz
Algorithm Hash digest
SHA256 e8d5b8afaed73936768cf058423d7f1f6c723de5843884f78fbc75cb1ed1d584
MD5 b9ff45c0f7452ba9a2a205323ccd4368
BLAKE2b-256 fc7efc1c297c1825f7f4cb0419c8df8a0d143b81515ab9fefb738f017399adcd

See more details on using hashes here.

File details

Details for the file pykasm-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: pykasm-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 44.7 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for pykasm-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 b871c26e9f9aa18bec2426c41496b9b359b5417cd39e32318720f38915bcf652
MD5 b7169b8a019843410fcb2816950449fc
BLAKE2b-256 34452f256031a6721bc89c238845cfa6a4c46fbfec80db780c9eb8ec505115f3

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