mirror of
https://github.com/ReneLergner/WPinternals.git
synced 2026-06-14 03:16:40 +10:00
Project: Add SDK
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
public enum CreationDisposition
|
||||
{
|
||||
CreateNew = 1,
|
||||
CreateAlways,
|
||||
OpenExisting,
|
||||
OpenAlways,
|
||||
TruncateExisting,
|
||||
OpenForLoader
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
public static class Environment
|
||||
{
|
||||
public static bool HasRootAccess()
|
||||
{
|
||||
bool result = true;
|
||||
try
|
||||
{
|
||||
new Folder("C:\\Windows\\System32\\config").GetSubItems();
|
||||
}
|
||||
catch
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
try
|
||||
{
|
||||
new RegistryKey((RegistryHive)2147483650U, "Security").GetSubItems();
|
||||
}
|
||||
catch
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
try
|
||||
{
|
||||
Environment.ShellExecute("C:\\WINDOWS\\SYSTEM32\\INSTALLAGENT.EXE");
|
||||
}
|
||||
catch
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void Elevate()
|
||||
{
|
||||
IntPtr intPtr;
|
||||
UIntPtr uintPtr;
|
||||
UIntPtr uintPtr2;
|
||||
uint num;
|
||||
if (!Win32.LogonUserExEx("DefApps", "", "", 2U, 0U, UIntPtr.Zero, out intPtr, out uintPtr, out uintPtr2, out num, UIntPtr.Zero))
|
||||
{
|
||||
throw new Win32Exception(Marshal.GetLastWin32Error(), "Elevate failed");
|
||||
}
|
||||
}
|
||||
|
||||
public static void ShellExecute(string Application)
|
||||
{
|
||||
Environment.ShellExecute(Application, null);
|
||||
}
|
||||
|
||||
public static void ShellExecute(string Application, string Arguments)
|
||||
{
|
||||
PROCESS_INFORMATION process_INFORMATION = default(PROCESS_INFORMATION);
|
||||
STARTUPINFO startupinfo = default(STARTUPINFO);
|
||||
if (!Win32.CreateProcess(Application, Arguments, UIntPtr.Zero, UIntPtr.Zero, false, 32U, IntPtr.Zero, null, ref startupinfo, out process_INFORMATION))
|
||||
{
|
||||
throw new Win32Exception(Marshal.GetLastWin32Error(), "CreateProcess failed");
|
||||
}
|
||||
if (process_INFORMATION.hProcess != IntPtr.Zero && process_INFORMATION.hProcess != (IntPtr)(-1))
|
||||
{
|
||||
Win32.CloseHandle(process_INFORMATION.hProcess);
|
||||
}
|
||||
if (process_INFORMATION.hThread != IntPtr.Zero && process_INFORMATION.hThread != (IntPtr)(-1))
|
||||
{
|
||||
Win32.CloseHandle(process_INFORMATION.hThread);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
internal struct FILETIME
|
||||
{
|
||||
public uint DateTimeLow;
|
||||
|
||||
public uint DateTimeHigh;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
public class File : FileSystemEntry
|
||||
{
|
||||
public File(string Path, FileAttributes Attributes) : base(Path, Attributes)
|
||||
{
|
||||
}
|
||||
|
||||
public ulong Size
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!this.sizeQueried)
|
||||
{
|
||||
this.size = FileSystem.GetFileSize(base.Path);
|
||||
}
|
||||
return this.size;
|
||||
}
|
||||
internal set
|
||||
{
|
||||
this.size = value;
|
||||
this.sizeQueried = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return base.Path;
|
||||
}
|
||||
|
||||
private bool sizeQueried;
|
||||
|
||||
private ulong size;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
[Flags]
|
||||
internal enum FileAccess : uint
|
||||
{
|
||||
AccessSystemSecurity = 16777216U,
|
||||
MaximumAllowed = 33554432U,
|
||||
Delete = 65536U,
|
||||
ReadControl = 131072U,
|
||||
WriteDAC = 262144U,
|
||||
WriteOwner = 524288U,
|
||||
Synchronize = 1048576U,
|
||||
StandardRightsRequired = 983040U,
|
||||
StandardRightsRead = 131072U,
|
||||
StandardRightsWrite = 131072U,
|
||||
StandardRightsExecute = 131072U,
|
||||
StandardRightsAll = 2031616U,
|
||||
SpecificRightsAll = 65535U,
|
||||
ReadData = 1U,
|
||||
ListDirectory = 1U,
|
||||
WriteData = 2U,
|
||||
AddFile = 2U,
|
||||
AppendData = 4U,
|
||||
AddSubdirectory = 4U,
|
||||
CreatePipeInstance = 4U,
|
||||
ReadEa = 8U,
|
||||
WriteEa = 16U,
|
||||
Execute = 32U,
|
||||
Traverse = 32U,
|
||||
DeleteChild = 64U,
|
||||
ReadAttributes = 128U,
|
||||
WriteAttributes = 256U,
|
||||
GenericRead = 2147483648U,
|
||||
GenericWrite = 1073741824U,
|
||||
GenericExecute = 536870912U,
|
||||
GenericAll = 268435456U
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
[Flags]
|
||||
public enum FileAttributes : uint
|
||||
{
|
||||
Invalid = 4294967295U,
|
||||
Readonly = 1U,
|
||||
Hidden = 2U,
|
||||
System = 4U,
|
||||
Directory = 16U,
|
||||
Archive = 32U,
|
||||
Device = 64U,
|
||||
Normal = 128U,
|
||||
Temporary = 256U,
|
||||
SparseFile = 512U,
|
||||
ReparsePoint = 1024U,
|
||||
Compressed = 2048U,
|
||||
Offline = 4096U,
|
||||
NotContentIndexed = 8192U,
|
||||
Encrypted = 16384U,
|
||||
Virtual = 65536U,
|
||||
BackupSemantics = 33554432U,
|
||||
DeleteOnClose = 67108864U,
|
||||
NoBuffering = 536870912U,
|
||||
OpenNoRecall = 1048576U,
|
||||
OpenReparsePoint = 2097152U,
|
||||
Overlapped = 1073741824U,
|
||||
PosixSemantics = 1048576U,
|
||||
RandomAccess = 268435456U,
|
||||
SessionAware = 8388608U,
|
||||
SequentialScan = 134217728U,
|
||||
WriteThrough = 2147483648U
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,254 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
public class FileStream : Stream
|
||||
{
|
||||
public FileStream(string Path, FileStreamMode Mode)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.path = Path;
|
||||
this.mode = Mode;
|
||||
switch (this.mode)
|
||||
{
|
||||
case FileStreamMode.Read:
|
||||
this.length = (uint)FileSystem.GetFileSize(this.path);
|
||||
if (this.length > 0U)
|
||||
{
|
||||
this.hFile = Win32.CreateFile(this.path, (FileAccess)2147483648U, ShareMode.Read | ShareMode.Write, IntPtr.Zero, CreationDisposition.OpenExisting, FileAttributes.Normal, IntPtr.Zero);
|
||||
}
|
||||
break;
|
||||
case FileStreamMode.Write:
|
||||
this.hFile = Win32.CreateFile(this.path, FileAccess.GenericWrite, ShareMode.None, IntPtr.Zero, CreationDisposition.CreateAlways, FileAttributes.Normal, IntPtr.Zero);
|
||||
break;
|
||||
case FileStreamMode.ReadWrite:
|
||||
if (FileSystem.FileExists(this.path))
|
||||
{
|
||||
this.length = (uint)FileSystem.GetFileSize(this.path);
|
||||
}
|
||||
this.hFile = Win32.CreateFile(this.path, (FileAccess)3221225472U, ShareMode.None, IntPtr.Zero, CreationDisposition.OpenAlways, FileAttributes.Normal, IntPtr.Zero);
|
||||
break;
|
||||
}
|
||||
this.open = true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanRead
|
||||
{
|
||||
get
|
||||
{
|
||||
return (this.mode == FileStreamMode.Read || this.mode == FileStreamMode.ReadWrite) && this.open;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanSeek
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanWrite
|
||||
{
|
||||
get
|
||||
{
|
||||
return (this.mode == FileStreamMode.Write || this.mode == FileStreamMode.ReadWrite) && this.open;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Flush()
|
||||
{
|
||||
}
|
||||
|
||||
public override long Length
|
||||
{
|
||||
get
|
||||
{
|
||||
return (long)((ulong)((this.mode == FileStreamMode.Read) ? this.length : this.position));
|
||||
}
|
||||
}
|
||||
|
||||
public override long Position
|
||||
{
|
||||
get
|
||||
{
|
||||
return (long)((ulong)this.position);
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value != (long)((ulong)this.position))
|
||||
{
|
||||
if (value < 0L || value > -1)
|
||||
{
|
||||
throw new IndexOutOfRangeException("Position must be unsigned 32 bit");
|
||||
}
|
||||
int num;
|
||||
if (Win32.SetFilePointer(this.hFile, (int)value, out num, MoveMethod.Begin) == 4294967295U)
|
||||
{
|
||||
throw new Win32Exception(Marshal.GetLastWin32Error(), "Failed to set position");
|
||||
}
|
||||
this.position = (uint)value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
if (!this.open)
|
||||
{
|
||||
throw new InvalidOperationException("Stream is closed");
|
||||
}
|
||||
if (this.mode != FileStreamMode.Read && this.mode != FileStreamMode.ReadWrite)
|
||||
{
|
||||
throw new InvalidOperationException("Cannot read from this stream");
|
||||
}
|
||||
if (count < 0)
|
||||
{
|
||||
throw new ArgumentException("Count must have a positive value");
|
||||
}
|
||||
uint num = this.length - this.position;
|
||||
if (num < 0U)
|
||||
{
|
||||
num = 0U;
|
||||
}
|
||||
if (buffer == null)
|
||||
{
|
||||
throw new ArgumentNullException("Buffer cannot be null");
|
||||
}
|
||||
if ((ulong)num > (ulong)((long)count))
|
||||
{
|
||||
num = (uint)count;
|
||||
}
|
||||
if (num > 0U)
|
||||
{
|
||||
if ((long)offset + (long)((ulong)num) > (long)buffer.Length)
|
||||
{
|
||||
throw new ArgumentException("Buffer too small");
|
||||
}
|
||||
if (!Win32.ReadFile(this.hFile, buffer, (uint)count, out num, UIntPtr.Zero))
|
||||
{
|
||||
throw new Win32Exception(Marshal.GetLastWin32Error(), "Failed to read file");
|
||||
}
|
||||
this.position += num;
|
||||
}
|
||||
return (int)num;
|
||||
}
|
||||
|
||||
public override long Seek(long offset, SeekOrigin origin)
|
||||
{
|
||||
if (offset < -2147483648L || offset > 2147483647L)
|
||||
{
|
||||
throw new IndexOutOfRangeException("Offset must be in 32 bit range");
|
||||
}
|
||||
int num2;
|
||||
uint num = Win32.SetFilePointer(this.hFile, (int)offset, out num2, (MoveMethod)origin);
|
||||
if (num == 4294967295U)
|
||||
{
|
||||
throw new Win32Exception(Marshal.GetLastWin32Error(), "Seek failed");
|
||||
}
|
||||
this.position = num;
|
||||
return (long)((ulong)this.position);
|
||||
}
|
||||
|
||||
public override void SetLength(long value)
|
||||
{
|
||||
if (this.mode != FileStreamMode.ReadWrite)
|
||||
{
|
||||
throw new InvalidOperationException("Only possible to set the lenght when FileAccessMode is ReadWrite");
|
||||
}
|
||||
if (value < 0L || value > -1)
|
||||
{
|
||||
throw new IndexOutOfRangeException("Length must be unsigned 32 bit");
|
||||
}
|
||||
int num;
|
||||
if (Win32.SetFilePointer(this.hFile, (int)value, out num, MoveMethod.Begin) == 4294967295U)
|
||||
{
|
||||
throw new Win32Exception(Marshal.GetLastWin32Error(), "Failed to set length");
|
||||
}
|
||||
if (!Win32.SetEndOfFile(this.hFile))
|
||||
{
|
||||
throw new Win32Exception(Marshal.GetLastWin32Error(), "Failed to set length");
|
||||
}
|
||||
if ((ulong)this.position > (ulong)value)
|
||||
{
|
||||
this.position = (uint)value;
|
||||
}
|
||||
if (Win32.SetFilePointer(this.hFile, (int)this.position, out num, MoveMethod.Begin) == 4294967295U)
|
||||
{
|
||||
throw new Win32Exception(Marshal.GetLastWin32Error(), "Failed to set length");
|
||||
}
|
||||
this.length = (uint)value;
|
||||
}
|
||||
|
||||
public override void Write(byte[] buffer, int offset, int count)
|
||||
{
|
||||
if (!this.open)
|
||||
{
|
||||
throw new InvalidOperationException("Stream is closed");
|
||||
}
|
||||
if (this.mode != FileStreamMode.Write && this.mode != FileStreamMode.ReadWrite)
|
||||
{
|
||||
throw new InvalidOperationException("Cannot write to this stream");
|
||||
}
|
||||
if (count < 0)
|
||||
{
|
||||
throw new ArgumentException("Count must have a positive value");
|
||||
}
|
||||
uint num = (uint)(buffer.Length - offset);
|
||||
if (buffer == null)
|
||||
{
|
||||
throw new ArgumentNullException("Buffer cannot be null");
|
||||
}
|
||||
if ((ulong)num > (ulong)((long)count))
|
||||
{
|
||||
num = (uint)count;
|
||||
}
|
||||
if ((long)count > (long)((ulong)num))
|
||||
{
|
||||
throw new ArgumentException("Buffer too small");
|
||||
}
|
||||
if (num > 0U)
|
||||
{
|
||||
if (!Win32.WriteFile(this.hFile, buffer, (uint)count, out num, UIntPtr.Zero))
|
||||
{
|
||||
throw new Win32Exception(Marshal.GetLastWin32Error(), "Failed to write file");
|
||||
}
|
||||
this.position += num;
|
||||
if (this.length < this.position)
|
||||
{
|
||||
this.length = this.position;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (this.open)
|
||||
{
|
||||
Win32.CloseHandle(this.hFile);
|
||||
}
|
||||
this.open = false;
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
private readonly string path;
|
||||
|
||||
private readonly FileStreamMode mode;
|
||||
|
||||
public bool open;
|
||||
|
||||
private uint position;
|
||||
|
||||
private uint length;
|
||||
|
||||
private IntPtr hFile = (IntPtr)(-1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
public enum FileStreamMode
|
||||
{
|
||||
Read,
|
||||
Write,
|
||||
ReadWrite
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
public static class FileSystem
|
||||
{
|
||||
public static Folder GetFolder(string Path)
|
||||
{
|
||||
Folder folder = null;
|
||||
string text = Path.TrimEnd(new char[]
|
||||
{
|
||||
'\\'
|
||||
});
|
||||
if (FileSystem.UseFolderCache)
|
||||
{
|
||||
KeyedList<string, Folder> folderCache = FileSystem.FolderCache;
|
||||
lock (folderCache)
|
||||
{
|
||||
string key = text.ToLower();
|
||||
if (FileSystem.FolderCache.Contains(key))
|
||||
{
|
||||
folder = FileSystem.FolderCache[key];
|
||||
FileSystem.FolderCache.Remove(folder);
|
||||
FileSystem.FolderCache.Insert(0, folder);
|
||||
return folder;
|
||||
}
|
||||
folder = new Folder(text);
|
||||
FileSystem.FolderCache.Insert(0, folder);
|
||||
while (FileSystem.FolderCache.Count > 100)
|
||||
{
|
||||
FileSystem.FolderCache.RemoveAt(100);
|
||||
}
|
||||
return folder;
|
||||
}
|
||||
}
|
||||
folder = new Folder(text);
|
||||
return folder;
|
||||
}
|
||||
|
||||
public static void ClearFolderCache(string Path)
|
||||
{
|
||||
string key = Path.ToLower();
|
||||
if (FileSystem.FolderCache.Contains(key))
|
||||
{
|
||||
Folder item = FileSystem.FolderCache[key];
|
||||
FileSystem.FolderCache.Remove(item);
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] ReadFile(string Path)
|
||||
{
|
||||
uint num = (uint)FileSystem.GetFileSize(Path);
|
||||
byte[] array = new byte[num];
|
||||
if (num > 0U)
|
||||
{
|
||||
IntPtr intPtr = Win32.CreateFile(Path, (FileAccess)2147483648U, ShareMode.Read | ShareMode.Write | ShareMode.Delete, IntPtr.Zero, CreationDisposition.OpenExisting, FileAttributes.Normal, IntPtr.Zero);
|
||||
if (intPtr == (IntPtr)(-1))
|
||||
{
|
||||
throw new Win32Exception(Marshal.GetLastWin32Error(), "Could not open file");
|
||||
}
|
||||
uint num2;
|
||||
if (!Win32.ReadFile(intPtr, array, num, out num2, UIntPtr.Zero))
|
||||
{
|
||||
Win32.CloseHandle(intPtr);
|
||||
throw new Win32Exception(Marshal.GetLastWin32Error(), "Failed to read file");
|
||||
}
|
||||
Win32.CloseHandle(intPtr);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public static string ReadAsciiFile(string Path)
|
||||
{
|
||||
byte[] array = FileSystem.ReadFile(Path);
|
||||
return Encoding.UTF8.GetString(array, 0, array.Length);
|
||||
}
|
||||
|
||||
public static string ReadUnicodeFile(string Path)
|
||||
{
|
||||
byte[] array = FileSystem.ReadFile(Path);
|
||||
return Encoding.Unicode.GetString(array, 0, array.Length);
|
||||
}
|
||||
|
||||
public static void WriteFile(string Path, byte[] Buffer)
|
||||
{
|
||||
IntPtr intPtr = Win32.CreateFile(Path, FileAccess.GenericWrite, ShareMode.None, IntPtr.Zero, CreationDisposition.CreateAlways, FileAttributes.Normal, IntPtr.Zero);
|
||||
if (intPtr == (IntPtr)(-1))
|
||||
{
|
||||
throw new Win32Exception(Marshal.GetLastWin32Error(), "Could not open file");
|
||||
}
|
||||
uint num;
|
||||
if (!Win32.WriteFile(intPtr, Buffer, (uint)Buffer.Length, out num, UIntPtr.Zero))
|
||||
{
|
||||
Win32.CloseHandle(intPtr);
|
||||
throw new Win32Exception(Marshal.GetLastWin32Error(), "Failed to write file");
|
||||
}
|
||||
Win32.CloseHandle(intPtr);
|
||||
}
|
||||
|
||||
public static void WriteAsciiFile(string Path, string Text)
|
||||
{
|
||||
FileSystem.WriteFile(Path, Encoding.UTF8.GetBytes(Text));
|
||||
}
|
||||
|
||||
public static void WriteUnicodeFile(string Path, string Text)
|
||||
{
|
||||
FileSystem.WriteFile(Path, Encoding.Unicode.GetBytes(Text));
|
||||
}
|
||||
|
||||
public static void CopyFile(string SourceFilePath, string DestinationFilePath)
|
||||
{
|
||||
if (!Win32.CopyFile(SourceFilePath, DestinationFilePath, false))
|
||||
{
|
||||
throw new Win32Exception(Marshal.GetLastWin32Error(), "Failed to copy file");
|
||||
}
|
||||
}
|
||||
|
||||
public static void MoveFile(string SourceFilePath, string DestinationFilePath, MoveFileFlags Flags)
|
||||
{
|
||||
if (!Win32.MoveFileEx(SourceFilePath, DestinationFilePath, Flags))
|
||||
{
|
||||
throw new Win32Exception(Marshal.GetLastWin32Error(), "Failed to move file");
|
||||
}
|
||||
}
|
||||
|
||||
public static bool FileExists(string Path)
|
||||
{
|
||||
return Win32.GetFileAttributes(Path) != (FileAttributes)4294967295U;
|
||||
}
|
||||
|
||||
public static void DeleteFolder(string Path)
|
||||
{
|
||||
foreach (FileSystemEntry fileSystemEntry in FileSystem.GetFolder(Path).GetSubItems())
|
||||
{
|
||||
if (fileSystemEntry.IsFile)
|
||||
{
|
||||
FileSystem.DeleteFile(fileSystemEntry.Path);
|
||||
}
|
||||
else
|
||||
{
|
||||
FileSystem.DeleteFolder(fileSystemEntry.Path);
|
||||
}
|
||||
}
|
||||
if (!Win32.RemoveDirectory(Path))
|
||||
{
|
||||
throw new Win32Exception(Marshal.GetLastWin32Error(), "Failed to delete folder");
|
||||
}
|
||||
}
|
||||
|
||||
public static void CreateFolder(string Path)
|
||||
{
|
||||
if (!Win32.CreateDirectory(Path, IntPtr.Zero) && Marshal.GetLastWin32Error() != 183)
|
||||
{
|
||||
throw new Win32Exception(Marshal.GetLastWin32Error(), "Failed to create folder");
|
||||
}
|
||||
}
|
||||
|
||||
public static void DeleteFile(string Path)
|
||||
{
|
||||
if (!Win32.DeleteFile(Path))
|
||||
{
|
||||
throw new Win32Exception(Marshal.GetLastWin32Error(), "Failed to delete file");
|
||||
}
|
||||
}
|
||||
|
||||
public static void RenameFile(string OldPath, string NewPath)
|
||||
{
|
||||
if (!Win32.MoveFileEx(OldPath, NewPath, (MoveFileFlags)0))
|
||||
{
|
||||
throw new Win32Exception(Marshal.GetLastWin32Error(), "Failed to rename file");
|
||||
}
|
||||
}
|
||||
|
||||
public static ulong GetFileSize(string Path)
|
||||
{
|
||||
WIN32_FILE_ATTRIBUTE_DATA win32_FILE_ATTRIBUTE_DATA;
|
||||
if (!Win32.GetFileAttributesEx(Path, GET_FILEEX_INFO_LEVELS.GetFileExInfoStandard, out win32_FILE_ATTRIBUTE_DATA))
|
||||
{
|
||||
throw new Win32Exception(Marshal.GetLastWin32Error(), "GetFileSize failed");
|
||||
}
|
||||
return (ulong)win32_FILE_ATTRIBUTE_DATA.nFileSizeHigh << 32 | (ulong)win32_FILE_ATTRIBUTE_DATA.nFileSizeLow;
|
||||
}
|
||||
|
||||
public static bool UseFolderCache = false;
|
||||
|
||||
public static int FolderCacheSize = 100;
|
||||
|
||||
private static readonly KeyedList<string, Folder> FolderCache = new KeyedList<string, Folder>((Folder folder) => folder.Path.ToLower());
|
||||
|
||||
public static readonly Folder Root = FileSystem.GetFolder("C:\\");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
using System;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
public class FileSystemEntry : IComparable<FileSystemEntry>
|
||||
{
|
||||
public string Path { get; private set; }
|
||||
|
||||
public string Name { get; private set; }
|
||||
|
||||
internal FileSystemEntry(string Path, FileAttributes Attributes)
|
||||
{
|
||||
string text = Path.TrimEnd(new char[]
|
||||
{
|
||||
'\\'
|
||||
});
|
||||
this.Path = text;
|
||||
this.Name = text;
|
||||
int num = this.Name.LastIndexOf('\\');
|
||||
if (num >= 0)
|
||||
{
|
||||
this.Name = this.Name.Substring(num + 1);
|
||||
}
|
||||
this.Attributes = Attributes;
|
||||
}
|
||||
|
||||
int IComparable<FileSystemEntry>.CompareTo(FileSystemEntry Other)
|
||||
{
|
||||
if (Other == null)
|
||||
{
|
||||
throw new ArgumentException();
|
||||
}
|
||||
if (this.IsFolder && Other.IsFile)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (this.IsFile && Other.IsFolder)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return string.Compare(this.Name, Other.Name, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public bool IsFolder
|
||||
{
|
||||
get
|
||||
{
|
||||
return (this.Attributes & FileAttributes.Directory) > ~FileAttributes.Invalid;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsFile
|
||||
{
|
||||
get
|
||||
{
|
||||
return (this.Attributes & FileAttributes.Directory) == ~FileAttributes.Invalid;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsReadOnly
|
||||
{
|
||||
get
|
||||
{
|
||||
return (this.Attributes & FileAttributes.Readonly) > ~FileAttributes.Invalid;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsHidden
|
||||
{
|
||||
get
|
||||
{
|
||||
return (this.Attributes & FileAttributes.Hidden) > ~FileAttributes.Invalid;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsSystem
|
||||
{
|
||||
get
|
||||
{
|
||||
return (this.Attributes & FileAttributes.System) > ~FileAttributes.Invalid;
|
||||
}
|
||||
}
|
||||
|
||||
public readonly FileAttributes Attributes;
|
||||
|
||||
public readonly FileSystemType Type = FileSystemType.Unknown;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
public enum FileSystemType
|
||||
{
|
||||
Directory,
|
||||
File,
|
||||
Unknown
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
public class Folder : FileSystemEntry
|
||||
{
|
||||
internal Folder(string Path, FileAttributes Attributes) : base(Path, Attributes | FileAttributes.Directory)
|
||||
{
|
||||
}
|
||||
|
||||
internal Folder(string Path) : base(Path, FileAttributes.Directory)
|
||||
{
|
||||
}
|
||||
|
||||
public Folder() : base("", FileAttributes.Directory)
|
||||
{
|
||||
}
|
||||
|
||||
public List<FileSystemEntry> GetSubItems()
|
||||
{
|
||||
this.QueryFolder();
|
||||
return this.SubItems;
|
||||
}
|
||||
|
||||
private void QueryFolder()
|
||||
{
|
||||
object obj = this.queryLockObject;
|
||||
lock (obj)
|
||||
{
|
||||
if (this.SubItems == null)
|
||||
{
|
||||
this.SubItems = new List<FileSystemEntry>();
|
||||
this.subFolderCount = 0;
|
||||
this.fileCount = 0;
|
||||
if (base.Path.Length > 0)
|
||||
{
|
||||
string text = base.Path;
|
||||
if (!base.Path.EndsWith("*"))
|
||||
{
|
||||
if (base.Path.EndsWith("\\"))
|
||||
{
|
||||
text += "*";
|
||||
}
|
||||
else
|
||||
{
|
||||
text += "\\*";
|
||||
}
|
||||
}
|
||||
WIN32_FIND_DATA win32_FIND_DATA;
|
||||
IntPtr intPtr = Win32.FindFirstFile(text, out win32_FIND_DATA);
|
||||
if (intPtr == (IntPtr)(-1))
|
||||
{
|
||||
int lastWin32Error = Marshal.GetLastWin32Error();
|
||||
if (lastWin32Error != 18)
|
||||
{
|
||||
throw new Win32Exception(lastWin32Error, "Failed to query folder");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
do
|
||||
{
|
||||
string text2 = base.Path;
|
||||
if (!base.Path.EndsWith("\\"))
|
||||
{
|
||||
text2 += "\\";
|
||||
}
|
||||
text2 += win32_FIND_DATA.cFileName;
|
||||
if ((win32_FIND_DATA.dwFileAttributes & 16U) != 0U)
|
||||
{
|
||||
if (win32_FIND_DATA.cFileName != "." && win32_FIND_DATA.cFileName != "..")
|
||||
{
|
||||
this.SubItems.Add(FileSystem.GetFolder(text2));
|
||||
this.subFolderCount++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
File file = new File(text2, (FileAttributes)win32_FIND_DATA.dwFileAttributes);
|
||||
file.Size = ((ulong)win32_FIND_DATA.nFileSizeHigh << 32 | (ulong)win32_FIND_DATA.nFileSizeLow);
|
||||
this.SubItems.Add(file);
|
||||
this.fileCount++;
|
||||
}
|
||||
}
|
||||
while (Win32.FindNextFile(intPtr, out win32_FIND_DATA));
|
||||
Win32.FindClose(intPtr);
|
||||
this.SubItems.Sort();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Folder GetParent()
|
||||
{
|
||||
if (base.Path == "" || base.Path == "\\")
|
||||
{
|
||||
return null;
|
||||
}
|
||||
int num = base.Path.LastIndexOf('\\');
|
||||
if (num < 0)
|
||||
{
|
||||
return FileSystem.GetFolder("\\");
|
||||
}
|
||||
return FileSystem.GetFolder(base.Path.Substring(0, num));
|
||||
}
|
||||
|
||||
public void RefreshFolder()
|
||||
{
|
||||
if (this.SubItems != null)
|
||||
{
|
||||
object obj = this.queryLockObject;
|
||||
lock (obj)
|
||||
{
|
||||
this.SubItems = null;
|
||||
this.subFolderCount = -1;
|
||||
this.fileCount = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int GetSubFolderCount()
|
||||
{
|
||||
this.QueryFolder();
|
||||
return this.subFolderCount;
|
||||
}
|
||||
|
||||
public int GetFileCount()
|
||||
{
|
||||
this.QueryFolder();
|
||||
return this.fileCount;
|
||||
}
|
||||
|
||||
public Folder OpenSubFolder(string Name)
|
||||
{
|
||||
return FileSystem.GetFolder(base.Path + "\\" + Name.TrimStart(new char[]
|
||||
{
|
||||
'\\'
|
||||
}));
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return base.Path;
|
||||
}
|
||||
|
||||
private List<FileSystemEntry> SubItems;
|
||||
|
||||
private int subFolderCount = -1;
|
||||
|
||||
private int fileCount = -1;
|
||||
|
||||
private readonly object queryLockObject = new object();
|
||||
|
||||
private readonly object detailLockObject = new object();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
internal enum GET_FILEEX_INFO_LEVELS
|
||||
{
|
||||
GetFileExInfoStandard,
|
||||
GetFileExMaxInfoLevel
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
internal class KeyedList<TKey, TItem> : KeyedCollection<TKey, TItem>
|
||||
{
|
||||
public KeyedList(Func<TItem, TKey> getKeyFunc)
|
||||
{
|
||||
this._getKeyFunc = getKeyFunc;
|
||||
}
|
||||
|
||||
protected override TKey GetKeyForItem(TItem item)
|
||||
{
|
||||
return this._getKeyFunc(item);
|
||||
}
|
||||
|
||||
public bool TryGetValue(TKey key, out TItem item)
|
||||
{
|
||||
if (base.Dictionary == null)
|
||||
{
|
||||
item = default(TItem);
|
||||
return false;
|
||||
}
|
||||
return base.Dictionary.TryGetValue(key, out item);
|
||||
}
|
||||
|
||||
public void AddOrUpdate(TItem item)
|
||||
{
|
||||
if (!this.Contains(item))
|
||||
{
|
||||
base.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
public new bool Contains(TItem item)
|
||||
{
|
||||
return base.Contains(this._getKeyFunc(item));
|
||||
}
|
||||
|
||||
public new bool Contains(TKey key)
|
||||
{
|
||||
return base.Contains(key);
|
||||
}
|
||||
|
||||
public int IndexOf(TKey key)
|
||||
{
|
||||
return base.IndexOf(base[key]);
|
||||
}
|
||||
|
||||
private readonly Func<TItem, TKey> _getKeyFunc;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
[Flags]
|
||||
public enum MoveFileFlags
|
||||
{
|
||||
ReplaceExisting = 1,
|
||||
CopyAllowed = 2,
|
||||
DelayUntilReboot = 4,
|
||||
WriteThrough = 8,
|
||||
CreateHardLink = 16,
|
||||
FailIfNotTrackable = 32
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
public enum MoveMethod : uint
|
||||
{
|
||||
Begin,
|
||||
Current,
|
||||
End
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
internal struct PROCESS_INFORMATION
|
||||
{
|
||||
public IntPtr hProcess;
|
||||
|
||||
public IntPtr hThread;
|
||||
|
||||
public int dwProcessId;
|
||||
|
||||
public int dwThreadId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Versioning;
|
||||
|
||||
[assembly: AssemblyVersion("1.0.5795.42493")]
|
||||
[assembly: AssemblyTitle("WPinternals SDK")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("WPinternals")]
|
||||
[assembly: AssemblyProduct("WPinternals SDK")]
|
||||
[assembly: AssemblyCopyright("Copyright by Heathcliff74 / WPinternals")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: ComVisible(false)]
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
internal struct QUOTA_LIMITS
|
||||
{
|
||||
private readonly uint PagedPoolLimit;
|
||||
|
||||
private readonly uint NonPagedPoolLimit;
|
||||
|
||||
private readonly uint MinimumWorkingSetSize;
|
||||
|
||||
private readonly uint MaximumWorkingSetSize;
|
||||
|
||||
private readonly uint PagefileLimit;
|
||||
|
||||
private readonly long TimeLimit;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
[Flags]
|
||||
public enum RegCreateKeyOption
|
||||
{
|
||||
NonVolatile = 0,
|
||||
Volatile = 1,
|
||||
CreateLink = 2,
|
||||
BackupRestore = 4,
|
||||
OpenLink = 8
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
[Flags]
|
||||
public enum RegOpenKeyOption
|
||||
{
|
||||
OpenLink = 8
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
public enum RegResult
|
||||
{
|
||||
CreatedNewKey = 1,
|
||||
OpenedExistingKey
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
[Flags]
|
||||
public enum RegSAM
|
||||
{
|
||||
QueryValue = 1,
|
||||
SetValue = 2,
|
||||
CreateSubKey = 4,
|
||||
EnumerateSubKeys = 8,
|
||||
Notify = 16,
|
||||
CreateLink = 32,
|
||||
WOW64_32Key = 512,
|
||||
WOW64_64Key = 256,
|
||||
WOW64_Res = 768,
|
||||
Read = 131097,
|
||||
Write = 131078,
|
||||
Execute = 131097,
|
||||
AllAccess = 983103
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,258 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
public static class Registry
|
||||
{
|
||||
public static RegistryKey GetKey(RegistryHive Root, string Key)
|
||||
{
|
||||
return new RegistryKey(Root, Key);
|
||||
}
|
||||
|
||||
public static int GetDWordValue(RegistryHive Root, string Key, string ValueName)
|
||||
{
|
||||
return (int)Registry.GetValue(Root, Key, ValueName);
|
||||
}
|
||||
|
||||
public static void SetDWordValue(RegistryHive Root, string Key, string ValueName, int Value)
|
||||
{
|
||||
Registry.SetValue(Root, Key, ValueName, Value);
|
||||
}
|
||||
|
||||
public static string GetStringValue(RegistryHive Root, string Key, string ValueName)
|
||||
{
|
||||
return (string)Registry.GetValue(Root, Key, ValueName);
|
||||
}
|
||||
|
||||
public static void SetStringValue(RegistryHive Root, string Key, string ValueName, string Value)
|
||||
{
|
||||
Registry.SetValue(Root, Key, ValueName, Value);
|
||||
}
|
||||
|
||||
public static string[] GetMultiStringValue(RegistryHive Root, string Key, string ValueName)
|
||||
{
|
||||
return (string[])Registry.GetValue(Root, Key, ValueName);
|
||||
}
|
||||
|
||||
public static void SetMultiStringValue(RegistryHive Root, string Key, string ValueName, string[] Value)
|
||||
{
|
||||
Registry.SetValue(Root, Key, ValueName, Value);
|
||||
}
|
||||
|
||||
public static byte[] GetBinaryValue(RegistryHive Root, string Key, string ValueName)
|
||||
{
|
||||
return (byte[])Registry.GetValue(Root, Key, ValueName);
|
||||
}
|
||||
|
||||
public static void SetBinaryValue(RegistryHive Root, string Key, string ValueName, byte[] Value)
|
||||
{
|
||||
Registry.SetValue(Root, Key, ValueName, Value);
|
||||
}
|
||||
|
||||
public static void DeleteKey(RegistryHive Root, string Key)
|
||||
{
|
||||
foreach (RegistryItem registryItem in Registry.GetKey(Root, Key).GetSubItems())
|
||||
{
|
||||
if (registryItem is RegistryKey)
|
||||
{
|
||||
Registry.DeleteKey(Root, ((RegistryKey)registryItem).Path);
|
||||
}
|
||||
}
|
||||
int num = Key.LastIndexOf('\\');
|
||||
int num2;
|
||||
if (num < 0)
|
||||
{
|
||||
num2 = Win32.RegDeleteKeyEx((UIntPtr)((uint)Root), Key, 0U, 0U);
|
||||
}
|
||||
else
|
||||
{
|
||||
string lpSubKey = Key.Substring(0, num);
|
||||
string lpSubKey2 = Key.Substring(num + 1);
|
||||
UIntPtr hKey;
|
||||
num2 = Win32.RegOpenKeyEx((UIntPtr)((uint)Root), lpSubKey, (RegOpenKeyOption)0, RegSAM.AllAccess, out hKey);
|
||||
if (num2 != 0)
|
||||
{
|
||||
throw new Win32Exception(num2, "DeleteKey failed");
|
||||
}
|
||||
num2 = Win32.RegDeleteKeyEx(hKey, lpSubKey2, 0U, 0U);
|
||||
Win32.RegCloseKey(hKey);
|
||||
}
|
||||
if (num2 != 0)
|
||||
{
|
||||
throw new Win32Exception(num2, "DeleteKey failed");
|
||||
}
|
||||
}
|
||||
|
||||
public static void CreateKey(RegistryHive Root, string Key)
|
||||
{
|
||||
UIntPtr zero = UIntPtr.Zero;
|
||||
RegResult regResult;
|
||||
int num = Win32.RegCreateKeyEx((UIntPtr)((uint)Root), Key, 0, null, RegCreateKeyOption.NonVolatile, RegSAM.AllAccess, UIntPtr.Zero, out zero, out regResult);
|
||||
if (num != 0)
|
||||
{
|
||||
throw new Win32Exception(num, "CreateKey failed");
|
||||
}
|
||||
if (zero != UIntPtr.Zero)
|
||||
{
|
||||
Win32.RegCloseKey(zero);
|
||||
}
|
||||
}
|
||||
|
||||
public static void DeleteValue(RegistryHive Root, string Key, string ValueName)
|
||||
{
|
||||
UIntPtr hKey = UIntPtr.Zero;
|
||||
int num;
|
||||
if (Key != null && Key.Length > 0)
|
||||
{
|
||||
num = Win32.RegOpenKeyEx((UIntPtr)((uint)Root), Key, (RegOpenKeyOption)0, RegSAM.AllAccess, out hKey);
|
||||
if (num != 0)
|
||||
{
|
||||
throw new Win32Exception(num, "DeleteValue failed");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hKey = (UIntPtr)((uint)Root);
|
||||
}
|
||||
num = Win32.RegDeleteValue(hKey, ValueName);
|
||||
if (Key != null && Key.Length > 0)
|
||||
{
|
||||
Win32.RegCloseKey(hKey);
|
||||
}
|
||||
if (num != 0)
|
||||
{
|
||||
throw new Win32Exception(num, "DeleteValue failed");
|
||||
}
|
||||
}
|
||||
|
||||
public static object GetValue(RegistryHive Root, string Key, string ValueName)
|
||||
{
|
||||
object obj = null;
|
||||
UIntPtr hKey = UIntPtr.Zero;
|
||||
int num;
|
||||
if (Key != null && Key.Length > 0)
|
||||
{
|
||||
num = Win32.RegOpenKeyEx((UIntPtr)((uint)Root), Key, (RegOpenKeyOption)0, RegSAM.AllAccess, out hKey);
|
||||
if (num != 0)
|
||||
{
|
||||
throw new Win32Exception(num, "GetValue failed");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hKey = (UIntPtr)((uint)Root);
|
||||
}
|
||||
RegistryValueType registryValueType = RegistryValueType.None;
|
||||
int num2 = 0;
|
||||
num = Win32.RegQueryValueEx(hKey, ValueName, 0, ref registryValueType, null, ref num2);
|
||||
if (num == 0)
|
||||
{
|
||||
byte[] array = new byte[num2];
|
||||
Win32.RegQueryValueEx(hKey, ValueName, 0, ref registryValueType, array, ref num2);
|
||||
switch (registryValueType)
|
||||
{
|
||||
case RegistryValueType.String:
|
||||
obj = Encoding.Unicode.GetString(array, 0, num2 - 2);
|
||||
break;
|
||||
case RegistryValueType.ExpandString:
|
||||
case (RegistryValueType)5:
|
||||
case (RegistryValueType)6:
|
||||
break;
|
||||
case RegistryValueType.Binary:
|
||||
obj = array;
|
||||
break;
|
||||
case RegistryValueType.DWord:
|
||||
obj = BitConverter.ToInt32(array, 0);
|
||||
break;
|
||||
case RegistryValueType.MultiString:
|
||||
obj = Encoding.Unicode.GetString(array, 0, num2 - 4).Split(new char[1]);
|
||||
break;
|
||||
default:
|
||||
if (registryValueType == RegistryValueType.QWord)
|
||||
{
|
||||
obj = BitConverter.ToInt64(array, 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (Key != null && Key.Length > 0)
|
||||
{
|
||||
Win32.RegCloseKey(hKey);
|
||||
}
|
||||
if (num != 0)
|
||||
{
|
||||
throw new Win32Exception(num, "GetValue failed");
|
||||
}
|
||||
if (obj == null)
|
||||
{
|
||||
throw new NotSupportedException("Registry value cannot be read. Unknown type.");
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
public static void SetValue(RegistryHive Root, string Key, string ValueName, object Value)
|
||||
{
|
||||
byte[] array;
|
||||
RegistryValueType registryValueType;
|
||||
if (Value is string)
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.Append((string)Value);
|
||||
stringBuilder.Append('\0');
|
||||
array = Encoding.Unicode.GetBytes(stringBuilder.ToString());
|
||||
registryValueType = RegistryValueType.String;
|
||||
}
|
||||
else if (Value is uint)
|
||||
{
|
||||
array = BitConverter.GetBytes((uint)Value);
|
||||
registryValueType = RegistryValueType.DWord;
|
||||
}
|
||||
else if (Value is int)
|
||||
{
|
||||
array = BitConverter.GetBytes((int)Value);
|
||||
registryValueType = RegistryValueType.DWord;
|
||||
}
|
||||
else if (Value is ulong)
|
||||
{
|
||||
array = BitConverter.GetBytes((ulong)Value);
|
||||
registryValueType = RegistryValueType.QWord;
|
||||
}
|
||||
else if (Value is long)
|
||||
{
|
||||
array = BitConverter.GetBytes((long)Value);
|
||||
registryValueType = RegistryValueType.QWord;
|
||||
}
|
||||
else if (Value is string[])
|
||||
{
|
||||
string[] array2 = Value as string[];
|
||||
StringBuilder stringBuilder2 = new StringBuilder();
|
||||
for (int i = 0; i < array2.Length; i++)
|
||||
{
|
||||
stringBuilder2.Append(array2[i]);
|
||||
stringBuilder2.Append('\0');
|
||||
}
|
||||
stringBuilder2.Append('\0');
|
||||
array = Encoding.Unicode.GetBytes(stringBuilder2.ToString());
|
||||
registryValueType = RegistryValueType.MultiString;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(Value is byte[]))
|
||||
{
|
||||
throw new NotSupportedException("Registry value cannot be written. Type unknown.");
|
||||
}
|
||||
array = (byte[])Value;
|
||||
registryValueType = RegistryValueType.Binary;
|
||||
}
|
||||
UIntPtr hKey = (UIntPtr)((uint)Root);
|
||||
RegistryValueType dwType = registryValueType;
|
||||
byte[] array3 = array;
|
||||
int num = Win32.RegSetKeyValue(hKey, Key, ValueName, dwType, array3, array3.Length);
|
||||
if (num != 0)
|
||||
{
|
||||
throw new Win32Exception(num, "SetValue failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
public enum RegistryHive : uint
|
||||
{
|
||||
ClassesRoot = 2147483648U,
|
||||
CurrentUser,
|
||||
LocalMachine,
|
||||
Users
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using System;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
public class RegistryItem
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,258 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
public class RegistryKey : RegistryItem
|
||||
{
|
||||
public RegistryKey(RegistryHive Root, string Path)
|
||||
{
|
||||
this.root = Root;
|
||||
this.path = Path;
|
||||
}
|
||||
|
||||
public RegistryHive Root
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.root;
|
||||
}
|
||||
}
|
||||
|
||||
public string Path
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.path;
|
||||
}
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
string text = this.path;
|
||||
int num = text.LastIndexOf('\\');
|
||||
if (num >= 0)
|
||||
{
|
||||
text = text.Substring(num + 1);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
public List<RegistryItem> GetSubItems()
|
||||
{
|
||||
this.QueryKey();
|
||||
return this.SubItems;
|
||||
}
|
||||
|
||||
private void QueryKey()
|
||||
{
|
||||
if (this.SubItems == null)
|
||||
{
|
||||
this.SubItems = new List<RegistryItem>();
|
||||
this.SubKeys = new List<RegistryKey>();
|
||||
this.Values = new List<RegistryValue>();
|
||||
this.subKeyCount = 0;
|
||||
this.valueCount = 0;
|
||||
Dictionary<string, RegistryKey> dictionary = new Dictionary<string, RegistryKey>();
|
||||
Dictionary<string, RegistryValue> dictionary2 = new Dictionary<string, RegistryValue>();
|
||||
UIntPtr uintPtr = UIntPtr.Zero;
|
||||
int num;
|
||||
if (this.Path != null && this.Path.Length > 0)
|
||||
{
|
||||
num = Win32.RegOpenKeyEx((UIntPtr)((uint)this.Root), this.Path, (RegOpenKeyOption)0, RegSAM.AllAccess, out uintPtr);
|
||||
if (num != 0)
|
||||
{
|
||||
throw new Win32Exception(num, "QueryKey failed");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
uintPtr = (UIntPtr)((uint)this.Root);
|
||||
}
|
||||
bool flag = false;
|
||||
uint num2 = 0U;
|
||||
StringBuilder stringBuilder = new StringBuilder(260);
|
||||
do
|
||||
{
|
||||
uint num3 = 260U;
|
||||
long num4;
|
||||
num = Win32.RegEnumKeyEx(uintPtr, num2, stringBuilder, ref num3, UIntPtr.Zero, UIntPtr.Zero, UIntPtr.Zero, out num4);
|
||||
if (num == 0)
|
||||
{
|
||||
RegistryKey value = new RegistryKey(this.root, ((this.path == "") ? "" : (this.path + "\\")) + stringBuilder.ToString());
|
||||
dictionary.Add(stringBuilder.ToString(), value);
|
||||
this.subKeyCount++;
|
||||
num2 += 1U;
|
||||
}
|
||||
else if (num == 259)
|
||||
{
|
||||
num = 0;
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
while (!flag && num == 0);
|
||||
flag = false;
|
||||
num2 = 0U;
|
||||
do
|
||||
{
|
||||
uint num3 = 260U;
|
||||
uint num5 = 0U;
|
||||
byte[] array = null;
|
||||
RegistryValueType registryValueType;
|
||||
Win32.RegEnumValue(uintPtr, num2, stringBuilder, ref num3, UIntPtr.Zero, out registryValueType, array, ref num5);
|
||||
if (num5 > 0U)
|
||||
{
|
||||
array = new byte[num5];
|
||||
}
|
||||
num3 = 260U;
|
||||
num = Win32.RegEnumValue(uintPtr, num2, stringBuilder, ref num3, UIntPtr.Zero, out registryValueType, array, ref num5);
|
||||
object value2 = null;
|
||||
if (num == 0)
|
||||
{
|
||||
switch (registryValueType)
|
||||
{
|
||||
case RegistryValueType.String:
|
||||
value2 = Encoding.Unicode.GetString(array, 0, (int)(num5 - 2U));
|
||||
break;
|
||||
case RegistryValueType.ExpandString:
|
||||
case (RegistryValueType)5:
|
||||
case (RegistryValueType)6:
|
||||
break;
|
||||
case RegistryValueType.Binary:
|
||||
value2 = array;
|
||||
break;
|
||||
case RegistryValueType.DWord:
|
||||
value2 = BitConverter.ToInt32(array, 0);
|
||||
break;
|
||||
case RegistryValueType.MultiString:
|
||||
value2 = Encoding.Unicode.GetString(array, 0, (int)(num5 - 4U)).Split(new char[1]);
|
||||
break;
|
||||
default:
|
||||
if (registryValueType == RegistryValueType.QWord)
|
||||
{
|
||||
value2 = BitConverter.ToInt64(array, 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
RegistryValue value3 = new RegistryValue(this.root, this.path, stringBuilder.ToString(), registryValueType, value2);
|
||||
dictionary2.Add(stringBuilder.ToString(), value3);
|
||||
this.valueCount++;
|
||||
num2 += 1U;
|
||||
}
|
||||
else if (num == 259)
|
||||
{
|
||||
num = 0;
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
while (!flag && num == 0);
|
||||
if (this.Path != null && this.Path.Length > 0)
|
||||
{
|
||||
Win32.RegCloseKey(uintPtr);
|
||||
}
|
||||
if (num != 0)
|
||||
{
|
||||
throw new Win32Exception(num, "QueryKey failed");
|
||||
}
|
||||
foreach (KeyValuePair<string, RegistryKey> keyValuePair in from entry in dictionary
|
||||
orderby entry.Key
|
||||
select entry)
|
||||
{
|
||||
this.SubItems.Add(keyValuePair.Value);
|
||||
this.SubKeys.Add(keyValuePair.Value);
|
||||
}
|
||||
foreach (KeyValuePair<string, RegistryValue> keyValuePair2 in from entry in dictionary2
|
||||
orderby entry.Key
|
||||
select entry)
|
||||
{
|
||||
this.SubItems.Add(keyValuePair2.Value);
|
||||
this.Values.Add(keyValuePair2.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public RegistryKey GetParent()
|
||||
{
|
||||
if (this.path == "")
|
||||
{
|
||||
return null;
|
||||
}
|
||||
int num = this.path.LastIndexOf('\\');
|
||||
if (num < 0)
|
||||
{
|
||||
return new RegistryKey(this.root, "");
|
||||
}
|
||||
return new RegistryKey(this.root, this.path.Substring(0, num));
|
||||
}
|
||||
|
||||
public void RefreshKey()
|
||||
{
|
||||
this.SubItems = null;
|
||||
this.subKeyCount = -1;
|
||||
this.valueCount = -1;
|
||||
}
|
||||
|
||||
public int GetSubKeyCount()
|
||||
{
|
||||
this.QueryKey();
|
||||
return this.subKeyCount;
|
||||
}
|
||||
|
||||
public int GetValueCount()
|
||||
{
|
||||
this.QueryKey();
|
||||
return this.valueCount;
|
||||
}
|
||||
|
||||
public RegistryKey GetSubKey(string Key)
|
||||
{
|
||||
return new RegistryKey(this.root, this.path + ((this.path == "") ? "" : "\\") + Key);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "Subkey: " + this.Name;
|
||||
}
|
||||
|
||||
private static RegistryValueType GetValueKindFromObject(object Value)
|
||||
{
|
||||
RegistryValueType result = RegistryValueType.Unknown;
|
||||
if (Value is int || Value is uint)
|
||||
{
|
||||
result = RegistryValueType.DWord;
|
||||
}
|
||||
if (Value is string)
|
||||
{
|
||||
result = RegistryValueType.String;
|
||||
}
|
||||
if (Value is byte[])
|
||||
{
|
||||
result = RegistryValueType.Binary;
|
||||
}
|
||||
if (Value is string[])
|
||||
{
|
||||
result = RegistryValueType.MultiString;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private readonly string path;
|
||||
|
||||
private readonly RegistryHive root;
|
||||
|
||||
private List<RegistryItem> SubItems;
|
||||
|
||||
private List<RegistryKey> SubKeys;
|
||||
|
||||
private List<RegistryValue> Values;
|
||||
|
||||
private int subKeyCount = -1;
|
||||
|
||||
private int valueCount = -1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
using System;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
public class RegistryValue : RegistryItem
|
||||
{
|
||||
public RegistryValue(RegistryHive Root, string Key, string ValueName, RegistryValueType Type, object Value)
|
||||
{
|
||||
this.root = Root;
|
||||
this.key = Key;
|
||||
this.valueName = ValueName;
|
||||
this.type = Type;
|
||||
this.value = Value;
|
||||
}
|
||||
|
||||
public RegistryHive Root
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.root;
|
||||
}
|
||||
}
|
||||
|
||||
public string Key
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.key;
|
||||
}
|
||||
}
|
||||
|
||||
public string ValueName
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.valueName;
|
||||
}
|
||||
}
|
||||
|
||||
public RegistryValueType Type
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.type;
|
||||
}
|
||||
}
|
||||
|
||||
public object Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string text = null;
|
||||
RegistryValueType registryValueType = this.type;
|
||||
switch (registryValueType)
|
||||
{
|
||||
case RegistryValueType.String:
|
||||
text = (string)this.value;
|
||||
break;
|
||||
case RegistryValueType.ExpandString:
|
||||
case (RegistryValueType)5:
|
||||
case (RegistryValueType)6:
|
||||
break;
|
||||
case RegistryValueType.Binary:
|
||||
text = "<Binary>";
|
||||
break;
|
||||
case RegistryValueType.DWord:
|
||||
text = "0x" + ((int)this.value).ToString("X8");
|
||||
break;
|
||||
case RegistryValueType.MultiString:
|
||||
text = "<Multistring>";
|
||||
break;
|
||||
default:
|
||||
if (registryValueType == RegistryValueType.QWord)
|
||||
{
|
||||
text = "0x" + ((long)this.value).ToString("X16");
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (text == null)
|
||||
{
|
||||
return this.ValueName + ": <Unknown>";
|
||||
}
|
||||
return this.ValueName + ": " + text;
|
||||
}
|
||||
|
||||
private readonly RegistryHive root;
|
||||
|
||||
private readonly string key;
|
||||
|
||||
private readonly string valueName;
|
||||
|
||||
private readonly RegistryValueType type = RegistryValueType.Unknown;
|
||||
|
||||
private readonly object value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
public enum RegistryValueType
|
||||
{
|
||||
String = 1,
|
||||
ExpandString,
|
||||
Binary,
|
||||
DWord,
|
||||
MultiString = 7,
|
||||
QWord = 11,
|
||||
Unknown = -1,
|
||||
None
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
internal struct SECURITY_ATTRIBUTES
|
||||
{
|
||||
public int nLength;
|
||||
|
||||
public IntPtr lpSecurityDescriptor;
|
||||
|
||||
public int bInheritHandle;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
internal struct STARTUPINFO
|
||||
{
|
||||
public int cb;
|
||||
|
||||
public string lpReserved;
|
||||
|
||||
public string lpDesktop;
|
||||
|
||||
public string lpTitle;
|
||||
|
||||
public int dwX;
|
||||
|
||||
public int dwY;
|
||||
|
||||
public int dwXSize;
|
||||
|
||||
public int dwYSize;
|
||||
|
||||
public int dwXCountChars;
|
||||
|
||||
public int dwYCountChars;
|
||||
|
||||
public int dwFillAttribute;
|
||||
|
||||
public int dwFlags;
|
||||
|
||||
public short wShowWindow;
|
||||
|
||||
public short cbReserved2;
|
||||
|
||||
public IntPtr lpReserved2;
|
||||
|
||||
public IntPtr hStdInput;
|
||||
|
||||
public IntPtr hStdOutput;
|
||||
|
||||
public IntPtr hStdError;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
[Flags]
|
||||
internal enum ShareMode : uint
|
||||
{
|
||||
None = 0U,
|
||||
Read = 1U,
|
||||
Write = 2U,
|
||||
Delete = 4U
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
internal struct WIN32_FILE_ATTRIBUTE_DATA
|
||||
{
|
||||
public FileAttributes dwFileAttributes;
|
||||
|
||||
public FILETIME ftCreationTime;
|
||||
|
||||
public FILETIME ftLastAccessTime;
|
||||
|
||||
public FILETIME ftLastWriteTime;
|
||||
|
||||
public uint nFileSizeHigh;
|
||||
|
||||
public uint nFileSizeLow;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
internal struct WIN32_FIND_DATA
|
||||
{
|
||||
public uint dwFileAttributes;
|
||||
|
||||
public FILETIME ftCreationTime;
|
||||
|
||||
public FILETIME ftLastAccessTime;
|
||||
|
||||
public FILETIME ftLastWriteTime;
|
||||
|
||||
public uint nFileSizeHigh;
|
||||
|
||||
public uint nFileSizeLow;
|
||||
|
||||
public uint dwReserved0;
|
||||
|
||||
public uint dwReserved1;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
|
||||
public string cFileName;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
|
||||
public string cAlternateFileName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<MSBuildAllProjects Condition="'$(MSBuildVersion)' == '' Or '$(MSBuildVersion)' < '16.0'">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
|
||||
<HasSharedItems>true</HasSharedItems>
|
||||
<SharedGUID>d29275f2-bb58-44a2-81e1-96d68c4c48db</SharedGUID>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="Configuration">
|
||||
<Import_RootNamespace>WPinternalsSDK</Import_RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)CreationDisposition.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Environment.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)File.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)FileAccess.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)FileAttributes.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)FileStream.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)FileStreamMode.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)FileSystem.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)FileSystemEntry.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)FileSystemType.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)FILETIME.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Folder.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)GET_FILEEX_INFO_LEVELS.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)KeyedList.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)MoveFileFlags.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)MoveMethod.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)PROCESS_INFORMATION.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)QUOTA_LIMITS.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)RegCreateKeyOption.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Registry.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)RegistryHive.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)RegistryItem.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)RegistryKey.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)RegistryValue.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)RegistryValueType.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)RegOpenKeyOption.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)RegResult.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)RegSAM.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)SECURITY_ATTRIBUTES.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ShareMode.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)STARTUPINFO.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Win32.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Win32Exception.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)WIN32_FILE_ATTRIBUTE_DATA.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)WIN32_FIND_DATA.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>d29275f2-bb58-44a2-81e1-96d68c4c48db</ProjectGuid>
|
||||
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
|
||||
<PropertyGroup />
|
||||
<Import Project="WPinternalsSDK.projitems" Label="Shared" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -0,0 +1,102 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
internal class Win32
|
||||
{
|
||||
[DllImport("KERNELBASE.DLL", CharSet = CharSet.Unicode)]
|
||||
internal static extern int RegDeleteKeyEx(UIntPtr hKey, string lpSubKey, uint samDesired, uint Reserved);
|
||||
|
||||
[DllImport("KERNELBASE.DLL", CharSet = CharSet.Unicode)]
|
||||
internal static extern int RegCreateKeyEx(UIntPtr hKey, string lpSubKey, int Reserved, string lpClass, RegCreateKeyOption dwOptions, RegSAM samDesired, UIntPtr lpSecurityAttributes, out UIntPtr phkResult, out RegResult lpdwDisposition);
|
||||
|
||||
[DllImport("KERNELBASE.DLL")]
|
||||
internal static extern int RegCloseKey(UIntPtr hKey);
|
||||
|
||||
[DllImport("KERNELBASE.DLL", CharSet = CharSet.Unicode)]
|
||||
internal static extern int RegDeleteValue(UIntPtr hKey, string lpValueName);
|
||||
|
||||
[DllImport("KERNELBASE.DLL", CharSet = CharSet.Unicode)]
|
||||
internal static extern int RegOpenKeyEx(UIntPtr hKey, string lpSubKey, RegOpenKeyOption dwOptions, RegSAM samDesired, out UIntPtr phkResult);
|
||||
|
||||
[DllImport("Powrprof.dll", SetLastError = true)]
|
||||
internal static extern bool SetSuspendState(bool hibernate, bool forceCritical, bool disableWakeEvent);
|
||||
|
||||
[DllImport("ShellChromeAPI.dll")]
|
||||
internal static extern int Shell_RequestShutdown(int ShutDownType);
|
||||
|
||||
[DllImport("KERNELBASE.DLL", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
internal static extern bool CreateProcess(string lpApplicationName, string lpCommandLine, UIntPtr lpProcessAttributes, UIntPtr lpThreadAttributes, bool bInheritHandles, uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, [In] ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);
|
||||
|
||||
[DllImport("KERNELBASE.DLL", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool CloseHandle(IntPtr hObject);
|
||||
|
||||
[DllImport("KERNELBASE.DLL", CharSet = CharSet.Unicode)]
|
||||
internal static extern int RegQueryValueEx(UIntPtr hKey, string lpValueName, int lpReserved, ref RegistryValueType lpType, byte[] lpData, ref int lpcbData);
|
||||
|
||||
[DllImport("SSPICLI.DLL", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
internal static extern bool LogonUserExEx(string Username, string Domain, string Password, uint LogonType, uint LogonProvider, UIntPtr TokenGroups, out IntPtr hToken, out UIntPtr pLogonSid, out UIntPtr pBuffer, out uint BufferLength, UIntPtr Reserved);
|
||||
|
||||
[DllImport("KERNELBASE.DLL", CharSet = CharSet.Unicode)]
|
||||
internal static extern int RegSetKeyValue(UIntPtr hKey, string lpSubKey, string lpValueName, RegistryValueType dwType, byte[] lpData, int cbData);
|
||||
|
||||
[DllImport("KERNELBASE.DLL", CharSet = CharSet.Unicode)]
|
||||
internal static extern int RegEnumKeyEx(UIntPtr hkey, uint index, StringBuilder lpName, ref uint lpcbName, UIntPtr reserved, UIntPtr lpClass, UIntPtr lpcbClass, out long lpftLastWriteTime);
|
||||
|
||||
[DllImport("KERNELBASE.DLL", CharSet = CharSet.Unicode)]
|
||||
internal static extern int RegEnumValue(UIntPtr hKey, uint dwIndex, StringBuilder lpValueName, ref uint lpcValueName, UIntPtr lpReserved, out RegistryValueType lpType, byte[] lpData, ref uint lpcbData);
|
||||
|
||||
[DllImport("KERNELBASE.DLL", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool GetFileAttributesEx(string lpFileName, GET_FILEEX_INFO_LEVELS fInfoLevelId, out WIN32_FILE_ATTRIBUTE_DATA fileData);
|
||||
|
||||
[DllImport("KERNELBASE.DLL", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
internal static extern FileAttributes GetFileAttributes(string lpFileName);
|
||||
|
||||
[DllImport("KERNELBASE.DLL", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
internal static extern IntPtr CreateFile([MarshalAs(UnmanagedType.LPWStr)] string filename, [MarshalAs(UnmanagedType.U4)] FileAccess access, [MarshalAs(UnmanagedType.U4)] ShareMode share, IntPtr securityAttributes, [MarshalAs(UnmanagedType.U4)] CreationDisposition creationDisposition, [MarshalAs(UnmanagedType.U4)] FileAttributes flagsAndAttributes, IntPtr templateFile);
|
||||
|
||||
[DllImport("KERNELBASE.DLL", SetLastError = true)]
|
||||
internal static extern bool ReadFile(IntPtr hFile, [Out] byte[] lpBuffer, uint nNumberOfBytesToRead, out uint lpNumberOfBytesRead, UIntPtr lpOverlapped);
|
||||
|
||||
[DllImport("KERNELBASE.DLL", SetLastError = true)]
|
||||
internal static extern bool WriteFile(IntPtr hFile, byte[] lpBuffer, uint nNumberOfBytesToWrite, out uint lpNumberOfBytesWritten, [In] UIntPtr lpOverlapped);
|
||||
|
||||
[DllImport("KERNELBASE.DLL", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
internal static extern bool CopyFile(string lpExistingFileName, string lpNewFileName, bool bFailIfExists);
|
||||
|
||||
[DllImport("KERNELBASE.DLL", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
internal static extern bool MoveFileEx(string lpExistingFileName, string lpNewFileName, MoveFileFlags Flags);
|
||||
|
||||
[DllImport("KERNELBASE.DLL", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
internal static extern bool RemoveDirectory(string lpPathName);
|
||||
|
||||
[DllImport("KERNELBASE.DLL", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
internal static extern bool CreateDirectory(string lpPathName, IntPtr lpSecurityAttributes);
|
||||
|
||||
[DllImport("KERNELBASE.DLL", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
internal static extern bool DeleteFile(string lpFileName);
|
||||
|
||||
[DllImport("KERNELBASE.DLL", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
internal static extern uint SetFilePointer([In] IntPtr hFile, [In] int lDistanceToMove, out int lpDistanceToMoveHigh, [In] MoveMethod dwMoveMethod);
|
||||
|
||||
[DllImport("KERNELBASE.DLL", SetLastError = true)]
|
||||
internal static extern bool SetEndOfFile(IntPtr hFile);
|
||||
|
||||
[DllImport("KERNELBASE.DLL", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
internal static extern IntPtr FindFirstFile(string lpFileName, out WIN32_FIND_DATA lpFindFileData);
|
||||
|
||||
[DllImport("KERNELBASE.DLL", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
internal static extern bool FindNextFile(IntPtr hFindFile, out WIN32_FIND_DATA lpFindFileData);
|
||||
|
||||
[DllImport("KERNELBASE.DLL", SetLastError = true)]
|
||||
internal static extern bool FindClose(IntPtr hFindFile);
|
||||
|
||||
internal const uint INVALID_SET_FILE_POINTER = 4294967295U;
|
||||
|
||||
internal const int ERROR_NO_MORE_FILES = 18;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
|
||||
namespace WPinternalsSDK
|
||||
{
|
||||
public class Win32Exception : Exception
|
||||
{
|
||||
public Win32Exception(int HResult)
|
||||
{
|
||||
this.HResult = HResult;
|
||||
}
|
||||
|
||||
public Win32Exception(int HResult, string Message) : base(Message)
|
||||
{
|
||||
this.HResult = HResult;
|
||||
}
|
||||
|
||||
public new int HResult
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._HResult;
|
||||
}
|
||||
set
|
||||
{
|
||||
this._HResult = value;
|
||||
}
|
||||
}
|
||||
|
||||
private int _HResult;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user