Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <windows.h>
- #include <inttypes.h>
- typedef int (*somefn) ( int, int );
- int main()
- {
- char prebuf[ 512 ];
- int precnt = 0;
- int randnum = rand();
- #define APPEND_CODE( cb, cbsize ) \
- memcpy( prebuf + precnt, cb, cbsize ); \
- precnt += cbsize;
- // return ( randnum + arg0 ) * arg1
- {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);}
- #undef APPEND_CODE
- while( precnt % 4 != 0 )
- prebuf[ precnt++ ] = 0x90; // padding NOP
- void* func = VirtualAlloc( NULL, precnt, MEM_COMMIT, PAGE_EXECUTE_READWRITE );
- memcpy( func, prebuf, precnt );
- int test = ((somefn)func)( 3, 2 );
- printf( "random number: %d\nreturn value: %d\n", randnum, test );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement