flat assembler
Message board for the users of flat assembler.

Index > Main > Read arguments from Stack!

Author
Thread Post new topic Reply to topic
q6z4k



Joined: 28 Jul 2005
Posts: 2
q6z4k
Hi!
I'm trying to write very simple server app. I'm having trouble with recv function.
Code:
ssize_t recv(int s, void *buf, size_t len, int flags);    

In C its very easy, just declare char array and give it as a second argument for recv(); How can I do it with asm? I think I need to find a free space in the stack, and give recv(); function address, and then latter I could read the received data! How can I do this? This is how far I get:
Code:
...
           push 0x00                   ; int flags
           push 0x0a                   ; size_t len
           push long esp              ; void *buf
           mov esi, esp                ; save the addresss
           push edi                       ; int s

           mov eax, 0x66             ; sockcall();
           mov ebx, 0x0a             ; recv();
           mov ecx, esi                 ; address to the recv(); arguments on the stack
           int 0x80                       ; call the kernel

           mov eax, 4                   ; write();
           mov ebx, 1                   
           mov ecx, esi                 ; the address where recv. data should be
           mov edx, 25               
           int 0x80
...    

All I get is: öÿ¿<!DOCTYPE ,öÿ¿ I think I give the recv(); wrong address! Do I have to allocate space on the stack like in C with malloc? How can I do it with FASM? Thank you!
Post 28 Jul 2005, 13:32
View user's profile Send private message Reply with quote
kandamun



Joined: 20 Jul 2005
Posts: 25
kandamun
To allocated some stack you can do
Code:
sub esp, SIZE_OF_BUFFER     ;; now esp points the buffer 
mov esi, esp                ;; then save it or use it
    


I'm not sure if SIZE_OF_BUFFER must be multiple of 4.
And don't forget to clean it up before returning from the function.
Code:
;; you can always do
add esp, SIZE_OF_BUFFER
;; at the right place between push and pop blocks
    
Post 28 Jul 2005, 16:27
View user's profile Send private message ICQ Number Reply with quote
q6z4k



Joined: 28 Jul 2005
Posts: 2
q6z4k
Thanks man, that worked!
What are the limitations? Whats the maximum that, I can allocate?
Post 28 Jul 2005, 19:59
View user's profile Send private message 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.