public override Guid BufferToValue(Api.Buffer buffer) { buffer.ThrowIfNull("buffer"); var bytes = buffer.GetBytes(0, 16); return(new Guid(bytes)); }
public override bool BufferToValue(Api.Buffer buffer) { buffer.ThrowIfNull("buffer"); var bytes = buffer.GetBytes(); return(bytes.Any(b => b != 0)); }
public override TInteger BufferToValue(Api.Buffer buffer) { buffer.ThrowIfNull("buffer"); var integerSize = Marshal.SizeOf(typeof(TInteger)); var bytes = buffer.GetBytes(0, integerSize); return(_fromBytes(bytes)); }
public override GenericSecurityDescriptor BufferToValue(Api.Buffer buffer) { buffer.ThrowIfNull("buffer"); var bytes = buffer.GetBytes(); var securityDescriptor = new RawSecurityDescriptor(bytes, 0); return(securityDescriptor); }
public static string GetErrorMessage(int errorCode) { const int formatMessageFromSystem = 0x1000; using (var buffer = new Api.Buffer(4096)) { int messageLen = FormatMessage(formatMessageFromSystem, IntPtr.Zero, errorCode, 0, buffer.Data, buffer.Length, IntPtr.Zero); if (messageLen == 0) { return(string.Format("Unknown error code [0].", errorCode)); } var messageBytes = buffer.GetBytes(0, messageLen * 2); return(Encoding.Unicode.GetString(messageBytes)); } }
public override string BufferToValue(Api.Buffer buffer) { buffer.ThrowIfNull("buffer"); var bytes = buffer.GetBytes(); // Figure out how much data there is, ignoring any null terminator. var byteLength = bytes.Length; if (byteLength > 2 && bytes[byteLength - 1] == 0 && bytes[byteLength - 2] == 0) { byteLength -= 2; } return(Encoding.Unicode.GetString(bytes, 0, byteLength)); }
public override string[] BufferToValue(Api.Buffer buffer) { buffer.ThrowIfNull("buffer"); // All strings to be returned. var result = new List <string>(); // Variables used during the string conversions. var data = buffer.GetBytes(); var offset = 0; var length = 0; // Don't go past the end of the data. while (offset < data.Length) { // Find out how many bytes are used for the string. for (length = 0; length + 2 <= data.Length; length += 2) { if (data[offset + length] == 0 && data[offset + length + 1] == 0) { break; } } // The list is terminate by a single empty string. if (length == 0) { break; } // Get the string and add it to the result. var item = Encoding.Unicode.GetString(data, offset, length); result.Add(item); // Update the offset to point to the next string. offset += length + 2; } // Return the converted strings. return(result.ToArray()); }
public override byte[] BufferToValue(Api.Buffer buffer) { buffer.ThrowIfNull("buffer"); return(buffer.GetBytes()); }