Nytro Posted February 8, 2009 Report Posted February 8, 2009 PORTABLE EXECUTABLE FORMAT Author: Micheal J. O'Leary Preface This document was edited and released by Microsoft Developer Support. It describes the binary portable executable format for NT. The information is provided at this point because we feel it will make the work of application development easier. Unfortunately, the information in this document may change before the final release of Windows NT. Microsoft is NOT committing to stay with these formats by releasing this document. Questions or follow-ups for any of the information presented here should be posted to CompuServe MSWIN32 forum, section 6. --Steve Firebaugh Microsoft Developer SupportContents 1. Overview 2. PE Header 3. Object Table 4. Image Pages 5. Exports 5.1 Export Directory Table 5.2 Export Address Table 5.3 Export Name Table Pointers 5.4 Export Ordinal Table 5.5 Export Name Table 6. Imports 6.1 Import Directory Table 6.2 Import Lookup Table 6.3 Hint-Name Table 6.4 Import Address Table 7. Thread Local Storage 7.1 Thread Local Storage Directory Table 7.2 Thread Local Storage CallBack Table 8. Resources 8.1 Resource Directory Table 8.2 Resource Example 9. Fixup Table 9.1 Fixup Block 10. Debug Information 10.1 Debug Directory1. Overview ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ <ÄÄ¿ <ÄÄÄÄÄ Base of Image Header ³ DOS 2 Compatible ³ ³ ³ EXE Header ³ ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ ³ unused ³ ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ ³ OEM Identifier ³ ³ ³ OEM Info ³ ³ ³ ³ ³ DOS 2.0 Section ³ Offset to ³ ³ (for DOS compatibility only) ³ PE Header ³ ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ ³ DOS 2.0 Stub ³ ³ ³ Program & ³ ³ ³ Reloc. Table ³ ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ <ÄÄÙ ³ unused ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ <ÄÄÄÄÄÄÄÄÄ Aligned on 8 byte boundary ³ PE Header ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ Object Table ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ Image Pages ³ ³ import info ³ ³ export info ³ ³ fixup info ³ ³ resource info³ ³ debug info ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙFigure 1. A typical 32-bit Portable EXE File Layout2. PE Header ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ SIGNATURE BYTES ³ CPU TYPE ³ # OBJECTS ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ TIME/DATE STAMP ³ RESERVED ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ RESERVED ³ NT HDR SIZE³ FLAGS ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÂÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ RESERVED ³LMAJOR³LMINOR³ RESERVED ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÁÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ RESERVED ³ RESERVED ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ ENTRYPOINT RVA ³ RESERVED ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ RESERVED ³ IMAGE BASE ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ OBJECT ALIGN ³ FILE ALIGN ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ OS MAJOR ³ OS MINOR ³USER MAJOR ³USER MINOR ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ SUBSYS MAJOR³ SUBSYS MINOR³ RESERVED ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ IMAGE SIZE ³ HEADER SIZE ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ FILE CHECKSUM ³ SUBSYSTEM ³ DLL FLAGS ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ STACK RESERVE SIZE ³ STACK COMMIT SIZE ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ HEAP RESERVE SIZE ³ HEAP COMMIT SIZE ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ RESERVED ³ # INTERESTING RVA/SIZES ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ EXPORT TABLE RVA ³ TOTAL EXPORT DATA SIZE ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ IMPORT TABLE RVA ³ TOTAL IMPORT DATA SIZE ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ RESOURCE TABLE RVA ³ TOTAL RESOURCE DATA SIZE ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ EXCEPTION TABLE RVA ³ TOTAL EXCEPTION DATA SIZE³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ SECURITY TABLE RVA ³ TOTAL SECURITY DATA SIZE ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ FIXUP TABLE RVA ³ TOTAL FIXUP DATA SIZE ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ DEBUG TABLE RVA ³ TOTAL DEBUG DIRECTORIES ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ IMAGE DESCRIPTION RVA ³ TOTAL DESCRIPTION SIZE ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ MACHINE SPECIFIC RVA ³ MACHINE SPECIFIC SIZE ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ THREAD LOCAL STORAGE RVA ³ TOTAL TLS SIZE ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙFigure 2. PE HeaderNotes: o A VA is a virtual address that is already biased by the Image Base found in the PE Header. A RVA is a virtual address that is relative to the Image Base. o An RVA in the PE Header which has a value of zero indicates the field isn't used. o Image pages are aligned and zero padded to a File Align boundary. The bases of all other tables and structures must be aligned on DWORD (4 byte) boundary. Thus, all VA's and RVA's must be on a 32 bit boundary. All table and structure fields must be aligned on their "natural" boundaries, with the possible exception of the Debug Info.SIGNATURE BYTES = DB * 4.Current value is "PE/0/0". Thats PE followed by two zeros (nulls).CPU TYPE = DW CPU Type.This field specifies the type of CPU compatibility required by thisimage to run. The values are: o 0000h __unknown o 014Ch __80386 o 014Dh __80486 o 014Eh __80586 o 0162h __MIPS Mark I (R2000, R3000) o 0163h __MIPS Mark II (R6000) o 0166h __MIPS Mark III (R4000)# OBJECTS = DW Number of object entries.This field specifies the number of entries in the Object Table.TIME/DATE STAMP = DD Used to store the time and date the file wascreated or modified by the linker.NT HDR SIZE = DW This is the number of remaining bytes in the NTheader that follow the FLAGS field.FLAGS = DW Flag bits for the image.The flag bits have the following definitons: o 0000h __Program image. o 0002h __Image is executable. If this bit isn't set, then it indicates that either errors where detected at link time or that the image is being incrementally linked and therefore can't be loaded. o 0200h __Fixed. Indicates that if the image can't be loaded at the Image Base, then don't load it. o 2000h __Library image.LMAJOR/LMINOR = DB Linker major/minor version number.ENTRYPOINT RVA = DD Entrypoint relative virtual address.The address is relative to the Image Base. The address is thestarting address for program images and the library initializationand library termination address for library images.IMAGE BASE = DD The virtual base of the image.This will be the virtual address of the first byte of the file (DosHeader). This must be a multiple of 64K.OBJECT ALIGN = DD The alignment of the objects. This must be a powerof 2 between 512 and 256M inclusive. The default is 64K.FILE ALIGN = DD Alignment factor used to align image pages. Thealignment factor (in bytes) used to align the base of the image pagesand to determine the granularity of per-object trailing zero pad.Larger alignment factors will cost more file space; smaller alignmentfactors will impact demand load performance, perhaps significantly.Of the two, wasting file space is preferable. This value should be apower of 2 between 512 and 64K inclusive.OS MAJOR/MINOR = DW OS version number required to run this image.USER MAJOR/MINOR # = DW User major/minor version number.This is useful for differentiating between revisions ofimages/dynamic linked libraries. The values are specified at linktime by the user.SUBSYS MAJOR/MINOR # = DW Subsystem major/minor version number.IMAGE SIZE = DD The virtual size (in bytes) of the image.This includes all headers. The total image size must be a multipleof Object Align.HEADER SIZE = DD Total header size.The combined size of the Dos Header, PE Header and Object Table.FILE CHECKSUM = DD Checksum for entire file. Set to 0 by the linker.SUBSYSTEM = DW NT Subsystem required to run this image.The values are: o 0000h __Unknown o 0001h __Native o 0002h __Windows GUI o 0003h __Windows Character o 0005h __OS/2 Character o 0007h __Posix CharacterDLL FLAGS = DW Indicates special loader requirements.This flag has the following bit values: o 0001h __Per-Process Library Initialization. o 0002h __Per-Process Library Termination. o 0004h __Per-Thread Library Initialization. o 0008h __Per-Thread Library Termination.All other bits are reserved for future use and should be set to zero.STACK RESERVE SIZE = DD Stack size needed for image.The memory is reserved, but only the STACK COMMIT SIZE is committed.The next page of the stack is a 'guarded page'. When the applicationhits the guarded page, the guarded page becomes valid, and the nextpage becomes the guarded page. This continues until the RESERVE SIZEis reached.STACK COMMIT SIZE = DD Stack commit size.HEAP RESERVE SIZE = DD Size of local heap to reserve.HEAP COMMIT SIZE = DD Amount to commit in local heap.# INTERESTING VA/SIZES = DD Indicates the size of the VA/SIZE arraythat follows.EXPORT TABLE RVA = DD Relative Virtual Address of the Export Table.This address is relative to the Image Base.IMPORT TABLE RVA = DD Relative Virtual Address of the Import Table.This address is relative to the Image Base.RESOURCE TABLE RVA = DD Relative Virtual Address of the ResourceTable. This address is relative to the Image Base.EXCEPTION TABLE RVA = DD Relative Virtual Address of the ExceptionTable. This address is relative to the Image Base.SECURITY TABLE RVA = DD Relative Virtual Address of the SecurityTable. This address is relative to the Image Base.FIXUP TABLE RVA = DD Relative Virtual Address of the Fixup Table.This address is relative to the Image Base.DEBUG TABLE RVA = DD Relative Virtual Address of the Debug Table.This address is relative to the Image Base.IMAGE DESCRIPTION RVA = DD Relative Virtual Address of thedescription string specified in the module definiton file.MACHINE SPECIFIC RVA = DD Relative Virtual Address of a machinespecific value. This address is relative to the Image Base.TOTAL EXPORT DATA SIZE = DD Total size of the export data.TOTAL IMPORT DATA SIZE = DD Total size of the import data.TOTAL RESOURCE DATA SIZE = DD Total size of the resource data.TOTAL EXCEPTION DATA SIZE = DD Total size of the exception data.TOTAL SECURITY DATA SIZE = DD Total size of the security data.TOTAL FIXUP DATA SIZE = DD Total size of the fixup data.TOTAL DEBUG DIRECTORIES = DD Total number of debug directories.TOTAL DESCRIPTION SIZE = DD Total size of the description data.MACHINE SPECIFIC SIZE = DD A machine specific value.3. Object TableThe number of entries in the Object Table is given by the # Objectsfield in the PE Header. Entries in the Object Table are numberedstarting from one. The object table immediately follows the PEHeader. The code and data memory object entries are in the orderchosen by the linker. The virtual addresses for objects must beassigned by the linker such that they are in ascending order andadjacent, and must be a multiple of Object Align in the PE header.Each Object Table entry has the following format: ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ OBJECT NAME ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ VIRTUAL SIZE ³ RVA ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ PHYSICAL SIZE ³ PHYSICAL OFFSET ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ RESERVED ³ RESERVED ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ RESERVED ³ OBJECT FLAGS ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙFigure 3. Object TableOBJECT NAME = DB * 8 Object name. This is an eight-byte null-paddedASCII string representing the object name.VIRTUAL SIZE = DD Virtual memory size. The size of the object thatwill be allocated when the object is loaded. Any difference betweenPHYSICAL SIZE and VIRTUAL SIZE is zero filled.RVA = DD Relative Virtual Address. The virtual address the object iscurrently relocated to, relative to the Image Base. Each Object'svirtual address space consumes a multiple of Object Align (power of 2between 512 and 256M inclusive. Default is 64K), and immediatelyfollows the previous Object in the virtual address space (the virtualaddress space for a image must be dense).PHYSICAL SIZE = DD Physical file size of initialized data. The sizeof the initialized data in the file for the object. The physicalsize must be a multiple of the File Align field in the PE Header, andmust be less than or equal to the Virtual Size.PHYSICAL OFFSET = DD Physical offset for object's first page. Thisoffset is relative to beginning of the EXE file, and is aligned on amultiple of the File Align field in the PE Header. The offset isused as a seek value.OBJECT FLAGS = DD Flag bits for the object. The object flag bitshave the following definitions: o 000000020h __Code object. o 000000040h __Initialized data object. o 000000080h __Uninitialized data object. o 040000000h __Object must not be cached. o 080000000h __Object is not pageable. o 100000000h __Object is shared. o 200000000h __Executable object. o 400000000h __Readable object. o 800000000h __Writeable object.All other bits are reserved for future use and should be set to zero.4. Image PagesThe Image Pages section contains all initialized data for allobjects. The seek offset for the first page in each object isspecified in the object table and is aligned on a File Alignboundary. The objects are ordered by the RVA. Every object beginson a multiple of Object Align.5. ExportsA typical file layout for the export information follows: ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ DIRECTORY TABLE ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ ADDRESS TABLE ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ NAME PTR TABLE ³ ³ ³ ³ ³ ³ ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ ORDINAL TABLE ³ ³ ³ ³ ³ ³ ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ NAME STRINGS ³ ³ ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙFigure 4. Export File Layout5.1 Export Directory TableThe export information begins with the Export Directory Table whichdescribes the remainder of the export information. The ExportDirectory Table contains address information that is used to resolvefixup references to the entry points within this image. ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ EXPORT FLAGS ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ TIME/DATE STAMP ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ MAJOR VERSION ³ MINOR VERSION ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ NAME RVA ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ ORDINAL BASE ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ # EAT ENTRIES ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ # NAME PTRS ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ ADDRESS TABLE RVA ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ NAME PTR TABLE RVA ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ ORDINAL TABLE RVA ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙFigure 5. Export Directory Table EntryEXPORT FLAGS = DD Currently set to zero.TIME/DATE STAMP = DD Time/Date the export data was created.MAJOR/MINOR VERSION = DW A user settable major/minor version number.NAME RVA = DD Relative Virtual Address of the Dll asciiz Name.This is the address relative to the Image Base.ORDINAL BASE = DD First valid exported ordinal.This field specifies the starting ordinal number for the exportaddress table for this image. Normally set to 1.# EAT ENTRIES = DD Indicates number of entries in the Export AddressTable.# NAME PTRS = DD This indicates the number of entries in the Name PtrTable (and parallel Ordinal Table).ADDRESS TABLE RVA = DD Relative Virtual Address of the Export AddressTable.This address is relative to the Image Base.NAME TABLE RVA = DD Relative Virtual Address of the Export Name TablePointers.This address is relative to the beginning of the Image Base. Thistable is an array of RVA's with # NAMES entries.ORDINAL TABLE RVA = DD Relative Virtual Address of Export OrdinalsTable Entry.This address is relative to the beginning of the Image Base.5.2 Export Address TableThe Export Address Table contains the address of exported entrypointsand exported data and absolutes. An ordinal number is used to indexthe Export Address Table. The ORDINAL BASE must be subracted from theordinal number before indexing into this table.Export Address Table entry formats are described below: ÚÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄ¿ ³ EXPORTED RVA ³ ÀÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÙFigure 6. Export Address Table EntryEXPORTED RVA = DD Export address.This field contains the relative virtual address of the exportedentry (relative to the Image Base).5.3 Export Name Table PointersThe export name table pointers array contains address into the ExportName Table. The pointers are 32-bits each, and are relative to theImage Base. The pointers are ordered lexically to allow binarysearches.5.4 Export Ordinal TableThe Export Name Table Pointers and the Export Ordinal Table form twoparallel arrays, separated to allow natural field alignment. Theexport ordinal table array contains the Export Address Table ordinalnumbers associated with the named export referenced by correspondingExport Name Table Pointers.The ordinals are 16-bits each, and already include the Ordinal Basestored in the Export Directory Table.5.5 Export Name TableThe export name table contains optional ASCII names for exportedentries in the image. These tables are used with the array of ExportName Table Pointers and the array of Export Ordinals to translate aprocedure name string into an ordinal number by searching for amatching name string. The ordinal number is used to locate the entrypoint information in the export address table.Import references by name require the Export Name Table Pointerstable to be binary searched to find the matching name, then thecorresponding Export Ordinal Table is known to contain the entrypoint ordinal number. Import references by ordinal number providethe fastest lookup since searching the name table is not required.Each name table entry has the following format: ÚÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄ¿ ³ ASCII STRING ::: :::::::: '\0' ³ ÀÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÙFigure 7. Export Name Table EntryASCII STRING = DB ASCII String.The string is case sensitive and is terminated by a null byte.6. ImportsA typical file layout for the import information follows: ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ DIRECTORY TABLE ³ ³ ³ ³ ³ ³ ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ NULL DIR ENTRY ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ DLL1 LOOKUP TABLE ³ ³ ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ NULL ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ DLL2 LOOKUP TABLE ³ ³ ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ NULL ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ Dll3 LOOKUP TABLE ³ ³ ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ NULL ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ HINT-NAME TABLE ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ DLL1 ADDRESS TABLE ³ ³ ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ NULL ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ DLL2 ADDRESS TABLE ³ ³ ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ NULL ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ DLL3 ADDRESS TABLE ³ ³ ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ NULL ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙFigure 8. Import File Layout6.1 Import Directory TableThe import information begins with the Import Directory Table whichdescribes the remainder of the import information. The ImportDirectory Table contains address information that is used to resolvefixup references to the entry points within a DLL image. The importdirectory table consists of an array of Import Directory Entries, oneentry for each DLL this image references. The last directory entry isempty (NULL) which indicates the end of the directory table.An Import Directory Entry has the following format: ÚÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄ¿ ³ IMPORT FLAGS ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ TIME/DATE STAMP ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ MAJOR VERSION ³ MINOR VERSION ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ NAME RVA ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ IMPORT LOOKUP TABLE RVA ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ IMPORT ADDRESS TABLE RVA ³ ÀÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÙFigure 9. Import Directory EntryIMPORT FLAGS = DD Currently set to zero.TIME/DATE STAMP = DD Time/Date the import data was pre-snapped orzero if not pre-snapped.MAJOR/MINOR VERSION = DW The major/minor version number of the dllbeing referenced.NAME RVA = DD Relative Virtual Address of the Dll asciiz Name.This is the address relative to the Image Base.IMPORT LOOKUP TABLE RVA = DD This field contains the address of thestart of the import lookup table for this image. The address isrelative to the beginning of the Image Base.IMPORT ADDRESS TABLE RVA = DD This field contains the address of thestart of the import addresses for this image. The address isrelative to the beginning of the Image Base.6.2 Import Lookup TableThe Import Lookup Table is an array of ordinal or hint/name RVA's foreach DLL. The last entry is empty (NULL) which indicates the end ofthe table.The last element is empty. 3 0 1 ÚÄÒÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄ¿ ³0º ORDINAL#/HINT-NAME TABLE RVA ³ ÀÄÐÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÙFigure 10. Import Address Table FormatORDINAL/HINT-NAME TABLE RVA = 31-bits (mask = 7fffffffh) OrdinalNumber or Name Table RVA.If the import is by ordinal, this field contains a 31 bit ordinalnumber. If the import is by name, this field contains a 31 bitaddress relative to the Image Base to the Hint-Name Table.O = 1-bit (mask = 80000000h) Import by ordinal flag. o 00000000h __Import by name. o 80000000h __Import by ordinal.6.3 Hint-Name TableThe Hint-Name Table format follows: ÚÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄ¿ ³ HINT ³ ASCII STRING |||³ ÃÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄ´ ³|||||||||||||||||³ '\0' PAD ³ ÀÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÙ The PAD field is optional.Figure 11. Import Hint-Name TableHINT = DW Hint into Export Name Table Pointers.The hint value is used to index the Export Name Table Pointers array,allowing faster by-name imports. If the hint is incorrect, then abinary search is performed on the Export Name Ptr Table.ASCII STRING = DB ASCII String.The string is case sensitive and is terminated by a null byte.PAD = DB Zero pad byte.A trailing zero pad byte appears after the trailing null byte ifnecessary to align the next entry on an even boundary.The loader overwrites the import address table when loading the imagewith the 32-bit address of the import.6.4 Import Address TableThe Import Address Table is an array of addresses of the importedroutines for each DLL. The last entry is empty (NULL) which indicatesthe end of the table.7. Thread Local StorageThread local storage is a special contiguous block of data. Eachthread will gets its own block upon creation of the thread.The file layout for thread local storage follows: ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ DIRECTORY TABLE ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ TLS DATA ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ INDEX VARIABLE ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ CALLBACK ADDRESSES ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙFigure 12. Thread Local Storage Layout7.1 Thread Local Storage Directory TableThe Thread Local Storage Directory Table contains address informationthat is used to describe the rest of TLS.The Thread Local Storage Directory Table has the following format: ÚÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄ¿ ³ START DATA BLOCK VA ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ END DATA BLOCK VA ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ INDEX VA ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ CALLBACK TABLE VA ³ ÀÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÙFigure 13. Thread Local Storage Directory TableSTART DATA BLOCK VA = DD Virtual Address of the start of the threadlocal storage data block.END DATA BLOCK VA = DD Virtual Address of the end of the thread localstorage data block.INDEX VA = DD Virtual Address of the index variable used to accessthe thread local storage data block.CALLBACK TABLE VA = DD Virtual Address of the callback table.7.2 Thread Local Storage CallBack TableThe Thread Local Storage Callbacks is an array of Virtual Address offunctions to be called by the loader after thread creation and threadtermination. The last entry is empty (NULL) which indicates the endof the table.The Thread Local Storage CallBack Table has the following format: ÚÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄ¿ ³ FUNCTION1 VA ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ FUNCTION2 VA ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ NULL ³ ÀÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÙFigure 14. Thread Local Storage CallBack Table8. ResourcesResources are indexed by a multiple level binary-sorted treestructure. The overall design can incorporate 2**31 levels, however,NT uses only three: the highest is TYPE, then NAME, then LANGUAGE.A typical file layout for the resource information follows: ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ RESOURCE DIRECTORY ³ ³ ³ ³ ³ ³ ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ RESOURCE DATA ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙFigure 15. Resource File LayoutThe Resource directory is made up of the following tables:8.1 Resource Directory TableÚÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄ¿³ RESOURCE FLAGS ³ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´³ TIME/DATE STAMP ³ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´³ MAJOR VERSION ³ MINOR VERSION ³ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´³ # NAME ENTRY ³ # ID ENTRY ³ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´³ RESOURCE DIR ENTRIES ³ÀÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÙFigure 16. Resource Table EntryRESOURCE FLAGS = DD Currently set to zero.TIME/DATE STAMP = DD Time/Date the resource data was created by theresource compiler.MAJOR/MINOR VERSION = DW A user settable major/minor version number.# NAME ENTRY = DW The number of name entries.This field contains the number of entries at the beginning of thearray of directory entries which have actual string names associatedwith them.# ID ENTRY = DW The number of ID integer entries.This field contains the number of 32-bit integer IDs as their namesin the array of directory entries.The resource directory is followed by a variable length array ofdirectory entries. # NAME ENTRY is the number of entries at thebeginning of the array that have actual names associated with eachentry. The entires are in ascending order, case insensitive strings.# ID ENTRY identifies the number of entries that have 32-bit integerIDs as their name. These entries are also sorted in ascending order.This structure allows fast lookup by either name or number, but forany given resource entry only one form of lookup is supported, notboth. This is consistent with the syntax of the .RC file and the .RESfile.The array of directory entries have the following format: 3 0 1ÚÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄ¿³ NAME RVA/INTEGER ID ³ÃÄÒÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´³Eº DATA ENTRY RVA/SUBDIR RVA ³ÀÄÐÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÙFigure 17. Resource Directory EntryINTERGER ID = DD ID.This field contains a integer ID field to identify a resource.NAME RVA = DD Name RVA address.This field contains a 31-bit address relative to the beginning of theImage Base to a Resource Directory String Entry.E = 1-bit (mask 80000000h) Unescape bit.This bit is zero for unescaped Resource Data Entries.DATA RVA = 31-bits (mask 7fffffffh) Data entry address.This field contains a 31-bit address relative to the beginning of theImage Base to a Resource Data Entry.E = 1-bit (mask 80000000h) Escape bit.This bit is 1 for escaped Subdirectory Entry.DATA RVA = 31-bits (mask 7fffffffh) Directory entries.This field contains a 31-bit address relative to the beginning of theImage Base to Subdirectory Entry.Each resource directory string entry has the following format:ÚÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄ¿³ LENGTH ³ UNICODE STRING ³ÃÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄ´³ ³ÀÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÙFigure 18. Resource Directory String EntryLENGTH = DW Length of string.UNICODE STRING = DW UNICODE String.All of these string objects are stored together after the lastresource directory entry and before the first resource data object.This minimizes the impact of these variable length objects on thealignment of the fixed size directory entry objects. The length needsto be word aligned.Each Resource Data Entry has the following format: ÚÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄ¿ ³ DATA RVA ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ SIZE ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ CODEPAGE ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ RESERVED ³ ÀÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÙFigure 19. Resource Data EntryDATA RVA = DD Address of Resource Data.This field contains 32-bit virtaul address of the resource data(relative to the Image Base).SIZE = DD Size of Resource Data.This field contains the size of the resource data for this resource.CODEPAGE = DD Codepage.RESERVED = DD Reserved - must be zero.Each resource data entry describes a leaf node in the resourcedirectory tree. It contains an address which is relative to thebeginning of Image Base, a size field that gives the number of bytesof data at that address, a CodePage that should be used when decodingcode point values within the resource data. Typically for newapplications the code page would be the unicode code page.8.2 Resource ExampleThe following is an example for an app. which wants to use the following dataas resources: TypeId# NameId# Language ID Resource Data 00000001 00000001 0 00010001 00000001 00000001 1 10010001 00000001 00000002 0 00010002 00000001 00000003 0 00010003 00000002 00000001 0 00020001 00000002 00000002 0 00020002 00000002 00000003 0 00020003 00000002 00000004 0 00020004 00000009 00000001 0 00090001 00000009 00000009 0 00090009 00000009 00000009 1 10090009 00000009 00000009 2 20090009Then the Resource Directory in the Portable format looks like:Offset Data0000: 00000000 00000000 00000000 00030000 (3 entries in this directory)0010: 00000001 80000028 (TypeId #1, Subdirectory at offset 0x28)0018: 00000002 80000050 (TypeId #2, Subdirectory at offset 0x50)0020: 00000009 80000080 (TypeId #9, Subdirectory at offset 0x80)0028: 00000000 00000000 00000000 00030000 (3 entries in this directory)0038: 00000001 800000A0 (NameId #1, Subdirectory at offset 0xA0)0040: 00000002 00000108 (NameId #2, data desc at offset 0x108)0048: 00000003 00000118 (NameId #3, data desc at offset 0x118)0050: 00000000 00000000 00000000 00040000 (4 entries in this directory)0060: 00000001 00000128 (NameId #1, data desc at offset 0x128)0068: 00000002 00000138 (NameId #2, data desc at offset 0x138)0070: 00000003 00000148 (NameId #3, data desc at offset 0x148)0078: 00000004 00000158 (NameId #4, data desc at offset 0x158)0080: 00000000 00000000 00000000 00020000 (2 entries in this directory)0090: 00000001 00000168 (NameId #1, data desc at offset 0x168)0098: 00000009 800000C0 (NameId #9, Subdirectory at offset 0xC0)00A0: 00000000 00000000 00000000 00020000 (2 entries in this directory)00B0: 00000000 000000E8 (Language ID 0, data desc at offset 0xE800B8: 00000001 000000F8 (Language ID 1, data desc at offset 0xF800C0: 00000000 00000000 00000000 00030000 (3 entries in this directory)00D0: 00000001 00000178 (Language ID 0, data desc at offset 0x17800D8: 00000001 00000188 (Language ID 1, data desc at offset 0x18800E0: 00000001 00000198 (Language ID 2, data desc at offset 0x19800E8: 000001A8 (At offset 0x1A8, for TypeId #1, NameId #1, Language id #0 00000004 (4 bytes of data) 00000000 (codepage) 00000000 (reserved)00F8: 000001AC (At offset 0x1AC, for TypeId #1, NameId #1, Language id #1 00000004 (4 bytes of data) 00000000 (codepage) 00000000 (reserved)0108: 000001B0 (At offset 0x1B0, for TypeId #1, NameId #2, 00000004 (4 bytes of data) 00000000 (codepage) 00000000 (reserved)0118: 000001B4 (At offset 0x1B4, for TypeId #1, NameId #3, 00000004 (4 bytes of data) 00000000 (codepage) 00000000 (reserved)0128: 000001B8 (At offset 0x1B8, for TypeId #2, NameId #1, 00000004 (4 bytes of data) 00000000 (codepage) 00000000 (reserved)0138: 000001BC (At offset 0x1BC, for TypeId #2, NameId #2, 00000004 (4 bytes of data) 00000000 (codepage) 00000000 (reserved)0148: 000001C0 (At offset 0x1C0, for TypeId #2, NameId #3, 00000004 (4 bytes of data) 00000000 (codepage) 00000000 (reserved)0158: 000001C4 (At offset 0x1C4, for TypeId #2, NameId #4, 00000004 (4 bytes of data) 00000000 (codepage) 00000000 (reserved)0168: 000001C8 (At offset 0x1C8, for TypeId #9, NameId #1, 00000004 (4 bytes of data) 00000000 (codepage) 00000000 (reserved)0178: 000001CC (At offset 0x1CC, for TypeId #9, NameId #9, Language id #0 00000004 (4 bytes of data) 00000000 (codepage) 00000000 (reserved)0188: 000001D0 (At offset 0x1D0, for TypeId #9, NameId #9, Language id #1 00000004 (4 bytes of data) 00000000 (codepage) 00000000 (reserved)0198: 000001D4 (At offset 0x1D4, for TypeId #9, NameId #9, Language id #2 00000004 (4 bytes of data) 00000000 (codepage) 00000000 (reserved)And the data for the resources will look like:01A8: 0001000101AC: 1001000101B0: 0001000201B4: 0001000301B8: 0002000101BC: 0002000201C0: 0002000301C4: 0002000401C8: 0009000101CC: 0009000901D0: 1009000901D4: 200900099. Fixup TableThe Fixup Table contains entries for all fixups in the image. TheTotal Fixup Data Size in the PE Header is the number of bytes in thefixup table. The fixup table is broken into blocks of fixups. Eachblock represents the fixups for a 4K page.Fixups that are resolved by the linker do not need to be processed bythe loader, unless the load image can't be loaded at the Image Basespecified in the PE Header.9.1 Fixup BlockFixup blocks have the following format: ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ PAGE RVA ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ BLOCK SIZE ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ TYPE/OFFSET ³ TYPE/OFFSET ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ TYPE/OFFSET ³ ... ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙFigure 20. Fixup Block FormatTo apply a fixup, a delta needs to be calculated. The 32-bit deltais the difference between the preferred base, and the base where theimage is actually loaded. If the image is loaded at its preferredbase, the delta would be zero, and thus the fixups would not have tobe applied. Each block must start on a DWORD boundary. The ABSOLUTEfixup type can be used to pad a block.PAGE RVA = DD Page RVA. The image base plus the page rva is added toeach offset to create the virtual address of where the fixup needs tobe applied.BLOCK SIZE = DD Number of bytes in the fixup block. This includes thePAGE RVA and SIZE fields.TYPE/OFFSET is defined as: 1 1 0 5 1 ÚÄÄÄÄÒÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³TYPEº OFFSET ³ ÀÄÄÄÄÐÄÄÄÄÄÄÄÄÄÄÄÄÙFigure 21. Fixup Record FormatTYPE = 4-bit fixup type. This value has the following definitions: o 0h __ABSOLUTE. This is a NOP. The fixup is skipped. o 1h __HIGH. Add the high 16-bits of the delta to the 16-bit field at Offset. The 16-bit field represents the high value of a 32- bit word. o 2h __LOW. Add the low 16-bits of the delta to the 16-bit field at Offset. The 16-bit field represents the low half value of a 32-bit word. This fixup will only be emitted for a RISC machine when the image Object Align isn't the default of 64K. o 3h __HIGHLOW. Apply the 32-bit delta to the 32-bit field at Offset. o 4h __HIGHADJUST. This fixup requires a full 32-bit value. The high 16-bits is located at Offset, and the low 16-bits is located in the next Offset array element (this array element is included in the SIZE field). The two need to be combined into a signed variable. Add the 32-bit delta. Then add 0x8000 and store the high 16-bits of the signed variable to the 16-bit field at Offset. o 5h __MIPSJMPADDR.All other values are reserved.10. Debug InformationThe debug information is defined by the debugger and is notcontrolled by the portable EXE format or linker. The only datadefined by the portable EXE format is the Debug Directory Table.10.1 Debug DirectoryThe debug directory table consists of one or more entries that havethe following format: ÚÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄ¿ ³ DEBUG FLAGS ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ TIME/DATE STAMP ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ MAJOR VERSION ³ MINOR VERSION ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ DEBUG TYPE ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ DATA SIZE ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ DATA RVA ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ DATA SEEK ³ ÀÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÙFigure 22. Debug Directory EntryDEBUG FLAGS = DD Set to zero for now.TIME/DATE STAMP = DD Time/Date the debug data was created.MAJOR/MINOR VERSION = DW Version stamp.This stamp can be used to determine the version of the debug data.DEBUG TYPE = DD Format type.To support multiple debuggers, this field determines the format ofthe debug information. This value has the following definitions: o 0001h __Image contains COFF symbolics. o 0001h __Image contains CodeView symbolics. o 0001h __Image contains FPO symbolics.DATA SIZE = DD The number of bytes in the debug data. This is thesize of the actual debug data and does not include the debugdirectory.DATA RVA = DD The relative virtual address of the debug data. Thisaddress is relative to the beginning of the Image Base.DATA SEEK = DD The seek value from the beginning of the file to thedebug data.If the image contains more than one type of debug information, thenthe next debug directory will immediately follow the first debugdirectory. Quote