summary refs log tree commit diff stats
path: root/Source/Memory.cpp
diff options
context:
space:
mode:
authorjbzdarkid <jbzdarkid@gmail.com>2018-11-07 09:26:42 -0800
committerjbzdarkid <jbzdarkid@gmail.com>2018-11-07 09:26:42 -0800
commit5ad08f6611c8c777c43cfa0d2380b6ad6554a54d (patch)
treee14b08857f15003bdeb47daca0dc5e741c033b94 /Source/Memory.cpp
parente762e48d6fbab7bd5137c369fa49df25ccd5369d (diff)
downloadwitness-tutorializer-5ad08f6611c8c777c43cfa0d2380b6ad6554a54d.tar.gz
witness-tutorializer-5ad08f6611c8c777c43cfa0d2380b6ad6554a54d.tar.bz2
witness-tutorializer-5ad08f6611c8c777c43cfa0d2380b6ad6554a54d.zip
Not sure what other feature work is valuable -- I'd rather work on exporting.
Diffstat (limited to 'Source/Memory.cpp')
-rw-r--r--Source/Memory.cpp35
1 files changed, 23 insertions, 12 deletions
diff --git a/Source/Memory.cpp b/Source/Memory.cpp index 0afeded..825346a 100644 --- a/Source/Memory.cpp +++ b/Source/Memory.cpp
@@ -18,8 +18,8 @@ Memory::Memory(const std::string& processName) {
18 } 18 }
19 } 19 }
20 if (!_handle) { 20 if (!_handle) {
21 std::cout << "Couldn't find " << processName.c_str() << ", is it open?" << std::endl; 21 std::cerr << "Couldn't find " << processName.c_str() << ", is it open?" << std::endl;
22 exit(EXIT_FAILURE); 22 throw std::exception("Unable to find process!");
23 } 23 }
24 24
25 // Next, get the process base address 25 // Next, get the process base address
@@ -27,19 +27,17 @@ Memory::Memory(const std::string& processName) {
27 std::vector<HMODULE> moduleList(1024); 27 std::vector<HMODULE> moduleList(1024);
28 EnumProcessModulesEx(_handle, &moduleList[0], static_cast<DWORD>(moduleList.size()), &numModules, 3); 28 EnumProcessModulesEx(_handle, &moduleList[0], static_cast<DWORD>(moduleList.size()), &numModules, 3);
29 29
30 std::string name(64, 0); 30 std::string name(64, '\0');
31 for (DWORD i = 0; i < numModules / sizeof(HMODULE); i++) { 31 for (DWORD i = 0; i < numModules / sizeof(HMODULE); i++) {
32 GetModuleBaseNameA(_handle, moduleList[i], &name[0], sizeof(name)); 32 int length = GetModuleBaseNameA(_handle, moduleList[i], &name[0], static_cast<DWORD>(name.size()));
33 33 name.resize(length);
34 // TODO: Filling with 0s still yeilds name.size() == 64... 34 if (processName == name) {
35 if (strcmp(processName.c_str(), name.c_str()) == 0) {
36 _baseAddress = (uintptr_t)moduleList[i]; 35 _baseAddress = (uintptr_t)moduleList[i];
37 break; 36 break;
38 } 37 }
39 } 38 }
40 if (_baseAddress == 0) { 39 if (_baseAddress == 0) {
41 std::cout << "Couldn't find the base process address!" << std::endl; 40 throw std::exception("Couldn't find the base process address!");
42 exit(EXIT_FAILURE);
43 } 41 }
44} 42}
45 43
@@ -47,11 +45,24 @@ Memory::~Memory() {
47 CloseHandle(_handle); 45 CloseHandle(_handle);
48} 46}
49 47
48int Memory::GetCurrentFrame()
49{
50 int SCRIPT_FRAMES;
51 if (GLOBALS == 0x5B28C0) {
52 SCRIPT_FRAMES = 0x5BE3B0;
53 } else if (GLOBALS == 0x62A080) {
54 SCRIPT_FRAMES = 0x63651C;
55 } else {
56 throw std::exception("Unknown value for Globals!");
57 }
58 return ReadData<int>({SCRIPT_FRAMES}, 1)[0];
59}
60
50void Memory::ThrowError() { 61void Memory::ThrowError() {
51 std::string message(256, '\0'); 62 std::string message(256, '\0');
52 FormatMessageA(4096, nullptr, GetLastError(), 1024, &message[0], static_cast<DWORD>(message.length()), nullptr); 63 int length = FormatMessageA(4096, nullptr, GetLastError(), 1024, &message[0], static_cast<DWORD>(message.size()), nullptr);
53 std::cout << message.c_str() << std::endl; 64 message.resize(length);
54 exit(EXIT_FAILURE); 65 throw std::exception(message.c_str());
55} 66}
56 67
57void* Memory::ComputeOffset(std::vector<int> offsets) 68void* Memory::ComputeOffset(std::vector<int> offsets)