Phân tích cấu trúc PE file

24 233 0
Phân tích cấu trúc PE file

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Cấu trúc PE file đọc PE file Tháng 8/ 2018 Trang Mục Lục I MỤC TIÊU • Tìm hiểu cấu trúc File PE bao gồm: o DOS MZ Header o PE Header: Signature, File Header, Optional Header o Section Header o Section Table • Viết chương trình đọc File PE gồm chức năng: o Kiểm tra có phải file PE hợp lệ hay khơng o Hiển thị liệu dạng HEX o Hiển thị giá trị DOS MZ Header o Hiển thị giá trị PE Header  Signature  File Header Trang Optional Header: Phần Data Directory hiển thị liệu Import Descriptor, Export Directory o Hiển thị liệu Section Table  II CẤU TRÚC FILE PE PE file định dạng file riêng Win32 Tất file thực thi Win32( ngoại trừ tập tin VxDs file Dlls 16 bit) sử dụng định dạng file PE Các file Dlls 32 bit, file Dlls 32 bit, file COMS, điều khiền OCX, chương trình ứng dụng nhỏ Control Pannel( CPL files) ứng dụng NET tất định dạng file PE Thậm chí chương trình điều khiển Kernel mode hệ điều hành NT sử dụng định dạng PE Cấu trúc file PE: DOS MZ Header DOS stub PE header Section table Section Section … Section n III MS-DOS HEADER Tất file PE bắt đầu DOS HEADER, vùng chiếm giữ 64 bytes file Nó bao gồm 19 thành phần có có thành phần đáng ý : e_magic e_lfanew Trang • Thành phần e_magic DOS header chứa giá trị 4Dh 5Ah( ký tự “M” “Z” ) Mark Zbikowsky người sáng tạo MS-DOS (MZ bytes mà bạn nhìn thấy file PE nào) • Thành phần e_lfanew giá trị DWORD( double word=4 bytes), nằm vị trí cuối DOS Header nằm vị trí bắt đầu DOS Stub, chứa offset PE Header • Các ánh xạ file thường sử dụng chúng nạp vào nhớ sử dụng file cách dễ dàng Khi sử dụng win32 API đọc file PE thì: Trang LBase CreateFile(): //Open the Exe File hFile = CreateFile("D:\\Test\\no.exe", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) { printf("\nERROR : Could not open the file specified\n"); _getch(); } • Hàm sử dụng để tạp mở file Nó mở file, pipe, stream thiết bị I/O có sẵn tạo file mở Ban đầu file đọc Disk sau lưu trữ tồn nội dung file PE vào Physical Memory sử dụng hàm sau: hMapObject = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL); Một File Mapping Object Map tới nhiều file View sử dụng hàm: lpBase = MapViewOfFile(hMapObject, FILE_MAP_READ, 0, 0, 0);  Hàm MapViewOfFile() trả trỏ trỏ đến địa sở ánh xạ FileView, pointer sử dụng để truy cập nhớ, nhờ mà ta đọc ghi vị trí file Ta gán vị trí trỏ dosHeader =lpBase có giá trị default 0x04000000 //Get the DOS Header Base dosHeader = (PIMAGE_DOS_HEADER)lpBase;// 0x04000000 Kiểm tra xem có phải file PE hợp lệ hay không: if (dosHeader->e_magic == IMAGE_DOS_SIGNATURE) { //Dump the Dos Header info Trang dumMSDOSHeader(dosHeader); } else { printf("\nGiven File is not a valid DOS file\n"); goto end; } Code hiển thị liệu MS DOS: void dumMSDOSHeader(PIMAGE_DOS_HEADER dosHeader) { printf("\nValid Dos Exe File\n \n"); printf("\nDumping DOS Header Info \n -"); printf("\n%-36s%s ", "Magic number : ", dosHeader->e_magic == 0x5a4d ? "MZ(Mark Zbikowski)" : "-"); printf("\n%-36s%#x", "Bytes on last page of file :", dosHeader>e_cblp); printf("\n%-36s%#x", "Pages in file : ", dosHeader->e_cp); printf("\n%-36s%#x", "Relocation : ", dosHeader->e_crlc); printf("\n%-36s%#x", "Size of header in paragraphs : ", dosHeader>e_cparhdr); printf("\n%-36s%#x", "Minimum extra paragraphs needed : ", dosHeader->e_minalloc); printf("\n%-36s%#x", "Maximum extra paragraphs needed : ", dosHeader->e_maxalloc); printf("\n%-36s%#x", "Initial (relative) SS value : ", dosHeader>e_ss); printf("\n%-36s%#x", "Initial SP value : ", dosHeader->e_sp); printf("\n%-36s%#x", "Checksum : ", dosHeader->e_csum); printf("\n%-36s%#x", "Initial IP value : ", dosHeader->e_ip); printf("\n%-36s%#x", "Initial (relative) CS value : ", dosHeader>e_cs); printf("\n%-36s%#x", "File address of relocation table : ", dosHeader->e_lfarlc); printf("\n%-36s%#x", "Overlay number : ", dosHeader->e_ovno); printf("\n%-36s%#x", "OEM identifier : ", dosHeader->e_oemid); printf("\n%-36s%#x", "OEM information(e_oemid specific) :", dosHeader->e_oeminfo); printf("\n%-36s%#x", "RVA address of PE header : ", dosHeader>e_lfanew); printf("\n=========================================== ====================================\n"); } IV PE HEADER PE Header thuật ngữ chung đại diện cho cấu trúc đặt tên IMAGE_NT_HEADERS Cấu trúc bao gồm thành phần định nghĩa file windows.inc sau: Trang Con trỏ trỏ đến NT HEADER tính trỏ đầu file + địa RVA PE Header //Get the Base of NT Header(PE Header) = lpBase + RVA address of PE header ntHeader = (PIMAGE_NT_HEADERS)((DWORD)lpBase + (dosHeader->e_lfanew)); • Signature: Là biến DWORD chứa giá trị sau: 50h, 45h, 00( ký tự “PE” kèm giá trị tận 0) Chúng ta cần kiểm tra giá trị để xem có phải file PE hợp lệ hay không: if (ntHeader->Signature == IMAGE_NT_SIGNATURE) { printf("NTHEADER: %x", ntHeader); printf("\nValid PE file \n -\n"); ………………… } • FileHeader ( 20bytes) IMAGE_FILE_HEADERS: chứa thơng tin sơ đồ bố trí vật lý nhũng đặc tính file Ví dụ: số lượng section,… o FileHeader định nghĩa sau: Trong cấu trúc thành phần cần quan tâm NumberOfSections Trong trường hợp muốn thêm xóa sections file PE thành phần phải thay đổi Characteristics bao gồm cờ mà cờ xác định thể để biết làm việc với file dll hay file thực thi Code hiển thị thông tin File Header: void DumFileHeader(PIMAGE_NT_HEADERS ntHeader) { //Get the IMAGE FILE HEADER Structure IMAGE_FILE_HEADER header = ntHeader->FileHeader; //Determine Machine Architechture printf("\n%-36s", "Machine Architechture :"); checkMachineOfFileHeader(header); //Determine the characteristics of the given file printf("\n%-36s %#x \n", "Characteristics:", header.Characteristics); checkCharacteristics(header); char buff[40]; Trang printf("\n%-36s%x", "Time Stamp :", header.TimeDateStamp); ctime_s(buff, sizeof buff, &(header.TimeDateStamp)); printf("- %s\n", buff); //Determine Time Stamp printf("%-36s%d", "No.sections(size) :", header.NumberOfSections); //Determine number of sections printf("\n%-36s%d", "No.entries in symbol table :", header.NumberOfSymbols); printf("\n%-36s%d", "Size of optional header :", header.SizeOfOptionalHeader); } Trên Lord xác định sau: • Optional Header( 224 bytes tiếp theo) IMAGE_OPTINAL_HEADER32: chứa thông tin sơ đồ logic bên file PE Ví dụ: AddressOpEntryPoint Kích thước quy định thành phần FileHeader Các cấu trúc thành phần định nghĩa file windows.h o Optional Header định nghĩa sau: Trang      AddressOfEntryPoint- RVA(địa tương đối ) câu lệnh mà thực thi chương trình PE Loader sẵn sàng để run PE File( thơng thường trỏ tới section text ) hay CODE Magic: Xác định xem nhị phân 32 bit hay 64 bit • 0x10B: 32 bit • 0x20B: 64 bit ImageBase- Địa nạp ưu tiên cho PE file Lấy ví dụ: Nếu giá trị trường hợp 400000h, Pe Loader cố gắng để nạp vào không gian địa ảo mà bắt đầu 4000000h Từ ưu tiên vào có nghĩ PE Loader khơng thể nạp file địa có module khác chiếm giữ vùng địa này, 99% trường hợp giá trị ImageBase 400000h SectionAlignment- Phần liên kết Sections nhớ Khi file thực thi ánh xạ vào nhớ section phải bắt đầu địa ảo mà bội số giá trị Ví dụ: Nếu giá trị trường 4096(1000h) section phải bắt đầu vị trí mà section trước cộng với 4096 bytes Nếu section 401000h kích thước 10 bytes, section 402000h cho dù không gian địa 401000h 402000h hầu không sử dụng FileAlignment- Phần liên kết Section file Ví dụ: giá trị cụ thể trường 512(200h) secti(tương tự SectionAlignment) Trang    SizeOfImage- Tồn kích thước PE Image nhớ I SizeOfHeader- Kích thước tất headers+section table Tóm lại Kích thước file- kích thước tổng hợp tồn sections file Có thể dùng giá trị file offset section file PE DataDirectoryMột mảng 16 IMAGE_DATA_DIRECTORY structures, phần có liên quan tới cấu trúc liệu quan trọng PE file chẳng hạn import address table Code hiển thị thông tin Optional Header: void DumOptionalHeader(PIMAGE_NT_HEADERS ntHeader) { printf("\n\nDumping PE Optional Header Info \n -"); //Info about Optional Header IMAGE_OPTIONAL_HEADER opHeader = ntHeader->OptionalHeader; //printf("\n\nInfo of optional Header\n -"); printf("\n%-36s%#x", "Address of Entry Point : ", opHeader.AddressOfEntryPoint); printf("\n%-36s%#x", "Base Address of the Image : ", opHeader.ImageBase); printf("\n%-36s%s", "SubSystem type : ", opHeader.Subsystem == ? "Device Driver(Native windows Process)" : opHeader.Subsystem == ? "Windows GUI" : opHeader.Subsystem == ? "Windows CLI" : opHeader.Subsystem == ? "Windows CE GUI" : "Unknown" ); printf("\n%-36s%s", "Given file is a : ", opHeader.Magic == 0x20b ? "PE32+(64)" : "PE32"); printf("\n%-36s%d", "Size of code segment(.text) : ", opHeader.SizeOfCode); printf("\n%-36s%#x", "Base address of code segment(RVA) :", opHeader.BaseOfCode); printf("\n%-36s%d", "Size of Initialized data : ", opHeader.SizeOfInitializedData); printf("\n%-36s%#x", "Base address of data segment(RVA) :", opHeader.BaseOfData); printf("\n%-36s%#x", "Section Alignment :", opHeader.SectionAlignment); printf("\n%-36s%d", "Major Linker Version : ", opHeader.MajorLinkerVersion); printf("\n%-36s%d", "Minor Linker Version : ", opHeader.MinorLinkerVersion); Trang 10 } Trên Lord xác định sau: Cấu trúc DATA DIRECTORY Data Directory 128 bytes cuối OptionalHeader, thành phần cuối IMAGE_NT_HEADERS Cấu trúc Data Directory có thành phần mà bao gồm thơng tin vị trí kích thước cấu trúc liệu o VirtualAddress: địa ảo tương đối (relative virtual address) cấu trúc liệu o isize: bao gồm kích thước theo bytes cấu trúc liệu o 16 directories mà cấu trúc tham chiếu đến, thân chúng được nghĩa file window.inc: Trang 11 Trong chương trình đọc file PE giá trị xác định sau: Virtual Address isize Trên hình minh họa , vị trí tơ màu hồng Import Table, với bytes đầu Virtual Address= 02D000h bytes cuối thể kích thước cấu trúc Import = 181Eh Trong win32 fuction, giá trị xác định sau: dwImportDirectoryVA = ntHeader->OptionalHeader.DataDirectory[1].VirtualAddress; ImportSize = ntHeader->OptionalHeader.DataDirectory[1].Size; với ntHeader trỏ trỏ đến cấu trúc IMAGE_NT_HEADER Để xác định vị trí directory đặc biệt, bạn xác định rõ địa tương đối từ data directory Sau sử dụng địa ảo để xác định section directory Một bạn phân tích section chứa directory, Section Header cho section sau sử dụng để tìm offset xác Ở cần xác định khái niệm RVA( relative virtual address) VA( virtual address) VA địa mà file nạp RVA xác định địa mà file nạp trừ Image Base RVA=VA- Image Base Ví dụ: Nếu File PE nạp địa 400000h virtual address(VA) space chương trình bắt đầu thực thi virtual address 401000h, nói chương trình bắt đầu thực thi RVA 1000h Trang 12 Tại lại sử dụng RVA? Đó để giảm q trình nạp trình loader Đó module relocated vị trí khơng gian địa ảo, gây trở ngại cho trình loader để fix hardcode address module Nhưng ngược lại, tất relocatable items file use RVA, there is no need for the loader to fix anything: đơn giản relocates toàn module tới new starting VA Chuyển đổi từ Virtual Offset đến RawOfsset: Công thức chung là: RVA= RawOffset_YouHaveRawOffsetOfSection+VirtualOffsetOfSection+ImageBase • IMAGE_EXPORT_DIRECTORY: trỏ tới mảng bảng chuỗi ký tự ASCII Mảng quan trọng Export Address Table( EAT), mảng trỏ hàm mà chứa địa export functions Hai mảng Export Name table Export Ordinal Table chạy song song theo thứ tự xếp tăng dần dựa theo tên hàm để thực đưa kết số thứ tự hàm tìm thấy vào mảng khác Trang 13 Thơng thường, NumberOfFunction phải NumberOfNames Tuy nhiên số trường hợp NumberOfNames NumberFunctions Khi hàm Export thơng quan số thứ tự, khơng có danh sách mảng ENT EOT- khơng có tên Những hàm khơng có tên Export thông qua số thứ tự Code hiển thị nội dung Export: void DumpExportDirectory32(LPVOID lpBase, PIMAGE_NT_HEADERS32 ntHeader, PIMAGE_DOS_HEADER dosHeader) { DWORD dwExportDirectoryVA, ExportSize, dwRawOffset; dwExportDirectoryVA = ntHeader>OptionalHeader.DataDirectory[0].VirtualAddress; //get address of ExportDirectory ExportSize = ntHeader->OptionalHeader.DataDirectory[0].Size; //get size of ExportDirectory Trang 14 if (dwExportDirectoryVA == 0) { printf("Export is NULL!\n"); } PIMAGE_SECTION_HEADER pSectionHeader = IMAGE_FIRST_SECTION(ntHeader); dwRawOffset = (DWORD)lpBase + pSectionHeader->PointerToRawData; PIMAGE_EXPORT_DIRECTORY pExportDirectory = (PIMAGE_EXPORT_DIRECTORY)(dwRawOffset + (dwExportDirectoryVA pSectionHeader->VirtualAddress)); printf("\nNumberOfFunctions: %d\n", pExportDirectory->NumberOfFunctions); printf("Address Of Function: %#x\n", pExportDirectory->AddressOfFunctions); printf("Address Of Name: %#x\n", pExportDirectory->AddressOfNames); printf("Address Of Name Ordinals: %#x\n", pExportDirectory>AddressOfNameOrdinals); printf("Ordinal Base: %d\n", pExportDirectory->Base); printf("Name RVA: %s\n", pExportDirectory->Name); char* buff[50]; ctime_s(buff, sizeof(buff), &pExportDirectory->TimeDateStamp); printf("Time Date Stamp: %s\n",buff); //get an array to store Name of Functions(Import from Name) DWORD32* name = (DWORD32*)((DWORD32)lpBase + (DWORD32)pExportDirectory->AddressOfNames + pSectionHeader>PointerToRawData - pSectionHeader->VirtualAddress); //get an array to store Address of FUnctions DWORD32* address = (DWORD32*)((DWORD32)lpBase + (DWORD32)pExportDirectory->AddressOfFunctions + pSectionHeader>PointerToRawData - pSectionHeader->VirtualAddress); //DWORD32* Ordinal = (DWORD32*)((DWORD32)lpBase + (DWORD32)pExportDirectory->AddressOfNameOrdinals + pSectionHeader>PointerToRawData - pSectionHeader->VirtualAddress); DWORD32 funcName, funcAddress, ordinal; if (strlen(name) != 0) { for (int i = 0; i < (DWORD32)pExportDirectory->NumberOfNames; i++) { funcName = name[i]; funcAddress = address[i]; ordinal = Ordinal[i]; printf("\nFunctions :%s \n", funcName + dwRawOffset pSectionHeader->VirtualAddress); printf("Address: %#x \n", funcAddress ); } else { printf("\nExport Directiory is Null.\n"); } } printf("\n========================================= ======================================\n"); Sau chạy ta kết sau( file lấy test wincredui.dll System32): Trang 15 Trang 16 Đối chiếu với kết PE View: Trang 17 • IMAGE_IMPORT_DESCRIPTOR(IID) Các thành phần quan trọng tên imported DLL mảng cảu cấu trúc IMAGE_THUNK_DATA Mỗi cấu trúc IMAGE_THUNK_DATA tương ứng với imported function từ DLL Số lượng phần tử mảng OriginalFirstThunk FirstThunk phụ thuộc vào số lượng hàm imported từ file DLL Hai mảng song song, tương đương gọi tên khác tên chung Import Address Table( cho gọi FirstThunk) Import Name Table hay Import Lookup Table(cho trỏ OrginalFirstThunk) Trong phần thử hiển thị liệu Import Table cách tính RVA Import Table (chuyển đổi qua RawOffset) Code hiển thị nội dung phần Import: Trang 18 void DumpImportDirectory64(LPVOID lpBase, PIMAGE_NT_HEADERS64 ntHeader, PIMAGE_DOS_HEADER dosHeader) { // Get Information of Data Diractory DWORD dwImportDirectoryVA, dwSectionCount, dwSection = 0, dwRawOffset, ImportSize; dwImportDirectoryVA = ntHeader>OptionalHeader.DataDirectory[1].VirtualAddress; ImportSize = ntHeader->OptionalHeader.DataDirectory[1].Size; dwSectionCount = ntHeader->FileHeader.NumberOfSections; printf("\n======================================= ========================================\n"); printf("RVA: %#x\n", dwImportDirectoryVA); printf("SIZE: %#x\n", ImportSize); //the pointer beginning of section=pointer of NtHeader+pointer of size of Nt header //size_of_IMAGE_NT_HEADERS64 PIMAGE_SECTION_HEADER pSectionHeader = (PIMAGE_SECTION_HEADER)((DWORD)lpBase + (dosHeader->e_lfanew) + sizeof(IMAGE_NT_HEADERS64)); for (; dwSection < dwSectionCount && pSectionHeader->VirtualAddress PointerToRawData; PIMAGE_IMPORT_DESCRIPTOR pImportDescriptor = (PIMAGE_IMPORT_DESCRIPTOR)(dwRawOffset + (dwImportDirectoryVA pSectionHeader->VirtualAddress)); printf("Section Header Last: %#x\n", pSectionHeader); for (; pImportDescriptor->Characteristics; pImportDescriptor++) { int count = 0; printf("\nDLL Name : %s\n\n", dwRawOffset + (pImportDescriptor->Name - pSectionHeader->VirtualAddress)); PIMAGE_THUNK_DATA64 pThunkData = (PIMAGE_THUNK_DATA64)( dwRawOffset + (pImportDescriptor>FirstThunk - pSectionHeader->VirtualAddress)); +) { { for (; pThunkData->u1.AddressOfData != 0; pThunkData+ if (pThunkData->u1.AddressOfData != 0x80000011) printf("\tFunction : %s \n", (dwRawOffset + (pThunkData->u1.AddressOfData - pSectionHeader->VirtualAddress + 2))); count++; Trang 19 } else { printf("\tFunction : %x \n", (dwRawOffset + (pThunkData->u1.AddressOfData - pSectionHeader->VirtualAddress + 2))); } } printf("So Function la: %d", count); } pSectionHeader = IMAGE_FIRST_SECTION(ntHeader); if (pSectionHeader->SizeOfRawData != 0) HexDump((char *)(dwRawOffset), pSectionHeader>SizeOfRawData, pSectionHeader->VirtualAddress); printf("======================================== =================="); } Sau lấy liệu Import Data Directory ta có kết quả: ( file lấy test file Unikey.exe): Trang 20 Đối chiếu với kết đọc file PE View ta được: V SECTION HEADER Là thành phần sau PE Header Nó mảng cấu trúc IMAGE_SECTION_HEADER, phẫn tử thông tin seciton PE File ví dụ thuộc tính offset ảo( virtual offset) Số lượng Section thành phần thứ File Header ( NumberOfSection) Nếu có Sections PE file có cấu trúc table Mỗi cấu trúc Header 40 bytes khơng có thêm padding chúng( có nghĩa khơng chèn thêm bytes có giá trị 00h).Cấu trúc định nghĩa file windows.inc sau: Trang 21 • • • • • VirtualSize: Kích thước thật section’s data theo bytes Nó kích thước section đĩa (SizeOfRawData) VirtualAddress- RVA section Trình PE loader phân tích sử dụng giá trị trường ánh xạ section vào nhớ Vì giá trị trường 1000h PE file nạp địa 4000000h section nạp địa 401000h SizeOfRawData: Kích thước section data file đĩa, làm tròn lên bội số liên kết trình biên dịch PointerToRawData( Raw Offset) thành phần thực hữu dụng offset từ vị trí bắt đầu file phần section data Nếu có giá trị 0, section’s data khơng chứa file khơng bị bó buộc vào thười gian nạp (load time) Trình PE Loader sử dụng giá trị trường để tìm kiếm phần data section data section đâu file Characteristics: Bao gồm cờ ví dụ section chứa executable code, initialized data, uninitialized data, ghi đọc Hiển thị thông tin Section: void DumSectionHeader(PIMAGE_SECTION_HEADER pSecHeader, PIMAGE_NT_HEADERS ntHeader) { printf("\n\nDumping Sections Header Info \n "); //Retrive a pointer to First Section Header(or Section Table Entry) int i; for (pSecHeader, i = 0; i < ntHeader->FileHeader.NumberOfSections; i++, pSecHeader++) { printf("\n\nSection Info (%d of %d)", i + 1, ntHeader>FileHeader.NumberOfSections); printf("\n -"); printf("\n%-36s%s", "Section Header name : ", pSecHeader->Name); printf("\n%-36s%#x", "ActualSize of code or data : ", pSecHeader>Misc.VirtualSize); printf("\n%-36s%#x", "Virtual Address(RVA) :", pSecHeader>VirtualAddress); printf("\n%-36s%#x", "Size of raw data (rounded to FA) : ", pSecHeader>SizeOfRawData); printf("\n%-36s%#x", "Pointer to Raw Data : ", pSecHeader>PointerToRawData); Trang 22 printf("\n%-36s%#x", "Pointer to Relocations : ", pSecHeader>PointerToRelocations); printf("\n%-36s%#x", "Pointer to Line numbers : ", pSecHeader>PointerToLinenumbers); printf("\n%-36s%#x", "Number of relocations : ", pSecHeader>NumberOfRelocations); printf("\n%-36s%#x", "Number of line numbers : ", pSecHeader>NumberOfLinenumbers); printf("\n%-36s%s%#x", "Characteristics : ", "Contains ", pSecHeader>Characteristics); checkCharacteristicsofSection(pSecHeader); } } Giá trị pSection xác định trỏ trỏ đến offset đầu SECTION_HEADER: tiên pSecHeader = IMAGE_FIRST_SECTION(ntHeader); sử dụng function win32, tính sau: //the pointer beginning of section=pointer of NtHeader+pointer of size of Nt header PIMAGE_SECTION_HEADER pSectionHeader = (PIMAGE_SECTION_HEADER) ((DWORD)lpBase + (dosHeader->e_lfanew) + sizeof(IMAGE_NT_HEADERS)); Trên Lord, giá trị xác định sau: VI LƯU Ý Trang 23 Trong phần DOS Header, cần lưu ý tới 02 trường: e_magic e_lfanew o Trong phần COFF File Header, cần lưu ý tới trường: NumberOfSections o Trong phần Optional Header, cần quan tâm tới số trường: AddressOfEntryPoint (RVA), ImageBase, SectionAlignment, FileAlignment, SizeOfImage, SizeOfHeaders DataDirectory o Cuối cùng, bảng section, số trường cần quan tâm: VirtualSize, VirtualAddress, SizeOfRawData, PointerToRawData, Characteristics Ngoài ra, cần quan tâm tới vị trí tương đối trường kích thước tương ứng chúng PE file o Trang 24 ... II CẤU TRÚC FILE PE PE file định dạng file riêng Win32 Tất file thực thi Win32( ngoại trừ tập tin VxDs file Dlls 16 bit) sử dụng định dạng file PE Các file Dlls 32 bit, file Dlls 32 bit, file. .. dụng file cách dễ dàng Khi sử dụng win32 API đọc file PE thì: Trang LBase CreateFile(): //Open the Exe File hFile = CreateFile("D:\Test\no.exe", GENERIC_READ, FILE_ SHARE_READ, NULL, OPEN_EXISTING,... Control Pannel( CPL files) ứng dụng NET tất định dạng file PE Thậm chí chương trình điều khiển Kernel mode hệ điều hành NT sử dụng định dạng PE Cấu trúc file PE: DOS MZ Header DOS stub PE header Section

Ngày đăng: 09/07/2019, 10:32

Từ khóa liên quan

Mục lục

  • I. MỤC TIÊU

  • II. CẤU TRÚC FILE PE

  • III. MS-DOS HEADER

  • IV. PE HEADER

    • Signature:

    • FileHeader ( 20bytes)

    • Optional Header( 224 bytes tiếp theo)

      • Cấu trúc DATA DIRECTORY

      • V. SECTION HEADER

      • VI. LƯU Ý

Tài liệu cùng người dùng

Tài liệu liên quan