libPeConv
A library to load, manipulate, dump PE files.
Loading...
Searching...
No Matches
hooks.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <windows.h>
9#include <iostream>
10#include <string>
11#include <map>
12
14#include <peconv/buffer_util.h>
15
16namespace peconv {
17
22 public:
27 : buffer(nullptr), bufferSize(0), sourcePtr(nullptr)
28 {
29 }
30
32 {
34 }
35
40 {
41 if (buffer) {
42 delete[] buffer;
43 buffer = nullptr;
44 bufferSize = 0;
45 sourcePtr = nullptr;
46 }
47 }
48
52 bool makeBackup(BYTE *patch_ptr, size_t patch_size);
53
57 bool applyBackup();
58
62 bool isBackup()
63 {
64 return buffer != nullptr;
65 }
66
67 protected:
68 BYTE *buffer;
69 size_t bufferSize;
70 BYTE *sourcePtr;
71
72 private:
73 // not implemented: no copying of the structure allowed
75 PatchBackup& operator=(const PatchBackup&);
76 };
77
78
83 public:
89 void add_hook(const std::string &name, FARPROC function)
90 {
91 hooks_map[name] = function;
92 }
93
99 void replace_dll(std::string dll_name, std::string new_dll);
100
107 virtual FARPROC resolve_func(LPCSTR lib_name, LPCSTR func_name);
108
109 private:
110 std::map<std::string, FARPROC> hooks_map;
111 std::map<std::string, std::string> dll_replacements_map;
112 };
113
122 size_t redirect_to_local64(void *ptr, ULONGLONG new_offset, PatchBackup* backup = nullptr);
123
132 size_t redirect_to_local32(void *ptr, DWORD new_offset, PatchBackup* backup = nullptr);
133
142 size_t redirect_to_local(void *ptr, void* new_function_ptr, PatchBackup* backup = nullptr);
143
147 bool replace_target(BYTE *ptr, ULONGLONG dest_addr);
148
149};//namespace peconv
Definitions of the used buffer types. Functions for their allocation and deallocation.
size_t bufferSize
Definition: hooks.h:69
bool applyBackup()
Definition: hooks.cpp:70
BYTE * sourcePtr
Definition: hooks.h:70
BYTE * buffer
Definition: hooks.h:68
void deleteBackup()
Definition: hooks.h:39
bool makeBackup(BYTE *patch_ptr, size_t patch_size)
Definition: hooks.cpp:56
bool isBackup()
Definition: hooks.h:62
void replace_dll(std::string dll_name, std::string new_dll)
Definition: hooks.cpp:89
void add_hook(const std::string &name, FARPROC function)
Definition: hooks.h:89
virtual FARPROC resolve_func(LPCSTR lib_name, LPCSTR func_name)
Definition: hooks.cpp:96
Definitions of basic Imports Resolver classes. They can be used for filling imports when the PE is lo...
bool replace_target(BYTE *ptr, ULONGLONG dest_addr)
Definition: hooks.cpp:226
size_t redirect_to_local32(void *ptr, DWORD new_offset, PatchBackup *backup=nullptr)
Definition: hooks.cpp:156
size_t redirect_to_local64(void *ptr, ULONGLONG new_offset, PatchBackup *backup=nullptr)
Definition: hooks.cpp:119
size_t redirect_to_local(void *ptr, void *new_function_ptr, PatchBackup *backup=nullptr)
Definition: hooks.cpp:193