Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <malloc.h>
- int a = 0;
- void test() {
- a=0xabcd;
- }
- int main() {
- unsigned char Template[100];
- int Index = 0;
- // make a copy of the test() function in Template and find where the constant is
- int i, Length;
- unsigned char *OldTemplate = (char*)test;
- for(i=0;i<50;i++) {
- Template[i] = OldTemplate[i];
- if((OldTemplate[i] == 0xcd) && (OldTemplate[i+1] == 0xab))
- Index = i;
- if(OldTemplate[i] == 0xc3) // x86 RET opcode
- break;
- }
- Length = i+1;
- // display the function
- for(i=0;i<Length;i++) {
- if(i == Index || i == Index + 1)
- printf("xx ");
- else
- printf("%.2x ", Template[i]&255);
- }
- putchar('\n');
- // create 20 functions that set a global variable 0 to 19
- char *Created[20];
- for(i=0;i<20;i++) {
- Created[i] = (void*)malloc(Length);
- memcpy(Created[i], Template, Length);
- Created[i][Index+0] = i;
- Created[i][Index+1] = 0;
- }
- // call all the functions we just made
- for(i=0;i<20;i++) {
- void (*foo)(void) = (void*)Created[i];
- foo();
- printf("%i ", a);
- }
- putchar('\n');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement