本文整理汇总了C#中SYSTEM_INFO类的典型用法代码示例。如果您正苦于以下问题:C# SYSTEM_INFO类的具体用法?C# SYSTEM_INFO怎么用?C# SYSTEM_INFO使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SYSTEM_INFO类属于命名空间,在下文中一共展示了SYSTEM_INFO类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GainMemoryAccess
public static void GainMemoryAccess(IntPtr address, ulong len)
{
SYSTEM_INFO si = new SYSTEM_INFO();
GetSystemInfo(out si);
MEMORY_BASIC_INFORMATION mbi;
ulong currentAddress = RoundUpToPageBoundary((ulong)address, si.pageSize);
ulong endAddress = currentAddress + len;
uint ret;
uint oldProtect = 0;
while (currentAddress < endAddress)
{
mbi = new MEMORY_BASIC_INFORMATION();
ret = (uint)VirtualQuery((IntPtr)currentAddress, out mbi, (IntPtr)Marshal.SizeOf(mbi));
if (ret != 0)
{
if (mbi.state == MEM_COMMIT)
{
VirtualProtect(mbi.baseAddress, mbi.regionSize, PAGE_EXECUTE_READWRITE, out oldProtect);
}
if ((ulong)mbi.regionSize > 0) currentAddress += (ulong)mbi.regionSize;
else currentAddress += si.pageSize;
}
else currentAddress += si.pageSize;
}
}
示例2: GetOperationSystemPlatform
public static Platform GetOperationSystemPlatform()
{
var sysInfo = new SYSTEM_INFO();
// WinXP and older - use GetNativeSystemInfo
if (Environment.OSVersion.Version.Major > 5 ||
(Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor >= 1))
{
GetNativeSystemInfo(ref sysInfo);
}
// else use GetSystemInfo
else
{
GetSystemInfo(ref sysInfo);
}
switch (sysInfo.wProcessorArchitecture)
{
case PROCESSOR_ARCHITECTURE_IA64:
case PROCESSOR_ARCHITECTURE_AMD64:
return Platform.X64;
case PROCESSOR_ARCHITECTURE_INTEL:
return Platform.X86;
default:
return Platform.Unknown;
}
}
示例3: GetProcessorArchitecture
public static string GetProcessorArchitecture()
{
try
{
SYSTEM_INFO systemInfo = new SYSTEM_INFO();
GetNativeSystemInfo(ref systemInfo);
switch (systemInfo.wProcessorArchitecture)
{
case PROCESSOR_ARCHITECTURE_AMD64:
case PROCESSOR_ARCHITECTURE_IA64:
return "x64";
case PROCESSOR_ARCHITECTURE_ARM:
return "ARM";
case PROCESSOR_ARCHITECTURE_INTEL:
return "x86";
default:
return "Unknown";
}
}
catch
{
return "Unknown";
}
}
示例4: Core
public Core()
{
SYSTEM_INFO info = new SYSTEM_INFO();
GetSystemInfo(ref info);
PAGE_SIZE = info.pageSize;
//dbg //mbd
//CreateDataTypesXml();
}
示例5: Main
// finally...
public static void Main()
{
// getting minimum & maximum address
SYSTEM_INFO sys_info = new SYSTEM_INFO();
GetSystemInfo(out sys_info);
IntPtr proc_min_address = sys_info.minimumApplicationAddress;
IntPtr proc_max_address = sys_info.maximumApplicationAddress;
// saving the values as long ints so I won't have to do a lot of casts later
long proc_min_address_l = (long)proc_min_address;
long proc_max_address_l = (long)proc_max_address;
// notepad better be runnin'
Process process = Process.GetProcessesByName("tibia")[0];
// opening the process with desired access level
IntPtr processHandle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_WM_READ, false, process.Id);
StreamWriter sw = new StreamWriter("dump.txt");
// this will store any information we get from VirtualQueryEx()
MEMORY_BASIC_INFORMATION mem_basic_info = new MEMORY_BASIC_INFORMATION();
int bytesRead = 0; // number of bytes read with ReadProcessMemory
while (proc_min_address_l < proc_max_address_l)
{
// 28 = sizeof(MEMORY_BASIC_INFORMATION)
VirtualQueryEx(processHandle, proc_min_address, out mem_basic_info, 28);
// if this memory chunk is accessible
if (mem_basic_info.Protect == PAGE_READWRITE && mem_basic_info.State == MEM_COMMIT)
{
byte[] buffer = new byte[mem_basic_info.RegionSize];
// read everything in the buffer above
ReadProcessMemory((int)processHandle, mem_basic_info.BaseAddress, buffer, mem_basic_info.RegionSize, ref bytesRead);
// then output this in the file
for (int i = 0; i < mem_basic_info.RegionSize; i++)
sw.WriteLine("0x{0} : {1}", (mem_basic_info.BaseAddress + i).ToString("X"), (char)buffer[i]);
}
// move to the next memory chunk
proc_min_address_l += mem_basic_info.RegionSize;
proc_min_address = new IntPtr(proc_min_address_l);
}
sw.Flush();
sw.Close();
Console.ReadLine();
}
示例6: GetSystemInfo
internal static new void GetSystemInfo(ref SYSTEM_INFO lpSystemInfo)
{
if (MonoUtility.IsLinux)
{
throw new ApplicationException("This method is not supported in mono");
}
else
{
NativeMethods.GetSystemInfo(ref lpSystemInfo);
}
}
示例7: VerifyProcessorCount
bool VerifyProcessorCount()
{
SYSTEM_INFO sysInfo = new SYSTEM_INFO();
SYSTEM_INFO.GetSystemInfo(ref sysInfo);
if (Environment.ProcessorCount != sysInfo.dwNumberOfProcessors)
{
TestFramework.LogError("001", @"ProcessorCount not as expected. Expected (from Win32): " + sysInfo.dwNumberOfProcessors.ToString() + ", Actual (from CLR): " + Environment.ProcessorCount.ToString());
return false;
}
return true;
}
示例8: GetSystemInfoAbstracted
/// <summary>
/// Abstracts the retrieval of a SYSTEM_INFO structure.
/// </summary>
/// <param name="lpSystemInfo">A reference to a SYSTEM_INFO structure that receives the information.</param>
public static void GetSystemInfoAbstracted(ref SYSTEM_INFO lpSystemInfo)
{
if (System.Environment.OSVersion.Version.Major > 5 ||
(System.Environment.OSVersion.Version.Major == 5 && System.Environment.OSVersion.Version.Minor >= 1))
{
GetNativeSystemInfo(ref lpSystemInfo);
}
else
{
GetSystemInfo(ref lpSystemInfo);
}
}
示例9: Windows_ProcessorCountTest
public void Windows_ProcessorCountTest()
{
//arrange
SYSTEM_INFO sysInfo = new SYSTEM_INFO();
GetSystemInfo(ref sysInfo);
int expected = sysInfo.dwNumberOfProcessors;
//act
int actual = Environment.ProcessorCount;
//assert
Assert.True(actual > 0);
Assert.Equal(expected, actual);
}
示例10: GetProcessorType
public static ProcessorType GetProcessorType()
{
SYSTEM_INFO sysInfo = new SYSTEM_INFO();
GetNativeSystemInfo(ref sysInfo);
switch (sysInfo.wProcessorArchitecture)
{
case PROCESSOR_TYPE_INTEL_AMD64:
return ProcessorType.X64;
case PROCESSOR_TYPE_INTEL:
return ProcessorType.X86;
default:
return ProcessorType.Unknown;
}
}
示例11: PreloadLibrary
/// <summary>
/// Try to preload the library.
/// This is useful when we want to have AnyCPU .NET and CPU-specific native code.
/// Only available on Windows for now.
/// </summary>
/// <param name="libraryName">Name of the library.</param>
/// <exception cref="System.InvalidOperationException"></exception>
public static void PreloadLibrary(string libraryName)
{
#if SILICONSTUDIO_PLATFORM_WINDOWS_DESKTOP
var systemInfo = new SYSTEM_INFO();
GetNativeSystemInfo(out systemInfo);
string cpu;
if (systemInfo.processorArchitecture == PROCESSOR_ARCHITECTURE.PROCESSOR_ARCHITECTURE_ARM)
cpu = "ARM";
else
cpu = IntPtr.Size == 8 ? "x64" : "x86";
var libraryFilename = Path.Combine(Path.GetDirectoryName(typeof(NativeLibrary).Assembly.Location), cpu, libraryName);
var result = LoadLibrary(libraryFilename);
if (result == IntPtr.Zero)
throw new InvalidOperationException(string.Format("Could not load native library {0} using CPU architecture {1}.", libraryName, cpu));
#endif
}
示例12: GetProcessorArchitecture
public static ProcessorArchitecture GetProcessorArchitecture()
{
SYSTEM_INFO si = new SYSTEM_INFO();
GetNativeSystemInfo(ref si);
switch (si.wProcessorArchitecture)
{
case PROCESSOR_ARCHITECTURE_AMD64:
return ProcessorArchitecture.Amd64;
case PROCESSOR_ARCHITECTURE_IA64:
return ProcessorArchitecture.IA64;
case PROCESSOR_ARCHITECTURE_INTEL:
return ProcessorArchitecture.X86;
default:
return ProcessorArchitecture.None; // that's weird :-)
}
}
示例13: PreloadLibrary
/// <summary>
/// Try to preload the library.
/// This is useful when we want to have AnyCPU .NET and CPU-specific native code.
/// Only available on Windows for now.
/// </summary>
/// <param name="libraryName">Name of the library.</param>
/// <exception cref="System.InvalidOperationException"></exception>
public static void PreloadLibrary(string libraryName)
{
#if SILICONSTUDIO_PLATFORM_WINDOWS_DESKTOP
lock (LoadedLibraries)
{
// If already loaded, just exit as we want to load it just once
var libraryNameNormalized = libraryName.ToLowerInvariant();
if (LoadedLibraries.ContainsKey(libraryNameNormalized))
{
return;
}
var systemInfo = new SYSTEM_INFO();
GetNativeSystemInfo(out systemInfo);
string cpu;
if (systemInfo.processorArchitecture == PROCESSOR_ARCHITECTURE.PROCESSOR_ARCHITECTURE_ARM)
cpu = "ARM";
else
cpu = IntPtr.Size == 8 ? "x64" : "x86";
// We are trying to load the dll from a shadow path if it is already registered, otherwise we use it directly from the folder
var dllFolder = NativeLibraryInternal.GetShadowPathForNativeDll(libraryName) ?? Path.Combine(AppDomain.CurrentDomain.BaseDirectory, cpu);
var libraryFilename = Path.Combine(dllFolder, libraryName);
var result = LoadLibrary(libraryFilename);
if (result == IntPtr.Zero)
{
throw new InvalidOperationException(string.Format("Could not load native library {0} from path [{1}] using CPU architecture {2}.", libraryName, libraryFilename, cpu));
}
else
{
LoadedLibraries.Add(libraryName.ToLowerInvariant(), result);
}
}
#endif
}
示例14: GetSystemInfo
private static extern void GetSystemInfo(out SYSTEM_INFO input);
示例15: GetNativeSystemInfo
internal static extern void GetNativeSystemInfo(out SYSTEM_INFO info);