{"id":13490515,"url":"https://github.com/magniff/hacky","last_synced_at":"2026-01-23T09:50:39.745Z","repository":{"id":57436581,"uuid":"55308983","full_name":"magniff/hacky","owner":"magniff","description":"Low level CPython tinkering utils.","archived":false,"fork":false,"pushed_at":"2021-09-19T11:19:23.000Z","size":9,"stargazers_count":18,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-31T04:34:48.680Z","etag":null,"topics":["cpython","hack"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/magniff.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-02T18:05:34.000Z","updated_at":"2023-08-05T12:30:04.000Z","dependencies_parsed_at":"2022-09-10T01:51:41.411Z","dependency_job_id":null,"html_url":"https://github.com/magniff/hacky","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magniff%2Fhacky","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magniff%2Fhacky/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magniff%2Fhacky/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magniff%2Fhacky/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/magniff","download_url":"https://codeload.github.com/magniff/hacky/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245984510,"owners_count":20704791,"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":["cpython","hack"],"created_at":"2024-07-31T19:00:47.862Z","updated_at":"2026-01-23T09:50:34.693Z","avatar_url":"https://github.com/magniff.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"# HACKY\nPython hacking suite.\n\n## INSTALLATION\nTested on CPython 3.4\n```bash\npython setup.py install (preferred)\n```\nor\n```bash\npip install hacky\n```\n\n## EXAMPLES\n* Class transplantation:\n```python\n\u003e\u003e\u003e import hacky\n\u003e\u003e\u003e hacky.set_class(100, type('MyInt', (int,), {'__repr__': lambda self: \"hello from hacky\"}))\nhello from hacky\n\u003e\u003e\u003e 100\nhello from hacky\n\u003e\u003e\u003e \n```\n\n* Messing around with tp_flags:\n```python\n\u003e\u003e\u003e from types import FunctionType\n\u003e\u003e\u003e import hacky\n\u003e\u003e\u003e hacky.set_flags(\n        FunctionType,\n        hacky.get_flags(FunctionType) | (1 \u003c\u003c 10)\n    )\n\u003cclass 'function'\u003e\n# you can now subclass function type\n\u003e\u003e\u003e class T(FunctionType): pass\n\u003e\u003e\u003e\n```\n\n* Make your class final:\n```python\n\u003e\u003e\u003e hacky.set_flags(int, hacky.get_flags(int) ^ (1 \u003c\u003c 10))\n\u003cclass 'int'\u003e\n\u003e\u003e\u003e class T(int): pass\nTypeError: type 'int' is not an acceptable base type\n```\n\n* Read process's memory. Lets examine memory around `int` object `100`.\n```python\n\u003e\u003e\u003e [hacky.read_memory_in(id(100)+shift) for shift in range(20)]\n[7, 0, 0, 0, 0, 0, 0, 0, 192, 228, 158, 0, 0, 0, 0, 0, 1, 0, 0, 0]\n\u003e\u003e\u003e import struct\n\u003e\u003e\u003e [int(item) for item in struct.pack('\u003cI', id(int))]\n[192, 228, 158, 0]\n```\nThere are 7 links on this instance and also we get correct address of type `int` located in memory.\n\n* Modify process's memory:\n```python\n\u003e\u003e\u003e hacky.write_memory_in(id(100)+24, 200)\n\u003e\u003e\u003e 100\n200\n```\n\n* Inject attr at type`s dictionary\n```python\n\u003e\u003e\u003e object_dict = hacky.fetch_dict(object)\n\u003e\u003e\u003e object_dict[\"foo\"] = \"hello world\"\n\u003e\u003e\u003e (100).foo\n'hello world'\n\u003e\u003e\u003e \"hello world\".foo\n'hello world'\n\u003e\u003e\u003e (lambda x: x).foo\n'hello world'\n```\n\n* More stuff soon. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmagniff%2Fhacky","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmagniff%2Fhacky","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmagniff%2Fhacky/lists"}