通过调试发现,默认情况下写的C代码通过编译会自动变成汇编代码,但是如果写入下面裸函数代码则C代码不会变成汇编语言
// dstest1.cpp : Defines the entry point for the console application. // #include "stdafx.h" // 空函数 void Function() { } // 编写一个函数能够对任意2个整数实现加法,并分析函数的反汇编 int plus1(int x,int y) { return x+y; } // 编写一个函数,能够对任意3个整数实现加法,并分析函数的反汇编 int plus2(int x,int y,int z) { int t; int r; t = plus1(x,y); r = plus1(t,z); return r; } //编写一个函数,能够实现对任意5个整数实现加法,使用plus1和plus2 int plus3(int a,int b,int c,int d,int e){ int i; int j; int k; i = plus1(a,b); j = plus2(c,d,e); k = i+j; return k; } //程序入口 int main(int argc, char* argv[]) { //printf("Hello World!\n"); //plus2(3,4,5); //plus3(4,5,6,7,8); return 0; } 裸函数 // sjlx.cpp : Defines the entry point for the console application. // #include "stdafx.h" //无返回值,无参数 void __declspec(naked) Function() { __asm { push ebp mov ebp,esp sub esp,0x40 push ebx push esi push edi lea edi,dword ptr ds:[ebp-0x40] mov eax,0xCCCCCCCC mov ecx,0x10 rep stosd pop edi pop esi pop ebx mov esp,ebp pop ebp ret } } int main(int argc, char* argv[]) { //printf("Hello World!\n"); Function(); return 0; } ================================================================= //有返回值,有参数 int __declspec(naked) Function2(int x,int y) { __asm { push ebp mov ebp,esp sub esp,0x40 push ebx push esi push edi lea edi,dword ptr ds:[ebp-0x40] mov eax,0xCCCCCCCC mov ecx,0x10 rep stosd mov eax,dword ptr ds:[ebp+0x8] add eax,dword ptr ds:[ebp+0xC] pop edi pop esi pop ebx mov esp,ebp pop ebp ret } } int main(int argc, char* argv[]) { //printf("Hello World!\n"); Function2(1,2); return 0; } ======================================================================== //带局部变量的函数框架 int __declspec(naked) Function3(int x,int y) { __asm { push ebp mov ebp,esp sub esp,0x40 push ebx push esi push edi lea edi,dword ptr ds:[ebp-0x40] mov eax,0xCCCCCCCC mov ecx,0x10 rep stosd mov dword ptr ds:[ebp-0x4],3 mov dword ptr ds:[ebp-0x8],2 mov eax,dword ptr ds:[ebp+0x8] add eax,dword ptr ds:[ebp+0xc] pop edi pop esi pop ebx mov esp,ebp pop ebp ret } } int main(int argc, char* argv[]) { //printf("Hello World!\n"); Function3(1,2); return 0; }