Advertisement
snake5

asmix test code [preprocessed]

Aug 4th, 2014
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <windows.h>
  4. #include <inttypes.h>
  5.  
  6. typedef int (*somefn) ( int, int );
  7.  
  8. int main()
  9. {
  10.     char prebuf[ 512 ];
  11.     int precnt = 0;
  12.    
  13.     int randnum = rand();
  14.    
  15. #define APPEND_CODE( cb, cbsize ) \
  16.     memcpy( prebuf + precnt, cb, cbsize ); \
  17.     precnt += cbsize;
  18.    
  19.     // return ( randnum + arg0 ) * arg1
  20.     {char __asm0[] = {-72,0,0,0,0,3,68,36,4,15,-81,68,36,8,-61}; *(int32_t*)(__asm0+1) = randnum; APPEND_CODE(__asm0,15);}
  21. #undef APPEND_CODE
  22.    
  23.     while( precnt % 4 != 0 )
  24.         prebuf[ precnt++ ] = 0x90; // padding NOP
  25.    
  26.     void* func = VirtualAlloc( NULL, precnt, MEM_COMMIT, PAGE_EXECUTE_READWRITE );
  27.     memcpy( func, prebuf, precnt );
  28.    
  29.     int test = ((somefn)func)( 3, 2 );
  30.     printf( "random number: %d\nreturn value: %d\n", randnum, test );
  31.    
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement