移动导出表,重定位表,手动修复重定位表

要写这几个函数会频繁用到FOA转VA

//文件里的偏移转化为内存偏移
DWORD FOAToVA(DWORD FOA, PVOID pFileBuffer) {
   
   
	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;
	if (FOA < pSecHeader->PointerToRawData) {
   
   
		return FOA + (DWORD)pFileBuffer;
	}
	for (size_t i = 0; i < pFileHeader->NumberOfSections; i++) {
   
   
		if (FOA >= pSecHeader->PointerToRawData && FOA < (pSecHeader->PointerToRawData + pSecHeader->SizeOfRawData)) {
   
   
			return pSecHeader->VirtualAddress + (FOA - pSecHeader->PointerToRawData);
		}
		pSecHeader++;
	}
	return 0;
}
//移动导出表
BOOL MoveExportTable(PVOID fileName,PVOID newFileName) {
   
   
	if (!IncreaseSection(fileName)) {
   
   
		printf("Increase section failed\n");
		return FALSE;
	}
	PVOID pFileBuffer = FileToFileBuffer(newFileName);
	//定位导出表
	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
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值