ºìÁªLinuxÃÅ»§
Linux°ïÖú

C++¶ÔÏó²¼¾Ö¼°¶à̬ʵÏÖÖ®¶¯Ì¬ºÍÇ¿ÖÆת»»

·¢²¼Ê±¼ä:2006-05-03 11:16:54À´Ô´:ºìÁª×÷Õß:°®µÄ±ßÔµ
´ÓÕⲿ·Ö¿ªÊ¼ÎÒÃdzýÁËÀûÓÃÄÚ´æµÄÐÅÏ¢´òÓ¡À´½øÐÐ̽Ë÷Í⣬¸ü¶àµÄ»áͨ¹ý¸ú×ٺ͹۲ì±àÒëÆ÷²úÉúµÄ»ã±à´úÂëÀ´Àí½â±àÒëÆ÷¶ÔÕâЩÓïÑÔÌØÐÔµÄʵÏÖ·½Ê½¡£»ã±à·½Ãæ֪ʶµÄÌÖÂÛ³¬³öÁ˱¾Îĵķ¶Î§£¬ÎÒÖ»¶ÔºÍÎÒÃÇÌÖÂÛÏà¹ØµÄ»ã±à´úÂë½øÐнâÎö¡£Àí½â±¾ÎÄÒªÌÖÂÛµÄ֪ʶ²¢²»ÐèÒªÓкÜÍêÕûµÄ»ã±à֪ʶ£¬µ«±ØÐëÁ˽âÆðÂëµÄ¸ÅÄî¡£

ÏÂÃæÎÒÃÇ¿´¿´ÒýÈëÐé¼Ì³ÐºóµÄÓ°Ï졣ΪÁËÓÐËù¶Ô±ÈÎÒÃÇÊ×ÏÈ¿´¿´ÆÕͨ³ÉÔ±º¯ÊýµÄµ÷ÓÃÇé¿ö¡£

Ö´ÐÐÈçÏ´úÂ룬Ëü°üÀ¨Á˶ÔÏóµÄÆÕͨ³ÉÔ±º¯Êýµ÷Óã¬ÀàµÄ¾²Ì¬³ÉÔ±º¯Êýµ÷Óá¢Í¨¹ýÖ¸Õëµ÷ÓÃÆÕͨ³ÉÔ±º¯Êý£º

C010 obj;
PRINT_OBJ_ADR(obj)
obj.foo();
C012::sfoo();
C010 * pt = &obj;
pt-> foo();

½á¹ûÈçÏ£º

obj's address is : 0012F843

ÕâÊÇobj¶ÔÏóµÄÄÚ´æµØÖ·¡£

Ê×ÏÈÎÒÃÇ¿´¿´¶ÔÏóµÄÆÕͨ³ÉÔ±º¯Êýµ÷Óã¬obj.foo();£¬¶ÔÓ¦µÄ»ã±à´úÂëΪ£º

00422E09 lea ecx,[ebp+FFFFF967h]
00422E0F call 0041E289

µÚ1ÐаѶÔÏóµÄµØÖ·´æÈëecx¼Ä´æÆ÷£¬Ö´ÐÐÍêÕâÐÐÖ¸Áîºó£¬ÎÒÃÇÒªÒÔ¿´µ½ecxÖеÄֵΪ0x0012F843£¬¾ÍÊÇÇ°Ãæ´òÓ¡³öµÄÖµ¡£Èç¹ûº¯ÊýÐèÒª´«µÝ²ÎÊý£¬ÎÒÃÇ»¹»áÔÚÇ°Ãæ¿´µ½Ò»Ð©pushÖ¸Áî¡£ÔÚµÚ2ÐÐÎÒÃÇ¿ÉÒÔ¿´µ½callµÄÊÇÒ»¸öÖ±½ÓµÄµØÖ·£¬ÕâÒ²¾ÍÊǾ²Ì¬°ó¶¨¡£¼´º¯ÊýµÄµ÷ÓõØÖ·ÔÚ±àÒëʱÒѾ­±»±àÒëÆ÷¾öÒé¡£

¸ú×Ù½øÈ¥ÎÒÃÇÒªÒÔ¿´µ½ÊÇÒ»ÌõÌøתָÁ¼ÌÐøÖ´ÐпÉÒÔ¿´µ½ÕæÕýµÄº¯Êý´úÂ벿·Ö£¬ÈçÏÂ(×¢£ºÎªÁËÌÖÂÛ·½±ãÎÒÔÚµÚÐÐÇ°Ãæ¼ÓÁËÒ»¸öÐкÅ)£º

01 00425FE0 push ebp
02 00425FE1 mov ebp,esp
03 00425FE3 sub esp,0CCh
04 00425FE9 push ebx
05 00425FEA push esi
06 00425FEB push edi
07 00425FEC push ecx
08 00425FED lea edi,[ebp+FFFFFF34h]
09 00425FF3 mov ecx,33h
10 00425FF8 mov eax,0CCCCCCCCh
11 00425FFD rep stos dword ptr [edi]
12 00425FFF pop ecx
13 00426000 mov dword ptr [ebp-8],ecx
14 00426003 mov eax,dword ptr [ebp-8]
15 00426006 mov byte ptr [eax],2
16 00426009 pop edi
17 0042600A pop esi
18 0042600B pop ebx
19 0042600C mov esp,ebp
20 0042600E pop ebp
21 0042600F ret

ÎÒÃÇ¿´¿´µÚ7ÐУ¬°Ñecx¼Ä´æÆ÷ÈëÕ»£¬ºóÃæ4Ðгõʼ»¯Á˺¯ÊýµÄ¶ÑÕ»Öеı£´æ¾Ö²¿±äÁ¿µÄ²¿·Ö¡£µÚ12Ðе¯³öecxÖµ£¬µ½ÕâÀïʱecxµÄÖµ±£³ÖΪÔÚº¯Êýµ÷ÓÃÇ°´æÈëµÄ¶ÔÏóÄÚ´æµØÖ·£¬µÚ13ÐоÍÊDZ£´æthisÖ¸ÕëµÄÖµ£¬×÷Ϊһ¸ö¾Ö²¿±äÁ¿¡£ÕâÑùÎÒÃǾÍÖªµÀÁËVC7.1²»ÊÇÏó´«µÝÆÕͨº¯ÊýÄÇÑùͨ¹ýѹջÀ´´«µÝthis Ö¸Õ룬¶øÊÇͨ¹ýecx¼Ä´æÆ÷À´´«µÝ¡£µÚ14¡¢15ÐÐÀûÓÃÕâ¸öthisÖ¸Õë¸ø¶ÔÏóµÄ³ÉÔ±±äÁ¿½øÐÐÁ˸³Öµ¡£

ÔÙ¿´¿´¾²Ì¬³ÉÔ±º¯Êýµ÷ÓõĻã±à´úÂ룺

00422E14 call 0041DD84

·Ç³£Ö±½Ó£¬ÒòΪËü²»ÐèÒª´¦ÀíthisÖ¸Õ룬¸ú×Ùµ½º¯ÊýµÄ»ã±à´úÂ룬¿ÉÒÔ¿´µ½Í¬Ñù²»ÐèÒª´¦ÀíthisÖ¸Õë¡£¾ßÌåµÄ´úÂëÕâÀï¾Í²»ÁгöÀ´ÁË¡£

ÔÙ¿´¿´Í¨¹ýÖ¸Õëµ÷ÓÃÆÕͨ³ÉÔ±º¯Êýpt-> foo();£¬²úÉúµÄ»ã±à´úÂëÈçÏ£º

00422E25 mov ecx,dword ptr [ebp+FFFFF958h]
00422E2B call 0041E289

ºÍͨ¹ý¶ÔÏóµ÷ÓÃÆÕͨ³ÉÔ±º¯ÊýµÄ´úÂë²î²»¶à¡£²»¹ý´æ¶ÔÏóµØÖ·µ½ecx¼Ä´æÆ÷µØ£¬ÊÇͨ¹ý½âÒýÓÃptÖ¸ÕëÀ´ÕÒµ½¶ÔÏóµØÖ·µÄ¡£
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 0 ÌõÆÀÂÛ