libPeConv
A library to load, manipulate, dump PE files.
Loading...
Searching...
No Matches
util.h
Go to the documentation of this file.
1
6#pragma once
7
8#include "file_util.h"
9#include "resource_util.h"
10
11#ifdef _MSC_VER
12#define PECONV_FORCEINLINE __forceinline
13#define PECONV_TRY_EXCEPT_BLOCK_START __try {
14#define PECONV_TRY_EXCEPT_BLOCK_END __except (EXCEPTION_EXECUTE_HANDLER) {
15#else
16#define PECONV_FORCEINLINE __attribute__((always_inline)) inline
17#define PECONV_TRY_EXCEPT_BLOCK_START try {
18#define PECONV_TRY_EXCEPT_BLOCK_END catch (...) {
19#endif
20
21
22namespace peconv {
29 bool is_padding(const BYTE* cave_ptr, size_t cave_size, const BYTE padding_char);
30
34 DWORD get_process_id(HANDLE hProcess);
35
43 bool is_mem_accessible(LPCVOID areaStart, SIZE_T areaSize, DWORD accessRights);
44
50 bool is_bad_read_ptr(LPCVOID areaStart, SIZE_T areaSize);
51
55 template <typename CHAR_T>
56 bool is_valid_string(LPVOID modulePtr, const size_t moduleSize, const CHAR_T* name_ptr, const size_t max_len = 260)
57 {
58 bool is_terminated = false;
59 size_t i = 0;
60 for (; i < max_len; i++) {
61 if (!peconv::validate_ptr(modulePtr, moduleSize, &name_ptr[i], sizeof(CHAR_T))) {
62 return false;
63 }
64 if (name_ptr[i] == 0) {
65 is_terminated = true;
66 break;
67 }
68 }
69 return is_terminated && (i != 0);
70 }
71};
Functions related to operations on files. Wrappers for read/write.
DWORD get_process_id(HANDLE hProcess)
Definition: util.cpp:82
bool is_valid_string(LPVOID modulePtr, const size_t moduleSize, const CHAR_T *name_ptr, const size_t max_len=260)
Definition: util.h:56
bool is_mem_accessible(LPCVOID areaStart, SIZE_T areaSize, DWORD accessRights)
Definition: util.cpp:116
bool validate_ptr(IN const void *buffer_bgn, IN size_t buffer_size, IN const void *field_bgn, IN size_t field_size)
Definition: buffer_util.cpp:9
bool is_padding(const BYTE *cave_ptr, size_t cave_size, const BYTE padding_char)
Definition: util.cpp:106
bool is_bad_read_ptr(LPCVOID areaStart, SIZE_T areaSize)
Definition: util.cpp:156
Functions related to manual retrieving of PE resources.