* docs(development): add an artifact format guide and contributor skill Document the files, registration points, parsing rules, limits, tests and docs a new inspect_artifact format needs, and add a rea-artifact-format skill for the judgment calls: establishing a layout from samples, naming only established fields, and what a reader exposes. * docs(development): correct artifact format registration and evidence guidance
7.9 KiB
Adding an artifact format
This guide covers adding a file format that inspect_artifact recognizes and
extract_artifact can extract, such as a firmware image, a ROM, or a compiled
program container. Read it with the tool design guide and the
testing guide. Format inspection and ordinary extraction are in
contribution scope; decrypting or
otherwise recovering protected content is not, and needs a maintainer decision
first.
Choose the shape
Most formats are a container whose root has header facts and whose entries are regions of the file. Pick the reader base from what the entries are:
| Entries are | Use |
|---|---|
| Byte ranges stored in the file | PositionalArtifactReader; nothing is retained, and entries marked encrypted are refused on open |
| Bytes REA decodes, such as decompressed or de-interleaved data | DecodedRegionArtifactReader; the whole file is buffered under a fixed ceiling |
| Nothing to list; a dedicated tool reads the file | A standalone format in STANDALONE_ARTIFACT_FORMATS, routed to that tool |
Start from the nearest existing format of the same shape. Image4 and Nintendo DS are positional readers; bFLT, UF2 and SWF decode regions.
Files to add
| File | Owns |
|---|---|
src/domain/<format>.ts |
Magic predicate, header parse and layout. The only place the format's bytes are interpreted |
src/domain/formatMetadata/<format>Metadata.ts |
Strict zod schemas for the root metadata kind and the entry metadata kind |
src/artifacts/<Format>ArtifactReader.ts |
Maps the parsed layout to entries and coverage, and parse failures to reader failures |
src/domain/<format>.fixture.ts |
A synthetic file builder for tests |
src/domain/<format>.test.ts, src/artifacts/<Format>ArtifactReader.test.ts |
Parser semantics, then inventory and extraction |
Register the format
A new format id is listed in several places. The typecheck fails when one of the first group is missing; the second group is not enforced, so check each.
Enforced by tsc:
src/domain/artifactGraph.ts:ARTIFACT_FORMAT_IDSand the content-format list.src/resources/ArtifactReader.ts: the readerformatunion.src/artifacts/artifactFormats.ts: thecontainer(...)descriptor, with areaderLimitationthat says what is and is not read.src/domain/artifactFormatRecognition.ts: the recognized-format union.src/domain/targetFormats.ts: the target format kind, usuallyarchive.src/domain/artifactFormatMetadata.ts: both metadata schemas in the union, and adeclarationsByKindentry deciding what artifact comparison compares.
Not enforced:
src/domain/artifactFormatRecognition.ts: a recognizer inARTIFACT_FORMAT_RECOGNIZERS. Without it the format is never recognized.src/domain/analysisView/artifactInventoryView.ts: the formats whose summary includes hash status counts.src/domain/native/peOverlay.ts:PE_OVERLAY_LEADING_FORMATS, so PE overlay inspection can name the format.src/application/binary/TargetFormatVocabularies.test.ts: the vocabulary row.scripts/ci/scopes.mjs: globs for the new reader, parser and guide.scripts/verify/fixed-ceiling-registry.json: any fixed ceiling; see limits.
Recognizers run in order, and the first claim wins. Put a short or common magic after recognizers whose claim is more specific, and claim only what the magic establishes; let the parser refuse a file that is too short.
Parse once, at the owning boundary
- Read integers through
BinaryReaderfromsrc/domain/binaryContainer.ts. The architecture guards reject rawBufferandDataViewnumeric reads. - Throw
ParseFailureErrorthroughunrecognizedInput,malformedInput,truncatedInputandunsupportedInput, with the offset, field and, for truncation, the available and required bytes. Uselimitonly for a named allowance. - Keep partial facts. A region that cannot be served is omitted with a
limitation and coverage
unknown, not a whole-file refusal. - Name a field only when its meaning is established from the specification or
from observation against known inputs. Report other fields raw with their
offset, and name enum values only where observed; anything else is
unknown. - Decode text strictly, for example
new TextDecoder(..., { fatal: true }), so ill-formed input is reported asmalformedrather than silently replaced. - Mark an entry
encryptedonly when the format declares encryption. Bytes that only look opaque keepencrypted: falsewith a limitation saying their encoding is unknown, and get a neutral name such as.storedrather than an extension they do not hold. - Preserve declared fields, including public cryptographic values such as IVs and key identifiers. Redact only transport credentials and values the format explicitly marks as sensitive; do not infer secrecy from a field's name.
Limits
An admission limit must follow a real format, protection or resource
constraint. Bound counts and sizes before allocation. Prefer an existing
per-call or runtime control from
analysis settings, limits, and recovery.
A fixed ceiling needs a registry entry with its class and reason in
scripts/verify/fixed-ceiling-registry.json, a reader mapping through
artifactFixedLimitFailure, and a paragraph in the limits reference.
Test
- Build fixtures synthetically. Do not commit third-party binaries.
- Cover the parser's facts, every refusal kind it can raise, and limitations
with
unknowncoverage. - Test the reader through
scanCanonicalArtifactInventoryandextractArtifact, and compare extracted bytes withBuffer.equals; the lint rule rejects deep equality on buffers. - Add a recognition case to
src/domain/artifactFormatRecognition.test.tsand a public workflow case totests/boundary/providers/native/artifactProvider.standaloneFormats.test.ts. - Validate against real samples when you can, and report the sample set, versions and results in the pull request instead of committing them.
Document
- Add a guide under
docs/guides/<area>/and register it indocs/.vitepress/documentation.tsanddocs/README.md. - Add a row to
docs/reference/supported-targets.mdand an example todocs/getting-started/cli.md. - Describe the format for agents in
.agents/skills/reverse-engineer-anything/references/native-and-artifacts.md, then runnpm run cursor-plugin:generate.
Check
npx tsc --noEmit -p tsconfig.json
npm run check:fast
npx oxfmt --check .
npm run test:local -- src/domain/<format>.test.ts src/artifacts/<Format>ArtifactReader.test.ts src/domain/artifactFormatRecognition.test.ts src/application/binary/TargetFormatVocabularies.test.ts
npm run test:focused -- tests/boundary/providers/native/artifactProvider.standaloneFormats.test.ts tests/conformance/artifactComparisonDocs.test.ts
npm run docs:check