-
Notifications
You must be signed in to change notification settings - Fork 3
/
funcjmp_simple_x86.c
43 lines (38 loc) · 940 Bytes
/
funcjmp_simple_x86.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
#include <stdio.h>
#include <stdlib.h>
#ifndef __i386
#error "Unsupported Architecture"
#endif
#define INTEL_ASM(_asm_str) asm volatile(".intel_syntax noprefix"); \
asm volatile(_asm_str); \
asm volatile(".att_syntax prefix");
#define JUMPABLE_FUNC(fname) int fname(void)
#define JMP_FUNC_DECL(func) void *fptr = (void *)( &func );
#define JMP_TO_FUNC \
INTEL_ASM(" \
call getip; \
jmp short donext; \
cfunc: \
mov eax,[fptr]; \
add eax,0x0; \
jmp eax; \
ret; \
getip: \
nop; \
jmp short cfunc; \
donext: \
");
JUMPABLE_FUNC(testfkt);
JMP_FUNC_DECL(testfkt);
JUMPABLE_FUNC(testfkt)
{
int var0 = 0x1, var1 = 0x2, var2 = 0x3;
var0 += var1 + var2;
printf("Subroutine: %d = %d + %d\n", var0, var1, var2);
return 0;
}
int main(int argc, char **argv)
{
JMP_TO_FUNC;
return 0;
}