polyfile-weave 0.5.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of polyfile-weave might be problematic. Click here for more details.

Files changed (585) hide show
  1. polyfile/__init__.py +15 -0
  2. polyfile/__main__.py +394 -0
  3. polyfile/arithmetic.py +27 -0
  4. polyfile/ast.py +114 -0
  5. polyfile/debugger.py +1039 -0
  6. polyfile/expressions.py +346 -0
  7. polyfile/fileutils.py +343 -0
  8. polyfile/html.py +135 -0
  9. polyfile/http/__init__.py +1 -0
  10. polyfile/http/defacto.py +37 -0
  11. polyfile/http/deprecated.py +51 -0
  12. polyfile/http/experimental.py +67 -0
  13. polyfile/http/http_11.py +548 -0
  14. polyfile/http/matcher.py +37 -0
  15. polyfile/http/structured_headers.py +48 -0
  16. polyfile/iterators.py +72 -0
  17. polyfile/jpeg.py +24 -0
  18. polyfile/kaitai/__init__.py +0 -0
  19. polyfile/kaitai/compiler.py +156 -0
  20. polyfile/kaitai/parser.py +312 -0
  21. polyfile/kaitai/parsers/__init__.py +0 -0
  22. polyfile/kaitai/parsers/aix_utmp.py +116 -0
  23. polyfile/kaitai/parsers/allegro_dat.py +367 -0
  24. polyfile/kaitai/parsers/andes_firmware.py +64 -0
  25. polyfile/kaitai/parsers/android_bootldr_asus.py +105 -0
  26. polyfile/kaitai/parsers/android_bootldr_huawei.py +181 -0
  27. polyfile/kaitai/parsers/android_bootldr_qcom.py +217 -0
  28. polyfile/kaitai/parsers/android_dto.py +138 -0
  29. polyfile/kaitai/parsers/android_img.py +319 -0
  30. polyfile/kaitai/parsers/android_nanoapp_header.py +83 -0
  31. polyfile/kaitai/parsers/android_opengl_shaders_cache.py +151 -0
  32. polyfile/kaitai/parsers/android_sparse.py +237 -0
  33. polyfile/kaitai/parsers/android_super.py +401 -0
  34. polyfile/kaitai/parsers/apm_partition_table.py +196 -0
  35. polyfile/kaitai/parsers/apple_single_double.py +180 -0
  36. polyfile/kaitai/parsers/asn1_der.py +235 -0
  37. polyfile/kaitai/parsers/au.py +138 -0
  38. polyfile/kaitai/parsers/avantes_roh60.py +112 -0
  39. polyfile/kaitai/parsers/avi.py +296 -0
  40. polyfile/kaitai/parsers/bcd.py +111 -0
  41. polyfile/kaitai/parsers/bitcoin_transaction.py +210 -0
  42. polyfile/kaitai/parsers/blender_blend.py +334 -0
  43. polyfile/kaitai/parsers/bmp.py +780 -0
  44. polyfile/kaitai/parsers/bson.py +411 -0
  45. polyfile/kaitai/parsers/btrfs_stream.py +318 -0
  46. polyfile/kaitai/parsers/bytes_with_io.py +27 -0
  47. polyfile/kaitai/parsers/chrome_pak.py +194 -0
  48. polyfile/kaitai/parsers/code_6502.py +456 -0
  49. polyfile/kaitai/parsers/compressed_resource.py +217 -0
  50. polyfile/kaitai/parsers/cpio_old_le.py +154 -0
  51. polyfile/kaitai/parsers/cramfs.py +344 -0
  52. polyfile/kaitai/parsers/creative_voice_file.py +342 -0
  53. polyfile/kaitai/parsers/dbf.py +274 -0
  54. polyfile/kaitai/parsers/dcmp_0.py +664 -0
  55. polyfile/kaitai/parsers/dcmp_1.py +422 -0
  56. polyfile/kaitai/parsers/dcmp_2.py +312 -0
  57. polyfile/kaitai/parsers/dcmp_variable_length_integer.py +66 -0
  58. polyfile/kaitai/parsers/dex.py +1086 -0
  59. polyfile/kaitai/parsers/dicom.py +4370 -0
  60. polyfile/kaitai/parsers/dime_message.py +201 -0
  61. polyfile/kaitai/parsers/dns_packet.py +569 -0
  62. polyfile/kaitai/parsers/doom_wad.py +654 -0
  63. polyfile/kaitai/parsers/dos_datetime.py +191 -0
  64. polyfile/kaitai/parsers/dos_mz.py +172 -0
  65. polyfile/kaitai/parsers/ds_store.py +513 -0
  66. polyfile/kaitai/parsers/dtb.py +310 -0
  67. polyfile/kaitai/parsers/dune_2_pak.py +126 -0
  68. polyfile/kaitai/parsers/edid.py +472 -0
  69. polyfile/kaitai/parsers/efivar_signature_list.py +331 -0
  70. polyfile/kaitai/parsers/elf.py +2482 -0
  71. polyfile/kaitai/parsers/ethernet_frame.py +114 -0
  72. polyfile/kaitai/parsers/exif.py +723 -0
  73. polyfile/kaitai/parsers/ext2.py +537 -0
  74. polyfile/kaitai/parsers/fallout2_dat.py +187 -0
  75. polyfile/kaitai/parsers/fallout_dat.py +156 -0
  76. polyfile/kaitai/parsers/fasttracker_xm_module.py +558 -0
  77. polyfile/kaitai/parsers/ftl_dat.py +90 -0
  78. polyfile/kaitai/parsers/genmidi_op2.py +161 -0
  79. polyfile/kaitai/parsers/gettext_mo.py +541 -0
  80. polyfile/kaitai/parsers/gif.py +492 -0
  81. polyfile/kaitai/parsers/gimp_brush.py +244 -0
  82. polyfile/kaitai/parsers/glibc_utmp.py +114 -0
  83. polyfile/kaitai/parsers/gltf_binary.py +132 -0
  84. polyfile/kaitai/parsers/google_protobuf.py +151 -0
  85. polyfile/kaitai/parsers/gpt_partition_table.py +175 -0
  86. polyfile/kaitai/parsers/gran_turismo_vol.py +140 -0
  87. polyfile/kaitai/parsers/grub2_font.py +337 -0
  88. polyfile/kaitai/parsers/gzip.py +232 -0
  89. polyfile/kaitai/parsers/hashcat_restore.py +60 -0
  90. polyfile/kaitai/parsers/hccap.py +111 -0
  91. polyfile/kaitai/parsers/hccapx.py +103 -0
  92. polyfile/kaitai/parsers/heaps_pak.py +177 -0
  93. polyfile/kaitai/parsers/heroes_of_might_and_magic_agg.py +116 -0
  94. polyfile/kaitai/parsers/heroes_of_might_and_magic_bmp.py +34 -0
  95. polyfile/kaitai/parsers/icmp_packet.py +136 -0
  96. polyfile/kaitai/parsers/ico.py +129 -0
  97. polyfile/kaitai/parsers/id3v1_1.py +220 -0
  98. polyfile/kaitai/parsers/id3v2_3.py +324 -0
  99. polyfile/kaitai/parsers/id3v2_4.py +423 -0
  100. polyfile/kaitai/parsers/ines.py +282 -0
  101. polyfile/kaitai/parsers/ipv4_packet.py +158 -0
  102. polyfile/kaitai/parsers/ipv6_packet.py +55 -0
  103. polyfile/kaitai/parsers/iso9660.py +544 -0
  104. polyfile/kaitai/parsers/java_class.py +1113 -0
  105. polyfile/kaitai/parsers/jpeg.py +361 -0
  106. polyfile/kaitai/parsers/luks.py +149 -0
  107. polyfile/kaitai/parsers/lzh.py +165 -0
  108. polyfile/kaitai/parsers/mac_os_resource_snd.py +493 -0
  109. polyfile/kaitai/parsers/mach_o.py +3033 -0
  110. polyfile/kaitai/parsers/mach_o_fat.py +92 -0
  111. polyfile/kaitai/parsers/magicavoxel_vox.py +391 -0
  112. polyfile/kaitai/parsers/manifest.json +1 -0
  113. polyfile/kaitai/parsers/mbr_partition_table.py +119 -0
  114. polyfile/kaitai/parsers/mcap.py +1015 -0
  115. polyfile/kaitai/parsers/microsoft_cfb.py +293 -0
  116. polyfile/kaitai/parsers/microsoft_network_monitor_v2.py +309 -0
  117. polyfile/kaitai/parsers/microsoft_pe.py +765 -0
  118. polyfile/kaitai/parsers/mifare_classic.py +706 -0
  119. polyfile/kaitai/parsers/minecraft_nbt.py +449 -0
  120. polyfile/kaitai/parsers/monomakh_sapr_chg.py +69 -0
  121. polyfile/kaitai/parsers/mozilla_mar.py +239 -0
  122. polyfile/kaitai/parsers/mp4.py +333 -0
  123. polyfile/kaitai/parsers/msgpack.py +467 -0
  124. polyfile/kaitai/parsers/nitf.py +1189 -0
  125. polyfile/kaitai/parsers/nt_mdt_pal.py +155 -0
  126. polyfile/kaitai/parsers/ogg.py +118 -0
  127. polyfile/kaitai/parsers/openpgp_message.py +993 -0
  128. polyfile/kaitai/parsers/packet_ppi.py +515 -0
  129. polyfile/kaitai/parsers/pcap.py +344 -0
  130. polyfile/kaitai/parsers/pcf_font.py +506 -0
  131. polyfile/kaitai/parsers/pcx.py +195 -0
  132. polyfile/kaitai/parsers/pcx_dcx.py +79 -0
  133. polyfile/kaitai/parsers/phar_without_stub.py +399 -0
  134. polyfile/kaitai/parsers/php_serialized_value.py +505 -0
  135. polyfile/kaitai/parsers/png.py +721 -0
  136. polyfile/kaitai/parsers/protocol_body.py +260 -0
  137. polyfile/kaitai/parsers/psx_tim.py +104 -0
  138. polyfile/kaitai/parsers/python_pickle.py +718 -0
  139. polyfile/kaitai/parsers/python_pyc_27.py +510 -0
  140. polyfile/kaitai/parsers/quake_mdl.py +441 -0
  141. polyfile/kaitai/parsers/quake_pak.py +112 -0
  142. polyfile/kaitai/parsers/quicktime_mov.py +634 -0
  143. polyfile/kaitai/parsers/rar.py +265 -0
  144. polyfile/kaitai/parsers/regf.py +569 -0
  145. polyfile/kaitai/parsers/renderware_binary_stream.py +877 -0
  146. polyfile/kaitai/parsers/resource_fork.py +611 -0
  147. polyfile/kaitai/parsers/respack.py +57 -0
  148. polyfile/kaitai/parsers/riff.py +409 -0
  149. polyfile/kaitai/parsers/rpm.py +964 -0
  150. polyfile/kaitai/parsers/rtcp_payload.py +579 -0
  151. polyfile/kaitai/parsers/rtp_packet.py +150 -0
  152. polyfile/kaitai/parsers/rtpdump.py +115 -0
  153. polyfile/kaitai/parsers/ruby_marshal.py +423 -0
  154. polyfile/kaitai/parsers/s3m.py +493 -0
  155. polyfile/kaitai/parsers/saints_row_2_vpp_pc.py +254 -0
  156. polyfile/kaitai/parsers/shapefile_index.py +174 -0
  157. polyfile/kaitai/parsers/shapefile_main.py +893 -0
  158. polyfile/kaitai/parsers/some_ip.py +209 -0
  159. polyfile/kaitai/parsers/some_ip_container.py +37 -0
  160. polyfile/kaitai/parsers/some_ip_sd.py +86 -0
  161. polyfile/kaitai/parsers/some_ip_sd_entries.py +160 -0
  162. polyfile/kaitai/parsers/some_ip_sd_options.py +374 -0
  163. polyfile/kaitai/parsers/specpr.py +404 -0
  164. polyfile/kaitai/parsers/sqlite3.py +472 -0
  165. polyfile/kaitai/parsers/ssh_public_key.py +252 -0
  166. polyfile/kaitai/parsers/standard_midi_file.py +390 -0
  167. polyfile/kaitai/parsers/stl.py +111 -0
  168. polyfile/kaitai/parsers/sudoers_ts.py +201 -0
  169. polyfile/kaitai/parsers/swf.py +406 -0
  170. polyfile/kaitai/parsers/systemd_journal.py +361 -0
  171. polyfile/kaitai/parsers/tcp_segment.py +57 -0
  172. polyfile/kaitai/parsers/tga.py +213 -0
  173. polyfile/kaitai/parsers/tls_client_hello.py +293 -0
  174. polyfile/kaitai/parsers/tr_dos_image.py +322 -0
  175. polyfile/kaitai/parsers/tsm.py +198 -0
  176. polyfile/kaitai/parsers/ttf.py +1847 -0
  177. polyfile/kaitai/parsers/udp_datagram.py +42 -0
  178. polyfile/kaitai/parsers/uefi_te.py +236 -0
  179. polyfile/kaitai/parsers/uimage.py +198 -0
  180. polyfile/kaitai/parsers/utf8_string.py +137 -0
  181. polyfile/kaitai/parsers/vfat.py +410 -0
  182. polyfile/kaitai/parsers/vlq_base128_be.py +104 -0
  183. polyfile/kaitai/parsers/vlq_base128_le.py +129 -0
  184. polyfile/kaitai/parsers/vmware_vmdk.py +167 -0
  185. polyfile/kaitai/parsers/vp8_ivf.py +112 -0
  186. polyfile/kaitai/parsers/warcraft_2_pud.py +423 -0
  187. polyfile/kaitai/parsers/wav.py +1014 -0
  188. polyfile/kaitai/parsers/websocket.py +167 -0
  189. polyfile/kaitai/parsers/windows_evt_log.py +304 -0
  190. polyfile/kaitai/parsers/windows_lnk_file.py +467 -0
  191. polyfile/kaitai/parsers/windows_minidump.py +575 -0
  192. polyfile/kaitai/parsers/windows_resource_file.py +243 -0
  193. polyfile/kaitai/parsers/windows_shell_items.py +190 -0
  194. polyfile/kaitai/parsers/windows_systemtime.py +52 -0
  195. polyfile/kaitai/parsers/wmf.py +502 -0
  196. polyfile/kaitai/parsers/xar.py +181 -0
  197. polyfile/kaitai/parsers/xwd.py +189 -0
  198. polyfile/kaitai/parsers/zip.py +685 -0
  199. polyfile/kaitai/parsers/zisofs.py +158 -0
  200. polyfile/kaitai/parsers/zx_spectrum_tap.py +184 -0
  201. polyfile/kaitaimatcher.py +113 -0
  202. polyfile/languagematcher.py +217 -0
  203. polyfile/logger.py +135 -0
  204. polyfile/magic.py +2983 -0
  205. polyfile/magic_defs/COPYING +29 -0
  206. polyfile/magic_defs/__init__.py +0 -0
  207. polyfile/magic_defs/acorn +102 -0
  208. polyfile/magic_defs/adi +13 -0
  209. polyfile/magic_defs/adventure +122 -0
  210. polyfile/magic_defs/aes +29 -0
  211. polyfile/magic_defs/algol68 +35 -0
  212. polyfile/magic_defs/allegro +9 -0
  213. polyfile/magic_defs/alliant +18 -0
  214. polyfile/magic_defs/alpha +32 -0
  215. polyfile/magic_defs/amanda +12 -0
  216. polyfile/magic_defs/amigaos +218 -0
  217. polyfile/magic_defs/android +259 -0
  218. polyfile/magic_defs/animation +1197 -0
  219. polyfile/magic_defs/aout +46 -0
  220. polyfile/magic_defs/apache +28 -0
  221. polyfile/magic_defs/apl +7 -0
  222. polyfile/magic_defs/apple +773 -0
  223. polyfile/magic_defs/application +7 -0
  224. polyfile/magic_defs/applix +13 -0
  225. polyfile/magic_defs/apt +52 -0
  226. polyfile/magic_defs/archive +2586 -0
  227. polyfile/magic_defs/aria +38 -0
  228. polyfile/magic_defs/arm +50 -0
  229. polyfile/magic_defs/asf +132 -0
  230. polyfile/magic_defs/assembler +18 -0
  231. polyfile/magic_defs/asterix +18 -0
  232. polyfile/magic_defs/att3b +41 -0
  233. polyfile/magic_defs/audio +1291 -0
  234. polyfile/magic_defs/avm +33 -0
  235. polyfile/magic_defs/basis +18 -0
  236. polyfile/magic_defs/beetle +7 -0
  237. polyfile/magic_defs/ber +65 -0
  238. polyfile/magic_defs/bflt +14 -0
  239. polyfile/magic_defs/bhl +10 -0
  240. polyfile/magic_defs/bioinformatics +178 -0
  241. polyfile/magic_defs/biosig +154 -0
  242. polyfile/magic_defs/blackberry +8 -0
  243. polyfile/magic_defs/blcr +25 -0
  244. polyfile/magic_defs/blender +50 -0
  245. polyfile/magic_defs/blit +24 -0
  246. polyfile/magic_defs/bm +10 -0
  247. polyfile/magic_defs/bout +11 -0
  248. polyfile/magic_defs/bsdi +33 -0
  249. polyfile/magic_defs/bsi +10 -0
  250. polyfile/magic_defs/btsnoop +13 -0
  251. polyfile/magic_defs/burp +7 -0
  252. polyfile/magic_defs/bytecode +41 -0
  253. polyfile/magic_defs/c-lang +110 -0
  254. polyfile/magic_defs/c64 +531 -0
  255. polyfile/magic_defs/cad +437 -0
  256. polyfile/magic_defs/cafebabe +107 -0
  257. polyfile/magic_defs/cbor +21 -0
  258. polyfile/magic_defs/ccf +14 -0
  259. polyfile/magic_defs/cddb +12 -0
  260. polyfile/magic_defs/chord +15 -0
  261. polyfile/magic_defs/cisco +12 -0
  262. polyfile/magic_defs/citrus +12 -0
  263. polyfile/magic_defs/clarion +27 -0
  264. polyfile/magic_defs/claris +48 -0
  265. polyfile/magic_defs/clipper +65 -0
  266. polyfile/magic_defs/clojure +30 -0
  267. polyfile/magic_defs/coff +98 -0
  268. polyfile/magic_defs/commands +201 -0
  269. polyfile/magic_defs/communications +22 -0
  270. polyfile/magic_defs/compress +461 -0
  271. polyfile/magic_defs/console +1213 -0
  272. polyfile/magic_defs/convex +69 -0
  273. polyfile/magic_defs/coverage +91 -0
  274. polyfile/magic_defs/cracklib +14 -0
  275. polyfile/magic_defs/crypto +31 -0
  276. polyfile/magic_defs/csv +8 -0
  277. polyfile/magic_defs/ctags +6 -0
  278. polyfile/magic_defs/ctf +23 -0
  279. polyfile/magic_defs/cubemap +8 -0
  280. polyfile/magic_defs/cups +56 -0
  281. polyfile/magic_defs/dact +11 -0
  282. polyfile/magic_defs/database +886 -0
  283. polyfile/magic_defs/dataone +47 -0
  284. polyfile/magic_defs/dbpf +15 -0
  285. polyfile/magic_defs/der +146 -0
  286. polyfile/magic_defs/diamond +12 -0
  287. polyfile/magic_defs/dif +33 -0
  288. polyfile/magic_defs/diff +41 -0
  289. polyfile/magic_defs/digital +59 -0
  290. polyfile/magic_defs/dolby +69 -0
  291. polyfile/magic_defs/dsf +25 -0
  292. polyfile/magic_defs/dump +96 -0
  293. polyfile/magic_defs/dwarfs +45 -0
  294. polyfile/magic_defs/dyadic +61 -0
  295. polyfile/magic_defs/ebml +8 -0
  296. polyfile/magic_defs/edid +11 -0
  297. polyfile/magic_defs/editors +43 -0
  298. polyfile/magic_defs/efi +15 -0
  299. polyfile/magic_defs/elf +379 -0
  300. polyfile/magic_defs/encore +22 -0
  301. polyfile/magic_defs/epoc +62 -0
  302. polyfile/magic_defs/erlang +21 -0
  303. polyfile/magic_defs/espressif +57 -0
  304. polyfile/magic_defs/esri +28 -0
  305. polyfile/magic_defs/etf +33 -0
  306. polyfile/magic_defs/fcs +9 -0
  307. polyfile/magic_defs/filesystems +2694 -0
  308. polyfile/magic_defs/finger +16 -0
  309. polyfile/magic_defs/firmware +133 -0
  310. polyfile/magic_defs/flash +62 -0
  311. polyfile/magic_defs/flif +36 -0
  312. polyfile/magic_defs/fonts +449 -0
  313. polyfile/magic_defs/forth +82 -0
  314. polyfile/magic_defs/fortran +9 -0
  315. polyfile/magic_defs/frame +62 -0
  316. polyfile/magic_defs/freebsd +164 -0
  317. polyfile/magic_defs/fsav +128 -0
  318. polyfile/magic_defs/fusecompress +12 -0
  319. polyfile/magic_defs/games +696 -0
  320. polyfile/magic_defs/gcc +17 -0
  321. polyfile/magic_defs/gconv +10 -0
  322. polyfile/magic_defs/gentoo +85 -0
  323. polyfile/magic_defs/geo +166 -0
  324. polyfile/magic_defs/geos +20 -0
  325. polyfile/magic_defs/gimp +77 -0
  326. polyfile/magic_defs/git +13 -0
  327. polyfile/magic_defs/glibc +21 -0
  328. polyfile/magic_defs/gnome +59 -0
  329. polyfile/magic_defs/gnu +173 -0
  330. polyfile/magic_defs/gnumeric +8 -0
  331. polyfile/magic_defs/gpt +240 -0
  332. polyfile/magic_defs/gpu +28 -0
  333. polyfile/magic_defs/grace +21 -0
  334. polyfile/magic_defs/graphviz +12 -0
  335. polyfile/magic_defs/gringotts +48 -0
  336. polyfile/magic_defs/guile +13 -0
  337. polyfile/magic_defs/hardware +12 -0
  338. polyfile/magic_defs/hitachi-sh +30 -0
  339. polyfile/magic_defs/hp +433 -0
  340. polyfile/magic_defs/human68k +26 -0
  341. polyfile/magic_defs/ibm370 +52 -0
  342. polyfile/magic_defs/ibm6000 +35 -0
  343. polyfile/magic_defs/icc +214 -0
  344. polyfile/magic_defs/iff +80 -0
  345. polyfile/magic_defs/images +4210 -0
  346. polyfile/magic_defs/inform +9 -0
  347. polyfile/magic_defs/intel +310 -0
  348. polyfile/magic_defs/interleaf +9 -0
  349. polyfile/magic_defs/island +10 -0
  350. polyfile/magic_defs/ispell +63 -0
  351. polyfile/magic_defs/isz +15 -0
  352. polyfile/magic_defs/java +52 -0
  353. polyfile/magic_defs/javascript +171 -0
  354. polyfile/magic_defs/jpeg +252 -0
  355. polyfile/magic_defs/json +8 -0
  356. polyfile/magic_defs/karma +9 -0
  357. polyfile/magic_defs/kde +11 -0
  358. polyfile/magic_defs/keepass +20 -0
  359. polyfile/magic_defs/kerberos +45 -0
  360. polyfile/magic_defs/kicad +85 -0
  361. polyfile/magic_defs/kml +34 -0
  362. polyfile/magic_defs/lammps +64 -0
  363. polyfile/magic_defs/lecter +6 -0
  364. polyfile/magic_defs/lex +12 -0
  365. polyfile/magic_defs/lif +50 -0
  366. polyfile/magic_defs/linux +557 -0
  367. polyfile/magic_defs/lisp +78 -0
  368. polyfile/magic_defs/llvm +22 -0
  369. polyfile/magic_defs/locoscript +12 -0
  370. polyfile/magic_defs/lua +31 -0
  371. polyfile/magic_defs/luks +126 -0
  372. polyfile/magic_defs/m4 +11 -0
  373. polyfile/magic_defs/mach +303 -0
  374. polyfile/magic_defs/macintosh +505 -0
  375. polyfile/magic_defs/macos +7 -0
  376. polyfile/magic_defs/magic +10 -0
  377. polyfile/magic_defs/magic.mgc +0 -0
  378. polyfile/magic_defs/mail.news +132 -0
  379. polyfile/magic_defs/make +21 -0
  380. polyfile/magic_defs/map +413 -0
  381. polyfile/magic_defs/maple +109 -0
  382. polyfile/magic_defs/marc21 +30 -0
  383. polyfile/magic_defs/mathcad +8 -0
  384. polyfile/magic_defs/mathematica +188 -0
  385. polyfile/magic_defs/matroska +17 -0
  386. polyfile/magic_defs/mcrypt +52 -0
  387. polyfile/magic_defs/measure +44 -0
  388. polyfile/magic_defs/mercurial +13 -0
  389. polyfile/magic_defs/metastore +8 -0
  390. polyfile/magic_defs/meteorological +53 -0
  391. polyfile/magic_defs/microfocus +21 -0
  392. polyfile/magic_defs/mime +9 -0
  393. polyfile/magic_defs/mips +120 -0
  394. polyfile/magic_defs/mirage +8 -0
  395. polyfile/magic_defs/misctools +140 -0
  396. polyfile/magic_defs/mkid +11 -0
  397. polyfile/magic_defs/mlssa +8 -0
  398. polyfile/magic_defs/mmdf +6 -0
  399. polyfile/magic_defs/modem +92 -0
  400. polyfile/magic_defs/modulefile +9 -0
  401. polyfile/magic_defs/motorola +71 -0
  402. polyfile/magic_defs/mozilla +37 -0
  403. polyfile/magic_defs/msdos +2304 -0
  404. polyfile/magic_defs/msooxml +68 -0
  405. polyfile/magic_defs/msvc +222 -0
  406. polyfile/magic_defs/msx +309 -0
  407. polyfile/magic_defs/mup +24 -0
  408. polyfile/magic_defs/music +17 -0
  409. polyfile/magic_defs/nasa +7 -0
  410. polyfile/magic_defs/natinst +24 -0
  411. polyfile/magic_defs/ncr +49 -0
  412. polyfile/magic_defs/neko +12 -0
  413. polyfile/magic_defs/netbsd +251 -0
  414. polyfile/magic_defs/netscape +26 -0
  415. polyfile/magic_defs/netware +11 -0
  416. polyfile/magic_defs/news +13 -0
  417. polyfile/magic_defs/nifty +202 -0
  418. polyfile/magic_defs/nim-lang +29 -0
  419. polyfile/magic_defs/nitpicker +14 -0
  420. polyfile/magic_defs/numpy +9 -0
  421. polyfile/magic_defs/oasis +12 -0
  422. polyfile/magic_defs/ocaml +14 -0
  423. polyfile/magic_defs/octave +6 -0
  424. polyfile/magic_defs/ole2compounddocs +760 -0
  425. polyfile/magic_defs/olf +98 -0
  426. polyfile/magic_defs/openfst +17 -0
  427. polyfile/magic_defs/opentimestamps +16 -0
  428. polyfile/magic_defs/oric +16 -0
  429. polyfile/magic_defs/os2 +186 -0
  430. polyfile/magic_defs/os400 +39 -0
  431. polyfile/magic_defs/os9 +80 -0
  432. polyfile/magic_defs/osf1 +10 -0
  433. polyfile/magic_defs/palm +156 -0
  434. polyfile/magic_defs/parix +13 -0
  435. polyfile/magic_defs/parrot +22 -0
  436. polyfile/magic_defs/pascal +39 -0
  437. polyfile/magic_defs/pbf +11 -0
  438. polyfile/magic_defs/pbm +8 -0
  439. polyfile/magic_defs/pc88 +24 -0
  440. polyfile/magic_defs/pc98 +77 -0
  441. polyfile/magic_defs/pci_ids +116 -0
  442. polyfile/magic_defs/pcjr +8 -0
  443. polyfile/magic_defs/pdf +51 -0
  444. polyfile/magic_defs/pdp +42 -0
  445. polyfile/magic_defs/perl +100 -0
  446. polyfile/magic_defs/pgf +52 -0
  447. polyfile/magic_defs/pgp +581 -0
  448. polyfile/magic_defs/pgp-binary-keys +388 -0
  449. polyfile/magic_defs/pkgadd +7 -0
  450. polyfile/magic_defs/plan9 +25 -0
  451. polyfile/magic_defs/playdate +57 -0
  452. polyfile/magic_defs/plus5 +18 -0
  453. polyfile/magic_defs/pmem +46 -0
  454. polyfile/magic_defs/polyfile_zip +5 -0
  455. polyfile/magic_defs/polyml +23 -0
  456. polyfile/magic_defs/printer +269 -0
  457. polyfile/magic_defs/project +10 -0
  458. polyfile/magic_defs/psdbms +14 -0
  459. polyfile/magic_defs/psl +14 -0
  460. polyfile/magic_defs/pulsar +13 -0
  461. polyfile/magic_defs/puzzle +17 -0
  462. polyfile/magic_defs/pwsafe +14 -0
  463. polyfile/magic_defs/pyramid +12 -0
  464. polyfile/magic_defs/python +305 -0
  465. polyfile/magic_defs/qt +30 -0
  466. polyfile/magic_defs/revision +66 -0
  467. polyfile/magic_defs/riff +840 -0
  468. polyfile/magic_defs/rinex +44 -0
  469. polyfile/magic_defs/ringdove +45 -0
  470. polyfile/magic_defs/rpi +52 -0
  471. polyfile/magic_defs/rpm +45 -0
  472. polyfile/magic_defs/rpmsg +7 -0
  473. polyfile/magic_defs/rst +11 -0
  474. polyfile/magic_defs/rtf +94 -0
  475. polyfile/magic_defs/ruby +55 -0
  476. polyfile/magic_defs/rust +21 -0
  477. polyfile/magic_defs/sc +7 -0
  478. polyfile/magic_defs/sccs +24 -0
  479. polyfile/magic_defs/scientific +144 -0
  480. polyfile/magic_defs/securitycerts +6 -0
  481. polyfile/magic_defs/selinux +24 -0
  482. polyfile/magic_defs/sendmail +37 -0
  483. polyfile/magic_defs/sequent +42 -0
  484. polyfile/magic_defs/sereal +35 -0
  485. polyfile/magic_defs/sgi +144 -0
  486. polyfile/magic_defs/sgml +161 -0
  487. polyfile/magic_defs/sharc +23 -0
  488. polyfile/magic_defs/sinclair +40 -0
  489. polyfile/magic_defs/sisu +18 -0
  490. polyfile/magic_defs/sketch +6 -0
  491. polyfile/magic_defs/smalltalk +25 -0
  492. polyfile/magic_defs/smile +34 -0
  493. polyfile/magic_defs/sniffer +482 -0
  494. polyfile/magic_defs/softquad +40 -0
  495. polyfile/magic_defs/sosi +40 -0
  496. polyfile/magic_defs/spec +21 -0
  497. polyfile/magic_defs/spectrum +184 -0
  498. polyfile/magic_defs/sql +288 -0
  499. polyfile/magic_defs/ssh +39 -0
  500. polyfile/magic_defs/ssl +20 -0
  501. polyfile/magic_defs/statistics +45 -0
  502. polyfile/magic_defs/subtitle +38 -0
  503. polyfile/magic_defs/sun +141 -0
  504. polyfile/magic_defs/svf +5 -0
  505. polyfile/magic_defs/sylk +36 -0
  506. polyfile/magic_defs/symbos +42 -0
  507. polyfile/magic_defs/sysex +429 -0
  508. polyfile/magic_defs/tcl +29 -0
  509. polyfile/magic_defs/teapot +6 -0
  510. polyfile/magic_defs/terminfo +63 -0
  511. polyfile/magic_defs/tex +141 -0
  512. polyfile/magic_defs/tgif +7 -0
  513. polyfile/magic_defs/ti-8x +239 -0
  514. polyfile/magic_defs/timezone +42 -0
  515. polyfile/magic_defs/tplink +95 -0
  516. polyfile/magic_defs/troff +38 -0
  517. polyfile/magic_defs/tuxedo +8 -0
  518. polyfile/magic_defs/typeset +8 -0
  519. polyfile/magic_defs/uf2 +72 -0
  520. polyfile/magic_defs/unicode +15 -0
  521. polyfile/magic_defs/unisig +12 -0
  522. polyfile/magic_defs/unknown +34 -0
  523. polyfile/magic_defs/usd +21 -0
  524. polyfile/magic_defs/uterus +16 -0
  525. polyfile/magic_defs/uuencode +28 -0
  526. polyfile/magic_defs/vacuum-cleaner +54 -0
  527. polyfile/magic_defs/varied.out +46 -0
  528. polyfile/magic_defs/varied.script +21 -0
  529. polyfile/magic_defs/vax +32 -0
  530. polyfile/magic_defs/vicar +17 -0
  531. polyfile/magic_defs/virtual +307 -0
  532. polyfile/magic_defs/virtutech +12 -0
  533. polyfile/magic_defs/visx +32 -0
  534. polyfile/magic_defs/vms +30 -0
  535. polyfile/magic_defs/vmware +6 -0
  536. polyfile/magic_defs/vorbis +155 -0
  537. polyfile/magic_defs/vxl +14 -0
  538. polyfile/magic_defs/warc +16 -0
  539. polyfile/magic_defs/weak +16 -0
  540. polyfile/magic_defs/web +18 -0
  541. polyfile/magic_defs/webassembly +17 -0
  542. polyfile/magic_defs/windows +1811 -0
  543. polyfile/magic_defs/wireless +7 -0
  544. polyfile/magic_defs/wordprocessors +630 -0
  545. polyfile/magic_defs/wsdl +23 -0
  546. polyfile/magic_defs/x68000 +25 -0
  547. polyfile/magic_defs/xdelta +13 -0
  548. polyfile/magic_defs/xenix +106 -0
  549. polyfile/magic_defs/xilinx +58 -0
  550. polyfile/magic_defs/xo65 +37 -0
  551. polyfile/magic_defs/xwindows +43 -0
  552. polyfile/magic_defs/yara +17 -0
  553. polyfile/magic_defs/zfs +96 -0
  554. polyfile/magic_defs/zilog +12 -0
  555. polyfile/magic_defs/zip +126 -0
  556. polyfile/magic_defs/zyxel +17 -0
  557. polyfile/nes.py +144 -0
  558. polyfile/nitf.py +15 -0
  559. polyfile/pdf.py +1264 -0
  560. polyfile/pickles.py +45 -0
  561. polyfile/polyfile.py +409 -0
  562. polyfile/profiling.py +115 -0
  563. polyfile/repl.py +624 -0
  564. polyfile/search.py +310 -0
  565. polyfile/serialization.py +323 -0
  566. polyfile/structmatcher.py +46 -0
  567. polyfile/structs.py +281 -0
  568. polyfile/templates/download.js +162 -0
  569. polyfile/templates/hexdump.css +268 -0
  570. polyfile/templates/hexdump.js +756 -0
  571. polyfile/templates/jquery-3.4.1.min.js +2 -0
  572. polyfile/templates/template.html +119 -0
  573. polyfile/wildcards.py +62 -0
  574. polyfile/zipmatcher.py +183 -0
  575. polyfile_weave-0.5.5.dist-info/METADATA +173 -0
  576. polyfile_weave-0.5.5.dist-info/RECORD +585 -0
  577. polyfile_weave-0.5.5.dist-info/WHEEL +5 -0
  578. polyfile_weave-0.5.5.dist-info/entry_points.txt +2 -0
  579. polyfile_weave-0.5.5.dist-info/licenses/LICENSE +202 -0
  580. polyfile_weave-0.5.5.dist-info/top_level.txt +2 -0
  581. polymerge/__init__.py +1 -0
  582. polymerge/__main__.py +296 -0
  583. polymerge/cfg.py +127 -0
  584. polymerge/polymerge.py +227 -0
  585. polymerge/polytracker.py +190 -0
@@ -0,0 +1,3033 @@
1
+ # This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
2
+
3
+ from pkg_resources import parse_version
4
+ import kaitaistruct
5
+ from kaitaistruct import KaitaiStruct, KaitaiStream, BytesIO
6
+ from enum import Enum
7
+ import collections
8
+
9
+
10
+ if parse_version(kaitaistruct.__version__) < parse_version('0.9'):
11
+ raise Exception("Incompatible Kaitai Struct Python API: 0.9 or later is required, but you have %s" % (kaitaistruct.__version__))
12
+
13
+ from polyfile.kaitai.parsers import asn1_der
14
+ class MachO(KaitaiStruct):
15
+ """
16
+ .. seealso::
17
+ Source - https://www.stonedcoder.org/~kd/lib/MachORuntime.pdf
18
+
19
+
20
+ .. seealso::
21
+ Source - https://opensource.apple.com/source/python_modules/python_modules-43/Modules/macholib-1.5.1/macholib-1.5.1.tar.gz
22
+
23
+
24
+ .. seealso::
25
+ Source - https://github.com/comex/cs/blob/07a88f9/macho_cs.py
26
+
27
+
28
+ .. seealso::
29
+ Source - https://opensource.apple.com/source/Security/Security-55471/libsecurity_codesigning/requirements.grammar.auto.html
30
+
31
+
32
+ .. seealso::
33
+ Source - https://github.com/apple/darwin-xnu/blob/xnu-2782.40.9/bsd/sys/codesign.h
34
+
35
+
36
+ .. seealso::
37
+ Source - https://opensource.apple.com/source/dyld/dyld-852/src/ImageLoaderMachO.cpp.auto.html
38
+
39
+
40
+ .. seealso::
41
+ Source - https://opensource.apple.com/source/dyld/dyld-852/src/ImageLoaderMachOCompressed.cpp.auto.html
42
+ """
43
+
44
+ class MagicType(Enum):
45
+ macho_le_x86 = 3472551422
46
+ macho_le_x64 = 3489328638
47
+ macho_be_x86 = 4277009102
48
+ macho_be_x64 = 4277009103
49
+
50
+ class CpuType(Enum):
51
+ vax = 1
52
+ romp = 2
53
+ ns32032 = 4
54
+ ns32332 = 5
55
+ i386 = 7
56
+ mips = 8
57
+ ns32532 = 9
58
+ hppa = 11
59
+ arm = 12
60
+ mc88000 = 13
61
+ sparc = 14
62
+ i860 = 15
63
+ i860_little = 16
64
+ rs6000 = 17
65
+ powerpc = 18
66
+ abi64 = 16777216
67
+ x86_64 = 16777223
68
+ arm64 = 16777228
69
+ powerpc64 = 16777234
70
+ any = 4294967295
71
+
72
+ class FileType(Enum):
73
+ object = 1
74
+ execute = 2
75
+ fvmlib = 3
76
+ core = 4
77
+ preload = 5
78
+ dylib = 6
79
+ dylinker = 7
80
+ bundle = 8
81
+ dylib_stub = 9
82
+ dsym = 10
83
+ kext_bundle = 11
84
+
85
+ class LoadCommandType(Enum):
86
+ segment = 1
87
+ symtab = 2
88
+ symseg = 3
89
+ thread = 4
90
+ unix_thread = 5
91
+ load_fvm_lib = 6
92
+ id_fvm_lib = 7
93
+ ident = 8
94
+ fvm_file = 9
95
+ prepage = 10
96
+ dysymtab = 11
97
+ load_dylib = 12
98
+ id_dylib = 13
99
+ load_dylinker = 14
100
+ id_dylinker = 15
101
+ prebound_dylib = 16
102
+ routines = 17
103
+ sub_framework = 18
104
+ sub_umbrella = 19
105
+ sub_client = 20
106
+ sub_library = 21
107
+ twolevel_hints = 22
108
+ prebind_cksum = 23
109
+ segment_64 = 25
110
+ routines_64 = 26
111
+ uuid = 27
112
+ code_signature = 29
113
+ segment_split_info = 30
114
+ lazy_load_dylib = 32
115
+ encryption_info = 33
116
+ dyld_info = 34
117
+ version_min_macosx = 36
118
+ version_min_iphoneos = 37
119
+ function_starts = 38
120
+ dyld_environment = 39
121
+ data_in_code = 41
122
+ source_version = 42
123
+ dylib_code_sign_drs = 43
124
+ encryption_info_64 = 44
125
+ linker_option = 45
126
+ linker_optimization_hint = 46
127
+ version_min_tvos = 47
128
+ version_min_watchos = 48
129
+ build_version = 50
130
+ req_dyld = 2147483648
131
+ load_weak_dylib = 2147483672
132
+ rpath = 2147483676
133
+ reexport_dylib = 2147483679
134
+ dyld_info_only = 2147483682
135
+ load_upward_dylib = 2147483683
136
+ main = 2147483688
137
+ SEQ_FIELDS = ["magic", "header", "load_commands"]
138
+ def __init__(self, _io, _parent=None, _root=None):
139
+ self._io = _io
140
+ self._parent = _parent
141
+ self._root = _root if _root else self
142
+ self._debug = collections.defaultdict(dict)
143
+
144
+ def _read(self):
145
+ self._debug['magic']['start'] = self._io.pos()
146
+ self.magic = KaitaiStream.resolve_enum(MachO.MagicType, self._io.read_u4be())
147
+ self._debug['magic']['end'] = self._io.pos()
148
+ self._debug['header']['start'] = self._io.pos()
149
+ self.header = MachO.MachHeader(self._io, self, self._root)
150
+ self.header._read()
151
+ self._debug['header']['end'] = self._io.pos()
152
+ self._debug['load_commands']['start'] = self._io.pos()
153
+ self.load_commands = [None] * (self.header.ncmds)
154
+ for i in range(self.header.ncmds):
155
+ if not 'arr' in self._debug['load_commands']:
156
+ self._debug['load_commands']['arr'] = []
157
+ self._debug['load_commands']['arr'].append({'start': self._io.pos()})
158
+ _t_load_commands = MachO.LoadCommand(self._io, self, self._root)
159
+ _t_load_commands._read()
160
+ self.load_commands[i] = _t_load_commands
161
+ self._debug['load_commands']['arr'][i]['end'] = self._io.pos()
162
+
163
+ self._debug['load_commands']['end'] = self._io.pos()
164
+
165
+ class RpathCommand(KaitaiStruct):
166
+ SEQ_FIELDS = ["path_offset", "path"]
167
+ def __init__(self, _io, _parent=None, _root=None):
168
+ self._io = _io
169
+ self._parent = _parent
170
+ self._root = _root if _root else self
171
+ self._debug = collections.defaultdict(dict)
172
+
173
+ def _read(self):
174
+ self._debug['path_offset']['start'] = self._io.pos()
175
+ self.path_offset = self._io.read_u4le()
176
+ self._debug['path_offset']['end'] = self._io.pos()
177
+ self._debug['path']['start'] = self._io.pos()
178
+ self.path = (self._io.read_bytes_term(0, False, True, True)).decode(u"utf-8")
179
+ self._debug['path']['end'] = self._io.pos()
180
+
181
+
182
+ class Uleb128(KaitaiStruct):
183
+ SEQ_FIELDS = ["b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "b10"]
184
+ def __init__(self, _io, _parent=None, _root=None):
185
+ self._io = _io
186
+ self._parent = _parent
187
+ self._root = _root if _root else self
188
+ self._debug = collections.defaultdict(dict)
189
+
190
+ def _read(self):
191
+ self._debug['b1']['start'] = self._io.pos()
192
+ self.b1 = self._io.read_u1()
193
+ self._debug['b1']['end'] = self._io.pos()
194
+ if (self.b1 & 128) != 0:
195
+ self._debug['b2']['start'] = self._io.pos()
196
+ self.b2 = self._io.read_u1()
197
+ self._debug['b2']['end'] = self._io.pos()
198
+
199
+ if (self.b2 & 128) != 0:
200
+ self._debug['b3']['start'] = self._io.pos()
201
+ self.b3 = self._io.read_u1()
202
+ self._debug['b3']['end'] = self._io.pos()
203
+
204
+ if (self.b3 & 128) != 0:
205
+ self._debug['b4']['start'] = self._io.pos()
206
+ self.b4 = self._io.read_u1()
207
+ self._debug['b4']['end'] = self._io.pos()
208
+
209
+ if (self.b4 & 128) != 0:
210
+ self._debug['b5']['start'] = self._io.pos()
211
+ self.b5 = self._io.read_u1()
212
+ self._debug['b5']['end'] = self._io.pos()
213
+
214
+ if (self.b5 & 128) != 0:
215
+ self._debug['b6']['start'] = self._io.pos()
216
+ self.b6 = self._io.read_u1()
217
+ self._debug['b6']['end'] = self._io.pos()
218
+
219
+ if (self.b6 & 128) != 0:
220
+ self._debug['b7']['start'] = self._io.pos()
221
+ self.b7 = self._io.read_u1()
222
+ self._debug['b7']['end'] = self._io.pos()
223
+
224
+ if (self.b7 & 128) != 0:
225
+ self._debug['b8']['start'] = self._io.pos()
226
+ self.b8 = self._io.read_u1()
227
+ self._debug['b8']['end'] = self._io.pos()
228
+
229
+ if (self.b8 & 128) != 0:
230
+ self._debug['b9']['start'] = self._io.pos()
231
+ self.b9 = self._io.read_u1()
232
+ self._debug['b9']['end'] = self._io.pos()
233
+
234
+ if (self.b9 & 128) != 0:
235
+ self._debug['b10']['start'] = self._io.pos()
236
+ self.b10 = self._io.read_u1()
237
+ self._debug['b10']['end'] = self._io.pos()
238
+
239
+
240
+ @property
241
+ def value(self):
242
+ if hasattr(self, '_m_value'):
243
+ return self._m_value if hasattr(self, '_m_value') else None
244
+
245
+ self._m_value = (((self.b1 % 128) << 0) + (0 if (self.b1 & 128) == 0 else (((self.b2 % 128) << 7) + (0 if (self.b2 & 128) == 0 else (((self.b3 % 128) << 14) + (0 if (self.b3 & 128) == 0 else (((self.b4 % 128) << 21) + (0 if (self.b4 & 128) == 0 else (((self.b5 % 128) << 28) + (0 if (self.b5 & 128) == 0 else (((self.b6 % 128) << 35) + (0 if (self.b6 & 128) == 0 else (((self.b7 % 128) << 42) + (0 if (self.b7 & 128) == 0 else (((self.b8 % 128) << 49) + (0 if (self.b8 & 128) == 0 else (((self.b9 % 128) << 56) + (0 if (self.b8 & 128) == 0 else ((self.b10 % 128) << 63)))))))))))))))))))
246
+ return self._m_value if hasattr(self, '_m_value') else None
247
+
248
+
249
+ class SourceVersionCommand(KaitaiStruct):
250
+ SEQ_FIELDS = ["version"]
251
+ def __init__(self, _io, _parent=None, _root=None):
252
+ self._io = _io
253
+ self._parent = _parent
254
+ self._root = _root if _root else self
255
+ self._debug = collections.defaultdict(dict)
256
+
257
+ def _read(self):
258
+ self._debug['version']['start'] = self._io.pos()
259
+ self.version = self._io.read_u8le()
260
+ self._debug['version']['end'] = self._io.pos()
261
+
262
+
263
+ class CsBlob(KaitaiStruct):
264
+
265
+ class CsMagic(Enum):
266
+ blob_wrapper = 4208855809
267
+ requirement = 4208856064
268
+ requirements = 4208856065
269
+ code_directory = 4208856066
270
+ embedded_signature = 4208856256
271
+ detached_signature = 4208856257
272
+ entitlements = 4208882033
273
+ der_entitlements = 4208882034
274
+ SEQ_FIELDS = ["magic", "length", "body"]
275
+ def __init__(self, _io, _parent=None, _root=None):
276
+ self._io = _io
277
+ self._parent = _parent
278
+ self._root = _root if _root else self
279
+ self._debug = collections.defaultdict(dict)
280
+
281
+ def _read(self):
282
+ self._debug['magic']['start'] = self._io.pos()
283
+ self.magic = KaitaiStream.resolve_enum(MachO.CsBlob.CsMagic, self._io.read_u4be())
284
+ self._debug['magic']['end'] = self._io.pos()
285
+ self._debug['length']['start'] = self._io.pos()
286
+ self.length = self._io.read_u4be()
287
+ self._debug['length']['end'] = self._io.pos()
288
+ self._debug['body']['start'] = self._io.pos()
289
+ _on = self.magic
290
+ if _on == MachO.CsBlob.CsMagic.requirement:
291
+ self._raw_body = self._io.read_bytes((self.length - 8))
292
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
293
+ self.body = MachO.CsBlob.Requirement(_io__raw_body, self, self._root)
294
+ self.body._read()
295
+ elif _on == MachO.CsBlob.CsMagic.code_directory:
296
+ self._raw_body = self._io.read_bytes((self.length - 8))
297
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
298
+ self.body = MachO.CsBlob.CodeDirectory(_io__raw_body, self, self._root)
299
+ self.body._read()
300
+ elif _on == MachO.CsBlob.CsMagic.requirements:
301
+ self._raw_body = self._io.read_bytes((self.length - 8))
302
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
303
+ self.body = MachO.CsBlob.Requirements(_io__raw_body, self, self._root)
304
+ self.body._read()
305
+ elif _on == MachO.CsBlob.CsMagic.blob_wrapper:
306
+ self._raw_body = self._io.read_bytes((self.length - 8))
307
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
308
+ self.body = MachO.CsBlob.BlobWrapper(_io__raw_body, self, self._root)
309
+ self.body._read()
310
+ elif _on == MachO.CsBlob.CsMagic.embedded_signature:
311
+ self._raw_body = self._io.read_bytes((self.length - 8))
312
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
313
+ self.body = MachO.CsBlob.SuperBlob(_io__raw_body, self, self._root)
314
+ self.body._read()
315
+ elif _on == MachO.CsBlob.CsMagic.entitlements:
316
+ self._raw_body = self._io.read_bytes((self.length - 8))
317
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
318
+ self.body = MachO.CsBlob.Entitlements(_io__raw_body, self, self._root)
319
+ self.body._read()
320
+ elif _on == MachO.CsBlob.CsMagic.detached_signature:
321
+ self._raw_body = self._io.read_bytes((self.length - 8))
322
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
323
+ self.body = MachO.CsBlob.SuperBlob(_io__raw_body, self, self._root)
324
+ self.body._read()
325
+ elif _on == MachO.CsBlob.CsMagic.der_entitlements:
326
+ self._raw_body = self._io.read_bytes((self.length - 8))
327
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
328
+ self.body = asn1_der.Asn1Der(_io__raw_body)
329
+ self.body._read()
330
+ else:
331
+ self.body = self._io.read_bytes((self.length - 8))
332
+ self._debug['body']['end'] = self._io.pos()
333
+
334
+ class CodeDirectory(KaitaiStruct):
335
+ SEQ_FIELDS = ["version", "flags", "hash_offset", "ident_offset", "n_special_slots", "n_code_slots", "code_limit", "hash_size", "hash_type", "spare1", "page_size", "spare2", "scatter_offset", "team_id_offset"]
336
+ def __init__(self, _io, _parent=None, _root=None):
337
+ self._io = _io
338
+ self._parent = _parent
339
+ self._root = _root if _root else self
340
+ self._debug = collections.defaultdict(dict)
341
+
342
+ def _read(self):
343
+ self._debug['version']['start'] = self._io.pos()
344
+ self.version = self._io.read_u4be()
345
+ self._debug['version']['end'] = self._io.pos()
346
+ self._debug['flags']['start'] = self._io.pos()
347
+ self.flags = self._io.read_u4be()
348
+ self._debug['flags']['end'] = self._io.pos()
349
+ self._debug['hash_offset']['start'] = self._io.pos()
350
+ self.hash_offset = self._io.read_u4be()
351
+ self._debug['hash_offset']['end'] = self._io.pos()
352
+ self._debug['ident_offset']['start'] = self._io.pos()
353
+ self.ident_offset = self._io.read_u4be()
354
+ self._debug['ident_offset']['end'] = self._io.pos()
355
+ self._debug['n_special_slots']['start'] = self._io.pos()
356
+ self.n_special_slots = self._io.read_u4be()
357
+ self._debug['n_special_slots']['end'] = self._io.pos()
358
+ self._debug['n_code_slots']['start'] = self._io.pos()
359
+ self.n_code_slots = self._io.read_u4be()
360
+ self._debug['n_code_slots']['end'] = self._io.pos()
361
+ self._debug['code_limit']['start'] = self._io.pos()
362
+ self.code_limit = self._io.read_u4be()
363
+ self._debug['code_limit']['end'] = self._io.pos()
364
+ self._debug['hash_size']['start'] = self._io.pos()
365
+ self.hash_size = self._io.read_u1()
366
+ self._debug['hash_size']['end'] = self._io.pos()
367
+ self._debug['hash_type']['start'] = self._io.pos()
368
+ self.hash_type = self._io.read_u1()
369
+ self._debug['hash_type']['end'] = self._io.pos()
370
+ self._debug['spare1']['start'] = self._io.pos()
371
+ self.spare1 = self._io.read_u1()
372
+ self._debug['spare1']['end'] = self._io.pos()
373
+ self._debug['page_size']['start'] = self._io.pos()
374
+ self.page_size = self._io.read_u1()
375
+ self._debug['page_size']['end'] = self._io.pos()
376
+ self._debug['spare2']['start'] = self._io.pos()
377
+ self.spare2 = self._io.read_u4be()
378
+ self._debug['spare2']['end'] = self._io.pos()
379
+ if self.version >= 131328:
380
+ self._debug['scatter_offset']['start'] = self._io.pos()
381
+ self.scatter_offset = self._io.read_u4be()
382
+ self._debug['scatter_offset']['end'] = self._io.pos()
383
+
384
+ if self.version >= 131584:
385
+ self._debug['team_id_offset']['start'] = self._io.pos()
386
+ self.team_id_offset = self._io.read_u4be()
387
+ self._debug['team_id_offset']['end'] = self._io.pos()
388
+
389
+
390
+ @property
391
+ def ident(self):
392
+ if hasattr(self, '_m_ident'):
393
+ return self._m_ident if hasattr(self, '_m_ident') else None
394
+
395
+ _pos = self._io.pos()
396
+ self._io.seek((self.ident_offset - 8))
397
+ self._debug['_m_ident']['start'] = self._io.pos()
398
+ self._m_ident = (self._io.read_bytes_term(0, False, True, True)).decode(u"utf-8")
399
+ self._debug['_m_ident']['end'] = self._io.pos()
400
+ self._io.seek(_pos)
401
+ return self._m_ident if hasattr(self, '_m_ident') else None
402
+
403
+ @property
404
+ def team_id(self):
405
+ if hasattr(self, '_m_team_id'):
406
+ return self._m_team_id if hasattr(self, '_m_team_id') else None
407
+
408
+ _pos = self._io.pos()
409
+ self._io.seek((self.team_id_offset - 8))
410
+ self._debug['_m_team_id']['start'] = self._io.pos()
411
+ self._m_team_id = (self._io.read_bytes_term(0, False, True, True)).decode(u"utf-8")
412
+ self._debug['_m_team_id']['end'] = self._io.pos()
413
+ self._io.seek(_pos)
414
+ return self._m_team_id if hasattr(self, '_m_team_id') else None
415
+
416
+ @property
417
+ def hashes(self):
418
+ if hasattr(self, '_m_hashes'):
419
+ return self._m_hashes if hasattr(self, '_m_hashes') else None
420
+
421
+ _pos = self._io.pos()
422
+ self._io.seek(((self.hash_offset - 8) - (self.hash_size * self.n_special_slots)))
423
+ self._debug['_m_hashes']['start'] = self._io.pos()
424
+ self._m_hashes = [None] * ((self.n_special_slots + self.n_code_slots))
425
+ for i in range((self.n_special_slots + self.n_code_slots)):
426
+ if not 'arr' in self._debug['_m_hashes']:
427
+ self._debug['_m_hashes']['arr'] = []
428
+ self._debug['_m_hashes']['arr'].append({'start': self._io.pos()})
429
+ self._m_hashes[i] = self._io.read_bytes(self.hash_size)
430
+ self._debug['_m_hashes']['arr'][i]['end'] = self._io.pos()
431
+
432
+ self._debug['_m_hashes']['end'] = self._io.pos()
433
+ self._io.seek(_pos)
434
+ return self._m_hashes if hasattr(self, '_m_hashes') else None
435
+
436
+
437
+ class Data(KaitaiStruct):
438
+ SEQ_FIELDS = ["length", "value", "padding"]
439
+ def __init__(self, _io, _parent=None, _root=None):
440
+ self._io = _io
441
+ self._parent = _parent
442
+ self._root = _root if _root else self
443
+ self._debug = collections.defaultdict(dict)
444
+
445
+ def _read(self):
446
+ self._debug['length']['start'] = self._io.pos()
447
+ self.length = self._io.read_u4be()
448
+ self._debug['length']['end'] = self._io.pos()
449
+ self._debug['value']['start'] = self._io.pos()
450
+ self.value = self._io.read_bytes(self.length)
451
+ self._debug['value']['end'] = self._io.pos()
452
+ self._debug['padding']['start'] = self._io.pos()
453
+ self.padding = self._io.read_bytes((-(self.length) % 4))
454
+ self._debug['padding']['end'] = self._io.pos()
455
+
456
+
457
+ class SuperBlob(KaitaiStruct):
458
+ SEQ_FIELDS = ["count", "blobs"]
459
+ def __init__(self, _io, _parent=None, _root=None):
460
+ self._io = _io
461
+ self._parent = _parent
462
+ self._root = _root if _root else self
463
+ self._debug = collections.defaultdict(dict)
464
+
465
+ def _read(self):
466
+ self._debug['count']['start'] = self._io.pos()
467
+ self.count = self._io.read_u4be()
468
+ self._debug['count']['end'] = self._io.pos()
469
+ self._debug['blobs']['start'] = self._io.pos()
470
+ self.blobs = [None] * (self.count)
471
+ for i in range(self.count):
472
+ if not 'arr' in self._debug['blobs']:
473
+ self._debug['blobs']['arr'] = []
474
+ self._debug['blobs']['arr'].append({'start': self._io.pos()})
475
+ _t_blobs = MachO.CsBlob.BlobIndex(self._io, self, self._root)
476
+ _t_blobs._read()
477
+ self.blobs[i] = _t_blobs
478
+ self._debug['blobs']['arr'][i]['end'] = self._io.pos()
479
+
480
+ self._debug['blobs']['end'] = self._io.pos()
481
+
482
+
483
+ class Expr(KaitaiStruct):
484
+
485
+ class OpEnum(Enum):
486
+ false = 0
487
+ true = 1
488
+ ident = 2
489
+ apple_anchor = 3
490
+ anchor_hash = 4
491
+ info_key_value = 5
492
+ and_op = 6
493
+ or_op = 7
494
+ cd_hash = 8
495
+ not_op = 9
496
+ info_key_field = 10
497
+ cert_field = 11
498
+ trusted_cert = 12
499
+ trusted_certs = 13
500
+ cert_generic = 14
501
+ apple_generic_anchor = 15
502
+ entitlement_field = 16
503
+
504
+ class CertSlot(Enum):
505
+ left_cert = 0
506
+ anchor_cert = 4294967295
507
+ SEQ_FIELDS = ["op", "data"]
508
+ def __init__(self, _io, _parent=None, _root=None):
509
+ self._io = _io
510
+ self._parent = _parent
511
+ self._root = _root if _root else self
512
+ self._debug = collections.defaultdict(dict)
513
+
514
+ def _read(self):
515
+ self._debug['op']['start'] = self._io.pos()
516
+ self.op = KaitaiStream.resolve_enum(MachO.CsBlob.Expr.OpEnum, self._io.read_u4be())
517
+ self._debug['op']['end'] = self._io.pos()
518
+ self._debug['data']['start'] = self._io.pos()
519
+ _on = self.op
520
+ if _on == MachO.CsBlob.Expr.OpEnum.ident:
521
+ self.data = MachO.CsBlob.Expr.IdentExpr(self._io, self, self._root)
522
+ self.data._read()
523
+ elif _on == MachO.CsBlob.Expr.OpEnum.or_op:
524
+ self.data = MachO.CsBlob.Expr.OrExpr(self._io, self, self._root)
525
+ self.data._read()
526
+ elif _on == MachO.CsBlob.Expr.OpEnum.info_key_value:
527
+ self.data = MachO.CsBlob.Data(self._io, self, self._root)
528
+ self.data._read()
529
+ elif _on == MachO.CsBlob.Expr.OpEnum.anchor_hash:
530
+ self.data = MachO.CsBlob.Expr.AnchorHashExpr(self._io, self, self._root)
531
+ self.data._read()
532
+ elif _on == MachO.CsBlob.Expr.OpEnum.info_key_field:
533
+ self.data = MachO.CsBlob.Expr.InfoKeyFieldExpr(self._io, self, self._root)
534
+ self.data._read()
535
+ elif _on == MachO.CsBlob.Expr.OpEnum.not_op:
536
+ self.data = MachO.CsBlob.Expr(self._io, self, self._root)
537
+ self.data._read()
538
+ elif _on == MachO.CsBlob.Expr.OpEnum.entitlement_field:
539
+ self.data = MachO.CsBlob.Expr.EntitlementFieldExpr(self._io, self, self._root)
540
+ self.data._read()
541
+ elif _on == MachO.CsBlob.Expr.OpEnum.trusted_cert:
542
+ self.data = MachO.CsBlob.Expr.CertSlotExpr(self._io, self, self._root)
543
+ self.data._read()
544
+ elif _on == MachO.CsBlob.Expr.OpEnum.and_op:
545
+ self.data = MachO.CsBlob.Expr.AndExpr(self._io, self, self._root)
546
+ self.data._read()
547
+ elif _on == MachO.CsBlob.Expr.OpEnum.cert_generic:
548
+ self.data = MachO.CsBlob.Expr.CertGenericExpr(self._io, self, self._root)
549
+ self.data._read()
550
+ elif _on == MachO.CsBlob.Expr.OpEnum.cert_field:
551
+ self.data = MachO.CsBlob.Expr.CertFieldExpr(self._io, self, self._root)
552
+ self.data._read()
553
+ elif _on == MachO.CsBlob.Expr.OpEnum.cd_hash:
554
+ self.data = MachO.CsBlob.Data(self._io, self, self._root)
555
+ self.data._read()
556
+ elif _on == MachO.CsBlob.Expr.OpEnum.apple_generic_anchor:
557
+ self.data = MachO.CsBlob.Expr.AppleGenericAnchorExpr(self._io, self, self._root)
558
+ self.data._read()
559
+ self._debug['data']['end'] = self._io.pos()
560
+
561
+ class InfoKeyFieldExpr(KaitaiStruct):
562
+ SEQ_FIELDS = ["data", "match"]
563
+ def __init__(self, _io, _parent=None, _root=None):
564
+ self._io = _io
565
+ self._parent = _parent
566
+ self._root = _root if _root else self
567
+ self._debug = collections.defaultdict(dict)
568
+
569
+ def _read(self):
570
+ self._debug['data']['start'] = self._io.pos()
571
+ self.data = MachO.CsBlob.Data(self._io, self, self._root)
572
+ self.data._read()
573
+ self._debug['data']['end'] = self._io.pos()
574
+ self._debug['match']['start'] = self._io.pos()
575
+ self.match = MachO.CsBlob.Match(self._io, self, self._root)
576
+ self.match._read()
577
+ self._debug['match']['end'] = self._io.pos()
578
+
579
+
580
+ class CertSlotExpr(KaitaiStruct):
581
+ SEQ_FIELDS = ["value"]
582
+ def __init__(self, _io, _parent=None, _root=None):
583
+ self._io = _io
584
+ self._parent = _parent
585
+ self._root = _root if _root else self
586
+ self._debug = collections.defaultdict(dict)
587
+
588
+ def _read(self):
589
+ self._debug['value']['start'] = self._io.pos()
590
+ self.value = KaitaiStream.resolve_enum(MachO.CsBlob.Expr.CertSlot, self._io.read_u4be())
591
+ self._debug['value']['end'] = self._io.pos()
592
+
593
+
594
+ class CertGenericExpr(KaitaiStruct):
595
+ SEQ_FIELDS = ["cert_slot", "data", "match"]
596
+ def __init__(self, _io, _parent=None, _root=None):
597
+ self._io = _io
598
+ self._parent = _parent
599
+ self._root = _root if _root else self
600
+ self._debug = collections.defaultdict(dict)
601
+
602
+ def _read(self):
603
+ self._debug['cert_slot']['start'] = self._io.pos()
604
+ self.cert_slot = KaitaiStream.resolve_enum(MachO.CsBlob.Expr.CertSlot, self._io.read_u4be())
605
+ self._debug['cert_slot']['end'] = self._io.pos()
606
+ self._debug['data']['start'] = self._io.pos()
607
+ self.data = MachO.CsBlob.Data(self._io, self, self._root)
608
+ self.data._read()
609
+ self._debug['data']['end'] = self._io.pos()
610
+ self._debug['match']['start'] = self._io.pos()
611
+ self.match = MachO.CsBlob.Match(self._io, self, self._root)
612
+ self.match._read()
613
+ self._debug['match']['end'] = self._io.pos()
614
+
615
+
616
+ class IdentExpr(KaitaiStruct):
617
+ SEQ_FIELDS = ["identifier"]
618
+ def __init__(self, _io, _parent=None, _root=None):
619
+ self._io = _io
620
+ self._parent = _parent
621
+ self._root = _root if _root else self
622
+ self._debug = collections.defaultdict(dict)
623
+
624
+ def _read(self):
625
+ self._debug['identifier']['start'] = self._io.pos()
626
+ self.identifier = MachO.CsBlob.Data(self._io, self, self._root)
627
+ self.identifier._read()
628
+ self._debug['identifier']['end'] = self._io.pos()
629
+
630
+
631
+ class CertFieldExpr(KaitaiStruct):
632
+ SEQ_FIELDS = ["cert_slot", "data", "match"]
633
+ def __init__(self, _io, _parent=None, _root=None):
634
+ self._io = _io
635
+ self._parent = _parent
636
+ self._root = _root if _root else self
637
+ self._debug = collections.defaultdict(dict)
638
+
639
+ def _read(self):
640
+ self._debug['cert_slot']['start'] = self._io.pos()
641
+ self.cert_slot = KaitaiStream.resolve_enum(MachO.CsBlob.Expr.CertSlot, self._io.read_u4be())
642
+ self._debug['cert_slot']['end'] = self._io.pos()
643
+ self._debug['data']['start'] = self._io.pos()
644
+ self.data = MachO.CsBlob.Data(self._io, self, self._root)
645
+ self.data._read()
646
+ self._debug['data']['end'] = self._io.pos()
647
+ self._debug['match']['start'] = self._io.pos()
648
+ self.match = MachO.CsBlob.Match(self._io, self, self._root)
649
+ self.match._read()
650
+ self._debug['match']['end'] = self._io.pos()
651
+
652
+
653
+ class AnchorHashExpr(KaitaiStruct):
654
+ SEQ_FIELDS = ["cert_slot", "data"]
655
+ def __init__(self, _io, _parent=None, _root=None):
656
+ self._io = _io
657
+ self._parent = _parent
658
+ self._root = _root if _root else self
659
+ self._debug = collections.defaultdict(dict)
660
+
661
+ def _read(self):
662
+ self._debug['cert_slot']['start'] = self._io.pos()
663
+ self.cert_slot = KaitaiStream.resolve_enum(MachO.CsBlob.Expr.CertSlot, self._io.read_u4be())
664
+ self._debug['cert_slot']['end'] = self._io.pos()
665
+ self._debug['data']['start'] = self._io.pos()
666
+ self.data = MachO.CsBlob.Data(self._io, self, self._root)
667
+ self.data._read()
668
+ self._debug['data']['end'] = self._io.pos()
669
+
670
+
671
+ class AppleGenericAnchorExpr(KaitaiStruct):
672
+ SEQ_FIELDS = []
673
+ def __init__(self, _io, _parent=None, _root=None):
674
+ self._io = _io
675
+ self._parent = _parent
676
+ self._root = _root if _root else self
677
+ self._debug = collections.defaultdict(dict)
678
+
679
+ def _read(self):
680
+ pass
681
+
682
+ @property
683
+ def value(self):
684
+ if hasattr(self, '_m_value'):
685
+ return self._m_value if hasattr(self, '_m_value') else None
686
+
687
+ self._m_value = u"anchor apple generic"
688
+ return self._m_value if hasattr(self, '_m_value') else None
689
+
690
+
691
+ class EntitlementFieldExpr(KaitaiStruct):
692
+ SEQ_FIELDS = ["data", "match"]
693
+ def __init__(self, _io, _parent=None, _root=None):
694
+ self._io = _io
695
+ self._parent = _parent
696
+ self._root = _root if _root else self
697
+ self._debug = collections.defaultdict(dict)
698
+
699
+ def _read(self):
700
+ self._debug['data']['start'] = self._io.pos()
701
+ self.data = MachO.CsBlob.Data(self._io, self, self._root)
702
+ self.data._read()
703
+ self._debug['data']['end'] = self._io.pos()
704
+ self._debug['match']['start'] = self._io.pos()
705
+ self.match = MachO.CsBlob.Match(self._io, self, self._root)
706
+ self.match._read()
707
+ self._debug['match']['end'] = self._io.pos()
708
+
709
+
710
+ class AndExpr(KaitaiStruct):
711
+ SEQ_FIELDS = ["left", "right"]
712
+ def __init__(self, _io, _parent=None, _root=None):
713
+ self._io = _io
714
+ self._parent = _parent
715
+ self._root = _root if _root else self
716
+ self._debug = collections.defaultdict(dict)
717
+
718
+ def _read(self):
719
+ self._debug['left']['start'] = self._io.pos()
720
+ self.left = MachO.CsBlob.Expr(self._io, self, self._root)
721
+ self.left._read()
722
+ self._debug['left']['end'] = self._io.pos()
723
+ self._debug['right']['start'] = self._io.pos()
724
+ self.right = MachO.CsBlob.Expr(self._io, self, self._root)
725
+ self.right._read()
726
+ self._debug['right']['end'] = self._io.pos()
727
+
728
+
729
+ class OrExpr(KaitaiStruct):
730
+ SEQ_FIELDS = ["left", "right"]
731
+ def __init__(self, _io, _parent=None, _root=None):
732
+ self._io = _io
733
+ self._parent = _parent
734
+ self._root = _root if _root else self
735
+ self._debug = collections.defaultdict(dict)
736
+
737
+ def _read(self):
738
+ self._debug['left']['start'] = self._io.pos()
739
+ self.left = MachO.CsBlob.Expr(self._io, self, self._root)
740
+ self.left._read()
741
+ self._debug['left']['end'] = self._io.pos()
742
+ self._debug['right']['start'] = self._io.pos()
743
+ self.right = MachO.CsBlob.Expr(self._io, self, self._root)
744
+ self.right._read()
745
+ self._debug['right']['end'] = self._io.pos()
746
+
747
+
748
+
749
+ class BlobIndex(KaitaiStruct):
750
+
751
+ class CsslotType(Enum):
752
+ code_directory = 0
753
+ info_slot = 1
754
+ requirements = 2
755
+ resource_dir = 3
756
+ application = 4
757
+ entitlements = 5
758
+ der_entitlements = 7
759
+ alternate_code_directories = 4096
760
+ signature_slot = 65536
761
+ SEQ_FIELDS = ["type", "offset"]
762
+ def __init__(self, _io, _parent=None, _root=None):
763
+ self._io = _io
764
+ self._parent = _parent
765
+ self._root = _root if _root else self
766
+ self._debug = collections.defaultdict(dict)
767
+
768
+ def _read(self):
769
+ self._debug['type']['start'] = self._io.pos()
770
+ self.type = KaitaiStream.resolve_enum(MachO.CsBlob.BlobIndex.CsslotType, self._io.read_u4be())
771
+ self._debug['type']['end'] = self._io.pos()
772
+ self._debug['offset']['start'] = self._io.pos()
773
+ self.offset = self._io.read_u4be()
774
+ self._debug['offset']['end'] = self._io.pos()
775
+
776
+ @property
777
+ def blob(self):
778
+ if hasattr(self, '_m_blob'):
779
+ return self._m_blob if hasattr(self, '_m_blob') else None
780
+
781
+ io = self._parent._io
782
+ _pos = io.pos()
783
+ io.seek((self.offset - 8))
784
+ self._debug['_m_blob']['start'] = io.pos()
785
+ self._raw__m_blob = io.read_bytes_full()
786
+ _io__raw__m_blob = KaitaiStream(BytesIO(self._raw__m_blob))
787
+ self._m_blob = MachO.CsBlob(_io__raw__m_blob, self, self._root)
788
+ self._m_blob._read()
789
+ self._debug['_m_blob']['end'] = io.pos()
790
+ io.seek(_pos)
791
+ return self._m_blob if hasattr(self, '_m_blob') else None
792
+
793
+
794
+ class Match(KaitaiStruct):
795
+
796
+ class Op(Enum):
797
+ exists = 0
798
+ equal = 1
799
+ contains = 2
800
+ begins_with = 3
801
+ ends_with = 4
802
+ less_than = 5
803
+ greater_than = 6
804
+ less_equal = 7
805
+ greater_equal = 8
806
+ SEQ_FIELDS = ["match_op", "data"]
807
+ def __init__(self, _io, _parent=None, _root=None):
808
+ self._io = _io
809
+ self._parent = _parent
810
+ self._root = _root if _root else self
811
+ self._debug = collections.defaultdict(dict)
812
+
813
+ def _read(self):
814
+ self._debug['match_op']['start'] = self._io.pos()
815
+ self.match_op = KaitaiStream.resolve_enum(MachO.CsBlob.Match.Op, self._io.read_u4be())
816
+ self._debug['match_op']['end'] = self._io.pos()
817
+ if self.match_op != MachO.CsBlob.Match.Op.exists:
818
+ self._debug['data']['start'] = self._io.pos()
819
+ self.data = MachO.CsBlob.Data(self._io, self, self._root)
820
+ self.data._read()
821
+ self._debug['data']['end'] = self._io.pos()
822
+
823
+
824
+
825
+ class Requirement(KaitaiStruct):
826
+ SEQ_FIELDS = ["kind", "expr"]
827
+ def __init__(self, _io, _parent=None, _root=None):
828
+ self._io = _io
829
+ self._parent = _parent
830
+ self._root = _root if _root else self
831
+ self._debug = collections.defaultdict(dict)
832
+
833
+ def _read(self):
834
+ self._debug['kind']['start'] = self._io.pos()
835
+ self.kind = self._io.read_u4be()
836
+ self._debug['kind']['end'] = self._io.pos()
837
+ self._debug['expr']['start'] = self._io.pos()
838
+ self.expr = MachO.CsBlob.Expr(self._io, self, self._root)
839
+ self.expr._read()
840
+ self._debug['expr']['end'] = self._io.pos()
841
+
842
+
843
+ class Requirements(KaitaiStruct):
844
+ SEQ_FIELDS = ["count", "items"]
845
+ def __init__(self, _io, _parent=None, _root=None):
846
+ self._io = _io
847
+ self._parent = _parent
848
+ self._root = _root if _root else self
849
+ self._debug = collections.defaultdict(dict)
850
+
851
+ def _read(self):
852
+ self._debug['count']['start'] = self._io.pos()
853
+ self.count = self._io.read_u4be()
854
+ self._debug['count']['end'] = self._io.pos()
855
+ self._debug['items']['start'] = self._io.pos()
856
+ self.items = [None] * (self.count)
857
+ for i in range(self.count):
858
+ if not 'arr' in self._debug['items']:
859
+ self._debug['items']['arr'] = []
860
+ self._debug['items']['arr'].append({'start': self._io.pos()})
861
+ _t_items = MachO.CsBlob.RequirementsBlobIndex(self._io, self, self._root)
862
+ _t_items._read()
863
+ self.items[i] = _t_items
864
+ self._debug['items']['arr'][i]['end'] = self._io.pos()
865
+
866
+ self._debug['items']['end'] = self._io.pos()
867
+
868
+
869
+ class BlobWrapper(KaitaiStruct):
870
+ SEQ_FIELDS = ["data"]
871
+ def __init__(self, _io, _parent=None, _root=None):
872
+ self._io = _io
873
+ self._parent = _parent
874
+ self._root = _root if _root else self
875
+ self._debug = collections.defaultdict(dict)
876
+
877
+ def _read(self):
878
+ self._debug['data']['start'] = self._io.pos()
879
+ self.data = self._io.read_bytes_full()
880
+ self._debug['data']['end'] = self._io.pos()
881
+
882
+
883
+ class Entitlements(KaitaiStruct):
884
+ SEQ_FIELDS = ["data"]
885
+ def __init__(self, _io, _parent=None, _root=None):
886
+ self._io = _io
887
+ self._parent = _parent
888
+ self._root = _root if _root else self
889
+ self._debug = collections.defaultdict(dict)
890
+
891
+ def _read(self):
892
+ self._debug['data']['start'] = self._io.pos()
893
+ self.data = self._io.read_bytes_full()
894
+ self._debug['data']['end'] = self._io.pos()
895
+
896
+
897
+ class RequirementsBlobIndex(KaitaiStruct):
898
+
899
+ class RequirementType(Enum):
900
+ host = 1
901
+ guest = 2
902
+ designated = 3
903
+ library = 4
904
+ SEQ_FIELDS = ["type", "offset"]
905
+ def __init__(self, _io, _parent=None, _root=None):
906
+ self._io = _io
907
+ self._parent = _parent
908
+ self._root = _root if _root else self
909
+ self._debug = collections.defaultdict(dict)
910
+
911
+ def _read(self):
912
+ self._debug['type']['start'] = self._io.pos()
913
+ self.type = KaitaiStream.resolve_enum(MachO.CsBlob.RequirementsBlobIndex.RequirementType, self._io.read_u4be())
914
+ self._debug['type']['end'] = self._io.pos()
915
+ self._debug['offset']['start'] = self._io.pos()
916
+ self.offset = self._io.read_u4be()
917
+ self._debug['offset']['end'] = self._io.pos()
918
+
919
+ @property
920
+ def value(self):
921
+ if hasattr(self, '_m_value'):
922
+ return self._m_value if hasattr(self, '_m_value') else None
923
+
924
+ _pos = self._io.pos()
925
+ self._io.seek((self.offset - 8))
926
+ self._debug['_m_value']['start'] = self._io.pos()
927
+ self._m_value = MachO.CsBlob(self._io, self, self._root)
928
+ self._m_value._read()
929
+ self._debug['_m_value']['end'] = self._io.pos()
930
+ self._io.seek(_pos)
931
+ return self._m_value if hasattr(self, '_m_value') else None
932
+
933
+
934
+
935
+ class BuildVersionCommand(KaitaiStruct):
936
+ SEQ_FIELDS = ["platform", "minos", "sdk", "ntools", "tools"]
937
+ def __init__(self, _io, _parent=None, _root=None):
938
+ self._io = _io
939
+ self._parent = _parent
940
+ self._root = _root if _root else self
941
+ self._debug = collections.defaultdict(dict)
942
+
943
+ def _read(self):
944
+ self._debug['platform']['start'] = self._io.pos()
945
+ self.platform = self._io.read_u4le()
946
+ self._debug['platform']['end'] = self._io.pos()
947
+ self._debug['minos']['start'] = self._io.pos()
948
+ self.minos = self._io.read_u4le()
949
+ self._debug['minos']['end'] = self._io.pos()
950
+ self._debug['sdk']['start'] = self._io.pos()
951
+ self.sdk = self._io.read_u4le()
952
+ self._debug['sdk']['end'] = self._io.pos()
953
+ self._debug['ntools']['start'] = self._io.pos()
954
+ self.ntools = self._io.read_u4le()
955
+ self._debug['ntools']['end'] = self._io.pos()
956
+ self._debug['tools']['start'] = self._io.pos()
957
+ self.tools = [None] * (self.ntools)
958
+ for i in range(self.ntools):
959
+ if not 'arr' in self._debug['tools']:
960
+ self._debug['tools']['arr'] = []
961
+ self._debug['tools']['arr'].append({'start': self._io.pos()})
962
+ _t_tools = MachO.BuildVersionCommand.BuildToolVersion(self._io, self, self._root)
963
+ _t_tools._read()
964
+ self.tools[i] = _t_tools
965
+ self._debug['tools']['arr'][i]['end'] = self._io.pos()
966
+
967
+ self._debug['tools']['end'] = self._io.pos()
968
+
969
+ class BuildToolVersion(KaitaiStruct):
970
+ SEQ_FIELDS = ["tool", "version"]
971
+ def __init__(self, _io, _parent=None, _root=None):
972
+ self._io = _io
973
+ self._parent = _parent
974
+ self._root = _root if _root else self
975
+ self._debug = collections.defaultdict(dict)
976
+
977
+ def _read(self):
978
+ self._debug['tool']['start'] = self._io.pos()
979
+ self.tool = self._io.read_u4le()
980
+ self._debug['tool']['end'] = self._io.pos()
981
+ self._debug['version']['start'] = self._io.pos()
982
+ self.version = self._io.read_u4le()
983
+ self._debug['version']['end'] = self._io.pos()
984
+
985
+
986
+
987
+ class RoutinesCommand(KaitaiStruct):
988
+ SEQ_FIELDS = ["init_address", "init_module", "reserved"]
989
+ def __init__(self, _io, _parent=None, _root=None):
990
+ self._io = _io
991
+ self._parent = _parent
992
+ self._root = _root if _root else self
993
+ self._debug = collections.defaultdict(dict)
994
+
995
+ def _read(self):
996
+ self._debug['init_address']['start'] = self._io.pos()
997
+ self.init_address = self._io.read_u4le()
998
+ self._debug['init_address']['end'] = self._io.pos()
999
+ self._debug['init_module']['start'] = self._io.pos()
1000
+ self.init_module = self._io.read_u4le()
1001
+ self._debug['init_module']['end'] = self._io.pos()
1002
+ self._debug['reserved']['start'] = self._io.pos()
1003
+ self.reserved = self._io.read_bytes(24)
1004
+ self._debug['reserved']['end'] = self._io.pos()
1005
+
1006
+
1007
+ class MachoFlags(KaitaiStruct):
1008
+ SEQ_FIELDS = []
1009
+ def __init__(self, value, _io, _parent=None, _root=None):
1010
+ self._io = _io
1011
+ self._parent = _parent
1012
+ self._root = _root if _root else self
1013
+ self.value = value
1014
+ self._debug = collections.defaultdict(dict)
1015
+
1016
+ def _read(self):
1017
+ pass
1018
+
1019
+ @property
1020
+ def subsections_via_symbols(self):
1021
+ """safe to divide up the sections into sub-sections via symbols for dead code stripping."""
1022
+ if hasattr(self, '_m_subsections_via_symbols'):
1023
+ return self._m_subsections_via_symbols if hasattr(self, '_m_subsections_via_symbols') else None
1024
+
1025
+ self._m_subsections_via_symbols = (self.value & 8192) != 0
1026
+ return self._m_subsections_via_symbols if hasattr(self, '_m_subsections_via_symbols') else None
1027
+
1028
+ @property
1029
+ def dead_strippable_dylib(self):
1030
+ if hasattr(self, '_m_dead_strippable_dylib'):
1031
+ return self._m_dead_strippable_dylib if hasattr(self, '_m_dead_strippable_dylib') else None
1032
+
1033
+ self._m_dead_strippable_dylib = (self.value & 4194304) != 0
1034
+ return self._m_dead_strippable_dylib if hasattr(self, '_m_dead_strippable_dylib') else None
1035
+
1036
+ @property
1037
+ def weak_defines(self):
1038
+ """the final linked image contains external weak symbols."""
1039
+ if hasattr(self, '_m_weak_defines'):
1040
+ return self._m_weak_defines if hasattr(self, '_m_weak_defines') else None
1041
+
1042
+ self._m_weak_defines = (self.value & 32768) != 0
1043
+ return self._m_weak_defines if hasattr(self, '_m_weak_defines') else None
1044
+
1045
+ @property
1046
+ def prebound(self):
1047
+ """the file has its dynamic undefined references prebound."""
1048
+ if hasattr(self, '_m_prebound'):
1049
+ return self._m_prebound if hasattr(self, '_m_prebound') else None
1050
+
1051
+ self._m_prebound = (self.value & 16) != 0
1052
+ return self._m_prebound if hasattr(self, '_m_prebound') else None
1053
+
1054
+ @property
1055
+ def all_mods_bound(self):
1056
+ """indicates that this binary binds to all two-level namespace modules of its dependent libraries. only used when MH_PREBINDABLE and MH_TWOLEVEL are both set."""
1057
+ if hasattr(self, '_m_all_mods_bound'):
1058
+ return self._m_all_mods_bound if hasattr(self, '_m_all_mods_bound') else None
1059
+
1060
+ self._m_all_mods_bound = (self.value & 4096) != 0
1061
+ return self._m_all_mods_bound if hasattr(self, '_m_all_mods_bound') else None
1062
+
1063
+ @property
1064
+ def has_tlv_descriptors(self):
1065
+ if hasattr(self, '_m_has_tlv_descriptors'):
1066
+ return self._m_has_tlv_descriptors if hasattr(self, '_m_has_tlv_descriptors') else None
1067
+
1068
+ self._m_has_tlv_descriptors = (self.value & 8388608) != 0
1069
+ return self._m_has_tlv_descriptors if hasattr(self, '_m_has_tlv_descriptors') else None
1070
+
1071
+ @property
1072
+ def force_flat(self):
1073
+ """the executable is forcing all images to use flat name space bindings."""
1074
+ if hasattr(self, '_m_force_flat'):
1075
+ return self._m_force_flat if hasattr(self, '_m_force_flat') else None
1076
+
1077
+ self._m_force_flat = (self.value & 256) != 0
1078
+ return self._m_force_flat if hasattr(self, '_m_force_flat') else None
1079
+
1080
+ @property
1081
+ def root_safe(self):
1082
+ """When this bit is set, the binary declares it is safe for use in processes with uid zero."""
1083
+ if hasattr(self, '_m_root_safe'):
1084
+ return self._m_root_safe if hasattr(self, '_m_root_safe') else None
1085
+
1086
+ self._m_root_safe = (self.value & 262144) != 0
1087
+ return self._m_root_safe if hasattr(self, '_m_root_safe') else None
1088
+
1089
+ @property
1090
+ def no_undefs(self):
1091
+ """the object file has no undefined references."""
1092
+ if hasattr(self, '_m_no_undefs'):
1093
+ return self._m_no_undefs if hasattr(self, '_m_no_undefs') else None
1094
+
1095
+ self._m_no_undefs = (self.value & 1) != 0
1096
+ return self._m_no_undefs if hasattr(self, '_m_no_undefs') else None
1097
+
1098
+ @property
1099
+ def setuid_safe(self):
1100
+ """When this bit is set, the binary declares it is safe for use in processes when issetugid() is true."""
1101
+ if hasattr(self, '_m_setuid_safe'):
1102
+ return self._m_setuid_safe if hasattr(self, '_m_setuid_safe') else None
1103
+
1104
+ self._m_setuid_safe = (self.value & 524288) != 0
1105
+ return self._m_setuid_safe if hasattr(self, '_m_setuid_safe') else None
1106
+
1107
+ @property
1108
+ def no_heap_execution(self):
1109
+ if hasattr(self, '_m_no_heap_execution'):
1110
+ return self._m_no_heap_execution if hasattr(self, '_m_no_heap_execution') else None
1111
+
1112
+ self._m_no_heap_execution = (self.value & 16777216) != 0
1113
+ return self._m_no_heap_execution if hasattr(self, '_m_no_heap_execution') else None
1114
+
1115
+ @property
1116
+ def no_reexported_dylibs(self):
1117
+ """When this bit is set on a dylib, the static linker does not need to examine dependent dylibs to see if any are re-exported."""
1118
+ if hasattr(self, '_m_no_reexported_dylibs'):
1119
+ return self._m_no_reexported_dylibs if hasattr(self, '_m_no_reexported_dylibs') else None
1120
+
1121
+ self._m_no_reexported_dylibs = (self.value & 1048576) != 0
1122
+ return self._m_no_reexported_dylibs if hasattr(self, '_m_no_reexported_dylibs') else None
1123
+
1124
+ @property
1125
+ def no_multi_defs(self):
1126
+ """this umbrella guarantees no multiple defintions of symbols in its sub-images so the two-level namespace hints can always be used."""
1127
+ if hasattr(self, '_m_no_multi_defs'):
1128
+ return self._m_no_multi_defs if hasattr(self, '_m_no_multi_defs') else None
1129
+
1130
+ self._m_no_multi_defs = (self.value & 512) != 0
1131
+ return self._m_no_multi_defs if hasattr(self, '_m_no_multi_defs') else None
1132
+
1133
+ @property
1134
+ def app_extension_safe(self):
1135
+ if hasattr(self, '_m_app_extension_safe'):
1136
+ return self._m_app_extension_safe if hasattr(self, '_m_app_extension_safe') else None
1137
+
1138
+ self._m_app_extension_safe = (self.value & 33554432) != 0
1139
+ return self._m_app_extension_safe if hasattr(self, '_m_app_extension_safe') else None
1140
+
1141
+ @property
1142
+ def prebindable(self):
1143
+ """the binary is not prebound but can have its prebinding redone. only used when MH_PREBOUND is not set."""
1144
+ if hasattr(self, '_m_prebindable'):
1145
+ return self._m_prebindable if hasattr(self, '_m_prebindable') else None
1146
+
1147
+ self._m_prebindable = (self.value & 2048) != 0
1148
+ return self._m_prebindable if hasattr(self, '_m_prebindable') else None
1149
+
1150
+ @property
1151
+ def incr_link(self):
1152
+ """the object file is the output of an incremental link against a base file and can't be link edited again."""
1153
+ if hasattr(self, '_m_incr_link'):
1154
+ return self._m_incr_link if hasattr(self, '_m_incr_link') else None
1155
+
1156
+ self._m_incr_link = (self.value & 2) != 0
1157
+ return self._m_incr_link if hasattr(self, '_m_incr_link') else None
1158
+
1159
+ @property
1160
+ def bind_at_load(self):
1161
+ """the object file's undefined references are bound by the dynamic linker when loaded."""
1162
+ if hasattr(self, '_m_bind_at_load'):
1163
+ return self._m_bind_at_load if hasattr(self, '_m_bind_at_load') else None
1164
+
1165
+ self._m_bind_at_load = (self.value & 8) != 0
1166
+ return self._m_bind_at_load if hasattr(self, '_m_bind_at_load') else None
1167
+
1168
+ @property
1169
+ def canonical(self):
1170
+ """the binary has been canonicalized via the unprebind operation."""
1171
+ if hasattr(self, '_m_canonical'):
1172
+ return self._m_canonical if hasattr(self, '_m_canonical') else None
1173
+
1174
+ self._m_canonical = (self.value & 16384) != 0
1175
+ return self._m_canonical if hasattr(self, '_m_canonical') else None
1176
+
1177
+ @property
1178
+ def two_level(self):
1179
+ """the image is using two-level name space bindings."""
1180
+ if hasattr(self, '_m_two_level'):
1181
+ return self._m_two_level if hasattr(self, '_m_two_level') else None
1182
+
1183
+ self._m_two_level = (self.value & 128) != 0
1184
+ return self._m_two_level if hasattr(self, '_m_two_level') else None
1185
+
1186
+ @property
1187
+ def split_segs(self):
1188
+ """the file has its read-only and read-write segments split."""
1189
+ if hasattr(self, '_m_split_segs'):
1190
+ return self._m_split_segs if hasattr(self, '_m_split_segs') else None
1191
+
1192
+ self._m_split_segs = (self.value & 32) != 0
1193
+ return self._m_split_segs if hasattr(self, '_m_split_segs') else None
1194
+
1195
+ @property
1196
+ def lazy_init(self):
1197
+ """the shared library init routine is to be run lazily via catching memory faults to its writeable segments (obsolete)."""
1198
+ if hasattr(self, '_m_lazy_init'):
1199
+ return self._m_lazy_init if hasattr(self, '_m_lazy_init') else None
1200
+
1201
+ self._m_lazy_init = (self.value & 64) != 0
1202
+ return self._m_lazy_init if hasattr(self, '_m_lazy_init') else None
1203
+
1204
+ @property
1205
+ def allow_stack_execution(self):
1206
+ """When this bit is set, all stacks in the task will be given stack execution privilege. Only used in MH_EXECUTE filetypes."""
1207
+ if hasattr(self, '_m_allow_stack_execution'):
1208
+ return self._m_allow_stack_execution if hasattr(self, '_m_allow_stack_execution') else None
1209
+
1210
+ self._m_allow_stack_execution = (self.value & 131072) != 0
1211
+ return self._m_allow_stack_execution if hasattr(self, '_m_allow_stack_execution') else None
1212
+
1213
+ @property
1214
+ def binds_to_weak(self):
1215
+ """the final linked image uses weak symbols."""
1216
+ if hasattr(self, '_m_binds_to_weak'):
1217
+ return self._m_binds_to_weak if hasattr(self, '_m_binds_to_weak') else None
1218
+
1219
+ self._m_binds_to_weak = (self.value & 65536) != 0
1220
+ return self._m_binds_to_weak if hasattr(self, '_m_binds_to_weak') else None
1221
+
1222
+ @property
1223
+ def no_fix_prebinding(self):
1224
+ """do not have dyld notify the prebinding agent about this executable."""
1225
+ if hasattr(self, '_m_no_fix_prebinding'):
1226
+ return self._m_no_fix_prebinding if hasattr(self, '_m_no_fix_prebinding') else None
1227
+
1228
+ self._m_no_fix_prebinding = (self.value & 1024) != 0
1229
+ return self._m_no_fix_prebinding if hasattr(self, '_m_no_fix_prebinding') else None
1230
+
1231
+ @property
1232
+ def dyld_link(self):
1233
+ """the object file is input for the dynamic linker and can't be staticly link edited again."""
1234
+ if hasattr(self, '_m_dyld_link'):
1235
+ return self._m_dyld_link if hasattr(self, '_m_dyld_link') else None
1236
+
1237
+ self._m_dyld_link = (self.value & 4) != 0
1238
+ return self._m_dyld_link if hasattr(self, '_m_dyld_link') else None
1239
+
1240
+ @property
1241
+ def pie(self):
1242
+ """When this bit is set, the OS will load the main executable at a random address. Only used in MH_EXECUTE filetypes."""
1243
+ if hasattr(self, '_m_pie'):
1244
+ return self._m_pie if hasattr(self, '_m_pie') else None
1245
+
1246
+ self._m_pie = (self.value & 2097152) != 0
1247
+ return self._m_pie if hasattr(self, '_m_pie') else None
1248
+
1249
+
1250
+ class RoutinesCommand64(KaitaiStruct):
1251
+ SEQ_FIELDS = ["init_address", "init_module", "reserved"]
1252
+ def __init__(self, _io, _parent=None, _root=None):
1253
+ self._io = _io
1254
+ self._parent = _parent
1255
+ self._root = _root if _root else self
1256
+ self._debug = collections.defaultdict(dict)
1257
+
1258
+ def _read(self):
1259
+ self._debug['init_address']['start'] = self._io.pos()
1260
+ self.init_address = self._io.read_u8le()
1261
+ self._debug['init_address']['end'] = self._io.pos()
1262
+ self._debug['init_module']['start'] = self._io.pos()
1263
+ self.init_module = self._io.read_u8le()
1264
+ self._debug['init_module']['end'] = self._io.pos()
1265
+ self._debug['reserved']['start'] = self._io.pos()
1266
+ self.reserved = self._io.read_bytes(48)
1267
+ self._debug['reserved']['end'] = self._io.pos()
1268
+
1269
+
1270
+ class LinkerOptionCommand(KaitaiStruct):
1271
+ SEQ_FIELDS = ["num_strings", "strings"]
1272
+ def __init__(self, _io, _parent=None, _root=None):
1273
+ self._io = _io
1274
+ self._parent = _parent
1275
+ self._root = _root if _root else self
1276
+ self._debug = collections.defaultdict(dict)
1277
+
1278
+ def _read(self):
1279
+ self._debug['num_strings']['start'] = self._io.pos()
1280
+ self.num_strings = self._io.read_u4le()
1281
+ self._debug['num_strings']['end'] = self._io.pos()
1282
+ self._debug['strings']['start'] = self._io.pos()
1283
+ self.strings = [None] * (self.num_strings)
1284
+ for i in range(self.num_strings):
1285
+ if not 'arr' in self._debug['strings']:
1286
+ self._debug['strings']['arr'] = []
1287
+ self._debug['strings']['arr'].append({'start': self._io.pos()})
1288
+ self.strings[i] = (self._io.read_bytes_term(0, False, True, True)).decode(u"utf-8")
1289
+ self._debug['strings']['arr'][i]['end'] = self._io.pos()
1290
+
1291
+ self._debug['strings']['end'] = self._io.pos()
1292
+
1293
+
1294
+ class SegmentCommand64(KaitaiStruct):
1295
+ SEQ_FIELDS = ["segname", "vmaddr", "vmsize", "fileoff", "filesize", "maxprot", "initprot", "nsects", "flags", "sections"]
1296
+ def __init__(self, _io, _parent=None, _root=None):
1297
+ self._io = _io
1298
+ self._parent = _parent
1299
+ self._root = _root if _root else self
1300
+ self._debug = collections.defaultdict(dict)
1301
+
1302
+ def _read(self):
1303
+ self._debug['segname']['start'] = self._io.pos()
1304
+ self.segname = (KaitaiStream.bytes_strip_right(self._io.read_bytes(16), 0)).decode(u"ascii")
1305
+ self._debug['segname']['end'] = self._io.pos()
1306
+ self._debug['vmaddr']['start'] = self._io.pos()
1307
+ self.vmaddr = self._io.read_u8le()
1308
+ self._debug['vmaddr']['end'] = self._io.pos()
1309
+ self._debug['vmsize']['start'] = self._io.pos()
1310
+ self.vmsize = self._io.read_u8le()
1311
+ self._debug['vmsize']['end'] = self._io.pos()
1312
+ self._debug['fileoff']['start'] = self._io.pos()
1313
+ self.fileoff = self._io.read_u8le()
1314
+ self._debug['fileoff']['end'] = self._io.pos()
1315
+ self._debug['filesize']['start'] = self._io.pos()
1316
+ self.filesize = self._io.read_u8le()
1317
+ self._debug['filesize']['end'] = self._io.pos()
1318
+ self._debug['maxprot']['start'] = self._io.pos()
1319
+ self.maxprot = MachO.VmProt(self._io, self, self._root)
1320
+ self.maxprot._read()
1321
+ self._debug['maxprot']['end'] = self._io.pos()
1322
+ self._debug['initprot']['start'] = self._io.pos()
1323
+ self.initprot = MachO.VmProt(self._io, self, self._root)
1324
+ self.initprot._read()
1325
+ self._debug['initprot']['end'] = self._io.pos()
1326
+ self._debug['nsects']['start'] = self._io.pos()
1327
+ self.nsects = self._io.read_u4le()
1328
+ self._debug['nsects']['end'] = self._io.pos()
1329
+ self._debug['flags']['start'] = self._io.pos()
1330
+ self.flags = self._io.read_u4le()
1331
+ self._debug['flags']['end'] = self._io.pos()
1332
+ self._debug['sections']['start'] = self._io.pos()
1333
+ self.sections = [None] * (self.nsects)
1334
+ for i in range(self.nsects):
1335
+ if not 'arr' in self._debug['sections']:
1336
+ self._debug['sections']['arr'] = []
1337
+ self._debug['sections']['arr'].append({'start': self._io.pos()})
1338
+ _t_sections = MachO.SegmentCommand64.Section64(self._io, self, self._root)
1339
+ _t_sections._read()
1340
+ self.sections[i] = _t_sections
1341
+ self._debug['sections']['arr'][i]['end'] = self._io.pos()
1342
+
1343
+ self._debug['sections']['end'] = self._io.pos()
1344
+
1345
+ class Section64(KaitaiStruct):
1346
+ SEQ_FIELDS = ["sect_name", "seg_name", "addr", "size", "offset", "align", "reloff", "nreloc", "flags", "reserved1", "reserved2", "reserved3"]
1347
+ def __init__(self, _io, _parent=None, _root=None):
1348
+ self._io = _io
1349
+ self._parent = _parent
1350
+ self._root = _root if _root else self
1351
+ self._debug = collections.defaultdict(dict)
1352
+
1353
+ def _read(self):
1354
+ self._debug['sect_name']['start'] = self._io.pos()
1355
+ self.sect_name = (KaitaiStream.bytes_strip_right(self._io.read_bytes(16), 0)).decode(u"ascii")
1356
+ self._debug['sect_name']['end'] = self._io.pos()
1357
+ self._debug['seg_name']['start'] = self._io.pos()
1358
+ self.seg_name = (KaitaiStream.bytes_strip_right(self._io.read_bytes(16), 0)).decode(u"ascii")
1359
+ self._debug['seg_name']['end'] = self._io.pos()
1360
+ self._debug['addr']['start'] = self._io.pos()
1361
+ self.addr = self._io.read_u8le()
1362
+ self._debug['addr']['end'] = self._io.pos()
1363
+ self._debug['size']['start'] = self._io.pos()
1364
+ self.size = self._io.read_u8le()
1365
+ self._debug['size']['end'] = self._io.pos()
1366
+ self._debug['offset']['start'] = self._io.pos()
1367
+ self.offset = self._io.read_u4le()
1368
+ self._debug['offset']['end'] = self._io.pos()
1369
+ self._debug['align']['start'] = self._io.pos()
1370
+ self.align = self._io.read_u4le()
1371
+ self._debug['align']['end'] = self._io.pos()
1372
+ self._debug['reloff']['start'] = self._io.pos()
1373
+ self.reloff = self._io.read_u4le()
1374
+ self._debug['reloff']['end'] = self._io.pos()
1375
+ self._debug['nreloc']['start'] = self._io.pos()
1376
+ self.nreloc = self._io.read_u4le()
1377
+ self._debug['nreloc']['end'] = self._io.pos()
1378
+ self._debug['flags']['start'] = self._io.pos()
1379
+ self.flags = self._io.read_u4le()
1380
+ self._debug['flags']['end'] = self._io.pos()
1381
+ self._debug['reserved1']['start'] = self._io.pos()
1382
+ self.reserved1 = self._io.read_u4le()
1383
+ self._debug['reserved1']['end'] = self._io.pos()
1384
+ self._debug['reserved2']['start'] = self._io.pos()
1385
+ self.reserved2 = self._io.read_u4le()
1386
+ self._debug['reserved2']['end'] = self._io.pos()
1387
+ self._debug['reserved3']['start'] = self._io.pos()
1388
+ self.reserved3 = self._io.read_u4le()
1389
+ self._debug['reserved3']['end'] = self._io.pos()
1390
+
1391
+ class CfStringList(KaitaiStruct):
1392
+ SEQ_FIELDS = ["items"]
1393
+ def __init__(self, _io, _parent=None, _root=None):
1394
+ self._io = _io
1395
+ self._parent = _parent
1396
+ self._root = _root if _root else self
1397
+ self._debug = collections.defaultdict(dict)
1398
+
1399
+ def _read(self):
1400
+ self._debug['items']['start'] = self._io.pos()
1401
+ self.items = []
1402
+ i = 0
1403
+ while not self._io.is_eof():
1404
+ if not 'arr' in self._debug['items']:
1405
+ self._debug['items']['arr'] = []
1406
+ self._debug['items']['arr'].append({'start': self._io.pos()})
1407
+ _t_items = MachO.SegmentCommand64.Section64.CfString(self._io, self, self._root)
1408
+ _t_items._read()
1409
+ self.items.append(_t_items)
1410
+ self._debug['items']['arr'][len(self.items) - 1]['end'] = self._io.pos()
1411
+ i += 1
1412
+
1413
+ self._debug['items']['end'] = self._io.pos()
1414
+
1415
+
1416
+ class CfString(KaitaiStruct):
1417
+ SEQ_FIELDS = ["isa", "info", "data", "length"]
1418
+ def __init__(self, _io, _parent=None, _root=None):
1419
+ self._io = _io
1420
+ self._parent = _parent
1421
+ self._root = _root if _root else self
1422
+ self._debug = collections.defaultdict(dict)
1423
+
1424
+ def _read(self):
1425
+ self._debug['isa']['start'] = self._io.pos()
1426
+ self.isa = self._io.read_u8le()
1427
+ self._debug['isa']['end'] = self._io.pos()
1428
+ self._debug['info']['start'] = self._io.pos()
1429
+ self.info = self._io.read_u8le()
1430
+ self._debug['info']['end'] = self._io.pos()
1431
+ self._debug['data']['start'] = self._io.pos()
1432
+ self.data = self._io.read_u8le()
1433
+ self._debug['data']['end'] = self._io.pos()
1434
+ self._debug['length']['start'] = self._io.pos()
1435
+ self.length = self._io.read_u8le()
1436
+ self._debug['length']['end'] = self._io.pos()
1437
+
1438
+
1439
+ class EhFrameItem(KaitaiStruct):
1440
+ SEQ_FIELDS = ["length", "length64", "id", "body"]
1441
+ def __init__(self, _io, _parent=None, _root=None):
1442
+ self._io = _io
1443
+ self._parent = _parent
1444
+ self._root = _root if _root else self
1445
+ self._debug = collections.defaultdict(dict)
1446
+
1447
+ def _read(self):
1448
+ self._debug['length']['start'] = self._io.pos()
1449
+ self.length = self._io.read_u4le()
1450
+ self._debug['length']['end'] = self._io.pos()
1451
+ if self.length == 4294967295:
1452
+ self._debug['length64']['start'] = self._io.pos()
1453
+ self.length64 = self._io.read_u8le()
1454
+ self._debug['length64']['end'] = self._io.pos()
1455
+
1456
+ self._debug['id']['start'] = self._io.pos()
1457
+ self.id = self._io.read_u4le()
1458
+ self._debug['id']['end'] = self._io.pos()
1459
+ if self.length > 0:
1460
+ self._debug['body']['start'] = self._io.pos()
1461
+ _on = self.id
1462
+ if _on == 0:
1463
+ self._raw_body = self._io.read_bytes((self.length - 4))
1464
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
1465
+ self.body = MachO.SegmentCommand64.Section64.EhFrameItem.Cie(_io__raw_body, self, self._root)
1466
+ self.body._read()
1467
+ else:
1468
+ self.body = self._io.read_bytes((self.length - 4))
1469
+ self._debug['body']['end'] = self._io.pos()
1470
+
1471
+
1472
+ class CharChain(KaitaiStruct):
1473
+ SEQ_FIELDS = ["chr", "next"]
1474
+ def __init__(self, _io, _parent=None, _root=None):
1475
+ self._io = _io
1476
+ self._parent = _parent
1477
+ self._root = _root if _root else self
1478
+ self._debug = collections.defaultdict(dict)
1479
+
1480
+ def _read(self):
1481
+ self._debug['chr']['start'] = self._io.pos()
1482
+ self.chr = self._io.read_u1()
1483
+ self._debug['chr']['end'] = self._io.pos()
1484
+ if self.chr != 0:
1485
+ self._debug['next']['start'] = self._io.pos()
1486
+ self.next = MachO.SegmentCommand64.Section64.EhFrameItem.CharChain(self._io, self, self._root)
1487
+ self.next._read()
1488
+ self._debug['next']['end'] = self._io.pos()
1489
+
1490
+
1491
+
1492
+ class Cie(KaitaiStruct):
1493
+ SEQ_FIELDS = ["version", "aug_str", "code_alignment_factor", "data_alignment_factor", "return_address_register", "augmentation"]
1494
+ def __init__(self, _io, _parent=None, _root=None):
1495
+ self._io = _io
1496
+ self._parent = _parent
1497
+ self._root = _root if _root else self
1498
+ self._debug = collections.defaultdict(dict)
1499
+
1500
+ def _read(self):
1501
+ self._debug['version']['start'] = self._io.pos()
1502
+ self.version = self._io.read_u1()
1503
+ self._debug['version']['end'] = self._io.pos()
1504
+ self._debug['aug_str']['start'] = self._io.pos()
1505
+ self.aug_str = MachO.SegmentCommand64.Section64.EhFrameItem.CharChain(self._io, self, self._root)
1506
+ self.aug_str._read()
1507
+ self._debug['aug_str']['end'] = self._io.pos()
1508
+ self._debug['code_alignment_factor']['start'] = self._io.pos()
1509
+ self.code_alignment_factor = MachO.Uleb128(self._io, self, self._root)
1510
+ self.code_alignment_factor._read()
1511
+ self._debug['code_alignment_factor']['end'] = self._io.pos()
1512
+ self._debug['data_alignment_factor']['start'] = self._io.pos()
1513
+ self.data_alignment_factor = MachO.Uleb128(self._io, self, self._root)
1514
+ self.data_alignment_factor._read()
1515
+ self._debug['data_alignment_factor']['end'] = self._io.pos()
1516
+ self._debug['return_address_register']['start'] = self._io.pos()
1517
+ self.return_address_register = self._io.read_u1()
1518
+ self._debug['return_address_register']['end'] = self._io.pos()
1519
+ if self.aug_str.chr == 122:
1520
+ self._debug['augmentation']['start'] = self._io.pos()
1521
+ self.augmentation = MachO.SegmentCommand64.Section64.EhFrameItem.AugmentationEntry(self._io, self, self._root)
1522
+ self.augmentation._read()
1523
+ self._debug['augmentation']['end'] = self._io.pos()
1524
+
1525
+
1526
+
1527
+ class AugmentationEntry(KaitaiStruct):
1528
+ SEQ_FIELDS = ["length", "fde_pointer_encoding"]
1529
+ def __init__(self, _io, _parent=None, _root=None):
1530
+ self._io = _io
1531
+ self._parent = _parent
1532
+ self._root = _root if _root else self
1533
+ self._debug = collections.defaultdict(dict)
1534
+
1535
+ def _read(self):
1536
+ self._debug['length']['start'] = self._io.pos()
1537
+ self.length = MachO.Uleb128(self._io, self, self._root)
1538
+ self.length._read()
1539
+ self._debug['length']['end'] = self._io.pos()
1540
+ if self._parent.aug_str.next.chr == 82:
1541
+ self._debug['fde_pointer_encoding']['start'] = self._io.pos()
1542
+ self.fde_pointer_encoding = self._io.read_u1()
1543
+ self._debug['fde_pointer_encoding']['end'] = self._io.pos()
1544
+
1545
+
1546
+
1547
+
1548
+ class EhFrame(KaitaiStruct):
1549
+ SEQ_FIELDS = ["items"]
1550
+ def __init__(self, _io, _parent=None, _root=None):
1551
+ self._io = _io
1552
+ self._parent = _parent
1553
+ self._root = _root if _root else self
1554
+ self._debug = collections.defaultdict(dict)
1555
+
1556
+ def _read(self):
1557
+ self._debug['items']['start'] = self._io.pos()
1558
+ self.items = []
1559
+ i = 0
1560
+ while not self._io.is_eof():
1561
+ if not 'arr' in self._debug['items']:
1562
+ self._debug['items']['arr'] = []
1563
+ self._debug['items']['arr'].append({'start': self._io.pos()})
1564
+ _t_items = MachO.SegmentCommand64.Section64.EhFrameItem(self._io, self, self._root)
1565
+ _t_items._read()
1566
+ self.items.append(_t_items)
1567
+ self._debug['items']['arr'][len(self.items) - 1]['end'] = self._io.pos()
1568
+ i += 1
1569
+
1570
+ self._debug['items']['end'] = self._io.pos()
1571
+
1572
+
1573
+ class PointerList(KaitaiStruct):
1574
+ SEQ_FIELDS = ["items"]
1575
+ def __init__(self, _io, _parent=None, _root=None):
1576
+ self._io = _io
1577
+ self._parent = _parent
1578
+ self._root = _root if _root else self
1579
+ self._debug = collections.defaultdict(dict)
1580
+
1581
+ def _read(self):
1582
+ self._debug['items']['start'] = self._io.pos()
1583
+ self.items = []
1584
+ i = 0
1585
+ while not self._io.is_eof():
1586
+ if not 'arr' in self._debug['items']:
1587
+ self._debug['items']['arr'] = []
1588
+ self._debug['items']['arr'].append({'start': self._io.pos()})
1589
+ self.items.append(self._io.read_u8le())
1590
+ self._debug['items']['arr'][len(self.items) - 1]['end'] = self._io.pos()
1591
+ i += 1
1592
+
1593
+ self._debug['items']['end'] = self._io.pos()
1594
+
1595
+
1596
+ class StringList(KaitaiStruct):
1597
+ SEQ_FIELDS = ["strings"]
1598
+ def __init__(self, _io, _parent=None, _root=None):
1599
+ self._io = _io
1600
+ self._parent = _parent
1601
+ self._root = _root if _root else self
1602
+ self._debug = collections.defaultdict(dict)
1603
+
1604
+ def _read(self):
1605
+ self._debug['strings']['start'] = self._io.pos()
1606
+ self.strings = []
1607
+ i = 0
1608
+ while not self._io.is_eof():
1609
+ if not 'arr' in self._debug['strings']:
1610
+ self._debug['strings']['arr'] = []
1611
+ self._debug['strings']['arr'].append({'start': self._io.pos()})
1612
+ self.strings.append((self._io.read_bytes_term(0, False, True, True)).decode(u"ascii"))
1613
+ self._debug['strings']['arr'][len(self.strings) - 1]['end'] = self._io.pos()
1614
+ i += 1
1615
+
1616
+ self._debug['strings']['end'] = self._io.pos()
1617
+
1618
+
1619
+ @property
1620
+ def data(self):
1621
+ if hasattr(self, '_m_data'):
1622
+ return self._m_data if hasattr(self, '_m_data') else None
1623
+
1624
+ io = self._root._io
1625
+ _pos = io.pos()
1626
+ io.seek(self.offset)
1627
+ self._debug['_m_data']['start'] = io.pos()
1628
+ _on = self.sect_name
1629
+ if _on == u"__objc_nlclslist":
1630
+ self._raw__m_data = io.read_bytes(self.size)
1631
+ _io__raw__m_data = KaitaiStream(BytesIO(self._raw__m_data))
1632
+ self._m_data = MachO.SegmentCommand64.Section64.PointerList(_io__raw__m_data, self, self._root)
1633
+ self._m_data._read()
1634
+ elif _on == u"__objc_methname":
1635
+ self._raw__m_data = io.read_bytes(self.size)
1636
+ _io__raw__m_data = KaitaiStream(BytesIO(self._raw__m_data))
1637
+ self._m_data = MachO.SegmentCommand64.Section64.StringList(_io__raw__m_data, self, self._root)
1638
+ self._m_data._read()
1639
+ elif _on == u"__nl_symbol_ptr":
1640
+ self._raw__m_data = io.read_bytes(self.size)
1641
+ _io__raw__m_data = KaitaiStream(BytesIO(self._raw__m_data))
1642
+ self._m_data = MachO.SegmentCommand64.Section64.PointerList(_io__raw__m_data, self, self._root)
1643
+ self._m_data._read()
1644
+ elif _on == u"__la_symbol_ptr":
1645
+ self._raw__m_data = io.read_bytes(self.size)
1646
+ _io__raw__m_data = KaitaiStream(BytesIO(self._raw__m_data))
1647
+ self._m_data = MachO.SegmentCommand64.Section64.PointerList(_io__raw__m_data, self, self._root)
1648
+ self._m_data._read()
1649
+ elif _on == u"__objc_selrefs":
1650
+ self._raw__m_data = io.read_bytes(self.size)
1651
+ _io__raw__m_data = KaitaiStream(BytesIO(self._raw__m_data))
1652
+ self._m_data = MachO.SegmentCommand64.Section64.PointerList(_io__raw__m_data, self, self._root)
1653
+ self._m_data._read()
1654
+ elif _on == u"__cstring":
1655
+ self._raw__m_data = io.read_bytes(self.size)
1656
+ _io__raw__m_data = KaitaiStream(BytesIO(self._raw__m_data))
1657
+ self._m_data = MachO.SegmentCommand64.Section64.StringList(_io__raw__m_data, self, self._root)
1658
+ self._m_data._read()
1659
+ elif _on == u"__objc_classlist":
1660
+ self._raw__m_data = io.read_bytes(self.size)
1661
+ _io__raw__m_data = KaitaiStream(BytesIO(self._raw__m_data))
1662
+ self._m_data = MachO.SegmentCommand64.Section64.PointerList(_io__raw__m_data, self, self._root)
1663
+ self._m_data._read()
1664
+ elif _on == u"__objc_protolist":
1665
+ self._raw__m_data = io.read_bytes(self.size)
1666
+ _io__raw__m_data = KaitaiStream(BytesIO(self._raw__m_data))
1667
+ self._m_data = MachO.SegmentCommand64.Section64.PointerList(_io__raw__m_data, self, self._root)
1668
+ self._m_data._read()
1669
+ elif _on == u"__objc_imageinfo":
1670
+ self._raw__m_data = io.read_bytes(self.size)
1671
+ _io__raw__m_data = KaitaiStream(BytesIO(self._raw__m_data))
1672
+ self._m_data = MachO.SegmentCommand64.Section64.PointerList(_io__raw__m_data, self, self._root)
1673
+ self._m_data._read()
1674
+ elif _on == u"__objc_methtype":
1675
+ self._raw__m_data = io.read_bytes(self.size)
1676
+ _io__raw__m_data = KaitaiStream(BytesIO(self._raw__m_data))
1677
+ self._m_data = MachO.SegmentCommand64.Section64.StringList(_io__raw__m_data, self, self._root)
1678
+ self._m_data._read()
1679
+ elif _on == u"__cfstring":
1680
+ self._raw__m_data = io.read_bytes(self.size)
1681
+ _io__raw__m_data = KaitaiStream(BytesIO(self._raw__m_data))
1682
+ self._m_data = MachO.SegmentCommand64.Section64.CfStringList(_io__raw__m_data, self, self._root)
1683
+ self._m_data._read()
1684
+ elif _on == u"__objc_classrefs":
1685
+ self._raw__m_data = io.read_bytes(self.size)
1686
+ _io__raw__m_data = KaitaiStream(BytesIO(self._raw__m_data))
1687
+ self._m_data = MachO.SegmentCommand64.Section64.PointerList(_io__raw__m_data, self, self._root)
1688
+ self._m_data._read()
1689
+ elif _on == u"__objc_protorefs":
1690
+ self._raw__m_data = io.read_bytes(self.size)
1691
+ _io__raw__m_data = KaitaiStream(BytesIO(self._raw__m_data))
1692
+ self._m_data = MachO.SegmentCommand64.Section64.PointerList(_io__raw__m_data, self, self._root)
1693
+ self._m_data._read()
1694
+ elif _on == u"__objc_classname":
1695
+ self._raw__m_data = io.read_bytes(self.size)
1696
+ _io__raw__m_data = KaitaiStream(BytesIO(self._raw__m_data))
1697
+ self._m_data = MachO.SegmentCommand64.Section64.StringList(_io__raw__m_data, self, self._root)
1698
+ self._m_data._read()
1699
+ elif _on == u"__got":
1700
+ self._raw__m_data = io.read_bytes(self.size)
1701
+ _io__raw__m_data = KaitaiStream(BytesIO(self._raw__m_data))
1702
+ self._m_data = MachO.SegmentCommand64.Section64.PointerList(_io__raw__m_data, self, self._root)
1703
+ self._m_data._read()
1704
+ elif _on == u"__eh_frame":
1705
+ self._raw__m_data = io.read_bytes(self.size)
1706
+ _io__raw__m_data = KaitaiStream(BytesIO(self._raw__m_data))
1707
+ self._m_data = MachO.SegmentCommand64.Section64.EhFrame(_io__raw__m_data, self, self._root)
1708
+ self._m_data._read()
1709
+ elif _on == u"__objc_superrefs":
1710
+ self._raw__m_data = io.read_bytes(self.size)
1711
+ _io__raw__m_data = KaitaiStream(BytesIO(self._raw__m_data))
1712
+ self._m_data = MachO.SegmentCommand64.Section64.PointerList(_io__raw__m_data, self, self._root)
1713
+ self._m_data._read()
1714
+ else:
1715
+ self._m_data = io.read_bytes(self.size)
1716
+ self._debug['_m_data']['end'] = io.pos()
1717
+ io.seek(_pos)
1718
+ return self._m_data if hasattr(self, '_m_data') else None
1719
+
1720
+
1721
+
1722
+ class VmProt(KaitaiStruct):
1723
+ SEQ_FIELDS = ["strip_read", "is_mask", "reserved0", "copy", "no_change", "execute", "write", "read", "reserved1"]
1724
+ def __init__(self, _io, _parent=None, _root=None):
1725
+ self._io = _io
1726
+ self._parent = _parent
1727
+ self._root = _root if _root else self
1728
+ self._debug = collections.defaultdict(dict)
1729
+
1730
+ def _read(self):
1731
+ self._debug['strip_read']['start'] = self._io.pos()
1732
+ self.strip_read = self._io.read_bits_int_be(1) != 0
1733
+ self._debug['strip_read']['end'] = self._io.pos()
1734
+ self._debug['is_mask']['start'] = self._io.pos()
1735
+ self.is_mask = self._io.read_bits_int_be(1) != 0
1736
+ self._debug['is_mask']['end'] = self._io.pos()
1737
+ self._debug['reserved0']['start'] = self._io.pos()
1738
+ self.reserved0 = self._io.read_bits_int_be(1) != 0
1739
+ self._debug['reserved0']['end'] = self._io.pos()
1740
+ self._debug['copy']['start'] = self._io.pos()
1741
+ self.copy = self._io.read_bits_int_be(1) != 0
1742
+ self._debug['copy']['end'] = self._io.pos()
1743
+ self._debug['no_change']['start'] = self._io.pos()
1744
+ self.no_change = self._io.read_bits_int_be(1) != 0
1745
+ self._debug['no_change']['end'] = self._io.pos()
1746
+ self._debug['execute']['start'] = self._io.pos()
1747
+ self.execute = self._io.read_bits_int_be(1) != 0
1748
+ self._debug['execute']['end'] = self._io.pos()
1749
+ self._debug['write']['start'] = self._io.pos()
1750
+ self.write = self._io.read_bits_int_be(1) != 0
1751
+ self._debug['write']['end'] = self._io.pos()
1752
+ self._debug['read']['start'] = self._io.pos()
1753
+ self.read = self._io.read_bits_int_be(1) != 0
1754
+ self._debug['read']['end'] = self._io.pos()
1755
+ self._debug['reserved1']['start'] = self._io.pos()
1756
+ self.reserved1 = self._io.read_bits_int_be(24)
1757
+ self._debug['reserved1']['end'] = self._io.pos()
1758
+
1759
+
1760
+ class DysymtabCommand(KaitaiStruct):
1761
+ SEQ_FIELDS = ["i_local_sym", "n_local_sym", "i_ext_def_sym", "n_ext_def_sym", "i_undef_sym", "n_undef_sym", "toc_off", "n_toc", "mod_tab_off", "n_mod_tab", "ext_ref_sym_off", "n_ext_ref_syms", "indirect_sym_off", "n_indirect_syms", "ext_rel_off", "n_ext_rel", "loc_rel_off", "n_loc_rel"]
1762
+ def __init__(self, _io, _parent=None, _root=None):
1763
+ self._io = _io
1764
+ self._parent = _parent
1765
+ self._root = _root if _root else self
1766
+ self._debug = collections.defaultdict(dict)
1767
+
1768
+ def _read(self):
1769
+ self._debug['i_local_sym']['start'] = self._io.pos()
1770
+ self.i_local_sym = self._io.read_u4le()
1771
+ self._debug['i_local_sym']['end'] = self._io.pos()
1772
+ self._debug['n_local_sym']['start'] = self._io.pos()
1773
+ self.n_local_sym = self._io.read_u4le()
1774
+ self._debug['n_local_sym']['end'] = self._io.pos()
1775
+ self._debug['i_ext_def_sym']['start'] = self._io.pos()
1776
+ self.i_ext_def_sym = self._io.read_u4le()
1777
+ self._debug['i_ext_def_sym']['end'] = self._io.pos()
1778
+ self._debug['n_ext_def_sym']['start'] = self._io.pos()
1779
+ self.n_ext_def_sym = self._io.read_u4le()
1780
+ self._debug['n_ext_def_sym']['end'] = self._io.pos()
1781
+ self._debug['i_undef_sym']['start'] = self._io.pos()
1782
+ self.i_undef_sym = self._io.read_u4le()
1783
+ self._debug['i_undef_sym']['end'] = self._io.pos()
1784
+ self._debug['n_undef_sym']['start'] = self._io.pos()
1785
+ self.n_undef_sym = self._io.read_u4le()
1786
+ self._debug['n_undef_sym']['end'] = self._io.pos()
1787
+ self._debug['toc_off']['start'] = self._io.pos()
1788
+ self.toc_off = self._io.read_u4le()
1789
+ self._debug['toc_off']['end'] = self._io.pos()
1790
+ self._debug['n_toc']['start'] = self._io.pos()
1791
+ self.n_toc = self._io.read_u4le()
1792
+ self._debug['n_toc']['end'] = self._io.pos()
1793
+ self._debug['mod_tab_off']['start'] = self._io.pos()
1794
+ self.mod_tab_off = self._io.read_u4le()
1795
+ self._debug['mod_tab_off']['end'] = self._io.pos()
1796
+ self._debug['n_mod_tab']['start'] = self._io.pos()
1797
+ self.n_mod_tab = self._io.read_u4le()
1798
+ self._debug['n_mod_tab']['end'] = self._io.pos()
1799
+ self._debug['ext_ref_sym_off']['start'] = self._io.pos()
1800
+ self.ext_ref_sym_off = self._io.read_u4le()
1801
+ self._debug['ext_ref_sym_off']['end'] = self._io.pos()
1802
+ self._debug['n_ext_ref_syms']['start'] = self._io.pos()
1803
+ self.n_ext_ref_syms = self._io.read_u4le()
1804
+ self._debug['n_ext_ref_syms']['end'] = self._io.pos()
1805
+ self._debug['indirect_sym_off']['start'] = self._io.pos()
1806
+ self.indirect_sym_off = self._io.read_u4le()
1807
+ self._debug['indirect_sym_off']['end'] = self._io.pos()
1808
+ self._debug['n_indirect_syms']['start'] = self._io.pos()
1809
+ self.n_indirect_syms = self._io.read_u4le()
1810
+ self._debug['n_indirect_syms']['end'] = self._io.pos()
1811
+ self._debug['ext_rel_off']['start'] = self._io.pos()
1812
+ self.ext_rel_off = self._io.read_u4le()
1813
+ self._debug['ext_rel_off']['end'] = self._io.pos()
1814
+ self._debug['n_ext_rel']['start'] = self._io.pos()
1815
+ self.n_ext_rel = self._io.read_u4le()
1816
+ self._debug['n_ext_rel']['end'] = self._io.pos()
1817
+ self._debug['loc_rel_off']['start'] = self._io.pos()
1818
+ self.loc_rel_off = self._io.read_u4le()
1819
+ self._debug['loc_rel_off']['end'] = self._io.pos()
1820
+ self._debug['n_loc_rel']['start'] = self._io.pos()
1821
+ self.n_loc_rel = self._io.read_u4le()
1822
+ self._debug['n_loc_rel']['end'] = self._io.pos()
1823
+
1824
+ @property
1825
+ def indirect_symbols(self):
1826
+ if hasattr(self, '_m_indirect_symbols'):
1827
+ return self._m_indirect_symbols if hasattr(self, '_m_indirect_symbols') else None
1828
+
1829
+ io = self._root._io
1830
+ _pos = io.pos()
1831
+ io.seek(self.indirect_sym_off)
1832
+ self._debug['_m_indirect_symbols']['start'] = io.pos()
1833
+ self._m_indirect_symbols = [None] * (self.n_indirect_syms)
1834
+ for i in range(self.n_indirect_syms):
1835
+ if not 'arr' in self._debug['_m_indirect_symbols']:
1836
+ self._debug['_m_indirect_symbols']['arr'] = []
1837
+ self._debug['_m_indirect_symbols']['arr'].append({'start': io.pos()})
1838
+ self._m_indirect_symbols[i] = io.read_u4le()
1839
+ self._debug['_m_indirect_symbols']['arr'][i]['end'] = io.pos()
1840
+
1841
+ self._debug['_m_indirect_symbols']['end'] = io.pos()
1842
+ io.seek(_pos)
1843
+ return self._m_indirect_symbols if hasattr(self, '_m_indirect_symbols') else None
1844
+
1845
+
1846
+ class MachHeader(KaitaiStruct):
1847
+ SEQ_FIELDS = ["cputype", "cpusubtype", "filetype", "ncmds", "sizeofcmds", "flags", "reserved"]
1848
+ def __init__(self, _io, _parent=None, _root=None):
1849
+ self._io = _io
1850
+ self._parent = _parent
1851
+ self._root = _root if _root else self
1852
+ self._debug = collections.defaultdict(dict)
1853
+
1854
+ def _read(self):
1855
+ self._debug['cputype']['start'] = self._io.pos()
1856
+ self.cputype = KaitaiStream.resolve_enum(MachO.CpuType, self._io.read_u4le())
1857
+ self._debug['cputype']['end'] = self._io.pos()
1858
+ self._debug['cpusubtype']['start'] = self._io.pos()
1859
+ self.cpusubtype = self._io.read_u4le()
1860
+ self._debug['cpusubtype']['end'] = self._io.pos()
1861
+ self._debug['filetype']['start'] = self._io.pos()
1862
+ self.filetype = KaitaiStream.resolve_enum(MachO.FileType, self._io.read_u4le())
1863
+ self._debug['filetype']['end'] = self._io.pos()
1864
+ self._debug['ncmds']['start'] = self._io.pos()
1865
+ self.ncmds = self._io.read_u4le()
1866
+ self._debug['ncmds']['end'] = self._io.pos()
1867
+ self._debug['sizeofcmds']['start'] = self._io.pos()
1868
+ self.sizeofcmds = self._io.read_u4le()
1869
+ self._debug['sizeofcmds']['end'] = self._io.pos()
1870
+ self._debug['flags']['start'] = self._io.pos()
1871
+ self.flags = self._io.read_u4le()
1872
+ self._debug['flags']['end'] = self._io.pos()
1873
+ if ((self._root.magic == MachO.MagicType.macho_be_x64) or (self._root.magic == MachO.MagicType.macho_le_x64)) :
1874
+ self._debug['reserved']['start'] = self._io.pos()
1875
+ self.reserved = self._io.read_u4le()
1876
+ self._debug['reserved']['end'] = self._io.pos()
1877
+
1878
+
1879
+ @property
1880
+ def flags_obj(self):
1881
+ if hasattr(self, '_m_flags_obj'):
1882
+ return self._m_flags_obj if hasattr(self, '_m_flags_obj') else None
1883
+
1884
+ self._debug['_m_flags_obj']['start'] = self._io.pos()
1885
+ self._m_flags_obj = MachO.MachoFlags(self.flags, self._io, self, self._root)
1886
+ self._m_flags_obj._read()
1887
+ self._debug['_m_flags_obj']['end'] = self._io.pos()
1888
+ return self._m_flags_obj if hasattr(self, '_m_flags_obj') else None
1889
+
1890
+
1891
+ class LinkeditDataCommand(KaitaiStruct):
1892
+ SEQ_FIELDS = ["data_off", "data_size"]
1893
+ def __init__(self, _io, _parent=None, _root=None):
1894
+ self._io = _io
1895
+ self._parent = _parent
1896
+ self._root = _root if _root else self
1897
+ self._debug = collections.defaultdict(dict)
1898
+
1899
+ def _read(self):
1900
+ self._debug['data_off']['start'] = self._io.pos()
1901
+ self.data_off = self._io.read_u4le()
1902
+ self._debug['data_off']['end'] = self._io.pos()
1903
+ self._debug['data_size']['start'] = self._io.pos()
1904
+ self.data_size = self._io.read_u4le()
1905
+ self._debug['data_size']['end'] = self._io.pos()
1906
+
1907
+
1908
+ class SubCommand(KaitaiStruct):
1909
+ SEQ_FIELDS = ["name"]
1910
+ def __init__(self, _io, _parent=None, _root=None):
1911
+ self._io = _io
1912
+ self._parent = _parent
1913
+ self._root = _root if _root else self
1914
+ self._debug = collections.defaultdict(dict)
1915
+
1916
+ def _read(self):
1917
+ self._debug['name']['start'] = self._io.pos()
1918
+ self.name = MachO.LcStr(self._io, self, self._root)
1919
+ self.name._read()
1920
+ self._debug['name']['end'] = self._io.pos()
1921
+
1922
+
1923
+ class TwolevelHintsCommand(KaitaiStruct):
1924
+ SEQ_FIELDS = ["offset", "num_hints"]
1925
+ def __init__(self, _io, _parent=None, _root=None):
1926
+ self._io = _io
1927
+ self._parent = _parent
1928
+ self._root = _root if _root else self
1929
+ self._debug = collections.defaultdict(dict)
1930
+
1931
+ def _read(self):
1932
+ self._debug['offset']['start'] = self._io.pos()
1933
+ self.offset = self._io.read_u4le()
1934
+ self._debug['offset']['end'] = self._io.pos()
1935
+ self._debug['num_hints']['start'] = self._io.pos()
1936
+ self.num_hints = self._io.read_u4le()
1937
+ self._debug['num_hints']['end'] = self._io.pos()
1938
+
1939
+
1940
+ class Version(KaitaiStruct):
1941
+ SEQ_FIELDS = ["p1", "minor", "major", "release"]
1942
+ def __init__(self, _io, _parent=None, _root=None):
1943
+ self._io = _io
1944
+ self._parent = _parent
1945
+ self._root = _root if _root else self
1946
+ self._debug = collections.defaultdict(dict)
1947
+
1948
+ def _read(self):
1949
+ self._debug['p1']['start'] = self._io.pos()
1950
+ self.p1 = self._io.read_u1()
1951
+ self._debug['p1']['end'] = self._io.pos()
1952
+ self._debug['minor']['start'] = self._io.pos()
1953
+ self.minor = self._io.read_u1()
1954
+ self._debug['minor']['end'] = self._io.pos()
1955
+ self._debug['major']['start'] = self._io.pos()
1956
+ self.major = self._io.read_u1()
1957
+ self._debug['major']['end'] = self._io.pos()
1958
+ self._debug['release']['start'] = self._io.pos()
1959
+ self.release = self._io.read_u1()
1960
+ self._debug['release']['end'] = self._io.pos()
1961
+
1962
+
1963
+ class EncryptionInfoCommand(KaitaiStruct):
1964
+ SEQ_FIELDS = ["cryptoff", "cryptsize", "cryptid", "pad"]
1965
+ def __init__(self, _io, _parent=None, _root=None):
1966
+ self._io = _io
1967
+ self._parent = _parent
1968
+ self._root = _root if _root else self
1969
+ self._debug = collections.defaultdict(dict)
1970
+
1971
+ def _read(self):
1972
+ self._debug['cryptoff']['start'] = self._io.pos()
1973
+ self.cryptoff = self._io.read_u4le()
1974
+ self._debug['cryptoff']['end'] = self._io.pos()
1975
+ self._debug['cryptsize']['start'] = self._io.pos()
1976
+ self.cryptsize = self._io.read_u4le()
1977
+ self._debug['cryptsize']['end'] = self._io.pos()
1978
+ self._debug['cryptid']['start'] = self._io.pos()
1979
+ self.cryptid = self._io.read_u4le()
1980
+ self._debug['cryptid']['end'] = self._io.pos()
1981
+ if ((self._root.magic == MachO.MagicType.macho_be_x64) or (self._root.magic == MachO.MagicType.macho_le_x64)) :
1982
+ self._debug['pad']['start'] = self._io.pos()
1983
+ self.pad = self._io.read_u4le()
1984
+ self._debug['pad']['end'] = self._io.pos()
1985
+
1986
+
1987
+
1988
+ class CodeSignatureCommand(KaitaiStruct):
1989
+ SEQ_FIELDS = ["data_off", "data_size"]
1990
+ def __init__(self, _io, _parent=None, _root=None):
1991
+ self._io = _io
1992
+ self._parent = _parent
1993
+ self._root = _root if _root else self
1994
+ self._debug = collections.defaultdict(dict)
1995
+
1996
+ def _read(self):
1997
+ self._debug['data_off']['start'] = self._io.pos()
1998
+ self.data_off = self._io.read_u4le()
1999
+ self._debug['data_off']['end'] = self._io.pos()
2000
+ self._debug['data_size']['start'] = self._io.pos()
2001
+ self.data_size = self._io.read_u4le()
2002
+ self._debug['data_size']['end'] = self._io.pos()
2003
+
2004
+ @property
2005
+ def code_signature(self):
2006
+ if hasattr(self, '_m_code_signature'):
2007
+ return self._m_code_signature if hasattr(self, '_m_code_signature') else None
2008
+
2009
+ io = self._root._io
2010
+ _pos = io.pos()
2011
+ io.seek(self.data_off)
2012
+ self._debug['_m_code_signature']['start'] = io.pos()
2013
+ self._raw__m_code_signature = io.read_bytes(self.data_size)
2014
+ _io__raw__m_code_signature = KaitaiStream(BytesIO(self._raw__m_code_signature))
2015
+ self._m_code_signature = MachO.CsBlob(_io__raw__m_code_signature, self, self._root)
2016
+ self._m_code_signature._read()
2017
+ self._debug['_m_code_signature']['end'] = io.pos()
2018
+ io.seek(_pos)
2019
+ return self._m_code_signature if hasattr(self, '_m_code_signature') else None
2020
+
2021
+
2022
+ class DyldInfoCommand(KaitaiStruct):
2023
+
2024
+ class BindOpcode(Enum):
2025
+ done = 0
2026
+ set_dylib_ordinal_immediate = 16
2027
+ set_dylib_ordinal_uleb = 32
2028
+ set_dylib_special_immediate = 48
2029
+ set_symbol_trailing_flags_immediate = 64
2030
+ set_type_immediate = 80
2031
+ set_append_sleb = 96
2032
+ set_segment_and_offset_uleb = 112
2033
+ add_address_uleb = 128
2034
+ do_bind = 144
2035
+ do_bind_add_address_uleb = 160
2036
+ do_bind_add_address_immediate_scaled = 176
2037
+ do_bind_uleb_times_skipping_uleb = 192
2038
+ SEQ_FIELDS = ["rebase_off", "rebase_size", "bind_off", "bind_size", "weak_bind_off", "weak_bind_size", "lazy_bind_off", "lazy_bind_size", "export_off", "export_size"]
2039
+ def __init__(self, _io, _parent=None, _root=None):
2040
+ self._io = _io
2041
+ self._parent = _parent
2042
+ self._root = _root if _root else self
2043
+ self._debug = collections.defaultdict(dict)
2044
+
2045
+ def _read(self):
2046
+ self._debug['rebase_off']['start'] = self._io.pos()
2047
+ self.rebase_off = self._io.read_u4le()
2048
+ self._debug['rebase_off']['end'] = self._io.pos()
2049
+ self._debug['rebase_size']['start'] = self._io.pos()
2050
+ self.rebase_size = self._io.read_u4le()
2051
+ self._debug['rebase_size']['end'] = self._io.pos()
2052
+ self._debug['bind_off']['start'] = self._io.pos()
2053
+ self.bind_off = self._io.read_u4le()
2054
+ self._debug['bind_off']['end'] = self._io.pos()
2055
+ self._debug['bind_size']['start'] = self._io.pos()
2056
+ self.bind_size = self._io.read_u4le()
2057
+ self._debug['bind_size']['end'] = self._io.pos()
2058
+ self._debug['weak_bind_off']['start'] = self._io.pos()
2059
+ self.weak_bind_off = self._io.read_u4le()
2060
+ self._debug['weak_bind_off']['end'] = self._io.pos()
2061
+ self._debug['weak_bind_size']['start'] = self._io.pos()
2062
+ self.weak_bind_size = self._io.read_u4le()
2063
+ self._debug['weak_bind_size']['end'] = self._io.pos()
2064
+ self._debug['lazy_bind_off']['start'] = self._io.pos()
2065
+ self.lazy_bind_off = self._io.read_u4le()
2066
+ self._debug['lazy_bind_off']['end'] = self._io.pos()
2067
+ self._debug['lazy_bind_size']['start'] = self._io.pos()
2068
+ self.lazy_bind_size = self._io.read_u4le()
2069
+ self._debug['lazy_bind_size']['end'] = self._io.pos()
2070
+ self._debug['export_off']['start'] = self._io.pos()
2071
+ self.export_off = self._io.read_u4le()
2072
+ self._debug['export_off']['end'] = self._io.pos()
2073
+ self._debug['export_size']['start'] = self._io.pos()
2074
+ self.export_size = self._io.read_u4le()
2075
+ self._debug['export_size']['end'] = self._io.pos()
2076
+
2077
+ class RebaseData(KaitaiStruct):
2078
+
2079
+ class Opcode(Enum):
2080
+ done = 0
2081
+ set_type_immediate = 16
2082
+ set_segment_and_offset_uleb = 32
2083
+ add_address_uleb = 48
2084
+ add_address_immediate_scaled = 64
2085
+ do_rebase_immediate_times = 80
2086
+ do_rebase_uleb_times = 96
2087
+ do_rebase_add_address_uleb = 112
2088
+ do_rebase_uleb_times_skipping_uleb = 128
2089
+ SEQ_FIELDS = ["items"]
2090
+ def __init__(self, _io, _parent=None, _root=None):
2091
+ self._io = _io
2092
+ self._parent = _parent
2093
+ self._root = _root if _root else self
2094
+ self._debug = collections.defaultdict(dict)
2095
+
2096
+ def _read(self):
2097
+ self._debug['items']['start'] = self._io.pos()
2098
+ self.items = []
2099
+ i = 0
2100
+ while True:
2101
+ if not 'arr' in self._debug['items']:
2102
+ self._debug['items']['arr'] = []
2103
+ self._debug['items']['arr'].append({'start': self._io.pos()})
2104
+ _t_items = MachO.DyldInfoCommand.RebaseData.RebaseItem(self._io, self, self._root)
2105
+ _t_items._read()
2106
+ _ = _t_items
2107
+ self.items.append(_)
2108
+ self._debug['items']['arr'][len(self.items) - 1]['end'] = self._io.pos()
2109
+ if _.opcode == MachO.DyldInfoCommand.RebaseData.Opcode.done:
2110
+ break
2111
+ i += 1
2112
+ self._debug['items']['end'] = self._io.pos()
2113
+
2114
+ class RebaseItem(KaitaiStruct):
2115
+ SEQ_FIELDS = ["opcode_and_immediate", "uleb", "skip"]
2116
+ def __init__(self, _io, _parent=None, _root=None):
2117
+ self._io = _io
2118
+ self._parent = _parent
2119
+ self._root = _root if _root else self
2120
+ self._debug = collections.defaultdict(dict)
2121
+
2122
+ def _read(self):
2123
+ self._debug['opcode_and_immediate']['start'] = self._io.pos()
2124
+ self.opcode_and_immediate = self._io.read_u1()
2125
+ self._debug['opcode_and_immediate']['end'] = self._io.pos()
2126
+ if ((self.opcode == MachO.DyldInfoCommand.RebaseData.Opcode.set_segment_and_offset_uleb) or (self.opcode == MachO.DyldInfoCommand.RebaseData.Opcode.add_address_uleb) or (self.opcode == MachO.DyldInfoCommand.RebaseData.Opcode.do_rebase_uleb_times) or (self.opcode == MachO.DyldInfoCommand.RebaseData.Opcode.do_rebase_add_address_uleb) or (self.opcode == MachO.DyldInfoCommand.RebaseData.Opcode.do_rebase_uleb_times_skipping_uleb)) :
2127
+ self._debug['uleb']['start'] = self._io.pos()
2128
+ self.uleb = MachO.Uleb128(self._io, self, self._root)
2129
+ self.uleb._read()
2130
+ self._debug['uleb']['end'] = self._io.pos()
2131
+
2132
+ if self.opcode == MachO.DyldInfoCommand.RebaseData.Opcode.do_rebase_uleb_times_skipping_uleb:
2133
+ self._debug['skip']['start'] = self._io.pos()
2134
+ self.skip = MachO.Uleb128(self._io, self, self._root)
2135
+ self.skip._read()
2136
+ self._debug['skip']['end'] = self._io.pos()
2137
+
2138
+
2139
+ @property
2140
+ def opcode(self):
2141
+ if hasattr(self, '_m_opcode'):
2142
+ return self._m_opcode if hasattr(self, '_m_opcode') else None
2143
+
2144
+ self._m_opcode = KaitaiStream.resolve_enum(MachO.DyldInfoCommand.RebaseData.Opcode, (self.opcode_and_immediate & 240))
2145
+ return self._m_opcode if hasattr(self, '_m_opcode') else None
2146
+
2147
+ @property
2148
+ def immediate(self):
2149
+ if hasattr(self, '_m_immediate'):
2150
+ return self._m_immediate if hasattr(self, '_m_immediate') else None
2151
+
2152
+ self._m_immediate = (self.opcode_and_immediate & 15)
2153
+ return self._m_immediate if hasattr(self, '_m_immediate') else None
2154
+
2155
+
2156
+
2157
+ class BindItem(KaitaiStruct):
2158
+ SEQ_FIELDS = ["opcode_and_immediate", "uleb", "skip", "symbol"]
2159
+ def __init__(self, _io, _parent=None, _root=None):
2160
+ self._io = _io
2161
+ self._parent = _parent
2162
+ self._root = _root if _root else self
2163
+ self._debug = collections.defaultdict(dict)
2164
+
2165
+ def _read(self):
2166
+ self._debug['opcode_and_immediate']['start'] = self._io.pos()
2167
+ self.opcode_and_immediate = self._io.read_u1()
2168
+ self._debug['opcode_and_immediate']['end'] = self._io.pos()
2169
+ if ((self.opcode == MachO.DyldInfoCommand.BindOpcode.set_dylib_ordinal_uleb) or (self.opcode == MachO.DyldInfoCommand.BindOpcode.set_append_sleb) or (self.opcode == MachO.DyldInfoCommand.BindOpcode.set_segment_and_offset_uleb) or (self.opcode == MachO.DyldInfoCommand.BindOpcode.add_address_uleb) or (self.opcode == MachO.DyldInfoCommand.BindOpcode.do_bind_add_address_uleb) or (self.opcode == MachO.DyldInfoCommand.BindOpcode.do_bind_uleb_times_skipping_uleb)) :
2170
+ self._debug['uleb']['start'] = self._io.pos()
2171
+ self.uleb = MachO.Uleb128(self._io, self, self._root)
2172
+ self.uleb._read()
2173
+ self._debug['uleb']['end'] = self._io.pos()
2174
+
2175
+ if self.opcode == MachO.DyldInfoCommand.BindOpcode.do_bind_uleb_times_skipping_uleb:
2176
+ self._debug['skip']['start'] = self._io.pos()
2177
+ self.skip = MachO.Uleb128(self._io, self, self._root)
2178
+ self.skip._read()
2179
+ self._debug['skip']['end'] = self._io.pos()
2180
+
2181
+ if self.opcode == MachO.DyldInfoCommand.BindOpcode.set_symbol_trailing_flags_immediate:
2182
+ self._debug['symbol']['start'] = self._io.pos()
2183
+ self.symbol = (self._io.read_bytes_term(0, False, True, True)).decode(u"ascii")
2184
+ self._debug['symbol']['end'] = self._io.pos()
2185
+
2186
+
2187
+ @property
2188
+ def opcode(self):
2189
+ if hasattr(self, '_m_opcode'):
2190
+ return self._m_opcode if hasattr(self, '_m_opcode') else None
2191
+
2192
+ self._m_opcode = KaitaiStream.resolve_enum(MachO.DyldInfoCommand.BindOpcode, (self.opcode_and_immediate & 240))
2193
+ return self._m_opcode if hasattr(self, '_m_opcode') else None
2194
+
2195
+ @property
2196
+ def immediate(self):
2197
+ if hasattr(self, '_m_immediate'):
2198
+ return self._m_immediate if hasattr(self, '_m_immediate') else None
2199
+
2200
+ self._m_immediate = (self.opcode_and_immediate & 15)
2201
+ return self._m_immediate if hasattr(self, '_m_immediate') else None
2202
+
2203
+
2204
+ class BindData(KaitaiStruct):
2205
+ SEQ_FIELDS = ["items"]
2206
+ def __init__(self, _io, _parent=None, _root=None):
2207
+ self._io = _io
2208
+ self._parent = _parent
2209
+ self._root = _root if _root else self
2210
+ self._debug = collections.defaultdict(dict)
2211
+
2212
+ def _read(self):
2213
+ self._debug['items']['start'] = self._io.pos()
2214
+ self.items = []
2215
+ i = 0
2216
+ while not self._io.is_eof():
2217
+ if not 'arr' in self._debug['items']:
2218
+ self._debug['items']['arr'] = []
2219
+ self._debug['items']['arr'].append({'start': self._io.pos()})
2220
+ _t_items = MachO.DyldInfoCommand.BindItem(self._io, self, self._root)
2221
+ _t_items._read()
2222
+ self.items.append(_t_items)
2223
+ self._debug['items']['arr'][len(self.items) - 1]['end'] = self._io.pos()
2224
+ i += 1
2225
+
2226
+ self._debug['items']['end'] = self._io.pos()
2227
+
2228
+
2229
+ class ExportNode(KaitaiStruct):
2230
+ SEQ_FIELDS = ["terminal_size", "children_count", "children", "terminal"]
2231
+ def __init__(self, _io, _parent=None, _root=None):
2232
+ self._io = _io
2233
+ self._parent = _parent
2234
+ self._root = _root if _root else self
2235
+ self._debug = collections.defaultdict(dict)
2236
+
2237
+ def _read(self):
2238
+ self._debug['terminal_size']['start'] = self._io.pos()
2239
+ self.terminal_size = MachO.Uleb128(self._io, self, self._root)
2240
+ self.terminal_size._read()
2241
+ self._debug['terminal_size']['end'] = self._io.pos()
2242
+ self._debug['children_count']['start'] = self._io.pos()
2243
+ self.children_count = self._io.read_u1()
2244
+ self._debug['children_count']['end'] = self._io.pos()
2245
+ self._debug['children']['start'] = self._io.pos()
2246
+ self.children = [None] * (self.children_count)
2247
+ for i in range(self.children_count):
2248
+ if not 'arr' in self._debug['children']:
2249
+ self._debug['children']['arr'] = []
2250
+ self._debug['children']['arr'].append({'start': self._io.pos()})
2251
+ _t_children = MachO.DyldInfoCommand.ExportNode.Child(self._io, self, self._root)
2252
+ _t_children._read()
2253
+ self.children[i] = _t_children
2254
+ self._debug['children']['arr'][i]['end'] = self._io.pos()
2255
+
2256
+ self._debug['children']['end'] = self._io.pos()
2257
+ self._debug['terminal']['start'] = self._io.pos()
2258
+ self.terminal = self._io.read_bytes(self.terminal_size.value)
2259
+ self._debug['terminal']['end'] = self._io.pos()
2260
+
2261
+ class Child(KaitaiStruct):
2262
+ SEQ_FIELDS = ["name", "node_offset"]
2263
+ def __init__(self, _io, _parent=None, _root=None):
2264
+ self._io = _io
2265
+ self._parent = _parent
2266
+ self._root = _root if _root else self
2267
+ self._debug = collections.defaultdict(dict)
2268
+
2269
+ def _read(self):
2270
+ self._debug['name']['start'] = self._io.pos()
2271
+ self.name = (self._io.read_bytes_term(0, False, True, True)).decode(u"ascii")
2272
+ self._debug['name']['end'] = self._io.pos()
2273
+ self._debug['node_offset']['start'] = self._io.pos()
2274
+ self.node_offset = MachO.Uleb128(self._io, self, self._root)
2275
+ self.node_offset._read()
2276
+ self._debug['node_offset']['end'] = self._io.pos()
2277
+
2278
+ @property
2279
+ def value(self):
2280
+ if hasattr(self, '_m_value'):
2281
+ return self._m_value if hasattr(self, '_m_value') else None
2282
+
2283
+ _pos = self._io.pos()
2284
+ self._io.seek(self.node_offset.value)
2285
+ self._debug['_m_value']['start'] = self._io.pos()
2286
+ self._m_value = MachO.DyldInfoCommand.ExportNode(self._io, self, self._root)
2287
+ self._m_value._read()
2288
+ self._debug['_m_value']['end'] = self._io.pos()
2289
+ self._io.seek(_pos)
2290
+ return self._m_value if hasattr(self, '_m_value') else None
2291
+
2292
+
2293
+
2294
+ @property
2295
+ def bind(self):
2296
+ if hasattr(self, '_m_bind'):
2297
+ return self._m_bind if hasattr(self, '_m_bind') else None
2298
+
2299
+ if self.bind_size != 0:
2300
+ io = self._root._io
2301
+ _pos = io.pos()
2302
+ io.seek(self.bind_off)
2303
+ self._debug['_m_bind']['start'] = io.pos()
2304
+ self._raw__m_bind = io.read_bytes(self.bind_size)
2305
+ _io__raw__m_bind = KaitaiStream(BytesIO(self._raw__m_bind))
2306
+ self._m_bind = MachO.DyldInfoCommand.BindData(_io__raw__m_bind, self, self._root)
2307
+ self._m_bind._read()
2308
+ self._debug['_m_bind']['end'] = io.pos()
2309
+ io.seek(_pos)
2310
+
2311
+ return self._m_bind if hasattr(self, '_m_bind') else None
2312
+
2313
+ @property
2314
+ def exports(self):
2315
+ if hasattr(self, '_m_exports'):
2316
+ return self._m_exports if hasattr(self, '_m_exports') else None
2317
+
2318
+ if self.export_size != 0:
2319
+ io = self._root._io
2320
+ _pos = io.pos()
2321
+ io.seek(self.export_off)
2322
+ self._debug['_m_exports']['start'] = io.pos()
2323
+ self._raw__m_exports = io.read_bytes(self.export_size)
2324
+ _io__raw__m_exports = KaitaiStream(BytesIO(self._raw__m_exports))
2325
+ self._m_exports = MachO.DyldInfoCommand.ExportNode(_io__raw__m_exports, self, self._root)
2326
+ self._m_exports._read()
2327
+ self._debug['_m_exports']['end'] = io.pos()
2328
+ io.seek(_pos)
2329
+
2330
+ return self._m_exports if hasattr(self, '_m_exports') else None
2331
+
2332
+ @property
2333
+ def weak_bind(self):
2334
+ if hasattr(self, '_m_weak_bind'):
2335
+ return self._m_weak_bind if hasattr(self, '_m_weak_bind') else None
2336
+
2337
+ if self.weak_bind_size != 0:
2338
+ io = self._root._io
2339
+ _pos = io.pos()
2340
+ io.seek(self.weak_bind_off)
2341
+ self._debug['_m_weak_bind']['start'] = io.pos()
2342
+ self._raw__m_weak_bind = io.read_bytes(self.weak_bind_size)
2343
+ _io__raw__m_weak_bind = KaitaiStream(BytesIO(self._raw__m_weak_bind))
2344
+ self._m_weak_bind = MachO.DyldInfoCommand.BindData(_io__raw__m_weak_bind, self, self._root)
2345
+ self._m_weak_bind._read()
2346
+ self._debug['_m_weak_bind']['end'] = io.pos()
2347
+ io.seek(_pos)
2348
+
2349
+ return self._m_weak_bind if hasattr(self, '_m_weak_bind') else None
2350
+
2351
+ @property
2352
+ def rebase(self):
2353
+ if hasattr(self, '_m_rebase'):
2354
+ return self._m_rebase if hasattr(self, '_m_rebase') else None
2355
+
2356
+ if self.rebase_size != 0:
2357
+ io = self._root._io
2358
+ _pos = io.pos()
2359
+ io.seek(self.rebase_off)
2360
+ self._debug['_m_rebase']['start'] = io.pos()
2361
+ self._raw__m_rebase = io.read_bytes(self.rebase_size)
2362
+ _io__raw__m_rebase = KaitaiStream(BytesIO(self._raw__m_rebase))
2363
+ self._m_rebase = MachO.DyldInfoCommand.RebaseData(_io__raw__m_rebase, self, self._root)
2364
+ self._m_rebase._read()
2365
+ self._debug['_m_rebase']['end'] = io.pos()
2366
+ io.seek(_pos)
2367
+
2368
+ return self._m_rebase if hasattr(self, '_m_rebase') else None
2369
+
2370
+ @property
2371
+ def lazy_bind(self):
2372
+ if hasattr(self, '_m_lazy_bind'):
2373
+ return self._m_lazy_bind if hasattr(self, '_m_lazy_bind') else None
2374
+
2375
+ if self.lazy_bind_size != 0:
2376
+ io = self._root._io
2377
+ _pos = io.pos()
2378
+ io.seek(self.lazy_bind_off)
2379
+ self._debug['_m_lazy_bind']['start'] = io.pos()
2380
+ self._raw__m_lazy_bind = io.read_bytes(self.lazy_bind_size)
2381
+ _io__raw__m_lazy_bind = KaitaiStream(BytesIO(self._raw__m_lazy_bind))
2382
+ self._m_lazy_bind = MachO.DyldInfoCommand.BindData(_io__raw__m_lazy_bind, self, self._root)
2383
+ self._m_lazy_bind._read()
2384
+ self._debug['_m_lazy_bind']['end'] = io.pos()
2385
+ io.seek(_pos)
2386
+
2387
+ return self._m_lazy_bind if hasattr(self, '_m_lazy_bind') else None
2388
+
2389
+
2390
+ class DylinkerCommand(KaitaiStruct):
2391
+ SEQ_FIELDS = ["name"]
2392
+ def __init__(self, _io, _parent=None, _root=None):
2393
+ self._io = _io
2394
+ self._parent = _parent
2395
+ self._root = _root if _root else self
2396
+ self._debug = collections.defaultdict(dict)
2397
+
2398
+ def _read(self):
2399
+ self._debug['name']['start'] = self._io.pos()
2400
+ self.name = MachO.LcStr(self._io, self, self._root)
2401
+ self.name._read()
2402
+ self._debug['name']['end'] = self._io.pos()
2403
+
2404
+
2405
+ class DylibCommand(KaitaiStruct):
2406
+ SEQ_FIELDS = ["name_offset", "timestamp", "current_version", "compatibility_version", "name"]
2407
+ def __init__(self, _io, _parent=None, _root=None):
2408
+ self._io = _io
2409
+ self._parent = _parent
2410
+ self._root = _root if _root else self
2411
+ self._debug = collections.defaultdict(dict)
2412
+
2413
+ def _read(self):
2414
+ self._debug['name_offset']['start'] = self._io.pos()
2415
+ self.name_offset = self._io.read_u4le()
2416
+ self._debug['name_offset']['end'] = self._io.pos()
2417
+ self._debug['timestamp']['start'] = self._io.pos()
2418
+ self.timestamp = self._io.read_u4le()
2419
+ self._debug['timestamp']['end'] = self._io.pos()
2420
+ self._debug['current_version']['start'] = self._io.pos()
2421
+ self.current_version = self._io.read_u4le()
2422
+ self._debug['current_version']['end'] = self._io.pos()
2423
+ self._debug['compatibility_version']['start'] = self._io.pos()
2424
+ self.compatibility_version = self._io.read_u4le()
2425
+ self._debug['compatibility_version']['end'] = self._io.pos()
2426
+ self._debug['name']['start'] = self._io.pos()
2427
+ self.name = (self._io.read_bytes_term(0, False, True, True)).decode(u"utf-8")
2428
+ self._debug['name']['end'] = self._io.pos()
2429
+
2430
+
2431
+ class SegmentCommand(KaitaiStruct):
2432
+ SEQ_FIELDS = ["segname", "vmaddr", "vmsize", "fileoff", "filesize", "maxprot", "initprot", "nsects", "flags", "sections"]
2433
+ def __init__(self, _io, _parent=None, _root=None):
2434
+ self._io = _io
2435
+ self._parent = _parent
2436
+ self._root = _root if _root else self
2437
+ self._debug = collections.defaultdict(dict)
2438
+
2439
+ def _read(self):
2440
+ self._debug['segname']['start'] = self._io.pos()
2441
+ self.segname = (KaitaiStream.bytes_strip_right(self._io.read_bytes(16), 0)).decode(u"ascii")
2442
+ self._debug['segname']['end'] = self._io.pos()
2443
+ self._debug['vmaddr']['start'] = self._io.pos()
2444
+ self.vmaddr = self._io.read_u4le()
2445
+ self._debug['vmaddr']['end'] = self._io.pos()
2446
+ self._debug['vmsize']['start'] = self._io.pos()
2447
+ self.vmsize = self._io.read_u4le()
2448
+ self._debug['vmsize']['end'] = self._io.pos()
2449
+ self._debug['fileoff']['start'] = self._io.pos()
2450
+ self.fileoff = self._io.read_u4le()
2451
+ self._debug['fileoff']['end'] = self._io.pos()
2452
+ self._debug['filesize']['start'] = self._io.pos()
2453
+ self.filesize = self._io.read_u4le()
2454
+ self._debug['filesize']['end'] = self._io.pos()
2455
+ self._debug['maxprot']['start'] = self._io.pos()
2456
+ self.maxprot = MachO.VmProt(self._io, self, self._root)
2457
+ self.maxprot._read()
2458
+ self._debug['maxprot']['end'] = self._io.pos()
2459
+ self._debug['initprot']['start'] = self._io.pos()
2460
+ self.initprot = MachO.VmProt(self._io, self, self._root)
2461
+ self.initprot._read()
2462
+ self._debug['initprot']['end'] = self._io.pos()
2463
+ self._debug['nsects']['start'] = self._io.pos()
2464
+ self.nsects = self._io.read_u4le()
2465
+ self._debug['nsects']['end'] = self._io.pos()
2466
+ self._debug['flags']['start'] = self._io.pos()
2467
+ self.flags = self._io.read_u4le()
2468
+ self._debug['flags']['end'] = self._io.pos()
2469
+ self._debug['sections']['start'] = self._io.pos()
2470
+ self.sections = [None] * (self.nsects)
2471
+ for i in range(self.nsects):
2472
+ if not 'arr' in self._debug['sections']:
2473
+ self._debug['sections']['arr'] = []
2474
+ self._debug['sections']['arr'].append({'start': self._io.pos()})
2475
+ _t_sections = MachO.SegmentCommand.Section(self._io, self, self._root)
2476
+ _t_sections._read()
2477
+ self.sections[i] = _t_sections
2478
+ self._debug['sections']['arr'][i]['end'] = self._io.pos()
2479
+
2480
+ self._debug['sections']['end'] = self._io.pos()
2481
+
2482
+ class Section(KaitaiStruct):
2483
+ SEQ_FIELDS = ["sect_name", "seg_name", "addr", "size", "offset", "align", "reloff", "nreloc", "flags", "reserved1", "reserved2"]
2484
+ def __init__(self, _io, _parent=None, _root=None):
2485
+ self._io = _io
2486
+ self._parent = _parent
2487
+ self._root = _root if _root else self
2488
+ self._debug = collections.defaultdict(dict)
2489
+
2490
+ def _read(self):
2491
+ self._debug['sect_name']['start'] = self._io.pos()
2492
+ self.sect_name = (KaitaiStream.bytes_strip_right(self._io.read_bytes(16), 0)).decode(u"ascii")
2493
+ self._debug['sect_name']['end'] = self._io.pos()
2494
+ self._debug['seg_name']['start'] = self._io.pos()
2495
+ self.seg_name = (KaitaiStream.bytes_strip_right(self._io.read_bytes(16), 0)).decode(u"ascii")
2496
+ self._debug['seg_name']['end'] = self._io.pos()
2497
+ self._debug['addr']['start'] = self._io.pos()
2498
+ self.addr = self._io.read_u4le()
2499
+ self._debug['addr']['end'] = self._io.pos()
2500
+ self._debug['size']['start'] = self._io.pos()
2501
+ self.size = self._io.read_u4le()
2502
+ self._debug['size']['end'] = self._io.pos()
2503
+ self._debug['offset']['start'] = self._io.pos()
2504
+ self.offset = self._io.read_u4le()
2505
+ self._debug['offset']['end'] = self._io.pos()
2506
+ self._debug['align']['start'] = self._io.pos()
2507
+ self.align = self._io.read_u4le()
2508
+ self._debug['align']['end'] = self._io.pos()
2509
+ self._debug['reloff']['start'] = self._io.pos()
2510
+ self.reloff = self._io.read_u4le()
2511
+ self._debug['reloff']['end'] = self._io.pos()
2512
+ self._debug['nreloc']['start'] = self._io.pos()
2513
+ self.nreloc = self._io.read_u4le()
2514
+ self._debug['nreloc']['end'] = self._io.pos()
2515
+ self._debug['flags']['start'] = self._io.pos()
2516
+ self.flags = self._io.read_u4le()
2517
+ self._debug['flags']['end'] = self._io.pos()
2518
+ self._debug['reserved1']['start'] = self._io.pos()
2519
+ self.reserved1 = self._io.read_u4le()
2520
+ self._debug['reserved1']['end'] = self._io.pos()
2521
+ self._debug['reserved2']['start'] = self._io.pos()
2522
+ self.reserved2 = self._io.read_u4le()
2523
+ self._debug['reserved2']['end'] = self._io.pos()
2524
+
2525
+ @property
2526
+ def data(self):
2527
+ if hasattr(self, '_m_data'):
2528
+ return self._m_data if hasattr(self, '_m_data') else None
2529
+
2530
+ io = self._root._io
2531
+ _pos = io.pos()
2532
+ io.seek(self.offset)
2533
+ self._debug['_m_data']['start'] = io.pos()
2534
+ self._m_data = io.read_bytes(self.size)
2535
+ self._debug['_m_data']['end'] = io.pos()
2536
+ io.seek(_pos)
2537
+ return self._m_data if hasattr(self, '_m_data') else None
2538
+
2539
+
2540
+
2541
+ class LcStr(KaitaiStruct):
2542
+ SEQ_FIELDS = ["length", "value"]
2543
+ def __init__(self, _io, _parent=None, _root=None):
2544
+ self._io = _io
2545
+ self._parent = _parent
2546
+ self._root = _root if _root else self
2547
+ self._debug = collections.defaultdict(dict)
2548
+
2549
+ def _read(self):
2550
+ self._debug['length']['start'] = self._io.pos()
2551
+ self.length = self._io.read_u4le()
2552
+ self._debug['length']['end'] = self._io.pos()
2553
+ self._debug['value']['start'] = self._io.pos()
2554
+ self.value = (self._io.read_bytes_term(0, False, True, True)).decode(u"UTF-8")
2555
+ self._debug['value']['end'] = self._io.pos()
2556
+
2557
+
2558
+ class LoadCommand(KaitaiStruct):
2559
+ SEQ_FIELDS = ["type", "size", "body"]
2560
+ def __init__(self, _io, _parent=None, _root=None):
2561
+ self._io = _io
2562
+ self._parent = _parent
2563
+ self._root = _root if _root else self
2564
+ self._debug = collections.defaultdict(dict)
2565
+
2566
+ def _read(self):
2567
+ self._debug['type']['start'] = self._io.pos()
2568
+ self.type = KaitaiStream.resolve_enum(MachO.LoadCommandType, self._io.read_u4le())
2569
+ self._debug['type']['end'] = self._io.pos()
2570
+ self._debug['size']['start'] = self._io.pos()
2571
+ self.size = self._io.read_u4le()
2572
+ self._debug['size']['end'] = self._io.pos()
2573
+ self._debug['body']['start'] = self._io.pos()
2574
+ _on = self.type
2575
+ if _on == MachO.LoadCommandType.id_dylinker:
2576
+ self._raw_body = self._io.read_bytes((self.size - 8))
2577
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2578
+ self.body = MachO.DylinkerCommand(_io__raw_body, self, self._root)
2579
+ self.body._read()
2580
+ elif _on == MachO.LoadCommandType.reexport_dylib:
2581
+ self._raw_body = self._io.read_bytes((self.size - 8))
2582
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2583
+ self.body = MachO.DylibCommand(_io__raw_body, self, self._root)
2584
+ self.body._read()
2585
+ elif _on == MachO.LoadCommandType.build_version:
2586
+ self._raw_body = self._io.read_bytes((self.size - 8))
2587
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2588
+ self.body = MachO.BuildVersionCommand(_io__raw_body, self, self._root)
2589
+ self.body._read()
2590
+ elif _on == MachO.LoadCommandType.source_version:
2591
+ self._raw_body = self._io.read_bytes((self.size - 8))
2592
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2593
+ self.body = MachO.SourceVersionCommand(_io__raw_body, self, self._root)
2594
+ self.body._read()
2595
+ elif _on == MachO.LoadCommandType.function_starts:
2596
+ self._raw_body = self._io.read_bytes((self.size - 8))
2597
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2598
+ self.body = MachO.LinkeditDataCommand(_io__raw_body, self, self._root)
2599
+ self.body._read()
2600
+ elif _on == MachO.LoadCommandType.rpath:
2601
+ self._raw_body = self._io.read_bytes((self.size - 8))
2602
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2603
+ self.body = MachO.RpathCommand(_io__raw_body, self, self._root)
2604
+ self.body._read()
2605
+ elif _on == MachO.LoadCommandType.sub_framework:
2606
+ self._raw_body = self._io.read_bytes((self.size - 8))
2607
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2608
+ self.body = MachO.SubCommand(_io__raw_body, self, self._root)
2609
+ self.body._read()
2610
+ elif _on == MachO.LoadCommandType.routines:
2611
+ self._raw_body = self._io.read_bytes((self.size - 8))
2612
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2613
+ self.body = MachO.RoutinesCommand(_io__raw_body, self, self._root)
2614
+ self.body._read()
2615
+ elif _on == MachO.LoadCommandType.sub_library:
2616
+ self._raw_body = self._io.read_bytes((self.size - 8))
2617
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2618
+ self.body = MachO.SubCommand(_io__raw_body, self, self._root)
2619
+ self.body._read()
2620
+ elif _on == MachO.LoadCommandType.dyld_info_only:
2621
+ self._raw_body = self._io.read_bytes((self.size - 8))
2622
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2623
+ self.body = MachO.DyldInfoCommand(_io__raw_body, self, self._root)
2624
+ self.body._read()
2625
+ elif _on == MachO.LoadCommandType.dyld_environment:
2626
+ self._raw_body = self._io.read_bytes((self.size - 8))
2627
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2628
+ self.body = MachO.DylinkerCommand(_io__raw_body, self, self._root)
2629
+ self.body._read()
2630
+ elif _on == MachO.LoadCommandType.load_dylinker:
2631
+ self._raw_body = self._io.read_bytes((self.size - 8))
2632
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2633
+ self.body = MachO.DylinkerCommand(_io__raw_body, self, self._root)
2634
+ self.body._read()
2635
+ elif _on == MachO.LoadCommandType.segment_split_info:
2636
+ self._raw_body = self._io.read_bytes((self.size - 8))
2637
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2638
+ self.body = MachO.LinkeditDataCommand(_io__raw_body, self, self._root)
2639
+ self.body._read()
2640
+ elif _on == MachO.LoadCommandType.main:
2641
+ self._raw_body = self._io.read_bytes((self.size - 8))
2642
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2643
+ self.body = MachO.EntryPointCommand(_io__raw_body, self, self._root)
2644
+ self.body._read()
2645
+ elif _on == MachO.LoadCommandType.load_dylib:
2646
+ self._raw_body = self._io.read_bytes((self.size - 8))
2647
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2648
+ self.body = MachO.DylibCommand(_io__raw_body, self, self._root)
2649
+ self.body._read()
2650
+ elif _on == MachO.LoadCommandType.encryption_info:
2651
+ self._raw_body = self._io.read_bytes((self.size - 8))
2652
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2653
+ self.body = MachO.EncryptionInfoCommand(_io__raw_body, self, self._root)
2654
+ self.body._read()
2655
+ elif _on == MachO.LoadCommandType.dysymtab:
2656
+ self._raw_body = self._io.read_bytes((self.size - 8))
2657
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2658
+ self.body = MachO.DysymtabCommand(_io__raw_body, self, self._root)
2659
+ self.body._read()
2660
+ elif _on == MachO.LoadCommandType.twolevel_hints:
2661
+ self._raw_body = self._io.read_bytes((self.size - 8))
2662
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2663
+ self.body = MachO.TwolevelHintsCommand(_io__raw_body, self, self._root)
2664
+ self.body._read()
2665
+ elif _on == MachO.LoadCommandType.encryption_info_64:
2666
+ self._raw_body = self._io.read_bytes((self.size - 8))
2667
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2668
+ self.body = MachO.EncryptionInfoCommand(_io__raw_body, self, self._root)
2669
+ self.body._read()
2670
+ elif _on == MachO.LoadCommandType.linker_option:
2671
+ self._raw_body = self._io.read_bytes((self.size - 8))
2672
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2673
+ self.body = MachO.LinkerOptionCommand(_io__raw_body, self, self._root)
2674
+ self.body._read()
2675
+ elif _on == MachO.LoadCommandType.dyld_info:
2676
+ self._raw_body = self._io.read_bytes((self.size - 8))
2677
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2678
+ self.body = MachO.DyldInfoCommand(_io__raw_body, self, self._root)
2679
+ self.body._read()
2680
+ elif _on == MachO.LoadCommandType.version_min_tvos:
2681
+ self._raw_body = self._io.read_bytes((self.size - 8))
2682
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2683
+ self.body = MachO.VersionMinCommand(_io__raw_body, self, self._root)
2684
+ self.body._read()
2685
+ elif _on == MachO.LoadCommandType.load_upward_dylib:
2686
+ self._raw_body = self._io.read_bytes((self.size - 8))
2687
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2688
+ self.body = MachO.DylibCommand(_io__raw_body, self, self._root)
2689
+ self.body._read()
2690
+ elif _on == MachO.LoadCommandType.segment_64:
2691
+ self._raw_body = self._io.read_bytes((self.size - 8))
2692
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2693
+ self.body = MachO.SegmentCommand64(_io__raw_body, self, self._root)
2694
+ self.body._read()
2695
+ elif _on == MachO.LoadCommandType.segment:
2696
+ self._raw_body = self._io.read_bytes((self.size - 8))
2697
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2698
+ self.body = MachO.SegmentCommand(_io__raw_body, self, self._root)
2699
+ self.body._read()
2700
+ elif _on == MachO.LoadCommandType.sub_umbrella:
2701
+ self._raw_body = self._io.read_bytes((self.size - 8))
2702
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2703
+ self.body = MachO.SubCommand(_io__raw_body, self, self._root)
2704
+ self.body._read()
2705
+ elif _on == MachO.LoadCommandType.version_min_watchos:
2706
+ self._raw_body = self._io.read_bytes((self.size - 8))
2707
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2708
+ self.body = MachO.VersionMinCommand(_io__raw_body, self, self._root)
2709
+ self.body._read()
2710
+ elif _on == MachO.LoadCommandType.routines_64:
2711
+ self._raw_body = self._io.read_bytes((self.size - 8))
2712
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2713
+ self.body = MachO.RoutinesCommand64(_io__raw_body, self, self._root)
2714
+ self.body._read()
2715
+ elif _on == MachO.LoadCommandType.id_dylib:
2716
+ self._raw_body = self._io.read_bytes((self.size - 8))
2717
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2718
+ self.body = MachO.DylibCommand(_io__raw_body, self, self._root)
2719
+ self.body._read()
2720
+ elif _on == MachO.LoadCommandType.sub_client:
2721
+ self._raw_body = self._io.read_bytes((self.size - 8))
2722
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2723
+ self.body = MachO.SubCommand(_io__raw_body, self, self._root)
2724
+ self.body._read()
2725
+ elif _on == MachO.LoadCommandType.dylib_code_sign_drs:
2726
+ self._raw_body = self._io.read_bytes((self.size - 8))
2727
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2728
+ self.body = MachO.LinkeditDataCommand(_io__raw_body, self, self._root)
2729
+ self.body._read()
2730
+ elif _on == MachO.LoadCommandType.symtab:
2731
+ self._raw_body = self._io.read_bytes((self.size - 8))
2732
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2733
+ self.body = MachO.SymtabCommand(_io__raw_body, self, self._root)
2734
+ self.body._read()
2735
+ elif _on == MachO.LoadCommandType.linker_optimization_hint:
2736
+ self._raw_body = self._io.read_bytes((self.size - 8))
2737
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2738
+ self.body = MachO.LinkeditDataCommand(_io__raw_body, self, self._root)
2739
+ self.body._read()
2740
+ elif _on == MachO.LoadCommandType.data_in_code:
2741
+ self._raw_body = self._io.read_bytes((self.size - 8))
2742
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2743
+ self.body = MachO.LinkeditDataCommand(_io__raw_body, self, self._root)
2744
+ self.body._read()
2745
+ elif _on == MachO.LoadCommandType.code_signature:
2746
+ self._raw_body = self._io.read_bytes((self.size - 8))
2747
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2748
+ self.body = MachO.CodeSignatureCommand(_io__raw_body, self, self._root)
2749
+ self.body._read()
2750
+ elif _on == MachO.LoadCommandType.version_min_iphoneos:
2751
+ self._raw_body = self._io.read_bytes((self.size - 8))
2752
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2753
+ self.body = MachO.VersionMinCommand(_io__raw_body, self, self._root)
2754
+ self.body._read()
2755
+ elif _on == MachO.LoadCommandType.load_weak_dylib:
2756
+ self._raw_body = self._io.read_bytes((self.size - 8))
2757
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2758
+ self.body = MachO.DylibCommand(_io__raw_body, self, self._root)
2759
+ self.body._read()
2760
+ elif _on == MachO.LoadCommandType.lazy_load_dylib:
2761
+ self._raw_body = self._io.read_bytes((self.size - 8))
2762
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2763
+ self.body = MachO.DylibCommand(_io__raw_body, self, self._root)
2764
+ self.body._read()
2765
+ elif _on == MachO.LoadCommandType.uuid:
2766
+ self._raw_body = self._io.read_bytes((self.size - 8))
2767
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2768
+ self.body = MachO.UuidCommand(_io__raw_body, self, self._root)
2769
+ self.body._read()
2770
+ elif _on == MachO.LoadCommandType.version_min_macosx:
2771
+ self._raw_body = self._io.read_bytes((self.size - 8))
2772
+ _io__raw_body = KaitaiStream(BytesIO(self._raw_body))
2773
+ self.body = MachO.VersionMinCommand(_io__raw_body, self, self._root)
2774
+ self.body._read()
2775
+ else:
2776
+ self.body = self._io.read_bytes((self.size - 8))
2777
+ self._debug['body']['end'] = self._io.pos()
2778
+
2779
+
2780
+ class UuidCommand(KaitaiStruct):
2781
+ SEQ_FIELDS = ["uuid"]
2782
+ def __init__(self, _io, _parent=None, _root=None):
2783
+ self._io = _io
2784
+ self._parent = _parent
2785
+ self._root = _root if _root else self
2786
+ self._debug = collections.defaultdict(dict)
2787
+
2788
+ def _read(self):
2789
+ self._debug['uuid']['start'] = self._io.pos()
2790
+ self.uuid = self._io.read_bytes(16)
2791
+ self._debug['uuid']['end'] = self._io.pos()
2792
+
2793
+
2794
+ class SymtabCommand(KaitaiStruct):
2795
+ SEQ_FIELDS = ["sym_off", "n_syms", "str_off", "str_size"]
2796
+ def __init__(self, _io, _parent=None, _root=None):
2797
+ self._io = _io
2798
+ self._parent = _parent
2799
+ self._root = _root if _root else self
2800
+ self._debug = collections.defaultdict(dict)
2801
+
2802
+ def _read(self):
2803
+ self._debug['sym_off']['start'] = self._io.pos()
2804
+ self.sym_off = self._io.read_u4le()
2805
+ self._debug['sym_off']['end'] = self._io.pos()
2806
+ self._debug['n_syms']['start'] = self._io.pos()
2807
+ self.n_syms = self._io.read_u4le()
2808
+ self._debug['n_syms']['end'] = self._io.pos()
2809
+ self._debug['str_off']['start'] = self._io.pos()
2810
+ self.str_off = self._io.read_u4le()
2811
+ self._debug['str_off']['end'] = self._io.pos()
2812
+ self._debug['str_size']['start'] = self._io.pos()
2813
+ self.str_size = self._io.read_u4le()
2814
+ self._debug['str_size']['end'] = self._io.pos()
2815
+
2816
+ class StrTable(KaitaiStruct):
2817
+ SEQ_FIELDS = ["unknown", "items"]
2818
+ def __init__(self, _io, _parent=None, _root=None):
2819
+ self._io = _io
2820
+ self._parent = _parent
2821
+ self._root = _root if _root else self
2822
+ self._debug = collections.defaultdict(dict)
2823
+
2824
+ def _read(self):
2825
+ self._debug['unknown']['start'] = self._io.pos()
2826
+ self.unknown = self._io.read_u4le()
2827
+ self._debug['unknown']['end'] = self._io.pos()
2828
+ self._debug['items']['start'] = self._io.pos()
2829
+ self.items = []
2830
+ i = 0
2831
+ while True:
2832
+ if not 'arr' in self._debug['items']:
2833
+ self._debug['items']['arr'] = []
2834
+ self._debug['items']['arr'].append({'start': self._io.pos()})
2835
+ _ = (self._io.read_bytes_term(0, False, True, False)).decode(u"utf-8")
2836
+ self.items.append(_)
2837
+ self._debug['items']['arr'][len(self.items) - 1]['end'] = self._io.pos()
2838
+ if _ == u"":
2839
+ break
2840
+ i += 1
2841
+ self._debug['items']['end'] = self._io.pos()
2842
+
2843
+
2844
+ class Nlist64(KaitaiStruct):
2845
+ SEQ_FIELDS = ["un", "type", "sect", "desc", "value"]
2846
+ def __init__(self, _io, _parent=None, _root=None):
2847
+ self._io = _io
2848
+ self._parent = _parent
2849
+ self._root = _root if _root else self
2850
+ self._debug = collections.defaultdict(dict)
2851
+
2852
+ def _read(self):
2853
+ self._debug['un']['start'] = self._io.pos()
2854
+ self.un = self._io.read_u4le()
2855
+ self._debug['un']['end'] = self._io.pos()
2856
+ self._debug['type']['start'] = self._io.pos()
2857
+ self.type = self._io.read_u1()
2858
+ self._debug['type']['end'] = self._io.pos()
2859
+ self._debug['sect']['start'] = self._io.pos()
2860
+ self.sect = self._io.read_u1()
2861
+ self._debug['sect']['end'] = self._io.pos()
2862
+ self._debug['desc']['start'] = self._io.pos()
2863
+ self.desc = self._io.read_u2le()
2864
+ self._debug['desc']['end'] = self._io.pos()
2865
+ self._debug['value']['start'] = self._io.pos()
2866
+ self.value = self._io.read_u8le()
2867
+ self._debug['value']['end'] = self._io.pos()
2868
+
2869
+ @property
2870
+ def name(self):
2871
+ if hasattr(self, '_m_name'):
2872
+ return self._m_name if hasattr(self, '_m_name') else None
2873
+
2874
+ if self.un != 0:
2875
+ _pos = self._io.pos()
2876
+ self._io.seek((self._parent.str_off + self.un))
2877
+ self._debug['_m_name']['start'] = self._io.pos()
2878
+ self._m_name = (self._io.read_bytes_term(0, False, True, True)).decode(u"utf-8")
2879
+ self._debug['_m_name']['end'] = self._io.pos()
2880
+ self._io.seek(_pos)
2881
+
2882
+ return self._m_name if hasattr(self, '_m_name') else None
2883
+
2884
+
2885
+ class Nlist(KaitaiStruct):
2886
+ SEQ_FIELDS = ["un", "type", "sect", "desc", "value"]
2887
+ def __init__(self, _io, _parent=None, _root=None):
2888
+ self._io = _io
2889
+ self._parent = _parent
2890
+ self._root = _root if _root else self
2891
+ self._debug = collections.defaultdict(dict)
2892
+
2893
+ def _read(self):
2894
+ self._debug['un']['start'] = self._io.pos()
2895
+ self.un = self._io.read_u4le()
2896
+ self._debug['un']['end'] = self._io.pos()
2897
+ self._debug['type']['start'] = self._io.pos()
2898
+ self.type = self._io.read_u1()
2899
+ self._debug['type']['end'] = self._io.pos()
2900
+ self._debug['sect']['start'] = self._io.pos()
2901
+ self.sect = self._io.read_u1()
2902
+ self._debug['sect']['end'] = self._io.pos()
2903
+ self._debug['desc']['start'] = self._io.pos()
2904
+ self.desc = self._io.read_u2le()
2905
+ self._debug['desc']['end'] = self._io.pos()
2906
+ self._debug['value']['start'] = self._io.pos()
2907
+ self.value = self._io.read_u4le()
2908
+ self._debug['value']['end'] = self._io.pos()
2909
+
2910
+ @property
2911
+ def name(self):
2912
+ if hasattr(self, '_m_name'):
2913
+ return self._m_name if hasattr(self, '_m_name') else None
2914
+
2915
+ if self.un != 0:
2916
+ _pos = self._io.pos()
2917
+ self._io.seek((self._parent.str_off + self.un))
2918
+ self._debug['_m_name']['start'] = self._io.pos()
2919
+ self._m_name = (self._io.read_bytes_term(0, False, True, True)).decode(u"utf-8")
2920
+ self._debug['_m_name']['end'] = self._io.pos()
2921
+ self._io.seek(_pos)
2922
+
2923
+ return self._m_name if hasattr(self, '_m_name') else None
2924
+
2925
+
2926
+ @property
2927
+ def symbols(self):
2928
+ if hasattr(self, '_m_symbols'):
2929
+ return self._m_symbols if hasattr(self, '_m_symbols') else None
2930
+
2931
+ io = self._root._io
2932
+ _pos = io.pos()
2933
+ io.seek(self.sym_off)
2934
+ self._debug['_m_symbols']['start'] = io.pos()
2935
+ self._m_symbols = [None] * (self.n_syms)
2936
+ for i in range(self.n_syms):
2937
+ if not 'arr' in self._debug['_m_symbols']:
2938
+ self._debug['_m_symbols']['arr'] = []
2939
+ self._debug['_m_symbols']['arr'].append({'start': io.pos()})
2940
+ _on = self._root.magic
2941
+ if _on == MachO.MagicType.macho_le_x64:
2942
+ if not 'arr' in self._debug['_m_symbols']:
2943
+ self._debug['_m_symbols']['arr'] = []
2944
+ self._debug['_m_symbols']['arr'].append({'start': io.pos()})
2945
+ _t__m_symbols = MachO.SymtabCommand.Nlist64(io, self, self._root)
2946
+ _t__m_symbols._read()
2947
+ self._m_symbols[i] = _t__m_symbols
2948
+ self._debug['_m_symbols']['arr'][i]['end'] = io.pos()
2949
+ elif _on == MachO.MagicType.macho_be_x64:
2950
+ if not 'arr' in self._debug['_m_symbols']:
2951
+ self._debug['_m_symbols']['arr'] = []
2952
+ self._debug['_m_symbols']['arr'].append({'start': io.pos()})
2953
+ _t__m_symbols = MachO.SymtabCommand.Nlist64(io, self, self._root)
2954
+ _t__m_symbols._read()
2955
+ self._m_symbols[i] = _t__m_symbols
2956
+ self._debug['_m_symbols']['arr'][i]['end'] = io.pos()
2957
+ elif _on == MachO.MagicType.macho_le_x86:
2958
+ if not 'arr' in self._debug['_m_symbols']:
2959
+ self._debug['_m_symbols']['arr'] = []
2960
+ self._debug['_m_symbols']['arr'].append({'start': io.pos()})
2961
+ _t__m_symbols = MachO.SymtabCommand.Nlist(io, self, self._root)
2962
+ _t__m_symbols._read()
2963
+ self._m_symbols[i] = _t__m_symbols
2964
+ self._debug['_m_symbols']['arr'][i]['end'] = io.pos()
2965
+ elif _on == MachO.MagicType.macho_be_x86:
2966
+ if not 'arr' in self._debug['_m_symbols']:
2967
+ self._debug['_m_symbols']['arr'] = []
2968
+ self._debug['_m_symbols']['arr'].append({'start': io.pos()})
2969
+ _t__m_symbols = MachO.SymtabCommand.Nlist(io, self, self._root)
2970
+ _t__m_symbols._read()
2971
+ self._m_symbols[i] = _t__m_symbols
2972
+ self._debug['_m_symbols']['arr'][i]['end'] = io.pos()
2973
+ self._debug['_m_symbols']['arr'][i]['end'] = io.pos()
2974
+
2975
+ self._debug['_m_symbols']['end'] = io.pos()
2976
+ io.seek(_pos)
2977
+ return self._m_symbols if hasattr(self, '_m_symbols') else None
2978
+
2979
+ @property
2980
+ def strs(self):
2981
+ if hasattr(self, '_m_strs'):
2982
+ return self._m_strs if hasattr(self, '_m_strs') else None
2983
+
2984
+ io = self._root._io
2985
+ _pos = io.pos()
2986
+ io.seek(self.str_off)
2987
+ self._debug['_m_strs']['start'] = io.pos()
2988
+ self._raw__m_strs = io.read_bytes(self.str_size)
2989
+ _io__raw__m_strs = KaitaiStream(BytesIO(self._raw__m_strs))
2990
+ self._m_strs = MachO.SymtabCommand.StrTable(_io__raw__m_strs, self, self._root)
2991
+ self._m_strs._read()
2992
+ self._debug['_m_strs']['end'] = io.pos()
2993
+ io.seek(_pos)
2994
+ return self._m_strs if hasattr(self, '_m_strs') else None
2995
+
2996
+
2997
+ class VersionMinCommand(KaitaiStruct):
2998
+ SEQ_FIELDS = ["version", "sdk"]
2999
+ def __init__(self, _io, _parent=None, _root=None):
3000
+ self._io = _io
3001
+ self._parent = _parent
3002
+ self._root = _root if _root else self
3003
+ self._debug = collections.defaultdict(dict)
3004
+
3005
+ def _read(self):
3006
+ self._debug['version']['start'] = self._io.pos()
3007
+ self.version = MachO.Version(self._io, self, self._root)
3008
+ self.version._read()
3009
+ self._debug['version']['end'] = self._io.pos()
3010
+ self._debug['sdk']['start'] = self._io.pos()
3011
+ self.sdk = MachO.Version(self._io, self, self._root)
3012
+ self.sdk._read()
3013
+ self._debug['sdk']['end'] = self._io.pos()
3014
+
3015
+
3016
+ class EntryPointCommand(KaitaiStruct):
3017
+ SEQ_FIELDS = ["entry_off", "stack_size"]
3018
+ def __init__(self, _io, _parent=None, _root=None):
3019
+ self._io = _io
3020
+ self._parent = _parent
3021
+ self._root = _root if _root else self
3022
+ self._debug = collections.defaultdict(dict)
3023
+
3024
+ def _read(self):
3025
+ self._debug['entry_off']['start'] = self._io.pos()
3026
+ self.entry_off = self._io.read_u8le()
3027
+ self._debug['entry_off']['end'] = self._io.pos()
3028
+ self._debug['stack_size']['start'] = self._io.pos()
3029
+ self.stack_size = self._io.read_u8le()
3030
+ self._debug['stack_size']['end'] = self._io.pos()
3031
+
3032
+
3033
+