|
local lpName = "AIDA64_SensorValues" |
|
local FILE_MAP_ACCESS = 0x0004 --> FILE_MAP_READ |
|
|
|
|
|
local ffi = require("ffi") |
|
|
|
ffi.cdef[[ |
|
void* __stdcall OpenFileMappingA( |
|
unsigned long dwDesiredAccess, |
|
int bInheritHandle, |
|
const char* lpName |
|
); |
|
void* __stdcall MapViewOfFile( |
|
void* hFileMappingObject, |
|
unsigned long dwDesiredAccess, |
|
unsigned long dwFileOffsetHigh, |
|
unsigned long dwFileOffsetLow, |
|
unsigned long dwNumberOfBytesToMap |
|
); |
|
int __stdcall UnmapViewOfFile(const void* lpBaseAddress); |
|
int __stdcall CloseHandle(void* hObject); |
|
void __stdcall Sleep(unsigned long dwMilliseconds); |
|
unsigned long __stdcall GetLastError(void); |
|
char* strerror(int errnum); |
|
]] |
|
|
|
|
|
local C = ffi.C |
|
|
|
local function error(errorString, exitCode) |
|
local errno = C.GetLastError() |
|
local strerror = ffi.string(C.strerror(errno)) |
|
print(string.format("%s (%d: %s)", errorString, errno, strerror)) |
|
os.exit(exitCode) |
|
end |
|
|
|
|
|
local hMapFile = C.OpenFileMappingA(FILE_MAP_ACCESS, 0, lpName) |
|
if hMapFile == nil then |
|
error("Could not open file mapping object", 1) |
|
end |
|
|
|
local pBuf = C.MapViewOfFile(hMapFile, FILE_MAP_ACCESS, 0, 0, 0) |
|
if pBuf == nil then |
|
print("CloseHandle...") |
|
C.CloseHandle(hMapFile) |
|
error("Could not map view of file", 2) |
|
end |
|
|
|
------------------------------------------------------------------------------- |
|
local pattern = "<id>([^<]+)</id><label>([^<]+)</label><value>([^<]+)</value>" |
|
for i = 1, 5 do |
|
local str = ffi.string(pBuf) |
|
for id, label, value in string.gmatch(str, pattern) do |
|
print(string.format("%16s %32s %16s", id, label, value)) |
|
end |
|
print() |
|
C.Sleep(1000) |
|
end |
|
------------------------------------------------------------------------------- |
|
|
|
C.UnmapViewOfFile(pBuf) |
|
|
|
C.CloseHandle(hMapFile) |
|
|
|
print("end") |