{"id":19248443,"url":"https://github.com/rocky/python-xasm","last_synced_at":"2025-04-13T07:48:43.413Z","repository":{"id":22232289,"uuid":"95669150","full_name":"rocky/python-xasm","owner":"rocky","description":"Python cross version bytecode/wordcode assembler","archived":false,"fork":false,"pushed_at":"2025-02-18T16:54:25.000Z","size":245,"stargazers_count":111,"open_issues_count":2,"forks_count":13,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-04T05:05:02.318Z","etag":null,"topics":["bytecode-manipulation","python"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rocky.png","metadata":{"files":{"readme":"README.rst","changelog":"ChangeLog","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.gpl2","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["rocky"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2017-06-28T12:57:09.000Z","updated_at":"2025-03-03T02:30:17.000Z","dependencies_parsed_at":"2023-01-13T21:54:50.492Z","dependency_job_id":"f5adf12b-0d93-4bfc-8571-00e13abf0f7c","html_url":"https://github.com/rocky/python-xasm","commit_stats":{"total_commits":123,"total_committers":7,"mean_commits":"17.571428571428573","dds":"0.44715447154471544","last_synced_commit":"ef038d608bf8c97551a25b8f18f02f0fb32f6c04"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rocky%2Fpython-xasm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rocky%2Fpython-xasm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rocky%2Fpython-xasm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rocky%2Fpython-xasm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rocky","download_url":"https://codeload.github.com/rocky/python-xasm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248681494,"owners_count":21144700,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bytecode-manipulation","python"],"created_at":"2024-11-09T18:07:55.280Z","updated_at":"2025-04-13T07:48:43.389Z","avatar_url":"https://github.com/rocky.png","language":"Python","readme":"|Pypi Installs| |Latest Version| |Supported Python Versions|\n\nxasm\n====\n\n*NOTE: this is in beta*\n\nA Cross-Python bytecode Assembler\n\n\nIntroduction\n------------\n\nThe Python `xasm` module has routines for assembly, and has a command to\nassemble bytecode for several different versions of Python.\n\nHere are some potential uses:\n\n* Make small changes to existing Python bytecode when you don’t have source\n* Craft custom and efficient bytecode\n* Write an instruction-level optimizing compiler\n* Experiment with and learn about Python bytecode\n* Foil decompilers like uncompyle6_ so that they can’t disassemble bytecode (at least for now)\n\nThis support the same kinds of bytecode that xdis_ supports. This is\npretty much all released bytecode, although we tend to lag behind the\nlatest Python releases.\n\nThe code requires Python 2.7 or later.\n\nAssembly files\n--------------\n\nSee how-to-use_ for more detail. Some general some principles:\n\n* Preferred extension for Python assembly is ``.pyasm``\n* assembly is designed to work with the output of ``pydisasm -F xasm``\n* Assembly file labels are at the beginning of the line\n  and end in a colon, e.g. ``END_IF:``\n* instruction offsets in the assembly file are ignored and don't need\n  to be entered\n* in those instructions that refer to offsets, if the if the\n  operand is an int, exactly that value will be used for the operand. Otherwise\n  we will look for labels and match up with that\n\n\nInstallation\n------------\n\nThe standard Python routine:\n\n::\n\n    pip install -e .\n    pip install -r requirements-dev.txt\n\nA GNU makefile is also provided so :code:`make install` (possibly as root or\nsudo) will do the steps above.\n\n\nTesting\n-------\n\n::\n\n   make check\n\nA GNU makefile has been added to smooth over setting running the right\ncommand, and running tests from fastest to slowest.\n\nIf you have remake_ installed, you can see the list of all tasks\nincluding tests via :code:`remake --tasks`.\n\n\nExample Assembly File\n---------------------\n\nFor this Python source code:\n\n::\n\n    def five():\n        return 5\n\n    print(five())\n\nHere is an assembly for the above:\n\n::\n\n    # Python bytecode 3.6 (3379)\n\n    # Method Name:       five\n    # Filename:          /tmp/five.pl\n    # Argument count:    0\n    # Kw-only arguments: 0\n    # Number of locals:  0\n    # Stack size:        1\n    # Flags:             0x00000043 (NOFREE | NEWLOCALS | OPTIMIZED)\n    # First Line:        1\n    # Constants:\n    #    0: None\n    #    1: 5\n      2:\n                LOAD_CONST           (5)\n                RETURN_VALUE\n\n\n    # Method Name:       \u003cmodule\u003e\n    # Filename:          /tmp/five.pl\n    # Argument count:    0\n    # Kw-only arguments: 0\n    # Number of locals:  0\n    # Stack size:        2\n    # Flags:             0x00000040 (NOFREE)\n    # First Line:        1\n    # Constants:\n    #    0: \u003ccode object five at 0x0000\u003e\n    #    1: 'five'\n    #    2: None\n    # Names:\n    #    0: five\n    #    1: print\n      1:\n                LOAD_CONST           0 (\u003ccode object five at 0x0000\u003e)\n                LOAD_CONST           ('five')\n                MAKE_FUNCTION        0\n                STORE_NAME           (five)\n\n      3:\n                LOAD_NAME            (print)\n                LOAD_NAME            (five)\n                CALL_FUNCTION        0\n                CALL_FUNCTION        1\n                POP_TOP\n                LOAD_CONST           (None)\n                RETURN_VALUE\n\n\nThe above can be created automatically from Python source code using the `pydisasm`\ncommand from `xdis`:\n\n::\n\n    pydisasm --format xasm /tmp/five.pyc\n\nIn the example above though, I have shortened and simplified the result.\n\n\nUsage\n-----\n\nTo create a python bytecode file from an assemble file, run:\n\n::\n\n   pyc-xasm [OPTIONS] ASM_PATH\n\n\nFor usage help, type:  ``pyc-xasm --help``.\n\n\nTo convert a python bytecode from one bytecode to another, run:\n\n::\n\n   pyc-convert [OPTIONS] INPUT_PYC [OUTPUT_PYC]\n\n\nFor usage help, type:  ``pyc-convert --help``.\n\n\nSee Also\n--------\n\n* https://github.com/rocky/python-xdis : Cross Python version disassemble\n* https://github.com/rocky/x-python : Cross Python version interpreter\n* https://github.com/rocky/python-xasm/blob/master/HOW-TO-USE.rst : How to write an assembler file\n* https://rocky.github.io/pycon2018-light.co/ : Pycolumbia 2018 Lightning talk showing how to use the assembler\n\n\n.. _uncompyle6: https://github.com/rocky/python-uncompyle6\n.. _how-to-use: https://github.com/rocky/python-xasm/blob/master/HOW-TO-USE.rst\n.. _xdis: https://github.com/rocky/xdis\n.. |Latest Version| image:: https://badge.fury.io/py/xasm.svg\n\t\t :target: https://badge.fury.io/py/xasm\n.. |Pypi Installs| image:: https://pepy.tech/badge/xasm\n.. |Supported Python Versions| image:: https://img.shields.io/pypi/pyversions/xasm.svg\n.. _remake: http://bashdb.sf.net/remake\n","funding_links":["https://github.com/sponsors/rocky"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frocky%2Fpython-xasm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frocky%2Fpython-xasm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frocky%2Fpython-xasm/lists"}