Files
rea/docs/guides/managed/dotnet-resources.md
Ysopwnableandgensokyo-dev c2960db49f feat(artifacts): inventory resources embedded in .NET assemblies (#17105)
* refactor(managed): read ManifestResource rows and the CLI Resources directory separately

Split a ManifestResource row's columns from its data, so a caller that
holds only the metadata can list resources, and let the CLI header prefix
report its Resources directory when it is read that far.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>

* feat(artifacts): bound .NET assembly manifest resource admission

Add the dotnet_assembly reader limit group: the resource count follows the
session member count, and metadata bytes bound the CLI metadata read to
list ManifestResource rows.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>

* feat(artifacts): locate a managed image's metadata and Resources directory

Read only the PE headers, section table and CLI header to find where a
managed image keeps its metadata and embedded manifest resources, so
recognition does not load the image.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>

* feat(artifacts): list the manifest resources a .NET assembly embeds

Add the dotnet-assembly reader. It reads the ManifestResource rows from
the CLI metadata and lists each resource embedded in the Resources
directory as its stored bytes. Linked resources are named in the root
metadata, since their bytes live in other files.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>

* feat(artifacts): open managed assemblies with embedded resources as containers

A PE whose CLI header declares a Resources directory, and that carries no
other package, now inventories as dotnet-assembly, so a WPF assembly's
.g.resources can be extracted and inspected as a resource set. Managed
inspection still leads its next probes; extraction follows.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>

* docs(managed): describe resources embedded in a .NET assembly

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>

* docs(skill): route assemblies with embedded resources to extraction

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>

* ci: scope the .NET assembly resource reader with the managed formats

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>

* fix(artifacts): keep located managed directories inside the file

A section can declare raw data past the end of the file. A metadata or
Resources directory mapped there is now malformed at location, instead of
failing the later exact read.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>

* fix(artifacts): report invalid manifest resource rows once

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>

* fix(artifacts): require a complete CLI header before locating managed directories

Check the declared header size against the 72-byte header and the CLI
directory, and that the whole header lies in the file, as the managed PE
reader does.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>

* test(managed): build fixtures that embed several manifest resources

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>

* fix(artifacts): inventory manifest resource names as flat keys

Names such as `a` and `a/b` are distinct resources. Inventory keeps both,
as it does for resource set names; extraction still refuses to write
conflicting paths together.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>

* feat(artifacts): add decode and retained-name controls for .NET assemblies

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>

* fix(artifacts): bound assembly resource names and keep readable rows

The metadata decode budget is now the group's representation_bytes
control, so a refusal names a field the caller can raise. Every listed
name counts against retained_name_bytes before output is built, since
rows can share one stored name. A row whose name cannot be read is
skipped and counted instead of refusing the whole assembly.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>

* docs(managed): list the .NET assembly reader controls

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>

* refactor(artifacts): pass the classified managed location to the assembly reader

Classification carries the located metadata and Resources directory in a
typed admission for the same descriptor, so the reader does not locate
them again.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>

* fix(artifacts): explain a damaged CLI Resources directory on extraction

Extraction now refuses such a PE with the location's reason instead of
reporting that the format has no reader. Inspection keeps the PE root,
where managed inspection reports the CLI header.

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>

* fix(artifacts): require the CLI header's declared size inside the file

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>

---------

Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
2026-12-06 00:53:42 +08:00

6.4 KiB

.NET resource sets

Resources embedded in an assembly

A managed assembly keeps its embedded resources, including a WPF assembly's <Assembly>.g.resources, in the CLI Resources directory. When the CLI header declares that directory and the file carries no other package, such as a .NET single-file bundle, rea inspect-artifact App.exe --json or MCP inspect_artifact inventories the file as dotnet-assembly: each ManifestResource row embedded in the directory is a member whose bytes follow its 4-byte length prefix. Nothing is decoded. A PE without a CLI header, or one whose CLI header declares no Resources directory, stays a pe root.

Each member records resource_name, its metadata token, flags and visibility, and declared_offset within the directory. Root metadata counts resource_count and embedded_count, records the directory's file range and names each linked resource (one whose rows name another file or assembly) with its implementation token; a linked resource's bytes are not in the module. Resources that overrun the directory, names that are not safe paths and repeated names are omitted and counted in the coverage limitations, and coverage is then unknown. Managed inspection still leads the next probes; extraction follows.

rea extract-artifact App.exe --output-root /absolute/output --json
rea inspect-artifact /absolute/output/App.g.resources --json

Reader admission uses artifact_limits.dotnet_assembly:

  • resource_count: the ManifestResource rows; 100,000 by default and backed by the session's artifact.member_count unless the call selects it.
  • metadata_bytes: 64 MiB of CLI metadata read to list the rows.
  • representation_bytes: 64 MiB of decoded rows and names.
  • retained_name_bytes: 16 MiB of listed names, counting a name again for every row that shares it.

A refusal names the field and, where it is known, the required value; retry with that field raised. A row whose name cannot be read is skipped and counted, and coverage is then unknown. Resource bytes are served from the file and are not read into memory.

Resource set files

Use rea inspect-artifact Strings.resources --json or MCP inspect_artifact to inventory a .resources stream, the format ResourceWriter and resgen produce and ResourceManager reads. Recognition uses the 0xBEEFCACE magic and a usable ResourceManager header; the file name does not matter. WPF assemblies embed their compiled XAML (BAML), images and other loose files in one such set, conventionally named <Assembly>.g.resources.

Each named resource is a member, and its bytes are one stored range of the set:

Value Member bytes Entry metadata
String The UTF-8 text value_kind: "string"
ByteArray, Stream The payload after its length value_kind: "bytes" or "stream"
Fixed-size primitives The stored little-endian bytes value_kind: "scalar" and the decoded value
Null Empty value_kind: "null"
Serialized objects (type codes ≥ 0x40) The serialized bytes value_kind: "serialized" and user_type_name

Decoded scalars keep JSON-safe forms: 64-bit integers, Decimal values and TimeSpan ticks are decimal text; a DateTime is ISO 8601 text with its 100-nanosecond ticks and date_time_kind. ToBinary stores a utc or local value as its UTC instant, so that text ends with Z; an unspecified value has no instant and no suffix. JSON cannot carry non-finite or negative-zero floating values, or a lone surrogate Char, faithfully, so those values are null; the member bytes keep the stored value. Serialized objects are never deserialized: the entry names the type from the set's type table and the bytes stay as stored. A version 1 set stores every value that way.

Every entry records resource_name and data_offset. It also records name_hash_matches: whether the stored hash agrees with ResourceReader's hash of the name. The root metadata counts name_hash_mismatches and reports name_hashes_sorted, because ResourceReader binary-searches that table and an unsorted or mismatched table makes lookups by name fail. A newer ResourceManager header version is skipped as the runtime does, leaving reader_type and resource_set_type null.

Use rea extract-artifact Strings.resources --output-root /absolute/output --json or MCP extract_artifact to write the members to files, for example each BAML document as views/mainwindow.baml. Select individual resources by their inventory occurrence IDs.

Resource names are logical paths. Names are flat keys, so a and a/b can both exist: inventory lists both, and extraction refuses to write them together; select one at a time. A name that is not a safe relative path, such as one that is absolute or contains .., is omitted and counted in the coverage limitations, as are names that are not well-formed UTF-16 and values that overrun their data. Coverage is then unknown.

Reader admission uses artifact_limits.dotnet_resources: resource_count (100,000 by default), type_count (4,096), header_bytes (16 MiB for the headers, type table, hash and position tables and name section, which are read before the data section) and retained_name_bytes (16 MiB of decoded names, counting a name again for every table entry that shares it). The session setting artifact.member_count, changed with update_analysis_settings, backs resource_count unless the call explicitly selects it. A limit failure names the effective control and the required value; a retained_name_bytes failure keeps the members read before it. Retry with that field raised.

rea inspect-artifact App.g.resources --artifact-limits '{"dotnet_resources":{"resource_count":200000}}' --json

The layout follows the .NET runtime's ResourceReader and ResourceWriter.