{"id":13643543,"url":"https://github.com/lunixbochs/patchkit","last_synced_at":"2025-04-04T15:08:10.890Z","repository":{"id":10269877,"uuid":"65162266","full_name":"lunixbochs/patchkit","owner":"lunixbochs","description":"binary patching from Python","archived":false,"fork":false,"pushed_at":"2023-07-06T02:12:21.000Z","size":231,"stargazers_count":631,"open_issues_count":23,"forks_count":85,"subscribers_count":28,"default_branch":"master","last_synced_at":"2024-10-30T08:19:08.728Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lunixbochs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-08-08T01:10:47.000Z","updated_at":"2024-10-29T02:06:46.000Z","dependencies_parsed_at":"2024-01-13T03:01:07.606Z","dependency_job_id":null,"html_url":"https://github.com/lunixbochs/patchkit","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/lunixbochs%2Fpatchkit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lunixbochs%2Fpatchkit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lunixbochs%2Fpatchkit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lunixbochs%2Fpatchkit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lunixbochs","download_url":"https://codeload.github.com/lunixbochs/patchkit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247198459,"owners_count":20900080,"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":[],"created_at":"2024-08-02T01:01:49.033Z","updated_at":"2025-04-04T15:08:10.870Z","avatar_url":"https://github.com/lunixbochs.png","language":"C","readme":"patchkit\n----\nPatches an ELF binary using one or more simple Python scripts.\n\nUsage:\n\n    patch \u003cbinary\u003e \u003cpatchdir|file\u003e [patchdir|file...]\n\n\npatchdir\n----\nContains one or more Python patch files, which will be executed in alphabetical order against a binary.\n\n\nPatch Examples\n----\n\nNopping an address, injecting an assembly function, and hooking the entry point:\n\n    def simple_patch(pt):\n        # nop out a jump at the entry point\n        pt.patch(pt.entry, hex='90' * 5)\n\n        # inject assembly into the binary and return the address\n        addr = pt.inject(asm='mov eax, 1; ret')\n\n        # hook the entry point to make it call addr (ret will run the original entry point)\n        pt.hook(pt.entry, addr)\n\nReplacing a C function:\n\n    def replace_free(pt):\n        # pretend free() is at this address:\n        old_free = 0x804fc4\n\n        # inject a function to replace free()\n        new_free = pt.inject(c=r'''\n        void free_stub(void *addr) {\n            printf(\"stubbed free(%p)\\n\", addr);\n        }\n        ''')\n\n        # patch the beginning of free() with a jump to our new function\n        pt.patch(old_free, jmp=new_free)\n\n\nAPI\n----\n    addr = search(data)\n    hook(addr, new_addr)\n    patch(addr, *compile arg*)\n    addr = inject(*compile arg*)\n\n    *compile arg* is any of the following:\n      raw='data'\n      hex='0bfe'\n      asm='nop'\n      jmp=0xaddr\n      c='void func() { int a; a = 1; }' (only supported on inject, not patch)\n\n\nIDA scripts\n----\nSome scripts live in the ida/ path. Run them like this:\n\n    /Applications/IDA\\ Pro\\ 6.8/idaq.app/Contents/MacOS/idaq64 -A -Sida/allfuncs.py a.out\n\nWhen invoked like this, allfuncs.py will generate `a.out.funcs` which is used by hardening scripts.\n\n\nTools\n----\nThese are somewhat CGC and x86-specific right now, but will be ported for general use in the future.\n\n- explore: uses a Python CFG and recursive backtracking emulator to find basic blocks in an executable\n- bindiff: uses the block boundaries from an explore run, as well as additional analysis to find and output basic block diffs between two binaries\n\n\nDependencies\n----\n- Run `./deps.sh` to automatically install these.\n  - Capstone Engine - https://github.com/aquynh/capstone.git\n  - Keystone Engine - https://github.com/keystone-engine/keystone.git\n  - Unicorn Engine  - https://github.com/unicorn-engine/unicorn.git\n","funding_links":[],"categories":["C","\u003ca id=\"7d557bc3d677d206ef6c5a35ca8b3a14\"\u003e\u003c/a\u003e补丁\u0026\u0026Patch"],"sub_categories":["\u003ca id=\"cf2efa7e3edb24975b92d2e26ca825d2\"\u003e\u003c/a\u003eROP"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flunixbochs%2Fpatchkit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flunixbochs%2Fpatchkit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flunixbochs%2Fpatchkit/lists"}