Changeset 1543
- Timestamp:
- 1/18/2010 4:19:42 AM (3 years ago)
- Location:
- branches/eraser6/CodeReview/Eraser.Util
- Files:
-
- 10 added
- 11 edited
-
AdvApi.cs (modified) (6 diffs)
-
Eraser.Util.csproj (modified) (1 diff)
-
KernelApi.cs (modified) (5 diffs)
-
MsCorEEApi.cs (modified) (1 diff)
-
NTApi.cs (modified) (2 diffs)
-
NativeMethods (added)
-
NativeMethods/AdvApi.cs (added)
-
NativeMethods/Kernel.cs (added)
-
NativeMethods/MsCorEE.cs (added)
-
NativeMethods/NetApi.cs (added)
-
NativeMethods/NtDll.cs (added)
-
NativeMethods/Shell.cs (added)
-
NativeMethods/User.cs (added)
-
NativeMethods/UxTheme.cs (added)
-
NativeMethods/WinTrust.cs (added)
-
NetApi.cs (modified) (1 diff)
-
NtfsApi.cs (modified) (2 diffs)
-
ShellApi.cs (modified) (2 diffs)
-
UserApi.cs (modified) (1 diff)
-
UxThemeApi.cs (modified) (3 diffs)
-
WintrustApi.cs (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eraser6/CodeReview/Eraser.Util/AdvApi.cs
r1359 r1543 60 60 //Get the process token. 61 61 SafeTokenHandle hToken = new SafeTokenHandle(); 62 bool result = NativeMethods.OpenProcessToken( KernelApi.NativeMethods.GetCurrentProcess(),62 bool result = NativeMethods.OpenProcessToken(NativeMethods.GetCurrentProcess(), 63 63 NativeMethods.TOKEN_QUERY, out hToken); 64 64 if (!result || hToken.IsInvalid) … … 90 90 } 91 91 } 92 93 /// <summary>94 /// Stores functions, structs and constants from Advapi32.dll95 /// </summary>96 internal static class NativeMethods97 {98 /// <summary>99 /// The CryptAcquireContext function is used to acquire a handle to a100 /// particular key container within a particular cryptographic service101 /// provider (CSP). This returned handle is used in calls to CryptoAPI102 /// functions that use the selected CSP.103 ///104 /// This function first attempts to find a CSP with the characteristics105 /// described in the dwProvType and pszProvider parameters. If the CSP106 /// is found, the function attempts to find a key container within the107 /// CSP that matches the name specified by the pszContainer parameter.108 /// To acquire the context and the key container of a private key109 /// associated with the public key of a certificate, use110 /// CryptAcquireCertificatePrivateKey.111 ///112 /// With the appropriate setting of dwFlags, this function can also create113 /// and destroy key containers and can provide access to a CSP with a114 /// temporary key container if access to a private key is not required.115 /// </summary>116 /// <param name="phProv">A pointer to a handle of a CSP. When you have117 /// finished using the CSP, release the handle by calling the118 /// CryptReleaseContext function.</param>119 /// <param name="pszContainer">The key container name. This is a120 /// null-terminated string that identifies the key container to the CSP.121 /// This name is independent of the method used to store the keys.122 /// Some CSPs store their key containers internally (in hardware),123 /// some use the system registry, and others use the file system. When124 /// dwFlags is set to CRYPT_VERIFYCONTEXT, pszContainer must be set to NULL.125 ///126 /// When pszContainer is NULL, a default key container name is used. For127 /// example, the Microsoft Base Cryptographic Provider uses the logon name128 /// of the currently logged on user as the key container name. Other CSPs129 /// can also have default key containers that can be acquired in this way.130 ///131 /// Applications must not use the default key container to store private132 /// keys. When multiple applications use the same container, one application133 /// can change or destroy the keys that another application needs to have134 /// available. If applications use key containers linked to the application,135 /// the risk is reduced of other applications tampering with keys necessary136 /// for proper function.137 ///138 /// An application can obtain the name of the key container in use by139 /// reading the PP_CONTAINER value with the CryptGetProvParam function.</param>140 /// <param name="pszProvider">A null-terminated string that specifies the141 /// name of the CSP to be used.142 ///143 /// If this parameter is NULL, the user default provider is used. For more144 /// information, see Cryptographic Service Provider Contexts. For a list145 /// of available cryptographic providers, see Cryptographic Provider Names.146 ///147 /// An application can obtain the name of the CSP in use by using the148 /// CryptGetProvParam function to read the PP_NAME CSP value in the dwParam149 /// parameter.150 ///151 /// Due to changing export control restrictions, the default CSP can change152 /// between operating system releases. To ensure interoperability on153 /// different operating system platforms, the CSP should be explicitly154 /// set by using this parameter instead of using the default CSP.</param>155 /// <param name="dwProvType">Specifies the type of provider to acquire.156 /// Defined provider types are discussed in Cryptographic Provider Types.</param>157 /// <param name="dwFlags">Flag values. This parameter is usually set to zero,158 /// but some applications set one or more flags.</param>159 /// <returns> If the function succeeds, the function returns nonzero (TRUE).160 /// If the function fails, it returns zero (FALSE). For extended error161 /// information, call Marshal.GetLastWin32Error.</returns>162 [DllImport("Advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]163 [return: MarshalAs(UnmanagedType.Bool)]164 public static extern bool CryptAcquireContext(out SafeCryptHandle phProv,165 string pszContainer, string pszProvider, uint dwProvType, uint dwFlags);166 167 /// <summary>168 /// The CryptGenRandom function fills a buffer with cryptographically random bytes.169 /// </summary>170 /// <param name="hProv">Handle of a cryptographic service provider (CSP)171 /// created by a call to CryptAcquireContext.</param>172 /// <param name="dwLen">Number of bytes of random data to be generated.</param>173 /// <param name="pbBuffer">Buffer to receive the returned data. This buffer174 /// must be at least dwLen bytes in length.175 ///176 /// Optionally, the application can fill this buffer with data to use as177 /// an auxiliary random seed.</param>178 [DllImport("Advapi32.dll", SetLastError = true)]179 [return: MarshalAs(UnmanagedType.Bool)]180 public static extern bool CryptGenRandom(SafeCryptHandle hProv, uint dwLen,181 byte[] pbBuffer);182 183 /// <summary>184 /// The CryptReleaseContext function releases the handle of a cryptographic185 /// service provider (CSP) and a key container. At each call to this function,186 /// the reference count on the CSP is reduced by one. When the reference187 /// count reaches zero, the context is fully released and it can no longer188 /// be used by any function in the application.189 ///190 /// An application calls this function after finishing the use of the CSP.191 /// After this function is called, the released CSP handle is no longer192 /// valid. This function does not destroy key containers or key pairs</summary>193 /// <param name="hProv">Handle of a cryptographic service provider (CSP)194 /// created by a call to CryptAcquireContext.</param>195 /// <param name="dwFlags">Reserved for future use and must be zero. If196 /// dwFlags is not set to zero, this function returns FALSE but the CSP197 /// is released.</param>198 /// <returns>If the function succeeds, the return value is nonzero (TRUE).199 ///200 /// If the function fails, the return value is zero (FALSE). For extended201 /// error information, call Marshal.GetLastWin32Error.</returns>202 [DllImport("Advapi32.dll", SetLastError = true)]203 [return: MarshalAs(UnmanagedType.Bool)]204 public static extern bool CryptReleaseContext(IntPtr hProv, uint dwFlags);205 206 public const uint PROV_RSA_FULL = 1;207 public const uint PROV_RSA_SIG = 2;208 public const uint PROV_DSS = 3;209 public const uint PROV_FORTEZZA = 4;210 public const uint PROV_MS_EXCHANGE = 5;211 public const uint PROV_SSL = 6;212 public const uint PROV_RSA_SCHANNEL = 12;213 public const uint PROV_DSS_DH = 13;214 public const uint PROV_EC_ECDSA_SIG = 14;215 public const uint PROV_EC_ECNRA_SIG = 15;216 public const uint PROV_EC_ECDSA_FULL = 16;217 public const uint PROV_EC_ECNRA_FULL = 17;218 public const uint PROV_DH_SCHANNEL = 18;219 public const uint PROV_SPYRUS_LYNKS = 20;220 public const uint PROV_RNG = 21;221 public const uint PROV_INTEL_SEC = 22;222 223 public const int NTE_BAD_KEYSET = unchecked((int)0x80090016);224 225 public const uint CRYPT_VERIFYCONTEXT = 0xF0000000;226 public const uint CRYPT_NEWKEYSET = 0x00000008;227 public const uint CRYPT_DELETEKEYSET = 0x00000010;228 public const uint CRYPT_MACHINE_KEYSET = 0x00000020;229 public const uint CRYPT_SILENT = 0x00000040;230 231 /// <summary>232 /// The GetTokenInformation function retrieves a specified type of information233 /// about an access token. The calling process must have appropriate access234 /// rights to obtain the information.235 /// </summary>236 /// <param name="TokenHandle">A handle to an access token from which237 /// information is retrieved. If TokenInformationClass specifies TokenSource,238 /// the handle must have TOKEN_QUERY_SOURCE access. For all other239 /// TokenInformationClass values, the handle must have TOKEN_QUERY access.</param>240 /// <param name="TokenInformationClass">Specifies a value from the241 /// TOKEN_INFORMATION_CLASS enumerated type to identify the type of242 /// information the function retrieves.</param>243 /// <param name="TokenInformation">A pointer to a buffer the function244 /// fills with the requested information. The structure put into this245 /// buffer depends upon the type of information specified by the246 /// TokenInformationClass parameter.</param>247 /// <param name="TokenInformationLength">Specifies the size, in bytes,248 /// of the buffer pointed to by the TokenInformation parameter.249 /// If TokenInformation is NULL, this parameter must be zero.</param>250 /// <param name="ReturnLength">A pointer to a variable that receives the251 /// number of bytes needed for the buffer pointed to by the TokenInformation252 /// parameter. If this value is larger than the value specified in the253 /// TokenInformationLength parameter, the function fails and stores no254 /// data in the buffer.255 ///256 /// If the value of the TokenInformationClass parameter is TokenDefaultDacl257 /// and the token has no default DACL, the function sets the variable pointed258 /// to by ReturnLength to sizeof(TOKEN_DEFAULT_DACL) and sets the259 /// DefaultDacl member of the TOKEN_DEFAULT_DACL structure to NULL.</param>260 /// <returns> If the function succeeds, the return value is true. To get261 /// extended error information, call Marshal.GetLastWin32Error().</returns>262 [DllImport("Advapi32.dll", SetLastError = true)]263 [return: MarshalAs(UnmanagedType.Bool)]264 public static extern bool GetTokenInformation(SafeTokenHandle TokenHandle,265 TOKEN_INFORMATION_CLASS TokenInformationClass, IntPtr TokenInformation,266 uint TokenInformationLength, out uint ReturnLength);267 268 /// <summary>269 /// The OpenProcessToken function opens the access token associated with a process.270 /// </summary>271 /// <param name="ProcessHandle">A handle to the process whose access token272 /// is opened. The process must have the PROCESS_QUERY_INFORMATION access273 /// permission.</param>274 /// <param name="DesiredAccess">Specifies an access mask that specifies275 /// the requested types of access to the access token. These requested276 /// access types are compared with the discretionary access control277 /// list (DACL) of the token to determine which accesses are granted or278 /// denied.</param>279 /// <param name="TokenHandle">A pointer to a handle that identifies the280 /// newly opened access token when the function returns.</param>281 /// <returns> If the function succeeds, the return value is true. To get282 /// extended error information, call Marshal.GetLastWin32Error().</returns>283 [DllImport("Advapi32.dll", SetLastError = true)]284 [return: MarshalAs(UnmanagedType.Bool)]285 public static extern bool OpenProcessToken(IntPtr ProcessHandle,286 UInt32 DesiredAccess, out SafeTokenHandle TokenHandle);287 288 public const uint STANDARD_RIGHTS_REQUIRED = 0xF0000;289 public const uint TOKEN_ASSIGN_PRIMARY = 0x00001;290 public const uint TOKEN_DUPLICATE = 0x00002;291 public const uint TOKEN_IMPERSONATE = 0x00004;292 public const uint TOKEN_QUERY = 0x00008;293 public const uint TOKEN_QUERY_SOURCE = 0x00010;294 public const uint TOKEN_ADJUST_PRIVILEGES = 0x00020;295 public const uint TOKEN_ADJUST_GROUPS = 0x00040;296 public const uint TOKEN_ADJUST_DEFAULT = 0x00080;297 public const uint TOKEN_ADJUST_SESSIONID = 0x00100;298 public const uint TOKEN_ALL_ACCESS_P = (STANDARD_RIGHTS_REQUIRED |299 TOKEN_ASSIGN_PRIMARY | TOKEN_DUPLICATE | TOKEN_IMPERSONATE | TOKEN_QUERY |300 TOKEN_QUERY_SOURCE | TOKEN_ADJUST_PRIVILEGES | TOKEN_ADJUST_GROUPS |301 TOKEN_ADJUST_DEFAULT);302 303 public enum TOKEN_INFORMATION_CLASS304 {305 TokenUser = 1,306 TokenGroups = 2,307 TokenPrivileges = 3,308 TokenOwner = 4,309 TokenPrimaryGroup = 5,310 TokenDefaultDacl = 6,311 TokenSource = 7,312 TokenType = 8,313 TokenImpersonationLevel = 9,314 TokenStatistics = 10,315 TokenRestrictedSids = 11,316 TokenSessionId = 12,317 TokenGroupsAndPrivileges = 13,318 TokenSessionReference = 14,319 TokenSandBoxInert = 15,320 TokenAuditPolicy = 16,321 TokenOrigin = 17,322 TokenElevationType = 18,323 TokenLinkedToken = 19,324 TokenElevation = 20,325 TokenHasRestrictions = 21,326 TokenAccessInformation = 22,327 TokenVirtualizationAllowed = 23,328 TokenVirtualizationEnabled = 24,329 TokenIntegrityLevel = 25,330 TokenUIAccess = 26,331 TokenMandatoryPolicy = 27,332 TokenLogonSid = 28,333 MaxTokenInfoClass = 29 // MaxTokenInfoClass should always be the last enum334 }335 336 public enum TOKEN_ELEVATION_TYPE337 {338 TokenElevationTypeDefault = 1,339 TokenElevationTypeFull = 2,340 TokenElevationTypeLimited = 3,341 }342 }343 92 } 344 93 … … 354 103 355 104 handle = new SafeCryptHandle(); 356 if ( AdvApi.NativeMethods.CryptAcquireContext(out handle, string.Empty,357 IntelDefaultProvider, AdvApi.NativeMethods.PROV_INTEL_SEC, 0))105 if (NativeMethods.CryptAcquireContext(out handle, string.Empty, 106 IntelDefaultProvider, NativeMethods.PROV_INTEL_SEC, 0)) 358 107 { 359 108 return; 360 109 } 361 else if ( AdvApi.NativeMethods.CryptAcquireContext(out handle, string.Empty,362 string.Empty, AdvApi.NativeMethods.PROV_RSA_FULL, 0))110 else if (NativeMethods.CryptAcquireContext(out handle, string.Empty, 111 string.Empty, NativeMethods.PROV_RSA_FULL, 0)) 363 112 { 364 113 return; 365 114 } 366 else if (Marshal.GetLastWin32Error() == AdvApi.NativeMethods.NTE_BAD_KEYSET)115 else if (Marshal.GetLastWin32Error() == NativeMethods.NTE_BAD_KEYSET) 367 116 { 368 117 //Default keyset doesn't exist, attempt to create a new one 369 if (AdvApi.NativeMethods.CryptAcquireContext(out handle, string.Empty, 370 string.Empty, AdvApi.NativeMethods.PROV_RSA_FULL, 371 AdvApi.NativeMethods.CRYPT_NEWKEYSET)) 118 if (NativeMethods.CryptAcquireContext(out handle, string.Empty, string.Empty, 119 NativeMethods.PROV_RSA_FULL, NativeMethods.CRYPT_NEWKEYSET)) 372 120 { 373 121 return; … … 407 155 public static bool CryptGenRandom(byte[] buffer) 408 156 { 409 return AdvApi.NativeMethods.CryptGenRandom(instance.handle, 410 (uint)buffer.Length, buffer); 157 return NativeMethods.CryptGenRandom(instance.handle, (uint)buffer.Length, buffer); 411 158 } 412 159 … … 436 183 protected override bool ReleaseHandle() 437 184 { 438 AdvApi.NativeMethods.CryptReleaseContext(handle, 0u);185 NativeMethods.CryptReleaseContext(handle, 0u); 439 186 handle = IntPtr.Zero; 440 187 return true; … … 456 203 protected override bool ReleaseHandle() 457 204 { 458 KernelApi.NativeMethods.CloseHandle(handle);205 NativeMethods.CloseHandle(handle); 459 206 handle = IntPtr.Zero; 460 207 return true; -
branches/eraser6/CodeReview/Eraser.Util/Eraser.Util.csproj
r1529 r1543 53 53 <Compile Include="Localisation.cs" /> 54 54 <Compile Include="MsCorEEApi.cs" /> 55 <Compile Include="NativeMethods\AdvApi.cs" /> 56 <Compile Include="NativeMethods\Kernel.cs" /> 57 <Compile Include="NativeMethods\MsCorEE.cs" /> 58 <Compile Include="NativeMethods\NetApi.cs" /> 59 <Compile Include="NativeMethods\NtDll.cs" /> 60 <Compile Include="NativeMethods\Shell.cs" /> 61 <Compile Include="NativeMethods\User.cs" /> 62 <Compile Include="NativeMethods\UxTheme.cs" /> 63 <Compile Include="NativeMethods\WinTrust.cs" /> 55 64 <Compile Include="NtfsApi.cs" /> 56 65 <Compile Include="ShellApi.cs" /> -
branches/eraser6/CodeReview/Eraser.Util/KernelApi.cs
r1530 r1543 335 335 return null; 336 336 } 337 338 /// <summary>339 /// Stores Kernel32.dll functions, structs and constants.340 /// </summary>341 internal static class NativeMethods342 {343 /// <summary>344 /// Closes an open object handle.345 /// </summary>346 /// <param name="hObject">A valid handle to an open object.</param>347 /// <returns>If the function succeeds, the return value is true. To get348 /// extended error information, call Marshal.GetLastWin32Error().349 ///350 /// If the application is running under a debugger, the function will throw351 /// an exception if it receives either a handle value that is not valid352 /// or a pseudo-handle value. This can happen if you close a handle twice,353 /// or if you call CloseHandle on a handle returned by the FindFirstFile354 /// function.</returns>355 [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]356 [return: MarshalAs(UnmanagedType.Bool)]357 public static extern bool CloseHandle(IntPtr hObject);358 359 /// <summary>360 /// Deletes an existing file.361 /// </summary>362 /// <param name="lpFileName">The name of the file to be deleted.363 ///364 /// In the ANSI version of this function, the name is limited to MAX_PATH365 /// characters. To extend this limit to 32,767 wide characters, call366 /// the Unicode version of the function and prepend "\\?\" to the path.367 /// For more information, see Naming a File.</param>368 /// <returns>If the function succeeds, the return value is nonzero.369 ///370 /// If the function fails, the return value is zero (0). To get extended371 /// error information, call Marshal.GetLastWin32Error().</returns>372 [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]373 [return: MarshalAs(UnmanagedType.Bool)]374 public static extern bool DeleteFile(string lpFileName);375 376 /// <summary>377 /// Retrieves a pseudo handle for the current process.378 /// </summary>379 /// <returns>A pseudo handle to the current process.</returns>380 /// <remarks>A pseudo handle is a special constant, currently (HANDLE)-1,381 /// that is interpreted as the current process handle. For compatibility382 /// with future operating systems, it is best to call GetCurrentProcess383 /// instead of hard-coding this constant value. The calling process can384 /// use a pseudo handle to specify its own process whenever a process385 /// handle is required. Pseudo handles are not inherited by child processes.386 ///387 /// This handle has the maximum possible access to the process object.388 /// For systems that support security descriptors, this is the maximum389 /// access allowed by the security descriptor for the calling process.390 /// For systems that do not support security descriptors, this is391 /// PROCESS_ALL_ACCESS. For more information, see Process Security and392 /// Access Rights.393 ///394 /// A process can create a "real" handle to itself that is valid in the395 /// context of other processes, or that can be inherited by other processes,396 /// by specifying the pseudo handle as the source handle in a call to the397 /// DuplicateHandle function. A process can also use the OpenProcess398 /// function to open a real handle to itself.399 ///400 /// The pseudo handle need not be closed when it is no longer needed.401 /// Calling the CloseHandle function with a pseudo handle has no effect.402 /// If the pseudo handle is duplicated by DuplicateHandle, the duplicate403 /// handle must be closed.</remarks>404 [DllImport("Kernel32.dll", SetLastError = true)]405 public static extern IntPtr GetCurrentProcess();406 407 /// <summary>408 /// Retrieves information about the current system.409 /// </summary>410 /// <param name="lpSystemInfo">A pointer to a SYSTEM_INFO structure that411 /// receives the information.</param>412 [DllImport("Kernel32.dll")]413 public static extern void GetSystemInfo(out SYSTEM_INFO lpSystemInfo);414 415 /// <summary>416 /// The QueryPerformanceCounter function retrieves the current value of417 /// the high-resolution performance counter.418 /// </summary>419 /// <param name="lpPerformanceCount">[out] Pointer to a variable that receives420 /// the current performance-counter value, in counts.</param>421 /// <returns>If the function succeeds, the return value is nonzero.422 ///423 /// If the function fails, the return value is zero. To get extended error424 /// information, call Marshal.GetLastWin32Error. </returns>425 [DllImport("Kernel32.dll", SetLastError = true)]426 [return: MarshalAs(UnmanagedType.Bool)]427 public static extern bool QueryPerformanceCounter(out long lpPerformanceCount);428 429 /// <summary>430 /// Contains information about the current computer system. This includes431 /// the architecture and type of the processor, the number of processors432 /// in the system, the page size, and other such information.433 /// </summary>434 [StructLayout(LayoutKind.Sequential)]435 internal struct SYSTEM_INFO436 {437 /// <summary>438 /// Represents a list of processor architectures.439 /// </summary>440 public enum ProcessorArchitecture : ushort441 {442 /// <summary>443 /// x64 (AMD or Intel).444 /// </summary>445 PROCESSOR_ARCHITECTURE_AMD64 = 9,446 447 /// <summary>448 /// Intel Itanium Processor Family (IPF).449 /// </summary>450 PROCESSOR_ARCHITECTURE_IA64 = 6,451 452 /// <summary>453 /// x86.454 /// </summary>455 PROCESSOR_ARCHITECTURE_INTEL = 0,456 457 /// <summary>458 /// Unknown architecture.459 /// </summary>460 PROCESSOR_ARCHITECTURE_UNKNOWN = 0xffff461 }462 463 /// <summary>464 /// The processor architecture of the installed operating system.465 /// This member can be one of the ProcessorArchitecture values.466 /// </summary>467 public ProcessorArchitecture processorArchitecture;468 469 /// <summary>470 /// This member is reserved for future use.471 /// </summary>472 private const ushort reserved = 0;473 474 /// <summary>475 /// The page size and the granularity of page protection and commitment.476 /// This is the page size used by the VirtualAlloc function.477 /// </summary>478 public uint pageSize;479 480 /// <summary>481 /// A pointer to the lowest memory address accessible to applications482 /// and dynamic-link libraries (DLLs).483 /// </summary>484 public IntPtr minimumApplicationAddress;485 486 /// <summary>487 /// A pointer to the highest memory address accessible to applications488 /// and DLLs.489 /// </summary>490 public IntPtr maximumApplicationAddress;491 492 /// <summary>493 /// A mask representing the set of processors configured into the system.494 /// Bit 0 is processor 0; bit 31 is processor 31.495 /// </summary>496 public IntPtr activeProcessorMask;497 498 /// <summary>499 /// The number of processors in the system.500 /// </summary>501 public uint numberOfProcessors;502 503 /// <summary>504 /// An obsolete member that is retained for compatibility. Use the505 /// wProcessorArchitecture, wProcessorLevel, and wProcessorRevision506 /// members to determine the type of processor.507 /// Name Value508 /// PROCESSOR_INTEL_386 386509 /// PROCESSOR_INTEL_486 486510 /// PROCESSOR_INTEL_PENTIUM 586511 /// PROCESSOR_INTEL_IA64 2200512 /// PROCESSOR_AMD_X8664 8664513 /// </summary>514 public uint processorType;515 516 /// <summary>517 /// The granularity for the starting address at which virtual memory518 /// can be allocated. For more information, see VirtualAlloc.519 /// </summary>520 public uint allocationGranularity;521 522 /// <summary>523 /// The architecture-dependent processor level. It should be used only524 /// for display purposes. To determine the feature set of a processor,525 /// use the IsProcessorFeaturePresent function.526 ///527 /// If wProcessorArchitecture is PROCESSOR_ARCHITECTURE_INTEL, wProcessorLevel528 /// is defined by the CPU vendor.529 /// If wProcessorArchitecture is PROCESSOR_ARCHITECTURE_IA64, wProcessorLevel530 /// is set to 1.531 /// </summary>532 public ushort processorLevel;533 534 /// <summary>535 /// The architecture-dependent processor revision. The following table536 /// shows how the revision value is assembled for each type of537 /// processor architecture.538 ///539 /// Processor Value540 /// Intel Pentium, Cyrix The high byte is the model and the541 /// or NextGen 586 low byte is the stepping. For example,542 /// if the value is xxyy, the model number543 /// and stepping can be displayed as follows:544 /// Model xx, Stepping yy545 /// Intel 80386 or 80486 A value of the form xxyz.546 /// If xx is equal to 0xFF, y - 0xA is the model547 /// number, and z is the stepping identifier.548 ///549 /// If xx is not equal to 0xFF, xx + 'A'550 /// is the stepping letter and yz is the minor stepping.551 /// </summary>552 public ushort processorRevision;553 }554 555 [DllImport("Kernel32.dll")]556 public static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);557 558 /// <summary>559 /// Execution state values to be used in conjuction with SetThreadExecutionState560 /// </summary>561 [Flags]562 public enum EXECUTION_STATE : uint563 {564 ES_AWAYMODE_REQUIRED = 0x00000040,565 ES_CONTINUOUS = 0x80000000,566 ES_DISPLAY_REQUIRED = 0x00000002,567 ES_SYSTEM_REQUIRED = 0x00000001,568 ES_USER_PRESENT = 0x00000004569 }570 571 [DllImport("Kernel32.dll", SetLastError = true)]572 [return: MarshalAs(UnmanagedType.Bool)]573 public static extern bool AllocConsole();574 575 [DllImport("Kernel32.dll", SetLastError = true)]576 [return: MarshalAs(UnmanagedType.Bool)]577 public static extern bool FreeConsole();578 579 /// <summary>580 /// The CreateFile function creates or opens a file, file stream, directory,581 /// physical disk, volume, console buffer, tape drive, communications resource,582 /// mailslot, or named pipe. The function returns a handle that can be used583 /// to access an object.584 /// </summary>585 /// <param name="FileName"></param>586 /// <param name="DesiredAccess"> access to the object, which can be read,587 /// write, or both</param>588 /// <param name="ShareMode">The sharing mode of an object, which can be589 /// read, write, both, or none</param>590 /// <param name="SecurityAttributes">A pointer to a SECURITY_ATTRIBUTES591 /// structure that determines whether or not the returned handle can be592 /// inherited by child processes. Can be null</param>593 /// <param name="CreationDisposition">An action to take on files that exist594 /// and do not exist</param>595 /// <param name="FlagsAndAttributes">The file attributes and flags.</param>596 /// <param name="hTemplateFile">A handle to a template file with the597 /// GENERIC_READ access right. The template file supplies file attributes598 /// and extended attributes for the file that is being created. This599 /// parameter can be null</param>600 /// <returns>If the function succeeds, the return value is an open handle601 /// to a specified file. If a specified file exists before the function602 /// all and dwCreationDisposition is CREATE_ALWAYS or OPEN_ALWAYS, a call603 /// to GetLastError returns ERROR_ALREADY_EXISTS, even when the function604 /// succeeds. If a file does not exist before the call, GetLastError605 /// returns 0.606 ///607 /// If the function fails, the return value is INVALID_HANDLE_VALUE.608 /// To get extended error information, call Marshal.GetLastWin32Error().</returns>609 [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]610 public static extern SafeFileHandle CreateFile(string lpFileName, uint dwDesiredAccess,611 uint dwShareMode, IntPtr SecurityAttributes, uint dwCreationDisposition,612 uint dwFlagsAndAttributes, IntPtr hTemplateFile);613 614 public const uint GENERIC_READ = 0x80000000;615 public const uint GENERIC_WRITE = 0x40000000;616 public const uint GENERIC_EXECUTE = 0x20000000;617 public const uint GENERIC_ALL = 0x10000000;618 619 public const uint FILE_SHARE_READ = 0x00000001;620 public const uint FILE_SHARE_WRITE = 0x00000002;621 public const uint FILE_SHARE_DELETE = 0x00000004;622 623 public const uint CREATE_NEW = 1;624 public const uint CREATE_ALWAYS = 2;625 public const uint OPEN_EXISTING = 3;626 public const uint OPEN_ALWAYS = 4;627 public const uint TRUNCATE_EXISTING = 5;628 629 public const uint FILE_FLAG_WRITE_THROUGH = 0x80000000;630 public const uint FILE_FLAG_OVERLAPPED = 0x40000000;631 public const uint FILE_FLAG_NO_BUFFERING = 0x20000000;632 public const uint FILE_FLAG_RANDOM_ACCESS = 0x10000000;633 public const uint FILE_FLAG_SEQUENTIAL_SCAN = 0x08000000;634 public const uint FILE_FLAG_DELETE_ON_CLOSE = 0x04000000;635 public const uint FILE_FLAG_BACKUP_SEMANTICS = 0x02000000;636 public const uint FILE_FLAG_POSIX_SEMANTICS = 0x01000000;637 public const uint FILE_FLAG_OPEN_REPARSE_POINT = 0x00200000;638 public const uint FILE_FLAG_OPEN_NO_RECALL = 0x00100000;639 public const uint FILE_FLAG_FIRST_PIPE_INSTANCE = 0x00080000;640 641 [DllImport("Kernel32.dll", SetLastError = true)]642 [return: MarshalAs(UnmanagedType.Bool)]643 public extern static bool DeviceIoControl(SafeFileHandle hDevice,644 uint dwIoControlCode, IntPtr lpInBuffer, uint nInBufferSize,645 out ushort lpOutBuffer, uint nOutBufferSize, out uint lpBytesReturned,646 IntPtr lpOverlapped);647 648 [DllImport("Kernel32.dll", SetLastError = true)]649 [return: MarshalAs(UnmanagedType.Bool)]650 public extern static bool DeviceIoControl(SafeFileHandle hDevice,651 uint dwIoControlCode, ref ushort lpInBuffer, uint nInBufferSize,652 IntPtr lpOutBuffer, uint nOutBufferSize, out uint lpBytesReturned,653 IntPtr lpOverlapped);654 655 public const uint FSCTL_GET_COMPRESSION = 0x9003C;656 public const uint FSCTL_SET_COMPRESSION = 0x9C040;657 public const ushort COMPRESSION_FORMAT_NONE = 0x0000;658 public const ushort COMPRESSION_FORMAT_DEFAULT = 0x0001;659 660 [DllImport("Kernel32.dll", SetLastError = true)]661 [return: MarshalAs(UnmanagedType.Bool)]662 public extern static bool DeviceIoControl(SafeFileHandle hDevice,663 uint dwIoControlCode, IntPtr lpInBuffer, uint nInBufferSize,664 IntPtr lpOutBuffer, uint nOutBufferSize, out uint lpBytesReturned,665 IntPtr lpOverlapped);666 public const uint FSCTL_LOCK_VOLUME = 0x90018;667 public const uint FSCTL_UNLOCK_VOLUME = 0x9001C;668 669 [DllImport("Kernel32.dll", SetLastError = true)]670 [return: MarshalAs(UnmanagedType.Bool)]671 public extern static bool DeviceIoControl(SafeFileHandle hDevice,672 uint dwIoControlCode, IntPtr lpInBuffer, uint nInBufferSize,673 out DiskPerformanceInfoInternal lpOutBuffer, uint nOutBufferSize, out uint lpBytesReturned,674 IntPtr lpOverlapped);675 676 public const uint IOCTL_DISK_PERFORMANCE = ((0x00000007) << 16) | ((0x0008) << 2);677 678 public unsafe struct DiskPerformanceInfoInternal679 {680 public long BytesRead;681 public long BytesWritten;682 public long ReadTime;683 public long WriteTime;684 public long IdleTime;685 public uint ReadCount;686 public uint WriteCount;687 public uint QueueDepth;688 public uint SplitCount;689 public long QueryTime;690 public uint StorageDeviceNumber;691 public fixed short StorageManagerName[8];692 }693 694 /// <summary>695 /// Retrieves a set of FAT file system attributes for a specified file or696 /// directory.697 /// </summary>698 /// <param name="lpFileName">The name of the file or directory.</param>699 /// <returns>If the function succeeds, the return value contains the attributes700 /// of the specified file or directory.701 ///702 /// If the function fails, the return value is INVALID_FILE_ATTRIBUTES.703 /// To get extended error information, call Marshal.GetLastWin32Error.704 ///705 /// The attributes can be one or more of the FILE_ATTRIBUTE_* values.</returns>706 [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]707 public static extern uint GetFileAttributes(string lpFileName);708 709 /// <summary>710 /// Sets the attributes for a file or directory.711 /// </summary>712 /// <param name="lpFileName">The name of the file whose attributes are713 /// to be set.</param>714 /// <param name="dwFileAttributes">The file attributes to set for the file.715 /// This parameter can be one or more of the FILE_ATTRIBUTE_* values.716 /// However, all other values override FILE_ATTRIBUTE_NORMAL.</param>717 /// <returns>If the function succeeds, the return value is nonzero.718 ///719 /// If the function fails, the return value is zero. To get extended error720 /// information, call Marshal.GetLastWin32Error.</returns>721 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2205:UseManagedEquivalentsOfWin32Api")]722 [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]723 [return: MarshalAs(UnmanagedType.Bool)]724 public static extern bool SetFileAttributes(string lpFileName,725 uint dwFileAttributes);726 727 /// <summary>728 /// Retrieves the size of the specified file.729 /// </summary>730 /// <param name="hFile">A handle to the file. The handle must have been731 /// created with either the GENERIC_READ or GENERIC_WRITE access right.732 /// For more information, see File Security and Access Rights.</param>733 /// <param name="lpFileSize">A reference to a long that receives the file734 /// size, in bytes.</param>735 /// <returns>If the function succeeds, the return value is nonzero.736 ///737 /// If the function fails, the return value is zero. To get extended error738 /// information, call Marshal.GetLastWin32Error.</returns>739 [DllImport("Kernel32.dll", SetLastError = true)]740 [return: MarshalAs(UnmanagedType.Bool)]741 public static extern bool GetFileSizeEx(SafeFileHandle hFile, out long lpFileSize);742 743 /// <summary>744 /// Retrieves the date and time that a file or directory was created, last745 /// accessed, and last modified.746 /// </summary>747 /// <param name="hFile">A handle to the file or directory for which dates748 /// and times are to be retrieved. The handle must have been created using749 /// the CreateFile function with the GENERIC_READ access right. For more750 /// information, see File Security and Access Rights.</param>751 /// <param name="lpCreationTime">A pointer to a FILETIME structure to752 /// receive the date and time the file or directory was created. This753 /// parameter can be NULL if the application does not require this754 /// information.</param>755 /// <param name="lpLastAccessTime">A pointer to a FILETIME structure to756 /// receive the date and time the file or directory was last accessed. The757 /// last access time includes the last time the file or directory was758 /// written to, read from, or, in the case of executable files, run. This759 /// parameter can be NULL if the application does not require this760 /// information.</param>761 /// <param name="lpLastWriteTime">A pointer to a FILETIME structure to762 /// receive the date and time the file or directory was last written to,763 /// truncated, or overwritten (for example, with WriteFile or SetEndOfFile).764 /// This date and time is not updated when file attributes or security765 /// descriptors are changed. This parameter can be NULL if the application766 /// does not require this information.</param>767 /// <returns>If the function succeeds, the return value is nonzero.768 ///769 /// If the function fails, the return value is zero. To get extended error770 /// information, call Marshal.GetLastWin32Error().</returns>771 [DllImport("Kernel32.dll", SetLastError = true)]772 [return: MarshalAs(UnmanagedType.Bool)]773 public static extern bool GetFileTime(SafeFileHandle hFile,774 out System.Runtime.InteropServices.ComTypes.FILETIME lpCreationTime,775 out System.Runtime.InteropServices.ComTypes.FILETIME lpLastAccessTime,776 out System.Runtime.InteropServices.ComTypes.FILETIME lpLastWriteTime);777 778 /// <summary>779 /// Sets the date and time that the specified file or directory was created,780 /// last accessed, or last modified.781 /// </summary>782 /// <param name="hFile">A handle to the file or directory. The handle must783 /// have been created using the CreateFile function with the784 /// FILE_WRITE_ATTRIBUTES access right. For more information, see File785 /// Security and Access Rights.</param>786 /// <param name="lpCreationTime">A pointer to a FILETIME structure that787 /// contains the new creation date and time for the file or directory.788 /// This parameter can be NULL if the application does not need to change789 /// this information.</param>790 /// <param name="lpLastAccessTime">A pointer to a FILETIME structure that791 /// contains the new last access date and time for the file or directory.792 /// The last access time includes the last time the file or directory was793 /// written to, read from, or (in the case of executable files) run. This794 /// parameter can be NULL if the application does not need to change this795 /// information.796 ///797 /// To preserve the existing last access time for a file even after accessing798 /// a file, call SetFileTime immediately after opening the file handle799 /// with this parameter's FILETIME structure members initialized to800 /// 0xFFFFFFFF.</param>801 /// <param name="lpLastWriteTime">A pointer to a FILETIME structure that802 /// contains the new last modified date and time for the file or directory.803 /// This parameter can be NULL if the application does not need to change804 /// this information.</param>805 /// <returns>If the function succeeds, the return value is nonzero.806 ///807 /// If the function fails, the return value is zero. To get extended error808 /// information, call GetLastError.</returns>809 [DllImport("Kernel32.dll", SetLastError = true)]810 [return: MarshalAs(UnmanagedType.Bool)]811 public static extern bool SetFileTime(SafeFileHandle hFile,812 ref System.Runtime.InteropServices.ComTypes.FILETIME lpCreationTime,813 ref System.Runtime.InteropServices.ComTypes.FILETIME lpLastAccessTime,814 ref System.Runtime.InteropServices.ComTypes.FILETIME lpLastWriteTime);815 816 /// <summary>817 /// Retrieves the name of a volume on a computer. FindFirstVolume is used818 /// to begin scanning the volumes of a computer.819 /// </summary>820 /// <param name="lpszVolumeName">A pointer to a buffer that receives a821 /// null-terminated string that specifies the unique volume name of the822 /// first volume found.</param>823 /// <param name="cchBufferLength">The length of the buffer to receive the824 /// name, in TCHARs.</param>825 /// <returns>If the function succeeds, the return value is a search handle826 /// used in a subsequent call to the FindNextVolume and FindVolumeClose827 /// functions.828 ///829 /// If the function fails to find any volumes, the return value is the830 /// INVALID_HANDLE_VALUE error code. To get extended error information,831 /// call GetLastError.</returns>832 [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]833 public static extern SafeFileHandle FindFirstVolume(StringBuilder lpszVolumeName,834 uint cchBufferLength);835 836 /// <summary>837 /// Continues a volume search started by a call to the FindFirstVolume838 /// function. FindNextVolume finds one volume per call.839 /// </summary>840 /// <param name="hFindVolume">The volume search handle returned by a previous841 /// call to the FindFirstVolume function.</param>842 /// <param name="lpszVolumeName">A pointer to a string that receives the843 /// unique volume name found.</param>844 /// <param name="cchBufferLength">The length of the buffer that receives845 /// the name, in TCHARs.</param>846 /// <returns>If the function succeeds, the return value is nonzero.847 ///848 /// If the function fails, the return value is zero. To get extended error849 /// information, call GetLastError. If no matching files can be found, the850 /// GetLastError function returns the ERROR_NO_MORE_FILES error code. In851 /// that case, close the search with the FindVolumeClose function.</returns>852 [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]853 [return: MarshalAs(UnmanagedType.Bool)]854 public static extern bool FindNextVolume(SafeHandle hFindVolume,855 StringBuilder lpszVolumeName, uint cchBufferLength);856 857 /// <summary>858 /// Closes the specified volume search handle. The FindFirstVolume and859 /// FindNextVolume functions use this search handle to locate volumes.860 /// </summary>861 /// <param name="hFindVolume">The volume search handle to be closed. This862 /// handle must have been previously opened by the FindFirstVolume function.</param>863 /// <returns>If the function succeeds, the return value is nonzero.864 ///865 /// If the function fails, the return value is zero. To get extended error866 /// information, call GetLastError.</returns>867 [DllImport("Kernel32.dll", SetLastError = true)]868 [return: MarshalAs(UnmanagedType.Bool)]869 public static extern bool FindVolumeClose(SafeHandle hFindVolume);870 871 /// <summary>872 /// Retrieves the name of a volume mount point on the specified volume.873 /// FindFirstVolumeMountPoint is used to begin scanning the volume mount874 /// points on a volume.875 /// </summary>876 /// <param name="lpszRootPathName">The unique volume name of the volume877 /// to scan for volume mount points. A trailing backslash is required.</param>878 /// <param name="lpszVolumeMountPoint">A pointer to a buffer that receives879 /// the name of the first volume mount point found.</param>880 /// <param name="cchBufferLength">The length of the buffer that receives881 /// the volume mount point name, in TCHARs.</param>882 /// <returns>If the function succeeds, the return value is a search handle883 /// used in a subsequent call to the FindNextVolumeMountPoint and884 /// FindVolumeMountPointClose functions.885 ///886 /// If the function fails to find a volume mount point on the volume, the887 /// return value is the INVALID_HANDLE_VALUE error code. To get extended888 /// error information, call GetLastError.</returns>889 [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]890 public static extern SafeFileHandle FindFirstVolumeMountPoint(891 string lpszRootPathName, StringBuilder lpszVolumeMountPoint,892 uint cchBufferLength);893 894 /// <summary>895 /// Continues a volume mount point search started by a call to the896 /// FindFirstVolumeMountPoint function. FindNextVolumeMountPoint finds one897 /// volume mount point per call.898 /// </summary>899 /// <param name="hFindVolumeMountPoint">A mount-point search handle returned900 /// by a previous call to the FindFirstVolumeMountPoint function.</param>901 /// <param name="lpszVolumeMountPoint">A pointer to a buffer that receives902 /// the name of the volume mount point found.</param>903 /// <param name="cchBufferLength">The length of the buffer that receives904 /// the names, in TCHARs.</param>905 /// <returns>If the function succeeds, the return value is nonzero.906 ///907 /// If the function fails, the return value is zero. To get extended error908 /// information, call GetLastError. If no matching files can be found, the909 /// GetLastError function returns the ERROR_NO_MORE_FILES error code. In910 /// that case, close the search with the FindVolumeMountPointClose function.</returns>911 [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]912 [return: MarshalAs(UnmanagedType.Bool)]913 public static extern bool FindNextVolumeMountPoint(914 SafeHandle hFindVolumeMountPoint, StringBuilder lpszVolumeMountPoint,915 uint cchBufferLength);916 917 /// <summary>918 /// Closes the specified mount-point search handle. The FindFirstVolumeMountPoint919 /// and FindNextVolumeMountPoint functions use this search handle to locate920 /// volume mount points on a specified volume.921 /// </summary>922 /// <param name="hFindVolumeMountPoint">The mount-point search handle to923 /// be closed. This handle must have been previously opened by the924 /// FindFirstVolumeMountPoint function.</param>925 /// <returns>If the function succeeds, the return value is nonzero.926 ///927 /// If the function fails, the return value is zero. To get extended error928 /// information, call GetLastError.</returns>929 [DllImport("Kernel32.dll", SetLastError = true)]930 [return: MarshalAs(UnmanagedType.Bool)]931 public static extern bool FindVolumeMountPointClose(SafeHandle hFindVolumeMountPoint);932 933 /// <summary>934 /// Retrieves information about the specified disk, including the amount935 /// of free space on the disk.936 ///937 /// The GetDiskFreeSpace function cannot report volume sizes that are938 /// greater than 2 gigabytes (GB). To ensure that your application works939 /// with large capacity hard drives, use the GetDiskFreeSpaceEx function.940 /// </summary>941 /// <param name="lpRootPathName">The root directory of the disk for which942 /// information is to be returned. If this parameter is NULL, the function943 /// uses the root of the current disk. If this parameter is a UNC name,944 /// it must include a trailing backslash (for example, \\MyServer\MyShare\).945 /// Furthermore, a drive specification must have a trailing backslash946 /// (for example, C:\). The calling application must have FILE_LIST_DIRECTORY947 /// access rights for this directory.</param>948 /// <param name="lpSectorsPerCluster">A pointer to a variable that receives949 /// the number of sectors per cluster.</param>950 /// <param name="lpBytesPerSector">A pointer to a variable that receives951 /// the number of bytes per sector.</param>952 /// <param name="lpNumberOfFreeClusters">A pointer to a variable that953 /// receives the total number of free clusters on the disk that are954 /// available to the user who is associated with the calling thread.955 ///956 /// If per-user disk quotas are in use, this value may be less than the957 /// total number of free clusters on the disk.</param>958 /// <param name="lpTotalNumberOfClusters">A pointer to a variable that959 /// receives the total number of clusters on the disk that are available960 /// to the user who is associated with the calling thread.961 ///962 /// If per-user disk quotas are in use, this value may be less than the963 /// total number of clusters on the disk.</param>964 /// <returns>If the function succeeds, the return value is true. To get965 /// extended error information, call Marshal.GetLastWin32Error().</returns>966 [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]967 [return: MarshalAs(UnmanagedType.Bool)]968 public static extern bool GetDiskFreeSpace(969 string lpRootPathName, out UInt32 lpSectorsPerCluster, out UInt32 lpBytesPerSector,970 out UInt32 lpNumberOfFreeClusters, out UInt32 lpTotalNumberOfClusters);971 972 973 /// <summary>974 /// Retrieves information about the amount of space that is available on975 /// a disk volume, which is the total amount of space, the total amount976 /// of free space, and the total amount of free space available to the977 /// user that is associated with the calling thread.978 /// </summary>979 /// <param name="lpDirectoryName">A directory on the disk.980 ///981 /// If this parameter is NULL, the function uses the root of the current982 /// disk.983 ///984 /// If this parameter is a UNC name, it must include a trailing backslash,985 /// for example, "\\MyServer\MyShare\".986 ///987 /// This parameter does not have to specify the root directory on a disk.988 /// The function accepts any directory on a disk.989 ///990 /// The calling application must have FILE_LIST_DIRECTORY access rights991 /// for this directory.</param>992 /// <param name="lpFreeBytesAvailable">A pointer to a variable that receives993 /// the total number of free bytes on a disk that are available to the994 /// user who is associated with the calling thread.995 ///996 /// This parameter can be NULL.997 ///998 /// If per-user quotas are being used, this value may be less than the999 /// total number of free bytes on a disk.</param>1000 /// <param name="lpTotalNumberOfBytes">A pointer to a variable that receives1001 /// the total number of bytes on a disk that are available to the user who1002 /// is associated with the calling thread.1003 ///1004 /// This parameter can be NULL.1005 ///1006 /// If per-user quotas are being used, this value may be less than the1007 /// total number of bytes on a disk.1008 ///1009 /// To determine the total number of bytes on a disk or volume, use1010 /// IOCTL_DISK_GET_LENGTH_INFO.</param>1011 /// <param name="lpTotalNumberOfFreeBytes">A pointer to a variable that1012 /// receives the total number of free bytes on a disk.1013 ///1014 /// This parameter can be NULL.</param>1015 /// <returns>If the function succeeds, the return value is nonzero.1016 ///1017 /// If the function fails, the return value is zero (0). To get extended1018 /// error information, call GetLastError.</returns>1019 [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]1020 [return: MarshalAs(UnmanagedType.Bool)]1021 public static extern bool GetDiskFreeSpaceEx(1022 string lpDirectoryName,1023 out UInt64 lpFreeBytesAvailable,1024 out UInt64 lpTotalNumberOfBytes,1025 out UInt64 lpTotalNumberOfFreeBytes);1026 1027 /// <summary>1028 /// Determines whether a disk drive is a removable, fixed, CD-ROM, RAM disk,1029 /// or network drive.1030 /// </summary>1031 /// <param name="lpRootPathName">The root directory for the drive.1032 ///1033 /// A trailing backslash is required. If this parameter is NULL, the function1034 /// uses the root of the current directory.</param>1035 /// <returns>The return value specifies the type of drive, which can be1036 /// one of the DriveInfo.DriveType values.</returns>1037 [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]1038 public static extern uint GetDriveType(string lpRootPathName);1039 1040 /// <summary>1041 /// Retrieves information about the file system and volume associated with1042 /// the specified root directory.1043 ///1044 /// To specify a handle when retrieving this information, use the1045 /// GetVolumeInformationByHandleW function.1046 ///1047 /// To retrieve the current compression state of a file or directory, use1048 /// FSCTL_GET_COMPRESSION.1049 /// </summary>1050 /// <param name="lpRootPathName"> A pointer to a string that contains1051 /// the root directory of the volume to be described.1052 ///1053 /// If this parameter is NULL, the root of the current directory is used.1054 /// A trailing backslash is required. For example, you specify1055 /// \\MyServer\MyShare as "\\MyServer\MyShare\", or the C drive as "C:\".</param>1056 /// <param name="lpVolumeNameBuffer">A pointer to a buffer that receives1057 /// the name of a specified volume. The maximum buffer size is MAX_PATH+1.</param>1058 /// <param name="nVolumeNameSize">The length of a volume name buffer, in1059 /// TCHARs. The maximum buffer size is MAX_PATH+1.1060 ///1061 /// This parameter is ignored if the volume name buffer is not supplied.</param>1062 /// <param name="lpVolumeSerialNumber">A pointer to a variable that receives1063 /// the volume serial number.1064 ///1065 /// This parameter can be NULL if the serial number is not required.1066 ///1067 /// This function returns the volume serial number that the operating system1068 /// assigns when a hard disk is formatted. To programmatically obtain the1069 /// hard disk's serial number that the manufacturer assigns, use the1070 /// Windows Management Instrumentation (WMI) Win32_PhysicalMedia property1071 /// SerialNumber.</param>1072 /// <param name="lpMaximumComponentLength">A pointer to a variable that1073 /// receives the maximum length, in TCHARs, of a file name component that1074 /// a specified file system supports.1075 ///1076 /// A file name component is the portion of a file name between backslashes.1077 ///1078 /// The value that is stored in the variable that *lpMaximumComponentLength1079 /// points to is used to indicate that a specified file system supports1080 /// long names. For example, for a FAT file system that supports long names,1081 /// the function stores the value 255, rather than the previous 8.3 indicator.1082 /// Long names can also be supported on systems that use the NTFS file system.</param>1083 /// <param name="lpFileSystemFlags">A pointer to a variable that receives1084 /// flags associated with the specified file system.1085 ///1086 /// This parameter can be one or more of the FS_FILE* flags. However,1087 /// FS_FILE_COMPRESSION and FS_VOL_IS_COMPRESSED are mutually exclusive.</param>1088 /// <param name="lpFileSystemNameBuffer">A pointer to a buffer that receives1089 /// the name of the file system, for example, the FAT file system or the1090 /// NTFS file system. The maximum buffer size is MAX_PATH+1.</param>1091 /// <param name="nFileSystemNameSize">The length of the file system name1092 /// buffer, in TCHARs. The maximum buffer size is MAX_PATH+1.1093 ///1094 /// This parameter is ignored if the file system name buffer is not supplied.</param>1095 /// <returns>If all the requested information is retrieved, the return value1096 /// is nonzero.1097 ///1098 ///1099 /// If not all the requested information is retrieved, the return value is1100 /// zero (0). To get extended error information, call GetLastError.</returns>1101 [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]1102 [return: MarshalAs(UnmanagedType.Bool)]1103 public static extern bool GetVolumeInformation(1104 string lpRootPathName,1105 StringBuilder lpVolumeNameBuffer,1106 uint nVolumeNameSize,1107 out uint lpVolumeSerialNumber,1108 out uint lpMaximumComponentLength,1109 out uint lpFileSystemFlags,1110 StringBuilder lpFileSystemNameBuffer,1111 uint nFileSystemNameSize);1112 1113 /// <summary>1114 /// Retrieves the unique volume name for the specified volume mount point or root directory.1115 /// </summary>1116 /// <param name="lpszVolumeMountPoint">The path of a volume mount point (with a trailing1117 /// backslash, "\") or a drive letter indicating a root directory (in the1118 /// form "D:\").</param>1119 /// <param name="lpszVolumeName">A pointer to a string that receives the1120 /// volume name. This name is a unique volume name of the form1121 /// "\\?\Volume{GUID}\" where GUID is the GUID that identifies the volume.</param>1122 /// <param name="cchBufferLength">The length of the output buffer, in TCHARs.1123 /// A reasonable size for the buffer to accommodate the largest possible1124 /// volume name is 50 characters.</param>1125 /// <returns>If the function succeeds, the return value is nonzero.1126 ///1127 /// If the function fails, the return value is zero. To get extended1128 /// error information, call GetLastError.</returns>1129 [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]1130 [return: MarshalAs(UnmanagedType.Bool)]1131 public static extern bool GetVolumeNameForVolumeMountPoint(1132 string lpszVolumeMountPoint, StringBuilder lpszVolumeName,1133 uint cchBufferLength);1134 1135 /// <summary>1136 /// Retrieves a list of path names for the specified volume name.1137 /// </summary>1138 /// <param name="lpszVolumeName">The volume name.</param>1139 /// <param name="lpszVolumePathNames">A pointer to a buffer that receives1140 /// the list of volume path names. The list is an array of null-terminated1141 /// strings terminated by an additional NULL character. If the buffer is1142 /// not large enough to hold the complete list, the buffer holds as much1143 /// of the list as possible.</param>1144 /// <param name="cchBufferLength">The length of the lpszVolumePathNames1145 /// buffer, in TCHARs.</param>1146 /// <param name="lpcchReturnLength">If the call is successful, this parameter1147 /// is the number of TCHARs copied to the lpszVolumePathNames buffer. Otherwise,1148 /// this parameter is the size of the buffer required to hold the complete1149 /// list, in TCHARs.</param>1150 /// <returns></returns>1151 [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]1152 [return: MarshalAs(UnmanagedType.Bool)]1153 public static extern bool GetVolumePathNamesForVolumeName(1154 string lpszVolumeName, StringBuilder lpszVolumePathNames, uint cchBufferLength,1155 out uint lpcchReturnLength);1156 1157 public const int MaxPath = 260;1158 public const int LongPath = 32768;1159 }1160 337 } 1161 338 … … 1178 355 /// not supported. 1179 356 /// </summary> 1180 AwayModeRequired = (int) KernelApi.NativeMethods.EXECUTION_STATE.ES_AWAYMODE_REQUIRED,357 AwayModeRequired = (int)NativeMethods.EXECUTION_STATE.ES_AWAYMODE_REQUIRED, 1181 358 1182 359 /// <summary> … … 1185 362 /// state flags is cleared. 1186 363 /// </summary> 1187 Continuous = unchecked((int) KernelApi.NativeMethods.EXECUTION_STATE.ES_CONTINUOUS),364 Continuous = unchecked((int)NativeMethods.EXECUTION_STATE.ES_CONTINUOUS), 1188 365 1189 366 /// <summary> 1190 367 /// Forces the display to be on by resetting the display idle timer. 1191 368 /// </summary> 1192 DisplayRequired = (int) KernelApi.NativeMethods.EXECUTION_STATE.ES_DISPLAY_REQUIRED,369 DisplayRequired = (int)NativeMethods.EXECUTION_STATE.ES_DISPLAY_REQUIRED, 1193 370 1194 371 /// <summary> … … 1196 373 /// idle timer. 1197 374 /// </summary> 1198 SystemRequired = (int) KernelApi.NativeMethods.EXECUTION_STATE.ES_SYSTEM_REQUIRED,375 SystemRequired = (int)NativeMethods.EXECUTION_STATE.ES_SYSTEM_REQUIRED, 1199 376 1200 377 /// <summary> … … 1207 384 /// ES_USER_PRESENT must be called with ES_CONTINUOUS. 1208 385 /// </summary> 1209 UserPresent = (int) KernelApi.NativeMethods.EXECUTION_STATE.ES_USER_PRESENT386 UserPresent = (int)NativeMethods.EXECUTION_STATE.ES_USER_PRESENT 1210 387 } 1211 388 } -
branches/eraser6/CodeReview/Eraser.Util/MsCorEEApi.cs
r1360 r1543 48 48 out wasVerified) && wasVerified; 49 49 } 50 51 /// <summary>52 /// Function, struct and constants imported from MsCorEE.dll53 /// </summary>54 internal static class NativeMethods55 {56 /// <summary>57 /// Gets a value indicating whether the assembly manifest at the supplied58 /// path contains a strong name signature.59 /// </summary>60 /// <param name="wszFilePath">The path to the portable executable (.exe or61 /// .dll) file for the assembly to be verified.</param>62 /// <param name="fForceVerification">true to perform verification, even if63 /// it is necessary to override registry settings; otherwise, false.</param>64 /// <param name="pfWasVerified">True if the strong name signature was verified;65 /// otherwise, false. pfWasVerified is also set to false if the verification66 /// was successful due to registry settings.</param>67 /// <returns>True if the verification was successful; otherwise, false.</returns>68 /// <remarks>StrongNameSignatureVerificationEx provides a capability similar to69 /// the StrongNameSignatureVerification function. However, the second input70 /// parameter and the output parameter for StrongNameSignatureVerificationEx71 /// are of type BOOLEAN instead of DWORD.</remarks>72 [DllImport("MsCoree.dll", CharSet = CharSet.Unicode)]73 [return: MarshalAs(UnmanagedType.Bool)]74 public static extern bool StrongNameSignatureVerificationEx(75 string wszFilePath, [MarshalAs(UnmanagedType.Bool)] bool fForceVerification,76 [MarshalAs(UnmanagedType.Bool)] out bool pfWasVerified);77 78 }79 50 } 80 51 } -
branches/eraser6/CodeReview/Eraser.Util/NTApi.cs
r1360 r1543 39 39 /// buffer.</param> 40 40 /// <returns>A system error code.</returns> 41 [Obsolete] 41 42 public static uint NtQuerySystemInformation(uint type, byte[] data, 42 43 uint maxSize, out uint dataSize) … … 45 46 out dataSize); 46 47 } 47 48 internal static class NativeMethods49 {50 /// <summary>51 /// Queries system parameters using the NT Native API.52 /// </summary>53 /// <param name="dwType">The type of information to retrieve.</param>54 /// <param name="dwData">The buffer to receive the information.</param>55 /// <param name="dwMaxSize">The size of the buffer.</param>56 /// <param name="dwDataSize">Receives the amount of data written to the57 /// buffer.</param>58 /// <returns>A system error code.</returns>59 [DllImport("NtDll.dll")]60 public static extern uint NtQuerySystemInformation(uint dwType, byte[] dwData,61 uint dwMaxSize, out uint dwDataSize);62 63 /// <summary>64 /// The ZwQueryInformationFile routine returns various kinds of information65 /// about a file object.66 /// </summary>67 /// <param name="FileHandle">Handle to a file object. The handle is created68 /// by a successful call to ZwCreateFile or ZwOpenFile.</param>69 /// <param name="IoStatusBlock">Pointer to an IO_STATUS_BLOCK structure70 /// that receives the final completion status and information about71 /// the operation. The Information member receives the number of bytes72 /// that this routine actually writes to the FileInformation buffer.</param>73 /// <param name="FileInformation">Pointer to a caller-allocated buffer74 /// into which the routine writes the requested information about the75 /// file object. The FileInformationClass parameter specifies the type76 /// of information that the caller requests.</param>77 /// <param name="Length">The size, in bytes, of the buffer pointed to78 /// by FileInformation.</param>79 /// <param name="FileInformationClass">Specifies the type of information80 /// to be returned about the file, in the buffer that FileInformation81 /// points to. Device and intermediate drivers can specify any of the82 /// following FILE_INFORMATION_CLASS enumeration values, which are defined83 /// in header file Wdm.h.</param>84 /// <returns>ZwQueryInformationFile returns STATUS_SUCCESS or an appropriate85 /// NTSTATUS error code.</returns>86 [DllImport("NtDll.dll")]87 private static extern uint NtQueryInformationFile(SafeFileHandle FileHandle,88 ref IO_STATUS_BLOCK IoStatusBlock, IntPtr FileInformation, uint Length,89 FILE_INFORMATION_CLASS FileInformationClass);90 91 public static FILE_STREAM_INFORMATION[] NtQueryInformationFile(SafeFileHandle FileHandle)92 {93 IO_STATUS_BLOCK status = new IO_STATUS_BLOCK();94 IntPtr fileInfoPtr = IntPtr.Zero;95 96 try97 {98 FILE_STREAM_INFORMATION streamInfo = new FILE_STREAM_INFORMATION();99 int fileInfoPtrLength = (Marshal.SizeOf(streamInfo) + 32768) / 2;100 uint ntStatus = 0;101 102 do103 {104 fileInfoPtrLength *= 2;105 if (fileInfoPtr != IntPtr.Zero)106 Marshal.FreeHGlobal(fileInfoPtr);107 fileInfoPtr = Marshal.AllocHGlobal(fileInfoPtrLength);108 109 ntStatus = NtQueryInformationFile(FileHandle, ref status, fileInfoPtr,110 (uint)fileInfoPtrLength, FILE_INFORMATION_CLASS.FileStreamInformation);111 }112 while (ntStatus != 0 /*STATUS_SUCCESS*/ && ntStatus == 0x80000005 /*STATUS_BUFFER_OVERFLOW*/);113 114 //Marshal the structure manually (argh!)115 List<FILE_STREAM_INFORMATION> result = new List<FILE_STREAM_INFORMATION>();116 unsafe117 {118 for (byte* i = (byte*)fileInfoPtr; streamInfo.NextEntryOffset != 0;119 i += streamInfo.NextEntryOffset)120 {121 byte* currStreamPtr = i;122 streamInfo.NextEntryOffset = *(uint*)currStreamPtr;123 currStreamPtr += sizeof(uint);124 125 streamInfo.StreamNameLength = *(uint*)currStreamPtr;126 currStreamPtr += sizeof(uint);127 128 streamInfo.StreamSize = *(long*)currStreamPtr;129 currStreamPtr += sizeof(long);130 131 streamInfo.StreamAllocationSize = *(long*)currStreamPtr;132 currStreamPtr += sizeof(long);133 134 streamInfo.StreamName = Marshal.PtrToStringUni((IntPtr)currStreamPtr,135 (int)streamInfo.StreamNameLength / 2);136 result.Add(streamInfo);137 }138 }139 140 return result.ToArray();141 }142 finally143 {144 Marshal.FreeHGlobal(fileInfoPtr);145 }146 }147 148 public struct IO_STATUS_BLOCK149 {150 public IntPtr PointerStatus;151 public UIntPtr Information;152 }153 154 public struct FILE_STREAM_INFORMATION155 {156 /// <summary>157 /// The offset of the next FILE_STREAM_INFORMATION entry. This158 /// member is zero if no other entries follow this one.159 /// </summary>160 public uint NextEntryOffset;161 162 /// <summary>163 /// Length, in bytes, of the StreamName string.164 /// </summary>165 public uint StreamNameLength;166 167 /// <summary>168 /// Size, in bytes, of the stream.169 /// </summary>170 public long StreamSize;171 172 /// <summary>173 /// File stream allocation size, in bytes. Usually this value174 /// is a multiple of the sector or cluster size of the underlying175 /// physical device.176 /// </summary>177 public long StreamAllocationSize;178 179 /// <summary>180 /// Unicode string that contains the name of the stream.181 /// </summary>182 public string StreamName;183 }184 185 public enum FILE_INFORMATION_CLASS186 {187 FileDirectoryInformation = 1,188 FileFullDirectoryInformation,189 FileBothDirectoryInformation,190 FileBasicInformation,191 FileStandardInformation,192 FileInternalInformation,193 FileEaInformation,194 FileAccessInformation,195 FileNameInformation,196 FileRenameInformation,197 FileLinkInformation,198 FileNamesInformation,199 FileDispositionInformation,200 FilePositionInformation,201 FileFullEaInformation,202 FileModeInformation,203 FileAlignmentInformation,204 FileAllInformation,205 FileAllocationInformation,206 FileEndOfFileInformation,207 FileAlternateNameInformation,208 FileStreamInformation,209 FilePipeInformation,210 FilePipeLocalInformation,211 FilePipeRemoteInformation,212 FileMailslotQueryInformation,213 FileMailslotSetInformation,214 FileCompressionInformation,215 FileCopyOnWriteInformation,216 FileCompletionInformation,217 FileMoveClusterInformation,218 FileQuotaInformation,219 FileReparsePointInformation,220 FileNetworkOpenInformation,221 FileObjectIdInformation,222 FileTrackingInformation,223 FileOleDirectoryInformation,224 FileContentIndexInformation,225 FileInheritContentIndexInformation,226 FileOleInformation,227 FileMaximumInformation228 }229 230 /// <summary>231 /// Represents volume data. This structure is passed to the232 /// FSCTL_GET_NTFS_VOLUME_DATA control code.233 /// </summary>234 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]235 public struct NTFS_VOLUME_DATA_BUFFER236 {237 /// <summary>238 /// The serial number of the volume. This is a unique number assigned239 /// to the volume media by the operating system.240 /// </summary>241 public long VolumeSerialNumber;242 243 /// <summary>244 /// The number of sectors in the specified volume.245 /// </summary>246 public long NumberSectors;247 248 /// <summary>249 /// The number of used and free clusters in the specified volume.250 /// </summary>251 public long TotalClusters;252 253 /// <summary>254 /// The number of free clusters in the specified volume.255 /// </summary>256 public long FreeClusters;257 258 /// <summary>259 /// The number of reserved clusters in the specified volume.260 /// </summary>261 public long TotalReserved;262 263 /// <summary>264 /// The number of bytes in a sector on the specified volume.265 /// </summary>266 public uint BytesPerSector;267 268 /// <summary>269 /// The number of bytes in a cluster on the specified volume. This270 /// value is also known as the cluster factor.271 /// </summary>272 public uint BytesPerCluster;273 274 /// <summary>275 /// The number of bytes in a file record segment.276 /// </summary>277 public uint BytesPerFileRecordSegment;278 279 /// <summary>280 /// The number of clusters in a file record segment.281 /// </summary>282 public uint ClustersPerFileRecordSegment;283 284 /// <summary>285 /// The length of the master file table, in bytes.286 /// </summary>287 public long MftValidDataLength;288 289 /// <summary>290 /// The starting logical cluster number of the master file table.291 /// </summary>292 public long MftStartLcn;293 294 /// <summary>295 /// The starting logical cluster number of the master file table mirror.296 /// </summary>297 public long Mft2StartLcn;298 299 /// <summary>300 /// The starting logical cluster number of the master file table zone.301 /// </summary>302 public long MftZoneStart;303 304 /// <summary>305 /// The ending logical cluster number of the master file table zone.306 /// </summary>307 public long MftZoneEnd;308 309 public uint ByteCount;310 public ushort MajorVersion;311 public ushort MinorVersion;312 }313 314 /// <summary>315 /// Retrieves information about the specified NTFS file system volume.316 /// </summary>317 public const int FSCTL_GET_NTFS_VOLUME_DATA = (9 << 16) | (25 << 2);318 319 /// <summary>320 /// Sends the FSCTL_GET_NTFS_VOLUME_DATA control code, returning the resuling321 /// NTFS_VOLUME_DATA_BUFFER.322 /// </summary>323 /// <param name="volume">The volume to query.</param>324 /// <returns>The NTFS_VOLUME_DATA_BUFFER structure representing the data325 /// file systme structures for the volume.</returns>326 public static NTFS_VOLUME_DATA_BUFFER GetNtfsVolumeData(VolumeInfo volume)327 {328 using (SafeFileHandle volumeHandle = KernelApi.NativeMethods.CreateFile(329 volume.VolumeId.Remove(volume.VolumeId.Length - 1),330 KernelApi.NativeMethods.GENERIC_READ, KernelApi.NativeMethods.FILE_SHARE_READ |331 KernelApi.NativeMethods.FILE_SHARE_WRITE, IntPtr.Zero,332 KernelApi.NativeMethods.OPEN_EXISTING, 0, IntPtr.Zero))333 {334 uint resultSize = 0;335 NTFS_VOLUME_DATA_BUFFER volumeData = new NTFS_VOLUME_DATA_BUFFER();336 if (DeviceIoControl(volumeHandle, FSCTL_GET_NTFS_VOLUME_DATA,337 IntPtr.Zero, 0, out volumeData, (uint)Marshal.SizeOf(volumeData),338 out resultSize, IntPtr.Zero))339 {340 return volumeData;341 }342 343 throw Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error());344 }345 }346 347 [DllImport("Kernel32.dll", CharSet = CharSet.Unicode)]348 [return: MarshalAs(UnmanagedType.Bool)]349 public static extern bool DeviceIoControl(SafeFileHandle hDevice,350 uint dwIoControlCode, IntPtr lpInBuffer, uint nInBufferSize,351 out NTFS_VOLUME_DATA_BUFFER lpOutBuffer, uint nOutBufferSize,352 out uint lpBytesReturned, IntPtr lpOverlapped);353 }354 48 } 355 49 } -
branches/eraser6/CodeReview/Eraser.Util/NetApi.cs
r1360 r1543 80 80 return null; 81 81 } 82 83 internal static class NativeMethods84 {85 [DllImport("Netapi32.dll", CharSet = CharSet.Unicode)]86 public static extern uint NetStatisticsGet(string server, string service,87 uint level, uint options, out IntPtr bufptr);88 89 /// <summary>90 /// The NetApiBufferSize function returns the size, in bytes, of a buffer91 /// allocated by a call to the NetApiBufferAllocate function.92 /// </summary>93 /// <param name="Buffer">Pointer to a buffer returned by the NetApiBufferAllocate94 /// function.</param>95 /// <param name="ByteCount">Receives the size of the buffer, in bytes.</param>96 /// <returns>If the function succeeds, the return value is NERR_Success.97 ///98 /// If the function fails, the return value is a system error code. For99 /// a list of error codes, see System Error Codes.</returns>100 [DllImport("Netapi32.dll")]101 public static extern uint NetApiBufferSize(IntPtr Buffer, out uint ByteCount);102 103 /// <summary>104 /// The NetApiBufferFree function frees the memory that the NetApiBufferAllocate105 /// function allocates. Call NetApiBufferFree to free the memory that other106 /// network management functions return.107 /// </summary>108 /// <param name="Buffer">Pointer to a buffer returned previously by another109 /// network management function.</param>110 /// <returns>If the function succeeds, the return value is NERR_Success.111 ///112 /// If the function fails, the return value is a system error code. For113 /// a list of error codes, see System Error Codes.</returns>114 [DllImport("Netapi32.dll")]115 public static extern uint NetApiBufferFree(IntPtr Buffer);116 117 private const uint NERR_Success = 0;118 }119 82 } 120 83 -
branches/eraser6/CodeReview/Eraser.Util/NtfsApi.cs
r1360 r1543 35 35 public static long GetMftValidSize(VolumeInfo volume) 36 36 { 37 NTApi.NativeMethods.NTFS_VOLUME_DATA_BUFFER data = 38 NTApi.NativeMethods.GetNtfsVolumeData(volume); 39 return data.MftValidDataLength; 37 return NativeMethods.GetNtfsVolumeData(volume).MftValidDataLength; 40 38 } 41 39 … … 47 45 public static long GetMftRecordSegmentSize(VolumeInfo volume) 48 46 { 49 NTApi.NativeMethods.NTFS_VOLUME_DATA_BUFFER data = 50 NTApi.NativeMethods.GetNtfsVolumeData(volume); 51 return data.BytesPerFileRecordSegment; 47 return NativeMethods.GetNtfsVolumeData(volume).BytesPerFileRecordSegment; 52 48 } 53 49 } -
branches/eraser6/CodeReview/Eraser.Util/ShellApi.cs
r1360 r1543 40 40 (NativeMethods.SHEmptyRecycleBinFlags)options); 41 41 } 42 43 /// <summary>44 /// Encapsulates all functions, structs and constants from Shell32.dll45 /// </summary>46 internal static class NativeMethods47 {48 /// <summary>49 /// Truncates a path to fit within a certain number of characters by50 /// replacing path components with ellipses.51 /// </summary>52 /// <param name="pszOut">[out] The address of the string that has been altered.</param>53 /// <param name="pszSrc">[in] A pointer to a null-terminated string of maximum54 /// length MAX_PATH that contains the path to be altered.</param>55 /// <param name="cchMax">[in] The maximum number of characters to be56 /// contained in the new string, including the terminating NULL character.57 /// For example, if cchMax = 8, the resulting string can contain a maximum58 /// of 7 characters plus the terminating NULL character.</param>59 /// <param name="dwFlags">Reserved.</param>60 /// <returns>Returns TRUE if successful, or FALSE otherwise.</returns>61 [DllImport("Shlwapi.dll", CharSet = CharSet.Unicode)]62 [return: MarshalAs(UnmanagedType.Bool)]63 public static extern bool PathCompactPathEx(StringBuilder pszOut,64 string pszSrc, uint cchMax, uint dwFlags);65 66 /// <summary>67 /// Empties the Recycle Bin on the specified drive.68 /// </summary>69 /// <param name="hwnd">A handle to the parent window of any dialog boxes70 /// that might be displayed during the operation. This parameter can be71 /// NULL.</param>72 /// <param name="pszRootPath">The address of a null-terminated string of73 /// maximum length MAX_PATH that contains the path of the root drive on74 /// which the Recycle Bin is located. This parameter can contain the address75 /// of a string formatted with the drive, folder, and subfolder names, for76 /// example c:\windows\system\. It can also contain an empty string or NULL.77 /// If this value is an empty string or NULL, all Recycle Bins on all drives78 /// will be emptied.</param>79 /// <param name="dwFlags">One or more of the SHEmptyRecycleBinFlags</param>80 /// <returns>Returns S_OK if successful, or a COM-defined error value81 /// otherwise.</returns>82 [DllImport("Shell32.dll", CharSet = CharSet.Unicode)]83 public static extern uint SHEmptyRecycleBin(IntPtr hwnd, string pszRootPath,84 SHEmptyRecycleBinFlags dwFlags);85 86 public enum SHEmptyRecycleBinFlags : uint87 {88 SHERB_NOCONFIRMATION = 0x00000001,89 SHERB_NOPROGRESSUI = 0x00000002,90 SHERB_NOSOUND = 0x0000000491 }92 93 /// <summary>94 /// Retrieves information about an object in the file system, such as a95 /// file, folder, directory, or drive root.96 /// </summary>97 /// <param name="path">[in] A pointer to a null-terminated string of maximum98 /// length MAX_PATH that contains the path and file name. Both absolute99 /// and relative paths are valid.100 ///101 /// If the uFlags parameter includes the SHGFI_PIDL flag, this parameter102 /// must be the address of an ITEMIDLIST (PIDL) structure that contains103 /// the list of item identifiers that uniquely identifies the file within104 /// the Shell's namespace. The pointer to an item identifier list (PIDL)105 /// must be a fully qualified PIDL. Relative PIDLs are not allowed.106 ///107 /// If the uFlags parameter includes the SHGFI_USEFILEATTRIBUTES flag,108 /// this parameter does not have to be a valid file name. The function109 /// will proceed as if the file exists with the specified name and with110 /// the file attributes passed in the dwFileAttributes parameter. This111 /// allows you to obtain information about a file type by passing just112 /// the extension for pszPath and passing FILE_ATTRIBUTE_NORMAL in113 /// dwFileAttributes.114 ///115 /// This string can use either short (the 8.3 form) or long file names.</param>116 /// <param name="fileAttributes">[in] A combination of one or more file117 /// attribute flags (FILE_ATTRIBUTE_ values as defined in Winnt.h). If118 /// uFlags does not include the SHGFI_USEFILEATTRIBUTES flag, this119 /// parameter is ignored.</param>120 /// <param name="psfi">[out] The address of a SHFILEINFO structure to121 /// receive the file information.</param>122 /// <param name="cbFileInfo">[in] The size, in bytes, of the SHFILEINFO123 /// structure pointed to by the psfi parameter.</param>124 /// <param name="uFlags">[in] The flags that specify the file information125 /// to retrieve.126 /// This parameter can be a combination of the values in SHGetFileInfoFlags</param>127 /// <returns>Returns a value whose meaning depends on the uFlags parameter.128 ///129 /// If uFlags does not contain SHGFI_EXETYPE or SHGFI_SYSICONINDEX, the return130 /// value is nonzero if successful, or zero otherwise.131 ///132 /// If uFlags contains the SHGFI_EXETYPE flag, the return value specifies133 /// the type of the executable file. It will be one of the following values.134 /// 0 Nonexecutable file or an error condition.135 /// LOWORD = NE or PE and HIWORD = Windows version Microsoft Windows application.136 /// LOWORD = MZ and HIWORD = 0 Windows 95, Windows 98: Microsoft MS-DOS .exe, .com, or .bat file137 /// Microsoft Windows NT, Windows 2000, Windows XP: MS-DOS .exe or .com file138 /// LOWORD = PE and HIWORD = 0 Windows 95, Windows 98: Microsoft Win32 console application139 /// Windows NT, Windows 2000, Windows XP: Win32 console application or .bat file140 /// </returns>141 [DllImport("Shell32.dll", CharSet = CharSet.Unicode)]142 public static extern IntPtr SHGetFileInfo(string path, uint fileAttributes,143 ref SHFILEINFO psfi, int cbFileInfo, SHGetFileInfoFlags uFlags);144 145 public enum SHGetFileInfoFlags146 {147 /// <summary>148 /// Retrieve the handle to the icon that represents the file and the149 /// index of the icon within the system image list. The handle is150 /// copied to the hIcon member of the structure specified by psfi,151 /// and the index is copied to the iIcon member.152 /// </summary>153 SHGFI_ICON = 0x000000100,154 155 /// <summary>156 /// Retrieve the display name for the file. The name is copied to the157 /// szDisplayName member of the structure specified in psfi. The returned158 /// display name uses the long file name, if there is one, rather than159 /// the 8.3 form of the file name.160 /// </summary>161 SHGFI_DISPLAYNAME = 0x000000200,162 163 /// <summary>164 /// Retrieve the string that describes the file's type. The string165 /// is copied to the szTypeName member of the structure specified in166 /// psfi.167 /// </summary>168 SHGFI_TYPENAME = 0x000000400,169 170 /// <summary>171 /// Retrieve the item attributes. The attributes are copied to the172 /// dwAttributes member of the structure specified in the psfi parameter.173 /// These are the same attributes that are obtained from174 /// IShellFolder::GetAttributesOf.175 /// </summary>176 SHGFI_ATTRIBUTES = 0x000000800,177 178 /// <summary>179 /// Retrieve the name of the file that contains the icon representing180 /// the file specified by pszPath, as returned by the181 /// IExtractIcon::GetIconLocation method of the file's icon handler.182 /// Also retrieve the icon index within that file. The name of the183 /// file containing the icon is copied to the szDisplayName member184 /// of the structure specified by psfi. The icon's index is copied to185 /// that structure's iIcon member.186 /// </summary>187 SHGFI_ICONLOCATION = 0x000001000,188 189 /// <summary>190 /// Retrieve the type of the executable file if pszPath identifies an191 /// executable file. The information is packed into the return value.192 /// This flag cannot be specified with any other flags.193 /// </summary>194 SHGFI_EXETYPE = 0x000002000,195 196 /// <summary>197 /// Retrieve the index of a system image list icon. If successful,198 /// the index is copied to the iIcon member of psfi. The return value199 /// is a handle to the system image list. Only those images whose200 /// indices are successfully copied to iIcon are valid. Attempting201 /// to access other images in the system image list will result in202 /// undefined behavior.203 /// </summary>204 SHGFI_SYSICONINDEX = 0x000004000,205 206 /// <summary>207 /// Modify SHGFI_ICON, causing the function to add the link overlay208 /// to the file's icon. The SHGFI_ICON flag must also be set.209 /// </summary>210 SHGFI_LINKOVERLAY = 0x000008000,211 212 /// <summary>213 /// Modify SHGFI_ICON, causing the function to blend the file's icon214 /// with the system highlight color. The SHGFI_ICON flag must also215 /// be set.216 /// </summary>217 SHGFI_SELECTED = 0x000010000,218 219 /// <summary>220 /// Modify SHGFI_ATTRIBUTES to indicate that the dwAttributes member221 /// of the SHFILEINFO structure at psfi contains the specific attributes222 /// that are desired. These attributes are passed to IShellFolder::GetAttributesOf.223 /// If this flag is not specified, 0xFFFFFFFF is passed to224 /// IShellFolder::GetAttributesOf, requesting all attributes. This flag225 /// cannot be specified with the SHGFI_ICON flag.226 /// </summary>227 SHGFI_ATTR_SPECIFIED = 0x000020000,228 229 /// <summary>230 /// Modify SHGFI_ICON, causing the function to retrieve the file's231 /// large icon. The SHGFI_ICON flag must also be set.232 /// </summary>233 SHGFI_LARGEICON = 0x000000000,234 235 /// <summary>236 /// Modify SHGFI_ICON, causing the function to retrieve the file's237 /// small icon. Also used to modify SHGFI_SYSICONINDEX, causing the238 /// function to return the handle to the system image list that239 /// contains small icon images. The SHGFI_ICON and/or240 /// SHGFI_SYSICONINDEX flag must also be set.241 /// </summary>242 SHGFI_SMALLICON = 0x000000001,243 244 /// <summary>245 /// Modify SHGFI_ICON, causing the function to retrieve the file's246 /// open icon. Also used to modify SHGFI_SYSICONINDEX, causing the247 /// function to return the handle to the system image list that248 /// contains the file's small open icon. A container object displays249 /// an open icon to indicate that the container is open. The SHGFI_ICON250 /// and/or SHGFI_SYSICONINDEX flag must also be set.251 /// </summary>252 SHGFI_OPENICON = 0x000000002,253 254 /// <summary>255 /// Modify SHGFI_ICON, causing the function to retrieve a Shell-sized256 /// icon. If this flag is not specified the function sizes the icon257 /// according to the system metric values. The SHGFI_ICON flag must258 /// also be set.259 /// </summary>260 SHGFI_SHELLICONSIZE = 0x000000004,261 262 /// <summary>263 /// Indicate that pszPath is the address of an ITEMIDLIST structure264 /// rather than a path name.265 /// </summary>266 SHGFI_PIDL = 0x000000008,267 268 /// <summary>269 /// Indicates that the function should not attempt to access the file270 /// specified by pszPath. Rather, it should act as if the file specified271 /// by pszPath exists with the file attributes passed in dwFileAttributes.272 /// This flag cannot be combined with the SHGFI_ATTRIBUTES, SHGFI_EXETYPE,273 /// or SHGFI_PIDL flags.274 /// </summary>275 SHGFI_USEFILEATTRIBUTES = 0x000000010,276 277 /// <summary>278 /// Version 5.0. Apply the appropriate overlays to the file's icon.279 /// The SHGFI_ICON flag must also be set.280 /// </summary>281 SHGFI_ADDOVERLAYS = 0x000000020,282 283 /// <summary>284 /// Version 5.0. Return the index of the overlay icon. The value of285 /// the overlay index is returned in the upper eight bits of the iIcon286 /// member of the structure specified by psfi. This flag requires that287 /// the SHGFI_ICON be set as well.288 /// </summary>289 SHGFI_OVERLAYINDEX = 0x000000040290 }291 292 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]293 public struct SHFILEINFO294 {295 /// <summary>296 /// A handle to the icon that represents the file. You are responsible297 /// for destroying this handle with DestroyIcon when you no longer need it.298 /// </summary>299 public IntPtr hIcon;300 301 /// <summary>302 /// The index of the icon image within the system image list.303 /// </summary>304 public int iIcon;305 306 /// <summary>307 /// An array of values that indicates the attributes of the file object.308 /// For information about these values, see the IShellFolder::GetAttributesOf309 /// method.310 /// </summary>311 public uint dwAttributes;312 313 /// <summary>314 /// A string that contains the name of the file as it appears in the315 /// Microsoft Windows Shell, or the path and file name of the file316 /// that contains the icon representing the file.317 /// </summary>318 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]319 public string szDisplayName;320 321 /// <summary>322 /// A string that describes the type of file.323 /// </summary>324 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]325 public string szTypeName;326 }327 }328 42 } 329 43 … … 339 53 /// No dialog box confirming the deletion of the objects will be displayed. 340 54 /// </summary> 341 NoConfirmation = (int) ShellApi.NativeMethods.SHEmptyRecycleBinFlags.SHERB_NOCONFIRMATION,55 NoConfirmation = (int)NativeMethods.SHEmptyRecycleBinFlags.SHERB_NOCONFIRMATION, 342 56 343 57 /// <summary> 344 58 /// No dialog box indicating the progress will be displayed. 345 59 /// </summary> 346 NoProgressUI = (int) ShellApi.NativeMethods.SHEmptyRecycleBinFlags.SHERB_NOPROGRESSUI,60 NoProgressUI = (int)NativeMethods.SHEmptyRecycleBinFlags.SHERB_NOPROGRESSUI, 347 61 348 62 /// <summary> 349 63 /// No sound will be played when the operation is complete. 350 64 /// </summary> 351 NoSound = (int) ShellApi.NativeMethods.SHEmptyRecycleBinFlags.SHERB_NOSOUND65 NoSound = (int)NativeMethods.SHEmptyRecycleBinFlags.SHERB_NOSOUND 352 66 } 353 67 } -
branches/eraser6/CodeReview/Eraser.Util/UserApi.cs
r1360 r1543 65 65 } 66 66 } 67 68 /// <summary>69 /// Classes, structs and constants imported from User32.dll70 /// </summary>71 internal static class NativeMethods72 {73 /// <summary>74 /// The GetCaretPos function copies the caret's position to the specified75 /// POINT structure.76 /// </summary>77 /// <param name="lpPoint">[out] Pointer to the POINT structure that is to78 /// receive the client coordinates of the caret.</param>79 /// <returns>If the function succeeds, the return value is nonzero.80 /// If the function fails, the return value is zero. To get extended error81 /// information, call Marshal.GetLastWin32Error.</returns>82 [DllImport("User32.dll", SetLastError = true)]83 [return: MarshalAs(UnmanagedType.Bool)]84 public static extern bool GetCaretPos(out Point lpPoint);85 86 /// <summary>87 /// The GetMessagePos function retrieves the cursor position for the88 /// last message retrieved by the GetMessage function.89 /// </summary>90 /// <returns>The return value specifies the x- and y-coordinates of the91 /// cursor position. The x-coordinate is the low order short and the92 /// y-coordinate is the high-order short.</returns>93 [DllImport("User32.dll")]94 public static extern uint GetMessagePos();95 96 /// <summary>97 /// The GetMessageTime function retrieves the message time for the last98 /// message retrieved by the GetMessage function. The time is a long99 /// integer that specifies the elapsed time, in milliseconds, from the100 /// time the system was started to the time the message was created101 /// (that is, placed in the thread's message queue).102 /// </summary>103 /// <returns>The return value specifies the message time.</returns>104 [DllImport("User32.dll")]105 public static extern int GetMessageTime();106 107 /// <summary>108 /// Sends the specified message to a window or windows. The SendMessage109 /// function calls the window procedure for the specified window and does110 /// not return until the window procedure has processed the message.111 /// </summary>112 /// <param name="hWnd">Handle to the window whose window procedure will113 /// receive the message. If this parameter is HWND_BROADCAST, the message114 /// is sent to all top-level windows in the system, including disabled115 /// or invisible unowned windows, overlapped windows, and pop-up windows;116 /// but the message is not sent to child windows.</param>117 /// <param name="Msg">Specifies the message to be sent.</param>118 /// <param name="wParam">Specifies additional message-specific information.</param>119 /// <param name="lParam">Specifies additional message-specific information.</param>120 [DllImport("User32.dll", SetLastError = true)]121 public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, UIntPtr wParam,122 IntPtr lParam);123 124 /// <summary>125 /// Paints via double-buffering, which reduces flicker. This extended126 /// style also enables alpha-blended marquee selection on systems where127 /// it is supported.128 /// </summary>129 public const uint LVS_EX_DOUBLEBUFFER = 0x00010000u;130 131 public const uint LVM_FIRST = 0x1000;132 133 /// <summary>134 /// Sets extended styles in list-view controls.135 /// </summary>136 public const uint LVM_SETEXTENDEDLISTVIEWSTYLE = (LVM_FIRST + 54);137 }138 67 } 139 68 } -
branches/eraser6/CodeReview/Eraser.Util/UxThemeApi.cs
r1500 r1543 26 26 using System.Windows.Forms; 27 27 using System.Drawing; 28 using System.IO;29 28 30 29 namespace Eraser.Util … … 77 76 { 78 77 NativeMethods.SetWindowTheme(lv.Handle, "EXPLORER", null); 79 UserApi.NativeMethods.SendMessage(lv.Handle, 80 UserApi.NativeMethods.LVM_SETEXTENDEDLISTVIEWSTYLE, 81 (UIntPtr)UserApi.NativeMethods.LVS_EX_DOUBLEBUFFER, 82 (IntPtr)UserApi.NativeMethods.LVS_EX_DOUBLEBUFFER); 78 NativeMethods.SendMessage(lv.Handle, NativeMethods.LVM_SETEXTENDEDLISTVIEWSTYLE, 79 (UIntPtr)NativeMethods.LVS_EX_DOUBLEBUFFER, 80 (IntPtr)NativeMethods.LVS_EX_DOUBLEBUFFER); 83 81 } 84 82 catch (DllNotFoundException) … … 224 222 private const int WM_DWMCOMPOSITIONCHANGED = 0x031E; 225 223 private bool ThemesActive; 226 }227 228 /// <summary>229 /// Stores functions, structs and constants from UxTheme.dll and User32.dll230 /// </summary>231 internal static class NativeMethods232 {233 [DllImport("UxTheme.dll", CharSet = CharSet.Unicode)]234 [return: MarshalAs(UnmanagedType.Bool)]235 private static extern bool IsThemeActive();236 237 public static bool ThemesActive238 {239 get240 {241 try242 {243 return IsThemeActive();244 }245 catch (FileLoadException)246 {247 return false;248 }249 }250 }251 252 /// <summary>253 /// Causes a window to use a different set of visual style information254 /// than its class normally uses.255 /// </summary>256 /// <param name="hwnd">Handle to the window whose visual style information257 /// is to be changed.</param>258 /// <param name="pszSubAppName">Pointer to a string that contains the259 /// application name to use in place of the calling application's name.260 /// If this parameter is NULL, the calling application's name is used.</param>261 /// <param name="pszSubIdList">Pointer to a string that contains a262 /// semicolon-separated list of class identifier (CLSID) names to use263 /// in place of the actual list passed by the window's class. If this264 /// parameter is NULL, the ID list from the calling class is used.</param>265 [DllImport("UxTheme.dll", CharSet = CharSet.Unicode)]266 public static extern void SetWindowTheme(IntPtr hwnd, string pszSubAppName,267 string pszSubIdList);268 224 } 269 225 } -
branches/eraser6/CodeReview/Eraser.Util/WintrustApi.cs
r1531 r1543 62 62 } 63 63 } 64 65 internal static class NativeMethods66 {67 /// <summary>68 /// The WinVerifyTrust function performs a trust verification action on a69 /// specified object. The function passes the inquiry to a trust provider70 /// that supports the action identifier, if one exists.71 ///72 /// For certificate verification, use the CertGetCertificateChain and73 /// CertVerifyCertificateChainPolicy functions.74 /// </summary>75 /// <param name="hWnd">Handle to a caller window. A trust provider can use76 /// this value to determine whether it can interact with the user. However,77 /// trust providers typically perform verification actions with input from78 /// the user.79 ///80 /// This parameter can be one of the following values.81 /// Value Meaning82 /// INVALID_HANDLE_VALUE There is no interactive user. The trust provider83 /// performs the verification action without the84 /// user's assistance.85 /// Zero The trust provider can use the interactive desktop86 /// to display its user interface.87 /// A valid window handle A trust provider can treat any value other than88 /// INVALID_HANDLE_VALUE or zero as a valid window89 /// handle that it can use to interact with the user.</param>90 /// <param name="pgActionID">A pointer to a GUID structure that identifies an91 /// action and the trust provider that supports that action. This value indicates92 /// the type of verification action to be performed on the structure pointed to93 /// by pWinTrustData.94 ///95 /// The WinTrust service is designed to work with trust providers implemented96 /// by third parties. Each trust provider provides its own unique set of action97 /// identifiers. For information about the action identifiers supported by a98 /// trust provider, see the documentation for that trust provider.99 ///100 /// or example, Microsoft provides a Software Publisher Trust Provider that can101 /// establish the trustworthiness of software being downloaded from the Internet102 /// or some other public network. The Software Publisher Trust Provider supports103 /// the following action identifiers. These constants are defined in Softpub.h.</param>104 /// <param name="pWVTData">A pointer that, when cast as a WINTRUST_DATA structure,105 /// contains information that the trust provider needs to process the specified106 /// action identifier. Typically, the structure includes information that107 /// identifies the object that the trust provider must evaluate.108 ///109 /// The format of the structure depends on the action identifier. For information110 /// about the data required for a specific action identifier, see the documentation111 /// for the trust provider that supports that action.</param>112 /// <returns>If the trust provider verifies that the subject is trusted for the113 /// specified action, the return value is zero. No other value besides zero114 /// should be considered a successful return.115 ///116 /// If the trust provider does not verify that the subject is trusted for the117 /// specified action, the function returns a status code from the trust provider.118 ///119 /// For example, a trust provider might indicate that the subject is not trusted,120 /// or is trusted but with limitations or warnings. The return value can be a121 /// trust-provider-specific value described in the documentation for an individual122 /// trust provider, or it can be one of the following error codes.123 ///124 /// Return code Description125 /// TRUST_E_SUBJECT_NOT_TRUSTED The subject failed the specified verification126 /// action. Most trust providers return a more127 /// detailed error code that describes the reason128 /// for the failure.129 /// TRUST_E_PROVIDER_UNKNOWN The trust provider is not recognized on this130 /// system.131 /// TRUST_E_ACTION_UNKNOWN The trust provider does not support the132 /// specified action.133 /// TRUST_E_SUBJECT_FORM_UNKNOWN The trust provider does not support the form134 /// specified for the subject.</returns>135 [DllImport("Wintrust.dll", CharSet = CharSet.Unicode)]136 public static extern int WinVerifyTrust(IntPtr hWnd, ref Guid pgActionID,137 ref WINTRUST_DATA pWVTData);138 139 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]140 public struct WINTRUST_FILE_INFO141 {142 public uint cbStruct; // = sizeof(WINTRUST_FILE_INFO)143 public string pcwszFilePath; // required, file name to be verified144 public IntPtr hFile; // optional, open handle to pcwszFilePath145 public IntPtr pgKnownSubject; // optional: fill if the subject type is known.146 }147 148 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]149 public struct WINTRUST_DATA150 {151 public uint cbStruct; // = sizeof(WINTRUST_DATA)152 153 public IntPtr pPolicyCallbackData; // optional: used to pass data between the app and policy154 public IntPtr pSIPClientData; // optional: used to pass data between the app and SIP.155 public UIChoices dwUIChoice; // required: UI choice. One of the following.156 public RevocationChecks fdwRevocationChecks;// required: certificate revocation check options157 public UnionChoices dwUnionChoice; // required: which structure is being passed in?158 159 public IntPtr pUnion;160 161 public StateActions dwStateAction; // optional (Catalog File Processing)162 public IntPtr hWVTStateData; // optional (Catalog File Processing)163 private string pwszURLReference; // optional: (future) used to determine zone.164 public ProviderFlags dwProvFlags;165 public UIContexts dwUIContext;166 167 public enum UIChoices : uint168 {169 WTD_UI_ALL = 1,170 WTD_UI_NONE = 2,171 WTD_UI_NOBAD = 3,172 WTD_UI_NOGOOD = 4,173 }174 public enum RevocationChecks : uint175 {176 WTD_REVOKE_NONE = 0x00000000,177 WTD_REVOKE_WHOLECHAIN = 0x00000001178 }179 public enum UnionChoices : uint180 {181 WTD_CHOICE_FILE = 1,182 WTD_CHOICE_CATALOG = 2,183 WTD_CHOICE_BLOB = 3,184 WTD_CHOICE_SIGNER = 4,185 WTD_CHOICE_CERT = 5186 }187 188 public enum StateActions : uint189 {190 WTD_STATEACTION_IGNORE = 0x00000000,191 WTD_STATEACTION_VERIFY = 0x00000001,192 WTD_STATEACTION_CLOSE = 0x00000002,193 WTD_STATEACTION_AUTO_CACHE = 0x00000003,194 WTD_STATEACTION_AUTO_CACHE_FLUSH = 0x00000004195 }196 public enum ProviderFlags : uint197 {198 WTD_PROV_FLAGS_MASK = 0x0000FFFF,199 WTD_USE_IE4_TRUST_FLAG = 0x00000001,200 WTD_NO_IE4_CHAIN_FLAG = 0x00000002,201 WTD_NO_POLICY_USAGE_FLAG = 0x00000004,202 WTD_REVOCATION_CHECK_NONE = 0x00000010,203 WTD_REVOCATION_CHECK_END_CERT = 0x00000020,204 WTD_REVOCATION_CHECK_CHAIN = 0x00000040,205 WTD_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT = 0x00000080,206 WTD_SAFER_FLAG = 0x00000100,207 WTD_HASH_ONLY_FLAG = 0x00000200,208 WTD_USE_DEFAULT_OSVER_CHECK = 0x00000400,209 WTD_LIFETIME_SIGNING_FLAG = 0x00000800,210 WTD_CACHE_ONLY_URL_RETRIEVAL = 0x00001000211 }212 public enum UIContexts213 {214 WTD_UICONTEXT_EXECUTE = 0,215 WTD_UICONTEXT_INSTALL = 1216 }217 }218 219 public static readonly Guid WINTRUST_ACTION_GENERIC_VERIFY_V2 = new Guid(0xaac56b,220 unchecked((short)0xcd44), 0x11d0, new byte[] { 0x8c, 0xc2, 0x0, 0xc0, 0x4f, 0xc2, 0x95, 0xee });221 }222 64 } 223 65 }
Note: See TracChangeset
for help on using the changeset viewer.
