← Mach-O
ARM64·Decompiler
All tools

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

  1. The pipeline
  2. Disassembly and the CFG
  3. Lifting to IR
  4. Calls and arguments
  5. SSA, propagation and dead code
  6. The stack
  7. Blocks and __block variables
  8. The Objective-C pass
  9. The Swift pass
  10. The IL2CPP pass (Unity)
  11. Structuring
  12. Names in the output
  13. The C-import argument table
  14. 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"):

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).

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:

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).

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:

  1. The Objective-C pass: objc_msgSend$sel takes 2 + the number of colons; the ARC and runtime entry points their fixed counts.
  2. The Swift pass: swift_allocObject 3, swift_beginAccess 4, retain/release 1 (2 for the _n forms), casts 2 or 4…
  3. 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).
  4. 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.
  5. 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

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.