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 "function_resolver.h"
10
11#include <iostream>
12#include <string>
13#include <map>
14#include "peconv/buffer_util.h"
15
16namespace peconv {
17
22 public:
27 : buffer(nullptr), bufferSize(0), sourcePtr(nullptr)
28 {
29 }
30
33 }
34
39 {
40 if (buffer) {
41 delete[] buffer;
42 bufferSize = 0;
43 sourcePtr = nullptr;
44 }
45 }
46
50 bool makeBackup(BYTE *patch_ptr, size_t patch_size);
51
55 bool applyBackup();
56
60 bool isBackup()
61 {
62 return buffer != nullptr;
63 }
64
65 protected:
66 BYTE *buffer;
67 size_t bufferSize;
68
69 BYTE *sourcePtr;
70 };
71
72
77 public:
83 void add_hook(const std::string &name, FARPROC function)
84 {
85 hooks_map[name] = function;
86 }
87
93 void replace_dll(std::string dll_name, const std::string &new_dll)
94 {
95 dll_replacements_map[dll_name] = new_dll;
96 }
97
104 virtual FARPROC resolve_func(LPCSTR lib_name, LPCSTR func_name);
105
106 private:
107 std::map<std::string, FARPROC> hooks_map;
108 std::map<std::string, std::string> dll_replacements_map;
109 };
110
119 size_t redirect_to_local64(void *ptr, ULONGLONG new_offset, PatchBackup* backup = nullptr);
120
129 size_t redirect_to_local32(void *ptr, DWORD new_offset, PatchBackup* backup = nullptr);
130
139 size_t redirect_to_local(void *ptr, void* new_function_ptr, PatchBackup* backup = nullptr);
140
144 bool replace_target(BYTE *ptr, ULONGLONG dest_addr);
145
146};//namespace peconv
Definitions of the used buffer types. Functions for their allocation and deallocation.
size_t bufferSize
Definition hooks.h:67
BYTE * sourcePtr
Definition hooks.h:69
void deleteBackup()
Definition hooks.h:38
bool makeBackup(BYTE *patch_ptr, size_t patch_size)
Definition hooks.cpp:50
bool isBackup()
Definition hooks.h:60
void add_hook(const std::string &name, FARPROC function)
Definition hooks.h:83
virtual FARPROC resolve_func(LPCSTR lib_name, LPCSTR func_name)
Definition hooks.cpp:81
void replace_dll(std::string dll_name, const std::string &new_dll)
Definition hooks.h:93
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:210
size_t redirect_to_local32(void *ptr, DWORD new_offset, PatchBackup *backup=nullptr)
Definition hooks.cpp:142
size_t redirect_to_local64(void *ptr, ULONGLONG new_offset, PatchBackup *backup=nullptr)
Definition hooks.cpp:107
size_t redirect_to_local(void *ptr, void *new_function_ptr, PatchBackup *backup=nullptr)
Definition hooks.cpp:177