xoru

MemoryEx and GetSystemInfo

Aug 28th, 2012
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.89 KB | None | 0 0
  1. function print(...)
  2.     Debug.ShowWindow();
  3.     for i, v in pairs{...}do
  4.         Debug.Print(tostring(v).."\t");
  5.     end
  6.     Debug.Print("\r\n");
  7.     return true;
  8. end
  9.  
  10.  
  11. -- wProcessorArchitecture
  12. PROCESSOR_ARCHITECTURE_AMD64    = 9 -- x64 (AMD or Intel)
  13. PROCESSOR_ARCHITECTURE_IA64     = 6 -- Intel Itanium-based
  14. PROCESSOR_ARCHITECTURE_INTEL    = 0 -- x86
  15. PROCESSOR_ARCHITECTURE_UNKNOWN  = 0xffff
  16.  
  17. PROCS = {
  18.     [PROCESSOR_ARCHITECTURE_AMD64]      = "x64 (AMD / Intel)";
  19.     [PROCESSOR_ARCHITECTURE_IA64]       = "Intel Itanium-based";
  20.     [PROCESSOR_ARCHITECTURE_INTEL]      = "x86";
  21.     [PROCESSOR_ARCHITECTURE_UNKNOWN]    = "Unknown";
  22. };
  23.  
  24. SYSTEM_INFO = MemoryEx.DefineStruct{
  25.     UNION{
  26.         UDWORD  ("dwOemId");
  27.         UWORD   ("wProcessorArchitecture", 2); -- [0] is the field you want. [1] is reserved.
  28.     };
  29.    
  30.     UDWORD  ("dwPageSize");
  31.     UINT    ("lpMinimumApplicationAddress");
  32.     UINT    ("lpMaximumApplicationAddress");
  33.     UDWORD  ("dwActiveProcessorMask");
  34.     UDWORD  ("dwNumberOfProcessors");
  35.     UDWORD  ("dwProcessorType");
  36.     UDWORD  ("dwAllocationGranularity");
  37.    
  38.     UWORD   ("wProcessorLevel");
  39.     UWORD   ("wProcessorRevision");
  40. };
  41.  
  42. function GetSystemInfo(lpStructure)
  43.     local proc = "GetSystemInfo";
  44.     if(System.Is64BitOS())then
  45.         proc = "GetNativeSystemInfo";
  46.     end
  47.    
  48.     DLL.CallFunction("kernel32.dll", proc, tostring(lpStructure), DLL_RETURN_TYPE_INTEGER, DLL_CALL_STDCALL);
  49. end
  50.  
  51. hBuffer = MemoryEx.AllocateEx(MemoryEx.StructSize(SYSTEM_INFO));
  52. if(hBuffer)then
  53.     local hSystemInfo = hBuffer:AssignStruct(SYSTEM_INFO);
  54.     if(hSystemInfo)then
  55.         GetSystemInfo(hBuffer:GetPointer());
  56.        
  57.         print("Proc Architecture",  PROCS[hSystemInfo.wProcessorArchitecture[0]]);
  58.         print("Proc Level",         hSystemInfo.wProcessorLevel);
  59.         print("Proc Revision",      hSystemInfo.wProcessorRevision);
  60.         print("CPU's / Cores",      hSystemInfo.dwNumberOfProcessors);
  61.         print("Page-size\t",        tostring(hSystemInfo.dwPageSize).." bytes");
  62.        
  63.        
  64.         hSystemInfo:Close();
  65.     end
  66.     hBuffer:Free();
  67. end
Advertisement
Add Comment
Please, Sign In to add comment