How the ARM64 decompiler works
The Decompiled tab of the Mach-O tool turns one function's ARM64 machine code into
C-like pseudocode, with Objective-C messages written as [receiver selector] and Swift calls
with their labels. This page explains each step, what the output means, and where it can be wrong.
It runs entirely in the browser, on one function at a time, and is built from three files:
lib/decompiler-core.js (a language-neutral IR, SSA, propagation and the structurer),
lib/arm64-decompiler.js (the ARM64 front end and the Objective-C, Swift and C passes; the
IL2CPP pass is in lib/il2cpp-types.js) and lib/swift-demangle.js. The Mach-O tool supplies the bytes, the function boundaries, and what every address means (strings, selectors,
classes, imports).
The output is pseudocode for reading, not source that compiles. When a line looks odd,
switch to the Assembly tab: it is the ground truth.
Contents
- The pipeline
- Disassembly and the CFG
- Lifting to IR
- Calls and arguments
- SSA, propagation and dead code
- The stack
- Blocks and __block variables
- The Objective-C pass
- The Swift pass
- The IL2CPP pass (Unity)
- Structuring
- Names in the output
- The C-import argument table
- Limits — when not to trust the output
1The pipeline
bytes of the function (start → next LC_FUNCTION_STARTS entry, ≤ 8,000 instructions)
│ Arm64Disassembler.decode
▼
instructions ──► CFG: basic blocks, jump tables, PAC checks removed
│ lift
▼
IR statements per block (assign / store / call / if / switch / ret)
│ dominators ─► SSA (φ nodes)
│ drop callee-saved spills · float results · promote stack slots
│ resolve addresses (strings, selectors, classes, imports)
│ propagate ⇄ resolve ⇄ language passes (ObjC, Swift) ← repeated until stable
│ dead code · __block variables · stack protector · dead stack stores
│ pass cleanups (block literals, [super …] structs) · short-circuit && / ||
│ propagate again · dead code
▼
variable naming (out of SSA) ─► structurer (if / else, loops, switch, goto) ─► lines
The status line under the output shows the function's address range, the number of instructions and basic
blocks, the time taken, and warnings such as some control flow kept as goto or truncated.
2Disassembly and the CFG
The function's bytes are decoded by the same ARM64 disassembler as the Assembly tab. Its end is the next
function start from LC_FUNCTION_STARTS, or the end of the section.
Basic blocks
A new block starts at the first instruction, at every branch target inside the function, and after every
branch, return, trap (brk, udf) and indirect jump. Edges follow b,
b.cond, cbz/cbnz, tbz/tbnz and
fall-through. A b to an address outside the function is a tail call: it becomes
return f(…).
Jump tables
An indirect br is checked against the shape compilers emit for a dense switch,
walking back up to 16 instructions:
cmp w8, #4 ; bound: 5 cases (0–4)
b.hi default
adrp x9, table@PAGE
add x9, x9, table@PAGEOFF ; table address
ldrsw x10, [x9, x8, lsl #2] ; entry size 4 (ldrb / ldrh / ldr w also accepted)
add x9, x9, x10 ; base = the table itself, or an earlier adr
br x9
The table is read from the file, each entry becomes a case target, and the block ends in a
switch statement. A csel xi, xi, xzr, ls clamp (out of range → case 0) is
recognised too. When the shape doesn't match, the jump stays an indirect jump:
goto *x9; // indirect jump.
PAC return checks
On arm64e, before a tail call the compiler checks that LR authenticated correctly:
eor x16, x30, x30, lsl #1
tbz x16, #62, ok
brk #0xc471
This test is not program logic. The CFG builder follows only the success edge, and the lifter drops the
eor, so the trap never appears in the output. Authentication instructions themselves
(pac*, aut*, xpac*, bti) are ignored, and
braa/blraa/retab are treated as
br/blr/ret.
3Lifting to IR
Each instruction becomes one or more IR statements over registers. w and x
forms are the same register (w3 → x3); b/h/s/d/q and v
forms are the same FP register (s1, v1.4s → d1). xzr
reads as 0 and writes are discarded.
| Instructions |
IR |
| mov, movz, movn, movk, fmov |
Constants; movk chains fold into one 64-bit value. |
| adr, adrp |
An address; adrp + add / ldr fold into a full address,
later resolved. |
| add sub and orr eor bic orn mul madd msub sdiv udiv lsl lsr asr |
+ - & | ^ * / << >>, with shifted and extended operands. |
| ubfx sbfx ubfiz sbfiz sxt* uxt* |
Shifts and masks; casts such as (int32_t)x. |
| csel csinc csinv csneg cset csetm cinc cneg |
Ternaries c ? a : b. |
| ldr* / str*, ldp / stp |
Loads *(uint32_t *)(x + 8) and stores, with pre/post-index writeback. |
| fadd fsub fmul fdiv fneg scvtf fcvt* |
FP arithmetic and casts (double), (int64_t). |
| ldadd swp cas… |
__atomic_ldadd(…) calls. |
| anything else |
__asm("…"); — kept verbatim, and its destination becomes unknown. |
Flags as compare nodes
NZCV is a pseudo-register. cmp a, b writes a compare node cmp(a, b) to it,
tst an and compare, cmn an add compare,
fcmp a floating-point one; subs/adds/ands compare their
result with zero. A conditional branch or csel reads it with a condition code, and the printer
turns the pair back into a comparison: cmp x8, #10; b.lt L → if (x < 10), with
(unsigned) for lo/hs/hi/ls.
cbz and tbz x, #3 become x == 0 and (x & 0x8) == 0.
ccmp chains are kept as ccmp(…) calls.
4Calls and arguments
Calls follow AAPCS64, the ARM64 procedure call standard as Apple uses it:
| Register |
Role at a call |
In the decompiler |
| x0–x7 |
Integer and pointer arguments; x0 (and x1) the result. |
Arguments: as many as the callee needs. After the call, x0 is the call's
value. |
| d0–d7 |
Floating-point arguments and result. |
Added after the integer arguments when the call's arity is unknown and FP registers were set. If
only d0 is read after the call, the call is a floating-point result. |
| x8 |
Indirect result: address where a large struct is returned. |
Noted when a function's argument use is scanned, but not shown as a parameter. |
| x9–x15 |
Scratch. |
Clobbered by every call. |
| x16, x17 |
Intra-procedure scratch (stubs, PAC modifiers). |
Clobbered. |
| x19–x28 |
Callee-saved. |
Survive calls; their saves to the stack are removed. |
| x20 |
Swift: self (or a closure context). |
Named self in Swift methods; a callee that reads x20 gets it as its receiver:
self.f(…). |
| x21 |
Swift: the error register (swifterror). |
mov x21, #0 before a call means the callee may throw; after the call x21 reads as
error. |
| x29, x30 |
Frame pointer, link register. |
x29 tracks the stack; x30 is clobbered. |
A call writes x0 with the call, then clobbers x0–x18, x30, NZCV and the caller-saved FP registers, so no
value is wrongly carried across it. A second result in x1 (Swift String pairs, optionals) is
kept as v.1 only for Swift and local functions.
Homogeneous FP aggregates
Structs of up to four floats or doubles (CGRect, CGPoint,
CGSize, UIEdgeInsets…) are passed and returned in consecutive d registers, not in
memory. For an Objective-C method whose type encoding says so, the decompiler names those registers after
the fields, and returns them as a struct:
- (void)setFrame:(CGRect)frame d0 → frame.origin.x d1 → frame.origin.y
d2 → frame.size.width d3 → frame.size.height
- (CGSize)intrinsicContentSize return {f1, f2};
5SSA, propagation and dead code
SSA
The IR is converted to static single assignment form (Cytron et al.): dominators are computed, φ nodes
are placed at the dominance frontiers of every register definition, and registers are renamed so each value
has exactly one definition. A register read before any write in the function is its entry value
(version 0): a parameter, or a callee-saved register.
Resolving addresses
Once constants are folded, every address and every load from a constant address is asked of the tool: a C
string becomes "…", a __cfstring @"…", a selector reference
@selector(…), a class reference or GOT slot its name, an __objc_ivar slot an ivar
offset, a __literal8 constant loaded into a d register a double, a writable global
g_<address>, code sub_<address> or the method's name.
Propagation
A value is copied or moved into the place that uses it, so x8 = "abc"; x0 = x8; f(x0) prints as
f("abc"):
- Cheap values (constants, strings, symbols, addresses, parameters, simple compares) are copied
into every use.
- Any other value with exactly one use is moved there if that is safe. A value that calls or reads
memory moves only within its block, and not across a store, a call or (for a call) a memory read; inside
the target statement it may not jump ahead of another call or load evaluated earlier. A pure value may
move to any use its definition dominates, but not into a loop it is outside of.
- Values joined by a φ become one variable later, so an expression reading such a value never moves past
another assignment to that variable.
Propagation, address resolution and the language passes run in alternation until nothing changes: a pass may
need a resolved selector, and propagation may need the pass's result.
Dead code
A definition nobody reads is removed; if it is a call, the call is kept as a statement. This removes the bulk
of register shuffling and every result that is ignored.
6The stack
SP is tracked statically through each block (sub sp, sp, #0x40, pre/post-indexed
stp/ldp), and x29 once it is set from SP, so every SP- or FP-relative access
becomes a stack slot named by its offset from the entry SP: var_18 below it,
arg_8 above (the caller's outgoing arguments).
- Callee-saved spills: a store of an entry value of x19–x30 or d8–d15 to the stack, and the reload
of that slot, are removed.
- Slot promotion: a slot written once with a simple value, whose address is never taken, and read
only where the write dominates, is replaced by that value.
- Dead stores: stores to slots that are never read are removed — unless the address of some slot is
passed somewhere, in which case all stores are kept.
- Stack protector: the canary pattern is removed.
adrp x8, ___stack_chk_guard@GOTPAGE
ldr x8, [x8, ___stack_chk_guard@GOTPAGEOFF]
ldr x8, [x8]
str x8, [sp, #0x28] ; save the canary
…
ldr x9, [sp, #0x28]
cmp x8, x9
b.ne fail ; fail: bl ___stack_chk_fail
→ the branch to __stack_chk_fail and the canary slot disappear
7Blocks and __block variables
Block literals
A block on the stack is a structure the compiler fills field by field: isa =
_NSConcreteStackBlock at +0, flags at +8, the invoke function at +16, the
descriptor at +24, captured values from +32 (the descriptor's size word says how many). When those slots are
only used through the block's address, the stores collapse into one expression at the place the block is
passed:
bl _dispatch_get_main_queue
mov x20, x0
adrp x8, __NSConcreteStackBlock@GOTPAGE
ldr x8, [x8, …]
str x8, [sp, #0x8] ; isa
mov x8, #0xc2000000
str x8, [sp, #0x10] ; flags
adr x8, sub_100006f10
str x8, [sp, #0x18] ; invoke
adrp x8, block_descriptor@PAGE
add x8, x8, block_descriptor@PAGEOFF
str x8, [sp, #0x20] ; descriptor
str x19, [sp, #0x28] ; capture: self
add x1, sp, #0x8
mov x0, x20
bl _dispatch_async
dispatch_async(dispatch_get_main_queue(), ^{ sub_100006f10(captures self) });
A global block (_NSConcreteGlobalBlock in __const, no captures) prints the same
way. The invoke function is a link: opening it shows the block's code, where the block pointer (the first
argument) is named block and its capture fields are named after the captured values, as
block->self.
__block variables
A variable declared __block lives in a byref structure on the stack: isa
(0), forwarding (its own address), flags and size, optional copy/dispose helpers (flag bit 25)
and extended layout (bit 28), then the value. Code reads and writes the value through the forwarding
pointer. The decompiler removes the header stores and the final
_Block_object_dispose(&byref, 8), turns accesses through the forwarding pointer into the
plain variable, and shows the structure's address — what blocks capture — as __block var_30.
Inside the block's own function (opened from the ^{ … } link), the same variable is reached as
*(*(capture + 8) + 0x18); that chain prints as block->var_30.
8The Objective-C pass
| Call |
Becomes |
| objc_msgSend$sel(recv, _cmd, …) (stub) |
[recv sel:arg …]; the number of arguments is the number of : in the
selector. |
| objc_msgSend(recv, @selector(s), …) |
[recv s…], once x1 has resolved to a selector. |
| objc_msgSendSuper2(&super, @selector(s), …) |
[super s…]; the objc_super {receiver, class} stores on the stack are
removed. |
| objc_alloc · objc_alloc_init · objc_opt_new |
[C alloc] · [[C alloc] init] · [C new] |
| objc_opt_class · objc_opt_isKindOfClass · objc_opt_respondsToSelector |
[x class] · [x isKindOfClass:c] ·
[x respondsToSelector:s] |
| objc_retain, objc_retainAutoreleasedReturnValue, objc_claimAutoreleasedReturnValue,
objc_autorelease, objc_retainBlock… |
Their argument: ARC bookkeeping is dropped. |
| objc_release, objc_destroyWeak |
Nothing. |
| objc_storeStrong(&x, v) |
x = v; |
| objc_loadWeakRetained(&x) |
x |
Floating-point arguments of a message go in d registers, not after the integer ones; the pass matches them to
keywords that look floating-point (…Width, …Alpha, …Duration,
…Rect…), else to the last parameters, and several d registers for one parameter become a struct
{f1, f2, f3, f4}.
Ivars
obj + offset, where the offset was loaded from an __objc_ivar slot, becomes
&obj->_name, and a load through it obj->_name. In an instance method,
self + constant matching one of the class's ivar offsets is named the same way.
Signature
For a method opened from the class browser, the first line comes from the selector and the type encoding:
- (BOOL)validateToken:(NSString *)token forUser:(id)user. x0 and x1 are self and
_cmd, the next registers are named after the selector's keywords (with,
for, by… prefixes dropped), and a void method returns nothing.
Example
-[LoginViewController viewDidLoad]
sub sp, sp, #0x30
stp x20, x19, [sp, #0x10]
stp x29, x30, [sp, #0x20]
add x29, sp, #0x20
mov x19, x0
adrp x8, … ; __objc_superrefs: class LoginViewController
ldr x8, [x8, …]
stp x0, x8, [sp] ; struct objc_super { self, class }
adrp x1, … ; @selector(viewDidLoad)
ldr x1, [x1, …]
mov x0, sp
bl _objc_msgSendSuper2
mov x0, x19
bl _objc_msgSend$view
mov x29, x29 ; ARC marker
bl _objc_retainAutoreleasedReturnValue
mov x20, x0
adrp x2, … ; @"Login"
add x2, x2, …
bl _objc_msgSend$setAccessibilityLabel:
mov x0, x20
bl _objc_release
…
- (void)viewDidLoad {
[super viewDidLoad];
[[self view] setAccessibilityLabel:@"Login"];
}
9The Swift pass
String literals
A Swift String is two registers. Constant strings are built from two immediates, which the pass
recognises in a call's arguments and replaces by the text:
- Small (≤ 15 UTF-8 bytes, stored inline): the first register holds bytes 0–7, the second bytes
8–14 and a top byte
0xEn (or 0xAn), where n is the
length.
- Large literal: the first register holds flags in the top bits and the length in the low 48 bits;
the second has bit 63 set and holds the address of the characters minus 32.
mov x0, #0x6568 ; "he"
movk x0, #0x6c6c, lsl #16 ; "ll"
movk x0, #0x6f, lsl #32 ; "o"
mov x1, #0xe500000000000000 ; small string, 5 bytes
bl _$s5MyApp6LoggerC3logyySSF ; MyApp.Logger.log(), reads x0, x1 and x20
self.log("hello");
The large form is only recognised when both halves fold to plain constants; a pointer built with
adrp / add may instead be shown as the address (or the string found at it) and a
separate flags constant.
When both halves are picked by the same condition, the result is a ternary of two strings.
Runtime calls
| Call |
Becomes |
| $s…Ma (type metadata accessor) |
Type.self |
| swift_getObjectType(x) |
type(of: x) |
| swift_dynamicCastClass · …Unknown · …ObjCClass |
(x as? T); the Unconditional variants (x as! T) |
| swift_retain, swift_bridgeObjectRetain, swift_unknownObjectRetain… |
Their argument. |
| swift_release, swift_bridgeObjectRelease, swift_beginAccess, swift_endAccess… |
Nothing. |
| swift_getObjCClassMetadata, swift_getObjCClassFromMetadata |
Their argument. |
Names and calls
Mangled names ($s…) are shown demangled (the mangled form is in the tooltip). A name with
argument labels — Type.fetch(id:completion:) — prints as
fetch(id: v1, completion: v2), with recv. in front when the callee takes
self in x20.
@objc thunk naming
In a stripped binary, Swift methods have no names. But a Swift class exposed to Objective-C has an ObjC
method list, and each entry's implementation is a small @objc thunk that converts the arguments and
calls the native Swift method. When a thunk makes exactly one direct call (or tail call, or hands exactly
one code address to a helper) into this binary's own code, that target is named after the selector,
converted to Swift style:
-[MyApp.SessionManager refreshTokenWithCompletion:] (thunk)
bl sub_10001c4e8
→ sub_10001c4e8 is named SessionManager.refreshToken(completion:)
These names appear in calls, in the Swift class browser's method labels, and in the signature line.
10The IL2CPP pass (Unity)
The IL2CPP tool uses the same decompiler on libil2cpp.so, with a pass
(lib/il2cpp-types.js) that uses what global-metadata.dat and the binary's
registration tables say about the managed code. IL2CPP compiles each C# method to a function taking
(this,) the C# parameters and a MethodInfo*, so every argument's type is known,
and from there the type of each value is followed through field loads, calls, φs and copies.
| In the code |
Shown as |
| *(this + 0x18) |
this.count: the instance field at that offset (parents included; a struct field
embedded in the object is followed into the struct). Auto-property backing fields show as the
property. |
| *(*TypeInfo Foo + 0xb8) + off |
Foo.instance: the class's static fields. |
| *(arr + 0x18), *(arr + 0x20 + i·size) |
arr.Length, arr[i] (Il2CppArray: header, bounds, length,
items). |
| *(str + 0x10), str + 0x14 + 2i |
str.Length, str[i]. |
| (**(klass + 0x138 + 16k))(obj, …, *(klass + 0x140 + 16k)) |
obj.Method(…): slot k of the static type's vtable (metadata 27 and later); an
abstract slot is named by the method that declares it. |
| get_X(obj) with no other arguments |
obj.X (or Type.X for a static property). |
| Method(this, …, 0) |
The trailing null MethodInfo* argument is dropped. |
| resolve(TypeInfo / "literal" / MethodInfo) |
Just the value: the runtime's lazy metadata resolver (recognised by its
mov w1, #1; b … body) returns its argument, resolved. |
| if (!flag) { resolve(…); flag = 1; } |
Removed: the one-time metadata initialisation at the start of a method. |
| if (klass has a cctor && it hasn't run) class_init(klass) |
Removed: the static-constructor check before a static access. |
| float constant in .rodata |
The number, in its shortest float form (0.299). |
Arguments follow AAPCS64: float/double parameters are named in d registers, a
struct of up to four floats or doubles (Vector3, Color…) is spread over d
registers as value.x, value.y…, other structs up to 16 bytes take one or two x
registers, and larger ones are passed by reference (and their fields named). The return register follows the
return type. The code generator's helpers are tiny stubs that branch on into the runtime; they're followed
to find how many arguments they take.
Interface calls. IL2CPP inlines the lookup of an interface method: it walks the class's interface
table (klass + 0xb0, klass + 0x12a entries) for the interface, falls back to a
runtime helper (GetInterfaceInvokeData(obj, IFoo, slot)) when it isn't there, and calls through
the vtable slot it found. The helper's arguments name the interface and the slot, so the lookup is removed
and the call reads obj.Method(args). The hidden MethodInfo argument of a call through a vtable
or interface slot is recognised by what it is (a load from the slot + 8), so float and struct parameters,
which travel in other registers, keep their places.
is and as. A type test against a class is inlined as two comparisons: the object's class is at least
as deep in the hierarchy as the class (klass + 0x12c), and its ancestor at that depth
(klass + 0xc8) is the class. They read obj is Foo,
obj is Foo ? obj : null reads obj as Foo, and the depth test is dropped when it
only guards the second comparison. When other code sits between the two, the first is shown as
TypeDepthAtLeast(obj, Foo).
Runtime helpers. The generated code calls small helpers that have no symbols. They are named by what
they lead to: a PLT stub by the imported function in its slot; a helper that reaches the same runtime
function as one of the exported il2cpp_* functions by that name; and a helper that builds an
exception by name ("System", "NullReferenceException") after it. The common ones
then read as C#: new Foo(args) (the allocation joined to the constructor call that follows it),
new int[n], throw e, throw new NullReferenceException(),
new IndexOutOfRangeException(), NullCheck(x). A call to a function that is only
ret (an empty constructor such as Object..ctor) is dropped.
The offsets of the class structure (static fields at 0xb8, the vtable at
0x138, the interface table and type hierarchy) are those of current Unity versions. Not
recovered yet: interface calls in shared generic code (the interface's class and the slot are looked up at
run time), type tests against interfaces, calls that return a float struct (the result after the first
member is lost), the less common runtime helpers (array stores and element checks, some casts: still
sub_…), and the element types of shared generic code (List<object>).
11Structuring
The structurer walks the CFG in order and turns edges back into C control flow, using dominators (a
block that every path from the entry passes through), post-dominators (where branches join again) and
back edges (an edge to a block that dominates its source: a loop).
- Short-circuit conditions are merged first: a block that only tests a second condition and shares
a target with its predecessor makes
if (a && b) or if (a || b) (and
the negated forms), when the φs at the shared target agree.
- if / else: the join point of a conditional branch is its immediate post-dominator; the two sides
are emitted up to it. An empty side becomes a plain
if with the condition negated, and
nested else { if … } becomes else if.
- Guard flattening: when the
then side ends by leaving (return,
break, continue, goto, __builtin_trap()), its
else is unnecessary and the rest is printed unindented.
- Loops: a loop header whose test leaves the loop is a
while (cond); otherwise
while (true) with break and continue. Then two rewrites:
x = init; while (cond(x)) { …; x++; } becomes for (x = init; cond; x++), and a
while (true) whose body ends in if (c) continue; break; becomes
do { … } while (c);.
- switch: jump-table cases are grouped by target, each case runs to the switch's post-dominator,
and a missing
break is added. switch (x - 3) with cases 0…n is rewritten to
switch (x) with cases 3…n+3.
- Shared tails: when both sides of an
if can return early (so the post-dominator is
the function's exit) but also meet again, the first block both sides reach — dominated by the
if and not a small return — is used as the join.
x = c ? f() : g(); if (!x) return 0; … comes back as an if/else followed by
the shared code instead of a goto.
- Tail calls through a pointer:
br xN without a jump table (witness tables, vtables,
thunks) is return (*f)(…); registers that only computed the target are not shown as
arguments. arm64e pointer checks (xpac + cmp + brk) are removed
like the return-address check.
- Dynamic stack allocation:
__chkstk_darwin probes and sp updates
disappear and the new pointer prints as alloca(n).
- Tail duplication: a small block reached a second time (one that returns, or a few statements
flowing to one successor) is printed again rather than jumped to.
- goto is the last resort: when a block has already been printed and cannot be duplicated, the
output says
goto loc_100004a2c; and puts the label on the target. The status line then says
some control flow kept as goto.
12Names in the output
| Name |
What it is |
| self, _cmd, token… |
Parameters of an ObjC method, from its selector and type encoding; HFA fields such as
frame.size.width. |
| a1 … a8 |
Entry values of x0–x7 (unnamed parameters). The signature of a function without metadata lists
as many as it reads. |
| fa1 … fa8 |
Entry values of d0–d7 (floating-point parameters). |
| self (Swift) |
x20 in a Swift instance method, or in any function that reads x20 when the binary has Swift
metadata. |
| v1, v2… |
Integer / pointer temporaries; values joined by a φ share one name. |
| f1, f2… |
Floating-point temporaries. |
| view, session… |
Hints from passes: the result of a getter-like message is named after it
([self view] → view), of
alloc/new/init after the class
([NSURLSession new] → urlSession), of a factory message after its
first word (stringWithFormat: → string, URLWithString: →
url, objectForKey: → object), of a Swift initializer or
getter after the type or property (URL.init(string:) → url,
Logger.logObject.getter → logObject), and of common C calls after
their result (SecItemCopyMatching → status, dlopen →
handle, dispatch_queue_create → queue). A variable
assigned in several places gets the name only when every assignment agrees. You can also rename
a variable yourself: double-click it. |
| var_18, arg_8 |
Stack slots below / above the entry SP, in hex. |
| __block var_30 |
A __block variable's byref structure. |
| g_10002c3f8 |
A writable global (__data, __bss, __common). |
| sub_100006f10 |
An unnamed function in this binary (a link that opens it). |
| loc_100004a2c |
A goto label: the block's address. |
| x19, x22… |
Entry value of a callee-saved register that the function reads without having set it — usually a
sign the function's start is wrong, or code shared between functions. |
13The C-import argument table
A call site doesn't say how many registers hold arguments: x2 may be an argument or a value the caller
happens to keep there. The decompiler decides in this order:
- The Objective-C pass:
objc_msgSend$sel takes 2 + the number of colons; the ARC and runtime
entry points their fixed counts.
- The Swift pass:
swift_allocObject 3, swift_beginAccess 4, retain/release 1 (2
for the _n forms), casts 2 or 4…
- The C table: argument counts of about 300 common imports, e.g.
strlen 1,
strcmp 2, memcpy 3, dispatch_async 2, dispatch_after
3, SecItemCopyMatching 2, SecTrustEvaluateWithError 2, CC_SHA256
3, CCCrypt 11, CCKeyDerivationPBKDF 9, ptrace 4,
sysctl 6, dlsym 2, _os_log_impl 6. A leading underscore is
ignored. When the table says more than eight, the arguments after x7 are read from the outgoing area at
the bottom of the stack (8-byte slots, which is how Apple's ABI passes pointers and
size_t).
- A local function in this binary: its own argument usage, from a straight-line scan of its first
96 instructions: the highest of x0–x7 read before being written (stack spills don't count). An early
tail branch marks a trampoline, whose usage is unknown.
- Otherwise, the highest of x0–x7 written since the previous call in the same block, plus any d registers
written.
Only eight register arguments are ever shown; see the limits below.
14Limits — when not to trust the output
- Argument counts are guessed from register use (above). An unknown external
call may show too many arguments (a register the caller set for its own later use) or too few (an
argument set in an earlier block). Check calls that matter in the Assembly tab.
- No type inference. Variables are named after what produces them (see naming), but not typed. Everything is a 64-bit value; loads show their width as a
cast (
*(uint32_t *)(v1 + 0x10)), pointers and integers look the same, and struct fields are
raw offsets. ObjC parameter types come only from the type encoding, and only in the signature.
- Stack-passed arguments are mostly missing. Only functions in the C table with more than eight
arguments (
CCCrypt, CCKeyDerivationPBKDF) get them. Other arguments beyond x7
/ d7 (and variadic arguments, which Apple's ABI always passes on the stack — NSLog,
stringWithFormat:, printf) are stores to the outgoing area at the bottom of
the stack. They appear as stores to var_… slots before the call, not as arguments.
- Indirect calls through a register (
blr x8, C++ / Swift vtable calls, protocol
witness calls, block invokes) print as (*v3)(…) with a guessed argument count; the target
is not resolved.
- Exceptions and unwinding are ignored.
@try/@catch, C++ exceptions and Swift
defer cleanups on unwind come from __unwind_info / __eh_frame
landing pads that no branch reaches; that code is either missing or shows up as unreachable-looking
blocks. Swift throws is visible only as the error register test after a call.
- Optimised Swift is hard: generic code passes metadata and witness tables as hidden arguments,
value types are copied through outlined helpers (
outlined copy / destroy
functions), and async functions are split into many partial functions that hand over through an
async context (x22) and tail calls. Expect many unnamed sub_ calls with odd arguments.
- Loop shapes may differ from the source. Compilers rotate loops, so a
for may come
back as do … while guarded by an if, or as while (true) with
breaks; the logic is the same.
- Values shown as raw addresses are addresses the tool could not describe: data inside a
structure, a table without symbols, or a section the tool doesn't load. A load from such an address
shows as
*0x10002c3f8.
- Function bounds come from
LC_FUNCTION_STARTS. Without it, or with code shared
between functions (outlined fragments, cold splits), a function may be cut short or run into the next
one. Functions longer than 8,000 instructions are truncated.
- Anything not lifted (SIMD, system registers, rare instructions) stays as
__asm("…");
and makes its destination unknown. A conditional compare
(ccmp/ccmn/fccmp) whose previous condition can't be expressed
stays a ccmp(…) call; the usual chains become && / ||.
- Instruction order can change: moving values into their uses is guarded against reordering calls
and memory accesses, but code reading memory that another thread or a callee changes may look simpler
than it is.
For anything security-relevant — an argument passed to SecItemAdd, the
condition of a jailbreak check, the exact comparison in a certificate pin — confirm it in the Assembly view
before relying on the pseudocode.