#include <stdio.h>
void myf(void){
printf("I am myf()\n");
}
int main(void){
int a = 100;
int d = 0;
int b = 3;
int res;
asm("divl %4;"
"jmp 1f;"
"1:jmp 1f;"
"1:"
:"=a"(res),"=d"(d):"a"(a),"d"(d),"b"(b));
// printf("%d\n", res);
// printf("%d\n", d);
int (*f())[3]{
int b[3] = {(0xff, ({int a = 0xf0;++a;++a;})), 0xfe, 0xfd};
int (*a)[3] = &b;
printf("########\n");
return a;
}
printf("0x%x\n", f);
register int __res;
asm("movl %1, %0":"=a"(__res):"b"(f));
asm("call 0x28ff1c\n"::);
printf("%x\n", __res);
asm("call *%0"::"a"(f));
asm("call *%0"::"a"(f));
asm("call *%0"::"a"(f));
asm("call *%0"::"a"(f));
asm("call *%0"::"a"(f));
asm("call *%0"::"a"(f));
asm("call *%0"::"a"(f));
asm("call *%0"::"a"(f));
asm("call *%0"::"a"(f));
asm("call *%0"::"a"(f));
asm("call *%0"::"a"(f));
asm("call *%%eax"::"a"(f));
asm("call *%%eax"::"a"(f));
asm("call *%%eax"::"a"(f));
asm("call *%%eax"::"a"(f));
asm("call *%%eax"::"a"(f));
// asm("call _myf\n");
// printf("%d\n", (*(f()))[0]);
// printf("%d\n", (*(f()))[1]);
// printf("%d\n", (*(f()))[2]);
char* mystr = "\n";
//这里没有用压栈指令,而是用数据传送指令来操作参数,是参考了最下面的反汇编代码。
//但我仍然没有看明白。
asm("movl %%eax, (%%esp)\n""call _printf\n"::"a"(mystr));
asm("movl %%eax, (%%esp)\n""call _printf\n"::"a"(mystr));
asm("movl %%eax, (%%esp)\n""call _printf\n"::"a"(mystr));
asm("movl %%eax, (%%esp)\n""call _printf\n"::"a"(mystr));
// asm("pushl %0\n""call _printf"::"b"(mystr));
// asm("pushl %0\n""call _printf"::"b"(mystr));
// asm("pushl %0\n""call _printf"::"b"(mystr));
void (*(*vvv())[2])(){
int c[4] = {({int a = 1;++a;++a;int b = 30;a = a + b;}),
({int a = 0; int b =20; a = (a + b) * 2;}),
({int a = 20; int c = 3; a = a % c * 2 - 1;}),
({char c = 'c'; char d = 'd'; c = (d - c) * 4;})};
int i = 0;
for(; i < 4; i++)
printf("%d\t", c[i]);
typedef void (*z)();
static z y[2];
void xx(){printf("I am xx\n");}
void yy(){printf("I am yy\n");}
y[0] = xx;
y[1] = yy;
y[0]();
y[1]();
return &y;
}
vvv();
}
//only a example.
void fff(char* str){}
void ff(void){
void f(void){}
f();
fff("Hello, World!\n");
}
/*
test504.o: file format pe-i386
Disassembly of section .text:
00000000 <_fff>:
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 90 nop
4: 5d pop %ebp
5: c3 ret
00000006 <_f.1412>:
6: 55 push %ebp
7: 89 e5 mov %esp,%ebp
9: 83 ec 04 sub $0x4,%esp
c: 89 4d fc mov %ecx,-0x4(%ebp)
f: 90 nop
10: c9 leave
11: c3 ret
00000012 <_ff>:
12: 55 push %ebp
13: 89 e5 mov %esp,%ebp
15: 83 ec 14 sub $0x14,%esp
18: 8d 45 08 lea 0x8(%ebp),%eax
1b: 89 45 fc mov %eax,-0x4(%ebp)
1e: 8d 45 fc lea -0x4(%ebp),%eax
21: 89 c1 mov %eax,%ecx
23: e8 de ff ff ff call 6 <_f.1412>
28: c7 04 24 00 00 00 00 movl $0x0,(%esp)
2f: e8 cc ff ff ff call 0 <_fff>
34: 90 nop
35: c9 leave
36: c3 ret
37: 90 nop
*/