libPeConv
A library to load, manipulate, dump PE files.
Loading...
Searching...
No Matches
pe_dumper.cpp
Go to the documentation of this file.
1#include "peconv/pe_dumper.h"
2
6#include "peconv/file_util.h"
8#include "fix_dot_net_ep.h"
9
10#include <iostream>
11
12using namespace peconv;
13
25
28 IN OUT BYTE *buffer, IN size_t mod_size,
31 IN OPTIONAL const peconv::ExportsMapper* exportsMap
32)
33{
34 // if the exportsMap is supplied, attempt to recover the (destroyed) import table:
35 if (exportsMap != nullptr) {
36 if (!peconv::fix_imports(buffer, mod_size, *exportsMap, NULL)) {
37 std::cerr << "[-] Unable to fix imports!" << std::endl;
38 }
39 }
42 }
43
44 BYTE* dump_data = buffer;
45 size_t dump_size = mod_size;
46 size_t out_size = 0;
47 BYTE* unmapped_module = nullptr;
48
50 //if the image base in headers is invalid, set the current base and prevent from relocating PE:
51 if (peconv::get_image_base(buffer) == 0) {
53 }
54 if (is_dot_net(buffer, mod_size)) {
55 fix_dot_net_ep(buffer, mod_size);
56 }
59 }
62 }
63 // unmap the PE file (convert from the Virtual Format into Raw Format)
64 if (unmapped_module) {
67 }
68 }
69 // save the read module into a file
71
73 return is_dumped;
74}
bool parse_delayed_desc(BYTE *modulePtr, const size_t moduleSize, const ULONGLONG img_base, LPSTR lib_name, const T_FIELD ordinal_flag, IMAGE_DELAYLOAD_DESCRIPTOR *desc, peconv::t_function_resolver *func_resolver)
Functions related to operations on files. Wrappers for read/write.
bool fix_dot_net_ep(BYTE *pe_buffer, size_t pe_buffer_size)
Functions and classes responsible for fixing Import Table. A definition of ImportedDllCoverage class.
bool dump_to_file(IN LPCTSTR path, IN PBYTE dump_data, IN size_t dump_size)
bool is_dot_net(BYTE *pe_buffer, size_t pe_buffer_size)
bool is_pe_raw(IN const BYTE *pe_buffer, IN size_t pe_size)
bool update_image_base(IN OUT BYTE *payload, IN ULONGLONG destImageBase)
bool fix_imports(IN OUT PVOID modulePtr, IN size_t moduleSize, IN const peconv::ExportsMapper &exportsMap, OUT OPTIONAL peconv::ImpsNotCovered *notCovered)
ULONGLONG get_image_base(IN const BYTE *pe_buffer)
BYTE * pe_virtual_to_raw(IN BYTE *payload, IN size_t in_size, IN ULONGLONG loadBase, OUT size_t &outputSize, IN OPTIONAL bool rebuffer=true)
t_pe_dump_mode
Definition pe_dumper.h:16
@ PE_DUMP_REALIGN
Definition pe_dumper.h:20
@ PE_DUMP_MODES_COUNT
Definition pe_dumper.h:21
@ PE_DUMP_UNMAP
Definition pe_dumper.h:19
@ PE_DUMP_AUTO
Definition pe_dumper.h:17
@ PE_DUMP_VIRTUAL
Definition pe_dumper.h:18
bool free_pe_buffer(ALIGNED_BUF buffer, size_t buffer_size=0)
t_pe_dump_mode detect_dump_mode(IN const BYTE *buffer, IN size_t buffer_size)
Definition pe_dumper.cpp:14
bool is_pe_expanded(IN const BYTE *pe_buffer, IN size_t pe_size)
bool dump_pe(IN LPCTSTR outputFilePath, IN OUT BYTE *buffer, IN size_t buffer_size, IN const ULONGLONG module_base, IN OUT t_pe_dump_mode &dump_mode, IN OPTIONAL const peconv::ExportsMapper *exportsMap=nullptr)
Definition pe_dumper.cpp:26
BYTE * pe_realign_raw_to_virtual(IN const BYTE *payload, IN size_t in_size, IN ULONGLONG loadBase, OUT size_t &outputSize)
Dumping PE from the memory buffer into a file.
Wrappers over various fields in the PE header. Read, write, parse PE headers.
Detecting in which mode is the PE in the supplied buffer (i.e. raw, virtual). Analyzes PE features ty...
Converting PE from virtual to raw format.