Name | pyas JSON |
Version |
1.2.4
JSON |
| download |
home_page | https://github.com/donno2048/pyas |
Summary | Run machine code, assembly and webassembly directly in Python |
upload_time | 2022-05-08 17:32:08 |
maintainer | |
docs_url | None |
author | Elisha Hollander |
requires_python | |
license | MIT |
keywords |
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# 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!
```diff
- currently this only supports Linux
```
## Installation
### From PyPI
```sh
pip3 install pyas
```
### From GitHub
```sh
pip3 install git+https://github.com/donno2048/pyas
```
## Usage / Example
### Machine code
Comments are noted with `;`, `#` and `//`
```py
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
```py
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`.
```py
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](https://donno2048.github.io/pyas/)
Raw data
{
"_id": null,
"home_page": "https://github.com/donno2048/pyas",
"name": "pyas",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Elisha Hollander",
"author_email": "just4now666666@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/8e/5d/e4b5b40b3d49b2f3a4cf6e17413922e997727f5a0c0370cf5d4dfc52edf0/pyas-1.2.4.tar.gz",
"platform": "linux",
"description": "# pyas\n\nRun machine code, assembly and webassembly directly in Python.\n\nHave you ever realized you can't remember how to add numbers in Python but you **do** remember how to do it in assembly?\n\nIf 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!\n\n```diff\n- currently this only supports Linux\n```\n\n## Installation\n\n### From PyPI\n\n```sh\npip3 install pyas\n```\n\n### From GitHub\n\n```sh\npip3 install git+https://github.com/donno2048/pyas\n```\n\n## Usage / Example\n\n### Machine code\n\nComments are noted with `;`, `#` and `//`\n\n```py\nfrom pyas import function\nadd_one = function(\n '8b c7' # mov eax, edi\n '83 c0 01' # add eax, 1\n 'c3' # ret\n)\nreturn_same = function(\n '''\n 8b c7 # mov eax, edi\n c3 // ret\n '''\n)\n\nprint(add_one(10), \"=\", return_same(10), \"+ 1\")\n# output: 11 = 10 + 1\n\nadd_numbers = lambda i, val: function(\n '''\n 8b c7 ; mov eax, edi\n 83 c0 %.2x # add eax, i\n c3 // ret\n '''\n %i,\n val # every value after the first argument will be passed directly to the function if supplied\n)\n\nprint(add_numbers(4, 10), \"=\", \"10 + 4\")\n# output: 14 = 10 + 4\n\n```\n\n### Assembly\n\n```py\nfrom pyas import function\nadd_one = function(\n '''\n mov eax, edi\n add eax, 1\n ret\n ''',\n raw = False\n)\nreturn_same = function(\n '''\n mov eax, edi\n ret\n ''',\n raw = False\n)\n\nprint(add_one(10), \"=\", return_same(10), \"+ 1\")\n# output: 11 = 10 + 1\n\nadd_numbers = lambda i, val: function(\n '''\n mov eax, edi\n add eax, %d\n ret\n '''\n %i,\n val, # every value after the first argument will be passed directly to the function if supplied\n raw = False\n)\n\nprint(add_numbers(4, 10), \"=\", \"10 + 4\")\n# output: 14 = 10 + 4\n\n```\n\n## WebAssembly\n\npyas will automatically recognize running in a web browser and will run Webassembly, but you'll have to specify a `func_name`.\n\n```py\nfrom pyas import function\nadd_one = function(\n '\\0asm\\1\\0\\0\\0\\1\\6\\1`\\1'\n '\\x7f\\1\\x7f\\3\\2\\1\\0\\7'\n '\\x0b\\1\\7add_one\\0\\0\\n\\t'\n '\\1\\7\\0\\x20\\0A\\x01j\\x0b'\n , func_name = 'add_one')\nprint(f\"{add_one(10)} = {add_one(9)} + 1\")\n```\n\nView [online](https://donno2048.github.io/pyas/)\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Run machine code, assembly and webassembly directly in Python",
"version": "1.2.4",
"project_urls": {
"Bug Reports": "https://github.com/donno2048/pyas/issues",
"Documentation": "https://github.com/donno2048/pyas#readme",
"Homepage": "https://github.com/donno2048/pyas",
"Source Code": "https://github.com/donno2048/pyas"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "e8a40852496ebf35912d4bfc13ff1883c7b8f9c22298c3a00985d076d680e4a8",
"md5": "bab06eff7f206ea5fb8331c3182aef17",
"sha256": "31bd3bde0b162566582ec7ef75f45d44a0c26160c1acaab8e79a72c36b6e20ab"
},
"downloads": -1,
"filename": "pyas-1.2.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "bab06eff7f206ea5fb8331c3182aef17",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 3721,
"upload_time": "2022-05-08T17:32:07",
"upload_time_iso_8601": "2022-05-08T17:32:07.466865Z",
"url": "https://files.pythonhosted.org/packages/e8/a4/0852496ebf35912d4bfc13ff1883c7b8f9c22298c3a00985d076d680e4a8/pyas-1.2.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "8e5de4b5b40b3d49b2f3a4cf6e17413922e997727f5a0c0370cf5d4dfc52edf0",
"md5": "96c0fc26a2190efc223745bc4cc5859a",
"sha256": "6201320b39f7327ff906f144167bfb9254268289f5cb165a7259ccb4cdad962a"
},
"downloads": -1,
"filename": "pyas-1.2.4.tar.gz",
"has_sig": false,
"md5_digest": "96c0fc26a2190efc223745bc4cc5859a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3504,
"upload_time": "2022-05-08T17:32:08",
"upload_time_iso_8601": "2022-05-08T17:32:08.841310Z",
"url": "https://files.pythonhosted.org/packages/8e/5d/e4b5b40b3d49b2f3a4cf6e17413922e997727f5a0c0370cf5d4dfc52edf0/pyas-1.2.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-05-08 17:32:08",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "donno2048",
"github_project": "pyas",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pyas"
}