                            TLS callbacks in tasm32
                            
Layout of TLS:
Offset  Field                   Description
0x00    Raw Data Start VA       Starting address of the TLS template
0x04    Raw Data End VA         Address of last byte of TLS template
0x08    Address of Index        Location to receive the TLS index
0x0C    Address of Callbacks    Pointer to array of TLS callbacks
0x10    Size of Zero Fill       Size of unused data in TLS template
0x14    Characteristics         (reserved but not checked)


At offset +0D in OptionalHeader is field that is pointing to the above
structure, it is NT.OptionalHeader.DirectoryEntires.TLS, so to make
all this work in tasm32 we shall make that structure at the beginning
of .data section and modify latter on in hiew or any other hex editor
to point to .data section:

code snippet:
.data
Tls:
                     dd     offset Tls1
                     dd     offset Tls2
                     dd     offset Tls3
                     dd     offset TlsCallBack
                     dd     0
                     dd     0

Tls1                 dd     0
Tls2                 dd     0
Tls3                 dd     0
TlsCallBack          dd     offset TlsProc
                     dd     0
                     dd     0
                     
where TlsCallBack is procedure that contains our code, compile this code,
open HIEW:

go to DataDirectory.TLS and set it's VirtualAddress to .data section, which
is in my example 2000h and set Size to 18 which is 6 fields * 4bytes for
TLS structure size, run code, voila it works like a charm...
exmaples : tls.asm and tls.exe

                                          S verom u Boga, deroko
      

