Advertisement
snake5

asmix test code

Aug 4th, 2014
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 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.     <$
  21.     mov eax, :i32(randnum)
  22.     add eax, [esp+4]
  23.     imul eax, [esp+8]
  24.     ret
  25.     $>
  26. #undef APPEND_CODE
  27.    
  28.     while( precnt % 4 != 0 )
  29.         prebuf[ precnt++ ] = 0x90; // padding NOP
  30.    
  31.     void* func = VirtualAlloc( NULL, precnt, MEM_COMMIT, PAGE_EXECUTE_READWRITE );
  32.     memcpy( func, prebuf, precnt );
  33.    
  34.     int test = ((somefn)func)( 3, 2 );
  35.     printf( "random number: %d\nreturn value: %d\n", randnum, test );
  36.    
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement