windows»·¾³ÏÂ32λ»ã±àÓïÑÔ³ÌÐòÉè¼Æ-µÚ6½Ú
°´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·ҳ£¬°´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ£¬°´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿£¡
¡ª¡ª¡ª¡ªÎ´ÔĶÁÍꣿ¼ÓÈëÊéÇ©ÒѱãÏ´μÌÐøÔĶÁ£¡
mov¡¡¡¡¡¡¡¡¡¡eax£»£§esi¡¡£«¡¡WNDCLASS¡£lpfnWndProc£§
×¢Ò⣺µÚ¶þ¾äÊÇ£§esi¡¡£«¡¡WNDCLASS¡£lpfnWndProc£§¶ø²»ÊÇ£§esi¡¡£«¡¡stWndClass¡£lpfnWndProc£§£¬ÒòΪǰÕ߻ᱻ±àÒë³Émov¡¡eax£»£§esi£«4£§£¬¶øºóÕ߻ᱻ±àÒë³Émov¡¡eax£»£§esi£«403004h£§£¬ºóÕߵĽá¹ûÏÔÈ»ÊÇ´íÎóµÄ£¡Èç¹ûÒª¶ÔÒ»¸öÊý¾Ý½á¹¹ÖеĴóÁ¿×ֶνøÐвÙ×÷£¬ÕâÖÖд·¨ÏÔÈ»±È½Ï·³Ëö£¬MASM»¹ÓÐÒ»¸öÓ÷¨£¬¿ÉÒÔÓÃassumeαָÁî°Ñ¼Ä´æÆ÷Ô¤Ïȶ¨ÒåΪ½á¹¹Ö¸Õ룬ÔÙ½øÐвÙ×÷£º
mov¡¡¡¡¡¡¡¡¡¡esi£»offset¡¡stWndClass
assume¡¡¡¡esi£ºptr¡¡WNDCLASS
mov¡¡¡¡¡¡¡¡¡¡eax£»£§esi£§¡£lpfnWndProc
¡
assume¡¡¡¡esi£ºnothing
ÕâÑù£¬Ê¹ÓüĴæÆ÷Ò²¿ÉÒÔÓöºµãÒýÓÃ×Ö¶ÎÃû£¬³ÌÐòµÄ¿É¶ÁÐԱȽϺá£ÕâÑùµÄд·¨ÔÚ×îºó±àÒë³É¿ÉÖ´ÐгÌÐòµÄʱºò²úÉúͬÑùµÄ´úÂë¡£×¢Ò⣺ÔÚ²»ÔÙʹÓÃesi¼Ä´æÆ÷×öÖ¸ÕëµÄʱºòÒªÓÃassume¡¡esi£ºnothingÈ¡Ïû¶¨Òå¡£
½á¹¹µÄ¶¨ÒåÒ²¿ÉÒÔǶÌ×£¬Èç¹ûÒª¶¨ÒåÒ»¸öеÄNEW_WNDCLASS½á¹¹£¬ÀïÃæ°üº¬Ò»¸öÀϵÄWNDCLASS½á¹¹ºÍÒ»¸öеÄdwOption×ֶΣ¬ÄÇô¿ÉÒÔÈç϶¨Ò壺
NEW_WNDCLASS¡¡¡¡¡¡¡¡¡¡struct
¡¡
DwOption¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡dword¡¡¡¡¡¡¡¡¡¡£¿
OldWndClass¡¡¡¡¡¡¡¡¡¡¡¡WNDCLASS¡¡¡¡
¡¡
NEW_WNDCLASS¡¡¡¡¡¡¡¡¡¡ends
¼ÙÉèÏÖÔÚesiÊÇÖ¸ÏòÒ»¸öNEW_WNDCLASSµÄÖ¸Õ룬ÄÇôÒýÓÃÀïÃæǶÌ×µÄoldWndClassÖеÄlpfnWndProc×Ö¶Îʱ£¬¾Í¿ÉÒÔÓÃÏÂÃæµÄÓï¾ä£º
mov¡¡¡¡¡¡¡¡¡¡eax£»£§esi£§¡£oldWndClass¡£lpfnWndProc
½á¹¹µÄǶÌ×ÔÚWindowsµÄÊý¾Ý¶¨ÒåÖÐÒ²³£ÓУ¬±ÈÈçÔÚµÚ13ÕÂ13¡£3½ÚÖÐʹÓõÄDEBUG_EVENT½á¹¹Öо¹È»Ê¹ÓÃÁË4²ãÊý¾Ý½á¹¹µÄǶÌס£¡¡ÊìÁ·ÕÆÎÕÊý¾Ý½á¹¹µÄʹÓöÔWin32»ã±à±à³ÌÊǺÜÖØÒªµÄ£¡
¡¡
À´Ô´£ºµç×Ó¹¤Òµ³ö°æÉç¡¡×÷ÕߣºÂÞÔƱò¡¡ÉÏÒ»Ò³¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡»ØÊéÄ¿¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ÏÂÒ»Ò³¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
ÉÏÒ»Ò³¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡»ØÊéÄ¿¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ÏÂÒ»Ò³¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
¡¡¡¡
µÚ3Õ¡¡Ê¹ÓÃMASM
3¡£3¡¡±êºÅ¡¢±äÁ¿ºÍÊý¾Ý½á¹¹£¨4£©
¡¡¡¡¡¡¡¡
3¡£3¡£5¡¡¡¡±äÁ¿µÄʹÓÃ
1¡£¡¡ÒÔ²»Í¬µÄÀàÐÍ·ÃÎʱäÁ¿
Õâ¸ö»°ÌâÓеãÏñCÓïÑÔÖеÄÊý¾ÝÀàÐÍÇ¿ÖÆת»»£¬CÓïÑÔÖеÄÀàÐÍת»»Ö¸µÄÊÇ°ÑÒ»¸ö±äÁ¿µÄÄÚÈÝת»»³ÉÁíÍâÒ»ÖÖÀàÐÍ£¬×ª»»¹ý³ÌÖУ¬Êý¾ÝµÄÄÚÈÝÒѾ·¢ÉúÁ˱仯£¬Èç°Ñ¸¡µãÊýת»»³ÉÕûÊýºó£¬Ð¡ÊýµãºóµÄÄÚÈݾͶªÊ§ÁË¡£ÔÚMASMÖÐÒÔ²»Í¬µÄÀàÐÍ·ÃÎʲ»»á¶Ô±äÁ¿Ôì³ÉÓ°Ïì¡£
¾ÙÒ»¸ö¼òµ¥µÄÀý×Ó£¬ÏÈÒÔdb·½Ê½¶¨ÒåÒ»¸ö»º³åÇø£º
szBuffer¡¡¡¡¡¡¡¡db¡¡¡¡¡¡¡¡¡¡¡¡1024¡¡dup¡¡£¨£¿£©
È»ºó´ÓÆäËûµØ·½È¡µÃÁËÊý¾Ý£¬µ«Êý¾ÝµÄ¸ñʽÊÇÒÔ×Ö·½Ê½×éÖ¯µÄ£¬Òª´¦ÀíÊý¾Ý£¬×îÓÐЧµÄ·½·¨ÊÇÁ½¸ö×Ö½ÚÁ½¸ö×ֽڵش¦Àí£¬µ«Èç¹ûÔÚ³ÌÐòÖаÑszBufferµÄÖµ·ÅÈëax£º
mov¡¡¡¡¡¡¡¡¡¡ax£»szBuffer
±àÒëÆ÷»á±¨Ò»¸ö´í£º
error¡¡A2070£º¡¡invalid¡¡instruction¡¡operands
Òâ˼ÊÇÎÞЧµÄÖ¸Áî²Ù×÷£¬ÎªÊ²Ã´ÄØ£¿ÒòΪszBufferÊÇÓÃdb¶¨ÒåµÄ£¬¶øaxµÄ³ß´çÊÇÒ»¸öword£¬µÈÓÚÁ½¸ö×Ö½Ú£¬³ß´ç²»·ûºÏ¡£MASMÖУ¬Èç¹ûÒªÓÃÖ¸¶¨ÀàÐÍÖ®ÍâµÄ³¤¶È·ÃÎʱäÁ¿£¬±ØÐëÏÔʽµØÖ¸³öÒª·ÃÎʵij¤¶È£¬ÕâÑù£¬±àÒëÆ÷ºöÂÔÓï·¨Éϵij¤¶È¼ìÑ飬½öʹÓñäÁ¿µÄµØÖ·¡£Ê¹Óõķ½·¨ÊÇ£º
ÀàÐÍ¡¡ptr¡¡±äÁ¿Ãû
ÀàÐÍ¿ÉÒÔÊÇbyte£¬word£¬dword£¬fword£¬qword£¬real8ºÍreal10¡£È磺
mov¡¡¡¡¡¡¡¡¡¡ax£»word¡¡ptr¡¡szBuffer
mov¡¡¡¡¡¡¡¡¡¡eax£»dword¡¡ptr¡¡szBuffer
ÉÏÊöÓï¾äÄÜͨ¹ý±àÒ룬µ±È»£¬ÀàÐͱØÐëºÍ²Ù×÷µÄ¼Ä´æÆ÷³¤¶ÈÆ¥Åä¡£ÔÚÕâÀïҪעÒâµÄÊÇ£¬Ö¸¶¨ÀàÐ͵IJÎÊý·ÃÎʲ¢²»»áÈ¥¼ì²â³¤¶ÈÊÇ·ñÒç³ö£¬¿´ÏÂÃæÒ»¶Î´úÂ룺
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£data
bTest1¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡db¡¡¡¡¡¡¡¡¡¡¡¡12h
wTest2¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡dw¡¡¡¡¡¡¡¡¡¡¡¡1234h
dwTest3¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡dd¡¡¡¡¡¡¡¡¡¡¡¡12345678h
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡de
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡mov¡¡¡¡¡¡¡¡¡¡al£»bTest1
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡mov¡¡¡¡¡¡¡¡¡¡ax£»word¡¡ptr¡¡bTest1
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡mov¡¡¡¡¡¡¡¡¡¡eax£»dword¡¡ptr¡¡bTest1
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
ÉÏÃæµÄ³ÌÐòƬ¶Ï£¬Ã¿Ò»¾äÖ´Ðкó¼Ä´æÆ÷ÖеÄÖµÊÇʲôÄØ£¬mov¡¡al£»bTest1ÕâÒ»¾äºÜÏÔȻʹalµÈÓÚ12h£¬ÏÂÃæµÄÁ½¾äÄØ£¬axºÍeaxÄѵÀµÈÓÚ0012hºÍ00000012hÂð£¿Êµ¼ÊÔËÐнá¹ûºÜ¡°Ææ¹Ö¡±£¬¾¹È»ÊÇ3412hºÍ78123412h£¬ÎªÊ²Ã´ÄØ£¿ÏÈÀ´¿´·´»ã±àµÄÄÚÈÝ£º
£»¡£data¶ÎÖеıäÁ¿
£º00403000¡¡12¡¡34¡¡12¡¡78¡¡56¡¡34¡¡12¡¡¡£¡£¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡©¦¡¡¡¡¡¡©¦¡¡¡¡¡¡¡¡¡¡©¦
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡©¦¡¡¡¡¡¡©¦¡¡¡¡¡¡¡¡¡¡©¸©¤¡ú¡¡dwTest3
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡©¦¡¡¡¡¡¡©¸©¤©¤©¤©¤©¤©¤¡ú¡¡wTest2
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡©¸©¤©¤©¤©¤©¤©¤©¤©¤©¤¡ú¡¡¡¡¡¡¡¡bTest1
¡¡
£»de¶ÎÖеĴúÂë
£º00401000¡¡A000304000¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡mov¡¡al£»¡¡byte¡¡ptr¡¡£§00403000£§
£º00401005¡¡66A100304000¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡mov¡¡ax£»¡¡word¡¡ptr¡¡£§00403000£§
£º0040100B¡¡A100304000¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡mov¡¡eax£»¡¡dword¡¡ptr¡¡£§00403000£§
¡£data¶ÎÖеıäÁ¿ÊÇ°´Ë³Ðò´ÓµÍµØÖ·Íù¸ßµØÖ·ÅÅÁеģ¬¶ÔÓÚ³¬¹ýÒ»¸ö×Ö½ÚµÄÊý¾Ý£¬80386´¦ÀíÆ÷µÄÊý¾ÝÅÅÁз½Ê½ÊǵÍλÊý¾ÝÔڵ͵ØÖ·£¬ËùÒÔwTest2µÄ1234hÔÚÄÚ´æÖеÄÅÅÁÐÊÇ34h¡¡12h£¬ÒòΪ34hÊǵÍλ¡£Í¬Ñù£¬dwTest3ÔÚÄÚ´æÖÐÒÔ78h¡¡56h¡¡34h¡¡12h´ÓµÍµØÖ·Íù¸ßµØÖ·´æ·Å£¬ÔÚÖ´ÐÐÖ¸Áîmov¡¡ax£»word¡¡ptr¡¡bTest1µÄʱºò£¬ÊÇ´ÓbTest1µÄµØÖ·403000h´¦È¡Ò»¸ö×Ö£¬Æ䳤¶ÈÒѾ³¬¹ýÁËbTest1µÄ·¶Î§²¢Âäµ½ÁËwTest2ÖУ¬´ÓÄÚ´æÖп´£¬ÊÇÈ¡ÁËbTest1µÄÊý¾Ý12hºÍwTest2µÄµÍλ34h£¬ÔÚÕâÁ½¸ö×Ö½ÚÖУ¬12hλÓڵ͵ØÖ·£¬ËùÒÔaxÖеÄÊýÖµÊÇ3412h¡£Í¬ÑùµÀÀí£¬¿´ÁíÒ»ÌõÖ¸Á
mov¡¡¡¡¡¡¡¡¡¡eax£»dword¡¡ptr¡¡bTest1
ÕâÌõÖ¸ÁîÈ¡ÁËbTest1£¬wTest2µÄÈ«²¿ºÍdwTest3µÄ×îµÍλ78h£¬ÔÚÄÚ´æÖеÄÅÅÁÐÊÇ12h¡¡¡¡34h¡¡12h¡¡78h£¬ËùÒÔeaxµÈÓÚ78123412h¡£
Õâ¸öÀý×Ó˵Ã÷ÁË»ã±àÖÐÓÃptrÇ¿ÖƸ²¸Ç±äÁ¿³¤¶ÈµÄʱºò£¬ÊµÖÊÉÏÊÇÖ»ÓÃÁ˱äÁ¿µÄµØÖ·¶ø½ûÖ¹±àÒëÆ÷½øÐмìÑ飬±àÒëÆ÷²¢²»»á¿¼ÂǶ¨½çµÄÎÊÌ⣬³ÌÐòÔ±ÔÚʹÓõÄʱºò±ØÐë¶ÔÄÚ´æÖеÄÊý¾ÝÅÅÁÐÓиöÈ«¾Ö¸ÅÄÒÔÃâÔ½½ç´æÈ¡µ½ÒâÁÏÖ®ÍâµÄÊý¾Ý¡£
Èç¹û³ÌÐòÔ±µÄ±¾ÒâÊÇÀàËÆÓÚCÓïÑÔµÄÇ¿ÖÆÀàÐÍת»»£¬Ïë°ÑbTest1µÄÒ»¸ö×Ö½ÚÀ©Õ¹µ½Ò»¸ö×Ö»òÒ»¸öË«×ÖÔٷŵ½ax»òeaxÖУ¬¸ßλ±£³Ö0¶ø²»ÊÇÔ½½ç´æÈ¡µ½ÆäËûµÄ±äÁ¿£¬¿ÉÒÔÓÃ80386µÄÀ©Õ¹Ö¸ÁîÀ´ÊµÏÖ¡£80386´¦ÀíÆ÷ÌṩµÄmovzxÖ¸Áî¿ÉÒÔʵÏÖÕâ¸ö¹¦ÄÜ£¬ÀýÈ磺
movzx¡¡¡¡¡¡¡¡¡¡¡¡¡¡ax£»bTest1¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£»Àý1
movzx¡¡¡¡¡¡¡¡¡¡¡¡¡¡eax£»bTest1¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£»Àý2
movzx¡¡¡¡¡¡¡¡¡¡¡¡¡¡eax£»cl¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£»Àý3
movzx¡¡¡¡¡¡¡¡¡¡¡¡¡¡eax£»ax¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£»Àý4
¡ñ¡¡¡¡¡¡Àý1°Ñµ¥×Ö½Ú±äÁ¿bTest1µÄÖµÀ©Õ¹µ½16λ·ÅÈëaxÖС£
¡ñ¡¡¡¡¡¡Àý2°Ñµ¥×Ö½Ú±äÁ¿bTest1µÄÖµÀ©Õ¹µ½32λ·ÅÈëeaxÖС£
¡ñ¡¡¡¡¡¡Àý3°ÑclÖеÄ8λֵÀ©Õ¹µ½32λ·ÅÈëeaxÖС£
¡ñ¡¡¡¡¡¡Àý4°ÑaxÖеÄ16λֵÀ©Õ¹µ½32λ·ÅÈëeaxÖС£
ÓÃmovzxÖ¸Áî½øÐÐÊý¾Ý³¤¶ÈÀ©Õ¹ÊÇWin32»ã±àÖо³£Óõ½µÄ¼¼ÇÉ¡£
2¡£¡¡±äÁ¿µÄ³ß´çºÍÊýÁ¿
ÔÚÔ´³ÌÐòÖÐÓõ½±äÁ¿µÄ³ß´çºÍÊýÁ¿µÄʱºò£¬¿ÉÒÔÓÃsizeofºÍlengthofαָÁîÀ´ÊµÏÖ£¬¸ñʽÊÇ£º
sizeof¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡±äÁ¿Ãû¡¢Êý¾ÝÀàÐÍ»òÊý¾Ý½á¹¹Ãû
lengthof¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡±äÁ¿Ãû¡¢Êý¾ÝÀàÐÍ»òÊý¾Ý½á¹¹Ãû
sizeofαָÁî¿ÉÒÔÈ¡µÃ±äÁ¿¡¢Êý¾ÝÀàÐÍ»òÊý¾Ý½á¹¹ÒÔ×Ö½ÚΪµ¥Î»µÄ³¤¶È£¬lengthof¿ÉÒÔÈ¡µÃ±äÁ¿ÖÐÊý¾ÝµÄÏîÊý¡£¼ÙÈ綨ÒåÁËÒÔÏÂÊý¾Ý£º
stWndClass¡¡¡¡¡¡¡¡¡¡WNDCLASS¡¡¡¡¡¡¡¡¡¡
szHello¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡db¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡'Hello£»world£¡'£»0
dwTest¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡dd¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡1£»2£»3£»4
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡de
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡mov¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡eax£»sizeof¡¡stWndClass
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡mov¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ebx£»sizeof¡¡WNDCLASS
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡mov¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ecx£»sizeof¡¡szHello
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡mov¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡edx£»sizeof¡¡dword
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡mov¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡esi£»sizeof¡¡dwTest
Ö´ÐкóeaxµÄÖµÊÇstWndClass½á¹¹µÄ³¤¶È40£¬ebxͬÑùÊÇ40£¬ecxµÄÖµÊÇ13£¬¾ÍÊÇ¡°Hello£»world£¡¡±×Ö·û´®µÄ³¤¶È¼ÓÉÏÒ»¸ö×Ö½ÚµÄ0½áÊø·û£¬edxµÄÖµÊÇÒ»¸öË«×ֵij¤¶È£º4£¬¶øesiÔòµÈÓÚ4¸öË«×ֵij¤¶È16¡£
Èç¹û°ÑËùÓеÄsizeof»»³Élengthof£¬ÄÇôeax»áµÈÓÚ1£¬ÒòΪֻ¶¨ÒåÁË1ÏîWNDCLASS£¬¶øecxͬÑùµÈÓÚ13£¬esiÔòµÈÓÚ4£¬¶ølengthof¡¡WNDCLASSºÍlengthof¡¡dwordÊÇ·Ç·¨µÄÓ÷¨£¬±àÒë³ÌÐò»á±¨´í¡£
ҪעÒâµÄÊÇ£¬sizeofºÍlengthofµÄÊýÖµÊDZàÒëʱºò²úÉúµÄ£¬ÓɱàÒëÆ÷´«µÝµ½Ö¸ÁîÖÐÈ¥£¬ÉϱߵÄÖ¸Áî×îºó²úÉúµÄ´úÂë¾ÍÊÇ£º
mov¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡eax£»40
mov¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ebx£»40
mov¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ecx£»13
mov¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡edx£»4
mov¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡esi£»16
¡¡Èç¹ûΪÁË°ÑHelloºÍWorld·ÖÁ½Ðж¨Ò壬szHelloÊÇÕâÑù¶¨ÒåµÄ£º
szHello¡¡¡¡¡¡¡¡¡¡¡¡¡¡db¡¡¡¡¡¡¡¡¡¡¡¡'Hello'£»0dh£»0ah
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡db¡¡¡¡¡¡¡¡¡¡¡¡'World'£»0
ÄÇôsizeof¡¡szHelloÊǶàÉÙÄØ£¿×¢Ò⣡ÊÇ7¶ø²»ÊÇ13£¬MASMÖеıäÁ¿¶¨ÒåÖ»ÈÏÒ»ÐУ¬ºóÒ»ÐÐdb¡¡'World'£»0ʵ¼ÊÉÏÊÇÁíÒ»¸öûÓÐÃû³ÆµÄÊý¾Ý¶¨Ò壬±àÒëÆ÷ÈÏΪsizeof¡¡szHelloÊǵÚÒ»ÐÐ×Ö·ûµÄÊýÁ¿¡£ËäÈ»°ÑszHelloµÄµØÖ·µ±²ÎÊý´«¸øMessageBoxµÈº¯ÊýÏÔʾʱ»á°ÑÁ½Ðж¼ÏÔʾ³öÀ´£¬µ«ÑϸñµØ˵ÕâÊÇÔ½½çʹÓñäÁ¿¡£ËäÈ»ÔÚʵ¼ÊµÄÓ¦ÓÃÖÐÕâÑù¶¨Ò峤×Ö·û´®µÄÓ÷¨ºÜÆձ飬ÒòΪÈç¹ûÒªÏÔʾһÆÁÄ»°ïÖú£¬Ò»ÐÐÊDz»¹»µÄ£¬µ«Òª×¢ÒâµÄÊÇ£ºÒªÓõ½ÕâÖÖ×Ö·û´®µÄ³¤¶Èʱ£¬Ç§Íò²»ÒªÓÃsizeofÈ¥±íʾ£¬×îºÃÊÇÔÚ³ÌÐòÖÐÓÃlstrlenº¯ÊýÈ¥¼ÆËã¡£
¡¡
À´Ô´£ºµç×Ó¹¤Òµ³ö°æÉç¡¡×÷ÕߣºÂÞÔƱò¡¡ÉÏÒ»Ò³¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡»ØÊéÄ¿¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ÏÂÒ»Ò³¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
ÉÏÒ»Ò³¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡»ØÊéÄ¿¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ÏÂÒ»Ò³¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
¡¡¡¡
µÚ3Õ¡¡Ê¹ÓÃMASM
3¡£3¡¡±êºÅ¡¢±äÁ¿ºÍÊý¾Ý½á¹¹£¨5£©
¡¡¡¡¡¡¡¡
3¡£¡¡»ñÈ¡±äÁ¿µØÖ·
»ñÈ¡±äÁ¿µØÖ·µÄ²Ù×÷¶ÔÓÚÈ«¾Ö±äÁ¿ºÍ¾Ö²¿±äÁ¿ÊDz»Í¬µÄ¡£
¶ÔÓÚÈ«¾Ö±äÁ¿£¬ËüµÄµØÖ·ÔÚ±àÒëµÄʱºòÒѾÓɱàÒëÆ÷È·¶¨ÁË£¬ËüµÄÓ÷¨´ó¼Ò¶¼²»Ä°Éú£º
mov¡¡¡¡¡¡¡¡¡¡¼Ä´æÆ÷£»offset¡¡±äÁ¿Ãû
ÆäÖÐoffsetÊÇÈ¡±äÁ¿µØÖ·µÄα²Ù×÷·û£¬ºÍsizeofα²Ù×÷·ûÒ»Ñù£¬Ëü½ö°Ñ±äÁ¿µÄµØÖ·´úµ½Ö¸ÁîÖÐÈ¥£¬Õâ¸ö²Ù×÷ÊÇÔÚ±àÒëʱ¶ø²»ÊÇÔÚÔËÐÐʱÍê³ÉµÄ¡£
¶ÔÓÚ¾Ö²¿±äÁ¿£¬ËüÊÇÓÃebpÀ´×öÖ¸Õë²Ù×÷µÄ£¬¼ÙÉèebpµÄÖµÊÇ40100h£¬ÄÇô¾Ö²¿±äÁ¿1µÄµØÖ·ÊÇebp¡4¼´400FCh£¬ÓÉÓÚebpµÄÖµËæ×ųÌÐòµÄÖ´Ðл·¾³²»Í¬¿ÉÄÜÊDz»Í¬µÄ£¬ËùÒÔ¾Ö²¿±äÁ¿µÄµØÖ·ÖµÔÚ±àÒëµÄʱºòÒ²ÊDz»È·¶¨µÄ£¬²»¿ÉÄÜÓÃoffsetα²Ù×÷·ûÀ´»ñÈ¡ËüµÄµØÖ·¡£
80386´¦ÀíÆ÷ÖÐÓÐÒ»ÌõÖ¸ÁîÓÃÀ´È¡Ö¸ÕëµÄµØÖ·£¬¾ÍÊÇleaÖ¸ÁÈ磺
lea¡¡¡¡¡¡¡¡¡¡eax£»£§ebp¡4£§
¸ÃÖ¸Áî¿ÉÒÔÔÚÔËÐÐʱ°´ÕÕebpµÄֵʵ¼Ê¼ÆËã³öµØÖ··Åµ½eaxÖС£
Èç¹ûÒªÔÚinvokeαָÁîµÄ²ÎÊýÖÐÓõ½Ò»¸ö¾Ö²¿±äÁ¿µÄµØÖ·£¬¸ÃÔõô°ìÄØ£¿²ÎÊýÖÐÊDz»¿ÉÄÜдÈëleaÖ¸ÁîµÄ£¬ÓÃoffsetÓÖÊDz»¶ÔµÄ¡£MASM¶Ô´ËÓÐÒ»¸öרÓõÄα²Ù×÷·ûaddr£¬Æä¸ñʽΪ£º
addr¡¡¾Ö²¿±äÁ¿ÃûºÍÈ«¾Ö±äÁ¿Ãû
µ±addrºó¸úÈ«¾Ö±äÁ¿ÃûµÄʱºò£¬Ó÷¨ºÍoffsetÊÇÏàͬµÄ£»µ±addrºóÃæ¸ú¾Ö²¿±äÁ¿ÃûµÄʱºò£¬±àÒëÆ÷»á×Ô¶¯ÓÃleaÖ¸ÁîÏȰѵØÖ·È¡µ½eaxÖУ¬È»ºóÓÃeaxÀ´´úÌæ±äÁ¿µØַʹÓá£×¢Òâaddrα²Ù×÷·ûÖ»ÄÜÔÚinvokeµÄ²ÎÊýÖÐʹÓ㬲»ÄÜÓÃÔÚÀàËÆÓÚÏÂÁеij¡ºÏ£º
mov¡¡eax£»addr¡¡¾Ö²¿±äÁ¿Ãû¡¡¡¡¡¡£»×¢Ò⣺´íÎóÓ÷¨
¡¡¼ÙÉèÔÚÒ»¸ö×Ó³ÌÐòÖÐÓÐÈçÏÂinvokeÖ¸Á
¡¡¡¡invoke¡¡¡¡Test£»eax£»addr¡¡szHello
ÆäÖÐTestÊÇÒ»¸öÐèÒªÁ½¸ö²ÎÊýµÄ×Ó³ÌÐò£¬szHelloÊÇÒ»¸ö¾Ö²¿±äÁ¿£¬»á·¢Éúʲô½á¹ûÄØ£¿±àÒëÆ÷»á°ÑinvokeαָÁîºÍaddr·Òë³ÉÏÂÃæÕâ¸öÄ£Ñù£º
lea¡¡¡¡¡¡¡¡eax£»£§ebp¡4£§
push¡¡¡¡¡¡eax¡¡¡¡¡¡¡¡£»²ÎÊý2£ºaddr¡¡szHello
push¡¡¡¡¡¡eax¡¡¡¡¡¡¡¡£»²ÎÊý1£ºeax
call¡¡¡¡¡¡Test
·¢ÏÖÁËʲô£¿µ½pushµÚÒ»¸ö²ÎÊýeax֮ǰ£¬eaxµÄÖµÒѾ±»lea¡¡eax£»£§ebp¡4£§Ö¸Á¸ÇÁË£¡Ò²¾ÍÊÇ˵£¬ÒªÓõ½µÄeaxµÄÖµ²»ÔÙÓÐЧ£¬ËùÒÔ£¬µ±ÔÚinvokeÖÐʹÓÃaddrα²Ù×÷·ûʱ£¬×¢ÒâÔÚËüµÄÇ°Ãæ²»ÄÜÓÃeax£¬·ñÔòeaxµÄÖµ»á±»¸²¸Çµô£¬µ±È»eaxÔÚaddrµÄºóÃæµÄ²ÎÊýÖÐÓÃÊÇ¿ÉÒԵġ£ÐÒ¿÷MASM±àÒëÆ÷¶ÔÕâÖÖÇé¿öÓÐÈçÏ´íÎóÌáʾ£º
error¡¡A2133£º¡¡register¡¡value¡¡overwritten¡¡by¡¡INVOKE
·ñÔò£¬²»ÖªµÀÓÖ»áÒý³ö¶àÉÙĪÃûÆäÃîµÄ´íÎó£¡
¡¡
À´Ô´£ºµç×Ó¹¤Òµ³ö°æÉç¡¡×÷ÕߣºÂÞÔƱò¡¡ÉÏÒ»Ò³¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡»ØÊéÄ¿¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ÏÂÒ»Ò³¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
ÉÏÒ»Ò³¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡»ØÊéÄ¿¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ÏÂÒ»Ò³¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
¡¡¡¡
µÚ3Õ¡¡Ê¹ÓÃMASM
3¡£4¡¡Ê¹ÓÃ×Ó³ÌÐò
¡¡¡¡¡¡¡¡
µ±³ÌÐòÖÐÏàͬ¹¦ÄܵÄÒ»¶Î´úÂëÓõñȽÏƵ·±Ê±£¬¿ÉÒÔ½«Ëü·ÖÀ