跳到主要内容

REA 逆向分析工作流

收藏0

在授权前提下对原生二进制、JavaScript/Electron、APK、固件等做取证、反编译、版本比对与证据化分析的工作流手册;是 REA MCP 服务器的配套指令(需另装工具本体),仅限合法安全研究。

让 AI 安装

github最新版本 0.1.1更新于 2026-10-19下载 0 次2 个版本

references/native-and-artifacts.md

18.5 KB查看排版效果
1# Native, managed, and packaged artifacts
2
3## Go build metadata
4
5Use `inspect_go_binary` for an explicit local ELF, PE or thin Mach-O when the
6question concerns the embedded compiler version, module/dependency versions,
7local replacements or build settings. No `open_binary`, Go installation or
8target execution is required. The CLI equivalent is `inspect-go-binary PATH`.
9Preserve artifact SHA-256, original file ranges, framed module bytes and every
10unparsed module-text line. A missing record is an unknown, not proof of a
11non-Go binary; observed metadata does not authenticate its claims. Function,
12source and type recovery remain a separate native-analysis question.
13
14## Rust dependency metadata
15
16Use `inspect_rust_binary` for an explicit local ELF, PE, or thin Mach-O when
17the question concerns the cargo-auditable crate list embedded in `.dep-v0`
18(Mach-O: `__DATA,.dep-v0`). No `open_binary`, Rust installation, or target
19execution is required. The CLI equivalent is `inspect-rust-binary PATH`.
20Preserve artifact SHA-256, package order, dependency indices, and the section
21file range. A missing section is null metadata, not proof the binary has no
22dependencies. An omitted package kind stays null. A rustc commit hash is
23inferred from a read-only `/rustc/<40-hex>/` path and does not by itself
24identify the compiler. See [Rust binaries](https://github.com/morluto/rea/blob/main/docs/rust-binaries.md).
25
26## SQLite snapshots
27
28Use `inspect_sqlite_database` with an explicit local database snapshot for its
29schema and optional rows from one exact ordinary table. It requires Node.js
3024.x >=24.15 or 26+ with the native `DatabaseSync.limits` API. It also consumes the
31existing sibling `-wal`; retain both original digests when citing its result.
32Default output is a compact inventory; a selected table expands only its own
33schema and samples 20 rows. Select `columns` to avoid irrelevant or large cells,
34and request `schema_scope: "database"` only for complete schema details.
35Choose `row_limit` when a finite sample is useful and keep truncation and
36unspecified row order explicit. Virtual tables, shadow tables and views are
37schema facts, not row-read targets. REA inspects private copies and leaves
38the source files untouched; obtain a coherent quiescent database/WAL snapshot
39before inspection. See [SQLite snapshots](https://github.com/morluto/rea/blob/main/docs/sqlite-databases.md).
40
41## Recorded Linux crashes
42
43Use `inspect_recorded_crash` with an explicit Linux x86-64 ELF core path to
44inspect historical thread registers, signals, raw notes and original file
45ranges. It is independent of the active disassembler target. Source-bound
46register values and note bytes are observations; missing notes, signal-thread
47association and current executable/library identity remain unknown. PIDs are
48historical metadata and never authorize live attach or control.
49
50The optional `include_debugger_context` facet adds mapping candidates through
51caller-supplied GDB/pwndbg in an owned core-only session. Display names do not
52establish current file identity; zero reported flags leave permissions unknown.
53Requested unavailable context fails with setup guidance. See
54[recorded crashes](https://github.com/morluto/rea/blob/main/docs/recorded-crashes.md)
55for exact upstream profiles, bounds and verification coverage.
56
57## Offline ELF layout
58
59Use `inspect_binary_layout` with an explicit local ELF path for file-backed
60sections, symbols, relocations, linkage names, and static mitigation inferences
61without opening a disassembler target. When that complete record is already
62retained, call `inspect_analysis_view` for a summary, mitigations or linkage
63facet, one section or symbol, or a stable page. Do not re-run the decoder to
64read a single object.
65
66## Offline WASM
67
68Use `inspect_wasm_artifact` with caller-supplied WABT for selected local bytes.
69For counts, validation and WAT identity, select `detail: "summary"` on the first
70MCP call. The complete original Evidence stays retained; use
71`normalized_result.parent_evidence_id` for exact exports or text pages. Omitted
72or complete detail keeps the existing complete result.
73For a completed result, use `inspect_analysis_view` with its reported retained
74reference for a summary or `view: {kind: "wasm", facet: "exports", offset: 0, limit: 32}`.
75Facets also include sections, imports, candidates, glue, WAT, headers, details
76and tool profile. Text offsets count UTF-16 code units; follow `next_offset`.
77The complete source remains retained after an oversized MCP reply. No target
78execution or network acquisition is implied, and WAT is decoded representation.
79
80## Native targets
81
82After `open_binary`, use focused search, procedure, or function tools directly.
83Use `binary_overview` when target metadata or inventory context helps answer the
84question. Prefer literal search, names, decompilation, callers, callees, and
85cross-references. Addresses and recovered pseudocode are analysis observations,
86not original source. Provider unavailability and unsupported metadata remain
87unknown rather than false.
88
89For a completed `analyze_function` dossier, use `inspect_analysis_view` with
90`view: {kind: "native", facet: "value_flow_operations", offset: 0, limit: 32}`
91and the exact retained Evidence ID to read selected facts without reanalysis.
92Native facets also include procedure, pseudocode, assembly, basic blocks,
93comments, callers/callees, references, unresolved calls, referenced strings and
94names, the native API record, and value-flow summaries. Pseudocode offsets and limits count UTF-16
95code units; use the returned `next_offset` for continuation. Provider limitations
96and unavailable facts remain explicit; the complete parent Evidence is retained.
97
98`inspect_macho` on a large framework returns megabytes of imports and exports.
99Select `detail: "summary"` for slice identity, UUID and per-collection counts,
100then page rows with `view: {kind: "macho", facet: "exports", offset: 0, limit: 64}`
101and `normalized_result.parent_evidence_id`. Facets are entrypoints,
102architectures, build_metadata, load_commands, dependencies, imports, exports,
103segments and provenance. `source_exhaustive: false` means unreturned symbols
104may exist.
105
106To see which functions or Objective-C methods a Mach-O actually calls in one
107run, use `observe_native_calls` with explicit breakpoints and a bounded
108`duration_ms`/`max_events`. It launches a new process under LLDB, so the target
109runs and may change files or use the network. Hardened-runtime targets need the
110`get-task-allow` entitlement.
111
112Use `binary_session` with no arguments to check the open target, selected
113provider, and alignment. Its default `result.tool_availability` carries a
114complete inventory grouped by shared facts. Expand each group's `names` and
115inherit the inventory-level client requirements unless a group overrides them;
116availability, reasons, remediation, modes, and flags remain inline. The
117`effects` and `annotations` arrays name true flags from fixed vocabularies, so an
118omitted known flag is false. `tools/list` remains the canonical source for full
119tool schemas when target or provider state changes.
120
121Provider capability groups carry provider identity and ordered limitations.
122Prepend each set's `shared_limitations` to a group's `limitations` to recover the
123operation's full ordered list. Candidate capabilities describe possible
124providers. Top-level session capabilities describe the current route, and
125`analysis_provider_binding` identifies the selected provider.
126
127## Static memory and original file bytes
128
129For Ghidra, `read_bytes` reads initialized analysis memory, including loader
130fixups; it does not read a running process. Check `returned_bytes` and `complete`
131before decoding a table. An incomplete read is missing coverage, not a zero-filled
132tail. Use `list_segments` to inspect the selected block's initialization and address-space
133facts, and retain unavailable facts as unknown.
134
135Use `address_to_file_offset` to anchor one observed address to original file
136bytes. A mapping for the first address does not establish a contiguous mapping
137for an entire table, and loader fixups can make analysis bytes differ from source
138bytes. Keep source ranges and analysis-memory observations separate.
139
140A pointer table can refer to writable slots populated by a constructor rather
141than directly to immutable resources. An uninitialized block or an observed zero
142does not establish the slot's later runtime value. Follow `xrefs` and the relevant
143writer's assembly or pseudocode; distinguish recorded assignments from inferred
144execution order. Do not replace unreadable bytes with zeros or conclude that a
145resource is absent without the necessary initialization evidence.
146
147## DOS MZ with Ghidra
148
149For an admitted DOS MZ target, use `inspect_native_load_image` to check measured
150loaded bytes, file mappings, relocations and the entry against the immutable
151snapshot. Keep `mismatch` and `unsupported` explicit. Verified import covers the
152reported static image, not runtime DOS or PC-98 hardware behavior.
153
154For Ghidra decompilation, `procedure_pseudo_code` also accepts `procedure: "file-offset:0x..."`; CLI `rea decompile <path> --file-offset=0x... --provider ghidra` resolves the source byte offset internally. An unresolved 0x-prefixed numeric procedure selector also falls back to a unique file mapping. Existing symbols and analysis addresses win; multiple mappings fail as ambiguous. Preserve the returned file-offset and address locations and raw selection observations. ELF virtual addresses are distinct from file offsets; never assume an arbitrary offset plus image base is an analysis address.
155
156Complete function body ranges use inclusive ends and can contain gaps. Do not
157treat the enclosing span as code.
158For packed targets, retain the original and separately derived artifact identities;
159decompiling an unpacking stub does not recover the unpacked program.
160
161When reading Objective-C dispatch metadata, distinguish class implementation
162methods from protocol requirements: class methods report null requirement
163flags, while decoded protocol declarations retain required and optional facts.
164Property attributes remain raw name/value tokens; use the property's
165`atomicity` field for the decoded `N` marker or the default atomic behavior.
166Null class/meta flags, ivar counts, atomicity, or read-only values mean the
167selected provider did not establish that fact. Symbol names alone do not prove
168that a class is a root class or has no ivars.
169
170## Managed PE/CLI
171
172Start with `inspect_managed_artifact`. REA's canonical managed inspection is
173execution-free: do not claim it loaded, reflected, executed, or resolved the
174assembly. Keep managed/native boundaries and unavailable reconstruction facts
175explicit. A bring-your-own reconstruction oracle is separate from the canonical
176parser and must not become an implicit setup dependency.
177
178For identity/classification questions, `inspect_managed_artifact` can explicitly
179select `detail: "summary"` on the first MCP call. It retains complete metadata
180and returns a linked overview with full classification/evidence, nullable
181module/MVID, frameworks, metadata coverage/issues/limitations and returned-row
182counts. Default complete requests remain unchanged. Read original rows with
183`inspect_analysis_view`, source `normalized_result.parent_evidence_id`, and
184`view: {kind: "managed", collection: "attributes", offset: 0, limit: 16}`.
185Collections are `references`, `resources` and `attributes`. Paging does not
186repeat parsing. Returned-row exhaustion
187does not prove complete metadata or absence under partial/unavailable coverage;
188preserve build-local tokens and their artifact/MVID scope.
189
190`inspect_managed_members` always returns the assembly-wide `member_refs`, even
191for one selected type. For questions about a selected type, select
192`detail: "summary"` with `type_names`; it returns the selection (with unmatched
193names), coverage and per-collection counts. Page rows with
194`view: {kind: "managed-members", collection: "call_edges", offset: 0, limit: 64}`
195over `types`, `exported_types`, `fields`, `methods`, `member_refs`, `call_edges`,
196`field_accesses` or `user_strings`.
197
198### .NET NativeAOT
199
200NativeAOT binaries contain native machine code, so ordinary CIL decompilers
201cannot recover the original method bodies. When managed metadata/CIL is absent,
202classify that as a native-analysis route rather than claiming source recovery.
203Open the native image with the selected deep provider and inspect functions,
204strings, calls, and references; describe decompiler output as pseudocode and
205inference.
206
207NativeAOT images can be PE/COFF, ELF, or Mach-O executables and shared
208libraries. Use file bytes and loader metadata rather than suffixes to identify
209them. For packaged apps, inventory/extract with REA's artifact tools and retain
210the exact contained image identity. PDB, ELF debug, or dSYM sidecars are
211additional evidence only when the provider accepts and matches them.
212
213REA has a built-in read-only snapshot parser for x64 PE targets with .NET 8 RTR
2149.1 metadata. An optional headless Ghidra adapter adds database annotations and
215broader metadata recovery on Linux; it requires an explicitly configured
216NativeAOT JAR. These are separate routes. The built-in parser also runs on
217Windows Ghidra P0; read frozen literals from its report, because
218`search_strings` does not include them. See the
219[NativeAOT guide](https://github.com/morluto/rea/blob/main/docs/ghidra-nativeaot.md)
220for setup, supported layouts, and host restrictions. Preserve binary identity
221and distinguish derived metadata from Ghidra database observations. Recovered
222types and native pseudocode are not original C# source. Windows Ghidra P0 has
223no database mutation authority.
224
225## Packages and extraction
226
227Use `inspect_artifact` for application bundles, archives, ZIP/APK/IPA/MSIX/AppX,
228ASAR, or DMG inputs when the artifact graph and findings help answer the
229question. It returns the complete artifact graph inline. Cite graph manifest
230IDs when using them.
231
232For an IPA or a macOS `.app`, ZIP, or DMG, pass the inventory Evidence to
233`project_apple_application_graph`. It reports application roots and nested
234bundles by path convention: app extensions, XPC services, frameworks, login
235items, system and driver extensions, and plug-ins. It also lists privileged
236helpers, launchd plists, symlinks, and each bundle's `info_plist_path` and
237executable candidates. Roles are path conventions, not parsed plists; read the
238listed plists with `inspect_plist`.
239
240After `open_binary` on a `.app` or Mach-O, use `trace_dylib_resolution` to see
241which file each `@rpath`, `@loader_path` and `@executable_path` load reaches for
242every executable in the bundle. It also lists missing or weak loads and earlier
243`@rpath` candidates that are absent. Narrow large bundles with `roots` or
244`architecture`. System paths stay undetermined because the dyld shared cache
245provides them.
246
247Use `extract_artifact` when materialized files are needed. It extracts the active
248target and accepts optional `integrity_policy`; see the [MCP contracts](https://github.com/morluto/rea/blob/main/docs/mcp-contracts.md).
249It materializes all regular files into a fresh temporary directory chosen by
250REA. Symlinks and encrypted entries are inventory facts, not extractable files.
251The result reports the materialized directory; callers do not choose the
252destination. No separate permission grant is needed.
253
254Native DMG traversal automatically uses a read-only mount on supported macOS
255hosts, with an owned temporary mount directory and cleanup. It needs no approval
256flag. Unsupported hosts or mount failures remain explicit limitations; do not
257claim child inventory when only root identity is available. Extraction is a
258separate filesystem-writing operation.
259
260For headerless DOS COM, explicitly open with `format: "dos-com"` (CLI
261`--target-format dos-com`). Inspect the load image before trusting function
262analysis: the entry is `0x10100`, file offset zero, with imposed real-mode segment
263context. PSP/stack/device state remains unmodeled. See [DOS guide](https://github.com/morluto/rea/blob/main/docs/ghidra-dos.md).
264
265For other headerless images (embedded firmware without ELF/Mach-O/PE/MZ
266headers), open with `format: "raw-binary"`, `architecture` (`x86`, `x86_64`,
267`arm`, `arm64`, `6502`, or `m68k`), and `entry_point` (`0x` hex). File offset 0 is mapped at
268that address. Hopper and IDA refuse this interpretation; Ghidra uses
269`BinaryLoader` with a generic language: big-endian for `m68k`, little-endian
270otherwise. Big-endian ARM, Thumb-only, and Cortex-M variants are unsupported.
271`6502` selects NMOS 6502; the entry and complete file mapping must fit within
272`0x0000..0xffff`. 65C02, 65816, cartridge containers, bank switching, and mapper
273semantics are unsupported. `m68k` requires an even entry and decodes the 68040
274superset of the 68000 family; Amiga/Atari containers and vector-table entry
275discovery are unsupported. Windows Ghidra P0 admits raw images only for `6502`. See [raw binary guide](https://github.com/morluto/rea/blob/main/docs/raw-binary.md).
276
277### Function annotations in Ghidra
278
279Use `annotate_native_function` for one function name and/or entry comments, with at least one explicit change. Review its annotation readback and refreshed dossier inline. Changes are atomic and session-scoped; empty comments clear them, omitted fields preserve them. Later MCP calls observe edits until close. CLI `annotate-native-function` returns the updated analysis before discarding the session. Original executable bytes are unchanged; edits invalidate immutable snapshots. Windows P0 does not admit database mutations. For naming only, `set_address_name` / `set_addresses_names` also work with Ghidra: they name function entries or data addresses (primary labels) and return compact per-address success booleans instead of a dossier.
280
281## Offline PE resource inventory
282
283Use `inspect_pe_resources` with an absolute `path`, or
284`rea inspect-pe-resources ./selected.exe --json`, for portable PE32/PE32+
285resource inspection without opening a native target. Preserve returned Evidence:
286type/name/language IDs and UTF-16 names, original directory/data/payload ranges,
287code pages, payload hashes and static icon-group references. Same-language icon
288resolution is explicit; missing references and size mismatch remain visible.
289Other payloads are opaque, and this operation does not decode images or simulate
290Windows resource loading. Consult the budgets and supported tree profile in
291[offline binary diagnostics](https://github.com/morluto/rea/blob/main/docs/binary-diagnostics.md).
292
293For exact core-module import/export differences, use `compare_wasm_interfaces`
294with two complete inspection Evidence records (or current-session retained
295references) and explicit scope. Preserve unknown types/duplicate names; static
296interface equality is not runtime compatibility. CLI accepts complete inline
297Evidence in `rea compare-wasm-interfaces input.json --json`.

文件内容是平台检查时读出的文本,只供查看。平台不会运行包里的任何脚本或程序。