PE-sieve
Scans all running processes. Recognizes and dumps a variety of potentially malicious implants (replaced/implanted PEs, shellcodes, hooks, in-memory patches).
Loading...
Searching...
No Matches
pe_buffer.h
Go to the documentation of this file.
1#pragma once
2
3#include <peconv.h>
5
6namespace pesieve {
7
8 class PeBuffer {
9 public:
15
17 {
18 freeBuffer();
19 }
20
21 bool isFilled()
22 {
23 return (vBuf && vBufSize > 0);
24 }
25
26 bool isValidPe()
27 {
28 if (!vBuf) return false;
29 if (peconv::get_nt_hdrs(vBuf, vBufSize)) {
30 return true;
31 }
32 return false;
33 }
34
35 bool isCode();
36
37 // Returns the size of the internal buffer
38 size_t getBufferSize() const
39 {
40 return vBufSize;
41 }
42
43 // Reads content from the remote process into a buffer. Automatically allocates sutiable buffer.
45
46 // Fill the content from the cached buffer.
48
49 // Resizes internal buffer into a new size.
50 // The internal buffer must be non empty.
51 bool resizeBuffer(size_t new_size);
52
53 // Requires the internal buffer to contain a valid PE. Resizes the last section of the PE, to make it fit the new Image Size.
54 // The internal buffer must be non empty, and not smaller than the new Image Size.
56
57 // Requires the internal buffer to contain a valid PE.
58 // Dumps the PE into a file with a given name.
59 bool dumpPeToFile(IN std::string dumpFileName,
60 IN OUT peconv::t_pe_dump_mode &dumpMode,
61 IN OPTIONAL const peconv::ExportsMapper* exportsMap = NULL,
62 OUT OPTIONAL peconv::ImpsNotCovered *notCovered = NULL
63 );
64
65 bool dumpToFile(IN std::string dumpFileName);
66
68 {
69 return moduleBase;
70 }
71
73 {
74 return relocBase;
75 }
76
81
82 protected:
84
86
87 bool allocBuffer(const size_t pe_vsize)
88 {
89 freeBuffer();
90 vBuf = peconv::alloc_aligned(pe_vsize, PAGE_READWRITE);
91 if (!vBuf) {
92 return false;
93 }
95 return true;
96 }
97
99 {
100 peconv::free_aligned(vBuf);
101 vBuf = nullptr;
102 vBufSize = 0;
103 }
104
106 bool isRefl;
108 size_t vBufSize;
111
112 friend class ImpReconstructor;
113 friend class PeReconstructor;
114 };
115
116}; //namespace pesieve
void setRelocBase(ULONGLONG reloc_base)
Definition pe_buffer.h:77
bool fillFromBuffer(ULONGLONG module_base, util::ByteBuffer &data_cache)
Definition pe_buffer.cpp:42
size_t calcRemoteImgSize(ULONGLONG module_base) const
Definition pe_buffer.cpp:7
ULONGLONG moduleBase
Definition pe_buffer.h:109
size_t getBufferSize() const
Definition pe_buffer.h:38
bool allocBuffer(const size_t pe_vsize)
Definition pe_buffer.h:87
PeBuffer(HANDLE _process_hndl, bool _is_refl)
Definition pe_buffer.h:10
bool _readRemote(ULONGLONG module_base, size_t pe_vsize)
Definition pe_buffer.cpp:58
bool readRemote(ULONGLONG module_base, size_t pe_vsize)
Definition pe_buffer.cpp:27
bool dumpPeToFile(IN std::string dumpFileName, IN OUT peconv::t_pe_dump_mode &dumpMode, IN OPTIONAL const peconv::ExportsMapper *exportsMap=NULL, OUT OPTIONAL peconv::ImpsNotCovered *notCovered=NULL)
ULONGLONG getModuleBase() const
Definition pe_buffer.h:67
bool resizeLastSection(size_t new_img_size)
Definition pe_buffer.cpp:99
bool resizeBuffer(size_t new_size)
Definition pe_buffer.cpp:81
ULONGLONG getRelocBase() const
Definition pe_buffer.h:72
ULONGLONG relocBase
Definition pe_buffer.h:110
bool dumpToFile(IN std::string dumpFileName)
size_t fill_iat(BYTE *vBuf, size_t vBufSize, IN const peconv::ExportsMapper *exportsMap, IN OUT IATBlock &iat, IN ThunkFoundCallback *callback)
Definition iat_finder.h:31