flat assembler
Message board for the users of flat assembler.

Index > Windows > symbol 'sprintf' out of scope

Author
Thread Post new topic Reply to topic
l4m2



Joined: 15 Jan 2015
Posts: 648
l4m2
I was trying to use sprintf in fasm and wrote
Code:
include 'win32ax.inc'
macro japi [name] { if used name
                    label name dword at name
                   end if }

.code

  start:
        invoke  sprintf, ddd, "%d", 3
        invoke  MessageBox,HWND_DESKTOP,ddd,invoke GetCommandLine,MB_OK
        invoke  ExitProcess,0

.end start

section '.data' data readable writeable
     ddd: db 32 dup 0
     ;library mscvrt,'mscvrt.DLL'
import mscvrt,sprintf,'sprintf'
    japi sprintf
                            
and error occured:

symbol 'sprintf' out of scope
label sprintf dword at sprintf[/list]
Post 16 Oct 2015, 23:24
View user's profile Send private message Reply with quote
l4m2



Joined: 15 Jan 2015
Posts: 648
l4m2
and this one can be successfully compiled but runtime error
Code:
; Simple text editor - fasm example program

format PE GUI 4.0
entry start

include 'win32a.inc'

IDM_NEW   = 101
IDM_EXIT  = 102
IDM_ABOUT = 901

section '.text' code readable executable

  start:
        invoke  sprintf, ddd, "%d", 3
        invoke  MessageBox,HWND_DESKTOP,ddd,"",MB_OK
        invoke  ExitProcess,0


section '.data' data readable writeable

   ddd db 32 dup 0

section '.idata' import data readable writeable

  library kernel,'KERNEL32.DLL',\
          user,'USER32.DLL',\
          mscvrt,'msvcrt.DLL'

  import kernel,\
         ExitProcess,'ExitProcess'

  import user,\
         MessageBox,'MessageBoxA'

  import mscvrt,sprintf,'sprintf'    
Post 16 Oct 2015, 23:33
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17450
Location: In your JS exploiting you and your system
revolution
If you want to put string pointers in invoke calls then you need to use win32ax.inc.

And sprintf is a ccall function so you need to use cinvoke.
Post 17 Oct 2015, 00:20
View user's profile Send private message Visit poster's website Reply with quote
l4m2



Joined: 15 Jan 2015
Posts: 648
l4m2
So why does the function 1 complied failed?
cinvoke should be used but here even if you use invoke it runs successfully and just there'd be some rubbish on the stack (but still thank you for your answering about this!)
Post 17 Oct 2015, 02:01
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17450
Location: In your JS exploiting you and your system
revolution
There is a difference between a string pointer and a string constant:
Code:
push "AB" ;push 0x00004241 <--- string constant
org 0x12345678
AB: db "AB",0
push AB ;push 0x12345678 <--- pointer to string    
The win32ax version of the macros will convert string constants to string pointers for you.
Post 17 Oct 2015, 02:57
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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.