-
Notifications
You must be signed in to change notification settings - Fork 6
/
windows_library.h
44 lines (39 loc) · 1.46 KB
/
windows_library.h
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
#pragma once
#include "windows_api.h"
#include <string>
#include <unordered_map>
class MappedMemory {
public:
MappedMemory(void* mapping, size_t size);
MappedMemory(const MappedMemory&) = delete;
MappedMemory(MappedMemory&& other);
MappedMemory& operator=(const MappedMemory&) = delete;
MappedMemory& operator=(MappedMemory&&) = delete;
~MappedMemory();
operator uint8_t* () const { return reinterpret_cast<uint8_t*>(m_mapping); }
operator void* () const { return reinterpret_cast<void*>(m_mapping); }
void* ptr() const { return reinterpret_cast<void*>(m_mapping); }
size_t size() const { return m_size; }
private:
void* m_mapping;
size_t m_size;
};
typedef BOOL(WINAPI* tEntryPoint)(void* hinstDLL, DWORD fdwReason, void* lpReserved);
class WindowsLibrary {
public:
WindowsLibrary(MappedMemory&& mapping, std::unordered_map<std::string, void*>&& exports, tEntryPoint entryPoint);
WindowsLibrary(const WindowsLibrary&) = delete;
WindowsLibrary(WindowsLibrary&& other);
WindowsLibrary& operator=(const WindowsLibrary&) = delete;
WindowsLibrary& operator=(WindowsLibrary&&) = delete;
~WindowsLibrary();
void* GetExport(const std::string& exportName);
void* GetBaseAddress();
static void SetupCall();
static WindowsLibrary Load(const char* path);
private:
MappedMemory m_mapping;
std::unordered_map<std::string, void*> m_exports;
tEntryPoint m_entryPoint;
static __thread TIB s_tib;
};