Prolouge: The purpose of this page is in order to figure out what is export table in PE file and how the OS find the export function used for others program
This post is related to PE HEADER knowledges!
Introduction
First of all we need to understand what is data directory. Basically, Data directory is just an attribute in the IMAGE_OPTIONAL_HEADER which belongs to IMAGE_NT_HEADER which also be coordinated by IMAGE_DOS_HEADER e_lfanew attribute.
Deep into data directory element, the data directory itself, is an array or a table contains lots of thing used to manage many stuff by operating system. And the first one is export table which hold two value. The RVA lead to the IMAGE_EXPORT_DIRECTORY and the size of Export Table.
Geninuelly, the IMAGE_EXPORT_DIRECTORY is a struct that remain those values
Source: https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#export-directory-table
The value that we must take a look here is from Ordinal Base to Ordinal Table RVA
Now the IMAGE_EXPORT_DIRECTORY contains 3 table.
- Export Address Table EAT contains an array of DWORD that each lead to the specific function in the program or a string if that is a forwarded export function. This table has
Addres Table Entriessize - Name Pointer RVA, which is an array of DWORD (4 bytes) stores the RVA directly to the name of the function with null terminated char.
- The Ordinal Table RVA which is an array of WORD (2 bytes) stores the index (0-based index) which is used for locating the function in EAT
Both 2 and 3 has
Number of Name Pointerssize
Now what is actually Ordinal Base. Well bascially, by concept there are two different ordinal base. The one used as importer to search suitable function (importer request) called Ordinal Number, others is used for locating the function in the program (export table lookup value) called Ordinal index. However, The formular and relationship of those is.
Ordinal Number=Ordinal Base+Ordinal IndexOrdinal Index=Ordinal Number-Ordinal Base
The process of tracing function in the exporter program.
- For example you require a function HelloWorld(). Now first of all the OS will find the function name in the AddressOfName (Name Pointer RVA) and filter out the index in that table called X.
- After that extracting the ordinal index from Ordinal Table RVA using the value X, call this value is Y
- The value Y will be used in order to access the function in the EAT
Script
All thing is clear now, lets try to extract those attribute clearly. We will write a small script using Ipyida or Idapython i don’t really know the name lol.
Now first of all we have to add type library MSSDK in ida like this. This is just for using struct like IMAGE_DOS_HEADER, … etc
The second one
| |
You can open abitrary DLL file on your window computer or download on the internet and load it into IDA and use this script for testing.
If you found any misleading knowledge or something about my understanding, please comment I will fix it!
This post references: https://www.youtube.com/watch?v=VjxPWbUJI9A