From 6f2b52153d9162ac7ed24f6000ac679a8f719d61 Mon Sep 17 00:00:00 2001 From: xerox Date: Sun, 8 Nov 2020 15:27:10 -0800 Subject: [PATCH] cleaned some code --- nasa-tables/main.cpp | 1 - nasa-tables/mem_ctx/mem_ctx.cpp | 27 ++++++++++++++------------- nasa-tables/mem_ctx/mem_ctx.hpp | 18 ++++++++---------- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/nasa-tables/main.cpp b/nasa-tables/main.cpp index c2b0b27..d4cbac0 100644 --- a/nasa-tables/main.cpp +++ b/nasa-tables/main.cpp @@ -28,7 +28,6 @@ int __cdecl main(int argc, char** argv) return -1; } - my_proc.~mem_ctx(); //needs to be destroyed before vdm::vdm_ctx... std::printf("[+] press any key to close...\n"); std::getchar(); } \ No newline at end of file diff --git a/nasa-tables/mem_ctx/mem_ctx.cpp b/nasa-tables/mem_ctx/mem_ctx.cpp index 12ebd48..f767947 100644 --- a/nasa-tables/mem_ctx/mem_ctx.cpp +++ b/nasa-tables/mem_ctx/mem_ctx.cpp @@ -201,15 +201,16 @@ namespace nasa return true; } - std::pair mem_ctx::get_pte(void* addr, bool use_hyperspace) + auto mem_ctx::get_pte(void* addr, bool use_hyperspace) -> std::pair { if (!dirbase || !addr) - return {}; + return { {}, {} }; pt_entries entries; if ((use_hyperspace ? hyperspace_entries(entries, addr) : (bool)virt_to_phys(entries, addr))) return { entries.pt.first, entries.pt.second }; - return {}; + + return { {}, {} }; } void mem_ctx::set_pte(void* addr, const ::pte& pte, bool use_hyperspace) @@ -223,7 +224,7 @@ namespace nasa write_phys(addr, pte); } - std::pair mem_ctx::get_pde(void* addr, bool use_hyperspace) + auto mem_ctx::get_pde(void* addr, bool use_hyperspace) -> std::pair { if (!dirbase || !addr) return {}; @@ -236,7 +237,7 @@ namespace nasa void mem_ctx::set_pde(void* addr, const ::pde& pde, bool use_hyperspace) { - if (!this->dirbase || !addr) + if (!dirbase || !addr) return; if (use_hyperspace) @@ -245,7 +246,7 @@ namespace nasa write_phys(addr, pde); } - std::pair mem_ctx::get_pdpte(void* addr, bool use_hyperspace) + auto mem_ctx::get_pdpte(void* addr, bool use_hyperspace) -> std::pair { if (!dirbase || !addr) return {}; @@ -258,7 +259,7 @@ namespace nasa void mem_ctx::set_pdpte(void* addr, const ::pdpte& pdpte, bool use_hyperspace) { - if (!this->dirbase || !addr) + if (!dirbase || !addr) return; if (use_hyperspace) @@ -267,9 +268,9 @@ namespace nasa write_phys(addr, pdpte); } - std::pair mem_ctx::get_pml4e(void* addr, bool use_hyperspace) + auto mem_ctx::get_pml4e(void* addr, bool use_hyperspace) -> std::pair { - if (!this->dirbase || !addr) + if (!dirbase || !addr) return {}; pt_entries entries; @@ -280,7 +281,7 @@ namespace nasa void mem_ctx::set_pml4e(void* addr, const ::pml4e& pml4e, bool use_hyperspace) { - if (!this->dirbase || !addr) + if (!dirbase || !addr) return; if (use_hyperspace) @@ -289,7 +290,7 @@ namespace nasa write_phys(addr, pml4e); } - std::pair mem_ctx::read_virtual(void* buffer, void* addr, std::size_t size) + auto mem_ctx::read_virtual(void* buffer, void* addr, std::size_t size) -> std::pair { if (!buffer || !addr || !size || !dirbase) return {}; @@ -331,7 +332,7 @@ namespace nasa } } - std::pair mem_ctx::write_virtual(void* buffer, void* addr, std::size_t size) + auto mem_ctx::write_virtual(void* buffer, void* addr, std::size_t size) -> std::pair { if (!buffer || !addr || !size || !dirbase) return {}; @@ -403,7 +404,7 @@ namespace nasa void* mem_ctx::virt_to_phys(pt_entries& entries, void* addr) { - if (!addr || !this->dirbase) + if (!addr || !dirbase) return {}; const virt_addr_t virt_addr{ addr }; diff --git a/nasa-tables/mem_ctx/mem_ctx.hpp b/nasa-tables/mem_ctx/mem_ctx.hpp index 8a69c48..89c2b2c 100644 --- a/nasa-tables/mem_ctx/mem_ctx.hpp +++ b/nasa-tables/mem_ctx/mem_ctx.hpp @@ -10,16 +10,16 @@ namespace nasa explicit mem_ctx(vdm::vdm_ctx& v_ctx, DWORD pid = GetCurrentProcessId()); ~mem_ctx(); - std::pair get_pte(void* addr, bool use_hyperspace = false); + auto get_pte(void* addr, bool use_hyperspace = false) -> std::pair; void set_pte(void* addr, const ::pte& pte, bool use_hyperspace = false); - std::pair get_pde(void* addr, bool use_hyperspace = false); + auto get_pde(void* addr, bool use_hyperspace = false) -> std::pair; void set_pde(void* addr, const ::pde& pde, bool use_hyperspace = false); - std::pair get_pdpte(void* addr, bool use_hyperspace = false); + auto get_pdpte(void* addr, bool use_hyperspace = false) -> std::pair; void set_pdpte(void* addr, const ::pdpte& pdpte, bool use_hyperspace = false); - std::pair get_pml4e(void* addr, bool use_hyperspace = false); + auto get_pml4e(void* addr, bool use_hyperspace = false) -> std::pair; void set_pml4e(void* addr, const ::pml4e& pml4e, bool use_hyperspace = false); void* get_dirbase() const; @@ -29,23 +29,21 @@ namespace nasa void write_phys(void* buffer, void* addr, std::size_t size); template - T read_phys(void* addr) + __forceinline T read_phys(void* addr) { - if (!addr) return {}; T buffer; read_phys((void*)&buffer, addr, sizeof(T)); return buffer; } template - void write_phys(void* addr, const T& data) + __forceinline void write_phys(void* addr, const T& data) { - if (!addr) return; write_phys((void*)&data, addr, sizeof(T)); } - std::pair read_virtual(void* buffer, void* addr, std::size_t size); - std::pair write_virtual(void* buffer, void* addr, std::size_t size); + auto read_virtual(void* buffer, void* addr, std::size_t size) -> std::pair; + auto write_virtual(void* buffer, void* addr, std::size_t size) -> std::pair; template __forceinline T read_virtual(void* addr)