This is jtool v(almost 1.0) (Moscow) - with partial ARMv7k disassembly and SLC symbol resolution, compiled on Jan 8 2017 20:33:01
Usage: jtool [options] _filename_
OTool Compatible Options:
-arch .. For fat (universal) binaries: i386,x86_64[h], arm[v[67]]
-h print header (ELF or Mach-O)
-f print fat header
-l List sections/commands in binary
-L List shared libraries used (like LDD)
-v[v] Verbose output. -vv is even more verbose. -vvv might be more than you can handle :-)
New Options:
--pages Show file page map (similar to pagestuff(1))
-a _offset_ Find virtual address corresponding to file offset _offset
-e[xtract] _name_ Extract section/segment _name_ in binary, or file _name_ from shared cache
-e[xtract] arch Extract selected architecture from FAT file. Specify arch with -arch .. or ARCH=
-e[xtract] signature Extract code signature from binary
-F [_string_] find all occurrences of _string_ in binary
-Fs _string_ also show search results (experimental)
-S List Symbols (like NM)
-Sa _address_ _symbolname_ Add symbolname manually for address (to .jtool)
-Sd _symbolname_ (not yet) Remove symbolname for address (to .jtool)
-p _addr_[,_size_] Peek at _size_ bytes in virtual _address_ in binary (like OD, but on memory)
dyldinfo Compatible Options:
-bind print addresses dyld will set based on symbolic lookups
-lazy_bind print symbols which dyld will lazily set on first use
-weak_bind print symbols which dyld must coalesce
-export print addresses of all symbols this file exports
-opcodes print opcodes used to generate the rebase and binding information
-function_starts print table of function start addresses
-data_in_code print any data-in-code inforamtion
Destructive Options (will write output to /tmp):
-m Modify
__SEGMENT[.__section],[_offset][,size] (null)
-r Remove/Resize (Experimental)
-rL _dylib/soname_ Library
-rC _Load_Command_#_ Load Command
-/+pie Toggle Position Independent Executable (ASLR)
-/+lcmain Toggle pre-Mountain-Lion/iOS6 compatibility (LC_UNIXTHREAD/LC_MAIN)
-/+enc Mark as decrypted/encrypted (toggles cryptid of LC_ENCRYPTION_INFO[64])
Disassembly/Dump Options:
-d[_arg_[,size]] disassemble/dump (experimental) - _arg_ may specify address/section/symbol/Obj-C class. size is optional
-dA [_arg_[,size]] Disassemble as ARM code (32-bit instructions)
-dT [_arg_[,size]] Disassemble as Thumb/Thumb-2 code (16/32-bit instructions)
-dD [_arg_[,size]] Dump (even on a text segment)
-do [_arg_[,size]] Dump/Disassemble from offset, rather than address
-d objc Dump objective-C classes in binary, if any
-D : As -d, but attempts to decompile only (i.e. shows only C-level code, no disassembly (null)
-opcodes Also dump opcode bytes
--jtooldir _path_ path to search for companion jtool files (default: $PWD).
Use this to force create a file, if one does not exist
Code Signing Options:
--sig Show code signature in binary (if any)
--sign [adhoc] self-sign with no certificate
--ident _ident_ provides identity (fake, of course)
--appdir Set App Path (for code signing and/or verification)
--ent Show entitlements in binary (if any)
Advanced Options:
--pcrelative show addresses as PC relative offset
--slide _slide_ slide text by _slide_ bytes (may be negative)
--rebase _address_ rebase text to this address (destructive)
--inplace Perform destructive operations in place (instead of out.bin) for the brave
--version Show tool version and compilation date
Output Options:
--html Output as HTML (implies color)
--curses Output as Color using ncurses (can also set JCOLOR=1)
Environment variables: JDEBUG=1, NOPSUP=1 (suppress NOPs in disassembly), NOOBJC=1 (avoid Obj-C crashes)
Note: Experimental features may not be available in public version of this tool
$ pagestuff ~/Documents/iOS/JB/Pangu9/pguntether -a | more
File Page 0 contains fat file headers
File Page 1 contains empty space in the file between:
fat file headers and
Mach-O file for armv7
...
File Page 8 contains empty space in the Mach-O file for armv7 between:
Mach-O headers and
contents of section (__TEXT,__text)
File Page 9 contains contents of section (__TEXT,__text) (armv7)
Symbols on file page 9 virtual address 0x91f8 to 0xa000
... this little piggy went to the river...
jtool --pages 选项能够提供更清晰的输出
# Cut to the chase:
Phontifex-Magnus:~ root# ARCH=arm64 jtool --pages /pguntether
0x0-0x38000 __TEXT
0x53e8-0x34f50 __TEXT.__text
0x34f50-0x35490 __TEXT.__stubs
0x35490-0x359e8 __TEXT.__stub_helper
0x359e8-0x36a11 __TEXT.__const
0x36a11-0x379cf __TEXT.__cstring
0x379cf-0x37e30 __TEXT.__objc_methname
0x37e30-0x37e64 __TEXT.__gcc_except_tab
0x37e64-0x37ffc __TEXT.__unwind_info
0x38000-0x3c000 __DATA
0x38000-0x38048 __DATA.__got
0x38048-0x383c8 __DATA.__la_symbol_ptr
0x383d0-0x38530 __DATA.__const
0x38530-0x389d0 __DATA.__cfstring
0x389d0-0x389d8 __DATA.__objc_imageinfo
0x389d8-0x38b80 __DATA.__objc_selrefs
0x38b80-0x38bd8 __DATA.__objc_classrefs
0x38bd8-0x3b99c __DATA.__data
0x3c000-0x3f120 __LINKEDIT
0x3c000-0x3c030 Rebase Info (opcodes)
0x3c030-0x3c2d8 Binding Info (opcodes)
0x3c2d8-0x3cb98 Lazy Bind Info (opcodes)
0x3cb98-0x3ce70 Exports
0x3ce70-0x3d008 Function Starts
0x3d008-0x3d080 Code Signature DRS
0x3d008-0x3d008 Data In Code
0x3d080-0x3dcd0 Symbol Table
0x3dcd0-0x3e074 Indirect Symbol Table
0x3e074-0x3e974 String Table
0x3e980-0x3f120 Code signature
Phontifex-Magnus:~ root# ARCH=arm64 jtool -a 0x38b81 /pguntether
Offset 38b81 in file will be loaded at 100038b81 (__DATA.__objc_classrefs)
Phontifex-Magnus:~ root# ARCH=arm64 jtool -a 0x81 /pguntether
Requested offset 129 falls in Load Command 1 (LC_SEGMENT_64)
morpheus@Zephyr (~)$ jtool --sign binary
**************************************************************************************
* Warning: Code signatures are still defined as Beta. Lots of minutiae to deal with, *
* and it isn't as easy as you might think to get things right with all these hashes. *
* *
* I suggest you use --sig -v to validate your pseudo-signed binaries. *
* Try JDEBUG=1 if you want to follow along. *
**************************************************************************************
Warning: Destructive option. Output (397920 bytes) written to out.bin
morpheus@Zephyr ()$ ldid -S binary
morpheus@Zephyr ()$ ls -l binary out.bin
-rwxr-xr-x 1 root staff 397920 Oct 18 03:30 binary
-rwxr-xr-x 1 root staff 397920 Oct 18 03:30 out.bin
morpheus@Zephyr ()$ diff out.bin binary
morpheus@Zephyr ()$ echo $?
0
morpheus@Zephyr (~)$ JDEBUG=1 ARCH=armv7 jtool --sign --ent ent.xml /tmp/a
Very last section ends at 0xc11c, so that's where the code signature will be
Aligning to 16 byte offset - 0xc120
Allocating Load Command
First section offset is 7ea4; Mach header size is 580
Patching header to reflect inserted command @580
Patching __LINKEDIT to reflect new size of file
Setting LC fields
Allocating code signature superblob of 669 bytes, with 3 sub-blobs..
Setting LC_CODE_SIGNATURE's blob size to match CS Blob size..
Creating Code Directory with 13 code slots and 5 special slots
Calculating Hashes to fill code slots..
Need to pad 288 bytes to page size in last page (because code signature is also in this page)
Padding to page size with 3808 bytes
Calculating (modified) last page hash
Adding empty requirements set to 447
Filling the special slot (-2) for requirements blob...
Copying entitlements blob to 459
Filling the special slot (-5) for entitlement blob...
Crafting New Mach-O
Inserting 669 bytes Blob at 49440, bringing new file size to 50109
Warning: Destructive option. Output (50109 bytes) written to out.bin
DYLD共享缓存(DYLD Shared Caches)
苹果将大多数dylibs和插件预先链接到“Shared Library Cache”中。 SLC位于 /var/db/dyld(OS X)和 /System/Library/Caches/com.apple.dyld(iOS)中。 OS X 缓存也有一个“map”,但是iOS没有。
注意这个是通过重建那些不在苹果官方oc库中的类来完成的,所以同样可以在Linux版本中工作。然而,因为这个类的遍历操作是我自己实现的,它会 A) 仍然有点慢(Springboard 是一个很好的例子,有着无数的类)和 B) 可能有bug。你可以用NOOBJC=1去禁用oc,但是请让我知道你在这里遇到的bug。
# Note that:
# A) you need to disable color for the regexp to work (because of curses sequences)
# B) the regexp is then "mach_msg(" (decompiled function) or "begins with _" (function label)
# C) jtool does everything in the cache, no need to extract!
#
morpheus@Zephyr (~/Documents/Work/JTool) % JCOLOR=0 jtool -d dyld_shared_cache_arm64:BackBoardServices |
| egrep "(_mach_msg\(|^_)" | less
_BKSRestartActionOptionsDescription: # No mach_msg here
_BKSTouchDeliveryPolicyServerGetProxyWithErrorHandler: # No mach_msg here either..
__BKSHIDGetBacklightFactor:
; _mach_msg(6000000)
__BKSHIDSetBacklightFactorPending:
; _mach_msg(6000001)
__BKSHIDSetBacklightFactorWithFadeDuration:
; _mach_msg(6000002)
__BKSHIDSetBacklightFactorWithFadeDurationAsync:
; _mach_msg(6000003)
..
morpheus@Zephyr (~/Documents/Work/JTool) % jtool -d dyld_shared_cache_arm64:BackBoardServices |
egrep "(_mach_msg\(|^_)"
_BKSRestartActionOptionsDescription:
_BKSTouchDeliveryPolicyServerGetProxyWithErrorHandler:
__BKSHIDGetBacklightFactor:
; _mach_msg(6000000)
__BKSHIDSetBacklightFactorPending:
; _mach_msg(6000001)
__BKSHIDSetBacklightFactorWithFadeDuration:
; _mach_msg(6000002)
...
__BKSHIDSetHardwareKeyboardLayout:
; _mach_msg(6000056)
__BKSHIDGetHardwareKeyboardLanguage:
; _mach_msg(6000057)
__BKSHIDSetEventRouters:
; _mach_msg(0) # OK, so it's not perfect -- I don't follow FP operations (yet)!
__BKSHIDSetKeyCommands:
; _mach_msg(6000059)
__BKSHIDSetStackshotCombos:
; _mach_msg(6000059)
__BKSHIDSetTouchHand:
; _mach_msg(6000061)
__BKSDisplayStart:
; _mach_msg(6001000)
__BKSDisplayIsDisabled:
; _mach_msg(6001001)
..
JDEBUG=1 ARCH=armv7 jtool --sign --ent ent.xml xxdaemon
will auto-process this architecture
Currently supported only on thin (single architecture) binaries