Skip to content
Tutorials Center
My learning

Topics

Lesson 13 of 37 ยท Static Analysis

Imports, Exports and Sections

Read a PE file's import table to infer capabilities, understand exports and DLLs, and spot suspicious section names, permissions and size mismatches with Python examples.

A program on Windows does not contain the code for opening files, making network connections or creating processes. It asks the operating system to do those jobs by calling functions in system libraries (DLLs) such as kernel32.dll, advapi32.dll and ws2_32.dll. The list of functions a program asks for is its import table, and it is one of the best static clues to what the program can do.

This lesson explains imports and exports, builds a synthetic import table and reads it back, then looks at sections, the regions of a PE file, and the anomalies that suggest packing or tampering.

The import table

When a program starts, the Windows loader reads the import table, loads each DLL listed there and fills in the addresses of the functions. In the file, the table is a list of import descriptors, one per DLL, each pointing to:

  • the DLL's name, and
  • an array (the import lookup table) of entries, each referring to a function by name (a hint number plus the name) or by ordinal.

An analyst scanning the imports can answer: does it touch the registry? the network? other processes' memory? The next table groups famous APIs by capability. Presence of one is not proof (a browser uses most of them), but combinations tell a story.

Capability Typical APIs
File access CreateFileA/W, WriteFile, DeleteFileA, FindFirstFileA
Registry RegOpenKeyExA, RegSetValueExA, RegCreateKeyExA
Network InternetOpenUrlA, URLDownloadToFileA, WSAStartup, connect, send, recv
Process creation CreateProcessA, ShellExecuteA, WinExec
Injection (memory) VirtualAllocEx, WriteProcessMemory, CreateRemoteThread, OpenProcess
Anti-analysis IsDebuggerPresent, CheckRemoteDebuggerPresent, GetTickCount
Dynamic loading LoadLibraryA, GetProcAddress
Crypto CryptEncrypt, CryptAcquireContextA, BCryptEncrypt
Keyboard/screen GetAsyncKeyState, SetWindowsHookExA, BitBlt

Notice the A and W suffixes: A is the ANSI (one byte per character) version and W the wide (UTF-16) version.

Few imports means suspicion

A normal program imports dozens of functions. A sample that imports only LoadLibraryA and GetProcAddress is usually resolving everything at run time, which hides its real imports from static view and is common in packed or obfuscated code.

Build and read an import table

The example creates a harmless synthetic PE whose only content is an import table, then parses it by converting RVAs to file offsets with the section table. It is longer than earlier examples, but it demonstrates exactly what a PE viewer does.

Python Parse a PE import table

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

You have just reproduced what pefile.PE(...).DIRECTORY_ENTRY_IMPORT does: convert RVAs to offsets using the section table, walk the descriptors until a null one, then walk each thunk array until a zero entry.

From imports to capabilities

Once you have the list, a simple lookup turns it into a capability summary for your notes. This version uses the table above.

Python Summarise capabilities from imports

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The final line is the real insight: you rarely conclude anything from one API, but a combination fits a behaviour pattern worth testing in the lab.

Exports

An export table lists functions a file offers to others. DLLs export their API; programs rarely export anything. Malware DLLs often export one or two odd functions, sometimes with names like DllRegisterServer, Start, ServiceMain or just numbers (ordinal-only exports), and the exported names can show how a loader will call them. Some DLLs forward exports to another DLL. When you are given a DLL sample, always check how it is meant to be started: through rundll32.exe, as a service or by being loaded by another program.

Sections

Sections group a file's contents by purpose and permissions. Compilers produce familiar names:

Name Usual content Typical permissions
.text Program code read, execute
.rdata Read-only data, import tables read
.data Global variables read, write
.rsrc Resources: icons, dialogs, embedded files read
.reloc Relocation info read
.idata, .edata Imports, exports (often folded into .rdata) read

Section names are just labels that the author controls, so unusual ones (UPX0, .aspack, random strings) can reveal a packer, but a normal name proves nothing.

Section anomalies

  • A section that is both writable and executable: code that modifies itself, typical for unpackers.
  • Raw size much smaller than virtual size: a section that is nearly empty on disk but large in memory is space reserved for an unpacked payload.
  • Very high entropy (see the next lesson) in a code section.
  • Unusual names or an executable .data section.
  • Resources that are large or have a high entropy: embedded payloads often hide in .rsrc.
Python Lint a section table

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

That table is exactly what UPX-packed programs look like: UPX0 is empty on disk but reserves memory where the packer unpacks code, and the sections are writable and executable. You will unpack the idea in Packers and Obfuscation.

Common mistakes

  • Treating one suspicious import as proof.
  • Ignoring the A/W variants when searching.
  • Forgetting that run-time resolving (GetProcAddress) hides imports.
  • Assuming a section named .text really holds only code.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does the import table of a PE file list?

    Imports are the DLL functions the program asks Windows to resolve. Exports are what a DLL offers.
  2. 2. A sample imports only LoadLibraryA and GetProcAddress. What does this commonly suggest?

    These two functions let a program find any API by name while running, which hides its true imports.
  3. 3. Which section configuration is most typical of a packer?

    Packers reserve memory to unpack code, then run it, so the section is writable and executable.
  4. 4. What does an RVA need in order to be read from a file on disk?

    RVAs are memory-relative. You map them to raw file offsets through the section containing them.

Summary

  • The import table lists the DLL functions a program needs; combinations of APIs hint at capabilities.
  • Few imports plus LoadLibrary/GetProcAddress suggests run-time resolving or packing.
  • Exports describe what a DLL offers and how it is meant to be started.
  • Sections hold code and data with permissions; names are author-controlled labels.
  • Writable-and-executable sections and big virtual-versus-raw gaps are classic packer signs.

Next: Entropy and File Structure Anomalies