7 bool is_valid_import_descriptor(BYTE* vBuf,
size_t vBufSize, IN
const peconv::ExportsMapper* exportsMap, IMAGE_IMPORT_DESCRIPTOR* desc)
9 if (!peconv::validate_ptr(vBuf, vBufSize, desc,
sizeof(IMAGE_IMPORT_DESCRIPTOR))) {
12 if (desc->TimeDateStamp != 0 && desc->TimeDateStamp != (-1)) {
15 char* name_ptr = (
char*)vBuf + desc->Name;
16 if (!peconv::validate_ptr(vBuf, vBufSize, name_ptr,
sizeof(
char))) {
20 if (!peconv::is_valid_import_name(vBuf, vBufSize, name_ptr))
return 0;
22 std::cout <<
"DLL: " << name_ptr <<
"\n";
25 if (desc->FirstThunk == 0 && desc->OriginalFirstThunk == 0) {
29 FIELD_T* orig_thunk_ptr = (FIELD_T*)(vBuf + desc->OriginalFirstThunk);
30 if (!peconv::validate_ptr(vBuf, vBufSize, orig_thunk_ptr,
sizeof(FIELD_T))) {
33 FIELD_T *thunk_ptr = (FIELD_T*)(vBuf + desc->FirstThunk);
34 if (!peconv::validate_ptr(vBuf, vBufSize, thunk_ptr,
sizeof(FIELD_T))) {
37 const peconv::ExportedFunc *exp = exportsMap->find_export_by_va(*thunk_ptr);
45 size_t calc_import_table_size(BYTE* vBuf,
size_t vBufSize, IN
const peconv::ExportsMapper* exportsMap, IMAGE_IMPORT_DESCRIPTOR* first_desc)
47 if (!vBuf || !exportsMap || !first_desc)
return 0;
49 IMAGE_IMPORT_DESCRIPTOR *desc =
nullptr;
50 for (desc = first_desc; ; desc++) {
51 if (!peconv::validate_ptr(vBuf, vBufSize, desc,
sizeof(IMAGE_IMPORT_DESCRIPTOR))) {
57 if (desc->FirstThunk == 0 && desc->OriginalFirstThunk == 0) {
62 size_t diff = (BYTE*)desc - (BYTE*)first_desc;
63 return diff +
sizeof(IMAGE_IMPORT_DESCRIPTOR);
67 IMAGE_IMPORT_DESCRIPTOR*
find_first_import_descriptor(BYTE* vBuf,
size_t vBufSize, IN
const peconv::ExportsMapper* exportsMap, IMAGE_IMPORT_DESCRIPTOR* found_desc)
69 if (!vBuf || !exportsMap || !found_desc)
return nullptr;
71 IMAGE_IMPORT_DESCRIPTOR *first_desc =
nullptr;
72 size_t prev_table_size = 0;
74 for (IMAGE_IMPORT_DESCRIPTOR *desc = found_desc; ; desc--) {
76 if (table_size == 0 || table_size < prev_table_size) {
79 prev_table_size = table_size;
89 IN
const peconv::ExportsMapper* exportsMap,
91 OUT
size_t &table_size,
92 IN OPTIONAL
size_t search_offset)
95 if (!vBuf || !iat_offset)
return nullptr;
96 if (search_offset > vBufSize || (vBufSize - search_offset) <
sizeof(DWORD)) {
99 size_t max_check = vBufSize -
sizeof(DWORD);
100 for (BYTE* ptr = vBuf + search_offset; ptr < vBuf + max_check; ptr++) {
101 DWORD *to_check = (DWORD*)ptr;
102 if (*to_check != iat_offset) {
105 size_t offset = (BYTE*)to_check - vBuf;
107 size_t desc_diff =
sizeof(IMAGE_IMPORT_DESCRIPTOR) -
sizeof(DWORD);
108 IMAGE_IMPORT_DESCRIPTOR *desc = (IMAGE_IMPORT_DESCRIPTOR*)((BYTE*)to_check - desc_diff);
109 if (!peconv::validate_ptr(vBuf, vBufSize, desc,
sizeof(IMAGE_IMPORT_DESCRIPTOR))) {
115 if (_table_size > 0) {
116 table_size = _table_size;
IMAGE_IMPORT_DESCRIPTOR * find_import_table_tpl(IN BYTE *vBuf, IN size_t vBufSize, IN const peconv::ExportsMapper *exportsMap, IN DWORD iat_offset, OUT size_t &table_size, IN OPTIONAL size_t search_offset)
IMAGE_IMPORT_DESCRIPTOR * find_import_table(IN bool is64bit, IN BYTE *vBuf, IN size_t vBufSize, IN const peconv::ExportsMapper *exportsMap, IN DWORD iat_offset, OUT size_t &table_size, IN OPTIONAL size_t search_offset)