diff --git a/VDM/VDM.vcxproj b/VDM/VDM.vcxproj index d516af0..0dc547e 100644 --- a/VDM/VDM.vcxproj +++ b/VDM/VDM.vcxproj @@ -169,6 +169,9 @@ + + + diff --git a/VDM/VDM.vcxproj.filters b/VDM/VDM.vcxproj.filters index 6a8f0ed..3cf6052 100644 --- a/VDM/VDM.vcxproj.filters +++ b/VDM/VDM.vcxproj.filters @@ -44,4 +44,9 @@ Header Files + + + Header Files + + \ No newline at end of file diff --git a/VDM/icon.rc b/VDM/icon.rc new file mode 100644 index 0000000..5856874 --- /dev/null +++ b/VDM/icon.rc @@ -0,0 +1,3 @@ +// Icon Resource Definition +#define MAIN_ICON 102 +MAIN_ICON ICON "small.ico" \ No newline at end of file diff --git a/VDM/small.ico b/VDM/small.ico new file mode 100644 index 0000000..a2f2362 Binary files /dev/null and b/VDM/small.ico differ diff --git a/VDM/util/util.hpp b/VDM/util/util.hpp index 060a796..57fb96f 100644 --- a/VDM/util/util.hpp +++ b/VDM/util/util.hpp @@ -21,27 +21,56 @@ namespace util 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 +#pragma pack (push, 1) + struct PhysicalMemoryPage//CM_PARTIAL_RESOURCE_DESCRIPTOR + { + uint8_t type; + uint8_t shareDisposition; + uint16_t flags; + uint64_t pBegin; + uint32_t sizeButNotExactly; + uint32_t pad; + + static constexpr uint16_t cm_resource_memory_large_40{ 0x200 }; + static constexpr uint16_t cm_resource_memory_large_48{ 0x400 }; + static constexpr uint16_t cm_resource_memory_large_64{ 0x800 }; + + uint64_t size()const noexcept + { + if (flags & cm_resource_memory_large_40) + return uint64_t{ sizeButNotExactly } << 8; + else if (flags & cm_resource_memory_large_48) + return uint64_t{ sizeButNotExactly } << 16; + else if (flags & cm_resource_memory_large_64) + return uint64_t{ sizeButNotExactly } << 32; + else + return uint64_t{ sizeButNotExactly }; + } + }; + static_assert(sizeof(PhysicalMemoryPage) == 20); +#pragma pack (pop) + + inline 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++) { +#if 0 pmem_ranges.emplace(*(uint64_t*)(pmi + 0), *(uint64_t*)(pmi + 8)); +#else + const PhysicalMemoryPage& page{ *(PhysicalMemoryPage*)(pmi - 4) }; + pmem_ranges.emplace(page.pBegin, page.size()); +#endif pmi += 20; } - delete[] data; RegCloseKey(h_key); return true;