10bool peconv::setup_exceptions(IN BYTE* modulePtr, IN
size_t moduleSize)
12 if (moduleSize == 0) {
17 moduleSize = img_size;
20 if (!my_dir || !my_dir->VirtualAddress || !my_dir->Size) {
23 RUNTIME_FUNCTION* exceptions_list = (RUNTIME_FUNCTION*)(my_dir->VirtualAddress + (ULONG_PTR)modulePtr);
24 if (!
validate_ptr(modulePtr, moduleSize, exceptions_list, my_dir->Size)) {
28 const size_t except_max_count = my_dir->Size /
sizeof(RUNTIME_FUNCTION);
30 std::cout <<
"[+] Found exception table of: " << std::dec << except_max_count <<
" entries\n";
33 for (i = 0; i < except_max_count; i++) {
34 RUNTIME_FUNCTION next_func = exceptions_list[i];
35 BYTE* start_ptr = next_func.BeginAddress + modulePtr;
37 size_t func_size = next_func.EndAddress - next_func.BeginAddress;
38#elif defined(_M_ARM64)
39 size_t func_size = next_func.FunctionLength;
41 if (!
validate_ptr(modulePtr, moduleSize, start_ptr, func_size)) {
46 std::cout <<
"[+] Valid exception entries: " << std::dec << i <<
" entries\n";
50 std::cerr <<
"[-] None of the exceptions was valid\n";
55 if (RtlAddFunctionTable(exceptions_list, (DWORD)i, (ULONG_PTR)modulePtr)) {
Functions related to Exceptions Table.
bool validate_ptr(IN const void *buffer_bgn, IN size_t buffer_size, IN const void *field_bgn, IN size_t field_size)
DWORD get_image_size(IN const BYTE *payload)
IMAGE_DATA_DIRECTORY * get_directory_entry(IN const BYTE *pe_buffer, IN DWORD dir_id, IN bool allow_empty=false)
Wrappers over various fields in the PE header. Read, write, parse PE headers.