能力值:
( LV2,RANK:10 )
|
-
-
2 楼
bool RelocImageBuffer(PVOID pImage,DWORD dwNewImageBase) { if (!pImage) { printf("模块地址为空\n"); Sleep(2000); return false; } //目标 根据重定位表 找到需要修改的地址 然后判断 如果新的模块基址大于原来的ImageBase PVOID pOptionHeader=0; GetPEOptionHeader(pImage,&pOptionHeader);
//得到原来的ImageBase DWORD dwOldImageBase=((PIMAGE_OPTIONAL_HEADER)pOptionHeader)->ImageBase;
//修改ImageBase ((PIMAGE_OPTIONAL_HEADER)pOptionHeader)->ImageBase=dwNewImageBase; //判断是否有重定位表 if (!((PIMAGE_OPTIONAL_HEADER)pOptionHeader)->DataDirectory[5].VirtualAddress) { printf("没有重定位表"); Sleep(5000); ExitThread(-1); return false; } //获取重定位页的位置 PVOID pRelocPage=((PIMAGE_OPTIONAL_HEADER)pOptionHeader)->DataDirectory[5].VirtualAddress+(PCHAR)pImage;
PRELOC_INFO pRelocInfo=(PRELOC_INFO)pRelocPage; while (pRelocInfo->VirtualAddress &&pRelocInfo->Size) { //找到需要修改的地址 DWORD dwIndex=0; while (dwIndex<(pRelocInfo->Size-8)/2) { PVOID dwModifyAddr=(PCHAR)pRelocInfo+8+dwIndex*2; //如果最高位为3 则修改 PRELOCCOLUM pRelocColum=(PRELOCCOLUM)dwModifyAddr;
if (pRelocColum->Flag==3) { //要修改的地址=imagebase+页+具体项 dwModifyAddr=(PCHAR)pImage+pRelocInfo->VirtualAddress+pRelocColum->Address; *(DWORD*)dwModifyAddr+=dwNewImageBase-dwOldImageBase; } dwIndex++; } //下一页=上一页的RVA+size PCHAR pRelocAddr=(PCHAR)pRelocInfo; pRelocAddr+=pRelocInfo->Size; pRelocInfo=(PRELOC_INFO)pRelocAddr; } return true; } 这是我以前写的。你自己对照下。
|
|
|