diff --git a/src/uimports.cpp b/src/uimports.cpp index 4b981a28..9f89c6fc 100644 --- a/src/uimports.cpp +++ b/src/uimports.cpp @@ -106,6 +106,34 @@ static BOOL UPDATE_IMPORTS_XX(HANDLE hProcess, } } + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //Added code + if (inh.IMPORT_DIRECTORY.VirtualAddress!=NULL && inh.IMPORT_DIRECTORY.Size==0) + { + //Don't worry about changing the PE file, because the load information of the original PE header has been saved and will be restored. The change here is just for the following code to work normally + PIMAGE_IMPORT_DESCRIPTOR pImageImport=(PIMAGE_IMPORT_DESCRIPTOR)(pbModule+inh.IMPORT_DIRECTORY.VirtualAddress); + IMAGE_IMPORT_DESCRIPTOR ImageImport; + + if(!ReadProcessMemory(hProcess,pImageImport,&ImageImport,sizeof(ImageImport),NULL)) + { + _Analysis_assume_(FALSE); + goto finish; + } + while(ImageImport.Name) + { + inh.IMPORT_DIRECTORY.Size+=sizeof(IMAGE_IMPORT_DESCRIPTOR); + if(!ReadProcessMemory(hProcess,pImageImport,&ImageImport,sizeof(ImageImport),NULL)) + { + _Analysis_assume_(FALSE); + goto finish; + } + ++pImageImport; + } + OutputDebugString(TEXT("[This PE file has an import table, but the import table size is marked as 0. This is an error.") + TEXT("Not repair will cause the launched program to not work normally, and its import table size has been automatically repaired for you! ! !]\r\n")); + } + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + DETOUR_TRACE((" Imports: %p..%p\n", (DWORD_PTR)pbModule + inh.IMPORT_DIRECTORY.VirtualAddress, (DWORD_PTR)pbModule + inh.IMPORT_DIRECTORY.VirtualAddress +