libPeConv
A library to load, manipulate, dump PE files.
Loading...
Searching...
No Matches
imports_loader.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <windows.h>
9#include <set>
10
11#include "pe_hdrs_helper.h"
12#include "function_resolver.h"
13#include "exports_mapper.h"
14
15namespace peconv {
16
21 {
22 public:
23 ImportThunksCallback(BYTE* _modulePtr, size_t _moduleSize)
24 : modulePtr(_modulePtr), moduleSize(_moduleSize)
25 {
26 this->is64b = is64bit((BYTE*)modulePtr);
27 }
28
30
38 virtual bool processThunks(LPSTR libName, ULONG_PTR origFirstThunkPtr, ULONG_PTR firstThunkPtr) = 0;
39
40 protected:
41 BYTE* modulePtr;
42 size_t moduleSize;
43 bool is64b;
44 };
45
46 //--
48 public:
50
52 {
53 clear();
54 }
55
56 void clear()
57 {
58 std::map<DWORD, peconv::ExportedFunc*>::iterator it;
59 for (it = thunkToFunc.begin(); it != thunkToFunc.end(); ++it) {
60 delete it->second;
61 }
62 thunkToFunc.clear();
63 }
64
65 size_t size() const
66 {
67 return thunkToFunc.size();
68 }
69
70 public:
71 std::map<DWORD, peconv::ExportedFunc*> thunkToFunc;
72
73 private:
74 // not implemented: no copying of the structure allowed
76 ImportsCollection& operator=(const ImportsCollection&);
77 };
78
79
87 bool process_import_table(IN BYTE* modulePtr, IN SIZE_T moduleSize, IN ImportThunksCallback *callback);
88
95 bool load_imports(BYTE* modulePtr, t_function_resolver* func_resolver=nullptr);
96
100 bool has_valid_import_table(const PBYTE modulePtr, size_t moduleSize, size_t max_count = 0);
101
106 bool is_valid_import_name(const PBYTE modulePtr, const size_t moduleSize, LPSTR lib_name);
107
111 bool collect_thunks(IN BYTE* modulePtr, IN SIZE_T moduleSize, OUT std::set<DWORD>& thunk_rvas);
112
113 bool collect_imports(IN BYTE* modulePtr, IN SIZE_T moduleSize, OUT ImportsCollection &collection);
114
115}; // namespace peconv
virtual bool processThunks(LPSTR libName, ULONG_PTR origFirstThunkPtr, ULONG_PTR firstThunkPtr)=0
ImportThunksCallback(BYTE *_modulePtr, size_t _moduleSize)
std::map< DWORD, peconv::ExportedFunc * > thunkToFunc
A definition of ExportsMapper class. Creates a lookup of all the exported functions from the supplied...
Definitions of basic Imports Resolver classes. They can be used for filling imports when the PE is lo...
bool has_valid_import_table(const PBYTE modulePtr, size_t moduleSize, size_t max_count=0)
bool process_import_table(IN BYTE *modulePtr, IN SIZE_T moduleSize, IN ImportThunksCallback *callback)
bool collect_thunks(IN BYTE *modulePtr, IN SIZE_T moduleSize, OUT std::set< DWORD > &thunk_rvas)
bool is64bit(IN const BYTE *pe_buffer)
bool is_valid_import_name(const PBYTE modulePtr, const size_t moduleSize, LPSTR lib_name)
bool collect_imports(IN BYTE *modulePtr, IN SIZE_T moduleSize, OUT ImportsCollection &collection)
bool load_imports(BYTE *modulePtr, t_function_resolver *func_resolver=nullptr)
Wrappers over various fields in the PE header. Read, write, parse PE headers.