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
addresslongThe non-negative address payload stored in the binary pointer field.
valueobjectThe parsed target when
isDereferencedis true; otherwise, null.depthintThe one-based pointer level represented by this value.
isDereferencedbooltrue only when
valuecontains the followed target.
Exceptions
- ArgumentOutOfRangeException
addressis negative ordepthis 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
Depth
Gets this pointer's one-based level in a parsed pointer chain.
public int Depth { get; }
Property Value
IsDereferenced
Gets a value indicating whether the parser followed this pointer to obtain Value.
public bool IsDereferenced { get; }
Property Value
IsNull
Gets whether pointer storage contains the null address.
public bool IsNull { get; }
Property Value
Next
Gets the next pointer in a multi-level chain, when the parsed target is another pointer.
public Pointer? Next { get; }
Property Value
Value
public object? Value { get; }
Property Value
Methods
Dereference()
Returns the parsed target value, or null when the pointer was not followed.
public object? Dereference()
Returns
ToString()
Returns the target value as readable text, or an empty string when no target was read.
public override string ToString()