flat assembler
Message board for the users of flat assembler.

Index > Windows > a question(too hard to explain in little amount of words...)

Author
Thread Post new topic Reply to topic
windwakr



Joined: 30 Jun 2004
Posts: 827
Location: Michigan, USA
windwakr
How do I do something like put an invoke into a string....what I mean is when I do an invoke how do I put the return into a string?
example:
I invoke getsystemmetrics,1.....how do I put that into a string?


Thanks

_________________
----> * <---- My star, won HERE
Post 12 Jul 2004, 20:03
View user's profile Send private message Reply with quote
coconut



Joined: 02 Apr 2004
Posts: 326
Location: usa
coconut
most APIs that return a string actually return a pointer to a string buffer, probably eax. example:

Code:
format pe gui 4.0
entry start

include '%FASMINC%\win32a.inc'

_hello db 'hello world',0


  start:
        mov     eax, _hello
        invoke  MessageBox,0,eax,eax,0
        invoke  ExitProcess


;;
section '.idata' import data readable writeable

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

  import kernel,\
         ExitProcess,'ExitProcess'

  import user,\
         MessageBox,'MessageBoxA'
    


any APIs like MessageBoxA that work with a pointer to a string buffer will take the returning buffer pointed at by eax. havent played with GetSystemMetrics myself but try maybe:

Code:

        invoke  GetSystemMetrics, 1
        mov     [buff], eax                ;return value/string buffer
        invoke  MessageBox,0,buff,buff,0
    


to format/process the string buffer you may have to play with various APIs like wsprintf, or perhaps search the boards for different string macros
Post 13 Jul 2004, 04:28
View user's profile Send private message Reply with quote
wolf



Joined: 28 Sep 2003
Posts: 11
wolf
Perhaps you mean sth. like this:
Code:
section '.code' code readable writeable executable

start:
syscall GetSystemMetrics,SM_CXFULLSCREEN
stdcall dwtoa,eax,Buffer
syscall MessageBox,0,eax,Title,0
syscall ExitProcess,0

proc dwtoa,value,buff
     enterproc
        mov eax,[value]
        mov ecx,10
        mov edi,[buff]
        add edi,14
        mov byte[edi+1],0
     .loop:
        xor edx,edx
        test eax,eax
        je .finish
        div ecx
        add dl,'0'
        mov byte[edi],dl
        dec edi
        jmp .loop
     .finish:
       inc edi
       mov eax,edi
     endproc

Title db 'function result is:',0
Buffer rb 16    
the dwtoa function is only for demonstration.

wolf
Post 13 Jul 2004, 10:55
View user's profile Send private message Reply with quote
coconut



Joined: 02 Apr 2004
Posts: 326
Location: usa
coconut
wolf, nice example on dwtoa. however it gives wierd results with negative numbers, was it meant to handle them?
Post 03 Aug 2004, 02:46
View user's profile Send private message Reply with quote
VitalOne



Joined: 29 Jul 2003
Posts: 54
Location: USA
VitalOne
You can also use wsprintf API, like this

Code:
invoke wsprintf,string_buffer,"%d",eax
    
Post 03 Aug 2004, 03:43
View user's profile Send private message AIM Address Yahoo Messenger 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.

Powered by rwasa.