| 19 | static std::vector<PFNGETACTIVATIONFACTORY> g_RoEntryPoints; |
| 20 | |
| 21 | HRESULT XWineGetImport(_In_opt_ HMODULE Module, _In_ HMODULE ImportModule, _In_ LPCSTR Import, |
| 22 | _Out_ PIMAGE_THUNK_DATA *pThunk) |
| 23 | { |
| 24 | importProcedure: |
| 25 | if (ImportModule == nullptr) |
| 26 | return E_INVALIDARG; |
| 27 | |
| 28 | if (pThunk == nullptr) |
| 29 | return E_POINTER; |
| 30 | |
| 31 | if (Module == nullptr) |
| 32 | Module = GetModuleHandleW(nullptr); |
| 33 | |
| 34 | auto dosHeader = (PIMAGE_DOS_HEADER)Module; |
| 35 | auto ntHeaders = (PIMAGE_NT_HEADERS)((PBYTE)Module + dosHeader->e_lfanew); |
| 36 | auto directory = &ntHeaders->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT]; |
| 37 | |
| 38 | if (directory->VirtualAddress == 0) |
| 39 | return E_FAIL; |
| 40 | |
| 41 | auto peImports = (PIMAGE_IMPORT_DESCRIPTOR)((PBYTE)Module + directory->VirtualAddress); |
| 42 | |
| 43 | for (size_t i = 0; peImports[i].Name; i++) |
| 44 | { |
| 45 | if (GetModuleHandleA((LPCSTR)((PBYTE)Module + peImports[i].Name)) != ImportModule) |
| 46 | continue; |
| 47 | |
| 48 | auto iatThunks = (PIMAGE_THUNK_DATA)((PBYTE)Module + peImports[i].FirstThunk); |
| 49 | auto intThunks = (PIMAGE_THUNK_DATA)((PBYTE)Module + peImports[i].OriginalFirstThunk); |
| 50 | |
| 51 | for (size_t j = 0; intThunks[j].u1.AddressOfData; j++) |
| 52 | { |
| 53 | if ((intThunks[j].u1.AddressOfData & IMAGE_ORDINAL_FLAG) != 0) |
| 54 | { |
| 55 | if (!IS_INTRESOURCE(Import)) |
| 56 | continue; |
| 57 | |
| 58 | if (((intThunks[j].u1.Ordinal & ~IMAGE_ORDINAL_FLAG) == (ULONG_PTR)Import)) |
| 59 | { |
| 60 | *pThunk = &iatThunks[j]; |
| 61 | return S_OK; |
| 62 | } |
| 63 | |
| 64 | continue; |
| 65 | } |
| 66 | |
| 67 | if (strcmp(((PIMAGE_IMPORT_BY_NAME)((PBYTE)Module + intThunks[j].u1.AddressOfData))->Name, Import)) |
| 68 | continue; |
| 69 | |
| 70 | *pThunk = &iatThunks[j]; |
| 71 | return S_OK; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | //Rodrigo Todescatto: I did this masterpiece. It looks awful, yet works perfectly. Never mess with something if it works. |
| 76 | if (ImportModule == GetModuleHandleW(L"vccorlib110.dll")) |
| 77 | { |
| 78 | ImportModule = GetModuleHandleW(L"vccorlib120.dll"); |
no outgoing calls
no test coverage detected