pyas
Run machine code, assembly and webassembly directly in Python.
Have you ever realized you can't remember how to add numbers in Python but you do remember how to do it in assembly?
If the answer is yes this is the package for you, using pyas you will be able to run machine code, assembly and webassembly directly from within Python!
- currently this only supports Linux
Installation
From PyPI
pip3 install pyas
From GitHub
pip3 install git+https://github.com/donno2048/pyas
Usage / Example
Machine code
Comments are noted with ;, # and //
from pyas import function
add_one = function(
'8b c7' # mov eax, edi
'83 c0 01' # add eax, 1
'c3' # ret
)
return_same = function(
'''
8b c7 # mov eax, edi
c3 // ret
'''
)
print(add_one(10), "=", return_same(10), "+ 1")
# output: 11 = 10 + 1
add_numbers = lambda i, val: function(
'''
8b c7 ; mov eax, edi
83 c0 %.2x # add eax, i
c3 // ret
'''
%i,
val # every value after the first argument will be passed directly to the function if supplied
)
print(add_numbers(4, 10), "=", "10 + 4")
# output: 14 = 10 + 4
Assembly
from pyas import function
add_one = function(
'''
mov eax, edi
add eax, 1
ret
''',
raw = False
)
return_same = function(
'''
mov eax, edi
ret
''',
raw = False
)
print(add_one(10), "=", return_same(10), "+ 1")
# output: 11 = 10 + 1
add_numbers = lambda i, val: function(
'''
mov eax, edi
add eax, %d
ret
'''
%i,
val, # every value after the first argument will be passed directly to the function if supplied
raw = False
)
print(add_numbers(4, 10), "=", "10 + 4")
# output: 14 = 10 + 4
WebAssembly
pyas will automatically recognize running in a web browser and will run Webassembly, but you'll have to specify a func_name.
from pyas import function
add_one = function(
'\0asm\1\0\0\0\1\6\1`\1'
'\x7f\1\x7f\3\2\1\0\7'
'\x0b\1\7add_one\0\0\n\t'
'\1\7\0\x20\0A\x01j\x0b'
, func_name = 'add_one')
print(f"{add_one(10)} = {add_one(9)} + 1")
View online
Metadata
Release files for pyas 1.2.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyas-1.2.4.tar.gz | 3.5 kB | Without provenance | Details for pyas-1.2.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyas-1.2.4-py3-none-any.whl | Python 3 | none | any | Details for pyas-1.2.4-py3-none-any.whl |
Total release size: 7.2 kB
Release files / pyas-1.2.4.tar.gz
| Download URL | pyas-1.2.4.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6201320b39f7327ff906f144167bfb9254268289f5cb165a7259ccb4cdad962a
|
|
BLAKE2b-256 checksum How to use checksums |
8e5de4b5b40b3d49b2f3a4cf6e17413922e997727f5a0c0370cf5d4dfc52edf0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.10.4
|
Release files / pyas-1.2.4-py3-none-any.whl
| Download URL | pyas-1.2.4-py3-none-any.whl |
|---|---|
| Size | 3.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
31bd3bde0b162566582ec7ef75f45d44a0c26160c1acaab8e79a72c36b6e20ab
|
|
BLAKE2b-256 checksum How to use checksums |
e8a40852496ebf35912d4bfc13ff1883c7b8f9c22298c3a00985d076d680e4a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.10.4
|
Security for pyas 1.2.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.