using System;
using System.Runtime.InteropServices;
using System.Text;
namespace Vanara.PInvoke
{
public static partial class Kernel32
{
/// Describes possible machine architectures. Used in GetSystemWow64Directory2 and IsWow64GuestMachineSupported.
// https://msdn.microsoft.com/en-us/library/windows/desktop/mt804345(v=vs.85).aspx
[PInvokeData("Winnt.h", MSDNShortId = "mt804345")]
public enum IMAGE_FILE_MACHINE : ushort
{
/// Unknown
IMAGE_FILE_MACHINE_UNKNOWN = 0,
///
/// Interacts with the host and not a WOW64 guest. This constant is available starting with Windows 10, version 1607 and
/// Windows Server 2016.
///
IMAGE_FILE_MACHINE_TARGET_HOST = 0x0001,
/// Intel 386
IMAGE_FILE_MACHINE_I386 = 0x014c,
/// MIPS little-endian, 0x160 big-endian
IMAGE_FILE_MACHINE_R3000 = 0x0162,
/// MIPS little-endian
IMAGE_FILE_MACHINE_R4000 = 0x0166,
/// MIPS little-endian
IMAGE_FILE_MACHINE_R10000 = 0x0168,
/// MIPS little-endian WCE v2
IMAGE_FILE_MACHINE_WCEMIPSV2 = 0x0169,
/// Alpha_AXP
IMAGE_FILE_MACHINE_ALPHA = 0x0184,
/// SH3 little-endian
IMAGE_FILE_MACHINE_SH3 = 0x01a2,
/// SH3DSP
IMAGE_FILE_MACHINE_SH3DSP = 0x01a3,
/// SH3E little-endian
IMAGE_FILE_MACHINE_SH3E = 0x01a4,
/// SH4 little-endian
IMAGE_FILE_MACHINE_SH4 = 0x01a6,
/// SH5
IMAGE_FILE_MACHINE_SH5 = 0x01a8,
/// ARM Little-Endian
IMAGE_FILE_MACHINE_ARM = 0x01c0,
/// ARM Thumb/Thumb-2 Little-Endian
IMAGE_FILE_MACHINE_THUMB = 0x01c2,
/// ARM Thumb-2 Little-Endian This constant is available starting with Windows 7 and Windows Server 2008 R2.
IMAGE_FILE_MACHINE_ARMNT = 0x01c4,
/// TAM33BD
IMAGE_FILE_MACHINE_AM33 = 0x01d3,
/// IBM PowerPC Little-Endian
IMAGE_FILE_MACHINE_POWERPC = 0x01F0,
/// POWERPCFP
IMAGE_FILE_MACHINE_POWERPCFP = 0x01f1,
/// Intel 64
IMAGE_FILE_MACHINE_IA64 = 0x0200,
/// MIPS
IMAGE_FILE_MACHINE_MIPS16 = 0x0266,
/// ALPHA64
IMAGE_FILE_MACHINE_ALPHA64 = 0x0284,
/// MIPS
IMAGE_FILE_MACHINE_MIPSFPU = 0x0366,
/// MIPS
IMAGE_FILE_MACHINE_MIPSFPU16 = 0x0466,
/// AXP64
IMAGE_FILE_MACHINE_AXP64 = 0x0284,
/// Infineon
IMAGE_FILE_MACHINE_TRICORE = 0x0520,
/// CEF
IMAGE_FILE_MACHINE_CEF = 0x0CEF,
/// EFI Byte Code
IMAGE_FILE_MACHINE_EBC = 0x0EBC,
/// AMD64 (K8)
IMAGE_FILE_MACHINE_AMD64 = 0x8664,
/// M32R little-endian
IMAGE_FILE_MACHINE_M32R = 0x9041,
/// ARM64 Little-Endian This constant is available starting with Windows 8.1 and Windows Server 2012 R2.
IMAGE_FILE_MACHINE_ARM64 = 0xAA64,
/// CEE
IMAGE_FILE_MACHINE_CEE = 0xC0EE,
}
/// Retrieves the path of the system directory used by WOW64. This directory is not present on 32-bit Windows.
/// A pointer to the buffer to receive the path. This path does not end with a backslash.
/// The maximum size of the buffer, in TCHARs.
///
///
/// If the function succeeds, the return value is the length, in TCHARs, of the string copied to the buffer, not including the
/// terminating null character. If the length is greater than the size of the buffer, the return value is the size of the buffer
/// required to hold the path.
///
/// If the function fails, the return value is zero. To get extended error information, call GetLastError.
/// On 32-bit Windows, the function always fails, and the extended error is set to ERROR_CALL_NOT_IMPLEMENTED.
///
// UINT WINAPI GetSystemWow64Directory( _Out_ LPTSTR lpBuffer, _In_ UINT uSize); https://msdn.microsoft.com/en-us/library/windows/desktop/ms724405(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("Winbase.h", MSDNShortId = "ms724405")]
public static extern uint GetSystemWow64Directory(StringBuilder lpBuffer, uint uSize);
///
/// Retrieves the path of the system directory used by WOW64, using the specified image file machine type. This directory is not
/// present on 32-bit Windows.
///
/// A pointer to the buffer to receive the path. This path does not end with a backslash.
/// The maximum size of the buffer, in TCHARs.
/// An IMAGE_FILE_MACHINE_* value that specifies the machine to test.
///
///
/// If the function succeeds, the return value is the length, in TCHARs, of the string copied to the buffer, not including the
/// terminating null character. If the length is greater than the size of the buffer, the return value is the size of the buffer
/// required to hold the path.
///
/// If the function fails, the return value is zero. To get extended error information, call GetLastError.
///
// UINT WINAPI GetSystemWow64Directory( _Out_ LPTSTR lpBuffer, _In_ UINT uSize, _In_ WORD ImageFileMachineType); https://msdn.microsoft.com/en-us/library/windows/desktop/mt804319(v=vs.85).aspx
[DllImport(Lib.KernelBase, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("Wow64apiset.h", MSDNShortId = "mt804319")]
public static extern uint GetSystemWow64Directory2(StringBuilder lpBuffer, uint uSize, IMAGE_FILE_MACHINE ImageFileMachineType);
///
///
/// [Some information relates to pre-released product which may be substantially modified before it's commercially released.
/// Microsoft makes no warranties, express or implied, with respect to the information provided here.]
///
/// Determines which architectures are supported (under WOW64) on the given machine architecture.
///
/// An IMAGE_FILE_MACHINE_* value that specifies the machine to test.
///
/// On success, returns a pointer to a boolean: true if the machine supports WOW64, or false if it does not.
///
/// On success, returns S_OK; otherwise, returns an error. To get extended error information, call GetLastError.
// HRESULT WINAPI IsWow64GuestMachineSupported( _In_ USHORT WowGuestMachine, _Out_ BOOLEAN *MachineIsSupported); https://msdn.microsoft.com/en-us/library/windows/desktop/mt804321(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("Wow64apiset.h", MSDNShortId = "mt804321")]
public static extern HRESULT IsWow64GuestMachineSupported(IMAGE_FILE_MACHINE WowGuestMachine, [MarshalAs(UnmanagedType.U1)] out bool MachineIsSupported);
/// Determines whether the specified process is running under WOW64.
///
///
/// A handle to the process. The handle must have the PROCESS_QUERY_INFORMATION or PROCESS_QUERY_LIMITED_INFORMATION access right.
/// For more information, see Process Security and Access Rights.
///
/// Windows Server 2003 and Windows XP: The handle must have the PROCESS_QUERY_INFORMATION access right.
///
///
/// A pointer to a value that is set to TRUE if the process is running under WOW64. If the process is running under 32-bit Windows,
/// the value is set to FALSE. If the process is a 64-bit application running under 64-bit Windows, the value is also set to FALSE.
///
///
/// If the function succeeds, the return value is a nonzero value.
/// If the function fails, the return value is zero. To get extended error information, call GetLastError.
///
// BOOL WINAPI IsWow64Process( _In_ HANDLE hProcess, _Out_ PBOOL Wow64Process); https://msdn.microsoft.com/en-us/library/windows/desktop/ms684139(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("WinBase.h", MSDNShortId = "ms684139")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool IsWow64Process([In] HPROCESS hProcess, [MarshalAs(UnmanagedType.Bool)] out bool Wow64Process);
///
/// Determines whether the specified process is running under WOW64; also returns additional machine process and architecture information.
///
///
/// A handle to the process. The handle must have the PROCESS_QUERY_INFORMATION or PROCESS_QUERY_LIMITED_INFORMATION access right.
/// For more information, see Process Security and Access Rights.
///
///
/// On success, returns a pointer to an IMAGE_FILE_MACHINE_* value. The value will be IMAGE_FILE_MACHINE_UNKNOWN if the target
/// process is not a WOW64 process; otherwise, it will identify the type of WoW process.
///
///
/// On success, returns a pointer to a possible IMAGE_FILE_MACHINE_* value identifying the native architecture of host system.
///
///
/// If the function succeeds, the return value is a nonzero value.
/// If the function fails, the return value is zero. To get extended error information, call GetLastError.
///
// BOOL WINAPI IsWow64Process( _In_ HANDLE hProcess, _Out_ USHORT *pProcessMachine, _Out_opt_ USHORT *pNativeMachine); https://msdn.microsoft.com/en-us/library/windows/desktop/mt804318(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("Wow64apiset.h", MSDNShortId = "mt804318")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool IsWow64Process2([In] HPROCESS hProcess, out IMAGE_FILE_MACHINE pProcessMachine, out IMAGE_FILE_MACHINE pNativeMachine);
/// Disables file system redirection for the calling thread. File system redirection is enabled by default.
///
/// The WOW64 file system redirection value. The system uses this parameter to store information necessary to revert (re-enable) file
/// system redirection.
///
///
/// If the function succeeds, the return value is a nonzero value.
/// If the function fails, the return value is zero. To get extended error information, call GetLastError.
///
// BOOL WINAPI Wow64DisableWow64FsRedirection( _Out_ PVOID *OldValue); https://msdn.microsoft.com/en-us/library/windows/desktop/aa365743(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("WinBase.h", MSDNShortId = "aa365743")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool Wow64DisableWow64FsRedirection(out IntPtr OldValue);
///
/// Restores file system redirection for the calling thread.
/// This function should not be called without a previous call to the Wow64DisableWow64FsRedirection function.
/// Any data allocation on behalf of the Wow64DisableWow64FsRedirection function is cleaned up by this function.
///
///
/// The WOW64 file system redirection value. This value is obtained from the Wow64DisableWow64FsRedirection function.
///
///
/// If the function succeeds, the return value is a nonzero value.
/// If the function fails, the return value is FALSE (zero). To get extended error information, call GetLastError.
///
// BOOL WINAPI Wow64RevertWow64FsRedirection( _In_ PVOID OldValue); https://msdn.microsoft.com/en-us/library/windows/desktop/aa365745(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("WinBase.h", MSDNShortId = "aa365745")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool Wow64RevertWow64FsRedirection(IntPtr OldValue);
/// Undocumented.
/// Undocumented.
/// Undocumented.
[DllImport(Lib.KernelBase, SetLastError = true, ExactSpelling = true)]
public static extern IMAGE_FILE_MACHINE Wow64SetThreadDefaultGuestMachine(IMAGE_FILE_MACHINE Machine);
}
}