This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathreadmacho.py
executable file
·60 lines (48 loc) · 2.65 KB
/
readmacho.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python
# encoding: utf-8
"""
Copyright 2013 Jérémie BOUTOILLE
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import argparse
from pymacho.MachO import MachO
from pymacho.Utils import yellow, green
def main():
parser = argparse.ArgumentParser(description="Read Mach-O file")
parser.add_argument('filename', help='Mach-O file to parse and print')
parser.add_argument('--headers', '-hd', help='show informations about header', action='store_true')
parser.add_argument('--segments', '-sg', help='display all segments', action='store_true')
parser.add_argument('--load-commands', '-lc', help='display all load commands', action='store_true')
parser.add_argument('--verbose', '-v', help='display many informations', action='store_true')
args = parser.parse_args()
m = MachO(args.filename)
if args.headers:
print yellow("[*]")+ " Headers :"
print green("\t[+]")+" magic : 0x%x %s" % (m.header.magic, "- " + m.header.display_magic() if args.verbose else "")
print green("\t[+]")+" cputype : 0x%x %s" % (m.header.cputype, "- " + m.header.display_cputype() if args.verbose else "")
print green("\t[+]")+" cpusubtype : 0x%s" % (m.header.cpusubtype)
print green("\t[+]")+" filetype : 0x%x %s" % (m.header.filetype, "- " + m.header.display_filetype() if args.verbose else "")
print green("\t[+]")+" ncmds : %d" % (m.header.ncmds)
print green("\t[+]")+" sizeofcmds : %d byte%s" % (m.header.sizeofcmds, "s" if m.header.sizeofcmds > 1 else "")
print green("\t[+]")+" flags : 0x%x %s" % (m.header.flags, "- " + ", ".join(m.header.display_flags()) if args.verbose else "")
if m.header.is_64():
print green("\t[+]")+" reserved : 0x%x" % (m.header.reserved)
if args.segments:
print yellow("[*]")+" Segments (%d) :" % len(m.segments)
for segment in m.segments:
segment.display(before="\t")
if args.load_commands:
print yellow("[*]")+" Load Commands (%d) :" % len(m.commands)
for lc in m.commands:
lc.display("\t")
if __name__ == '__main__':
main()