wraith/structures/pe/
tls.rs

1//! TLS (Thread Local Storage) structures
2
3#[repr(C)]
4#[derive(Debug, Clone, Copy)]
5pub struct TlsDirectory32 {
6    pub start_address_of_raw_data: u32,
7    pub end_address_of_raw_data: u32,
8    pub address_of_index: u32,
9    pub address_of_callbacks: u32, // pointer to array of PIMAGE_TLS_CALLBACK
10    pub size_of_zero_fill: u32,
11    pub characteristics: u32,
12}
13
14#[repr(C)]
15#[derive(Debug, Clone, Copy)]
16pub struct TlsDirectory64 {
17    pub start_address_of_raw_data: u64,
18    pub end_address_of_raw_data: u64,
19    pub address_of_index: u64,
20    pub address_of_callbacks: u64, // pointer to array of PIMAGE_TLS_CALLBACK
21    pub size_of_zero_fill: u32,
22    pub characteristics: u32,
23}
24
25pub enum TlsDirectory {
26    Tls32(TlsDirectory32),
27    Tls64(TlsDirectory64),
28}
29
30impl TlsDirectory {
31    pub fn callbacks_address(&self) -> u64 {
32        match self {
33            Self::Tls32(t) => t.address_of_callbacks as u64,
34            Self::Tls64(t) => t.address_of_callbacks,
35        }
36    }
37}
38
39/// TLS callback function signature
40pub type TlsCallback = unsafe extern "system" fn(
41    dll_handle: *mut core::ffi::c_void,
42    reason: u32,
43    reserved: *mut core::ffi::c_void,
44);