Why wsprintf is not clearing the stack (popping the arguments)

Started by Vineel Kumar Reddy Kovvuri, May 09, 2007, 03:45:04 PM

Previous topic - Next topic

Vineel Kumar Reddy Kovvuri




Hi Everybody

I am new to assembly and wanted to learn it.
plz help me

why wsprintf is not clearing the arguments on the stack (not popping the arguments)after the function call

where as some of win32 API functions like WriteFile is clearing the stack.

How can i know which function clears the stack and which does not ?

plz reply to this post

thanks in advance

:'(




BogdanOntanu

AFAIK from Win32API only wsprintf is using C calling conventions. All other API is using STDCALL and this means each function does clear it's own stack before exit.

wsprintf uses C calling convention because the number of parameters is unknown to the function at runtime since  it depends on the format string contents.

So in order to void crashing if a parameter is missing by mistake the stack has to be cleared by the caller. Hopefully the caler knows how many parameters have been pushed and will clear exactly that much no matter of the format string contents... this is the reason behind this...
Ambition is a lame excuse for the ones not brave enough to be lazy.
http://www.oby.ro

Vineel Kumar Reddy Kovvuri



thank you for your reply sir


now i clearly understood the idea behind wsprintf why it is not clearing the stack .

thanks alot


Vortex

vineel,

Using Ollydbg, try to observe the state of the stack before and after a call to wsprintf, this will help you to understand.

GregL

vineel,

Just so you know, if you use PROTO C and INVOKE the assembler takes care of balancing the stack for C functions.


Vineel Kumar Reddy Kovvuri



Thank you Vortex

I used olly and observed the stack .It is crystal clear thanks once again

Thank you Greg

yaa using INVOKE i observed it in olly . The disassembled code automatically erased the stack
by using "add esp 0c "    thank you for your suggestion






Vortex

Hi vineel,

You are welcome. Ollydbg is one of the best tools for asm coders.