-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.c
47 lines (36 loc) · 1.02 KB
/
test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#define SZ 0x10000
#define BUF_SIZE 2*SZ
int data[1000000]; //make a big data section
void start_rop(char *);
int main (int argc, char *argv[]) {
FILE * pFile;
long lSize;
char * buffer;
size_t result;
if(argc<2){
printf("Usage: %s <rop shellcode.bin>\n", argv[0]);
return 1;
}
pFile = fopen (argv[1], "rb" );
if (pFile==NULL) {fputs ("File error",stderr); exit (1);}
fseek (pFile , 0 , SEEK_END);
lSize = ftell (pFile);
rewind (pFile);
assert(lSize < BUF_SIZE/2);
buffer = (char*) malloc (BUF_SIZE);
if (buffer == NULL) {fputs ("Memory error",stderr); exit (2);}
printf("buf=0x%08x\n", (unsigned int)buffer);
buffer = (char*)((((unsigned int)buffer+SZ-1)/SZ)*SZ);
printf("roundup buf=0x%08x\n", (unsigned int)buffer);
result = fread (buffer,1,lSize,pFile);
if (result != lSize) {fputs ("Reading error",stderr); exit (3);}
//pass the shellcode
start_rop(buffer);
// terminate
fclose (pFile);
free (buffer);
return 0;
}