libPeConv
A library to load, manipulate, dump PE files.
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(std::string name, FARPROC function)
84 {
85 hooks_map[name] = function;
86 }
87
94 virtual FARPROC resolve_func(LPSTR lib_name, LPSTR func_name);
95
96 private:
97 std::map<std::string, FARPROC> hooks_map;
98 };
99
108 size_t redirect_to_local64(void *ptr, ULONGLONG new_offset, PatchBackup* backup = nullptr);
109
118 size_t redirect_to_local32(void *ptr, DWORD new_offset, PatchBackup* backup = nullptr);
119
128 size_t redirect_to_local(void *ptr, void* new_function_ptr, PatchBackup* backup = nullptr);
129
133 bool replace_target(BYTE *ptr, ULONGLONG dest_addr);
134
135};//namespace peconv
Definitions of the used buffer types. Functions for their allocation and deallocation.
size_t bufferSize
Definition: hooks.h:67
bool applyBackup()
Definition: hooks.cpp:64
BYTE * sourcePtr
Definition: hooks.h:69
BYTE * buffer
Definition: hooks.h:66
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(std::string name, FARPROC function)
Definition: hooks.h:83
virtual FARPROC resolve_func(LPSTR lib_name, LPSTR func_name)
Definition: hooks.cpp:81
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:200
size_t redirect_to_local32(void *ptr, DWORD new_offset, PatchBackup *backup=nullptr)
Definition: hooks.cpp:132
size_t redirect_to_local64(void *ptr, ULONGLONG new_offset, PatchBackup *backup=nullptr)
Definition: hooks.cpp:97
size_t redirect_to_local(void *ptr, void *new_function_ptr, PatchBackup *backup=nullptr)
Definition: hooks.cpp:167