¼ÌÐøPEϵÁбʼǵĸüÐÂ
PEÆäËü±Ê¼ÇË÷Òý¿ÉÇ°Íù£º
PEÎļþ±Ê¼ÇÒ» PE½éÉÜ
Ç°ÃæÔÚPEÎļþ±Ê¼ÇÊ®ËÄ µ¼³ö±íѧϰÁ˵¼³ö±í£¬½Ó×Åѧϰµ¼Èë±í
µ¼Èë±í
µ¼Èë±í×÷ÓÃ
µ±³ÌÐòÔËÐÐʱ£¬ÐèÒª¶à¸öPEÎļþ¹²Í¬×é³É
PEÎļþÌṩÄÄЩ¹¦ÄÜ¡úµ¼³ö±í
PEÎļþÐèÒªÒÀÀµµÄÄ£¿éÒÔ¼°ÒÀÀµÕâЩģ¿éÖеÄÄÄЩº¯Êý¡úµ¼Èë±í
ʲôÊǵ¼Èë±í
µ¼Èë±í¾ÍÊǼǼ¸ÃPEÎļþ»¹ÐèÒªÒÀÀµµÄÄ£¿éÒÔ¼°ÒÀÀµÕâЩģ¿éÖеÄÄÄЩº¯ÊýµÄÒ»Öֽṹ
¶¨Î»µ¼Èë±í
¶¨Î»µ¼Èë±íÔÀí
ÔÚÉÏÒ»¸ö±Ê¼Ç£ºPEÎļþ±Ê¼ÇÊ®ËÄ µ¼³ö±íÖÐÒÔ¼°Ìáµ½ÁË£¬Ïñµ¼Èë±í¡¢µ¼³ö±í¡¢Öض¨Î»±í¡¢×ÊÔ´±íµÈ±í£¬ÕâЩ±íµÄÆðʼµØÖ·ºÍ´óС¶¼´æ´¢ÔÚÀ©Õ¹PEÍ·ÀïµÄDataDirectoryÕâ¸öÊý×éµÄ³ÉÔ±ÖУ¬DataDirectoryÊÇÒ»¸öÊý×飬ÿ¸öÊý×é³ÉÔ±¶ÔÓ¦Ò»Õűí
»Ø¹ËÏÈÇ°µÄ±Ê¼Ç£¬Äܵõ½µ¼Èë±í¶ÔÓ¦µÄϱêΪ1
ºê¶¨Òå |
Öµ |
º¬Òå |
IMAGE_DIRECTORY_ENTRY_IMPORT |
1 |
µ¼Èë±í |
¼´DataDirectory[1]±íʾµ¼Èë±í
¹ØÓÚDataDirectoryµÄ¾ßÌåÃèÊöÔÚÉÏÒ»¸ö±Ê¼ÇÖÐÒѾÏêϸ˵Ã÷¹ýÁË£¬ÕâÀï²»ÔÙ׸Êö£º
IMAGE_DATA_DIRECTORY³ÉÔ± |
Êý¾Ý¿í¶È |
˵Ã÷ |
VirtualAddress |
DWORD(4×Ö½Ú) |
±íµÄÆðʼλÖã¨RVA£© |
Size |
DWORD(4×Ö½Ú) |
±íµÄ´óС |
¶¨Î»µ¼Èë±íÁ÷³Ì
- ÕÒµ½À©Õ¹PEÍ·µÄ×îºóÒ»¸ö³ÉÔ±DataDirectory
- »ñÈ¡DataDirectory[1]
- ͨ¹ýDataDirectory[1].VirtualAddressµÃµ½µ¼Èë±íµÄRVA
- ½«µ¼³ö±íµÄRVAת»»ÎªFOA£¬ÔÚÎļþÖж¨Î»µ½µ¼Èë±í
°´Á÷³Ì¶¨Î»µ¼Èë±í
Òª·ÖÎöµÄʵÀý
Õâ´ÎÒª·ÖÎöµÄʵÀýÓֻع鵽ÏÈÇ°µÄEverEdit.exeÁË
³ÌÐòÔÚºóÃæµÄ¸½¼þÖУ¬ÓÐÐèÒª¿ÉÒÔ×ÔÐÐÈ¡ÓÃ
ÕÒµ½DataDirectory
ʹÓÃWinHex´ò¿ªEverEdit.exe£¬ÏÈÕÒµ½PEÎļþÍ·µÄÆðʼµØÖ·£º0xF0
ÔÙÊý24¸ö×Ö½Ú£¨PEÎļþÍ·±êÖ¾´óС+±ê×¼PEÍ·´óС£©£¬µ½´ïÀ©Õ¹PEÍ·£º0xF0+24=240+24=264=0x108
È»ºóÔÚÊý224-128=96¸ö×Ö½Ú£¨À©Õ¹PEÍ·´óС¼õÈ¥DataDirectory´óС£©DataDirectory´óС= _IMAGE_DATA_DIRECTORY´óС¡Á16=8*16
DataDirectoryÊ×µØÖ· = À©Õ¹PEÍ·µØÖ·+96=0x108+96=264+96=360=0x168
»ñÈ¡DataDirectory[1]
¶øµ¼Èë±íΪDataDirectory[1]£¬Ò²¾ÍÊÇ´ÓÊ×µØÖ·¿ªÊ¼µÄDataDirectory[0]µÄÆ«ÒÆÖ®ºóµÄ8¸ö×Ö½Ú¾ÍÊÇÃèÊöµ¼Èë±íµÄIMAGE_DATA_DIRECTORY
µ¼Èë±íµØÖ· = DataDirectoryÊ×µØÖ· + sizeof(IMAGE_DATA_DIRECTORY)=0x168+8=360+8=368=0x170
IMAGE_DATA_DIRECTORY³ÉÔ± |
Öµ |
˵Ã÷ |
VirtualAddress |
0x001CF47C |
±íµÄÆðʼλÖã¨RVA£© |
Size |
0x00000140 |
±íµÄ´óС |
µÃµ½µ¼³ö±íµÄRVA
ÓÚÊǵõ½µ¼³ö±í¶ÔÓ¦µÄRVAΪ£º0x1CF47C
RVAת»»FOA
µ«ÊÇIMAGE_DATA_DIRECTORYÖеÄVirtualAddressÊÇRVA£¬ÐèÒª½«Æäת»»³ÉFOA
¹ØÓÚRVAתFOAµÄÄÚÈÝÔÚ PEÎļþ±Ê¼ÇÆß VAÓëFOAת»»ÖÐÒѾÏêϸ˵Ã÷ÁË£¬ÕâÀï²»ÔÙ׸Êö
Ö±½ÓʹÓÃÔڱʼÇÆßÖÐдµÄת»»´úÂë¼ÆËã³ö¶ÔÓ¦µÄFOA£º
// PE.cpp : Defines the entry point for the console application.
//
#include <stdio.h>
#include <malloc.h>
#include <windows.h>
#include <winnt.h>
#include <math.h>
//ÔÚVC6Õâ¸ö±È½Ï¾ÉµÄ»·¾³ÀûÓж¨Òå64λµÄÕâ¸öºê£¬ÐèÒª×Ô¼º¶¨Ò壬ÔÚVS2019ÖÐÎÞÐè×Ô¼º¶¨Òå
#define IMAGE_FILE_MACHINE_AMD64 0x8664
//VAתFOA 32λ
//µÚÒ»¸ö²ÎÊýΪҪת»»µÄÔÚÄÚ´æÖеĵØÖ·£ºVA
//µÚ¶þ¸ö²ÎÊýΪָÏòdosÍ·µÄÖ¸Õë
//µÚÈý¸ö²ÎÊýΪָÏòntÍ·µÄÖ¸Õë
//µÚËĸö²ÎÊýΪ´æ´¢Ö¸Ïò½ÚÖ¸ÕëµÄÊý×é
UINT VaToFoa32(UINT va, _IMAGE_DOS_HEADER* dos, _IMAGE_NT_HEADERS* nt, _IMAGE_SECTION_HEADER** sectionArr) {
//µÃµ½RVAµÄÖµ£ºRVA = VA - ImageBase
UINT rva = va - nt->OptionalHeader.ImageBase;
//Êä³örva
printf("rva:%X\n", rva);
//ÕÒµ½PEÎļþÍ·ºóµÄµØÖ· = PEÎļþÍ·Ê×µØÖ·+PEÎļþÍ·´óС
UINT PeEnd = (UINT)dos->e_lfanew + sizeof(_IMAGE_NT_HEADERS);
//Êä³öPeEnd
printf("PeEnd:%X\n", PeEnd);
//ÅжÏrvaÊÇ·ñλÓÚPEÎļþÍ·ÖÐ
if (rva < PeEnd) {
//Èç¹ûrvaλÓÚPEÎļþÍ·ÖУ¬Ôòfoa==rva£¬Ö±½Ó·µ»Ørva¼´¿É
printf("foa:%X\n", rva);
return rva;
}
else {
//Èç¹ûrvaÔÚPEÎļþÍ·Íâ
//ÅжÏrvaÊôÓÚÄĸö½Ú
int i;
for (i = 0; i < nt->FileHeader.NumberOfSections; i++) {
//¼ÆËãÄÚ´æ¶ÔÆëºó½ÚµÄ´óС
UINT SizeInMemory = ceil((double)max((UINT)sectionArr[i]->Misc.VirtualSize, (UINT)sectionArr[i]->SizeOfRawData) / (double)nt->OptionalHeader.SectionAlignment) * nt->OptionalHeader.SectionAlignment;
if (rva >= sectionArr[i]->VirtualAddress && rva < (sectionArr[i]->VirtualAddress + SizeInMemory)) {
//ÕÒµ½ËùÊôµÄ½Ú
//Êä³öÄÚ´æ¶ÔÆëºóµÄ½ÚµÄ´óС
printf("SizeInMemory:%X\n", SizeInMemory);
break;
}
}
if (i >= nt->FileHeader.NumberOfSections) {
//δÕÒµ½
printf("ûÓÐÕÒµ½Æ¥ÅäµÄ½Ú\n");
return -1;
}
else {
//¼ÆËã²îÖµ= RVA - ½Ú.VirtualAddress
UINT offset = rva - sectionArr[i]->VirtualAddress;
//FOA = ½Ú.PointerToRawData + ²îÖµ
UINT foa = sectionArr[i]->PointerToRawData + offset;
printf("foa:%X\n", foa);
return foa;
}
}
}
int main(int argc, char* argv[])
{
//´´½¨DOS¶ÔÓ¦µÄ½á¹¹ÌåÖ¸Õë
_IMAGE_DOS_HEADER* dos;
//¶ÁÈ¡Îļþ£¬·µ»ØÎļþ¾ä±ú
HANDLE hFile = CreateFileA("C:\\Documents and Settings\\Administrator\\×ÀÃæ\\user32.dll", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
//¸ù¾ÝÎļþ¾ä±ú´´½¨Ó³Éä
HANDLE hMap = CreateFileMappingA(hFile, NULL, PAGE_READWRITE, 0, 0, 0);
//Ó³ÉäÄÚÈÝ
LPVOID pFile = MapViewOfFile(hMap, FILE_SHARE_WRITE, 0, 0, 0);
//ÀàÐÍת»»£¬ÓýṹÌåµÄ·½Ê½À´¶ÁÈ¡
dos = (_IMAGE_DOS_HEADER*)pFile;
//Êä³ödos->e_magic£¬ÒÔÊ®Áù½øÖÆÊä³ö
printf("dos->e_magic:%X\n", dos->e_magic);
//´´½¨Ö¸ÏòPEÎļþÍ·±êÖ¾µÄÖ¸Õë
DWORD* peId;
//ÈÃPEÎļþÍ·±êÖ¾Ö¸ÕëÖ¸ÏòÆä¶ÔÓ¦µÄµØÖ·=DOSÊ×µØÖ·+Æ«ÒÆ
peId = (DWORD*)((UINT)dos + dos->e_lfanew);
//Êä³öPEÎļþÍ·±êÖ¾£¬ÆäֵӦΪ4550£¬·ñÔò²»ÊÇPEÎļþ
printf("peId:%X\n", *peId);
//´´½¨Ö¸Ïò¿ÉÑ¡PEÍ·µÄµÚÒ»¸ö³ÉÔ±magicµÄÖ¸Õë
WORD* magic;
//ÈÃmagicÖ¸ÕëÖ¸ÏòÆä¶ÔÓ¦µÄµØÖ·=PEÎļþÍ·±êÖ¾µØÖ·+PEÎļþÍ·±êÖ¾´óС+±ê×¼PEÍ·´óС
magic = (WORD*)((UINT)peId + sizeof(DWORD) + sizeof(_IMAGE_FILE_HEADER));
//Êä³ömagic£¬ÆäֵΪ0x10b´ú±í32λ³ÌÐò£¬ÆäֵΪ0x20b´ú±í64λ³ÌÐò
printf("magic:%X\n", *magic);
//¸ù¾ÝmagicÅжÏΪ32λ³ÌÐò»¹ÊÇ64λ³ÌÐò
switch (*magic) {
case IMAGE_NT_OPTIONAL_HDR32_MAGIC:
{
printf("32λ³ÌÐò\n");
//È·¶¨Îª32λ³ÌÐòºó£¬¾Í¿ÉÒÔʹÓÃ_IMAGE_NT_HEADERSÀ´½ÓÊÕÊý¾ÝÁË
//´´½¨Ö¸ÏòPEÎļþÍ·µÄÖ¸Õë
_IMAGE_NT_HEADERS* nt;
//ÈÃPEÎļþÍ·Ö¸ÕëÖ¸ÏòÆä¶ÔÓ¦µÄµØÖ·
nt = (_IMAGE_NT_HEADERS*)peId;
printf("Machine:%X\n", nt->FileHeader.Machine);
printf("Magic:%X\n", nt->OptionalHeader.Magic);
//´´½¨Ò»¸öÖ¸ÕëÊý×飬¸ÃÖ¸ÕëÊý×éÓÃÀ´´æ´¢ËùÓеĽڱíÖ¸Õë
//ÕâÀïÏ൱ÓÚ_IMAGE_SECTION_HEADER* sectionArr[nt->FileHeader.NumberOfSections],ÉùÃ÷ÁËÒ»¸ö¶¯Ì¬Êý×é
_IMAGE_SECTION_HEADER** sectionArr = (_IMAGE_SECTION_HEADER**)malloc(sizeof(_IMAGE_SECTION_HEADER*) * nt->FileHeader.NumberOfSections);
//´´½¨Ö¸Ïò¿é±íµÄÖ¸Õë
_IMAGE_SECTION_HEADER* sectionHeader;
//Èÿé±íµÄÖ¸ÕëÖ¸ÏòÆä¶ÔÓ¦µÄµØÖ·
sectionHeader = (_IMAGE_SECTION_HEADER*)((UINT)nt + sizeof(_IMAGE_NT_HEADERS));
//¼ÆÊý£¬ÓÃÀ´¼ÆËã¿é±íµØÖ·
int cnt = 0;
//±È½Ï ¼ÆÊý ºÍ ¿é±íµÄ¸öÊý£¬¼´±éÀúËùÓпé±í
while (cnt < nt->FileHeader.NumberOfSections) {
//´´½¨Ö¸Ïò¿é±íµÄÖ¸Õë
_IMAGE_SECTION_HEADER* section;
//Èÿé±íµÄÖ¸ÕëÖ¸ÏòÆä¶ÔÓ¦µÄµØÖ·=µÚÒ»¸ö¿é±íµØÖ·+¼ÆÊý*¿é±íµÄ´óС
section = (_IMAGE_SECTION_HEADER*)((UINT)sectionHeader + sizeof(_IMAGE_SECTION_HEADER) * cnt);
//½«µÃµ½µÄ¿é±íÖ¸Õë´æÈëÊý×é
sectionArr[cnt++] = section;
//Êä³ö¿é±íÃû³Æ
printf("%s\n", section->Name);
}
VaToFoa32(nt->OptionalHeader.ImageBase +0x1CF47C,dos,nt,sectionArr);
break;
}
case IMAGE_NT_OPTIONAL_HDR64_MAGIC:
{
printf("64λ³ÌÐò\n");
//È·¶¨Îª64λ³ÌÐòºó£¬¾Í¿ÉÒÔʹÓÃ_IMAGE_NT_HEADERS64À´½ÓÊÕÊý¾ÝÁË
//´´½¨Ö¸ÏòPEÎļþÍ·µÄÖ¸Õë
_IMAGE_NT_HEADERS64* nt;
nt = (_IMAGE_NT_HEADERS64*)peId;
printf("Machine:%X\n", nt->FileHeader.Machine);
printf("Magic:%X\n", nt->OptionalHeader.Magic);
//´´½¨Ò»¸öÖ¸ÕëÊý×飬¸ÃÖ¸ÕëÊý×éÓÃÀ´´æ´¢ËùÓеĽڱíÖ¸Õë
//ÕâÀïÏ൱ÓÚ_IMAGE_SECTION_HEADER* sectionArr[nt->FileHeader.NumberOfSections],ÉùÃ÷ÁËÒ»¸ö¶¯Ì¬Êý×é
_IMAGE_SECTION_HEADER** sectionArr = (_IMAGE_SECTION_HEADER**)malloc(sizeof(_IMAGE_SECTION_HEADER*) * nt->FileHeader.NumberOfSections);
//´´½¨Ö¸Ïò¿é±íµÄÖ¸Õë
_IMAGE_SECTION_HEADER* sectionHeader;
//Èÿé±íµÄÖ¸ÕëÖ¸ÏòÆä¶ÔÓ¦µÄµØÖ·£¬Çø±ðÔÚÓÚÕâÀï¼ÓÉϵÄÆ«ÒÆΪ_IMAGE_NT_HEADERS64
sectionHeader = (_IMAGE_SECTION_HEADER*)((UINT)nt + sizeof(_IMAGE_NT_HEADERS64));
//¼ÆÊý£¬ÓÃÀ´¼ÆËã¿é±íµØÖ·
int cnt = 0;
//±È½Ï ¼ÆÊý ºÍ ¿é±íµÄ¸öÊý£¬¼´±éÀúËùÓпé±í
while (cnt < nt->FileHeader.NumberOfSections) {
//´´½¨Ö¸Ïò¿é±íµÄÖ¸Õë
_IMAGE_SECTION_HEADER* section;
//Èÿé±íµÄÖ¸ÕëÖ¸ÏòÆä¶ÔÓ¦µÄµØÖ·=µÚÒ»¸ö¿é±íµØÖ·+¼ÆÊý*¿é±íµÄ´óС
section = (_IMAGE_SECTION_HEADER*)((UINT)sectionHeader + sizeof(_IMAGE_SECTION_HEADER) * cnt);
//½«µÃµ½µÄ¿é±íÖ¸Õë´æÈëÊý×é
sectionArr[cnt++] = section;
//Êä³ö¿é±íÃû³Æ
printf("%s\n", section->Name);
}
break;
}
default:
{
printf("error!\n");
break;
}
}
return 0;
}
¹Ø¼ü´úÂë:
VaToFoa32(nt->OptionalHeader.ImageBase +0x1CF47C,dos,nt,sectionArr);
ÒòΪÏÈǰдµÄº¯ÊýÊÇVAתFOA£¬ÕâÀïµÃµ½µÄÊÇRVA£¬ÓÚÊÇÒªÏÈÓÃRVA+ImageBaseµÃµ½VA
ÔËÐдúÂëµÃµ½£º
»ñµÃÁËFOAΪ0x1CDA7C£¬Ò²¾ÍÊǵ¼Èë±íµÄλÖÃÁË£¬¶¨Î»Íê³É
µ¼Èë±íµÄ½á¹¹
¶¨Î»µ½Á˵¼Èë±íºó×ÔȻҪÁ˽⵼Èë±íµÄ½á¹¹²ÅÄܽâ¶Áµ¼Èë±íµÄÄÚÈÝ
µ¼Èë±íµÄ¸öÊý
Óëµ¼³ö±í²»Í¬£¬µ¼Èë±íͨ³£Òª°üº¬¶à¸öÄ£¿é£¬¶ø²»Ïñµ¼³ö±íÖ»ÐèÒªÌṩ±¾PEÎļþÐèÒªÌṩµÄµ¼³öº¯Êý¼´¿É
Òò´Ë£¬µ¼³ö±íÖ»ÓÐÒ»¸ö£¬µ«µ¼Èë±íÔò¿ÉÄÜÓжà¸ö
µ±³ÌÐòÔËÐÐʱ£¬ÐèÒªÒÀÀµ¼¸¸öÄ£¿é£¬¾Í¶ÔÓ¦Óм¸Õŵ¼Èë±í
µ¼Èë±íµÄ½á¹¹Ìå
¸ø³öµ¼Èë±íÔÚCÓïÑÔÖеĽṹÌ壨ÔÚwinnt.hÖпÉÒÔÕÒµ½£©
¼´£º
typedef struct _IMAGE_IMPORT_DESCRIPTOR {
union {
DWORD Characteristics; // 0 for terminating null import descriptor
DWORD OriginalFirstThunk; // RVA to original unbound IAT (PIMAGE_THUNK_DATA)
};
DWORD TimeDateStamp; // 0 if not bound,
// -1 if bound, and real date\time stamp
// in IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT (new BIND)
// O.W. date/time stamp of DLL bound to (Old BIND)
DWORD ForwarderChain; // -1 if no forwarders
DWORD Name;
DWORD FirstThunk; // RVA to IAT (if bound this IAT has actual addresses)
} IMAGE_IMPORT_DESCRIPTOR;
½á¹¹Ìå·ÖÎö
³ÉÔ± |
Êý¾Ý¿í¶È |
˵Ã÷ |
Characteristics |
DWORD(4×Ö½Ú) |
±êÖ¾ Ϊ0±íʾ½áÊø ûÓе¼ÈëÃèÊö·ûÁË |
OriginalFirstThunk |
DWORD(4×Ö½Ú) |
RVAÖ¸ÏòIMAGE_THUNK_DATA½á¹¹Êý×飨ÇÅ1£© |
TimeDateStamp |
DWORD(4×Ö½Ú) |
ʱ¼ä´Á |
ForwarderChain |
DWORD(4×Ö½Ú) |
Á´±íµÄÇ°Ò»¸ö½á¹¹ |
Name |
DWORD(4×Ö½Ú) |
RVA£¬Ö¸ÏòDLLÃû×Ö£¬¸ÃÃû×ÖÒÔ''\0''½áβ |
FirstThunk |
DWORD(4×Ö½Ú) |
RVAÖ¸ÏòIMAGE_THUNK_DATA½á¹¹Êý×飨ÇÅ2£© |
Characteristics
±êÖ¾ Ϊ0±íʾ½áÊø ûÓе¼ÈëÃèÊö·ûÁË
IMAGE_THUNK_DATA
ÔÚ½éÉÜOriginalFirstThunk֮ǰ£¬ÒªÏÈÁ˽âÒ»ÏÂOriginalFirstThunkºÍFirstThunkËùÖ¸ÏòµÄ½á¹¹Êý×é
Ö¸ÏòµÄÊý×éÖÐÿһÏîΪһ¸ö½á¹¹£¬´Ë½á¹¹Ãû³ÆÊÇIMAGE_THUNK_DATA
Êý×é×îºóÒÔÒ»¸öÄÚÈÝȫΪ0µÄIMAGE_THUNK_DATA×÷Ϊ½áÊø
IMAGE_THUNK_DATAʵ¼ÊÉÏÖ»ÊÇÒ»¸öDWORD£¬µ«ÔÚ²»Í¬µÄʱ¿ÌÈ´ÓµÓв»Í¬µÄ½âÊÍ
IMAGE_THUNK_DATAÓÐÁ½ÖÖ½âÊÍ£º
- DWORD×î¸ßλΪ0£¬ÄÇô¸ÃÊýÖµÊÇÒ»¸öRVA£¬Ö¸Ïò_IMAGE_IMPORT_BY_NAME½á¹¹£¬±íÃ÷º¯ÊýÊÇÒÔ×Ö·û´®ÀàÐ͵ĺ¯ÊýÃûµ¼ÈëµÄ
- DWORD×î¸ßλΪ1£¬ÄÇô¸ÃÊýÖµµÄµÍ31λ¾ÍÊǺ¯ÊýµÄµ¼³öº¯ÊýµÄÐòºÅ
_IMAGE_IMPORT_BY_NAME½á¹¹£º
typedef struct _IMAGE_IMPORT_BY_NAME {
WORD Hint;
BYTE Name[1];
} IMAGE_IMPORT_BY_NAME, *PIMAGE_IMPORT_BY_NAME;
¸Ã½á¹¹¼´Îª£º"±àºÅ¡ªÃû³Æ"£¨Hint/Name£©ÃèÊö²¿·Ö
- Hint£ºµ¼³öº¯ÊýµØÖ·±íµÄË÷Òý±àºÅ£¬¿ÉÄÜΪ¿ÕÇÒ²»Ò»¶¨×¼È·£¬ÓɱàÒëÆ÷¾ö¶¨£¬Ò»°ã²»Ê¹ÓøÃÖµ
- Name£ºÕâ¸öÊÇÒ»¸öÒÔ"\0"½áβµÄ×Ö·û´®£¬±íʾº¯ÊýÃû
ÕâÀï²»ÄÑ·¢ÏÖ£¬IMAGE_THUNK_DATA×îÖÕÌṩµÄÊý¾ÝÒ²Ö»ÓÐ2¸ö£º
- DWORD×î¸ßλΪ0ʱ£ºÐèÒªµ¼È뺯ÊýµÄÃû³Æ£¨Hint²»Ò»¶¨×¼È·£¬ËùÒÔ²»Ê¹Óã©
- DWORD×î¸ßλΪ1ʱ£ºÐèÒªµ¼ÈëµÄº¯ÊýÔÚµ¼³ö±íÖеÄÐòºÅ
ÕýºÃ¶ÔÓ¦ÁËÔÚÉÏÒ»¸ö±Ê¼Ç£ºPEÎļþ±Ê¼ÇÊ®ËÄ µ¼³ö±íÖÐÓɵ¼³ö±í»ñµÃµ¼³öº¯ÊýËùÐèµÄÁ½ÖÖ·½·¨
¼´£º
- ¸ù¾Ýº¯ÊýÃû³Æ»ñÈ¡µ¼³öº¯ÊýµØÖ·
- ¸ù¾Ýº¯ÊýÐòºÅ»ñÈ¡µ¼³öº¯ÊýµØÖ·
OriginalFirstThunk
ÒòΪËüÊÇÖ¸ÏòÁíÍâÊý¾Ý½á¹¹µÄͨ·£¬Òò´Ë¼ò³ÆΪÇÅ1¡£¸Ã×Ö¶ÎÖ¸ÏòÒ»¸ö°üº¬ÁËһϵÁнṹµÄÊý×飺IMAGE_THUNK_DATA
ÇÅ1ËùÖ¸ÏòµÄµØÖ·ÁÐ±í±»¶¨ÒåΪ£ºINT£¨Import Name Table£© µ¼ÈëÃû³Æ±í
TimeDateStamp
ʱ¼ä´Á£¬Ò»°ã²»Ó㬴ó¶àÇé¿ö϶¼Îª0¡£Èç¹û¸Ãµ¼Èë±íÏî±»°ó¶¨£¬ÄÇô°ó¶¨ºóµÄÕâ¸öʱ¼ä´Á¾Í±»ÉèÖÃΪ¶ÔÓ¦DLLÎļþµÄʱ¼ä´Á¡£²Ù×÷ϵͳÔÚ¼ÓÔØʱ£¬¿ÉÒÔͨ¹ýÕâ¸öʱ¼ä´ÁÀ´Åжϰ󶨵ÄÐÅÏ¢ÊÇ·ñ¹ýʱ
ForwarderChain
Á´±íµÄÇ°Ò»¸ö½á¹¹
Name
ÕâÀïµÄNameÊÇÒ»¸öRVA£¬ËüÖ¸Ïò¸Ã½á¹¹¶ÔÓ¦µÄDLLÎļþµÄÃû³Æ£¬¶øÕâ¸öÃû³ÆÊÇÒÔ"\0"½áβµÄANSI×Ö·û´®
ANSI±àÂëÊÇÒ»ÖÖ¶ÔASCIIÂëµÄÍØÕ¹
FirstThunk
ÓëOriginalFirstThunkÏàͬ£¬ËüÖ¸ÏòµÄÁ´±í¶¨ÒåÁËÕë¶ÔNameÕâ¸ö¶¯Ì¬Á´½Ó¿âÒýÈëµÄËùÓе¼È뺯Êý£¬¼ò³ÆÇÅ2
ÇÅ2ËùÖ¸ÏòµÄµØÖ·ÁÐ±í±»¶¨ÒåΪ£ºIAT£¨Import Adress Table£© µ¼ÈëµØÖ·±í
µ¼Èë±íµÄË«ÇŽṹ
ÇÅ1ºÍÇÅ2×îÖÕµÄÄ¿µÄµØÊÇÒ»Öµģ¬¶¼Ö¸ÏòÁËÒýÈ뺯ÊýµÄ"±àºÅ¡ªÃû³Æ"£¨Hint/Name£©ÃèÊö²¿·Ö
ÇÅ1µ½Ä¿µÄµØµÄ¹ý³ÌÖУ¬¾¹ýÁË£ºINT£¨Import Name Table£©µ¼ÈëÃû³Æ±í
¶øÇÅ2µ½Ä¿µÄµØµÄ¹ý³ÌÖУ¬¾¹ýÁË£ºIAT(Import Address Table)µ¼ÈëµØÖ·±í
PEÎļþ¼ÓÔØÇ°
PEÎļþ¼ÓÔغó
¼ÓÔØÇ°ºó¶Ô±È
- ÔÚPEÎļþ¼ÓÔØÇ°£ºÇÅ1Ö¸ÏòµÄINTºÍÇÅ2Ö¸ÏòµÄIATµÄÊý¾ÝÖµÊÇÏàͬµÄ£¬µ«ÊÇÆä´æ´¢Î»ÖÃÊDz»Í¬µÄ
- ÔÚPEÎļþ¼ÓÔغó£ºÇÅ1Ö¸ÏòµÄINT²»±ä£¬µ«ÇÅ2Ö¸ÏòµÄIATµÄÊý¾ÝÖµ±äΪÁ˺¯ÊýÏàÓ¦µÄRVAµØÖ·
PS£ºº¯ÊýÏàÓ¦µÄRVAµØÖ·ÊǸù¾ÝIATÖеĺ¯ÊýÃû³Æ»òÕßµ¼³ö±íÖеÄÐòºÅ»ñµÃµÄ
°´½á¹¹·ÖÎöµ¼Èë±í
»Øµ½ÏÈÇ°µÃµ½µÄµ¼Èë±íµÄFOA£¬ÔÚWinHexÖÐÕÒµ½FOA£º0x1CDA7C
ÕâÀïÈ¡µÚÒ»¸ö_IMAGE_IMPORT_DESCRIPTOR½øÐзÖÎö
½«¶ÔÓ¦µÄÊý¾ÝÌîÈë½á¹¹Ìå³ÉÔ±Öеõ½£º
³ÉÔ± |
Öµ |
˵Ã÷ |
Characteristics |
0x001CF790 |
±êÖ¾ Ϊ0±íʾ½áÊø ûÓе¼ÈëÃèÊö·ûÁË |
OriginalFirstThunk |
0x001CF790 |
RVAÖ¸ÏòIMAGE_THUNK_DATA½á¹¹Êý×飨ÇÅ1£© |
TimeDateStamp |
0x00000000 |
ʱ¼ä´Á |
ForwarderChain |
0x00000000 |
Á´±íµÄÇ°Ò»¸ö½á¹¹ |
Name |
0x001D0788 |
RVA£¬Ö¸ÏòDLLÃû×Ö£¬¸ÃÃû×ÖÒÔ''\0''½áβ |
FirstThunk |
0x0019B1D4 |
RVAÖ¸ÏòIMAGE_THUNK_DATA½á¹¹Êý×飨ÇÅ2£© |
Characteristics
²»Îª0£¬±íʾ»¹Óе¼ÈëÃèÊö·û
OriginalFirstThunk
Ö¸ÏòIMAGE_THUNK_DATA½á¹¹Êý×飬ÏȽ«RVA£º0x001CF790ת»»ÎªFOA£º0x1CDD90
ת»»´úÂëΪ£º
VaToFoa32(nt->OptionalHeader.ImageBase +0x001CF790,dos,nt,sectionArr);
ÓÃWinHexÕÒµ½0x1CDD90µÄλÖãº
µÃµ½½á¹¹ÌåÊý×é INTΪ£º
Êý×éϱê |
IMAGE_THUNK_DATA(RVA) |
¶ÔÓ¦FOA |
0 |
0x001D0774 |
0x1CED74 |
1 |
0x001D2620 |
0x1D0C20 |
2 |
0x001D2606 |
0x1D0C06 |
3 |
0x001D25F4 |
0x1D0BF4 |
4 |
0x001D25E0 |
0x1D0BE0 |
.............. |
..................................... |
............ |
n |
0 |
0 |
ÒòΪÕâÀïÇ°ÃæµÄ¼¸¸öIMAGE_THUNK_DATAµÄ×î¸ßλ¶¼Îª0£¬ÓÚÊÇÆä±íʾµÄΪÄÚÈݱíʾָÏò_IMAGE_IMPORT_BY_NAMEµÄRVA
PS£ºÈô×î¸ßλΪ1£¬ÔòÆä±íʾµÄÄÚÈÝÈ¥µô×î¸ßλºóΪ£ºµ¼³öº¯ÊýµÄÐòºÅ
ÏȲ鿴ϱêΪ0 ¶ÔÓ¦µÄFOA£º
½«µÃµ½µÄÊý¾ÝÌîÈë_IMAGE_IMPORT_BY_NAME
_IMAGE_IMPORT_BY_NAME³ÉÔ± |
Öµ |
Hint |
0x018F |
Name |
ANSIÂëΪ"GetComputerNameW" |
ÕâÀï¾Í»ñµÃÁËÐèÒªµ¼ÈëµÄº¯ÊýµÄÃû³ÆºÍHint£¬Õâ¸öHint²»Ò»¶¨×¼È·£¬²»Ê¹ÓÃ
TimeDateStamp
ֵΪ0£¬±àÒëÆ÷²¢Î´Ìîдʱ¼ä´Á
ForwarderChain
ֵΪ0£¬Ã»ÓÐÁ´±íµÄÇ°Ò»¸ö½á¹¹
Name
ֵΪ0x001D0788£¬ÊǸöRVAµØÖ·£¬ÏȽ«Æäת»»³ÉFOA£º0x1CED88
ת»»´úÂ룺
VaToFoa32(nt->OptionalHeader.ImageBase +0x001D0788,dos,nt,sectionArr);
ÓÃWinHexÕÒµ½0x1CED88µÄλÖãº
µÃµ½µÚÒ»¸öµ¼ÈëÃèÊö·û ÃèÊöµÄµ¼ÈëÄ£¿éÃûΪ£º"KERNEL32.dll"
FirstThunk
ֵΪ0x0019B1D4£¬ÊǸöRVAµØÖ·£¬ÏȽ«Æäת»»³ÉFOA£º0x1997D4
ת»»´úÂ룺
VaToFoa32(nt->OptionalHeader.ImageBase +0x0019B1D4,dos,nt,sectionArr);
ÓÃWinHexÕÒµ½0x1997D4µÄλÖãº
µÃµ½½á¹¹ÌåÊý×é IATΪ£º
Êý×éϱê |
IMAGE_THUNK_DATA(RVA) |
¶ÔÓ¦FOA |
0 |
0x001D0774 |
0x1CED74 |
1 |
0x001D2620 |
0x1D0C20 |
2 |
0x001D2606 |
0x1D0C06 |
3 |
0x001D25F4 |
0x1D0BF4 |
4 |
0x001D25E0 |
0x1D0BE0 |
.............. |
..................................... |
............ |
n |
0 |
0 |
ÕâÀï»á·¢ÏÖIATºÍINTÖеÄÄÚÈÝÊÇÒ»Öµģ¬µ«ÊÇËüÃÇ´æ´¢ÔÚ²»Í¬µÄµØÖ·ÉÏ£¨FOA²»Í¬£¬Ç°ÃæINTµÄFOAΪ£º0x1CDD90£¬ÕâÀïIATµÄFOAΪ£º0x1997D4£©
ÑéÖ¤ÁË£ºÔÚPEÎļþ¼ÓÔØÇ°£¬ÇÅ1Ö¸ÏòµÄINTºÍÇÅ2Ö¸ÏòµÄIATµÄÊý¾ÝÖµÊÇÏàͬµÄ£¬µ«ÊÇÆä´æ´¢Î»ÖÃÊDz»Í¬µÄ
ÑéÖ¤PEÎļþ¼ÓÔغóµÄIAT±ä»¯
ÉÏÃæÖ»·ÖÎöÁËPEÎļþ¼ÓÔØÇ°µÄIAT£¬ÆäÄÚÈݺÍINTÒ»Ö£»µ±³ÌÐòÔËÐкó£¬ÔÙÓÃODÀ´²é¿´Æä¶ÔÓ¦µÄIATµÄ±ä»¯£º
ÏÈÇ°»ñµÃµÄIATµØַΪ£º0x0019B1D4£¨RVA£©£¬ÓÃOD´ò¿ªEverEdit.exe
Ñ¡ÖÐÊý¾Ý´°¿Ú
È»ºó°´¿ì½Ý¼ü£ºCtrl+G£¬µ¯³ö´°¿Ú
ÔÚµ¯³öµÄ´°¿ÚÖÐÌîдҪÌøתµÄRVAµØÖ·
È»ºó»á·¢ÏÖÄÚ´æ´°¿ÚÖеÄÄÚÈÝ·¢ÉúÁ˸ı䣬µ«ÏÔʾ·½Ê½²¢²»ÊǺÜÓѺÃ
ÓÚÊÇÐÞ¸ÄÒ»ÏÂÏÔʾ·½Ê½£¬ÔÚÄÚ´æ´°¿ÚÖÐ ÓÒ¼ü¡ú³¤ÐÍ¡úASCIIÊý¾ÝµØÖ·
¿ÉÒÔ¿´µ½£º
¿ÉÒÔ¿´µ½ÕâÀïµÄkerner32.GetComputerNameWÕýÊÇÇ°Ãæ·ÖÎö³öÀ´µÄÃû³Æ
ÑéÖ¤ÁËIAT±íÔÚPEÎļþ¼ÓÔغó·¢ÉúÁ˱仯
´úÂëʵÏÖ·ÖÎöµ¼Èë±í
// PE.cpp : Defines the entry point for the console application.
//
#include <stdio.h>
#include <malloc.h>
#include <windows.h>
#include <winnt.h>
#include <math.h>
//ÔÚVC6Õâ¸ö±È½Ï¾ÉµÄ»·¾³ÀûÓж¨Òå64λµÄÕâ¸öºê£¬ÐèÒª×Ô¼º¶¨Ò壬ÔÚVS2019ÖÐÎÞÐè×Ô¼º¶¨Òå
#define IMAGE_FILE_MACHINE_AMD64 0x8664
//VAתFOA 32λ
//µÚÒ»¸ö²ÎÊýΪҪת»»µÄÔÚÄÚ´æÖеĵØÖ·£ºVA
//µÚ¶þ¸ö²ÎÊýΪָÏòdosÍ·µÄÖ¸Õë
//µÚÈý¸ö²ÎÊýΪָÏòntÍ·µÄÖ¸Õë
//µÚËĸö²ÎÊýΪ´æ´¢Ö¸Ïò½ÚÖ¸ÕëµÄÊý×é
UINT VaToFoa32(UINT va, _IMAGE_DOS_HEADER* dos, _IMAGE_NT_HEADERS* nt, _IMAGE_SECTION_HEADER** sectionArr) {
//µÃµ½RVAµÄÖµ£ºRVA = VA - ImageBase
UINT rva = va - nt->OptionalHeader.ImageBase;
//Êä³örva
//printf("rva:%X\n", rva);
//ÕÒµ½PEÎļþÍ·ºóµÄµØÖ· = PEÎļþÍ·Ê×µØÖ·+PEÎļþÍ·´óС
UINT PeEnd = (UINT)dos->e_lfanew + sizeof(_IMAGE_NT_HEADERS);
//Êä³öPeEnd
//printf("PeEnd:%X\n", PeEnd);
//ÅжÏrvaÊÇ·ñλÓÚPEÎļþÍ·ÖÐ
if (rva < PeEnd) {
//Èç¹ûrvaλÓÚPEÎļþÍ·ÖУ¬Ôòfoa==rva£¬Ö±½Ó·µ»Ørva¼´¿É
//printf("foa:%X\n", rva);
return rva;
}
else {
//Èç¹ûrvaÔÚPEÎļþÍ·Íâ
//ÅжÏrvaÊôÓÚÄĸö½Ú
int i;
for (i = 0; i < nt->FileHeader.NumberOfSections; i++) {
//¼ÆËãÄÚ´æ¶ÔÆëºó½ÚµÄ´óС
UINT SizeInMemory = ceil((double)max((UINT)sectionArr[i]->Misc.VirtualSize, (UINT)sectionArr[i]->SizeOfRawData) / (double)nt->OptionalHeader.SectionAlignment) * nt->OptionalHeader.SectionAlignment;
if (rva >= sectionArr[i]->VirtualAddress && rva < (sectionArr[i]->VirtualAddress + SizeInMemory)) {
//ÕÒµ½ËùÊôµÄ½Ú
//Êä³öÄÚ´æ¶ÔÆëºóµÄ½ÚµÄ´óС
//printf("SizeInMemory:%X\n", SizeInMemory);
break;
}
}
if (i >= nt->FileHeader.NumberOfSections) {
//δÕÒµ½
printf("ûÓÐÕÒµ½Æ¥ÅäµÄ½Ú\n");
return -1;
}
else {
//¼ÆËã²îÖµ= RVA - ½Ú.VirtualAddress
UINT offset = rva - sectionArr[i]->VirtualAddress;
//FOA = ½Ú.PointerToRawData + ²îÖµ
UINT foa = sectionArr[i]->PointerToRawData + offset;
//printf("foa:%X\n", foa);
return foa;
}
}
}
void getImportTable(_IMAGE_DOS_HEADER* dos, _IMAGE_NT_HEADERS* nt, _IMAGE_SECTION_HEADER** sectionArr) {
_IMAGE_DATA_DIRECTORY importDataDirectory = nt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT];
//¼ÆÊý£¬ÓÃÀ´¼Ç¼µ¼ÈëÁ˶àÉÙ¸öÄ£¿é
int cnt = 0;
while (true) {
UINT importAddress = VaToFoa32(importDataDirectory.VirtualAddress + nt->OptionalHeader.ImageBase, dos, nt, sectionArr);
_IMAGE_IMPORT_DESCRIPTOR* importDirectory = (_IMAGE_IMPORT_DESCRIPTOR*)((UINT)dos + importAddress + sizeof(_IMAGE_IMPORT_DESCRIPTOR) * cnt) ;
if (importDirectory->OriginalFirstThunk != 0) {
UINT nameOffset = VaToFoa32(importDirectory->Name + nt->OptionalHeader.ImageBase, dos, nt, sectionArr);
char* name = (char*)((UINT)dos + nameOffset);
cnt++;
UINT offset=VaToFoa32(nt->OptionalHeader.ImageBase+importDirectory->OriginalFirstThunk, dos, nt, sectionArr);
if (offset == -1)return;
IMAGE_THUNK_DATA* INTTableBegin=(IMAGE_THUNK_DATA*)((UINT)dos + offset);
//¼ÆÊý£¬ÓÃÀ´¼Ç¼µ¼ÈëÁ˸ÃÄ£¿é¶àÉÙ¸öº¯Êý
int cnt2 = 0;
while (true) {
IMAGE_THUNK_DATA* address = INTTableBegin + cnt2;
if (address->u1.AddressOfData == 0) {
break;
}
else {
//ÅжÏ×î¸ßλ
if ((UINT)address->u1.AddressOfData >= 0x80000000) {
//×î¸ßλΪ1
printf("Ä£¿éÃû:%s\tº¯ÊýÐòºÅ:%X\n", name, address->u1.Ordinal-0x80000000);
}
else {
//×î¸ßλΪ0
UINT functionNameOffset= VaToFoa32(nt->OptionalHeader.ImageBase + (UINT)address->u1.AddressOfData, dos, nt, sectionArr);
_IMAGE_IMPORT_BY_NAME* functionName=(_IMAGE_IMPORT_BY_NAME*)((UINT)dos + functionNameOffset);
printf("Ä£¿éÃû:%s\tº¯ÊýÃû:%s\n", name,functionName->Name);
}
}
cnt2++;
}
printf("Ä£¿é%s\tº¯ÊýÊýÁ¿%d\n", name,cnt2);
}
else {
break;
}
}
printf("ÒýÓÃÄ£¿éÊý:%d\n", cnt);
}
int main(int argc, char* argv[])
{
//´´½¨DOS¶ÔÓ¦µÄ½á¹¹ÌåÖ¸Õë
_IMAGE_DOS_HEADER* dos;
//¶ÁÈ¡Îļþ£¬·µ»ØÎļþ¾ä±ú
HANDLE hFile = CreateFileA("C:\\Users\\lyl610abc\\Desktop\\EverEdit\\EverEdit.exe", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
//¸ù¾ÝÎļþ¾ä±ú´´½¨Ó³Éä
HANDLE hMap = CreateFileMappingA(hFile, NULL, PAGE_READWRITE, 0, 0, 0);
//Ó³ÉäÄÚÈÝ
LPVOID pFile = MapViewOfFile(hMap, FILE_SHARE_WRITE, 0, 0, 0);
//ÀàÐÍת»»£¬ÓýṹÌåµÄ·½Ê½À´¶ÁÈ¡
dos = (_IMAGE_DOS_HEADER*)pFile;
//Êä³ödos->e_magic£¬ÒÔÊ®Áù½øÖÆÊä³ö
printf("dos->e_magic:%X\n", dos->e_magic);
//´´½¨Ö¸ÏòPEÎļþÍ·±êÖ¾µÄÖ¸Õë
DWORD* peId;
//ÈÃPEÎļþÍ·±êÖ¾Ö¸ÕëÖ¸ÏòÆä¶ÔÓ¦µÄµØÖ·=DOSÊ×µØÖ·+Æ«ÒÆ
peId = (DWORD*)((UINT)dos + dos->e_lfanew);
//Êä³öPEÎļþÍ·±êÖ¾£¬ÆäֵӦΪ4550£¬·ñÔò²»ÊÇPEÎļþ
printf("peId:%X\n", *peId);
//´´½¨Ö¸Ïò¿ÉÑ¡PEÍ·µÄµÚÒ»¸ö³ÉÔ±magicµÄÖ¸Õë
WORD* magic;
//ÈÃmagicÖ¸ÕëÖ¸ÏòÆä¶ÔÓ¦µÄµØÖ·=PEÎļþÍ·±êÖ¾µØÖ·+PEÎļþÍ·±êÖ¾´óС+±ê×¼PEÍ·´óС
magic = (WORD*)((UINT)peId + sizeof(DWORD) + sizeof(_IMAGE_FILE_HEADER));
//Êä³ömagic£¬ÆäֵΪ0x10b´ú±í32λ³ÌÐò£¬ÆäֵΪ0x20b´ú±í64λ³ÌÐò
printf("magic:%X\n", *magic);
//¸ù¾ÝmagicÅжÏΪ32λ³ÌÐò»¹ÊÇ64λ³ÌÐò
switch (*magic) {
case IMAGE_NT_OPTIONAL_HDR32_MAGIC:
{
printf("32λ³ÌÐò\n");
//È·¶¨Îª32λ³ÌÐòºó£¬¾Í¿ÉÒÔʹÓÃ_IMAGE_NT_HEADERSÀ´½ÓÊÕÊý¾ÝÁË
//´´½¨Ö¸ÏòPEÎļþÍ·µÄÖ¸Õë
_IMAGE_NT_HEADERS* nt;
//ÈÃPEÎļþÍ·Ö¸ÕëÖ¸ÏòÆä¶ÔÓ¦µÄµØÖ·
nt = (_IMAGE_NT_HEADERS*)peId;
printf("Machine:%X\n", nt->FileHeader.Machine);
printf("Magic:%X\n", nt->OptionalHeader.Magic);
//´´½¨Ò»¸öÖ¸ÕëÊý×飬¸ÃÖ¸ÕëÊý×éÓÃÀ´´æ´¢ËùÓеĽڱíÖ¸Õë
//ÕâÀïÏ൱ÓÚ_IMAGE_SECTION_HEADER* sectionArr[nt->FileHeader.NumberOfSections],ÉùÃ÷ÁËÒ»¸ö¶¯Ì¬Êý×é
_IMAGE_SECTION_HEADER** sectionArr = (_IMAGE_SECTION_HEADER**)malloc(sizeof(_IMAGE_SECTION_HEADER*) * nt->FileHeader.NumberOfSections);
//´´½¨Ö¸Ïò¿é±íµÄÖ¸Õë
_IMAGE_SECTION_HEADER* sectionHeader;
//Èÿé±íµÄÖ¸ÕëÖ¸ÏòÆä¶ÔÓ¦µÄµØÖ·
sectionHeader = (_IMAGE_SECTION_HEADER*)((UINT)nt + sizeof(_IMAGE_NT_HEADERS));
//¼ÆÊý£¬ÓÃÀ´¼ÆËã¿é±íµØÖ·
int cnt = 0;
//±È½Ï ¼ÆÊý ºÍ ¿é±íµÄ¸öÊý£¬¼´±éÀúËùÓпé±í
while (cnt < nt->FileHeader.NumberOfSections) {
//´´½¨Ö¸Ïò¿é±íµÄÖ¸Õë
_IMAGE_SECTION_HEADER* section;
//Èÿé±íµÄÖ¸ÕëÖ¸ÏòÆä¶ÔÓ¦µÄµØÖ·=µÚÒ»¸ö¿é±íµØÖ·+¼ÆÊý*¿é±íµÄ´óС
section = (_IMAGE_SECTION_HEADER*)((UINT)sectionHeader + sizeof(_IMAGE_SECTION_HEADER) * cnt);
//½«µÃµ½µÄ¿é±íÖ¸Õë´æÈëÊý×é
sectionArr[cnt++] = section;
//Êä³ö¿é±íÃû³Æ
printf("%s\n", section->Name);
}
getImportTable(dos, nt, sectionArr);
break;
}
case IMAGE_NT_OPTIONAL_HDR64_MAGIC:
{
printf("64λ³ÌÐò\n");
//È·¶¨Îª64λ³ÌÐòºó£¬¾Í¿ÉÒÔʹÓÃ_IMAGE_NT_HEADERS64À´½ÓÊÕÊý¾ÝÁË
//´´½¨Ö¸ÏòPEÎļþÍ·µÄÖ¸Õë
_IMAGE_NT_HEADERS64* nt;
nt = (_IMAGE_NT_HEADERS64*)peId;
printf("Machine:%X\n", nt->FileHeader.Machine);
printf("Magic:%X\n", nt->OptionalHeader.Magic);
//´´½¨Ò»¸öÖ¸ÕëÊý×飬¸ÃÖ¸ÕëÊý×éÓÃÀ´´æ´¢ËùÓеĽڱíÖ¸Õë
//ÕâÀïÏ൱ÓÚ_IMAGE_SECTION_HEADER* sectionArr[nt->FileHeader.NumberOfSections],ÉùÃ÷ÁËÒ»¸ö¶¯Ì¬Êý×é
_IMAGE_SECTION_HEADER** sectionArr = (_IMAGE_SECTION_HEADER**)malloc(sizeof(_IMAGE_SECTION_HEADER*) * nt->FileHeader.NumberOfSections);
//´´½¨Ö¸Ïò¿é±íµÄÖ¸Õë
_IMAGE_SECTION_HEADER* sectionHeader;
//Èÿé±íµÄÖ¸ÕëÖ¸ÏòÆä¶ÔÓ¦µÄµØÖ·£¬Çø±ðÔÚÓÚÕâÀï¼ÓÉϵÄÆ«ÒÆΪ_IMAGE_NT_HEADERS64
sectionHeader = (_IMAGE_SECTION_HEADER*)((UINT)nt + sizeof(_IMAGE_NT_HEADERS64));
//¼ÆÊý£¬ÓÃÀ´¼ÆËã¿é±íµØÖ·
int cnt = 0;
//±È½Ï ¼ÆÊý ºÍ ¿é±íµÄ¸öÊý£¬¼´±éÀúËùÓпé±í
while (cnt < nt->FileHeader.NumberOfSections) {
//´´½¨Ö¸Ïò¿é±íµÄÖ¸Õë
_IMAGE_SECTION_HEADER* section;
//Èÿé±íµÄÖ¸ÕëÖ¸ÏòÆä¶ÔÓ¦µÄµØÖ·=µÚÒ»¸ö¿é±íµØÖ·+¼ÆÊý*¿é±íµÄ´óС
section = (_IMAGE_SECTION_HEADER*)((UINT)sectionHeader + sizeof(_IMAGE_SECTION_HEADER) * cnt);
//½«µÃµ½µÄ¿é±íÖ¸Õë´æÈëÊý×é
sectionArr[cnt++] = section;
//Êä³ö¿é±íÃû³Æ
printf("%s\n", section->Name);
}
break;
}
default:
{
printf("error!\n");
break;
}
}
return 0;
}
ÔËÐнá¹û
¿ÉÒÔ¿´µ½ÔËÐнá¹ûºÍÇ°ÃæÊÖ¶¯·ÖÎöµÄÒ»Ö£¬²¢ÇÒ¼ÈÄܽâÎö³öº¯ÊýÃûÒ²ÄܽâÎö³öº¯ÊýÐòºÅ
ÔÙÓÃPE¹¤¾ß£ºDIEÑéÖ¤Ò»ÏÂ
½á¹ûÊÇÒ»Öµģ¬´úÂ벿·ÖÍê³Éq(¨R¨Œ¨Qq)
´úÂë˵Ã÷
Õâ´ÎµÄ´úÂ벿·ÖÆäʵºÍÏÈÇ°µÄ½âÎöµ¼³ö±íÄѶȲ¶à
ҪעÒâµÄ¾ÍÊǽâÎöIMAGE_THUNK_DATAʱ£¬ÒªÏÈÅжÏÆä×î¸ßλ£»¸ù¾Ý×î¸ßλÊÇ·ñΪ1À´½øÐÐÀàÐÍת»»ºÍ½â¶Á
×ܽá
- µ¼³ö±í×î¶àÖ»ÓÐÒ»ÕÅ£¬¶øµ¼Èë±íͨ³£²»Ö»Ò»ÕÅ
- µ¼Èë±í¾ßÓÐË«ÇŽṹ£¬Ë«ÇŽṹÖеÄIATÔÚPEÎļþÔËÐÐÇ°ºÍPEÎļþÔËÐкóÄÚÈݲ»Í¬
- ÎÞÂÛÊÇINT»¹ÊÇIATÔÚPEÎļþÔËÐÐÇ°ÆäÄÚÈÝÊÇÒ»Öµģ¬½á¹¹¶¼ÎªIMAGE_THUNK_DATA
- ÎÞÂÛÊÇINT»¹ÊÇIATÔÚPEÎļþÔËÐÐÇ°£¬Æä´æ´¢µÄÄÚÈݹé¸ù½áµ×ҪôÊǵ¼³öº¯ÊýÐòºÅ£¬ÒªÃ´¾ÍÊǵ¼³öº¯ÊýÃû³Æ
- ͨ¹ýµ¼³öº¯ÊýÐòºÅºÍµ¼³öº¯ÊýÃû³ÆÔÙ¼ÓÉÏÄ£¿éÃû¾Í¿ÉÒÔ¸ù¾Ýµ¼³ö±í»ñÈ¡µ½¶ÔÓ¦µÄº¯ÊýµØÖ·
¸½¼þ
¸½Éϱ¾±Ê¼ÇÖзÖÎöµÄEverEditÎļþ£ºµãÎÒÏÂÔØ