diff --git a/DMALibrary/Memory/InputManager.cpp b/DMALibrary/Memory/InputManager.cpp index 1253ae5..c231762 100644 --- a/DMALibrary/Memory/InputManager.cpp +++ b/DMALibrary/Memory/InputManager.cpp @@ -71,12 +71,18 @@ void c_keys::UpdateKeys() VMMDLL_MemReadEx(mem.vHandle, this->win_logon_pid | VMMDLL_PID_PROCESS_WITH_KERNELMEMORY, gafAsyncKeyStateExport, (PBYTE)&state_bitmap, 64, NULL, VMMDLL_FLAG_NOCACHE); for (int vk = 0; vk < 256; ++vk) - if ((state_bitmap[((vk * 2) / 8)] & 1 << (vk % 8)) && !(previous_key_state_bitmap[((vk * 2) / 8)] & 1 << (vk % 8))) - previous_state_bitmap[vk / 8] |= 1 << (vk % 8); + if ((state_bitmap[(vk * 2 / 8)] & 1 << vk % 4 * 2) && !(previous_key_state_bitmap[(vk * 2 / 8)] & 1 << vk % 4 * 2)) + previous_state_bitmap[vk / 8] |= 1 << vk % 8; } bool c_keys::IsKeyDown(uint32_t virtual_key_code) { - this->UpdateKeys(); - return state_bitmap[((virtual_key_code * 2) / 8)] & 1 << (virtual_key_code % 8); + if (gafAsyncKeyStateExport < 0x7FFFFFFFFFFF) + return false; + if (std::chrono::system_clock::now() - start > std::chrono::milliseconds(1)) + { + UpdateKeys(); + start = std::chrono::system_clock::now(); + } + return state_bitmap[(virtual_key_code * 2 / 8)] & 1 << virtual_key_code % 4 * 2; } diff --git a/DMALibrary/Memory/InputManager.h b/DMALibrary/Memory/InputManager.h index f5acbc7..04648b7 100644 --- a/DMALibrary/Memory/InputManager.h +++ b/DMALibrary/Memory/InputManager.h @@ -13,6 +13,7 @@ private: int win_logon_pid = 0; c_registry registry; + std::chrono::time_point start = std::chrono::system_clock::now(); public: c_keys() = default; diff --git a/DMALibrary/Memory/Memory.cpp b/DMALibrary/Memory/Memory.cpp index 047b160..7f803bd 100644 --- a/DMALibrary/Memory/Memory.cpp +++ b/DMALibrary/Memory/Memory.cpp @@ -18,6 +18,9 @@ Memory::Memory() LOG("leech: %p\n", modules.LEECHCORE); THROW("[!] Could not load a library\n"); } + + this->key = std::make_shared(); + LOG("Successfully loaded libraries!\n"); } @@ -197,6 +200,11 @@ bool Memory::Init(std::string process_name, bool memMap, bool debug) LOG("[!] Could not get PID from name!\n"); return false; } + this->current_process.process_name = process_name; + if (!mem.FixCr3()) + std::cout << "Failed to fix CR3" << std::endl; + else + std::cout << "CR3 fixed" << std::endl; this->current_process.base_address = GetBaseDaddy(process_name); if (!this->current_process.base_address) @@ -212,8 +220,6 @@ bool Memory::Init(std::string process_name, bool memMap, bool debug) return false; } - this->current_process.process_name = process_name; - LOG("Process information of %s\n", process_name.c_str()); LOG("PID: %i\n", this->current_process.PID); LOG("Base Address: 0x%p\n", this->current_process.base_address); diff --git a/DMALibrary/Memory/Memory.h b/DMALibrary/Memory/Memory.h index b83604d..9737c57 100644 --- a/DMALibrary/Memory/Memory.h +++ b/DMALibrary/Memory/Memory.h @@ -46,7 +46,7 @@ private: bool SetFPGA(); //shared pointer - c_keys key; + std::shared_ptr key; c_registry registry; c_shellcode shellcode; @@ -71,7 +71,7 @@ public: * @brief Gets the key object * @return key class */ - c_keys GetKeyboard() { return key; } + c_keys* GetKeyboard() { return key.get(); } /** * @brief Gets the shellcode object diff --git a/DMALibrary/Memory/Registry.cpp b/DMALibrary/Memory/Registry.cpp index 97e7c0f..15887fe 100644 --- a/DMALibrary/Memory/Registry.cpp +++ b/DMALibrary/Memory/Registry.cpp @@ -4,6 +4,9 @@ std::string c_registry::QueryValue(const char* path, e_registry_type type) { + if (!mem.vHandle) + return ""; + BYTE buffer[0x128]; DWORD _type = (DWORD)type; DWORD size = sizeof(buffer); diff --git a/DMALibrary/Memory/Shellcode.h b/DMALibrary/Memory/Shellcode.h index c4c7cb4..1a760b9 100644 --- a/DMALibrary/Memory/Shellcode.h +++ b/DMALibrary/Memory/Shellcode.h @@ -33,7 +33,6 @@ public: **/ bool call_function(void* hook, void* function, std::string process_name); - //TODO: figure out the mem undeclared fuckery /*template auto SysCall(uint64_t function, Args&&... args) -> std::enable_if_t>::value, std::invoke_result_t> { diff --git a/Example/Example.cpp b/Example/Example.cpp index 74de62b..6af8fb5 100644 --- a/Example/Example.cpp +++ b/Example/Example.cpp @@ -6,7 +6,7 @@ int main() { - if (!mem.Init("explorer.exe", true)) + if (!mem.Init("explorer.exe", true, true)) { std::cout << "Failed to initilize DMA" << std::endl; return 1; @@ -14,27 +14,44 @@ int main() std::cout << "DMA initilized" << std::endl; - if (!mem.GetKeyboard().InitKeyboard()) + if (!mem.GetKeyboard()->InitKeyboard()) { std::cout << "Failed to initialize keyboard hotkeys through kernel." << std::endl; return 1; } //example keyboard usage. - //mem.GetKeyboard().IsKeyDown(VK_F5); + std::cout << "Continueing once 'A' has been pressed." << std::endl; + while (!mem.GetKeyboard()->IsKeyDown(0x41)) + { + } if (!mem.FixCr3()) std::cout << "Failed to fix CR3" << std::endl; else std::cout << "CR3 fixed" << std::endl; - /*auto all_modules = mem.GetModuleList("explorer.exe"); - std::cout << "Explorer.exe Modules: " << std::endl; - for (size_t i = 0; i < all_modules.size(); i++) - { - std::cout << "Module: " << all_modules[i] << std::endl; - }*/ - mem.DumpMemory(mem.GetBaseDaddy("Discovery.exe"), "C:\\dump.exe"); + uintptr_t base = mem.GetBaseDaddy("explorer.exe"); + + std::cout << "Value: " << mem.Read(base + 0x66) << std::endl; + mem.Write(base + 0x66, 0x69); + std::cout << "Value: " << mem.Read(base + 0x66) << std::endl; + + auto handle = mem.CreateScatterHandle(); + + int value = 0; + mem.AddScatterReadRequest(handle, base + 0x66, &value, sizeof(value)); + //You have to execute the read requests before you can read the values. + mem.ExecuteReadScatter(handle); + std::cout << "Value: " << value << std::endl; + + //You can also write to memory using scatter requests. + value = 500; + mem.AddScatterWriteRequest(handle, base + 0x66, &value, sizeof(value)); + mem.ExecuteWriteScatter(handle); + + //Always make sure to clean up the handle, otherwise you'll end up with a memory leak. + mem.CloseScatterHandle(handle); std::cout << "Hello World!\n"; //pause();