11 min read

Architecture

AArch64 Assembly

Every idiom in this section so far has been x86-64. AArch64, the 64-bit ARM architecture, runs on phones, on Apple silicon, on most embedded and IoT boards, and on much automotive and telecom firmware. The registers, the calling convention and the compiler's shapes all change. The reasoning does not.

One Instruction Set Is Not a Method

Reading a second architecture is not a second discipline. The questions are unchanged; only the register names are new.

Why a Second Architecture

x86-64 dominates the desk and the rack, which is a property of where analysis is taught rather than of the code being shipped. Handsets, vehicle telematics and baseband firmware, telephone-exchange switches, payment terminals and IoT boards are AArch64.

The risk is not that the analysis stops but that it continues wrongly. An analyst who cannot read the instructions still sees entropy, strings and a symbol table naming a packer, and reports the sample as packed — unexplained bytes look like concealment from a distance. On such a file the first decision is not which unpacker to run, but which architecture the disassembler should have been told.

The Register File and the Width Trap

AArch64 has thirty-one general-purpose 64-bit registers, x0 to x30, plus a stack pointer and a program counter that are not numbered, and a zero register that reads as zero and discards writes. Every numbered register has a 32-bit view: w0 is the low half of x0.

Writing the 32-bit view zeroes the upper half. A move of -1 into a w register leaves 0x00000000ffffffff, not all ones, and nothing in the syntax marks the transition. The frame uses eight-byte slots while the instruction names a four-byte write, so a store looks pointer-sized until you notice the w. A pointer that survives a call as a small positive number was truncated upstream.

x30 is the link register: a branch-with-link writes the return address into it, so the return address lives in a register, not on the stack. There is no push and no pop; the prologue stores frame pointer and link register as a pair and the epilogue loads them back. The stack pointer must be 16-byte aligned whenever it addresses memory, so every frame is a multiple of sixteen.

Registers Role at a call site
x0–x7 First eight integer or pointer arguments; x0 and x1 carry the return
x8 Indirect result pointer for a returned struct; the Linux syscall number
x9–x15 Caller-saved temporaries
x16, x17 Intra-procedure-call scratch, used by veneers and PLT stubs
x18 Platform register, reserved by the ABI on Darwin and Windows
x19–x28 Callee-saved; must be restored before returning
x29, x30 Frame pointer and link register

The Calling Convention You Read Call Sites With

The convention to read every call site against is AAPCS64: arguments arrive in order from x0, past the eighth they go on the stack, floating-point and vector arguments travel in the v registers instead, and x0 and x1 carry the return. The regularity is the point: a wrong convention does not fail, it shifts the argument list and leaves output that reads perfectly and is wrong.

aarch64-call-site.asm
; long parse_packet(struct pkt *p, const void *buf, size_t len, uint32_t flags)
; x0 = p, x1 = buf, x2 = len, x3 = flags  - filled in order, whatever the types

    adrp    x19, g_parser_state        ; page-aligned, PC-relative base
    add     x19, x19, :lo12:g_parser_state
    mov     x0, x20                    ; first argument
    mov     x1, x21                    ; second
    mov     x2, x22                    ; third
    mov     w3, wzr                    ; fourth = 0, and x3 = 0 with it
    bl      parse_packet               ; x30 = return address
    cbnz    w0, .Lerror                ; the result is tested as 32 bits

; after the call only x19-x28 and the stack survived; x0-x18 were the callee's to clobber

Idioms That Trip an x86 Reader

Conditional selection replaces most conditional jumps. AArch64 selects between two sources unconditionally: csel is the direct form, csinc and csinv add or invert when the condition fails, and cset turns a comparison into zero or one. A branch-free if is a compare followed by a select.

Addresses are built in pairs. adrp loads a page-aligned, PC-relative base within a four-gigabyte window and an add applies the low twelve bits, so a reference to a string or a global is two instructions rather than a move of a full address. Mach-O spells the second operand @PAGEOFF, ELF writes :lo12:. Recover the page base without the offset and the symbol appears four kilobytes from where it is.

System calls are a supervisor call with the number in a register, not a symbol: Linux takes it in x8, Darwin in x16 with a different immediate. The call is named only by reading the number against that kernel's syscall table.

Instructions are a fixed four bytes, which is good news for finding boundaries and bad news for constants. Arithmetic immediates are twelve bits, optionally shifted; logical immediates use a bitmask encoding that cannot express every value; a 64-bit constant that does not fit is assembled from sixteen-bit pieces or loaded from a literal pool. A constant that appears in four pieces is one number.

aarch64-idioms.asm
; if (a > b) r = x; else r = y;      - no branch
    cmp     w0, w1
    csel    w2, w3, w4, gt

; return (a == 0);
    cmp     w0, #0
    cset    w0, eq                     ; alias: csinc w0, wzr, wzr, ne

; puts("hello")                      - one address, two instructions
    adrp    x0, msg
    add     x0, x0, :lo12:msg
    bl      puts

; a 64-bit constant no immediate can carry
    movz    x0, #0x1234
    movk    x0, #0xabcd, lsl #16
    movk    x0, #0x5678, lsl #32

; write(1, buf, 5) on Linux
    mov     x0, #1                     ; fd
    adrp    x1, buf
    add     x1, x1, :lo12:buf
    mov     x2, #5
    mov     x8, #64                    ; __NR_write
    svc     #0

The fixed width is also a free triage signal: every instruction begins on a four-byte boundary, so a listing whose instructions start at odd addresses, or that decodes thousands of instructions without a branch, is some other instruction set being read four bytes at a time.

The Prologue You See Before Reading Anything

The pair store with pre-index is the standard prologue, and it describes the frame before a single instruction in the body does.

aarch64-prologue.asm
handle:
    stp     x29, x30, [sp, #-32]!      ; sp -= 32, then store fp and lr
    mov     x29, sp                    ; frame pointer for this frame
    stp     x19, x20, [sp, #16]        ; two callee-saved registers in the frame
    mov     x19, x0                    ; keep the first argument across calls
    ; ... body ...

    ldp     x19, x20, [sp, #16]
    ldp     x29, x30, [sp], #32        ; load, then sp += 32
    ret                                ; branch to x30

checksum:                              ; leaf: no frame at all
    eor     w2, w2, w0
    ret

The exclamation mark is the write-back: the pair store subtracts from the stack pointer before storing, so allocation and save are one instruction. The epilogue's bracket form loads first and adds afterwards, restoring the caller's frame and releasing the space together. An stp without the exclamation mark stores below the stack pointer without moving it, so the save lands outside the frame the function allocated.

From the prologue alone you know the frame size, which callee-saved registers the function owns, and whether it makes a call it needs to return from — a function that saves neither frame pointer nor link register and closes with ret has no nested call to come back to, so its arguments are still where the caller left them. Larger frames subtract further after the save. With the frame pointer chain you can walk callers in a debugger; a build that omits the frame pointer leaves unwind tables as the only guide.

Platform Differences That Change the Analysis

The instruction set is one thing; the ABI variant is another. A Mach-O binary is marked arm64 or arm64e, and the second enables pointer authentication: the toolchain signs pointers, so a function pointer in memory carries authentication bits in its high half. An Android binary is a conventional ELF, and whether the same features are enforced is declared in a GNU property note. Darwin and Windows both reserve x18 for the platform, so a decompiler that promotes it to a local is inventing a variable.

Pointer authentication is two instructions at a function's edges: a sign of the link register against the stack pointer on entry, an authenticate before the return. Data pointers are signed with a key and a context value, so the result is not a canonical address — which is why a table of function pointers disassembles into improbable constants. Strip the signature, or step past the authentication.

Filed as mitigations, these are also an analysis surface. An indirect branch must land on a designated landing pad at a function entry, so a hook placed mid-function faults instead of running, and a copied return address is worthless to a debugger that expects to rewrite it. The compensation is that the same instructions mark function boundaries: a landing pad at the top and a sign-and-authenticate pair around the body beat a symbol table entry as evidence of a start.

aarch64-pac-bti.asm
; arm64e-style prologue: the saved link register is signed, so a copy
; of the stack slot is not a usable address until it is authenticated
func:
    paciasp                            ; sign lr, key A, modifier sp
    stp     x29, x30, [sp, #-16]!
    mov     x29, sp
    ; ... body ...

    ldp     x29, x30, [sp], #16
    autiasp                            ; faults if the slot was modified
    ret

; a landing pad for indirect branches when branch target
; identification is enforced for this image
dispatch:
    bti     c
    br      x1                          ; a jump, so the target needs bti j / bti jc

The enforcement switch sits outside the code. A GNU property note in an ELF, or the equivalent Mach-O load command, tells the loader the image is compatible; a build without the note still runs where the hardware implements the checks, with them not applied. The instructions alone therefore do not settle whether a given device enforces them (the current policy is not stated here).

What Changes in the Tooling

Architecture is the first setting, before the base address and before any analysis option: in Ghidra the language, an AArch64 little-endian v8 entry; in IDA the ARM64 processor module; in Binary Ninja the aarch64 architecture; in radare2 an architecture of arm with a register width of 64. Everything downstream inherits it, including the convention the decompiler assumes.

Selecting wrong produces output that is plausible rather than empty. x86 decoders accept almost any byte sequence, so an ARM64 image read as x86 yields thousands of short instructions with improbable immediates, calls outside the image and functions that never return. Thumb code from a 32-bit ARM image read as AArch64 produces calls into the middle of nowhere. When a listing has no cross-references at all, check the architecture before concluding the binary is hostile.

"Unknown calling convention" usually describes the function, not the tool. A stub that loads a slot and branches through it — the shape a linker emits for an import, with the page base in x16 and the target in x17 — has no prologue to infer parameters from. So does hand-written assembly: a checksum or a syscall wrapper saves exactly the registers it needs. Apply AAPCS64 by hand, then correct the signature.

Misreads That Look Like Obfuscation

Each of these is a reading error that presents as concealment. Check the architecture and the register width before escalating.

  • Plausible output, no references: Clean decompilation with calls outside the image and no cross-references is the signature of a wrong architecture, not a hostile binary.
  • A pointer that shrank: A value that survives a call as a small positive number was written through a 32-bit view; the truncation is in the code.
  • Improbable constants in a table: High-half garbage in a pointer table is a signed pointer on an image using pointer authentication, not encrypted data.
  • Stubs the tool cannot type: A thunk, a PLT stub or a hand-written primitive has no prologue and no inferable signature, so the convention is unknown because none was declared.