Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Aug 6th, 2012  |  syntax: C  |  size: 0.80 KB  |  views: 32  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }
clone this paste RAW Paste Data