flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > 'undefined symbol' when use in DlgProc

Author
Thread Post new topic Reply to topic
Overclick



Joined: 11 Jul 2020
Posts: 669
Location: Ukraine
Overclick 27 Jul 2020, 16:54
Hi
My macro doesn't work in DlgProc with error like undefined symbol 'DlgProc.dragwindow'
It works almost perfect in test program but no luck on window project. Please help me to fix it. First of all I have to do something with sections. But where I move it to default one it doesn't help too
Code:
macro ShowERROR {
        local ..next, ..more, ..over, ..end, ..translator
        local ERROR_temp_buffer,b_ERROR_temp_buffer,ERROR_reg_names,ERROR_msg
        local ERROR_rax_decimal,ERROR_reg_buffer,ERROR_fun_code
        local ERROR_fun_sys,ERROR_fun_buffer,ERROR_flag
        jmp @F
        section '.edata' data readable writeable 
                ERROR_temp_buffer = $
                        times 20        db 0
                b_ERROR_temp_buffer = $
                ERROR_flag              db '<CUSTOM>'
                ERROR_reg_names db 'RAX RBX RCX RDX RSI RDI RBP RSP '
                                                db 'R8  R9  R10 R11 R12 R13 R14 R15 '
                ERROR_msg               db 09h,09h,'    FULL ERROR INFORMATION'
                                                db 0Dh,0Ah,0Dh,0Ah,'RAX Decimal',09h,09h,09h
                ERROR_rax_decimal = $
                        times 20        db ' '
                                                db 0Dh,0Ah,'RAX Signed',09h,09h,09h
                ERROR_rax_signed = $
                        times 20        db ' '
                                                db 0Dh,0Ah,0Dh,0Ah                              
                ERROR_reg_buffer = $
                        times 496       db 20h
                                                db 0Dh,0Ah,'LAST ERROR CODE:',09h,09h,09h
                ERROR_fun_code = $
                        times 20        db ' '
                                                db 0Dh,0Ah,'Flag',09h,09h,09h,09h
                ERROR_fun_sys = $
                                                db 'System  '
                                                db 0Dh,0Ah,'Description:',0Dh,0Ah,0Dh,0Ah
           ERROR_fun_buffer rb 512                                                      
        section '.etext' code readable executable
        @@:
        push                    rax ;120
        push                    rbx ;112
        push                    rcx ;104
        push                    rdx ;96
        push                    rsi ;88
        push                    rdi ;80
        push                    rbp ;72
        push                    rsp ;64
        push                    r8  ;56
        push                    r9  ;48
        push                    r10 ;40
        push                    r11 ;32
        push                    r12 ;24
        push                    r13 ;16
        push                    r14 ;8
        push                    r15
                cld
        ;RAX decimal
                mov                     rax,[rsp+120]
                lea                     rsi,[b_ERROR_temp_buffer]
                lea                     rdi,[ERROR_rax_decimal]
                mov                     rbx,10
                call            ..translator
                rep                     movsb
        ;RAX signed
                mov                     rax,[rsp+120]
                mov                     r8b,byte 20h
                lea                     rsi,[b_ERROR_temp_buffer]
                lea                     rdi,[ERROR_rax_signed]
                mov                     rbx,10
                cmp                     rax,0
                jns                     @F
                mov                     r8b,byte 2Dh
                neg                     rax     
                @@:
                call            ..translator
                inc                     rcx
                dec                     rsi
                mov                     [rsi],r8b
                rep                     movsb   
        ;Registers
                mov                     r11,120         ;stack shift
                mov                     rbx,16          ;divider
                mov                     r8,0       ;name shift
                mov                     r15,1
                lea                     rdi,[ERROR_reg_buffer]          
        ..next: 
                mov                     rax,30h
                push            rdi
                lea                     rdi,[ERROR_temp_buffer]
                mov                     rcx,20
                rep                     stosb
                pop                     rdi
                lea                     rsi,[ERROR_reg_names]
                mov                     rcx,4
                add                     rsi,r8
                rep                     movsb
                mov                     [rdi],byte 09h
                inc                     rdi
                mov                     rax,[rsp+r11]
                lea                     rsi,[b_ERROR_temp_buffer]               
                call            ..translator
                lea                     rsi,[ERROR_temp_buffer+4]
                mov                     r10,8
                @@:     
                mov                     rcx,2
                rep                     movsb
                mov                     [rdi],byte 20h
                inc                     rdi
                dec                     r10
                cmp                     r10,0
                jne                     @B
                cmp                     r15b,0
                jz                      @F
                mov                     [rdi],byte 09h
                inc                     rdi
                @@:             
                cmp                     r15b,0
                jnz                     @F
                mov                     [rdi],word 0D0Ah
                add                     rdi,2
                add                     r15b,2
                @@:     
                dec                     r15b
                add                     r8,4
                sub                     r11,8           
                cmp                     r8,64
                jne                     ..next                  
        jmp ..end
        ..translator:
                xor                     rcx,rcx
                ..more:
                inc                     rcx
                xor                     rdx,rdx
                div                     rbx
                dec                     rsi
                cmp                     dl,15           
                jne                     @F
                mov                     [rsi],byte 'F'
                jmp                     ..over
                @@:
                cmp                     dl,14           
                jne                     @F
                mov                     [rsi],byte 'E'
                jmp                     ..over
                @@:
                cmp                     dl,13           
                jne                     @F
                mov                     [rsi],byte 'D'
                jmp                     ..over
                @@:
                cmp                     dl,12           
                jne                     @F
                mov                     [rsi],byte 'C'
                jmp                     ..over
                @@:
                cmp                     dl,11           
                jne                     @F
                mov                     [rsi],byte 'B'
                jmp                     ..over
                @@:
                cmp                     dl,10           
                jne                     @F
                mov                     [rsi],byte 'A'
                jmp                     ..over
                @@:
                add                     dl,30h
                mov                     [rsi],dl
                ..over:
                cmp                     rax,0
                jne                     ..more
                ret
        ..end:
                add                     rsp,128
                invoke          GetLastError
                mov                     r15d,eax
                bt                      eax,29
                jnc                     @F
                lea                     rdi,[ERROR_fun_sys]
                lea                     rsi,[ERROR_flag]
                mov                     rcx,8
                rep                     movsb
                @@:
                mov                     r8b,byte 20h
                lea                     rsi,[b_ERROR_temp_buffer]
                lea                     rdi,[ERROR_fun_code]
                mov                     rbx,10
                cmp                     eax,0
                jns                     @F
                mov                     r8b,byte 2Dh
                mov                     rax,0xFFFFFFFFFFFFFFFF
                mov                     eax,r15d
                neg                     eax     
                @@:
                btr                     eax,29
                call            ..translator
                inc                     rcx
                dec                     rsi
                mov                     [rsi],r8b
                rep                     movsb   
                invoke          FormatMessage,FORMAT_MESSAGE_ALLOCATE_BUFFER+\
                                                                FORMAT_MESSAGE_FROM_SYSTEM,\
                                                                0,r15d,0,ERROR_fun_buffer,0,0
                invoke          MessageBox,HWND_DESKTOP,ERROR_msg,0,MB_OK
}
    

Also FomatMessage shows some rubbish


Description:
Filesize: 34.74 KB
Viewed: 11055 Time(s)

Capture.PNG


Post 27 Jul 2020, 16:54
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 27 Jul 2020, 22:52
Your code doesn't show any reference to DlgProc.dragwindow.
Post 27 Jul 2020, 22:52
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 669
Location: Ukraine
Overclick 28 Jul 2020, 05:21
I know. Say that to compiler Wink
Even if I remove extra sections the best I can see is absolutelly ignored macro operations.
Other macros works fine, DlgProc without this macro works too.
Could you try it by yourself?
Post 28 Jul 2020, 05:21
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 28 Jul 2020, 05:39
We don't know what you have done.

When I assemble the code you posted I see this:
Code:
1 passes, 0 bytes.    


Post some minimal code we can compile that shows the problem.

Minimal code usually doesn't need more than 5 or 10 lines at most.
Post 28 Jul 2020, 05:39
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 669
Location: Ukraine
Overclick 28 Jul 2020, 05:51
It does error in any DlgProc, not just mine.

Here the one from examples:
Code:

format PE64 GUI 5.0
entry start

include 'win64a.inc'
macro ShowERROR {
        local ..next, ..more, ..over, ..end, ..translator
        local ERROR_temp_buffer,b_ERROR_temp_buffer,ERROR_reg_names,ERROR_msg
        local ERROR_rax_decimal,ERROR_reg_buffer,ERROR_fun_code
        local ERROR_fun_sys,ERROR_fun_buffer,ERROR_flag
        jmp @F
        section '.edata' data readable writeable 
                ERROR_temp_buffer = $
                        times 20        db 0
                b_ERROR_temp_buffer = $
                ERROR_flag              db '<CUSTOM>'
                ERROR_reg_names db 'RAX RBX RCX RDX RSI RDI RBP RSP '
                                                db 'R8  R9  R10 R11 R12 R13 R14 R15 '
                ERROR_msg               db 09h,09h,'    FULL ERROR INFORMATION'
                                                db 0Dh,0Ah,0Dh,0Ah,'RAX Decimal',09h,09h,09h
                ERROR_rax_decimal = $
                        times 20        db ' '
                                                db 0Dh,0Ah,'RAX Signed',09h,09h,09h
                ERROR_rax_signed = $
                        times 20        db ' '
                                                db 0Dh,0Ah,0Dh,0Ah                              
                ERROR_reg_buffer = $
                        times 496       db 20h
                                                db 0Dh,0Ah,'LAST ERROR CODE:',09h,09h,09h
                ERROR_fun_code = $
                        times 20        db ' '
                                                db 0Dh,0Ah,'Flag',09h,09h,09h,09h
                ERROR_fun_sys = $
                                                db 'System  '
                                                db 0Dh,0Ah,'Description:',0Dh,0Ah,0Dh,0Ah
           ERROR_fun_buffer rb 512                                                      
        section '.etext' code readable executable
        @@:
        push                    rax ;120
        push                    rbx ;112
        push                    rcx ;104
        push                    rdx ;96
        push                    rsi ;88
        push                    rdi ;80
        push                    rbp ;72
        push                    rsp ;64
        push                    r8  ;56
        push                    r9  ;48
        push                    r10 ;40
        push                    r11 ;32
        push                    r12 ;24
        push                    r13 ;16
        push                    r14 ;8
        push                    r15
                cld
        ;RAX decimal
                mov                     rax,[rsp+120]
                lea                     rsi,[b_ERROR_temp_buffer]
                lea                     rdi,[ERROR_rax_decimal]
                mov                     rbx,10
                call            ..translator
                rep                     movsb
        ;RAX signed
                mov                     rax,[rsp+120]
                mov                     r8b,byte 20h
                lea                     rsi,[b_ERROR_temp_buffer]
                lea                     rdi,[ERROR_rax_signed]
                mov                     rbx,10
                cmp                     rax,0
                jns                     @F
                mov                     r8b,byte 2Dh
                neg                     rax     
                @@:
                call            ..translator
                inc                     rcx
                dec                     rsi
                mov                     [rsi],r8b
                rep                     movsb   
        ;Registers
                mov                     r11,120         ;stack shift
                mov                     rbx,16          ;divider
                mov                     r8,0       ;name shift
                mov                     r15,1
                lea                     rdi,[ERROR_reg_buffer]          
        ..next: 
                mov                     rax,30h
                push            rdi
                lea                     rdi,[ERROR_temp_buffer]
                mov                     rcx,20
                rep                     stosb
                pop                     rdi
                lea                     rsi,[ERROR_reg_names]
                mov                     rcx,4
                add                     rsi,r8
                rep                     movsb
                mov                     [rdi],byte 09h
                inc                     rdi
                mov                     rax,[rsp+r11]
                lea                     rsi,[b_ERROR_temp_buffer]               
                call            ..translator
                lea                     rsi,[ERROR_temp_buffer+4]
                mov                     r10,8
                @@:     
                mov                     rcx,2
                rep                     movsb
                mov                     [rdi],byte 20h
                inc                     rdi
                dec                     r10
                cmp                     r10,0
                jne                     @B
                cmp                     r15b,0
                jz                      @F
                mov                     [rdi],byte 09h
                inc                     rdi
                @@:             
                cmp                     r15b,0
                jnz                     @F
                mov                     [rdi],word 0D0Ah
                add                     rdi,2
                add                     r15b,2
                @@:     
                dec                     r15b
                add                     r8,4
                sub                     r11,8           
                cmp                     r8,64
                jne                     ..next                  
        jmp ..end
        ..translator:
                xor                     rcx,rcx
                ..more:
                inc                     rcx
                xor                     rdx,rdx
                div                     rbx
                dec                     rsi
                cmp                     dl,15           
                jne                     @F
                mov                     [rsi],byte 'F'
                jmp                     ..over
                @@:
                cmp                     dl,14           
                jne                     @F
                mov                     [rsi],byte 'E'
                jmp                     ..over
                @@:
                cmp                     dl,13           
                jne                     @F
                mov                     [rsi],byte 'D'
                jmp                     ..over
                @@:
                cmp                     dl,12           
                jne                     @F
                mov                     [rsi],byte 'C'
                jmp                     ..over
                @@:
                cmp                     dl,11           
                jne                     @F
                mov                     [rsi],byte 'B'
                jmp                     ..over
                @@:
                cmp                     dl,10           
                jne                     @F
                mov                     [rsi],byte 'A'
                jmp                     ..over
                @@:
                add                     dl,30h
                mov                     [rsi],dl
                ..over:
                cmp                     rax,0
                jne                     ..more
                ret
        ..end:
                add                     rsp,128
                invoke          GetLastError
                mov                     r15d,eax
                bt                      eax,29
                jnc                     @F
                lea                     rdi,[ERROR_fun_sys]
                lea                     rsi,[ERROR_flag]
                mov                     rcx,8
                rep                     movsb
                @@:
                mov                     r8b,byte 20h
                lea                     rsi,[b_ERROR_temp_buffer]
                lea                     rdi,[ERROR_fun_code]
                mov                     rbx,10
                cmp                     eax,0
                jns                     @F
                mov                     r8b,byte 2Dh
                mov                     rax,0xFFFFFFFFFFFFFFFF
                mov                     eax,r15d
                neg                     eax     
                @@:
                btr                     eax,29
                call            ..translator
                inc                     rcx
                dec                     rsi
                mov                     [rsi],r8b
                rep                     movsb   
                invoke          FormatMessage,FORMAT_MESSAGE_ALLOCATE_BUFFER+\
                                                                FORMAT_MESSAGE_FROM_SYSTEM,\
                                                                0,r15d,0,ERROR_fun_buffer,0,0
                invoke          MessageBox,HWND_DESKTOP,ERROR_msg,0,MB_OK
}
section '.text' code readable executable

  start:
        sub     rsp,8           ; Make stack dqword aligned

        invoke  GetModuleHandle,0
        mov     [wc.hInstance],rax
        invoke  LoadIcon,0,IDI_APPLICATION
        mov     [wc.hIcon],rax
        mov     [wc.hIconSm],rax
        invoke  LoadCursor,0,IDC_ARROW
        mov     [wc.hCursor],rax
        invoke  RegisterClassEx,wc
        test    rax,rax
        jz      error

        invoke  CreateWindowEx,0,_class,_title,WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU,128,128,256,192,NULL,NULL,[wc.hInstance],NULL
        test    rax,rax
        jz      error

  msg_loop:
        invoke  GetMessage,msg,NULL,0,0
        cmp     eax,1
        jb      end_loop
        jne     msg_loop
        invoke  TranslateMessage,msg
        invoke  DispatchMessage,msg
        jmp     msg_loop

  error:
        invoke  MessageBox,NULL,_error,NULL,MB_ICONERROR+MB_OK

  end_loop:
        invoke  ExitProcess,[msg.wParam]

proc WindowProc uses rbx rsi rdi, hwnd,wmsg,wparam,lparam

; Note that first four parameters are passed in registers,
; while names given in the declaration of procedure refer to the stack
; space reserved for them - you may store them there to be later accessible
; if the contents of registers gets destroyed. This may look like:
;       mov     [hwnd],rcx
;       mov     [wmsg],edx
;       mov     [wparam],r8
;       mov     [lparam],r9

        cmp     edx,WM_DESTROY
        je      .wmdestroy
  .defwndproc:
        ShowERROR
        invoke  DefWindowProc,rcx,rdx,r8,r9
        jmp     .finish
  .wmdestroy:
        invoke  PostQuitMessage,0
        xor     eax,eax
  .finish:
        ret

endp

section '.data' data readable writeable

  _title TCHAR 'Win64 program template',0
  _class TCHAR 'FASMWIN64',0
  _error TCHAR 'Startup failed.',0

  wc WNDCLASSEX sizeof.WNDCLASSEX,0,WindowProc,0,0,NULL,NULL,NULL,COLOR_BTNFACE+1,NULL,_class,NULL

  msg MSG

section '.idata' import data readable writeable

  library kernel32,'KERNEL32.DLL',\
          user32,'USER32.DLL'

  include 'api\kernel32.inc'
  include 'api\user32.inc'   
    
Post 28 Jul 2020, 05:51
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 28 Jul 2020, 05:58
Okay, you posted too much, but anyhow ...

So when you include your macro you make a new the base label which is probably "ERROR_fun_buffer" and the next dot label will be "ERROR_fun_buffer.wmdestroy"

You can try making all the local labels to begin with two dots. "..ERROR_fun_buffer"

BTW: You have a PE exe format, so fasm will create the sections, instead of using a linker. I wouldn't recommend making all those sections. fasm doesn't coalesce then together like the linker would.
Post 28 Jul 2020, 05:58
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 669
Location: Ukraine
Overclick 28 Jul 2020, 06:05
Any idea how to declare that data from macro temporary?
This macro needed just for maintenance, I don't want to hold all it's data on real code or clear it up every time.
Post 28 Jul 2020, 06:05
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 28 Jul 2020, 06:10
Macros don't create a special area for labels. Each time you instantiate them it is exactly the same as if you have cut-and-pasted it in there. So all the labels are created as normal.

The only effect local has to to append a unique sequence of letters the the label names. So if you create new base labels then you are stuck with them. So it could be something like "ERROR_fun_buffer?34FD" as a label name.

So like I mentioned above put two leading dots in each label name.
Code:
local ..ERROR_fun_buffer    


Last edited by revolution on 28 Jul 2020, 06:12; edited 1 time in total
Post 28 Jul 2020, 06:10
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 669
Location: Ukraine
Overclick 28 Jul 2020, 06:11
Added dots. No more errors but macro is ignored and next operation after that too
Post 28 Jul 2020, 06:11
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 28 Jul 2020, 06:13
Show the minimal code of what you did.
Post 28 Jul 2020, 06:13
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 669
Location: Ukraine
Overclick 28 Jul 2020, 06:16
Code:
format PE64 GUI 5.0
entry start

include 'win64a.inc'
macro ShowERROR {
        local ..next, ..more, ..over, ..end, ..translator
        local ..ERROR_temp_buffer,..b_ERROR_temp_buffer,..ERROR_reg_names,..ERROR_msg
        local ..ERROR_rax_decimal,..ERROR_reg_buffer,..ERROR_fun_code
        local ..ERROR_fun_sys,..ERROR_fun_buffer,..ERROR_flag
        jmp @F
        section '.edata' data readable writeable 
                ..ERROR_temp_buffer = $
                        times 20        db 0
                ..b_ERROR_temp_buffer = $
                ..ERROR_flag            db '<CUSTOM>'
                ..ERROR_reg_names       db 'RAX RBX RCX RDX RSI RDI RBP RSP '
                                                db 'R8  R9  R10 R11 R12 R13 R14 R15 '
                ..ERROR_msg             db 09h,09h,'    FULL ERROR INFORMATION'
                                                db 0Dh,0Ah,0Dh,0Ah,'RAX Decimal',09h,09h,09h
                ..ERROR_rax_decimal = $
                        times 20        db ' '
                                                db 0Dh,0Ah,'RAX Signed',09h,09h,09h
                ..ERROR_rax_signed = $
                        times 20        db ' '
                                                db 0Dh,0Ah,0Dh,0Ah                              
                ..ERROR_reg_buffer = $
                        times 496       db 20h
                                                db 0Dh,0Ah,'LAST ERROR CODE:',09h,09h,09h
                ..ERROR_fun_code = $
                        times 20        db ' '
                                                db 0Dh,0Ah,'Flag',09h,09h,09h,09h
                ..ERROR_fun_sys = $
                                                db 'System  '
                                                db 0Dh,0Ah,'Description:',0Dh,0Ah,0Dh,0Ah
           ..ERROR_fun_buffer db 512 dup (0)                                                    
        section '.etext' code readable executable
        @@:
        push                    rax ;120
        push                    rbx ;112
        push                    rcx ;104
        push                    rdx ;96
        push                    rsi ;88
        push                    rdi ;80
        push                    rbp ;72
        push                    rsp ;64
        push                    r8  ;56
        push                    r9  ;48
        push                    r10 ;40
        push                    r11 ;32
        push                    r12 ;24
        push                    r13 ;16
        push                    r14 ;8
        push                    r15
                cld
        ;RAX decimal
                mov                     rax,[rsp+120]
                lea                     rsi,[..b_ERROR_temp_buffer]
                lea                     rdi,[..ERROR_rax_decimal]
                mov                     rbx,10
                call            ..translator
                rep                     movsb
        ;RAX signed
                mov                     rax,[rsp+120]
                mov                     r8b,byte 20h
                lea                     rsi,[..b_ERROR_temp_buffer]
                lea                     rdi,[..ERROR_rax_signed]
                mov                     rbx,10
                cmp                     rax,0
                jns                     @F
                mov                     r8b,byte 2Dh
                neg                     rax     
                @@:
                call            ..translator
                inc                     rcx
                dec                     rsi
                mov                     [rsi],r8b
                rep                     movsb   
        ;Registers
                mov                     r11,120         ;stack shift
                mov                     rbx,16          ;divider
                mov                     r8,0       ;name shift
                mov                     r15,1
                lea                     rdi,[..ERROR_reg_buffer]                
        ..next: 
                mov                     rax,30h
                push            rdi
                lea                     rdi,[..ERROR_temp_buffer]
                mov                     rcx,20
                rep                     stosb
                pop                     rdi
                lea                     rsi,[..ERROR_reg_names]
                mov                     rcx,4
                add                     rsi,r8
                rep                     movsb
                mov                     [rdi],byte 09h
                inc                     rdi
                mov                     rax,[rsp+r11]
                lea                     rsi,[..b_ERROR_temp_buffer]             
                call            ..translator
                lea                     rsi,[..ERROR_temp_buffer+4]
                mov                     r10,8
                @@:     
                mov                     rcx,2
                rep                     movsb
                mov                     [rdi],byte 20h
                inc                     rdi
                dec                     r10
                cmp                     r10,0
                jne                     @B
                cmp                     r15b,0
                jz                      @F
                mov                     [rdi],byte 09h
                inc                     rdi
                @@:             
                cmp                     r15b,0
                jnz                     @F
                mov                     [rdi],word 0D0Ah
                add                     rdi,2
                add                     r15b,2
                @@:     
                dec                     r15b
                add                     r8,4
                sub                     r11,8           
                cmp                     r8,64
                jne                     ..next                  
        jmp ..end
        ..translator:
                xor                     rcx,rcx
                ..more:
                inc                     rcx
                xor                     rdx,rdx
                div                     rbx
                dec                     rsi
                cmp                     dl,15           
                jne                     @F
                mov                     [rsi],byte 'F'
                jmp                     ..over
                @@:
                cmp                     dl,14           
                jne                     @F
                mov                     [rsi],byte 'E'
                jmp                     ..over
                @@:
                cmp                     dl,13           
                jne                     @F
                mov                     [rsi],byte 'D'
                jmp                     ..over
                @@:
                cmp                     dl,12           
                jne                     @F
                mov                     [rsi],byte 'C'
                jmp                     ..over
                @@:
                cmp                     dl,11           
                jne                     @F
                mov                     [rsi],byte 'B'
                jmp                     ..over
                @@:
                cmp                     dl,10           
                jne                     @F
                mov                     [rsi],byte 'A'
                jmp                     ..over
                @@:
                add                     dl,30h
                mov                     [rsi],dl
                ..over:
                cmp                     rax,0
                jne                     ..more
                ret
        ..end:
                add                     rsp,128
                invoke          GetLastError
                mov                     r15d,eax
                bt                      eax,29
                jnc                     @F
                lea                     rdi,[..ERROR_fun_sys]
                lea                     rsi,[..ERROR_flag]
                mov                     rcx,8
                rep                     movsb
                @@:
                mov                     r8b,byte 20h
                lea                     rsi,[..b_ERROR_temp_buffer]
                lea                     rdi,[..ERROR_fun_code]
                mov                     rbx,10
                cmp                     eax,0
                jns                     @F
                mov                     r8b,byte 2Dh
                mov                     rax,0xFFFFFFFFFFFFFFFF
                mov                     eax,r15d
                neg                     eax     
                @@:
                btr                     eax,29
                call            ..translator
                inc                     rcx
                dec                     rsi
                mov                     [rsi],r8b
                rep                     movsb   
                invoke          FormatMessage,FORMAT_MESSAGE_ALLOCATE_BUFFER+\
                                                                FORMAT_MESSAGE_FROM_SYSTEM,\
                                                                0,r15d,0,..ERROR_fun_buffer,0,0
                invoke          MessageBox,HWND_DESKTOP,..ERROR_msg,0,MB_OK
}
section '.text' code readable executable

  start:
        sub     rsp,8           ; Make stack dqword aligned

        invoke  GetModuleHandle,0
        mov     [wc.hInstance],rax
        invoke  LoadIcon,0,IDI_APPLICATION
        mov     [wc.hIcon],rax
        mov     [wc.hIconSm],rax
        invoke  LoadCursor,0,IDC_ARROW
        mov     [wc.hCursor],rax
        invoke  RegisterClassEx,wc
        test    rax,rax
        jz      error

        invoke  CreateWindowEx,0,_class,_title,WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU,128,128,256,192,NULL,NULL,[wc.hInstance],NULL
        test    rax,rax
        jz      error

  msg_loop:
        invoke  GetMessage,msg,NULL,0,0
        cmp     eax,1
        jb      end_loop
        jne     msg_loop
        invoke  TranslateMessage,msg
        invoke  DispatchMessage,msg
        jmp     msg_loop

  error:
        invoke  MessageBox,NULL,_error,NULL,MB_ICONERROR+MB_OK

  end_loop:
        invoke  ExitProcess,[msg.wParam]

proc WindowProc uses rbx rsi rdi, hwnd,wmsg,wparam,lparam

; Note that first four parameters are passed in registers,
; while names given in the declaration of procedure refer to the stack
; space reserved for them - you may store them there to be later accessible
; if the contents of registers gets destroyed. This may look like:
;       mov     [hwnd],rcx
;       mov     [wmsg],edx
;       mov     [wparam],r8
;       mov     [lparam],r9

        cmp     edx,WM_DESTROY
        je      .wmdestroy
  .defwndproc:
        ShowERROR
        invoke  DefWindowProc,rcx,rdx,r8,r9
        jmp     .finish
  .wmdestroy:
        invoke  PostQuitMessage,0
        xor     eax,eax
  .finish:
        ret

endp

section '.data' data readable writeable

  _title TCHAR 'Win64 program template',0
  _class TCHAR 'FASMWIN64',0
  _error TCHAR 'Startup failed.',0

  wc WNDCLASSEX sizeof.WNDCLASSEX,0,WindowProc,0,0,NULL,NULL,NULL,COLOR_BTNFACE+1,NULL,_class,NULL

  msg MSG

section '.idata' import data readable writeable

  library kernel32,'KERNEL32.DLL',\
          user32,'USER32.DLL'

  include 'api\kernel32.inc'
  include 'api\user32.inc'    
Post 28 Jul 2020, 06:16
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 669
Location: Ukraine
Overclick 28 Jul 2020, 06:18
Is it about sections now?
Post 28 Jul 2020, 06:18
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 28 Jul 2020, 06:21
Works for me
Code:
4 passes, 0.2 seconds, 5632 bytes.    
Post 28 Jul 2020, 06:21
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 669
Location: Ukraine
Overclick 28 Jul 2020, 06:24
Sad
What version of fasm do you have?
For me it passed too but did you try to run it?
Post 28 Jul 2020, 06:24
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20363
Location: In your JS exploiting you and your system
revolution 28 Jul 2020, 06:26
I didn't run it.
Post 28 Jul 2020, 06:26
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.