Data Directories

Data Directories

The Data Directories (IMAGE_DATA_DIRECTORY) is the last member of the Optional Header. It is an array with a data type of IMAGE_DATA_DIRECTORY, and contains up to 16 structures.

For context and review, remember that the Optional Header itself is the last (and most important) part of the NT Headers within a PE file.

PE-Bear parses the Data Directories for us:

View of the Data Directories parsed with PE-Bear
Fig 1: View of the Data Directories parsed with PE-Bear.

The array has a size of IMAGE_NUMBEROF_DIRECTORY_ENTRIES:

IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];

Which is set to a constant of 16:

#define IMAGE_NUMBEROF_DIRECTORY_ENTRIES    16

Each IMAGE_DATA_DIRECTORY struct has two members, VirtualAddress and Size:

typedef struct _IMAGE_DATA_DIRECTORY {
    DWORD   VirtualAddress;
    DWORD   Size;
} IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY;
  • VirtualAddress is a relative virtual address (RVA) that points to the start of the data directory.
  • Size is the size of the data directory in bytes.

Table of Data Directories

Data directories contain information used by the PE loader. Each data directory has an index and a specified offset:

IndexOffset (PE/PE32+)NameDescription
096/112IMAGE_DIRECTORY_ENTRY_EXPORTExport table
1104/120IMAGE_DIRECTORY_ENTRY_IMPORTImport table
2112/128IMAGE_DIRECTORY_ENTRY_RESOURCEResource table
3120/136IMAGE_DIRECTORY_ENTRY_EXCEPTIONException table
4128/144IMAGE_DIRECTORY_ENTRY_SECURITYCertificate table
5136/152IMAGE_DIRECTORY_ENTRY_BASERELOCBase relocation table
6144/160IMAGE_DIRECTORY_ENTRY_DEBUGDebugging information
7152/168IMAGE_DIRECTORY_ENTRY_ARCHITECTURE /
IMAGE_DIRECTORY_ENTRY_COPYRIGHT
Architecture-specific data address
Used in x86
8160/176IMAGE_DIRECTORY_ENTRY_GLOBALPTRGlobal pointer register RVA
9168/184IMAGE_DIRECTORY_ENTRY_TLSThread local storage (TLS) table
10176/192IMAGE_DIRECTORY_ENTRY_LOAD_CONFIGLoad configuration table
11184/200IMAGE_DIRECTORY_ENTRY_BOUND_IMPORTBound import table
12192/208IMAGE_DIRECTORY_ENTRY_IATImport address table
13200/216IMAGE_DIRECTORY_ENTRY_DELAY_IMPORTDelay import descriptor
14208/224IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTORCLR header;
present if file contains a .NET assembly
15216/232Reserved

Of these, the most important are the Export Directory (IMAGE_DIRECTORY_ENTRY_EXPORT – index 0) and the Import Address Table (IMAGE_DIRECTORY_ENTRY_IAT).

Export Directory

The export directory is typically found in DLLs that export functions. It’s a data structure that contains the addresses of the exported functions and variables. These addresses can then be used by other executable files in order to access the exported functions, variables, and data.

Import Address Table

The import address table (IAT) contains information about functions imported from other executables. The addresses in the table are used to access the functions and data from the other executable files.

Scroll to Top