1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| void PrintExportTable(char* buffer) { PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)buffer; PIMAGE_NT_HEADERS pNtHeader = (PIMAGE_NT_HEADERS)(pDosHeader->e_lfanew + buffer); PIMAGE_DATA_DIRECTORY pDataDir = (PIMAGE_DATA_DIRECTORY)(pNtHeader->OptionalHeader.DataDirectory + IMAGE_DIRECTORY_ENTRY_EXPORT); PIMAGE_EXPORT_DIRECTORY pExport = (PIMAGE_EXPORT_DIRECTORY)(RVAToFOA(pDataDir->VirtualAddress, buffer) + buffer); if (pExport->AddressFunctions == 0) { printf("当前没有导出表!\n"); return; } char* szDllName = (char*)(RVAToFOA(pExport->Name, buffer) + buffer); printf("DllName: %s\n", DllName); printf("Base: %#08x\n", pExport->Base); printf("NumberOfFunctions: %#08x\n", pExport->NumberOfFunctions); printf("NumberOfNames: %#08x\n", pExport->NumberOfNames); printf("AddressOfFunctions: %#08x\n", pExport->AddressOfFunctions); printf("AddressOfNames: %#08x\n", pExport->AddressOfNames); printf("AddressOfNameOrdinals: %#08x\n", pExport->AddressOfNameOrdinals); DWORD dwNumberOfFunctions = pExport->NumberOfFunctions; DWORD dwNumberOfNames = pExport->NumberOfNames; DWORD dwBase = pExport->Base; PDWORD pExportAddrTable = (PDWORD)(RVAToFOA(pExport->AddressOfFunctions, buffer) + buffer); PDWORD pExportNameTable = (PDWORD)(RVAToFOA(pExport->AddressOfNames, buffer) + buffer); PWORD pExportIdTable = (PWORD)(RVAToFOA(pExport->AddressOfNameOrdinals, buffer) + buffer); for(int i = 0; i < dwNumberOfFunctions; i++) { if(pExportAddrTable[i] == i) { continue; } DWORD id = 0; for (; id < dwNumberOfNames; id++) { if(pExportIdTable[i] == id) { break; } } if (id == dwNumberOfNames) { printf("ID: %x Address: %#08x Name[NULL]\n", i + dwBase, pExportAddrTable[i]); } else { char* szFunName = (char*)(RVAToFileOffset(pExportNameTable[id], buffer) + buffer); printf("ID: %x Address: %#08x Name[%s]\n", i + dwBase, pExportAddrTable[i], szFunName); } } }
|