Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added methods to help decode NDR64 #74

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions NtApiDotNet/Ndr/Marshal/NdrUnmarshalBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,51 @@ public NdrUnmarshalBuffer(NdrPickledType pickled_type)
#endregion

#region Misc Methods

/// <summary>
/// When manually decoding 64bit NDR data, there are situations that
/// result in a single item getting stuck on the stack. This completely depends on what
/// is being decoded, so this function returns the _conformance_values array
/// to be evaluated. Depending on the evaluation, the _conformance_values array will be cleared.
/// </summary>
/// <returns></returns>
public int[] GetConformanceValuesArray()
{
return _conformance_values;
}

/// <summary>
/// When decoding 64bit NDR data, conformant arrays will leave data on the stack if pre alignment
/// is not possible. This results in other structs not being decoded correctly.
/// This method clears the stack manually.
/// </summary>
public void ClearConformanceValues()
{
_conformance_values = null;
}

/// <summary>
/// Reads given number of positions from the buffer and moves the position back to where it was.
/// This allows for reading data from the stream without consuming it
/// </summary>
/// <param name="length">Number of bytes to peek</param>
/// <returns>bytearray from the stream</returns>
public byte[] PeekBuffer(int length)
{

if ((long)length > _stm.RemainingLength())
throw new IndexOutOfRangeException("Given length bigger than remaining length");

long currentPosition = _stm.Position;

byte[] res = new byte[length];
res = ReadFixedByteArray(length);

_stm.Position = currentPosition;

return res;
}

public T ReadSystemHandle<T>() where T : NtObject
{
int index = ReadInt32();
Expand Down