{"id":15717923,"url":"https://github.com/penvirus/macho_parser","last_synced_at":"2025-05-13T02:16:25.349Z","repository":{"id":57439017,"uuid":"91766846","full_name":"penvirus/macho_parser","owner":"penvirus","description":"MachO binary parser","archived":false,"fork":false,"pushed_at":"2017-06-07T08:08:58.000Z","size":5,"stargazers_count":8,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-13T02:16:19.752Z","etag":null,"topics":["macho-parser","macosx"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/penvirus.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}},"created_at":"2017-05-19T04:53:45.000Z","updated_at":"2024-06-22T00:40:49.000Z","dependencies_parsed_at":"2022-09-18T09:04:00.513Z","dependency_job_id":null,"html_url":"https://github.com/penvirus/macho_parser","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/penvirus%2Fmacho_parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/penvirus%2Fmacho_parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/penvirus%2Fmacho_parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/penvirus%2Fmacho_parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/penvirus","download_url":"https://codeload.github.com/penvirus/macho_parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253856666,"owners_count":21974582,"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":["macho-parser","macosx"],"created_at":"2024-10-03T21:51:39.545Z","updated_at":"2025-05-13T02:16:25.325Z","avatar_url":"https://github.com/penvirus.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# macho_parser\n\nThis macho parser is intentionally incomplete.  If you have any feature request, please contact me.  I could enhance the module if I have time :-)\n\nIn addition to parse common meta data of Mach-O, I used it mainly to retrieve \"purposely hidden\" information within the MachO binary.  See the following examples to learn more.\n\nNOTE: little-endian\n\n# APIs\n## get_header()\nreturn a namedtuple regarding to a Mach-O header for either 32-bit and 64-bit\n## get_load_commands()\nreturn a generator for each load commands\n## get_segments()\nreturn a generator for each segments for either LC_SEGMENT or LC_SEGMENT_64\n## get_sections()\nreturn a generator for each sections for either SECTION or SECTION_64\n## get_section_data(segname, sectname)\nreturn the data within specific segment and specfic section\n\n# Examples\nC source code to put some information into Mach-O structure\n```\n#include \u003cstdio.h\u003e\n\nstatic char str[] __attribute__ ((section(\"__EXAMPLE_SEG,__example_sect\"))) = \"Hello World!\";\n\nint main()\n{\n        printf(\"%s\\n\", str);\n        return 0;\n}\n```\n\ncompile the program\n```\n$ clang -segprot __EXAMPLE_SEG rwx r example.c\n```\nNote: the -segprot tell clang to make the segment read-only\n\nretrieve the header\n```\n\u003e\u003e\u003e from macho_parser.macho_parser import MachO\n\u003e\u003e\u003e with MachO('/tmp/a.out') as m:\n...     print m.get_header()\n...\nmach_header_64(magic=4277009103, cputype=16777223, cpusubtype=-2147483645, filetype=2, ncmds=16, [snip]\n```\n\nlist each load commands\n```\n\u003e\u003e\u003e with MachO('/tmp/a.out') as m:\n...     for lc in m.get_load_commands():\n...             print lc\n...\nload_command(cmd=25, cmdsize=72)\nload_command(cmd=25, cmdsize=472)\nload_command(cmd=25, cmdsize=232)\nload_command(cmd=25, cmdsize=152)\nload_command(cmd=25, cmdsize=72)\nload_command(cmd=2147483682, cmdsize=48)\nload_command(cmd=2, cmdsize=24)\nload_command(cmd=11, cmdsize=80)\nload_command(cmd=14, cmdsize=32)\nload_command(cmd=27, cmdsize=24)\nload_command(cmd=36, cmdsize=16)\nload_command(cmd=42, cmdsize=16)\nload_command(cmd=2147483688, cmdsize=24)\nload_command(cmd=12, cmdsize=56)\nload_command(cmd=38, cmdsize=16)\nload_command(cmd=41, cmdsize=16)\n```\n\nlist each segments\n```\nwith MachO('/tmp/a.out') as m:\n...     for seg in m.get_segments():\n...             print seg\n...\nsegment_command_64(cmd=25, cmdsize=72, segname='__PAGEZERO\\x00\\x00\\x00\\x00\\x00\\x00',[snip]\nsegment_command_64(cmd=25, cmdsize=472, segname='__TEXT\\x00\\x00\\x00\\x00\\x00\\x00\\x00[snip]\nsegment_command_64(cmd=25, cmdsize=232, segname='__DATA\\x00\\x00\\x00\\x00\\x00\\x00\\x00[snip]\nsegment_command_64(cmd=25, cmdsize=152, segname='__EXAMPLE_SEG\\x00\\x00\\x00',[snip]\nsegment_command_64(cmd=25, cmdsize=72, segname='__LINKEDIT\\x00\\x00\\x00\\x00\\x00\\x00',[snip]\n```\n\nlist each sections\n```\n\u003e\u003e\u003e with MachO('/tmp/a.out') as m:\n...     for sect in m.get_sections():\n...             print sect\n...\nsection_64(sectname='__text\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00', segname='__TEXT\\x00[snip]\nsection_64(sectname='__stubs\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00', segname='__TEXT\\x00[snip]\nsection_64(sectname='__stub_helper\\x00\\x00\\x00', segname='__TEXT\\x00\\x00\\x00\\x00\\x00[snip]\nsection_64(sectname='__cstring\\x00\\x00\\x00\\x00\\x00\\x00\\x00', segname='__TEXT\\x00\\x00[snip]\nsection_64(sectname='__unwind_info\\x00\\x00\\x00', segname='__TEXT\\x00\\x00\\x00\\x00\\x00[snip]\nsection_64(sectname='__nl_symbol_ptr\\x00', segname='__DATA\\x00\\x00\\x00\\x00\\x00\\x00[snip]\nsection_64(sectname='__la_symbol_ptr\\x00', segname='__DATA\\x00\\x00\\x00\\x00\\x00\\x00[snip]\nsection_64(sectname='__example_sect\\x00\\x00', segname='__EXAMPLE_SEG\\x00\\x00\\x00'[snip]\n```\n\nretrieve data within __EXAMPLE_SEG.__example_sect\n```\n\u003e\u003e\u003e with MachO('/tmp/a.out') as m:\n...     print m.get_section_data('__EXAMPLE_SEG', '__example_sect')\n...\nHello World!\n```\n\n# Links\n\nhttps://pypi.python.org/pypi/macho_parser\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpenvirus%2Fmacho_parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpenvirus%2Fmacho_parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpenvirus%2Fmacho_parser/lists"}