Table of Contents

Class UserStringsStream

Namespace
AsmResolver.PE.DotNet.Metadata
Assembly
AsmResolver.PE.dll

Represents the metadata streams containing the user strings referenced by CIL method bodies.

public abstract class UserStringsStream : MetadataHeap, IMetadataStream, ISegment, IOffsetProvider, IWritable
Inheritance
UserStringsStream
Implements
Derived
Inherited Members

Remarks

Like most metadata streams, the user strings stream does not necessarily contain just valid strings. It can contain (garbage) data that is never referenced by any of the tables in the tables stream. The only guarantee that the strings heap provides, is that any string index in a CIL method body is the start address (relative to the start of the #US stream) of a unicode string, prefixed by a length, and suffixed by one extra terminator byte.

Constructors

UserStringsStream()

Initializes the user-strings stream with its default name.

protected UserStringsStream()

UserStringsStream(string)

Initializes the user-strings stream with a custom name.

protected UserStringsStream(string name)

Parameters

name string

Fields

DefaultName

The default name of a user-strings stream, as described in the specification provided by ECMA-335.

public const string DefaultName = "#US"

Field Value

string

Methods

EnumerateStrings()

Performs a linear sweep on the stream and yields all strings that are stored.

public abstract IEnumerable<(uint Index, string String)> EnumerateStrings()

Returns

IEnumerable<(uint Index, string String)>

The strings enumerator.

Remarks

As strings can be referenced at any offset within the heap, the heap is technically allowed to contain garbage data in between string entries. As such, this linear sweep enumerator may not be an accurate depiction of all strings that are used by the module.

GetStringByIndex(uint)

Gets a string by its string index.

public abstract string? GetStringByIndex(uint index)

Parameters

index uint

The offset into the heap to start reading.

Returns

string

The string, or null if the index was invalid.

TryFindStringIndex(string, out uint)

Searches the stream for the provided string.

public abstract bool TryFindStringIndex(string value, out uint index)

Parameters

value string

The string to search for.

index uint

When the function returns true, contains the index at which the string was found.

Returns

bool

true if the string index was found, false otherwise.

TryFindStringToken(string, out MetadataToken)

Searches the stream for the provided string.

public bool TryFindStringToken(string value, out MetadataToken token)

Parameters

value string

The string to search for.

token MetadataToken

When the function returns true, contains the token for which the string was found.

Returns

bool

true if the string token was found, false otherwise.