本文介绍了使用msvc附带的MASM创建Tls目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从masm源创建TLS目录。 masm源是C编译器输出的结果。


这就是我所做的:

 TITLE C:\ apps\sample.c 
.686P
.XMM
包括listing.inc

.model flat

OPTION CASEMAP:NONE

INCLUDELIB MSVCRT
INCLUDELIB OLDNAMES
INCLUDELIB USER32

PUBLIC _tls_callback @ 12

PUBLIC _tls_used;此名称是必需的,必须是PUBLIC !!!!



;备考创建部分名称.tls
;(但tls可以放在任何地方)
OPTION DOTNAME
.tls SEGMENT ALIAS(" .tls")
_tls_start LABEL DWORD
DWORD 80H DUP(" test")
_tls_end LABEL DWORD
.tls ENDS
OPTION NODOTNAME

.CONST
_tls_array EQU 2CH; FS:[2CH] - 指向复制tls块指针数组的指针

_DATA SEGMENT
__xl_a DWORD _tls_callback @ 12
__xl_z DWORD 0; null终止回调程序指针列表
_tls_index DWORD 0


TLS_DIRECTORY STRUCT
lpTlsDataStart DWORD? ;复制块从这里开始
lpTlsDataEnd DWORD? ;并在此结束+块(size = ZeroFillSize)填充0到
lpTlsIndex DWORD? ; DS:[FS:[2CH]] + TlsIndex * 4
lpTlsCallbacks DWORD? ;指向0终止回调指针的指针
ZeroFillSize DWORD? ;整体大小= lpTlsDataEnd-lpTlsDataStart + ZeroFillSize
特征DWORD? ;保留
TLS_DIRECTORY结束


_tls_used TLS_DIRECTORY< _tls_start,_tls_end,_tls_index,__ xl_a,0,?>


_TEXT SEGMENT
_DllHandle $ = 8; size = 4
_dwReason $ = 12; size = 4
_lpVd $ = 16; size = 4
_tls_callback @ 12 PROC; COMDAT

push ebp
mov ebp,esp

mov edx,DWORD PTR _msg

push 0
push edx
push edx
push 0
call DWORD PTR __imp__MessageBoxA @ 16
;第34行
pop ebp
ret 12; 0000000cH
_tls_callback @ 12 ENDP
_TEXT ENDS

所以我创建一个回调,显示带有一些消息的消息框,并且tls段的tls目录。但是在编译之后:
ml.exe sample.asm / coff  我在disassemlber IDA PRO中打开exe,我看到没有创建TLS目录条目,也没有创建tls段,当然也没有显示消息ID。如何在masm中执行此操作?


解决方案

I try to create TLS directory from masm source. The masm source is a result of a C compiler output.

Here is what i do:

TITLE   C:\apps\sample.c
    .686P
    .XMM
    include listing.inc
    
    .model    flat

OPTION  CASEMAP: NONE

INCLUDELIB MSVCRT
INCLUDELIB OLDNAMES
INCLUDELIB USER32

PUBLIC    _tls_callback@12

PUBLIC _tls_used ;this name is required and must be PUBLIC!!!!  



;pro forma create section with name .tls
;(but tls can be placed anywhere)
OPTION         DOTNAME
.tls   SEGMENT ALIAS(".tls")
_tls_start LABEL  DWORD
 DWORD     80H    DUP ("test")
_tls_end   LABEL  DWORD
.tls  ENDS
OPTION         NODOTNAME

.CONST
_tls_array EQU    2CH      ;FS:[2CH] - pointer to array of pointers to copied tls blocks

_DATA    SEGMENT
__xl_a DWORD _tls_callback@12
__xl_z DWORD 0    ;null terminated list of pointers to callback procedures
_tls_index DWORD  0


TLS_DIRECTORY    STRUCT
 lpTlsDataStart  DWORD ? ;copy block starting here
 lpTlsDataEnd    DWORD ? ;and ending here + block (size=ZeroFillSize) filled with 0 to
 lpTlsIndex      DWORD ? ;DS:[FS:[2CH]]+TlsIndex*4
 lpTlsCallbacks  DWORD ? ;pointer to 0 terminated array of pointers to callbacks
 ZeroFillSize     DWORD ? ;overall size=lpTlsDataEnd-lpTlsDataStart+ZeroFillSize
 Characteristic   DWORD ? ;reserved
TLS_DIRECTORY      ENDS


_tls_used TLS_DIRECTORY <_tls_start, _tls_end, _tls_index, __xl_a, 0, ?>


_TEXT   SEGMENT
_DllHandle$ = 8                     ; size = 4
_dwReason$ = 12                     ; size = 4
_lpVd$ = 16                     ; size = 4
_tls_callback@12 PROC                   ; COMDAT

    push    ebp
    mov ebp, esp

    mov edx, DWORD PTR _msg

    push 0
    push edx
    push edx
    push 0
    call DWORD PTR __imp__MessageBoxA@16
; Line 34
    pop ebp
    ret 12                  ; 0000000cH
_tls_callback@12 ENDP
_TEXT   ENDS

So i create one callback which displays messagebox with some message, and the tls directory with tls segment. But after compiling like this:ml.exe sample.asm /coff  i'm opening exe in the disassemlber IDA PRO, and i see that no TLS directory entry and no tls segment gets created and of course no message id displayed. How to do this in masm?

解决方案


这篇关于使用msvc附带的MASM创建Tls目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 09:22