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
- <$
- mov eax, :i32(randnum)
- add eax, [esp+4]
- imul eax, [esp+8]
- ret
- $>
- #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