News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

crash with uasm

Started by mabdelouahab, December 07, 2019, 07:07:36 PM

Previous topic - Next topic

mabdelouahab



;        uasm  -elf64 tagex.asm
;        gcc -o out  tagex.o -fno-pie -no-pie `pkg-config --cflags --libs gtk+-3.0`
     
OPTION LITERALS:ON

    gtk_init                    PROTO  :VARARG
    gtk_text_view_new           PROTO  :VARARG
    gtk_text_view_get_buffer    PROTO  :VARARG
    gtk_text_buffer_create_tag  PROTO  :VARARG
.DATA
        WWatch                  qword    0
        WWatchBuffer            qword    0
.CODE
    main PROC
        invoke gtk_init,0,0
        invoke gtk_text_view_new
        mov WWatch              ,rax
        invoke gtk_text_view_get_buffer,WWatch
        mov WWatchBuffer        ,rax
         invoke gtk_text_buffer_create_tag,WWatchBuffer, "rtl_quote",\
                                  "foreground", "green",\
                                  "wrap_mode", 2,\
                                  "direction", 2,\
                                  "indent", 30,\
                                  "left_margin", 20,\
                                  "right_margin", 20,\
                                  0
             invoke gtk_text_buffer_create_tag ,WWatchBuffer,"red_foreground","foreground", "red", 0                                 
        xor rax,rax
        ret
    main ENDP
end


UASM


   0x00401194      sub     rsp, 8
   0x00401198      mov     rdi, qword [obj.WWatchBuffer] ; 0x404058
   0x0040119f      lea     rsi, obj.__ls23949 ; 0x404060 ; "rtl_quote"
   0x004011a6      lea     rdx, obj.__ls50762 ; 0x4040be ; "foreground"
   0x004011ad      lea     rcx, obj.__ls1076 ; 0x404075 ; "green"
   0x004011b4      lea     r8, obj.__ls5511 ; 0x40407b ; "wrap_mode"
   0x004011bb      mov     r9, 2
   0x004011c2      push    0
   0x004011c4      push    0x14       ; 20
   0x004011c6      lea     rax, obj.__ls44569 ; 0x4040a2 ; "right_margin"
   0x004011cd      push    rax
   0x004011ce      push    0x14       ; 20
   0x004011d0      lea     rax, obj.__ls39112 ; 0x404096 ; "left_margin"
   0x004011d7      push    rax
   0x004011d8      push    0x1e       ; 30
   0x004011da      lea     rax, obj.__ls37456 ; 0x40408f ; "indent"
   0x004011e1      push    rax
   0x004011e2      push    2          ; r9
   0x004011e4      lea     rax, obj.__ls41541 ; 0x404085 ; "direction"
   0x004011eb      push    rax
   0x004011ec      xor     eax, eax
   0x004011ee      call    sym.imp.gtk_text_buffer_create_tag
   0x004011f3      add     rsp, 0x50
   0x004011f7      sub     rsp, 8
   0x004011fb      mov     rdi, qword [obj.WWatchBuffer] ; 0x404058
   0x00401202      lea     rsi, obj.__ls14102 ; 0x4040af ; "red_foreground"
   0x00401209      lea     rdx, obj.__ls50762 ; 0x4040be ; "foreground"
   0x00401210      lea     rcx, obj.__ls2622 ; 0x4040c9 ; "red"
   0x00401217      mov     r8, 0
   0x0040121e      xor     eax, eax
   0x00401220      call    sym.imp.gtk_text_buffer_create_tag
   0x00401225      add     rsp, 8

GCC

   0x000011d7      sub     rsp, 8
   0x000011db      push    0
   0x000011dd      push    0x14
   0x000011df      lea     rdx, str.right_margin ; 0x2029 ; "right_margin"
   0x000011e6      push    rdx
   0x000011e7      push    0x14
   0x000011e9      lea     rdx, str.left_margin ; 0x2036 ; "left_margin"
   0x000011f0      push    rdx
   0x000011f1      push    0x1e
   0x000011f3      lea     rdx, str.indent ; 0x2042 ; "indent"
   0x000011fa      push    rdx
   0x000011fb      push    2          ; r9 ; "LF\x02\x01\x01"
   0x000011fd      lea     rdx, str.direction ; 0x2049 ; "direction"
   0x00001204      push    rdx
   0x00001205      mov     r9d, 2
   0x0000120b      lea     r8, str.wrap_mode ; 0x2004 ; "wrap_mode"
   0x00001212      lea     rcx, str.green ; 0x200e ; "green"
   0x00001219      lea     rdx, str.foreground ; 0x2014 ; "foreground"
   0x00001220      lea     rsi, str.rtl_quote ; 0x201f ; "rtl_quote"
   0x00001227      mov     rdi, rax
   0x0000122a      mov     eax, 0
   0x0000122f      call    sym.imp.gtk_text_buffer_create_tag
   0x00001234      add     rsp, 0x50
   0x00001238      mov     rax, qword [var_8h]
   0x0000123c      mov     r8d, 0
   0x00001242      lea     rcx, [rcx] ; 0x2053 ; "red"
   0x00001249      lea     rdx, str.foreground ; 0x2014 ; "foreground"
   0x00001250      lea     rsi, str.red_foreground ; 0x2057 ; "red_foreground"
   0x00001257      mov     rdi, rax
   0x0000125a      mov     eax, 0
   0x0000125f      call    sym.imp.gtk_text_buffer_create_tag

KradMoonRa

;        uasm  -elf64 tagex.asm
;        gcc -o out  tagex.o -fno-pie -no-pie `pkg-config --cflags --libs gtk+-3.0`

.x64
option casemap:none
;option frame:auto
;option stackbase:rbp
;option win64:7
option literals:on

.DATA
        WWatch                  dq    0
        WWatchBuffer            dq    0

.CONST
        Tag_Name                db    'rtl_quote'
        First_Property_Name     db    'foreground'
        VarargSys               db    'Green', 'wrap_mode', 2, 'direction', 2, 'indent', 30, 'left_margin', 20, 'right_margin', 20, 0

.CODE

    gtk_init                    PROTO c :VARARG
    gtk_text_view_new           PROTO c :VARARG
    gtk_text_view_get_buffer    PROTO c :VARARG
    gtk_text_buffer_create_tag  PROTO c (ptr) buffer:ptr, tag_name:byte, first_property_name:byte, vararsys:byte

    main PROC
        invoke gtk_init,0,0
        invoke gtk_text_view_new
        mov WWatch              ,rax
        invoke gtk_text_view_get_buffer,WWatch
        mov WWatchBuffer        ,rax
         invoke gtk_text_buffer_create_tag, WWatchBuffer, Tag_Name, First_Property_Name, VarargSys
         ;invoke gtk_text_buffer_create_tag, WWatchBuffer, "red_foreground","foreground", "red", 0
        xor rax,rax
        ret
    main ENDP
end


.text:0000000000000000 ;
.text:0000000000000000 ; Input SHA256 : 7D74305F860BFB64E2FB72FB54BB413C1D2A3C6FBC3D026986AD1AA9CD1878DD
.text:0000000000000000 ; Input MD5    : 8A8B5A168E60D4039955E2AF3B440B53
.text:0000000000000000 ; Input CRC32  : 550833B2
.text:0000000000000000
.text:0000000000000000 ; File Name   : C:\Users\KradMoonRa\Documents\Visual Studio 2019\Projects\crashwithuasm\crashwithuasm\x64\Release\crashwithuasm.obj
.text:0000000000000000 ; Format      : ELF64 for x86-64 (Relocatable)
.text:0000000000000000 ;
.text:0000000000000000 ; Source File : 'crashwithuasm.asm'
.text:0000000000000000
.text:0000000000000000                 .686p
.text:0000000000000000                 .mmx
.text:0000000000000000                 .model flat
.text:0000000000000000 .intel_syntax noprefix
.text:0000000000000000
.text:0000000000000000 ; ===========================================================================
.text:0000000000000000
.text:0000000000000000 ; Segment type: Pure code
.text:0000000000000000 ; Segment permissions: Read/Execute
.text:0000000000000000 _text           segment byte public 'CODE' use64
.text:0000000000000000                 assume cs:_text
.text:0000000000000000                 assume es:nothing, ss:nothing, ds:_data, fs:nothing, gs:nothing
.text:0000000000000000
.text:0000000000000000 ; =============== S U B R O U T I N E =======================================
.text:0000000000000000
.text:0000000000000000
.text:0000000000000000 ; int __cdecl main(int argc, const char **argv, const char **envp)
.text:0000000000000000                 public main
.text:0000000000000000 main            proc near
.text:0000000000000000                 sub     rsp, 8
.text:0000000000000004                 push    0
.text:0000000000000006                 push    0
.text:0000000000000008                 bnd call gtk_init
.text:000000000000000E                 add     rsp, 10h
.text:0000000000000012                 bnd call gtk_text_view_new
.text:0000000000000018                 mov     cs:WWatch, rax
.text:000000000000001F                 push    cs:WWatch
.text:0000000000000025                 bnd call gtk_text_view_get_buffer
.text:000000000000002B                 add     rsp, 8
.text:000000000000002F                 mov     cs:WWatchBuffer, rax
.text:0000000000000036                 mov     al, cs:VarargSys
.text:000000000000003C                 push    rax
.text:000000000000003D                 mov     al, cs:First_Property_Name
.text:0000000000000043                 push    rax
.text:0000000000000044                 mov     al, cs:Tag_Name
.text:000000000000004A                 push    rax
.text:000000000000004B                 push    cs:WWatchBuffer
.text:0000000000000051                 bnd call gtk_text_buffer_create_tag
.text:0000000000000057                 add     rsp, 20h
.text:000000000000005B                 xor     rax, rax
.text:000000000000005E                 add     rsp, 8
.text:0000000000000062                 retn
.text:0000000000000062 main            endp
.text:0000000000000062
.text:0000000000000062 _text           ends
.text:0000000000000062
.data:0000000000000063 ; ===========================================================================
.data:0000000000000063
.data:0000000000000063 ; Segment type: Pure data
.data:0000000000000063 ; Segment permissions: Read/Write
.data:0000000000000063 _data           segment byte public 'DATA' use64
.data:0000000000000063                 assume cs:_data
.data:0000000000000063                 ;org 63h
.data:0000000000000063 WWatch          dq 0                    ; DATA XREF: main+18↑w
.data:0000000000000063                                         ; main+1F↑r
.data:000000000000006B WWatchBuffer    dq 0                    ; DATA XREF: main+2F↑w
.data:000000000000006B                                         ; main+4B↑r
.data:000000000000006B _data           ends
.data:000000000000006B
.rodata:0000000000000073 ; ===========================================================================
.rodata:0000000000000073
.rodata:0000000000000073 ; Segment type: Pure data
.rodata:0000000000000073 ; Segment permissions: Read
.rodata:0000000000000073 _rodata         segment byte public 'CONST' use64
.rodata:0000000000000073                 assume cs:_rodata
.rodata:0000000000000073                 ;org 73h
.rodata:0000000000000073 Tag_Name        db 72h                  ; DATA XREF: main+44↑r
.rodata:0000000000000074                 db  74h ; t
.rodata:0000000000000075                 db  6Ch ; l
.rodata:0000000000000076                 db  5Fh ; _
.rodata:0000000000000077                 db  71h ; q
.rodata:0000000000000078                 db  75h ; u
.rodata:0000000000000079                 db  6Fh ; o
.rodata:000000000000007A                 db  74h ; t
.rodata:000000000000007B                 db  65h ; e
.rodata:000000000000007C First_Property_Name db 66h              ; DATA XREF: main+3D↑r
.rodata:000000000000007D                 db  6Fh ; o
.rodata:000000000000007E                 db  72h ; r
.rodata:000000000000007F                 db  65h ; e
.rodata:0000000000000080                 db  67h ; g
.rodata:0000000000000081                 db  72h ; r
.rodata:0000000000000082                 db  6Fh ; o
.rodata:0000000000000083                 db  75h ; u
.rodata:0000000000000084                 db  6Eh ; n
.rodata:0000000000000085                 db  64h ; d
.rodata:0000000000000086 VarargSys       db 47h                  ; DATA XREF: main+36↑r
.rodata:0000000000000087                 db  72h ; r
.rodata:0000000000000088                 db  65h ; e
.rodata:0000000000000089                 db  65h ; e
.rodata:000000000000008A                 db  6Eh ; n
.rodata:000000000000008B                 db  77h ; w
.rodata:000000000000008C                 db  72h ; r
.rodata:000000000000008D                 db  61h ; a
.rodata:000000000000008E                 db  70h ; p
.rodata:000000000000008F                 db  5Fh ; _
.rodata:0000000000000090                 db  6Dh ; m
.rodata:0000000000000091                 db  6Fh ; o
.rodata:0000000000000092                 db  64h ; d
.rodata:0000000000000093                 db  65h ; e
.rodata:0000000000000094                 db    2
.rodata:0000000000000095                 db  64h ; d
.rodata:0000000000000096                 db  69h ; i
.rodata:0000000000000097                 db  72h ; r
.rodata:0000000000000098                 db  65h ; e
.rodata:0000000000000099                 db  63h ; c
.rodata:000000000000009A                 db  74h ; t
.rodata:000000000000009B                 db  69h ; i
.rodata:000000000000009C                 db  6Fh ; o
.rodata:000000000000009D                 db  6Eh ; n
.rodata:000000000000009E                 db    2
.rodata:000000000000009F                 db  69h ; i
.rodata:00000000000000A0                 db  6Eh ; n
.rodata:00000000000000A1                 db  64h ; d
.rodata:00000000000000A2                 db  65h ; e
.rodata:00000000000000A3                 db  6Eh ; n
.rodata:00000000000000A4                 db  74h ; t
.rodata:00000000000000A5                 db  1Eh
.rodata:00000000000000A6                 db  6Ch ; l
.rodata:00000000000000A7                 db  65h ; e
.rodata:00000000000000A8                 db  66h ; f
.rodata:00000000000000A9                 db  74h ; t
.rodata:00000000000000AA                 db  5Fh ; _
.rodata:00000000000000AB                 db  6Dh ; m
.rodata:00000000000000AC                 db  61h ; a
.rodata:00000000000000AD                 db  72h ; r
.rodata:00000000000000AE                 db  67h ; g
.rodata:00000000000000AF                 db  69h ; i
.rodata:00000000000000B0                 db  6Eh ; n
.rodata:00000000000000B1                 db  14h
.rodata:00000000000000B2                 db  72h ; r
.rodata:00000000000000B3                 db  69h ; i
.rodata:00000000000000B4                 db  67h ; g
.rodata:00000000000000B5                 db  68h ; h
.rodata:00000000000000B6                 db  74h ; t
.rodata:00000000000000B7                 db  5Fh ; _
.rodata:00000000000000B8                 db  6Dh ; m
.rodata:00000000000000B9                 db  61h ; a
.rodata:00000000000000BA                 db  72h ; r
.rodata:00000000000000BB                 db  67h ; g
.rodata:00000000000000BC                 db  69h ; i
.rodata:00000000000000BD                 db  6Eh ; n
.rodata:00000000000000BE                 db  14h
.rodata:00000000000000BF                 db    0
.rodata:00000000000000BF _rodata         ends
.rodata:00000000000000BF
extern:00000000000000C0 ; ===========================================================================
extern:00000000000000C0
extern:00000000000000C0 ; Segment type: Externs
extern:00000000000000C0 ; extern
extern:00000000000000C0                 extrn gtk_init:near     ; CODE XREF: main+8↑p
extern:00000000000000C8                 extrn gtk_text_view_new:near
extern:00000000000000C8                                         ; CODE XREF: main+12↑p
extern:00000000000000D0                 extrn gtk_text_view_get_buffer:near
extern:00000000000000D0                                         ; CODE XREF: main+25↑p
extern:00000000000000D8                 extrn gtk_text_buffer_create_tag:near
extern:00000000000000D8                                         ; CODE XREF: main+51↑p
extern:00000000000000D8
extern:00000000000000D8
extern:00000000000000D8                 end


Weird thing, seams uasm dont like undeclared convention with proto, basically the default it's systemv, no need to rewrite, but vararg it's not accepted  with systemv, but accept an va_list saved on the stack or passed in one register as memory address.

So for the sake of proto crash if no convention declared, must be typed anyways, and for the sake of the invoke knows wath is doing, (I don't like invokes), but usable wen we tell it everything what it needs to do.

The uasmlib

mabdelouahab

/usr/bin/ld: tagex.o: in function `main':
tagex.asm:(.text+0x9): undefined reference to `_gtk_init'
/usr/bin/ld: tagex.asm:(.text+0x12): undefined reference to `_gtk_text_view_new'
/usr/bin/ld: tagex.asm:(.text+0x24): undefined reference to `_gtk_text_view_get_buffer'
/usr/bin/ld: tagex.asm:(.text+0x4f): undefined reference to `_gtk_text_buffer_create_tag'
/usr/bin/ld: tagex.asm:(.text+0x73): undefined reference to `_gtk_text_buffer_create_tag'

KradMoonRa

uasm  -elf64 -zcw tagex.asm

-zcw: no c  _ prefix on names

dinging on the uasm  code fiding why using systemv on protos crash.  :sad:

The uasmlib

mineiro

tagex.uasm
;UTF8 file, CRLF
;assemble main file
;uasm -archSSE -elf64 -Fo=tagex.o tagex.uasm
;assemble module or library
;uasm -archSSE -elf64 -Fo=module.o module.uasm
;link both object files
;gcc -o tagex tagex.o module.o `pkg-config --cflags --libs gtk+-3.0`
;erase object files
;rm tagex.o module.o

.x64
option casemap:none
;option frame:auto
;option stackbase:rbp
;option win64:7
;option literals:on
;c prototypes functions
exit proto systemv status:dword
printf proto systemv pformat:PTR, arg:VARARG

;gtk prototypes functions
gtk_init                    PROTO  :VARARG ;;gtk_init(gint *argc, gchar ***argv)
gtk_text_view_new proto
gtk_text_view_get_buffer proto  :ptr GtkTextView
gtk_text_buffer_create_tag proto  :ptr GtkTextBuffer, :ptr gchar, :ptr gchar, :VARARG


LF equ 10 ;linux new line
CR equ 13 ;mac new line? 10,13?
CRLF equ 13,10 ;windows new line

three equ 3

;our prototypes library function
library proto systemv


.DATA
    WWatch                  dq    0
    WWatchBuffer            dq    0
    align 16
    four db "four",0
    align 16
    five db "five",0

.CODE

main PROC uses rbx r12 r13 r14 r15
local one:qword
local two:qword

    invoke gtk_init,0,0
    invoke gtk_text_view_new
    mov WWatch              ,rax
    invoke gtk_text_view_get_buffer,WWatch
    mov WWatchBuffer        ,rax
    invoke gtk_text_buffer_create_tag, WWatchBuffer, CStr("red_foreground"),CStr("foreground"), CStr("red"), 0

    mov one,1
    mov two,2
    invoke printf,CStr("printf = %d %d %d %s %s",LF),one,two,three,addr four,addr five

    invoke library

    invoke exit,0
main ENDP

end main


module.uasm
.X64

g_print PROTO pstring:PTR,args:VARARG

.data?

.data
align 16
input_string db "inside library",0

.code
align 16
public library ;to better visibility while debugging or disassemble
library proc
invoke g_print,CStr("glib = %s",10),addr input_string
ret
library endp

end
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

aw27

#5
I think some of these prototypes are wrong.
For example:
void gtk_init (int *argc,   char ***argv);
should not be prototyped
gtk_init  PROTO  :VARARG

The simplest way is:
gtk_init proto :PTR, :PTR
unless you want to have fun with pointers to pointers to pointers, but VARARG is never one of the solutions.

However, I don't know what exactly the problem is. Someone should put it in verbose instead of dropping tons of code just for the sake of it.

Sure, the variadic paradigma is different in x64, because a few arguments are passed in registers. Not producing an error when Vararg is declared is inviting for trouble.

mineiro

Boas senhor AW;
I agree with what has been said, the intention to use: VARARG in this particular case is to force the prototype to ignore argc, argv, env.
If the first two parameters of the gtk_init function are zero, then it is not a pointer and will not report errors when assembling. Other words, the program does not use them.
Just to preserve the use of invoke and not of checking the types of function arguments.
abraços.
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

aw27

@Mineiro,

I don't agree that we should attempt do the things in an envious way.
I believed this matter was settled here but apparently not:
http://masm32.com/board/index.php?topic=6774.0

(PS: please take care of Amazonia too)


aw27

I built my above mentioned sample in a Ubuntu 18.04 box.
All's fine.

This is a new VPS I rented yesterday @3.99/month and 300GB disk space that I will use for a huge database that currently seats in my Windows 2008R2 VPS.
The Ubuntu came completely bare, even without any desktop environment, and I am installing everything from scratch which is the hell of a job (because Linux simply sucks, as 90% of the World know but is afraid to say). I am not the guy to use SSH and the VNC alternatives are too slow. I tried to install Remote Desktop and after a few hours gave up, it looks broken with Ubuntu 18.04. Finally I found TeamViewer, and things are progressing faster.


mineiro

Boas senhor AW;
I suppose I didn't understand.
The example below works for me.


;uasm -archSSE -elf64 -Fo=tagex.o tagex.uasm
;gcc -o tagex tagex.o `pkg-config --cflags --libs gtk+-3.0`

.x64
option casemap:none
exit proto systemv status:dword
gtk_init proto :PTR, :PTR
;main proto argc:dword,argv:ptr

.DATA
.CODE

align 16
main proc uses rbx rbp r12 r13 r14 r15 argc:dword,argv:ptr ;opaque prototyping
local _argc:dword
local _argv:qword

    mov _argc,argc
    mov _argv,argv
    invoke gtk_init,addr _argc,addr _argv
    invoke exit,0

main endp
end main


---edit---
gdb is powerfull but more than 1.000 pages just to be read.
I'm using fdbg, but seems that some instructions mnemonics appears different.
http://fdbg.x86asm.net/
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

mabdelouahab


the problem in the stack alignment

Same example ASM an C (with exact prototypes)
The only difference between them is in the second function
Quoteinvoke gtk_text_buffer_create_tag ,WWatchBuffer,"red_foreground","foreground", "red", 0   
        gtk_text_buffer_create_tag (buffer,"red_foreground", "foreground", "red", NULL   )  ;                               
but with UASM:
   0x004011f7      sub     rsp, 8
   0x004011fb      mov     rdi, qword [obj.WWatchBuffer] ; 0x404058
   0x00401202      lea     rsi, obj.__ls14102 ; 0x4040af ; "red_foreground"
   0x00401209      lea     rdx, obj.__ls50762 ; 0x4040be ; "foreground"
   0x00401210      lea     rcx, obj.__ls2622 ; 0x4040c9 ; "red"
   0x00401217      mov     r8, 0
   0x0040121e      xor     eax, eax
   0x00401220      call    sym.imp.gtk_text_buffer_create_tag
   0x00401225      add     rsp, 8

and with gcc:
   0x00001238      mov     rax, qword [var_8h]
   0x0000123c      mov     r8d, 0
   0x00001242      lea     rcx, [rcx] ; 0x2053 ; "red"
   0x00001249      lea     rdx, str.foreground ; 0x2014 ; "foreground"
   0x00001250      lea     rsi, str.red_foreground ; 0x2057 ; "red_foreground"
   0x00001257      mov     rdi, rax
   0x0000125a      mov     eax, 0
   0x0000125f      call    sym.imp.gtk_text_buffer_create_tag


And it is exactly where the problem is located
;        uasm  -elf64 tagex.asm
;        gcc -o out  tagex.o -fno-pie -no-pie `pkg-config --cflags --libs gtk+-3.0`
OPTION LITERALS:ON
;   gtk_init (int *argc,          char ***argv);
    gtk_init                    PROTO  :QWORD,:QWORD
;   gtk_text_view_new (void);   
    gtk_text_view_new           PROTO 
;   gtk_text_view_get_buffer (GtkTextView *text_view);   
    gtk_text_view_get_buffer    PROTO  :ptr
;   gtk_text_buffer_create_tag (GtkTextBuffer *buffer,
;                                const gchar *tag_name,
;                                const gchar *first_property_name,
;                                ...);   
    gtk_text_buffer_create_tag  PROTO  :ptr,:ptr,:ptr,:VARARG
.DATA
        WWatch                  qword    0
        WWatchBuffer            qword    0
.CODE
    main PROC
        invoke gtk_init,0,0
        invoke gtk_text_view_new
        mov WWatch              ,rax
        invoke gtk_text_view_get_buffer,WWatch
        mov WWatchBuffer        ,rax
         invoke gtk_text_buffer_create_tag,WWatchBuffer, "rtl_quote",\
                                  "foreground", "green",\
                                  "wrap_mode", 2,\
                                  "direction", 2,\
                                  "indent", 30,\
                                  "left_margin", 20,\
                                  "right_margin", 20,\
                                  0
        invoke gtk_text_buffer_create_tag ,WWatchBuffer,"red_foreground","foreground", "red", 0                                 
        xor rax,rax
        ret
    main ENDP
end




// gcc tagex.c -o file `pkg-config --cflags --libs gtk+-3.0`
#include <stdlib.h>
#include <stdio.h>
#include <gtk/gtk.h>


int main(int argc, char **argv)
{
    GtkWidget *pWindow;
    GtkWidget *tview;
    GtkTextBuffer *buffer;
    gtk_init(&argc, &argv);

    tview = gtk_text_view_new();
    buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (tview));

   gtk_text_buffer_create_tag(buffer, "rtl_quote",
                                  "foreground", "green",
                                  "wrap_mode", 2,
                                  "direction", 2,
                                  "indent", 30,
                                  "left_margin", 20,
                                  "right_margin", 20,
                                  NULL);
    gtk_text_buffer_create_tag (buffer,"red_foreground", "foreground", "red", NULL   )  ;

    return EXIT_SUCCESS;
}

mineiro

hello sir mabdelouahab;
I suppose the problem can be in return use, sounds like a stackframe that leave.

objdump -d -M intel file
  inside main procedure
  400964: e8 d7 fd ff ff        call   400740 <gtk_text_buffer_create_tag@plt>
  400969: b8 00 00 00 00        mov    eax,0x0
  40096e: c9                    leave 
  40096f: c3                    ret   



  4009a4:       e8 d7 fd ff ff          call   400780 <gtk_text_buffer_create_tag@plt>
  4009a9:       bf 00 00 00 00          mov    edi,0x0
  4009ae:       e8 ad fd ff ff          call   400760 <exit@plt>
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

mabdelouahab

hi mineiro
The error occurs while calling the second function : gtk_text_buffer_create_tag
I tried the code  without this line:" sub rsp, 8", and I noticed the difference

mineiro

#13
I was using uasm version from one year ago, I update it in my machine and now can assemble your source code.
Well,
;        uasm  -elf64 tagex.asm
;        gcc -o out  tagex.o -fno-pie -no-pie `pkg-config --cflags --libs gtk+-3.0`

aligned macro
mov rax,rsp
and rax,0fh
.if rax==0
invoke printf,CStr("rsp aligned = %x",10),rax
.else
;         sub rsp,8
invoke printf,CStr("rsp not aligned = %x",10),rax
    mov rax,60   ;sys_exit
    mov rdi,-1     ;error code
    syscall
;        add rsp,8
.endif
endm


OPTION LITERALS:ON
exit proto :dword
printf proto :VARARG

;   gtk_init (int *argc,          char ***argv);
    gtk_init                    PROTO  :QWORD,:QWORD
;   gtk_text_view_new (void);
    gtk_text_view_new           PROTO
;   gtk_text_view_get_buffer (GtkTextView *text_view);
    gtk_text_view_get_buffer    PROTO  :ptr
;   gtk_text_buffer_create_tag (GtkTextBuffer *buffer,
;                                const gchar *tag_name,
;                                const gchar *first_property_name,
;                                ...);

    gtk_text_buffer_create_tag  PROTO  :ptr,:ptr,:ptr,:VARARG
.DATA
        WWatch                  qword    0
        WWatchBuffer            qword    0
.CODE
main PROC
;align 16
;public main
;main:
;sub rsp,8           ;<---
aligned
        invoke gtk_init,0,0
aligned
        invoke gtk_text_view_new
        mov WWatch              ,rax
aligned
        invoke gtk_text_view_get_buffer,WWatch
        mov WWatchBuffer        ,rax
aligned
          invoke gtk_text_buffer_create_tag,WWatchBuffer, "rtl_quote",\
                                   "foreground", "green",\
                                   "wrap_mode", 2,\
                                   "direction", 2,\
                                   "indent", 30,\
                                   "left_margin", 20,\
                                   "right_margin", 20,\
                                   0
aligned
         invoke gtk_text_buffer_create_tag ,WWatchBuffer,"red_foreground","foreground", "red", 0
aligned
;add rsp,8             <---
        xor rax,rax
        ret
    main ENDP
end


---edit--- add,sub rsp
---edit2-- removed add,sub rsp and inserted a "call" to an exit function to not propagate errors
--- last edit --- added comented sub and add 8
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

aw27

When we use procedures UASM aligns the stack for us when we use labels UASM does not do that. What else needs to be said about this? Nothing.

Quote
gdb is powerfull but more than 1.000 pages just to be read.
I'm using fdbg, but seems that some instructions mnemonics appears different.
http://fdbg.x86asm.net/

Try IDA, probably is the friendliest thing for Linux. (I am talking about the free version, image below)