打印导入表

打印这个表比较简单,看图说话水准

//打印导入表
VOID PrintImportTalbe(PVOID fileName) {
	PVOID pFileBuffer = FileToFileBuffer(fileName);
	//定位导入表
	PIMAGE_DOS_HEADER pDosHeader = pFileBuffer;
	PIMAGE_NT_HEADERS pNTHeader = (DWORD)pDosHeader + pDosHeader->e_lfanew;
	if (pNTHeader->Signature != IMAGE_NT_SIGNATURE) {
		printf("File is not PE\n");
		free(pFileBuffer);
		return FALSE;
	}
	PIMAGE_FILE_HEADER pFileHeader = &pNTHeader->FileHeader;
	PIMAGE_OPTIONAL_HEADER pOptHeader = (DWORD)pFileHeader + sizeof(IMAGE_FILE_HEADER);
	PIMAGE_SECTION_HEADER pSecHeader = (DWORD)pOptHeader + pFileHeader->SizeOfOptionalHeader;
	PIMAGE_IMPORT_DESCRIPTOR pImportTable =
		VAToFOA(pOptHeader->DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress, pFileBuffer);
	while (pImportTable->OriginalFirstThunk) {
		printf("-------------------------------------\n");
		printf("%s\n", (PBYTE)VAToFOA(pImportTable->Name,pFileBuffer));
		PDWORD pThunkData = VAToFOA(pImportTable->OriginalFirstThunk, pFileBuffer);
		while (*pThunkData) {
			if (*pThunkData) {
				if (*pThunkData & 0x80000000) {
					printf("function import by ordinals:%x\n", *pThunkData & 0x7fffffff);
				}
				else {
					printf("function import by name:");
					PIMAGE_IMPORT_BY_NAME pImportByName = VAToFOA(*pThunkData, pFileBuffer);
					printf("%s\n", pImportByName->Name);
				}
			}
			pThunkData++;
		}
		pImportTable++;
	}
	free(pFileBuffer);
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值