-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmemory.hpp
More file actions
47 lines (36 loc) · 968 Bytes
/
Copy pathmemory.hpp
File metadata and controls
47 lines (36 loc) · 968 Bytes
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
#ifndef MEMORY_HPP
#define MEMORY_HPP
#include <string>
#include <fstream>
#include <sstream>
#include "print.hpp"
static void* get_module_base_address(std::string module_name) {
std::ifstream file;
file.open("/proc/self/maps");
bool found = false;
std::string line;
std::string concat_line;
while (std::getline(file, line)) {
for (int i = 0; i < line.length(); i++) {
concat_line = "";
for (int h = 0; i+h < line.length() && h < module_name.length(); h++) {
concat_line += line[i+h];
}
if (concat_line == module_name) { found = true; break; }
}
if (found == true) {break;}
}
concat_line = "";
for (int i = 0; i <= line.length(); i++) {
if (line[i] == '-') { break; }
concat_line += line[i];
}
// Use stringstream for conversion
std::stringstream ss;
ss << std::hex << "0x"+concat_line;
// Store the result
unsigned long result;
ss >> result;
return (void*)result;
}
#endif