diff options
| author | jbzdarkid <jbzdarkid@gmail.com> | 2019-11-18 08:43:27 -0800 |
|---|---|---|
| committer | jbzdarkid <jbzdarkid@gmail.com> | 2019-11-18 08:43:27 -0800 |
| commit | 695d0e12950b9df248ea7b84f8434e32acc84f11 (patch) | |
| tree | 69ac20d6a4681fe517033a8c9210d4996a91a5d1 | |
| parent | 133975b5a2ceca273182829f2f11042a5276c2f0 (diff) | |
| download | witness-tutorializer-695d0e12950b9df248ea7b84f8434e32acc84f11.tar.gz witness-tutorializer-695d0e12950b9df248ea7b84f8434e32acc84f11.tar.bz2 witness-tutorializer-695d0e12950b9df248ea7b84f8434e32acc84f11.zip | |
actually free memory
| -rw-r--r-- | Source/Memory.cpp | 33 | ||||
| -rw-r--r-- | Source/Memory.h | 4 |
2 files changed, 2 insertions, 35 deletions
| diff --git a/Source/Memory.cpp b/Source/Memory.cpp index 26ef7e4..55ef18a 100644 --- a/Source/Memory.cpp +++ b/Source/Memory.cpp | |||
| @@ -192,36 +192,3 @@ void* Memory::ComputeOffset(std::vector<int> offsets) { | |||
| 192 | } | 192 | } |
| 193 | return reinterpret_cast<void*>(cumulativeAddress + final_offset); | 193 | return reinterpret_cast<void*>(cumulativeAddress + final_offset); |
| 194 | } | 194 | } |
| 195 | |||
| 196 | uintptr_t Memory::Allocate(size_t bytes) { | ||
| 197 | /* | ||
| 198 | uintptr_t ForeignProcessMemory::AllocateMemory(size_t Size, DWORD Flags) const { | ||
| 199 | if (!ProcessHandle) { | ||
| 200 | return 0; | ||
| 201 | } | ||
| 202 | return (uintptr_t)VirtualAllocEx(ProcessHandle, nullptr, Size, MEM_RESERVE | MEM_COMMIT, Flags); | ||
| 203 | } | ||
| 204 | |||
| 205 | void ForeignProcessMemory::DeallocateMemory(uintptr_t Addr) const { | ||
| 206 | if (!ProcessHandle || Addr == 0) { | ||
| 207 | return; | ||
| 208 | } | ||
| 209 | VirtualFreeEx(ProcessHandle, (void*)Addr, 0, MEM_RELEASE); | ||
| 210 | } | ||
| 211 | */ | ||
| 212 | uintptr_t current = _freeMem; | ||
| 213 | _freeMem += bytes; | ||
| 214 | |||
| 215 | if (_freeMem > _freeMemEnd) { | ||
| 216 | // If we don't have enough space at our current location, go allocate some more space. | ||
| 217 | // Note that the remaining space in our current page is unused. Oh well. | ||
| 218 | _freeMem = reinterpret_cast<uintptr_t>(::VirtualAllocEx(_handle, NULL, 0x1000, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)); | ||
| 219 | _freeMemEnd = _freeMem + 0x1000; | ||
| 220 | |||
| 221 | current = _freeMem; | ||
| 222 | _freeMem += bytes; | ||
| 223 | assert(_freeMem <= _freeMemEnd); // Don't allocate data > 0x1000 at a time. Duh. | ||
| 224 | } | ||
| 225 | |||
| 226 | return current; | ||
| 227 | } | ||
| diff --git a/Source/Memory.h b/Source/Memory.h index 70a271e..79fbaba 100644 --- a/Source/Memory.h +++ b/Source/Memory.h | |||
| @@ -41,9 +41,9 @@ public: | |||
| 41 | 41 | ||
| 42 | template <class T> | 42 | template <class T> |
| 43 | void WriteNewArray(int id, int offset, const std::vector<T>& data) { | 43 | void WriteNewArray(int id, int offset, const std::vector<T>& data) { |
| 44 | uintptr_t addr = VirtualAllocEx(_handle, nullptr, data.size() * sizeof(T), MEM_RESERVE | MEM_COMMIT, MEM_READWRITE); | 44 | uintptr_t addr = (uintptr_t)VirtualAllocEx(_handle, nullptr, data.size() * sizeof(T), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); |
| 45 | _allocations.emplace_back(addr); | 45 | _allocations.emplace_back(addr); |
| 46 | WriteEntityData(id, offset, addr); | 46 | WriteEntityData<uintptr_t>(id, offset, {addr}); |
| 47 | WriteArray(id, offset, data); | 47 | WriteArray(id, offset, data); |
| 48 | } | 48 | } |
| 49 | 49 | ||
