Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Format:.NET resources (.resources)

From ReverseEngineering.wiki
Format
On this wiki Facts · Code · Notes · Topics

The binary resource table of .NET (.resources files and the managed resources of assemblies): little-endian magic 0xBEEFCACE, a ResourceManager header naming the reader type, a RuntimeResourceSet header (version 2), a hash-sorted name table and a data section whose entries start with a ResourceTypeCode; also covers .resx and satellite assemblies.

The format behind ResourceManager in .NET Framework and .NET: what a resource compiler (resgen, MSBuild GenerateResource) makes out of .resx XML or .txt files, and what is embedded as a managed resource (ManifestResource table of Format:.NET metadata (ECMA-335)) named <Namespace>.<Class>.resources, e.g. MyApp.Properties.Resources.resources. It holds strings, images, icons, serialized objects and, in WPF applications, the compiled XAML (Format:BAML) under <App>.g.resources.

Identification

Layout

All integers little endian; strings are BinaryWriter strings (7-bit encoded byte length, then UTF-8) unless stated; resource names are UTF-16 with a 7-bit byte length.

Part Contents
ResourceManager header int32 magic 0xBEEFCACE, int32 header version (1), int32 number of bytes to skip, then the reader type name and the resource set type name (strings). For header version > 1 the reader skips the given bytes instead of parsing the names
RuntimeResourceSet header int32 file version (1 or 2 accepted, writer uses 2), int32 resource count, int32 type count, then the type names (strings: the table that user-type entries index into)
padding zero bytes up to the next multiple of 8 of the file position
name hashes int32 x count, sorted ascending, hash of the name
name positions int32 x count: offset of each name, relative to the name section start
data section offset int32 file offset where the data section starts
name section for each resource: name (7-bit byte length + UTF-16 chars) and an int32 offset into the data section
data section at each offset: a 7-bit encoded type code, then the value

The usual reader type name is System.Resources.ResourceReader, mscorlib, Version=4.0.0.0, ... (Framework) or a System.Private.CoreLib / System.Resources.Extensions variant (the shared ResourceWriter in dotnet/runtime at 66368e9, src/libraries/Common/src/System/Resources/ResourceWriter.cs line 35, writes System.Resources.ResourceReader, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089; Unverified: the exact strings other targets write, read them from the file). The resource set type is System.Resources.RuntimeResourceSet.

Name hash

The hash is a djb2 variant over UTF-16 code units: hash = 5381; for each char c: hash = ((hash << 5) + hash) ^ c in uint32 arithmetic (Fact:.NET resources (.resources)/behavior/Name hash function). Lookup is a binary search on the sorted hash array, then a name comparison.

Data entries (version 2)

The type code is a 7-bit encoded int (Fact:.NET resources (.resources)/enum/ResourceTypeCode): 0 Null, 1 String, 2 Boolean, 3 Char, 4 Byte, 5 SByte, 6 Int16, 7 UInt16, 8 Int32, 9 UInt32, 0xA Int64, 0xB UInt64, 0xC Single, 0xD Double, 0xE Decimal, 0xF DateTime (int64 ToBinary), 0x10 TimeSpan (int64 ticks), 0x20 ByteArray (int32 length + bytes), 0x21 Stream (int32 length + bytes), and 0x40 and above = user types: the value code - 0x40 is an index into the type name table and the payload is a BinaryFormatter-serialized object. In version 1 files the 7-bit number is the type table index directly (-1 means null) and the primitive types are recognised by type name.

So a reverser reading raw bytes finds: strings as length-prefixed UTF-8, images as 0x20/0x21 entries (often a PNG) or as user-type System.Drawing.Bitmap/Icon entries, and everything else as serialized objects (potential deserialization surface: treat them as data, do not load them).

.resx

.resx is the XML source form (<data name="..." type="..." mimetype="..."><value>..</value></data>, binary values as base64). It does not exist in a built program; a decompiler regenerates it from the .resources entries. The writer emits an XML schema block, then four <resheader> elements in this order: resmimetype = text/microsoft-resx, version = 2.0, reader (assembly-qualified name of ResXResourceReader) and writer (assembly-qualified name of ResXResourceWriter) (dotnet/winforms at c4891de, src/System.Windows.Forms/System/Resources/ResXResourceWriter.cs, lines 36-37 and 184-235). Binary values use the mimetype application/x-microsoft.net.object.binary.base64 by default (lines 32-35).

Satellite assemblies

Localized resources live in separate assemblies named <Assembly>.resources.dll placed in a folder named for the culture (de, fr-FR, ...) next to the main assembly (or in the bundle / deps.json resources entries, see Format:.NET runtimeconfig.json and deps.json). Each contains a <BaseName>.<culture>.resources resource in the format above and no code. The runtime falls back from specific to neutral culture and finally to the neutral resources in the main assembly. Unverified: single-file bundles keep satellite assemblies as type-1 assembly entries with the culture folder in the path.

Related

Format:BAML, Format:.NET single-file bundle, Format:.NET metadata (ECMA-335), Library:Costura.Fody

Evidence & references

  • dotnet/runtime, src/libraries/System.Private.CoreLib/src/System/Resources/: ResourceManager.cs (magic, header comment), ResourceReader.cs (_ReadResources, LoadObjectV2), FastResourceComparer.cs (hash), ResourceTypeCode.cs.