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_reconstructor.h
Go to the documentation of this file.
1#pragma once
2
3#include <windows.h>
4#include <psapi.h>
5#include <map>
6#include <peconv.h>
7
8#include "pe_buffer.h"
10
11namespace pesieve {
12
13 template <typename IMAGE_OPTIONAL_HEADER_T>
14 bool overwrite_opt_hdr(BYTE* vBuf, size_t vBufSize, IMAGE_OPTIONAL_HEADER_T* opt_hdr_ptr, PeArtefacts &artefacts)
15 {
16#ifdef _DEBUG
17 std::cout << "Trying to overwrite the optional header\n";
18#endif
19 if (!vBuf || !opt_hdr_ptr) return false;
20 if (!peconv::validate_ptr(vBuf, vBufSize, opt_hdr_ptr, sizeof(IMAGE_OPTIONAL_HEADER_T))) {
21 return false;
22 }
23 if (artefacts.is64bit) {
25 }
26 else {
28 }
29 //set typical values for the fields that has been erased:
30 if (opt_hdr_ptr->SectionAlignment == 0) {
31 opt_hdr_ptr->SectionAlignment = PAGE_SIZE;
32 }
33 if (opt_hdr_ptr->FileAlignment == 0) {
34 opt_hdr_ptr->FileAlignment = 0x200; // typical file alignment
35 }
36 if (opt_hdr_ptr->SizeOfHeaders == 0) {
37 opt_hdr_ptr->SizeOfHeaders = 0x400; //typical header size
38 }
39 if (opt_hdr_ptr->SizeOfImage < artefacts.calculatedImgSize) {
40 opt_hdr_ptr->SizeOfImage = MASK_TO_DWORD(artefacts.calculatedImgSize);
41 }
42 return true;
43 }
44
46 public:
51
52 bool reconstruct();
53
54 protected:
55 bool reconstructFileHdr();
56 bool reconstructPeHdr();
57 bool fixSectionsVirtualSize(HANDLE processHandle);
58 bool fixSectionsCharacteristics(HANDLE processHandle);
59
60 size_t shiftPeHeader();
61
65 };
66
67}; //mamespace pesieve
68
A report about the PE artefact detected in the workingset.
PeReconstructor(PeArtefacts _artefacts, PeBuffer &_peBuffer)
bool fixSectionsVirtualSize(HANDLE processHandle)
bool fixSectionsCharacteristics(HANDLE processHandle)
const PeArtefacts origArtefacts
#define MASK_TO_DWORD(val)
Definition iat_finder.h:9
bool overwrite_opt_hdr(BYTE *vBuf, size_t vBufSize, IMAGE_OPTIONAL_HEADER_T *opt_hdr_ptr, PeArtefacts &artefacts)
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
#define PAGE_SIZE