Beispiel #1
0
        internal static ProcessorArchitecture GetProcessorArchitecture(out bool isRunningOnArm)
        {
            NativeMethods.SYSTEM_INFO lpSystemInfo = new NativeMethods.SYSTEM_INFO();
            NativeMethods.GetSystemInfo(ref lpSystemInfo);
            isRunningOnArm = false;
            switch (lpSystemInfo.wProcessorArchitecture)
            {
            case 5:
            {
                ProcessorArchitecture none = ProcessorArchitecture.None;
                isRunningOnArm = true;
                return(none);
            }

            case 6:
                return(ProcessorArchitecture.IA64);

            case 9:
                return(ProcessorArchitecture.Amd64);

            case 0:
                return(ProcessorArchitecture.X86);
            }
            return(ProcessorArchitecture.None);
        }
Beispiel #2
0
        /// <summary>
        /// Returns processor architecture for the current process.
        /// If powershell is running inside Wow64, then <see cref="ProcessorArchitecture.X86"/> is returned.
        /// </summary>
        /// <returns>processor architecture for the current process</returns>
        internal static ProcessorArchitecture GetProcessorArchitecture(out bool isRunningOnArm)
        {
            var sysInfo = new NativeMethods.SYSTEM_INFO();

            NativeMethods.GetSystemInfo(ref sysInfo);
            ProcessorArchitecture result;

            isRunningOnArm = false;
            switch (sysInfo.wProcessorArchitecture)
            {
            case NativeMethods.PROCESSOR_ARCHITECTURE_IA64:
                result = ProcessorArchitecture.IA64;
                break;

            case NativeMethods.PROCESSOR_ARCHITECTURE_AMD64:
                result = ProcessorArchitecture.Amd64;
                break;

            case NativeMethods.PROCESSOR_ARCHITECTURE_INTEL:
                result = ProcessorArchitecture.X86;
                break;

            case NativeMethods.PROCESSOR_ARCHITECTURE_ARM:
                result         = ProcessorArchitecture.None;
                isRunningOnArm = true;
                break;

            default:
                result = ProcessorArchitecture.None;
                break;
            }

            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// Return true/false to indicate whether the processor architecture is ARM
        /// </summary>
        /// <returns></returns>
        internal static bool IsRunningOnProcessorArchitectureARM()
        {
            // Important:
            // this function has a clone in SMA in admin\monad\src\utils\PsUtils.cs
            // if you are making any changes specific to this function then update the clone as well.

            NativeMethods.SYSTEM_INFO sysInfo = new NativeMethods.SYSTEM_INFO();
            NativeMethods.GetSystemInfo(ref sysInfo);
            return(sysInfo.wProcessorArchitecture == NativeMethods.PROCESSOR_ARCHITECTURE_ARM);
        }
Beispiel #4
0
        /// <summary>
        /// Return true/false to indicate whether the processor architecture is ARM
        /// </summary>
        /// <returns></returns>
        internal static bool IsRunningOnProcessorArchitectureARM()
        {
#if CORECLR
            Architecture arch = RuntimeInformation.OSArchitecture;
            if (arch == Architecture.Arm || arch == Architecture.Arm64)
            {
                return(true);
            }
            else
            {
                return(false);
            }
#else
            // Important:
            // this function has a clone in Workflow.ServiceCore in admin\monad\src\m3p\product\ServiceCore\WorkflowCore\WorkflowRuntimeCompilation.cs
            // if you are making any changes specific to this function then update the clone as well.

            var sysInfo = new NativeMethods.SYSTEM_INFO();
            NativeMethods.GetSystemInfo(ref sysInfo);
            return(sysInfo.wProcessorArchitecture == NativeMethods.PROCESSOR_ARCHITECTURE_ARM);
#endif
        }
      private static void UpdateData()
      {
         NativeMethods.OSVERSIONINFOEX info = new NativeMethods.OSVERSIONINFOEX();
         info.dwOSVersionInfoSize = Marshal.SizeOf(info);

         NativeMethods.SYSTEM_INFO sysInfo = new NativeMethods.SYSTEM_INFO();

         NativeMethods.GetSystemInfo(out sysInfo);
         if (!NativeMethods.GetVersionExW(ref info))
         {
            Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error());
         }

         Debug.Assert(info.dwMajorVersion == Environment.OSVersion.Version.Major);
         Debug.Assert(info.dwMinorVersion == Environment.OSVersion.Version.Minor);
         Debug.Assert(info.dwBuildNumber == Environment.OSVersion.Version.Build);

         s_processorArchitecture = (ProcessorArchitecture)sysInfo.processorArchitecture;

         s_servicePackVersion = new Version(info.wServicePackMajor, info.wServicePackMinor);

         s_isServer = info.wProductType == NativeMethods.VER_NT_DOMAIN_CONTROLLER || info.wProductType == NativeMethods.VER_NT_SERVER;

         if (info.dwMajorVersion > 6)
         {
            s_osVersionName = OSVersionName.Later;
         }
         else if (info.dwMajorVersion == 6) 
         {
            if (info.dwMinorVersion == 0) // Windows Vista or Windows Server 2008
            {
               if (info.wProductType == NativeMethods.VER_NT_WORKSTATION) // Vista
               {
                  s_osVersionName = OSVersionName.WindowsVista;
               }
               else
               {
                  s_osVersionName = OSVersionName.WindowsServer2008;
               }
            }
            else if (info.dwMinorVersion == 1) // Windows 7 or Windows Server 2008 R2
            {
               if (info.wProductType == NativeMethods.VER_NT_WORKSTATION)
               {
                  s_osVersionName = Vss.OSVersionName.Windows7;
               }
               else
               {
                  s_osVersionName = Vss.OSVersionName.WindowsServer2008R2;
               }
            }
            else
            {
               s_osVersionName = Vss.OSVersionName.Later;
            }
         }
         else if (info.dwMajorVersion == 5)
         {
            if (info.dwMinorVersion == 0)
            {
               s_osVersionName = OSVersionName.Windows2000;
            }
            if (info.dwMinorVersion == 1)
            {
               s_osVersionName = OSVersionName.WindowsXP;
            }
            else if (info.dwMinorVersion == 2)
            {
               if (info.wProductType == NativeMethods.VER_NT_WORKSTATION && s_processorArchitecture == ProcessorArchitecture.X64)
               {
                  s_osVersionName = OSVersionName.WindowsXP;
               }
               else if (info.wProductType != NativeMethods.VER_NT_WORKSTATION)
               {
                  s_osVersionName = OSVersionName.WindowsServer2003;
               }
               else
               {
                  s_osVersionName = OSVersionName.Later;
               }
            }
            else
            {
               s_osVersionName = OSVersionName.Later;
            }
         }
      }
        private static void UpdateData()
        {
            var verInfo = new NativeMethods.RTL_OSVERSIONINFOEXW();

            // Needed to prevent: System.Runtime.InteropServices.COMException:
            // The data area passed to a system call is too small. (Exception from HRESULT: 0x8007007A)
            verInfo.dwOSVersionInfoSize = Marshal.SizeOf(verInfo);

            var sysInfo = new NativeMethods.SYSTEM_INFO();

            NativeMethods.GetNativeSystemInfo(ref sysInfo);


            // RtlGetVersion returns STATUS_SUCCESS (0).
            var success = !NativeMethods.RtlGetVersion(ref verInfo);

            var lastError = Marshal.GetLastWin32Error();

            if (!success)
            {
                throw new Win32Exception(lastError, "Function RtlGetVersion() failed to retrieve the operating system information.");
            }


            _osVersion = new Version(verInfo.dwMajorVersion, verInfo.dwMinorVersion, verInfo.dwBuildNumber);

            _processorArchitecture = sysInfo.wProcessorArchitecture;
            _servicePackVersion    = new Version(verInfo.wServicePackMajor, verInfo.wServicePackMinor);
            _isServer = verInfo.wProductType == NativeMethods.VER_NT_DOMAIN_CONTROLLER || verInfo.wProductType == NativeMethods.VER_NT_SERVER;


            // RtlGetVersion: https://msdn.microsoft.com/en-us/library/windows/hardware/ff561910%28v=vs.85%29.aspx
            // Operating System Version: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724832(v=vs.85).aspx

            // The following table summarizes the most recent operating system version numbers.
            //    Operating system	            Version number    Other
            // ================================================================================
            //    Windows 10                    10.0              OSVERSIONINFOEX.wProductType == VER_NT_WORKSTATION
            //    Windows Server 2016           10.0              OSVERSIONINFOEX.wProductType != VER_NT_WORKSTATION
            //    Windows 8.1                   6.3               OSVERSIONINFOEX.wProductType == VER_NT_WORKSTATION
            //    Windows Server 2012 R2        6.3               OSVERSIONINFOEX.wProductType != VER_NT_WORKSTATION
            //    Windows 8	                  6.2               OSVERSIONINFOEX.wProductType == VER_NT_WORKSTATION
            //    Windows Server 2012	         6.2               OSVERSIONINFOEX.wProductType != VER_NT_WORKSTATION
            //    Windows 7	                  6.1               OSVERSIONINFOEX.wProductType == VER_NT_WORKSTATION
            //    Windows Server 2008 R2	      6.1               OSVERSIONINFOEX.wProductType != VER_NT_WORKSTATION
            //    Windows Server 2008	         6.0               OSVERSIONINFOEX.wProductType != VER_NT_WORKSTATION
            //    Windows Vista	               6.0               OSVERSIONINFOEX.wProductType == VER_NT_WORKSTATION
            //    Windows Server 2003 R2	      5.2               GetSystemMetrics(SM_SERVERR2) != 0
            //    Windows Server 2003           5.2               GetSystemMetrics(SM_SERVERR2) == 0
            //    Windows XP 64-Bit Edition     5.2               (OSVERSIONINFOEX.wProductType == VER_NT_WORKSTATION) && (sysInfo.PaName == PaName.X64)
            //    Windows XP	                  5.1               Not applicable
            //    Windows 2000	               5.0               Not applicable


            // 2017-01-07: 10 == The lastest MajorVersion of Windows.
            if (verInfo.dwMajorVersion > 10)
            {
                _enumOsName = EnumOsName.Later;
            }

            else
            {
                switch (verInfo.dwMajorVersion)
                {
                    #region Version 10

                case 10:

                    // Windows 10 or Windows Server 2016

                    _enumOsName = verInfo.wProductType == NativeMethods.VER_NT_WORKSTATION
                     ? EnumOsName.Windows10
                     : EnumOsName.WindowsServer2016;

                    break;


                    #endregion // Version 10


                    #region Version 6

                case 6:
                    switch (verInfo.dwMinorVersion)
                    {
                    // Windows 8.1 or Windows Server 2012 R2
                    case 3:
                        _enumOsName = verInfo.wProductType == NativeMethods.VER_NT_WORKSTATION
                           ? EnumOsName.Windows81
                           : EnumOsName.WindowsServer2012R2;
                        break;


                    // Windows 8 or Windows Server 2012
                    case 2:
                        _enumOsName = verInfo.wProductType == NativeMethods.VER_NT_WORKSTATION
                           ? EnumOsName.Windows8
                           : EnumOsName.WindowsServer2012;
                        break;


                    // Windows 7 or Windows Server 2008 R2
                    case 1:
                        _enumOsName = verInfo.wProductType == NativeMethods.VER_NT_WORKSTATION
                           ? EnumOsName.Windows7
                           : EnumOsName.WindowsServer2008R2;
                        break;


                    // Windows Vista or Windows Server 2008
                    case 0:
                        _enumOsName = verInfo.wProductType == NativeMethods.VER_NT_WORKSTATION
                           ? EnumOsName.WindowsVista
                           : EnumOsName.WindowsServer2008;
                        break;


                    default:
                        _enumOsName = EnumOsName.Later;
                        break;
                    }

                    break;

                    #endregion // Version 6


                    #region Version 5

                case 5:
                    switch (verInfo.dwMinorVersion)
                    {
                    case 2:
                        _enumOsName = verInfo.wProductType == NativeMethods.VER_NT_WORKSTATION && _processorArchitecture == EnumProcessorArchitecture.X64
                           ? EnumOsName.WindowsXP
                           : verInfo.wProductType != NativeMethods.VER_NT_WORKSTATION ? EnumOsName.WindowsServer2003 : EnumOsName.Later;
                        break;


                    case 1:
                        _enumOsName = EnumOsName.WindowsXP;
                        break;


                    case 0:
                        _enumOsName = EnumOsName.Windows2000;
                        break;


                    default:
                        _enumOsName = EnumOsName.Later;
                        break;
                    }
                    break;

                    #endregion // Version 5


                default:
                    _enumOsName = EnumOsName.Earlier;
                    break;
                }
            }
        }
Beispiel #7
0
        private static void UpdateData()
        {
            NativeMethods.OSVERSIONINFOEX info = new NativeMethods.OSVERSIONINFOEX();
            info.dwOSVersionInfoSize = Marshal.SizeOf(info);

            NativeMethods.SYSTEM_INFO sysInfo = new NativeMethods.SYSTEM_INFO();

            NativeMethods.GetSystemInfo(out sysInfo);
            if (!NativeMethods.GetVersionExW(ref info))
            {
                Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error());
            }

            Debug.Assert(info.dwMajorVersion == Environment.OSVersion.Version.Major);
            Debug.Assert(info.dwMinorVersion == Environment.OSVersion.Version.Minor);
            Debug.Assert(info.dwBuildNumber == Environment.OSVersion.Version.Build);

            s_processorArchitecture = (ProcessorArchitecture)sysInfo.processorArchitecture;

            s_servicePackVersion = new Version(info.wServicePackMajor, info.wServicePackMinor);

            s_isServer = info.wProductType == NativeMethods.VER_NT_DOMAIN_CONTROLLER || info.wProductType == NativeMethods.VER_NT_SERVER;

            if (info.dwMajorVersion > 6)
            {
                s_osVersionName = OSVersionName.Later;
            }
            else if (info.dwMajorVersion == 6)
            {
                if (info.dwMinorVersion == 0)                                  // Windows Vista or Windows Server 2008
                {
                    if (info.wProductType == NativeMethods.VER_NT_WORKSTATION) // Vista
                    {
                        s_osVersionName = OSVersionName.WindowsVista;
                    }
                    else
                    {
                        s_osVersionName = OSVersionName.WindowsServer2008;
                    }
                }
                else if (info.dwMinorVersion == 1) // Windows 7 or Windows Server 2008 R2
                {
                    if (info.wProductType == NativeMethods.VER_NT_WORKSTATION)
                    {
                        s_osVersionName = Vss.OSVersionName.Windows7;
                    }
                    else
                    {
                        s_osVersionName = Vss.OSVersionName.WindowsServer2008R2;
                    }
                }
                else
                {
                    s_osVersionName = Vss.OSVersionName.Later;
                }
            }
            else if (info.dwMajorVersion == 5)
            {
                if (info.dwMinorVersion == 0)
                {
                    s_osVersionName = OSVersionName.Windows2000;
                }
                if (info.dwMinorVersion == 1)
                {
                    s_osVersionName = OSVersionName.WindowsXP;
                }
                else if (info.dwMinorVersion == 2)
                {
                    if (info.wProductType == NativeMethods.VER_NT_WORKSTATION && s_processorArchitecture == ProcessorArchitecture.X64)
                    {
                        s_osVersionName = OSVersionName.WindowsXP;
                    }
                    else if (info.wProductType != NativeMethods.VER_NT_WORKSTATION)
                    {
                        s_osVersionName = OSVersionName.WindowsServer2003;
                    }
                    else
                    {
                        s_osVersionName = OSVersionName.Later;
                    }
                }
                else
                {
                    s_osVersionName = OSVersionName.Later;
                }
            }
        }
Beispiel #8
0
        private List <NativeMethods.MEMORY_BASIC_INFORMATION> FetchMemoryPages()
        {
            currentStatus.Report(new StatusUpdate {
                CurrentProcess = StatusUpdate.ProcessType.ReadingMemory, ProcessPercentage = 0f
            });

            List <NativeMethods.MEMORY_BASIC_INFORMATION> areas = new List <NativeMethods.MEMORY_BASIC_INFORMATION>();

            NativeMethods.SYSTEM_INFO sys_info = new NativeMethods.SYSTEM_INFO();
            NativeMethods.GetSystemInfo(out sys_info);

            IntPtr proc_min_address = sys_info.minimumApplicationAddress;
            IntPtr proc_max_address = sys_info.maximumApplicationAddress;

            long proc_min_address_l = proc_min_address.ToInt64();
            long proc_max_address_l = proc_max_address.ToInt64();

            // this will store any information we get from VirtualQueryEx()
            NativeMethods.MEMORY_BASIC_INFORMATION mem_basic_info = new NativeMethods.MEMORY_BASIC_INFORMATION();

            long startAt = proc_min_address_l;

            while (proc_min_address_l < proc_max_address_l)
            {
                currentStatus.Report(new StatusUpdate {
                    CurrentProcess = StatusUpdate.ProcessType.ReadingMemory, ProcessPercentage = 1 - (proc_max_address_l - proc_min_address_l) / (float)(proc_max_address_l - startAt)
                });
                // 28 = sizeof(NativeMethods.MEMORY_BASIC_INFORMATION)
                NativeMethods.VirtualQueryEx(processHandle, proc_min_address, out mem_basic_info, new UIntPtr(48));
                int errorCode = Marshal.GetLastWin32Error();
                switch (errorCode)
                {
                case 0:
                    // intentionally void
                    break;

                case 299:
                    Trace.WriteLine("Couldn't read entire memory...");
                    break;

                default:
                    Marshal.ThrowExceptionForHR(errorCode);
                    break;
                }

                // if this memory chunk is accessible
                long regionSize = mem_basic_info.RegionSize.ToInt64();
                if (mem_basic_info.Protect == NativeMethods.AllocationProtectEnum.PAGE_READWRITE && mem_basic_info.State == NativeMethods.StateEnum.MEM_COMMIT)
                {
                    // memory area containing our byte usually are more than 100kb big
                    if (mem_basic_info.RegionSize.ToInt64() >= 0x10000)
                    {
                        areas.Add(mem_basic_info);
                    }
                }

                // move to the next memory chunk
                proc_min_address_l += regionSize;
                proc_min_address    = new IntPtr(proc_min_address_l);
            }

            currentStatus.Report(new StatusUpdate {
                CurrentProcess = StatusUpdate.ProcessType.ReadingMemory, ProcessPercentage = 1.0f
            });

            return(areas);
        }
Beispiel #9
0
        /// <summary>
        ///   References the native hunspell DLL.
        /// </summary>
        /// <exception cref="System.DllNotFoundException"></exception>
        /// <exception cref="System.NotSupportedException"></exception>
        internal static void ReferenceNativeHunspellDll()
        {
            lock (nativeDllReferenceCountLock)
            {
                if (nativeDllReferenceCount == 0)
                {
                    if (dllHandle != IntPtr.Zero)
                    {
                        throw new InvalidOperationException("Native Dll handle is not Zero");
                    }

                    try
                    {
                        // Initialze the dynamic marshall Infrastructure to call the 32Bit (x86) or the 64Bit (x64) Dll respectively
                        var info = new NativeMethods.SYSTEM_INFO();
                        NativeMethods.GetSystemInfo(ref info);

                        // Load the correct DLL according to the processor architecture
                        switch (info.wProcessorArchitecture)
                        {
                        case NativeMethods.PROCESSOR_ARCHITECTURE.Intel:
                            string pathx86 = NativeDLLPath;
                            if (!String.IsNullOrEmpty(pathx86) && !pathx86.EndsWith("\\"))
                            {
                                pathx86 += "\\";
                            }

                            pathx86 += Hunspell.HunspellX86DllName;

                            dllHandle = NativeMethods.LoadLibrary(pathx86);
                            if (dllHandle == IntPtr.Zero)
                            {
                                throw new DllNotFoundException(string.Format(Hunspell.HunspellX86DllNotFoundMessage, pathx86));
                            }

                            break;

                        case NativeMethods.PROCESSOR_ARCHITECTURE.Amd64:
                            string pathx64 = NativeDLLPath;
                            if (!String.IsNullOrEmpty(pathx64) && !pathx64.EndsWith("\\"))
                            {
                                pathx64 += "\\";
                            }

                            pathx64 += Hunspell.HunspellX64DllName;

                            dllHandle = NativeMethods.LoadLibrary(pathx64);
                            if (dllHandle == IntPtr.Zero)
                            {
                                throw new DllNotFoundException(string.Format(Hunspell.HunspellX64DllNotFoundMessage, pathx64));
                            }

                            break;

                        default:
                            throw new NotSupportedException(Hunspell.HunspellNotAvailabeForProcessorArchitectureMessage + info.wProcessorArchitecture);
                        }

                        HunspellInit = (HunspellInitDelegate)GetDelegate("HunspellInit", typeof(HunspellInitDelegate));
                        HunspellFree = (HunspellFreeDelegate)GetDelegate("HunspellFree", typeof(HunspellFreeDelegate));

                        HunspellAdd          = (HunspellAddDelegate)GetDelegate("HunspellAdd", typeof(HunspellAddDelegate));
                        HunspellAddWithAffix = (HunspellAddWithAffixDelegate)GetDelegate("HunspellAddWithAffix", typeof(HunspellAddWithAffixDelegate));

                        HunspellRemove = (HunspellRemoveDelegate)GetDelegate("HunspellRemove", typeof(HunspellRemoveDelegate));

                        HunspellSpell   = (HunspellSpellDelegate)GetDelegate("HunspellSpell", typeof(HunspellSpellDelegate));
                        HunspellSuggest = (HunspellSuggestDelegate)GetDelegate("HunspellSuggest", typeof(HunspellSuggestDelegate));

                        HunspellAnalyze  = (HunspellAnalyzeDelegate)GetDelegate("HunspellAnalyze", typeof(HunspellAnalyzeDelegate));
                        HunspellStem     = (HunspellStemDelegate)GetDelegate("HunspellStem", typeof(HunspellStemDelegate));
                        HunspellGenerate = (HunspellGenerateDelegate)GetDelegate("HunspellGenerate", typeof(HunspellGenerateDelegate));

                        HyphenInit      = (HyphenInitDelegate)GetDelegate("HyphenInit", typeof(HyphenInitDelegate));
                        HyphenFree      = (HyphenFreeDelegate)GetDelegate("HyphenFree", typeof(HyphenFreeDelegate));
                        HyphenHyphenate = (HyphenHyphenateDelegate)GetDelegate("HyphenHyphenate", typeof(HyphenHyphenateDelegate));
                    }
                    catch
                    {
                        if (dllHandle != IntPtr.Zero)
                        {
                            NativeMethods.FreeLibrary(dllHandle);
                            dllHandle = IntPtr.Zero;
                        }

                        throw;
                    }
                }

                ++nativeDllReferenceCount;
            }
        }
Beispiel #10
0
 internal static extern void GetSystemInfo(out NativeMethods.SYSTEM_INFO SystemInfo);
        /// <summary>
        /// Return true/false to indicate whether the processor architecture is ARM
        /// </summary>
        /// <returns></returns>
        internal static bool IsRunningOnProcessorArchitectureARM()
        {
            // Important:
            // this function has a clone in SMA in admin\monad\src\utils\PsUtils.cs
            // if you are making any changes specific to this function then update the clone as well.

            NativeMethods.SYSTEM_INFO sysInfo = new NativeMethods.SYSTEM_INFO();
            NativeMethods.GetSystemInfo(ref sysInfo);
            return sysInfo.wProcessorArchitecture == NativeMethods.PROCESSOR_ARCHITECTURE_ARM;
        }
Beispiel #12
0
        /// <summary>
        /// Return true/false to indicate whether the processor architecture is ARM
        /// </summary>
        /// <returns></returns>
        internal static bool IsRunningOnProcessorArchitectureARM()
        {
#if CORECLR
            Architecture arch = RuntimeInformation.OSArchitecture;
            if (arch == Architecture.Arm || arch == Architecture.Arm64)
            {
                return true;
            }
            else
            {
                return false;
            }
#else
            // Important:
            // this function has a clone in Workflow.ServiceCore in admin\monad\src\m3p\product\ServiceCore\WorkflowCore\WorkflowRuntimeCompilation.cs
            // if you are making any changes specific to this function then update the clone as well.

            var sysInfo = new NativeMethods.SYSTEM_INFO();
            NativeMethods.GetSystemInfo(ref sysInfo);
            return sysInfo.wProcessorArchitecture == NativeMethods.PROCESSOR_ARCHITECTURE_ARM;
#endif
        }
Beispiel #13
0
        /// <summary>
        /// Returns processor architecture for the current process.
        /// If powershell is running inside Wow64, then <see cref="ProcessorArchitecture.X86"/> is returned.
        /// </summary>
        /// <returns>processor architecture for the current process</returns>
        internal static ProcessorArchitecture GetProcessorArchitecture(out bool isRunningOnArm)
        {
            var sysInfo = new NativeMethods.SYSTEM_INFO();
            NativeMethods.GetSystemInfo(ref sysInfo);
            ProcessorArchitecture result;
            isRunningOnArm = false;
            switch (sysInfo.wProcessorArchitecture)
            {
                case NativeMethods.PROCESSOR_ARCHITECTURE_IA64:
                    result = ProcessorArchitecture.IA64;
                    break;
                case NativeMethods.PROCESSOR_ARCHITECTURE_AMD64:
                    result = ProcessorArchitecture.Amd64;
                    break;
                case NativeMethods.PROCESSOR_ARCHITECTURE_INTEL:
                    result = ProcessorArchitecture.X86;
                    break;
                case NativeMethods.PROCESSOR_ARCHITECTURE_ARM:
                    result = ProcessorArchitecture.None;
                    isRunningOnArm = true;
                    break;

                default:
                    result = ProcessorArchitecture.None;
                    break;
            }

            return result;
        }
Beispiel #14
0
 internal static bool IsRunningOnProcessorArchitectureARM()
 {
     NativeMethods.SYSTEM_INFO lpSystemInfo = new NativeMethods.SYSTEM_INFO();
     NativeMethods.GetSystemInfo(ref lpSystemInfo);
     return(lpSystemInfo.wProcessorArchitecture == 5);
 }
Beispiel #15
0
 internal static bool IsRunningOnProcessorArchitectureARM()
 {
     NativeMethods.SYSTEM_INFO lpSystemInfo = new NativeMethods.SYSTEM_INFO();
     NativeMethods.GetSystemInfo(ref lpSystemInfo);
     return (lpSystemInfo.wProcessorArchitecture == 5);
 }
Beispiel #16
0
        internal static ProcessorArchitecture GetProcessorArchitecture(out bool isRunningOnArm)
        {
            NativeMethods.SYSTEM_INFO lpSystemInfo = new NativeMethods.SYSTEM_INFO();
            NativeMethods.GetSystemInfo(ref lpSystemInfo);
            isRunningOnArm = false;
            switch (lpSystemInfo.wProcessorArchitecture)
            {
                case 5:
                {
                    ProcessorArchitecture none = ProcessorArchitecture.None;
                    isRunningOnArm = true;
                    return none;
                }
                case 6:
                    return ProcessorArchitecture.IA64;

                case 9:
                    return ProcessorArchitecture.Amd64;

                case 0:
                    return ProcessorArchitecture.X86;
            }
            return ProcessorArchitecture.None;
        }