c/c++Ö§³Ö¿É±ä²ÎÊýµÄº¯Êý
c/c++Ö§³Ö¿É±ä²ÎÊýµÄº¯Êý£¬¼´º¯ÊýµÄ²ÎÊýÊDz»È·¶¨µÄ¡£
Ò»¡¢ÎªÊ²Ã´ÒªÊ¹Óÿɱä²ÎÊýµÄº¯Êý£¿
Ò»°ãÎÒÃDZà³ÌµÄʱºò£¬º¯ÊýÖÐÐÎʽ²ÎÊýµÄÊýĿͨ³£ÊÇÈ·¶¨µÄ£¬ÔÚµ÷ÓÃʱҪÒÀ´Î¸ø³öÓëÐÎʽ²ÎÊý¶ÔÓ¦µÄËùÓÐʵ¼Ê²ÎÊý¡£µ«ÔÚijЩÇé¿öÏÂÏ£Íûº¯ÊýµÄ²ÎÊý¸öÊý¿ÉÒÔ¸ù¾ÝÐèҪȷ¶¨£¬Òò´ËcÓïÑÔÒýÈë¿É±ä²ÎÊýº¯Êý¡£ÕâÒ²ÊÇc¹¦ÄÜÇ¿´óµÄÒ»¸ö·½Ã棬ÆäËüijЩÓïÑÔ£¬±ÈÈçfortran¾ÍûÓÐÕâ¸ö¹¦ÄÜ¡£
µäÐ͵Ŀɱä²ÎÊýº¯ÊýµÄÀý×ÓÓдó¼ÒÊìϤµÄprintf()¡¢scanf()µÈ¡£
¶þ¡¢c/c++ÈçºÎʵÏֿɱä²ÎÊýµÄº¯Êý£¿
ΪÁËÖ§³Ö¿É±ä²ÎÊýº¯Êý£¬CÓïÑÔÒýÈëеĵ÷ÓÃÐÒ飬 ¼´CÓïÑÔµ÷ÓÃÔ¼¶¨ __cdecl ¡£ ²ÉÓÃC/C++ÓïÑÔ±à³ÌµÄʱºò£¬Ä¬ÈÏʹÓÃÕâ¸öµ÷ÓÃÔ¼¶¨¡£Èç¹ûÒª²ÉÓÃÆäËüµ÷ÓÃÔ¼¶¨£¬±ØÐëÌí¼ÓÆäËü¹Ø¼ü×ÖÉùÃ÷£¬ÀýÈçWIN32 APIʹÓÃPASCALµ÷ÓÃÔ¼¶¨£¬º¯ÊýÃû×Ö֮ǰ±ØÐë¼Ó__stdcall¹Ø¼ü×Ö¡£
²ÉÓÃCµ÷ÓÃÔ¼¶¨Ê±£¬º¯ÊýµÄ²ÎÊýÊÇ´ÓÓÒµ½×óÈëÕ»£¬¸öÊý¿É±ä¡£ÓÉÓÚº¯ÊýÌå²»ÄÜÔ¤ÏÈÖªµÀ´«½øÀ´µÄ²ÎÊý¸öÊý£¬Òò´Ë²ÉÓñ¾Ô¼¶¨Ê±±ØÐëÓɺ¯Êýµ÷ÓÃÕ߸ºÔð¶ÑÕ»ÇåÀí¡£¾Ù¸öÀý×Ó£º
//Cµ÷ÓÃÔ¼¶¨º¯Êý
int __cdecl Add(int a, int b)
{
return (a + b);
}
º¯Êýµ÷Óãº
Add(1, 2);
//»ã±à´úÂëÊÇ£º
push 2 ;²ÎÊýbÈëÕ»
push 1 ;²ÎÊýaÈëÕ»
call @Add ;µ÷Óú¯Êý¡£Æäʵ»¹ÓбàÒëÆ÷ÓÃÓÚ¶¨Î»º¯ÊýµÄ±í´ïʽÕâÀï°ÑËüÊ¡ÂÔÁË
add esp,8 ;µ÷ÓÃÕ߸ºÔðÇåÕ»
Èç¹ûµ÷Óú¯ÊýµÄʱºòʹÓõĵ÷ÓÃÐÒéºÍº¯ÊýÔÐÍÖÐÉùÃ÷µÄ²»Ò»Ö£¬¾Í»áµ¼ÖÂÕ»´íÎó£¬ÕâÊÇÁíÍâÒ»¸ö»°Ì⣬ÕâÀï²»ÔÙϸ˵¡£
ÁíÍâc/c++±àÒëÆ÷²ÉÓúêµÄÐÎʽ֧³Ö¿É±ä²ÎÊýº¯Êý¡£ÕâЩºê°üÀ¨va_start¡¢va_argºÍva_endµÈ¡£Ö®ËùÒÔÕâô×ö£¬ÊÇΪÁËÔö¼Ó³ÌÐòµÄ¿ÉÒÆÖ²ÐÔ¡£ÆÁ±Î²»Í¬µÄÓ²¼þƽ̨Ôì³ÉµÄ²îÒì¡£
Ö§³Ö¿É±ä²ÎÊýº¯ÊýµÄËùÓк궼¶¨ÒåÔÚstdarg.h ºÍ varargs.hÖС£ÀýÈç±ê×¼ANSIÐÎʽÏ£¬ÕâЩºêµÄ¶¨ÒåÊÇ£º
typedef char * va_list; //×Ö·û´®Ö¸Õë
#define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
#define va_start(ap,v) ( ap = (va_list)&v + _INTSIZEOF(v) )
#define va_arg(ap,t) ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
#define va_end(ap) ( ap = (va_list)0 )
ʹÓúê_INTSIZEOFÊÇΪÁË°´ÕÕÕûÊý×Ö½Ú¶ÔÆëÖ¸Õ룬ÒòΪcµ÷ÓÃÐÒéÏÂÃ棬²ÎÊýÈëÕ»¶¼ÊÇÕûÊý×Ö½Ú£¨Ö¸Õë»òÕßÖµ£©¡£
Èý¡¢ÈçºÎ¶¨ÒåÕâÀàµÄº¯Êý¡£
¿É±ä²ÎÊýº¯ÊýÔÚ²»Í¬µÄϵͳÏ£¬²ÉÓò»Í¬µÄÐÎʽ¶¨Òå¡£
1¡¢ÓÃANSI±ê×¼ÐÎʽʱ£¬²ÎÊý¸öÊý¿É±äµÄº¯ÊýµÄÔÐÍÉùÃ÷ÊÇ£º
type funcname(type para1, type para2, …);
Ïà¹ØÎĵµ£º
һƪ½²¶ÔÆë±È½ÏºÃµÄÎÄÕ£¬×ªÌùÈçÏÂ:
´óÖ±ê×¢Ò»¶þ:
1.ÄÚ´æ¶ÔÆë:¼ÆËã»úϵͳ¶Ô»ù±¾ÀàÐÍÊý¾ÝÔÚÄÚ´æÖдæ·ÅµÄλÖÃÓÐÏÞÖÆ£¬ËüÃÇ»áÒªÇóÕâЩÊý¾ÝµÄÊ×µØÖ·µÄÖµÊÇij¸öÊýk(ͨ³£ËüΪ4»ò8)µÄ±¶ÊýkÔò±»³ÆΪ¸ÃÊý¾ÝÀàÐ͵ĶÔÆëÄ£Êý(alignment modulus)
2.²»Í¬±àÒëÆ÷ĬÈϵÄ×î´ó¶ÔÆë×Ö½ÚÊýÊDz»Ò»ÑùµÄ,±ÈÈçvc==8,gcc==4,¿ÉÒÔͨ¹ ......
BoundsChecker²ÉÓÃÒ»ÖÖ±»³ÆΪ Code InjectionµÄ¼¼Êõ£¬À´½Ø»ñ¶Ô·ÖÅäÄÚ´æºÍÊÍ·ÅÄÚ´æµÄº¯ÊýµÄµ÷Ó᣼òµ¥µØ˵£¬µ±ÄãµÄ³ÌÐò¿ªÊ¼ÔËÐÐʱ£¬BoundsCheckerµÄDLL±»×Ô¶¯ÔØÈë½ø³ÌµÄµØÖ·¿Õ¼ä£¨Õâ¿ÉÒÔͨ¹ýsystem-levelµÄHookʵÏÖ£©£¬È»ºóËü»áÐ޸Ľø³ÌÖжÔÄÚ´æ·ÖÅäºÍÊͷŵĺ¯Êýµ÷Óã¬ÈÃÕâЩµ÷ÓÃÊ×ÏÈתÈëËüµÄ´úÂ룬ȻºóÔÙÖ´ÐÐÔÀ´µÄ´úÂë¡£Bo ......
freadº¯ÊýºÍfwriteº¯Êý
1.º¯Êý¹¦ÄÜ
ÓÃÀ´¶Áдһ¸öÊý¾Ý¿é¡£
2.Ò»°ãµ÷ÓÃÐÎʽ
fread(buffer,size,count,fp);
fwrite(buffer,size,count,fp);
3.˵Ã÷
£¨1£©buffer£ºÊÇÒ»¸öÖ¸Õ룬¶ÔfreadÀ´Ëµ£¬ËüÊǶÁÈëÊý¾ÝµÄ´æ·ÅµØÖ·¡£¶ÔfwriteÀ´Ëµ£¬ÊÇÒªÊä³öÊý¾ÝµÄµØÖ·¡£
£¨2£©size£ºÒª¶ÁдµÄ×Ö½ÚÊý ......
[C/C++ Digestion] –
×Ôµ×ÏòÉϵØ̽¾¿Ð麯Êý
×÷Õߣº
Jason Lee @
http://blog.csdn.net/jasonblog
ÈÕÆÚ£º
2010-05-19
»·¾³£º
Visual C++ Express
2008
ÉùÃ÷£º±¾ÎÄ·¢±íÔÚ
csdn
²©¿Í£¬ÈçÓÐתÔØ£¬Çë×¢Ã÷³ö´¦
[1]C++
¶ÔÏóÄ£ÐÍ»ù´¡
Ò»¸öÀàÖпÉÒÔ°üº¬¾²Ì¬Êý¾Ý³ÉÔ±¡¢¾²Ì¬³ÉÔ±º¯Êý¡¢·Ç¾²Ì¬³ÉÔ±º¯Êýº ......