Skip to content

feat(artifacts): read WeChat mini-program wxapkg containers - #8148

Merged
morluto merged 4 commits into
morluto:mainfrom
blankym:feat-wxapkg-reader
Nov 4, 2026
Merged

morluto merged 4 commits into
morluto:mainfrom
blankym:feat-wxapkg-reader

Conversation

@blankym

@blankym blankym commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Refs #8121. REA previously reported a .wxapkg WeChat mini-program package as an opaque file; analysts had to unpack it by hand before inventorying its members. inspect-artifact and extract-artifact now recognize plaintext wxapkg packages, list members with their absolute carrier offsets, and extract member bytes verbatim. V1MMWX PC-client packages are detected as encrypted containers whose members are represented as unavailable rather than decrypted or fabricated.

Problem and expected behavior

Mini-program reverse engineering starts from the cached .wxapkg package: config, page scripts, style sheets, and subpackage members. Without a reader, inspect-artifact app.wxapkg yielded a single opaque occurrence with no member list, and extract-artifact could not recover app-config.json, pages/**/*.js, or *.wxss payloads. The expected outcome is the same inventory/extraction contract already provided for UnityFS and Godot PCK containers: declared member names, sizes, and absolute source offsets; verified member hashes; and fail-closed handling for encrypted or malformed packages.

Change and scope

  • src/domain/wxapkgFormat.ts decodes the 18-byte big-endian header (info length, index length, data length, 0xBE/0xED marks) and distinguishes plaintext packages from V1MMWX PC-client encrypted packages; decoding is total on short inputs.
  • src/artifacts/WxapkgStructures.ts parses the bounded member table: per-row length checks, UTF-8 name decoding, and member extents validated against the data region rather than the raw file so members cannot overlap the header or index.
  • src/artifacts/WxapkgArtifactReader.ts streams member bytes lazily in bounded chunks with carrier freshness checks; the reader bounds active member streams and joins them before close. Members are raw, uncompressed ranges — no decompression or decryption is attempted.
  • Registry, format unions, resolver classification, inventory graph construction, extraction, and inventory view/projections wire wxapkg through the same paths as UnityFS and Godot PCK. Encrypted packages produce a root occurrence with encrypted: true, directory_status: "encrypted", null member facts, and a typed unsupported_target refusal on extraction.
  • Scope intentionally excludes: decryption of V1MMWX packages, JavaScript execution or WeChat runtime behavior, mutation, and embedded-carrier discovery inside other files.

Contract and boundary impact

  • Semantic owner and earliest changed stage: decodeWxapkgHeader owns header facts; parseWxapkgDirectory owns member rows; WxapkgArtifactReader owns member streaming and stream lifecycle. Consumers are inventory graph construction, extraction, and the inventory view — all reuse owner-produced facts.
  • Contribution scope fit and linked maintainer decision: read-only file inspection within the existing artifact-reader boundary, same class as merged UnityFS (feat(artifacts): read UnityFS AssetBundle containers #7699) and Godot PCK; no execution, injection, mutation, or protection recovery. Scope question raised in [Feature] Read WeChat mini-program wxapkg containers #8121 is left for maintainer triage.
  • CLI and MCP/tool-catalog contract: no new operations; inspect_artifact/extract_artifact accept .wxapkg and V1MMWX inputs through existing classification.
  • Provider, bridge, target-format, or platform compatibility: additive wxapkg format; other readers unchanged.
  • Evidence, artifact, provenance, or reconstruction contract: member occurrences carry source_location absolute offsets, wxapkg-entry format metadata, and verified or unavailable hash status; encrypted directories report unknown coverage.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): byte-signature classification only; reader closes via scope even when streams are abandoned.
  • Generated metadata: none; .agents skill reference and docs updated.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated: WxapkgArtifactReader.test.ts (20) and WxapkgArtifactReader.boundaries.test.ts (11) cover header decode, member listing, verbatim extraction, directory/path semantics, malformed marks/headers/tables, member extents overlapping the header or exceeding the file, unsafe paths, aliased and overlapping member ranges charged per logical occurrence, expansion/directory budgets, active-stream capacity, cancellation, paused traversal, incomplete coverage, carrier freshness, and reader close joining outstanding streams. tests/boundary/mcp/wxapkgMcp.test.ts (2) exercises compiled CLI/MCP inspection and extraction on a synthetic package.

  • Base reproduction or other evidence: inspect-artifact on a 119-byte synthetic package yields a wxapkg root with file_count: 3, directory_status: "available", and three member occurrences with real source_location offsets; extraction writes byte-identical members (pages/index/index.js sha256 dd411c84…). A synthetic V1MMWX package reports encrypted: true, directory_status: "encrypted", unknown coverage, and refuses extraction with typed unsupported_target.

  • User-visible CLI/MCP output: verified via compiled scripts/rea.mjs on the synthetic packages above.

  • Remaining proof gaps: verification used synthetic fixtures only; no real wxapkg sample was available locally, so real-producer coverage is unverified (sample availability and provenance are open questions in [Feature] Read WeChat mini-program wxapkg containers #8121).

  • Observed, derived, and inferred claims remain distinguishable.

  • Artifact identity, source provenance, and failed attempts remain preserved.

  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run check:fast — passed (typecheck + lint clean)
  • npm run test:local -- src/artifacts/WxapkgArtifactReader.test.ts — 20 passed
  • npm run test:local -- src/artifacts/WxapkgArtifactReader.boundaries.test.ts — 11 passed
  • npm run test:focused -- tests/boundary/mcp/wxapkgMcp.test.ts — 2 passed (compiled profiles)
  • npm run docs:check — passed
  • npm run build — 3 tasks successful
  • node scripts/rea.mjs inspect-artifact|extract-artifact /tmp/test.wxapkg — detected wxapkg, complete coverage, byte-identical member extraction; /tmp/test-encrypted.wxapkg — encrypted state, typed extraction refusal
  • Full suite (npm test): 38,179 passed / 271 failed / 579 skipped; all observed failures are environmental baseline issues (setup/doctor provider clients, Ghidra/JEB/Hopper/xcrun availability, local zstd) — artifact, inventory, and extraction areas had zero failures; the ZIP zstd failure reproduces standalone on this machine without this change.

Compatibility, safety, and release

  • Breaking changes or migration steps: none; additive reader.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable; real wxapkg package coverage unavailable (see above).
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: read-only parsing; bounded allocations admitted before directory read; malformed and encrypted inputs fail closed with typed errors.

Author readiness

Human owner: @blankym

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

Review follow-up

Head 89b22190d merges origin/main and bounds wxapkg member ranges to the declared data region.

resolveWxapkgIndexLayouts admits both index-length conventions (rows only, and rows plus the 4-byte member count) only when that region fits in the file. Both candidates stay until the parsed rows and member ranges select one, so four trailing bytes cannot make the rows-only layout replace a count-inclusive package. Member ranges outside the selected region are format failures. A data region declared past the end of the file is no longer clamped to the file.

wxapkg and wxapkg-entry metadata are not compared by artifact comparison: header facts repeat the package bytes, and source_path keeps a producer root prefix.

Validation on this head:

  • npm run check:fast passed (typecheck and lint), including the pre-push run.
  • npm run test:local -- src/artifacts/WxapkgArtifactReader.test.ts src/artifacts/WxapkgArtifactReader.boundaries.test.ts — 44 passed.

Not re-run on this head: npm run test:focused -- tests/boundary/mcp/wxapkgMcp.test.ts, npm run docs:check, npm run build, and the manual CLI inspect/extract commands.

Open in Web Open in Cursor 

@greptile-apps

greptile-apps Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: apex

[Medium impact] The code changes look safe, subject to the scope decision already noted by blankym.

Summary

Adds read-only wxapkg inspection and extraction through the existing artifact workflows. This update fixes layout selection when trailing bytes follow a package.

  • REA can inspect and extract plaintext WeChat package members.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["Package bytes"] --> B{"Plaintext or V1MMWX?"}
  B -- V1MMWX --> C["Unknown member coverage"]
  C --> D["Refuse extraction"]
  B -- Plaintext --> E["Admit supported index layouts"]
  E --> F["Check rows and every member range"]
  F --> G["Read declared ranges in bounded chunks"]
  G --> H["Inventory and extraction"]
Loading

Reviews (10) · Last reviewed commit: "fix(artifacts): choose the wxapkg index ..." · Reviewed by Greptile

Comment thread src/artifacts/WxapkgStructures.ts Resolved
Comment thread src/domain/wxapkgFormat.ts Resolved
Comment thread src/artifacts/WxapkgArtifactReader.ts Resolved
Comment thread docs/wxapkg.md Resolved
@blankym
blankym force-pushed the feat-wxapkg-reader branch from cc3ef85 to f5d7c8c Compare October 31, 2026 09:12
Comment thread src/artifacts/WxapkgStructures.ts Resolved
@blankym
blankym force-pushed the feat-wxapkg-reader branch from f5d7c8c to 2ec95b9 Compare October 31, 2026 09:26
Comment thread src/artifacts/WxapkgStructures.ts Resolved
@blankym
blankym force-pushed the feat-wxapkg-reader branch from 2ec95b9 to 05c65f9 Compare November 2, 2026 02:03
Comment thread src/artifacts/WxapkgStructures.ts Resolved
@blankym
blankym force-pushed the feat-wxapkg-reader branch 3 times, most recently from 1603897 to 3edb927 Compare November 3, 2026 02:49
Comment thread src/artifacts/WxapkgStructures.ts Resolved
Add a read-only reader for plaintext wxapkg packages: the 0xBE/0xED
18-byte big-endian header, the bounded name/offset/size member table,
and verbatim member bytes at absolute carrier offsets.

- Members retain declared names, absolute offsets and sizes, so
  source_location reports real carrier positions.
- V1MMWX PC-client packages are detected as encrypted coverage with
  null member facts; extraction refuses with a typed error and no
  decryption is attempted.
- Bounded table and directory budgets are admitted before allocation;
  malformed marks, truncated tables, invalid UTF-8 names, member
  extents inside the header or beyond the file, and counts that cannot
  fit their table are typed format or limit failures.
- Member reads stream in bounded 64 KiB chunks with carrier freshness
  checks; the reader joins outstanding streams before close and bounds
  active streams and repeated member I/O.

Refs morluto#8121.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@blankym
blankym force-pushed the feat-wxapkg-reader branch from 3edb927 to 9d245f9 Compare November 3, 2026 08:16
@morluto
morluto marked this pull request as ready for review November 4, 2026 16:07
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-11-04T16:43:41.694175Z
We couldn’t complete this review. Comment @codex review to try again.
89b2219 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9d245f9b38

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/artifacts/WxapkgStructures.ts Resolved
Normalize the two indexLength conventions before the table bounds check
and the table read. Member ranges must then lie in that declared data
region, which has to fit in the file.

Record wxapkg format metadata as not compared: header facts repeat the
package bytes, and entry source paths keep a producer root prefix.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

Comment thread src/domain/wxapkgFormat.ts Resolved
@greptile-apps

greptile-apps Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Want your agent to iterate on Greptile's feedback? Try greploops.

Four trailing bytes made the rows-only layout end on the file and dropped
the count-inclusive layout. Keep every admitted layout until the parsed
rows and member ranges select one.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@morluto
morluto merged commit 5990ff0 into morluto:main Nov 4, 2026
12 of 14 checks passed
@morluto morluto mentioned this pull request Nov 11, 2026
3 tasks done
@morluto morluto added area: evidence Evidence, artifacts, and reconstruction enhancement New feature or request labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: evidence Evidence, artifacts, and reconstruction enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants