Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 173 lines (164 sloc) 5.088 kB
67562a7 @comex more py files
authored
1 from block import *
2 from macho_cs import Blob
8fbb79f @comex bad crap
authored
3 from stuff import HexAdapter
67562a7 @comex more py files
authored
4
5 UInt32 = ULInt32
6
7 LoadCommand = Struct("LoadCommand",
8 Enum(UInt32("cmd"),
9 LC_SEGMENT = 0x1,
10 LC_SYMTAB = 0x2,
11 LC_SYMSEG = 0x3,
12 LC_THREAD = 0x4,
13 LC_UNIXTHREAD = 0x5,
14 LC_LOADFVMLIB = 0x6,
15 LC_IDFVMLIB = 0x7,
16 LC_IDENT = 0x8,
17 LC_FVMFILE = 0x9,
18 LC_PREPAGE = 0xa,
19 LC_DYSYMTAB = 0xb,
20 LC_LOAD_DYLIB = 0xc,
21 LC_ID_DYLIB = 0xd,
22 LC_LOAD_DYLINKER = 0xe,
23 LC_ID_DYLINKER = 0xf,
24 LC_PREBOUND_DYLIB = 0x10,
25 LC_ROUTINES = 0x11,
26 LC_SUB_FRAMEWORK = 0x12,
27 LC_SUB_UMBRELLA = 0x13,
28 LC_SUB_CLIENT = 0x14,
29 LC_SUB_LIBRARY = 0x15,
30 LC_TWOLEVEL_HINTS = 0x16,
31 LC_PREBIND_CKSUM = 0x17,
32 LC_LOAD_WEAK_DYLIB = 0x80000018,
33 LC_SEGMENT_64 = 0x19,
34 LC_ROUTINES_64 = 0x1a,
35 LC_UUID = 0x1b,
36 LC_RPATH = 0x8000001c,
37 LC_CODE_SIGNATURE = 0x1d,
38 LC_SEGMENT_SPLIT_INFO = 0x1e,
39 LC_REEXPORT_DYLIB = 0x8000001f,
40 LC_LAZY_LOAD_DYLIB = 0x20,
41 LC_ENCRYPTION_INFO = 0x21,
42 LC_DYLD_INFO = 0x22,
43 LC_DYLD_INFO_ONLY = 0x80000022,
44 LC_LOAD_UPWARD_DYLIB = 0x80000023,
f9dc323 @comex update
authored
45 LC_VERSION_MIN_MACOSX = 0x24,
46 LC_VERSION_MIN_IPHONEOS = 0x25,
47 LC_FUNCTION_STARTS = 0x26,
48 LC_DYLD_ENVIRONMENT = 0x27,
49 LC_MAIN = 0x80000028,
50 LC_DATA_IN_CODE = 0x29,
51 LC_SOURCE_VERSION = 0x2a,
52 LC_DYLIB_CODE_SIGN_DRS = 0x2b,
53 LC_ENCRYPTION_INFO_64 = 0x2c,
54 LC_LINKER_OPTION = 0x2d,
55 LC_LINKER_OPTIMIZATION_HINT = 0x2e,
67562a7 @comex more py files
authored
56 ),
f9dc323 @comex update
authored
57
67562a7 @comex more py files
authored
58 UInt32("cmdsize"),
59 Peek(Switch("data", lambda ctx: ctx['cmd'], {
60 'LC_SEGMENT': Struct('segment',
61 PaddedStringAdapter(Bytes('segname', 16)),
62 UInt32('vmaddr'),
63 UInt32('vmsize'),
64 UInt32('fileoff'),
65 UInt32('filesize'),
66 UInt32('maxprot'),
67 UInt32('initprot'),
68 UInt32('nsects'),
69 UInt32('flags'),
70 Rename("sections", StrictRepeater(lambda ctx: ctx['nsects'], Struct('Section',
71 PaddedStringAdapter(Bytes('sectname', 16)),
72 PaddedStringAdapter(Bytes('segname', 16)),
73 UInt32('addr'),
74 UInt32('size'),
75 UInt32('offset'),
76 UInt32('align'),
77 UInt32('reloff'),
78 UInt32('nreloc'),
79 UInt32('flags'),
80 UInt32('reserved1'),
81 UInt32('reserved2'),
82 ))),
83 ),
84 'LC_CODE_SIGNATURE': Struct("codesig",
85 UInt32('dataoff'),
86 UInt32('datasize'),
87 Pointer(lambda ctx: ctx['_']['_']['macho_start'] + ctx['dataoff'], Blob),
88 ),
89 }, default = Pass)),
90 OnDemand(Bytes('bytes', lambda ctx: ctx['cmdsize'] - 8)),
91 #Probe(),
92 )
93
94 MachO = Struct("MachO",
95 Anchor("macho_start"),
96 Enum(UInt32("magic"),
97 MH_MAGIC = 0xfeedface,
98 MH_MAGIC_64 = 0xfeedfacf,
99 ),
100 UInt32("cputype"),
101 UInt32("cpusubtype"),
102 Enum(UInt32("filetype"),
103 MH_OBJECT = 0x1,
104 MH_EXECUTE = 0x2,
105 MH_FVMLIB = 0x3,
106 MH_CORE = 0x4,
107 MH_PRELOAD = 0x5,
108 MH_DYLIB = 0x6,
109 MH_DYLINKER = 0x7,
110 MH_BUNDLE = 0x8,
111 MH_DYLIB_STUB = 0x9,
112 MH_DSYM = 0xa,
113 MH_KEXT_BUNDLE = 0xb,
114 _default_ = Pass,
115 ),
116 UInt32("ncmds"),
117 UInt32("sizeofcmds"),
118 FlagsEnum(UInt32("flags"),
119 MH_NOUNDEFS = 0x1,
120 MH_INCRLINK = 0x2,
121 MH_DYLDLINK = 0x4,
122 MH_BINDATLOAD = 0x8,
123 MH_PREBOUND = 0x10,
124 MH_SPLIT_SEGS = 0x20,
125 MH_LAZY_INIT = 0x40,
126 MH_TWOLEVEL = 0x80,
127 MH_FORCE_FLAT = 0x100,
128 MH_NOMULTIDEFS = 0x200,
129 MH_NOFIXPREBINDING = 0x400,
130 MH_PREBINDABLE = 0x800,
131 MH_ALLMODSBOUND = 0x1000,
132 MH_SUBSECTIONS_VIA_SYMBOLS = 0x2000,
133 MH_CANONICAL = 0x4000,
134 MH_WEAK_DEFINES = 0x8000,
135 MH_BINDS_TO_WEAK = 0x10000,
136 MH_ALLOW_STACK_EXECUTION = 0x20000,
137 MH_DEAD_STRIPPABLE_DYLIB = 0x400000,
138 MH_ROOT_SAFE = 0x40000,
139 MH_SETUID_SAFE = 0x80000,
140 MH_NO_REEXPORTED_DYLIBS = 0x100000,
141 MH_PIE = 0x200000,
142 ),
143 If(lambda ctx: ctx['magic'] == 'MH_MAGIC_64', UInt32('reserved')),
144 Rename('commands', StrictRepeater(lambda ctx: ctx['ncmds'], LoadCommand))
145 )
146
147 FatArch = Struct("FatArch",
148 UBInt32("cputype"),
149 UBInt32("cpusubtype"),
150 UBInt32("offset"),
151 UBInt32("size"),
152 UBInt32("align"),
153 Pointer(lambda ctx: ctx['offset'], MachO),
154 )
155
156 Fat = Struct("Fat",
157 HexAdapter(Const(UBInt32("magic"), 0xcafebabe)),
158 UBInt32("nfat_arch"),
159 StrictRepeater(lambda ctx: ctx['nfat_arch'], FatArch),
160 )
161
8c0e431 @comex add raw blob parsing; fix requirement parsing
authored
162 InputFile = Struct("InputFile",
67562a7 @comex more py files
authored
163 Peek(UInt32("magic")),
164 Switch("data", lambda ctx: ctx['magic'], {
165 0xfeedface: MachO,
f9dc323 @comex update
authored
166 0xfeedfacf: MachO,
67562a7 @comex more py files
authored
167 0xcafebabe: Fat,
168 0xbebafeca: Fat,
8c0e431 @comex add raw blob parsing; fix requirement parsing
authored
169 0xc10cdefa: Blob,
67562a7 @comex more py files
authored
170 })
171 )
172
Something went wrong with that request. Please try again.