The ELF tool
Android native libraries (lib*.so) and other ELF binaries: the header, program headers (segments), section headers, dynamic entries, symbols, relocations and notes. For 64-bit little-endian ARM64 binaries it also lists the functions (JNI entry points, exported and local symbols, PLT imports) and shows each one as Assembly or Decompiled C-like pseudocode, with the JNI bindings (Java_… exports and RegisterNatives tables) in their own section.
The code view is built from three libraries that every ARM64 viewer shares (Mach-O, ELF, IL2CPP, and the Dart viewer for the disassembler); they are documented below so they can be used elsewhere. Each is a JavaScript module that exports one class; a page or a module worker imports it (paths relative to the importing file), and a module imports its own dependencies. How the decompiler works step by step, and where it can be wrong, is explained in the decompiler guide. Swift symbol names are made readable by a fourth library, lib/swift-demangle.js, documented in the Mach-O guide.
- Arm64Disassembler (lib/arm64-disasm.js)
- DecompilerCore (lib/decompiler-core.js)
- Arm64Decompiler (lib/arm64-decompiler.js)
- ElfFile (lib/elf.js)
- Arm64Function (lib/arm64-function.js)
1Arm64Disassembler
lib/arm64-disasm.js decodes one AArch64 instruction word at a time: the base integer instructions, loads and stores (pairs, exclusives, acquire/release, LSE atomics), arm64e pointer authentication, scalar floating point and the common SIMD moves. A word it does not know comes back as .inst 0x…. A module with no dependencies; the class has static members only.
import { Arm64Disassembler } from "../lib/arm64-disasm.js";
| Method | What it does |
| Arm64Disassembler.decode(word, address, options) | The instruction { mn, ops } (mnemonic and operand text) plus the facts a viewer needs when they apply: target (branch, literal, adr/adrp), call, cond, indirect, ret, lit, register numbers rd/rn/rm, imm and addImm (add/sub immediate), adrp (the page), movz / movk, and mem { base, imm, rt, rt2, pair, load, wb } for loads and stores. address is the word's address, for PC-relative targets. options.dartNames chooses Dart VM register names (and is remembered). |
| Arm64Disassembler.setDartNames(on) | Whether registers are named by their Dart VM role (x26 → THR, x27 → PP, x22 → NULL, …). On by default; the Mach-O, ELF and IL2CPP viewers turn it off. |
| Arm64Disassembler.DART_REG | Register number → Dart VM role name. |
import { Arm64Disassembler } from "../lib/arm64-disasm.js";
Arm64Disassembler.setDartNames(false);
const view = new DataView(code.buffer, code.byteOffset, code.byteLength);
for (let offset = 0; offset + 4 <= code.length; offset += 4) {
const instruction = Arm64Disassembler.decode(view.getUint32(offset, true), start + offset);
console.log((start + offset).toString(16), instruction.mn, instruction.ops); // 1f2c bl 0x2a40
}
2DecompilerCore
lib/decompiler-core.js is the language-neutral half of the decompilers (ARM64 here, IL in the .NET viewer): an intermediate representation of expressions and statements, control-flow analyses, SSA, propagation, dead-code removal, a structurer that turns the graph back into if / while / for / do / switch, and an HTML renderer. A module with no dependencies; everything is a static method (or table) of DecompilerCore, so the methods can also be taken out of the class (const { walk } = DecompilerCore).
import { DecompilerCore } from "../lib/decompiler-core.js";
The IR is made of plain objects whose kind is in type; the other fields have full names. The node kinds themselves stay short tags ("reg", "bin"…).
| Node | Shape |
| reg | { type: "reg", name, version }: a register (or a local's name) and its SSA version (0: the value on entry). |
| lit, flit | { type: "lit", value } (a 64-bit BigInt); { type: "flit", value, bits } (a Number). |
| str, sel, sym, addr | { type: "str", text }, { type: "sel", text }, { type: "sym", name, address }, { type: "addr", value }. |
| stk, stkaddr, load | { type: "stk", offset } (a stack slot; stkaddr: its address); { type: "load", address, size, signed }. |
| bin, un, tern | { type: "bin", operator, left, right, unsigned }, { type: "un", operator, operand }, { type: "tern", condition, whenTrue, whenFalse }. |
| cmp, cond | { type: "cmp", kind, left, right } sets the flags; { type: "cond", conditionCode, flags } tests them ("eq", "lt", "hs"…). |
| call, msg | { type: "call", name, callee, arguments }; { type: "msg", receiver, selector, arguments, isSuper } (Objective-C). |
| statements | { type: "assign", destination, value }, { type: "store", address, value, size }, { type: "expr", value }, { type: "ret", value }, { type: "if", condition, taken }, { type: "goto", target }, { type: "switch", value, cases: [{ value, target }], defaultTarget }, { type: "phi", destination, sources: [{ predecessor, value }] }, { type: "clobber", registers }. |
| graph | { entry, blocks: Map(id → { id, statements, successors, predecessors, next }) }; a block's last statement is its terminator, or it falls through to next. |
The header of lib/decompiler-core.js lists every node; front ends add their own kinds with DecompilerCore.defineNodeType. The methods below are static: DecompilerCore.walk(…).
| Method | What it does |
| registerNode(name), literalNode(value), binaryNode(operator, left, right, unsigned), unaryNode(operator, operand) | Build a register, a 64-bit literal, a binary and a unary expression. |
| walk(e, visit), mapExpression(e, rewrite), eachChild(e, visit), clone(e) | Visit every node; rewrite bottom-up (return a replacement or undefined); visit each child slot with (get, set); deep copy keeping BigInts. |
| defineNodeType(type, childKeys, { effect, memory, cheap }) | Declare a node type a front end adds: the fields that hold its child expressions, and whether it has side effects, reads memory or may be copied freely. DecompilerCore.CHILD_KEYS is the table of child fields by type. |
| simplify(e) | Constant folding and algebraic clean-ups (x + 0, (x + 1) + 2, *&x, f() == 0 → !f(), bit patterns moved into FP registers…). |
| hasEffect(e), readsMemory(e), isCheap(e) | Whether an expression calls, reads memory, or is cheap enough to repeat at every use. |
| statementSlots(statement), statementDefinitions(statement) | The expression slots a statement reads ({ get, set }), and the registers it defines. |
| computeDominators(cfg), computePostDominators(cfg), dominates(idom, a, b) | { idom, rpo, reachable }; the immediate post-dominators (a virtual "EXIT" after the returning blocks); whether a dominates b. |
| buildSSA(cfg, dom) | Places φ nodes and numbers every definition; returns { defs: Map("name#version" → { statement, block }) }. Unreachable blocks are removed. |
| computeUses(cfg) | Map("name#version" → [{ statement, block, inPhi }]). |
| propagate(cfg, dom, ssa, { cheap, after }) | Moves values into their uses where that is safe (no call or store crossed); after() runs after each round and returns whether it changed anything. |
| removeDeadCode(cfg), variableGroups(cfg), mergeShortCircuit(cfg) | Removes unread definitions (calls stay as statements); groups the SSA values a φ joins into one variable (find("name#version")); merges two tests that share a target into one && / || condition. |
| structure(cfg, hooks) | { lines: [{ indent, html }], usedGoto }. hooks: statement(s), condition(c, negate), expression(e), label(id), optional exitId. |
| makeRenderer(hooks) | { expression(e, precedence), condition(c, negate), statement(s) } producing HTML with the code view's classes (kw, fn, num, str, mem…). Optional hooks: node, name, stack, callName, callFull, statement. |
| negateCondition(c), lowerCondition(c), escapeHtml(text) | Negate a condition; turn a condition code over a cmp into a comparison (cmp(a, b) + lt → a < b, including ccmp chains); escape HTML. |
import { DecompilerCore } from "../lib/decompiler-core.js";
const { registerNode, literalNode, binaryNode } = DecompilerCore;
const cfg = { entry: 0, blocks: new Map([
[0, { id: 0, statements: [
{ type: "assign", destination: registerNode("x0"), value: binaryNode("+", registerNode("x0"), literalNode(1)) },
{ type: "ret", value: registerNode("x0") }
], successors: [], predecessors: [], next: null }]
]) };
const dom = DecompilerCore.computeDominators(cfg);
const ssa = DecompilerCore.buildSSA(cfg, dom);
DecompilerCore.propagate(cfg, dom, ssa);
const renderer = DecompilerCore.makeRenderer({});
const result = DecompilerCore.structure(cfg, {
statement: s => renderer.statement(s),
condition: (c, negate) => renderer.condition(c, negate),
expression: e => renderer.expression(e, 0),
label: id => "loc_" + id
});
// result.lines: [{ indent: 0, html: "return x0 + 1;" (as HTML) }]
3Arm64Decompiler
lib/arm64-decompiler.js turns one function's decoded instructions into pseudocode, on top of DecompilerCore. It builds the control-flow graph (jump tables and arm64e checks included), lifts each instruction (the stack pointer is tracked so stack memory becomes named slots, flags become comparisons, calls follow the ARM64 calling convention), then runs the core's analyses and the language passes. The module imports lib/decompiler-core.js and lib/swift-demangle.js (readable Swift names) itself; the class has static members only.
import { Arm64Decompiler } from "../lib/arm64-decompiler.js";
| Method | What it does |
| Arm64Decompiler.decompile(fn, env) | { lines: [{ indent, html }], text, usedGoto, stats: { blocks, insns } }. fn = { start, end, insns, addrs } (the decoded instructions and their addresses). env answers questions about the binary: name(address) → { name }, data(address, isLoad) → an IR expression (a string, a symbol…), passes, read(address, size, signed) for jump tables, arity(address), link(address), mem(address, size), params, jni, isVoid, signature. Arm64Decompiler.lastCfg keeps the last graph for debugging. |
| Arm64Decompiler.switchTables(fn) | [{ addr, size }]: the jump tables the function reads, to fetch before decompiling so env.read can answer. |
| Arm64Decompiler.argUsage(insns) | { n, self, indirect } from a function's first instructions: how many argument registers (x0…) it reads before writing them, whether it reads x20 (Swift self) and x8 (indirect result); null for a stub that jumps straight on. |
| Arm64Decompiler.buildCFG(fn, env) | The control-flow graph alone. |
| Arm64Decompiler.passes | objc (messages, ARC, ivars, block literals), swift (string literals, casts, reference counting), libc (argument counts and variable names for common C imports), jni ((*env)->FindClass(env, …) → env->FindClass(…); set env.jni to { env: true } in Java_… functions, { vm: true } in JNI_OnLoad). A pass may provide args, arity, rewrite, rewriteAny, cleanup, render and hint. |
| Arm64Decompiler.jniName(symbol) | Java_com_example_Foo_bar__I → { full: "com.example.Foo.bar", sig: "I" }, or null. |
| Arm64Decompiler.lowerFirst(text), Arm64Decompiler.JNI_ENV | A variable name from a type or selector (URLString → urlString); the JNIEnv function table by slot. |
import { Arm64Disassembler } from "../lib/arm64-disasm.js";
import { Arm64Decompiler } from "../lib/arm64-decompiler.js";
const insns = [], addrs = [];
for (let address = start; address < end; address += 4) {
insns.push(Arm64Disassembler.decode(wordAt(address), address, { dartNames: false }));
addrs.push(address);
}
const result = Arm64Decompiler.decompile({ start, end, insns, addrs }, {
name: address => symbols.has(address) ? { name: symbols.get(address) } : null,
data: (address, isLoad) => null,
passes: [Arm64Decompiler.passes.jni, Arm64Decompiler.passes.libc],
params: ["env", "thiz"],
jni: { env: true }
});
console.log(result.text); // return env->NewStringUTF("Hello from C");
4ElfFile
lib/elf.js reads ELF files — executables, shared libraries, objects, core dumps — from a Blob with ranged reads, so only the headers and the small metadata sections are loaded. For little-endian AArch64 ELF64 files it also builds a code model: functions from the symbol tables, PLT stubs named through .rela.plt, JNI entry points (Java_… exports, JNI_OnLoad, RegisterNatives tables found as relocated {name, signature, fnPtr} triples) and the callbacks the decompiler and the code browser need. The module imports lib/arm64-disasm.js and lib/arm64-decompiler.js (for jniName); it has no DOM and works in a module worker. ElfFile.parse returns an ElfFile: the parsed fields plus the methods below.
import { ElfFile } from "../lib/elf.js";
| Method | What it does |
| ElfFile.parse(blob, fileName) | Promise of an ElfFile with the fields { fileName, fileSize, header, segments, sections, dynamic, symtabs, notes, needed, soname, runpath, buildId, stripped, truncated, mapSkipped, blob }. header has the e_ident fields (cls, data, is64, le, osabi) and the ELF header fields by their C names; each segment lists the sectionNames it contains; dynamic.entries have tag, name, val and str (NEEDED, SONAME, RPATH, RUNPATH) or decoded flags; each of symtabs is { section, kind: "dynsym" | "symtab", count, truncated, items }. Addresses above 253 stay BigInt. Throws on a file that is not ElfFile. |
| elf.hasArm64Code() | True for a little-endian ELF64 AArch64 file with executable sections (the code model needs one). |
| elf.vaToFileOffset(address) | The file offset of a virtual address through the PT_LOAD segments, or -1. |
| elf.codeModel() | Promise of the code model (built once, then cached): starts (every function start, sorted: symbols, natives, PLT stubs and bl targets), ranges (code outside the PLT), functions (address → { name, exported }), names, stubs (PLT stub → import), natives (address → { name, sig }), gotNames, relocatedPointers, jni ([{ addr, cls, method, sig, symbol, how: "export" | "lifecycle" | "RegisterNatives" }]), and the callbacks nameOf(address), describe(address, isLoad) (a listing comment), data(address, isLoad, size, floatingPoint) (a decompiler expression: string, symbol or floating-point literal), memory(address, size), sectionEnd(address), isCode(address) and read(address, length). |
| ElfFile.jniParameters(model, address) | { params, jni, ret } for the decompiler: env, thiz and the return type from the signature for a Java_… or registered native, vm, reserved for JNI_OnLoad; null for other functions. |
| ElfFile.jniReturnType(signature) | (Ljava/lang/String;)I → jint (jstring, jobject, jarray…). |
| ElfFile.jniSignatureToJava(signature) | (Ljava/lang/String;[BI)Z → boolean (String, byte[], int). |
| ElfFile.fridaHook(library, entry, bias) | A Frida Interceptor.attach script for one jni entry: by export name when it has a symbol, else by offset from the module base (bias = the lowest PT_LOAD address). |
| ElfFile.machineName(machine), ElfFile.flagList(value, table), ElfFile.sectionFlagLetters(flags), ElfFile.segmentFlagString(flags), ElfFile.readBytes(blob, start, end) | Helpers: 183 → AArch64; the names of the set bits; WAX-style section flags; r-x-style segment flags; a ranged read. |
| ElfFile.CLASSES, DATA_ENCODINGS, OS_ABIS, TYPES, MACHINES, SECTION_FLAGS | Name tables for the header fields and section flags. |
import { ElfFile } from "../lib/elf.js";
const elf = await ElfFile.parse(file, file.name);
console.log(elf.header.machine, elf.needed, elf.soname, elf.buildId);
if (elf.hasArm64Code()) {
const model = await elf.codeModel();
for (const entry of model.jni) {
console.log(entry.cls, entry.method, ElfFile.jniSignatureToJava(entry.sig), "0x" + entry.addr.toString(16));
}
console.log(model.nameOf(model.starts[0]), model.describe(0x1234, true));
}
5Arm64Function
lib/arm64-function.js works with the functions of an ARM64 binary through a source object that reads its code: starts (sorted function addresses), sectionEnd(address), read(address, length) (a Promise of bytes), ranges (the executable ranges), name(address), describe(address, isLoad) and isStub(address). The code browser of this page (common/a64-codeview.js) is built on it. The module imports lib/arm64-disasm.js and lib/arm64-decompiler.js; the class has static methods only.
import { Arm64Function } from "../lib/arm64-function.js";
| Method | What it does |
| Arm64Function.findStart(source, address) | The start of the function holding the address (the address itself for code before the first start), or null when it isn't code. |
| Arm64Function.load(source, start, { cap }) | The function, disassembled: { start, end, insns, addrs, truncated, tables }, with the bytes of its switch tables. cap (200,000) limits the instructions. |
| Arm64Function.calleeArity(source, insns, cache) | Fills a Map with the argument usage of every function the instructions call (for the decompiler's call arguments). |
| Arm64Function.listingNotes(fn, source, nameOf) | For each instruction: whether a branch lands on it, a branch target inside the function, a call target outside it ({ name, addr }), or a comment on the address that adrp / add / a load computes. |
| Arm64Function.crossReferences(source, onYield) | One scan of all code: { calls, refs }, Maps from a target address to [[function, site], …] (direct calls and tail branches; address references). |
import { Arm64Function } from "../lib/arm64-function.js";
const fn = await Arm64Function.load(source, Arm64Function.findStart(source, 0x10c8));
for (const row of Arm64Function.listingNotes(fn, source, source.name)) {
console.log(row.address.toString(16), row.instruction.mn, row.instruction.ops, row.note || (row.link && row.link.name) || "");
}
const { calls } = await Arm64Function.crossReferences(source);
console.log(calls.get(fn.start)); // who calls it