public static string GetDeviceName(FileHandle fhandle) { using (MemoryAlloc data = new MemoryAlloc(600)) { fhandle.IoControl(IoCtlQueryDeviceName, IntPtr.Zero, 0, data, data.Size); MountDevName name = data.ReadStruct <MountDevName>(); return(data.ReadUnicodeString(MountDevName.NameOffset, name.NameLength / 2)); } }
public string GetText() { int retChars; using (var data = new MemoryAlloc(0x200)) { retChars = Win32.InternalGetWindowText(this, data, data.Size / 2); return(data.ReadUnicodeString(0, retChars)); } }
public static void UnpackCredentials( MemoryRegion buffer, CredPackFlags flags, out string domainName, out string userName, out string password ) { using (MemoryAlloc domainNameBuffer = new MemoryAlloc(0x100)) using (MemoryAlloc userNameBuffer = new MemoryAlloc(0x100)) using (MemoryAlloc passwordBuffer = new MemoryAlloc(0x100)) { int domainNameSize = domainNameBuffer.Size / 2 - 1; int userNameSize = userNameBuffer.Size / 2 - 1; int passwordSize = passwordBuffer.Size / 2 - 1; if (!Win32.CredUnPackAuthenticationBuffer( flags, buffer, buffer.Size, userNameBuffer, ref userNameSize, domainNameBuffer, ref domainNameSize, passwordBuffer, ref passwordSize )) { domainNameBuffer.ResizeNew(domainNameSize * 2 + 2); userNameBuffer.ResizeNew(userNameSize * 2 + 2); passwordBuffer.ResizeNew(passwordSize * 2 + 2); if (!Win32.CredUnPackAuthenticationBuffer( flags, buffer, buffer.Size, userNameBuffer, ref userNameSize, domainNameBuffer, ref domainNameSize, passwordBuffer, ref passwordSize )) { Win32.Throw(); } } domainName = domainNameBuffer.ReadUnicodeString(0); userName = userNameBuffer.ReadUnicodeString(0); password = passwordBuffer.ReadUnicodeString(0); } }
private static string GetReparsePointTarget(FileHandle fhandle) { using (MemoryAlloc data = new MemoryAlloc(FileSystem.MaximumReparseDataBufferSize)) { fhandle.IoControl(FileSystem.FsCtlGetReparsePoint, IntPtr.Zero, 0, data, data.Size); FileSystem.ReparseDataBuffer buffer = data.ReadStruct <FileSystem.ReparseDataBuffer>(); // Make sure it is in fact a mount point. if (buffer.ReparseTag != (uint)IoReparseTag.MountPoint) { Win32.Throw(NtStatus.InvalidParameter); } return(data.ReadUnicodeString( FileSystem.ReparseDataBuffer.MountPointPathBuffer + buffer.SubstituteNameOffset, buffer.SubstituteNameLength / 2 )); } }
public string GetLogFileName() { NtStatus status; int retLength; using (var data = new MemoryAlloc(0x1000)) { status = Win32.NtQueryInformationTransactionManager( this, TmInformationClass.TransactionManagerLogPathInformation, data, data.Size, out retLength ); if (status == NtStatus.BufferTooSmall) { // Resize the buffer and try again. data.ResizeNew(retLength); status = Win32.NtQueryInformationTransactionManager( this, TmInformationClass.TransactionManagerLogPathInformation, data, data.Size, out retLength ); } if (status >= NtStatus.Error) { Win32.Throw(status); } TmLogPathInformation logPathInfo = data.ReadStruct <TmLogPathInformation>(); return(data.ReadUnicodeString(TmLogPathInformation.LogPathOffset, logPathInfo.LogPathLength)); } }
public static void UnpackCredentials( MemoryRegion buffer, CredPackFlags flags, out string domainName, out string userName, out string password ) { using (var domainNameBuffer = new MemoryAlloc(0x100)) using (var userNameBuffer = new MemoryAlloc(0x100)) using (var passwordBuffer = new MemoryAlloc(0x100)) { int domainNameSize = domainNameBuffer.Size / 2 - 1; int userNameSize = userNameBuffer.Size / 2 - 1; int passwordSize = passwordBuffer.Size / 2 - 1; if (!Win32.CredUnPackAuthenticationBuffer( flags, buffer, buffer.Size, userNameBuffer, ref userNameSize, domainNameBuffer, ref domainNameSize, passwordBuffer, ref passwordSize )) { domainNameBuffer.ResizeNew(domainNameSize * 2 + 2); userNameBuffer.ResizeNew(userNameSize * 2 + 2); passwordBuffer.ResizeNew(passwordSize * 2 + 2); if (!Win32.CredUnPackAuthenticationBuffer( flags, buffer, buffer.Size, userNameBuffer, ref userNameSize, domainNameBuffer, ref domainNameSize, passwordBuffer, ref passwordSize )) Win32.Throw(); } domainName = domainNameBuffer.ReadUnicodeString(0); userName = userNameBuffer.ReadUnicodeString(0); password = passwordBuffer.ReadUnicodeString(0); } }
public static bool PromptForCredentials( IWin32Window parent, string messageText, string captionText, string targetName, Win32Error errorCode, ref string userName, ref string password, ref bool save, CredUiFlags flags ) { const int maxBytes = 0x200; const int maxChars = (maxBytes - 2) / 2; Win32Error result; CredUiInfo info = new CredUiInfo(); if (userName.Length > maxChars || password.Length > maxChars) throw new ArgumentException("The user name or password string is too long."); info.Size = System.Runtime.InteropServices.Marshal.SizeOf(typeof(CredUiInfo)); info.Parent = parent != null ? parent.Handle : IntPtr.Zero; info.MessageText = messageText; info.CaptionText = captionText; using (var userNameAlloc = new MemoryAlloc(maxBytes)) using (var passwordAlloc = new MemoryAlloc(maxBytes)) { userNameAlloc.WriteUnicodeString(0, userName); userNameAlloc.WriteInt16(userName.Length * 2, 0); passwordAlloc.WriteUnicodeString(0, password); passwordAlloc.WriteInt16(password.Length * 2, 0); result = Win32.CredUIPromptForCredentials( ref info, targetName, IntPtr.Zero, errorCode, userNameAlloc, maxBytes / 2, passwordAlloc, maxBytes / 2, ref save, flags ); if (result == Win32Error.Cancelled) return false; if (result != Win32Error.Success) Win32.Throw(result); userName = userNameAlloc.ReadUnicodeString(0); password = passwordAlloc.ReadUnicodeString(0); return true; } }
private static string GetReparsePointTarget(FileHandle fhandle) { using (MemoryAlloc data = new MemoryAlloc(FileSystem.MaximumReparseDataBufferSize)) { fhandle.IoControl(FileSystem.FsCtlGetReparsePoint, IntPtr.Zero, 0, data, data.Size); FileSystem.ReparseDataBuffer buffer = data.ReadStruct<FileSystem.ReparseDataBuffer>(); // Make sure it is in fact a mount point. if (buffer.ReparseTag != (uint)IoReparseTag.MountPoint) Win32.Throw(NtStatus.InvalidParameter); return data.ReadUnicodeString( FileSystem.ReparseDataBuffer.MountPointPathBuffer + buffer.SubstituteNameOffset, buffer.SubstituteNameLength / 2 ); } }
public static string GetDeviceName(FileHandle fhandle) { using (MemoryAlloc data = new MemoryAlloc(600)) { fhandle.IoControl(IoCtlQueryDeviceName, IntPtr.Zero, 0, data, data.Size); MountDevName name = data.ReadStruct<MountDevName>(); return data.ReadUnicodeString(MountDevName.NameOffset, name.NameLength / 2); } }
public static bool PromptForCredentials( IWin32Window parent, string messageText, string captionText, string targetName, Win32Error errorCode, ref string userName, ref string password, ref bool save, CredUiFlags flags ) { const int maxBytes = 0x200; const int maxChars = (maxBytes - 2) / 2; Win32Error result; CredUiInfo info = new CredUiInfo(); if (userName.Length > maxChars || password.Length > maxChars) { throw new ArgumentException("The user name or password string is too long."); } info.Size = CredUiInfo.SizeOf; info.Parent = parent != null ? parent.Handle : IntPtr.Zero; info.MessageText = messageText; info.CaptionText = captionText; using (MemoryAlloc userNameAlloc = new MemoryAlloc(maxBytes)) using (MemoryAlloc passwordAlloc = new MemoryAlloc(maxBytes)) { userNameAlloc.WriteUnicodeString(0, userName); userNameAlloc.WriteInt16(userName.Length * 2, 0); passwordAlloc.WriteUnicodeString(0, password); passwordAlloc.WriteInt16(password.Length * 2, 0); result = Win32.CredUIPromptForCredentials( ref info, targetName, IntPtr.Zero, errorCode, userNameAlloc, maxBytes / 2, passwordAlloc, maxBytes / 2, ref save, flags ); if (result == Win32Error.Cancelled) { return(false); } if (result != Win32Error.Success) { Win32.Throw(result); } userName = userNameAlloc.ReadUnicodeString(0); password = passwordAlloc.ReadUnicodeString(0); return(true); } }