-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathExeFile.cpp
More file actions
54 lines (45 loc) · 1.06 KB
/
Copy pathExeFile.cpp
File metadata and controls
54 lines (45 loc) · 1.06 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
#include "hacklib/ExeFile.h"
#include <algorithm>
#include <fstream>
bool hl::ExeFile::loadFromFile(const std::string& path)
{
std::ifstream file(path, std::ios::binary | std::ios::ate);
const size_t size = (size_t)file.tellg();
file.seekg(0, std::ios::beg);
if (size == (size_t)-1)
{
return false;
}
std::vector<char> buf(size);
if (file.read(buf.data(), static_cast<std::streamsize>(size)))
{
return loadFromMem((uintptr_t)buf.data());
}
return false;
}
bool hl::ExeFile::hasRelocs() const
{
if (!m_valid)
{
throw std::runtime_error("no exe file loaded");
}
return !m_relocs.empty();
}
bool hl::ExeFile::isReloc(uintptr_t rva) const
{
if (!m_valid)
{
throw std::runtime_error("no exe file loaded");
}
auto it = std::ranges::find(m_relocs, rva);
return it != m_relocs.end();
}
uintptr_t hl::ExeFile::getExport(const std::string& name) const
{
auto it = m_exports.find(name);
if (it != m_exports.end())
{
return it->second;
}
return 0;
}