NAME=mach0 headers
FILE=bins/mach0/hello-osx-i386
CMDS=iH
EXPECT=<<EOF
pf.mach0_header @ 0x00001000
0x00001000  Magic       0xfeedface
0x00001004  CpuType     0x7
0x00001008  CpuSubType  0x3
0x0000100c  FileType    0x2
0x00001010  nCmds       11
0x00001014  sizeOfCmds  1172
0x00001018  Flags       0x85
pf.mach0_segment @ 0x0000101c
0x0000101c  cmd       0 0x1 LC_SEGMENT
0x00001020  cmdsize     56
0x00001024  name        __PAGEZERO
pf.mach0_segment @ 0x00001054
0x00001054  cmd       1 0x1 LC_SEGMENT
0x00001058  cmdsize     396
0x0000105c  name        __TEXT
pf.mach0_section @ 0x0000108c
pf.mach0_section @ 0x000010d0
pf.mach0_section @ 0x00001114
pf.mach0_section @ 0x00001158
pf.mach0_section @ 0x0000119c
pf.mach0_segment @ 0x000011e0
0x000011e0  cmd       2 0x1 LC_SEGMENT
0x000011e4  cmdsize     328
0x000011e8  name        __DATA
pf.mach0_section @ 0x00001218
pf.mach0_section @ 0x0000125c
pf.mach0_section @ 0x000012a0
pf.mach0_section @ 0x000012e4
pf.mach0_segment @ 0x00001328
0x00001328  cmd       3 0x1 LC_SEGMENT
0x0000132c  cmdsize     56
0x00001330  name        __LINKEDIT
pf.mach0_dyld_info_only_command @ 0x00001360
0x00001360  cmd       4 0x80000022 LC_DYLD_INFO_ONLY
0x00001364  cmdsize     48
pf.mach0_symtab_command @ 0x00001390
0x00001390  cmd       5 0x2 LC_SYMTAB
0x00001394  cmdsize     24
pf.mach0_dysymtab_command @ 0x000013a8
0x000013a8  cmd       6 0xb LC_DYSYMTAB
0x000013ac  cmdsize     80
pf.mach0_load_dylinker_command @ 0x000013f8
0x000013f8  cmd       7 0xe LC_LOAD_DYLINKER
0x000013fc  cmdsize     28
pf.mach0_uuid_command @ 0x00001414
0x00001414  cmd       8 0x1b LC_UUID
0x00001418  cmdsize     24
0x0000141c  uuid        2310026f6db717b4a9d7d991a5a686ff
pf.mach0_unixthread_command @ 0x0000142c
0x0000142c  cmd       9 0x5 LC_UNIXTHREAD
0x00001430  cmdsize     80
pf.mach0_dylib_command @ 0x0000147c
0x0000147c  cmd      10 0xc LC_LOAD_DYLIB
0x00001480  cmdsize     52
0x0000148c  current     125.2.10
0x00001490  compat      1.0.0
0x00001494  load_dylib  /usr/lib/libSystem.B.dylib
EOF
RUN

NAME=mach0 headers big-endian
FILE=bins/mach0/ppc-ls
CMDS=iH
EXPECT=<<EOF
pf.mach0_header @ 0x00001000
0x00001000  Magic       0xfeedface
0x00001004  CpuType     0x12
0x00001008  CpuSubType  0x0
0x0000100c  FileType    0x2
0x00001010  nCmds       11
0x00001014  sizeOfCmds  1608
0x00001018  Flags       0x85
pf.mach0_segment @ 0x0000101c
0x0000101c  cmd       0 0x1 LC_SEGMENT
0x00001020  cmdsize     56
0x00001024  name        __PAGEZERO
pf.mach0_segment @ 0x00001054
0x00001054  cmd       1 0x1 LC_SEGMENT
0x00001058  cmdsize     600
0x0000105c  name        __TEXT
pf.mach0_section @ 0x0000108c
pf.mach0_section @ 0x000010d0
pf.mach0_section @ 0x00001114
pf.mach0_section @ 0x00001158
pf.mach0_section @ 0x0000119c
pf.mach0_section @ 0x000011e0
pf.mach0_section @ 0x00001224
pf.mach0_section @ 0x00001268
pf.mach0_segment @ 0x000012ac
0x000012ac  cmd       2 0x1 LC_SEGMENT
0x000012b0  cmdsize     464
0x000012b4  name        __DATA
pf.mach0_section @ 0x000012e4
pf.mach0_section @ 0x00001328
pf.mach0_section @ 0x0000136c
pf.mach0_section @ 0x000013b0
pf.mach0_section @ 0x000013f4
pf.mach0_section @ 0x00001438
pf.mach0_segment @ 0x0000147c
0x0000147c  cmd       3 0x1 LC_SEGMENT
0x00001480  cmdsize     56
0x00001484  name        __LINKEDIT
pf.mach0_load_dylinker_command @ 0x000014b4
0x000014b4  cmd       4 0xe LC_LOAD_DYLINKER
0x000014b8  cmdsize     28
pf.mach0_dylib_command @ 0x000014d0
0x000014d0  cmd       5 0xc LC_LOAD_DYLIB
0x000014d4  cmdsize     56
0x000014e0  current     4.5.0
0x000014e4  compat      4.5.0
0x000014e8  load_dylib  /usr/lib/libncurses.5.4.dylib
pf.mach0_dylib_command @ 0x00001508
0x00001508  cmd       6 0xc LC_LOAD_DYLIB
0x0000150c  cmdsize     52
0x00001518  current     0.88.0
0x0000151c  compat      0.1.0
0x00001520  load_dylib  /usr/lib/libSystem.B.dylib
pf.mach0_symtab_command @ 0x0000153c
0x0000153c  cmd       7 0x2 LC_SYMTAB
0x00001540  cmdsize     24
pf.mach0_dysymtab_command @ 0x00001554
0x00001554  cmd       8 0xb LC_DYSYMTAB
0x00001558  cmdsize     80
0x000015a4  cmd       9 0x16 LC_TWOLEVEL_HINTS
0x000015a8  cmdsize     16
pf.mach0_unixthread_command @ 0x000015b4
0x000015b4  cmd      10 0x5 LC_UNIXTHREAD
0x000015b8  cmdsize     176
EOF
RUN

NAME=mach0 headers2
FILE=bins/mach0/ired
ARGS=-aarm -b32
CMDS=iH
EXPECT=<<EOF
pf.mach0_header @ 0x00004000
0x00004000  Magic       0xfeedface
0x00004004  CpuType     0xc
0x00004008  CpuSubType  0x9
0x0000400c  FileType    0x2
0x00004010  nCmds       17
0x00004014  sizeOfCmds  1148
0x00004018  Flags       0x200085
pf.mach0_segment @ 0x0000401c
0x0000401c  cmd       0 0x1 LC_SEGMENT
0x00004020  cmdsize     56
0x00004024  name        __PAGEZERO
pf.mach0_segment @ 0x00004054
0x00004054  cmd       1 0x1 LC_SEGMENT
0x00004058  cmdsize     328
0x0000405c  name        __TEXT
pf.mach0_section @ 0x0000408c
pf.mach0_section @ 0x000040d0
pf.mach0_section @ 0x00004114
pf.mach0_section @ 0x00004158
pf.mach0_segment @ 0x0000419c
0x0000419c  cmd       2 0x1 LC_SEGMENT
0x000041a0  cmdsize     328
0x000041a4  name        __DATA
pf.mach0_section @ 0x000041d4
pf.mach0_section @ 0x00004218
pf.mach0_section @ 0x0000425c
pf.mach0_section @ 0x000042a0
pf.mach0_segment @ 0x000042e4
0x000042e4  cmd       3 0x1 LC_SEGMENT
0x000042e8  cmdsize     56
0x000042ec  name        __LINKEDIT
pf.mach0_dyld_info_only_command @ 0x0000431c
0x0000431c  cmd       4 0x80000022 LC_DYLD_INFO_ONLY
0x00004320  cmdsize     48
pf.mach0_symtab_command @ 0x0000434c
0x0000434c  cmd       5 0x2 LC_SYMTAB
0x00004350  cmdsize     24
pf.mach0_dysymtab_command @ 0x00004364
0x00004364  cmd       6 0xb LC_DYSYMTAB
0x00004368  cmdsize     80
pf.mach0_load_dylinker_command @ 0x000043b4
0x000043b4  cmd       7 0xe LC_LOAD_DYLINKER
0x000043b8  cmdsize     28
pf.mach0_uuid_command @ 0x000043d0
0x000043d0  cmd       8 0x1b LC_UUID
0x000043d4  cmdsize     24
0x000043d8  uuid        ef8520a2ad483e1aa0e38b60d92c1dc8
pf.mach0_version_min_command @ 0x000043e8
0x000043e8  cmd       9 0x25 LC_VERSION_MIN_IPHONEOS
0x000043ec  cmdsize     16
pf.mach0_source_version_command @ 0x000043f8
0x000043f8  cmd      10 0x2a LC_SOURCE_VERSION
0x000043fc  cmdsize     16
pf.mach0_entry_point_command @ 0x00004408
0x00004408  cmd      11 0x80000028 LC_MAIN
0x0000440c  cmdsize     24
0x00004410  entry0      0x4da9
0x00004414  stacksize   0x0
pf.mach0_encryption_info_command @ 0x00004420
0x00004420  cmd      12 0x21 LC_ENCRYPTION_INFO
0x00004424  cmdsize     20
0x00004428  cryptoff   0x00004000
0x0000442c  cryptsize  16384
0x00004430  cryptid    0
pf.mach0_dylib_command @ 0x00004434
0x00004434  cmd      13 0xc LC_LOAD_DYLIB
0x00004438  cmdsize     52
0x00004444  current     1214.5.1
0x00004448  compat      1.0.0
0x0000444c  load_dylib  /usr/lib/libSystem.B.dylib
pf.mach0_function_starts_command @ 0x00004468
0x00004468  cmd      14 0x26 LC_FUNCTION_STARTS
0x0000446c  cmdsize     16
pf.mach0_data_in_code_command @ 0x00004478
0x00004478  cmd      15 0x29 LC_DATA_IN_CODE
0x0000447c  cmdsize     16
0x00004488  cmd      16 0x2b LC_DYLIB_CODE_SIGN_DRS
0x0000448c  cmdsize     16
EOF
RUN

NAME=mach0 entrypoint
FILE=bins/mach0/hello-osx-i386
CMDS=ie~addr
EXPECT=<<EOF
vaddr=0x00001f14 paddr=0x00000f14 haddr=0x00000464 type=program
EOF
RUN

NAME=mach0 entry0 data
FILE=bins/mach0/hello-osx-i386
CMDS=p8 10 @ entry0
EXPECT=<<EOF
6a0089e583e4f083ec10
EOF
RUN

NAME=mach0 entrypoint i386 LC_MAIN
FILE=bins/mach0/mach0-i386
CMDS=ie~addr
EXPECT=<<EOF
vaddr=0x00001f80 paddr=0x00000f80 haddr=0x00000240 type=program
EOF
RUN

NAME=mach0 entrypoint x86_64 LC_MAIN
FILE=bins/mach0/mach0_2-x86_64
CMDS=ie~addr
EXPECT=<<EOF
vaddr=0x100000f70 paddr=0x00000f70 haddr=0x000002e0 type=program
EOF
RUN

NAME=osx mach0 entrypoint
FILE=bins/mach0/ls-osx-x86_64
CMDS=ie~addr
EXPECT=<<EOF
vaddr=0x1000013d8 paddr=0x000013d8 haddr=0x00000648 type=program
EOF
RUN

NAME=osx mach0 ik
FILE=bins/mach0/ls-osx-x86_64
CMDS=ik ***~uuid
EXPECT=<<EOF
info/mach0_uuid_command.format=[4]Ed[16]b (mach0_load_command_type)cmd cmdsize uuid
info/mach0_cmd_8.format=mach0_uuid_command
info/uuid.0=ff4d6c2e1dc0369d98d0d3040a8049e8
info/mach0_cmd_8.cmd=uuid
EOF
RUN

NAME=mach0 exports trie
FILE=bins/mach0/Alamofire-stripped
CMDS=<<EOF
iE~_AlamofireVersionString?
psz@sym._AlamofireVersionString
EOF
EXPECT=<<EOF
1
@(#)PROGRAM:Alamofire  PROJECT:Pods-1
EOF
RUN

NAME=mach0 arm/thumb symbols bitness
FILE=bins/mach0/macho-bash
CMDS=<<EOF
ah. @ sym._main
ah. @ sym.__dyld_func_lookup
EOF
EXPECT=<<EOF
 0x00002c44 => bits=16
 0x0000206c => bits=32
EOF
RUN

NAME=mach0 symbols
FILE=bins/mach0/longIdentifiers.dylib
CMDS=is
EXPECT=<<EOF
[Symbols]

nth paddr       vaddr      bind   type size lib name
----------------------------------------------------
0    0x00007fa8 0x00007fa8 GLOBAL FUNC 0        _abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghij
1    0x00007fb0 0x00007fb0 GLOBAL FUNC 0        _abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrst
2    0x00007fa8 0x00007fa8 LOCAL  FUNC 0        func.00007fa8
3    0x00007fb0 0x00007fb0 LOCAL  FUNC 0        func.00007fb0
EOF
RUN
