Skip to content

Image TLS Directory

AFP edited this page Apr 1, 2023 · 2 revisions

How to Access Image TLS Directory

after initialize the PE class you can get access the Image TLS Directory structure by calling GetImageTlsDirectory() method. by calling this function, you get the object of ImageTlsDirectory class, so you can retrieve the fields, change or modify them.

#include <iostream>
#include <POEX.h> // include POEX header

int main()
{
    auto pe = POEX::PE(L"1.exe");

    // Access to Image TLS Directory
    auto tlsDirectory = pe.GetImageTlsDirectory();

    // other stuff in here

    return 0;
}

With calling GetImageTlsDirectory method, you can access the structure and method in bellow:

auto Callbacks() -> std::vector<ImageTlsCallback>;

/// <summary>
/// Start address of the raw data.
/// </summary>
/// <returns>offset</returns>
auto StartAddressOfRawData() const -> unsigned long;

/// <summary>
/// Start address of the raw data.
/// </summary>
/// <param name="off">offset</param>
/// <returns></returns>
auto StartAddressOfRawData(const unsigned long& off) -> void;

/// <summary>
/// End address of the raw data.
/// </summary>
/// <returns>offset</returns>
auto EndAddressOfRawData() const -> unsigned long;

/// <summary>
/// End address of the raw data.
/// </summary>
/// <param name="off">offset</param>
/// <returns></returns>
auto EndAddressOfRawData(const unsigned long& off) -> void;

/// <summary>
/// Address of index (pointer to TLS index).
/// </summary>
/// <returns>pointer to TLS index</returns>
auto AddressOfIndex() const -> unsigned long;

/// <summary>
/// Address of index (pointer to TLS index).
/// </summary>
/// <param name="off">pointer to TLS index</param>
/// <returns></returns>
auto AddressOfIndex(const unsigned long& off) -> void;

/// <summary>
/// Address of the callbacks.
/// </summary>
/// <returns>Callbacks offset</returns>
auto AddressOfCallBacks() const -> unsigned long;

/// <summary>
/// Address of the callbacks.
/// </summary>
/// <param name="off">Callbacks offset</param>
/// <returns></returns>
auto AddressOfCallBacks(const unsigned long& off) -> void;

/// <summary>
/// Size of zero fill.
/// </summary>
/// <returns>Zero fill length</returns>
auto SizeOfZeroFill() const -> unsigned int;

/// <summary>
/// Size of zero fill.
/// </summary>
/// <param name="length">Zero fill length</param>
/// <returns></returns>
auto SizeOfZeroFill(const unsigned int& length) -> void;

/// <summary>
/// Characteristics
/// </summary>
/// <returns>Characteristics</returns>
auto Characteristics() const -> unsigned int;

/// <summary>
/// Characteristics
/// </summary>
/// <param name="characteristics">Characteristics</param>
/// <returns></returns>
auto Characteristics(const unsigned int& characteristics) -> void;

And with calling method Callbacks you can access the callbacks structures:

/// <summary>
/// Address of actual callback code.
/// </summary>
/// <returns>Address of actual callback code.</returns>
auto Callback() const -> unsigned long;

/// <summary>
/// Address of actual callback code.
/// </summary>
/// <param name="off">Address of actual callback code.</param>
/// <returns></returns>
auto Callback(const unsigned long& off) -> void;
Clone this wiki locally