libPeConv
A library to load, manipulate, dump PE files.
Loading...
Searching...
No Matches
libpeconv
src
resource_util.cpp
Go to the documentation of this file.
1
#include "
peconv/resource_util.h
"
2
3
#ifdef _DEBUG
4
#include <iostream>
5
#endif
6
7
HMODULE
peconv::get_current_module_handle
()
8
{
9
HMODULE
hMod
=
NULL
;
10
GetModuleHandleExW
(
11
GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
|
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT
,
12
reinterpret_cast<
LPCWSTR
>
(&
peconv::get_current_module_handle
),
13
&
hMod
);
14
return
hMod
;
15
}
16
17
peconv::ALIGNED_BUF
peconv::load_resource_data
(
OUT
size_t
&
out_size
,
int
res_id
,
const
LPSTR
res_type
,
HMODULE
hInstance
)
18
{
19
if
(
hInstance
==
nullptr
) {
20
hInstance
=
GetModuleHandleA
(
NULL
);
21
}
22
HRSRC
res
=
FindResourceA
(
hInstance
,
MAKEINTRESOURCEA
(
res_id
),
res_type
);
23
if
(!
res
) {
24
#ifdef _DEBUG
25
std::cerr <<
"Cannot find resource"
<< std::endl;
26
#endif
27
return
nullptr
;
28
}
29
HGLOBAL
res_handle
=
LoadResource
(
hInstance
,
res
);
30
if
(
res_handle
==
nullptr
) {
31
#ifdef _DEBUG
32
std::cerr <<
"Cannot get resource handle"
<< std::endl;
33
#endif
34
return
nullptr
;
35
}
36
BYTE
*
res_data
= (
BYTE
*)
LockResource
(
res_handle
);
37
size_t
r_size
=
static_cast<
size_t
>
(
SizeofResource
(
hInstance
,
res
));
38
if
(
out_size
!= 0 &&
out_size
<=
r_size
) {
39
r_size
=
out_size
;
40
}
41
42
peconv::ALIGNED_BUF
out_buf
=
peconv::alloc_aligned
(
r_size
,
PAGE_READWRITE
);
43
if
(
out_buf
!=
nullptr
) {
44
memcpy
(
out_buf
,
res_data
,
r_size
);
45
out_size
=
r_size
;
46
}
else
{
47
out_size
= 0;
48
}
49
FreeResource
(
res_handle
);
50
return
out_buf
;
51
}
52
53
void
peconv::free_resource_data
(
peconv::ALIGNED_BUF
buffer)
54
{
55
peconv::free_aligned
(buffer);
56
}
parse_delayed_desc
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)
Definition
delayed_imports_loader.cpp:26
peconv::free_aligned
bool free_aligned(ALIGNED_BUF buffer, size_t buffer_size=0)
Definition
buffer_util.cpp:64
peconv::alloc_aligned
ALIGNED_BUF alloc_aligned(size_t buffer_size, DWORD protect, ULONGLONG desired_base=NULL)
Definition
buffer_util.cpp:56
peconv::ALIGNED_BUF
PBYTE ALIGNED_BUF
Definition
buffer_util.h:46
peconv::get_current_module_handle
HMODULE get_current_module_handle()
Definition
resource_util.cpp:7
peconv::free_resource_data
void free_resource_data(peconv::ALIGNED_BUF buffer)
Definition
resource_util.cpp:53
peconv::load_resource_data
peconv::ALIGNED_BUF load_resource_data(OUT size_t &out_size, const int res_id, const LPSTR res_type=RT_RCDATA_A, HMODULE hInstance=nullptr)
Definition
resource_util.cpp:17
resource_util.h
Functions related to manual retrieving of PE resources.
Generated on Thu Apr 11 2024 16:32:36 for libPeConv by
1.10.0