Advertisement
Guest User

Untitled

a guest
Aug 6th, 2012
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.80 KB | None | 0 0
  1. // Compile as C code, not C++
  2. #include <stdio.h>
  3. #include <stdarg.h>
  4.  
  5. int __cdecl fxn(const char* format, ...)
  6. {
  7.   int r;
  8.   void* p = NULL;
  9.   va_list vl;
  10.   va_start(vl, format);
  11.   r = vprintf(format, vl);
  12.   va_end(vl);
  13.   __asm
  14.   {
  15.     mov p, esp
  16.   }
  17.   printf("ESP = %X\n", p);
  18.   return r;
  19. }
  20.  
  21. int (__stdcall * pfxn)() = (int(__stdcall*)())&fxn;
  22.  
  23. int main(void)
  24. {
  25.   fxn("Hello world %d!\n", 1);
  26.   fxn("Hello world %d!\n", 2);
  27.   fxn("Hello world %d!\n", 3);
  28.   pfxn("Hello world %d!\n", 4);
  29.   pfxn("Hello world %d!\n", 5);
  30.   pfxn("Hello world %d!\n", 6);
  31. /*
  32.   Sample output:
  33.   Hello world 1!
  34.   ESP = CFE14
  35.   Hello world 2!
  36.   ESP = CFE14
  37.   Hello world 3!
  38.   ESP = CFE14
  39.   Hello world 4!
  40.   ESP = CFE14
  41.   Hello world 5!
  42.   ESP = CFE0C
  43.   Hello world 6!
  44.   ESP = CFE04
  45. */
  46.   return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement