From 089984b0f25a1656f04d353b12848b0bedc9a243 Mon Sep 17 00:00:00 2001 From: xerox Date: Fri, 8 May 2020 07:44:37 +0000 Subject: [PATCH] fixed small mistakes --- demo/gdrv/physmeme.hpp | 51 +++++++----------------------------------- 1 file changed, 8 insertions(+), 43 deletions(-) diff --git a/demo/gdrv/physmeme.hpp b/demo/gdrv/physmeme.hpp index 5fbad1d..8c25e02 100644 --- a/demo/gdrv/physmeme.hpp +++ b/demo/gdrv/physmeme.hpp @@ -17,50 +17,15 @@ typedef struct _GIOMAP } GIOMAP; #pragma pack ( pop ) -static const char* driver_name = "gdrv"; -static const char* driver_path = (std::filesystem::current_path().string() + "\\driver\\gdrv.sys").c_str(); +constexpr char[] driver_name = "gdrv"; +const char* driver_path = (std::filesystem::current_path().string() + "\\driver\\gdrv.sys").c_str(); namespace physmeme { - //--- ranges of physical memory - static std::map pmem_ranges; - - //--- validates the address - static bool is_valid(std::uintptr_t addr) - { - for (auto range : pmem_ranges) - if (addr >= range.first && addr <= range.first + range.second) - return true; - return false; - } - - // Author: Remy Lebeau - // taken from here: https://stackoverflow.com/questions/48485364/read-reg-resource-list-memory-values-incorrect-value - static const auto init_ranges = ([&]() -> bool - { - HKEY h_key; - DWORD type, size; - LPBYTE data; - RegOpenKeyEx(HKEY_LOCAL_MACHINE, "HARDWARE\\RESOURCEMAP\\System Resources\\Physical Memory", 0, KEY_READ, &h_key); - RegQueryValueEx(h_key, ".Translated", NULL, &type, NULL, &size); //get size - data = new BYTE[size]; - RegQueryValueEx(h_key, ".Translated", NULL, &type, data, &size); - DWORD count = *(DWORD*)(data + 16); - auto pmi = data + 24; - for (int dwIndex = 0; dwIndex < count; dwIndex++) - { - pmem_ranges.emplace(*(uint64_t*)(pmi + 0), *(uint64_t*)(pmi + 8)); - pmi += 20; - } - delete[] data; - RegCloseKey(h_key); - return true; - })(); - /* - please code this function depending on your method of physical read/write. -*/ - static HANDLE load_drv() + please code this function depending on your method of physical read/write. + */ + inline HANDLE load_drv() { const SC_HANDLE manager = OpenSCManager(nullptr, nullptr, SC_MANAGER_CREATE_SERVICE); @@ -102,7 +67,7 @@ namespace physmeme /* please code this function depending on your method of physical read/write. */ - static bool unload_drv() + inline bool unload_drv() { const SC_HANDLE manager = OpenSCManager(nullptr, nullptr, SC_MANAGER_CREATE_SERVICE); @@ -128,7 +93,7 @@ namespace physmeme /* please code this function depending on your method of physical read/write. */ - static std::uintptr_t map_phys( + inline std::uintptr_t map_phys( std::uintptr_t addr, std::size_t size ) @@ -144,7 +109,7 @@ namespace physmeme /* please code this function depending on your method of physical read/write. */ - static bool unmap_phys( + inline bool unmap_phys( std::uintptr_t addr, std::size_t size )