forked from samjviana/souls_vision
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory.cpp
More file actions
92 lines (74 loc) · 2.38 KB
/
Copy pathmemory.cpp
File metadata and controls
92 lines (74 loc) · 2.38 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//
// Created by PC-SAMUEL on 22/11/2024.
//
#include "memory.h"
#include <vector>
#include <sstream>
#include <psapi.h>
#include <cstdint>
#include <iostream>
#include <iomanip>
namespace souls_vision {
uintptr_t Memory::SignatureScan(const std::string& signature, const std::string& moduleName) {
HMODULE hModule = GetModuleHandleA(moduleName.c_str());
if (!hModule) {
return 0;
}
MODULEINFO modInfo = { 0 };
if (!GetModuleInformation(GetCurrentProcess(), hModule, &modInfo, sizeof(MODULEINFO))) {
return 0;
}
auto startAddress = reinterpret_cast<uintptr_t>(modInfo.lpBaseOfDll);
DWORD moduleSize = modInfo.SizeOfImage;
std::vector<uint8_t> patternBytes;
std::vector<bool> patternMask;
std::istringstream iss(signature);
std::string token;
while (iss >> token) {
if (token == "?" || token == "??") {
patternBytes.push_back(0);
patternMask.push_back(false);
} else {
patternBytes.push_back(static_cast<uint8_t>(std::stoul(token, nullptr, 16)));
patternMask.push_back(true);
}
}
size_t patternLength = patternBytes.size();
for (uintptr_t i = startAddress; i <= startAddress + moduleSize - patternLength; ++i) {
bool found = true;
for (size_t j = 0; j < patternLength; ++j) {
if (patternMask[j] && *(uint8_t*)(i + j) != patternBytes[j]) {
found = false;
break;
}
}
if (found) {
return i;
}
}
return 0;
}
uintptr_t Memory::DereferenceAddress(uintptr_t address) {
address += 3;
int offset = *reinterpret_cast<int*>(address);
address += offset + 4;
address = *reinterpret_cast<uintptr_t*>(address);
return address;
}
void Memory::PrintMemoryBytes(uintptr_t address, size_t size) {
auto ptr = reinterpret_cast<unsigned char*>(address);
std::cout << "0x" << std::hex << address << std::dec << ": " << std::endl;
for (size_t i = 0; i < size; ++i) {
std::cout << "\t" << std::setw(2) << std::setfill('0') << std::hex << static_cast<int>(ptr[i]) << " ";
if ((i + 1) % 8 == 0) {
std::cout << std::endl;
}
}
std::cout << std::endl;
}
std::string Memory::ToString(uintptr_t address) {
std::stringstream ss;
ss << std::hex << address;
return ss.str();
}
} // souls_vision