-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIMemoryInterface.cpp
38 lines (30 loc) · 1.1 KB
/
IMemoryInterface.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "IMemoryInterface.h"
#include "Utils.h"
namespace Memory {
const size_t readStringBufferSize = 255;
wchar_t readStringBuffer[readStringBufferSize];
std::wstring ReadString(IMemoryInterface* pMemoryInterface, uintptr_t address, bool sanitize) {
if (!address || address < MINIMUM_ADDRESS_SIZE) {
return INVALID_ADDRESS_WSTRING;
}
int stringLength = Memory::ReadValue<int>(pMemoryInterface, address + 0x10);
if (stringLength < 0 || stringLength > 255) {
return INVALID_LENGTH_WSTRING;
}
if (stringLength == 0) {
return L"";
}
if (!pMemoryInterface->ReadRaw(address + 0x14, readStringBuffer, sizeof(wchar_t) * stringLength)) {
return NULL_WSTRING;
}
if (sanitize) {
for (int i = 0; i < stringLength; i++) {
if (!Utils::IsValidWChar(readStringBuffer[i])) {
readStringBuffer[i] = L'?';
}
}
}
readStringBuffer[stringLength] = L'\0';
return std::wstring{readStringBuffer};
}
}