Table of Contents

Class Pointer

Namespace
CStructSharp.Values
Assembly
CStructSharp.dll

Represents a pointer read from a binary layout. It always exposes the stored address and, when pointer reading is enabled, also exposes the value found at that address.

public sealed class Pointer
Inheritance
Pointer
Inherited Members

Examples

The parsed Pointer keeps the stored address and, when dereferencing is enabled, the value read from its target:

FollowPointer is compiled and executed as part of the example program:

private static void FollowPointer()
{
    var layout = new CStruct("struct root { uint8 *target; };", pointerSize: 1);
    using var stream = new MemoryStream([0x01, 0x2A]);
    StructValue root = layout.Parse(stream, "root");
    Pointer pointer = root.Get<Pointer>("target");
    Equal(1L, pointer.Address);
    True(pointer.IsDereferenced, "Pointer should be followed by default.");
    Equal((byte)0x2A, (byte)pointer.Value!);
}

Remarks

A null pointer has address zero. A non-null unresolved pointer keeps its address but has no target value; this is distinct from a followed pointer whose target is available through Value.

Constructors

Pointer(long, object?, int, bool)

Creates a pointer value with its address, optional target, nesting depth, and explicit follow status. Address-only values are unresolved by default and can be supplied directly to writers.

public Pointer(long address, object? value, int depth, bool isDereferenced = false)

Parameters

address long

The non-negative address payload stored in the binary pointer field.

value object

The parsed target when isDereferenced is true; otherwise, null.

depth int

The one-based pointer level represented by this value.

isDereferenced bool

true only when value contains the followed target.

Exceptions

ArgumentOutOfRangeException

address is negative or depth is not positive.

ArgumentException

The address, target, and dereference status form an inconsistent pointer state.

Properties

Address

Gets the non-negative address payload read from pointer storage. In relative mode this is the encoded offset, while dereferencing uses the checked sum of this value and Origin.

public long Address { get; }

Property Value

long

Depth

Gets this pointer's one-based level in a parsed pointer chain.

public int Depth { get; }

Property Value

int

IsDereferenced

Gets a value indicating whether the parser followed this pointer to obtain Value.

public bool IsDereferenced { get; }

Property Value

bool

IsNull

Gets whether pointer storage contains the null address.

public bool IsNull { get; }

Property Value

bool

Next

Gets the next pointer in a multi-level chain, when the parsed target is another pointer.

public Pointer? Next { get; }

Property Value

Pointer

Value

Gets the parsed target, another Pointer, or null when not followed.

public object? Value { get; }

Property Value

object

Methods

Dereference()

Returns the parsed target value, or null when the pointer was not followed.

public object? Dereference()

Returns

object

The parsed target, another Pointer, or null.

ToString()

Returns the target value as readable text, or an empty string when no target was read.

public override string ToString()

Returns

string

The target's text representation, or Empty when no target was read.