ÓÑÇéÌáʾ£ºÈç¹û±¾ÍøÒ³´ò¿ªÌ«Âý»òÏÔʾ²»ÍêÕû£¬Çë³¢ÊÔÊó±êÓÒ¼ü¡°Ë¢Ð¡±±¾ÍøÒ³£¡ÔĶÁ¹ý³Ì·¢ÏÖÈκδíÎóÇë¸æËßÎÒÃÇ£¬Ð»Ð»£¡£¡ ±¨¸æ´íÎó
°ËÍòС˵Íø ·µ»Ø±¾ÊéĿ¼ ÎÒµÄÊé¼Ü ÎÒµÄÊéÇ© TXTÈ«±¾ÏÂÔØ ½øÈëÊé°É ¼ÓÈëÊéÇ©

windows»·¾³ÏÂ32λ»ã±àÓïÑÔ³ÌÐòÉè¼Æ-µÚ54²¿·Ö

°´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·­Ò³£¬°´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ£¬°´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿£¡
¡ª¡ª¡ª¡ªÎ´ÔĶÁÍꣿ¼ÓÈëÊéÇ©ÒѱãÏ´μÌÐøÔĶÁ£¡



ú×ٺͶ¨Î»¡£

×îºó£¬Ê¹ÓÃ˽ÓжÑҲʹ´óÁ¿ÄÚ´æµÄÇåÀí±äµÃ·½±ã£¬ÔÚĬÈ϶ÑÖзÖÅäµÄÄÚ´æÐèÒªÒ»¿é¿éµ¥¶ÀÊÍ·Å£¬µ«½«Ò»¸ö˽ÓжÑÊͷźó£¬ÔÚÕâ¸ö¶ÑÀïµÄÄÚ´æ¾ÍÈ«²¿±»ÊͷŵôÁË£¬²¢²»ÐèÒªÔ¤ÏÈÊͷŶÑÖеÄÿ¸öÄÚ´æ¿é£¬ÕâÑù·Ç³£±ãÓÚÄ£¿éµÄɨβ¹¤×÷¡£

1¡£¡¡Ë½ÓжѵĴ´½¨ºÍÊÍ·Å

´´½¨Ë½Óжѵĺ¯ÊýÊÇHeapCreate£º

¡¡¡¡¡¡¡¡invoke¡¡¡¡HeapCreate£¬flOptions£¬dwInitialSize£¬dwMaximumSize

¡¡¡¡¡¡¡¡¡£if¡¡¡¡¡¡¡¡¡¡eax¡¡&&¡¡£¨eax¡¡¡¶¡¡0c0000000h£©

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡mov¡¡hHeap£¬eax

¡¡¡¡¡¡¡¡¡£endif

flOptions²ÎÊýÊDZêÖ¾£¬ÓÃÀ´Ö¸¶¨¶ÑµÄÊôÐÔ£¬¿ÉÒÔÖ¸¶¨µÄÊôÐÔÓÐHEAP_NO_SERIALIZEºÍHEAP_GENERATE_EXCEPTIONSÁ½ÖÖ¡£

HEAP_GENERATE_EXCEPTIONS±êÖ¾ÓÃÀ´Ö¸¶¨º¯Êýʧ°ÜʱµÄ·µ»ØÖµ£¬²»Ö¸¶¨Õâ¸ö±êÖ¾µÄ»°£¬º¯Êýʧ°Üʱ·µ»ØNULL£¬·ñÔò·µ»ØÒ»¸ö¾ßÌåµÄ³ö´í´úÂ룬ÒÔ±ãÓÚ³ÌÐòÏêϸÁ˽â³ö´íÔ­Òò¡£³ö´í´úÂëµÄ¶¨ÒåÖµ¶¼´óÓÚ0c0000000h£¬ÒòΪ0c0000000h¿ªÊ¼µÄµØÖ·¿Õ¼äΪϵͳʹÓ㬷ÖÅäµÄÄÚ´æµØÖ·²»¿ÉÄܸßÓÚÕâ¸öµØÖ·£¬ËùÒÔ¼ì²âº¯ÊýÖ´ÐÐÊÇ·ñ³É¹¦µÄʱºò¿ÉÒÔʹÓÃÉÏÃæµÄ²âÊÔÓï¾äÀ´±È½Ï·µ»ØÖµÊÇ·ñÔÚ0¡«0c0000000hÖ®¼ä¡£

HEAP_NO_SERIALIZE±êÖ¾ÓÃÀ´¿ØÖƶÔ˽ÓжѵķÃÎÊÊÇ·ñÒª½øÐжÀÕ¼ÐԵļì²â£¬Ç°ÃæÔø¾­Ìáµ½ÔÚĬÈ϶ÑÖÐÉêÇëÄÚ´æ¿éµÄ²Ù×÷ÊÇ˳Ðò½øÐеģ¬¶à¸öÏß³ÌͬʱÉêÇëÄÚ´æµÄÇëÇóÖ»ÓÐÒ»¸öÄÜÂíÉÏÖ´ÐУ¬ÆäËû½«´¦Óڵȴý״̬£¬¶ÔÓÚÒ»¸ö˽ÓжÑÀ´Ëµ£¬Õâ¸öÏÞÖÆÈÔÈ»´æÔÚ£¬µ±´Ó¶ÑÖзÖÅäÄÚ´æʱ£¬ÏµÍ³ÓÐÏÂÃæµÄ²Ù×÷²½Ö裺

£¨1£©±éÀúÒÑ·ÖÅäµÄºÍ¿ÕÏеÄÄÚ´æ¿éµÄÁ´½Ó±í¡£

£¨2£©Ñ°ÕÒÒ»¸ö¿ÕÏÐÄÚ´æ¿éµÄµØÖ·¡£

£¨3£©Í¨¹ý½«¿ÕÏÐÄÚ´æ¿é±ê¼ÇΪ¡°ÒÑ·ÖÅ䡱À´·ÖÅäÐÂÄÚ´æ¿é¡£

£¨4£©½«ÐÂÄÚ´æ¿éÌí¼Ó¸øÄÚ´æ¿éÁ´½Ó±í¡£

µ±Á½¸öÏ̼߳¸ºõͬʱÔÚͬһ¸ö¶ÑÖÐÉêÇëÄÚ´æʱ£¬Èç¹ûµÚÒ»¸öÏß³ÌÖ´ÐÐÁË£¨1£©¡¢£¨2£©Á½²½µÄʱºò±»ÏµÍ³Çл»µ½µÚ¶þ¸öÏßÐÔ£¬Ïß³Ì2ͬÑùÓÖÖ´ÐУ¨1£©¡¢£¨2£©Á½²½£¬ÄÇôËüÃÇÕÒµ½µÄ¿ÕÏÐÄÚ´æ¿é¾Í»áÊÇͬһ¿éÄڴ棬½á¹û¿ÉÏë¶øÖª¡£½â¾öÎÊÌâµÄ°ì·¨¾ÍÊÇÈõ¥¸öÏ̶߳ÀÕ¼¶Ô¶ÑºÍËüµÄÁ´½Ó±íµÄ·ÃÎÊȨ£¬µ±Ò»¸öÏß³ÌÈ«²¿Ö´ÐÐÁËÕâ4¸ö²½Öèºó²ÅÔÊÐíµÚ¶þ¸öÏ߳̿ªÊ¼µÚÒ»¸ö²½Öè¡£

ÔÚÓÃĬÈϲÎÊý½¨Á¢µÄ¶ÑÖÐÉêÇëÄڴ棬ϵͳ»á½øÐжÀÕ¼µÄ¼ì²â¹¤×÷£¬µ±È»ÕâÒª»¨·ÑÒ»¶¨µÄϵͳ¿ªÏú¡£µ«Êǵ±ÒÔÏÂÇé¿ö´æÔÚʱ£¬¿ÉÒÔ±£Ö¤²»»áͬʱÓжà¸öÏß³ÌÔÚͬһ¸ö¶ÑÖÐÉêÇëÄڴ棺

¡ñ¡¡¡¡¡¡½ø³ÌֻʹÓÃÒ»¸öÏ̡߳£

¡ñ¡¡¡¡¡¡½ø³ÌʹÓöà¸öỊ̈߳¬µ«ÊÇÿ¸öÏß³ÌÖ»·ÃÎÊÊôÓÚ×Ô¼ºµÄ˽Óжѡ£

¡ñ¡¡¡¡¡¡½ø³ÌʹÓöà¸öỊ̈߳¬µ«³ÌÐòÖÐÒѾ­ÓÐÆäËû´ëÊ©À´±£Ö¤ËüÃDz»»áͬʱȥ·ÃÎÊͬһ¸ö˽Óжѡ£

ÔÚÕâЩÇé¿öÏ£¬¿ÉÒÔÖ¸¶¨HEAP_NO_SERIALIZE¡¡¡¡¡¡¡¡±êÖ¾À´½¨Á¢Ë½Óжѣ¬ÕâÑù½¨Á¢µÄ¶Ñ²»»á½øÐжÀÕ¼ÐԵļì²â£¬·ÃÎÊËٶȿÉÒÔ¸ü¿ì¡£

²ÎÊýdwInitialSizeÖ¸¶¨´´½¨¶Ñʱ·ÖÅä¸ø¶ÑµÄÎïÀíÄڴ棬Ëæ×ŶÑÖÐÄÚ´æµÄ·ÖÅ䣬µ±ÕâЩÄڴ汻ʹÓÃÍêʱ£¬¶ÑµÄ³¤¶È¿ÉÒÔ×Ô¶¯À©Õ¹¡£dwMaximumSize²ÎÊýÖ¸¶¨ÁËÄܹ»À©Õ¹µ½µÄ×î´óÖµ£¬µ±À©Õ¹µ½×î´óֵʱÔÙ³¢ÊÔÔÚ¶ÑÖзÖÅäÄÚ´æµÄ»°¾Í»áʧ°Ü£¬Õâ¸öÖµ¾ö¶¨ÁËϵͳ¸ø¶Ñ±£ÁôµÄÁ¬ÐøµØÖ·¿Õ¼äµÄ´óС£¬º¯Êý»á×Ô¶¯½«ÕâÁ½¸ö²ÎÊýµÄÊýÖµµ÷ÕûΪҳÃæ´óСµÄÕûÊý±¶¡£Èç¹ûdwMaximumSize²ÎÊýµÄÖµÖ¸¶¨Îª0£¬ÄÇô¶ÑûÓÐ×î´óÖµÏÞÖÆ£¬À©Õ¹·¶Î§Ö»ÊÜÏÞÓÚ¿ÕÏеÄÄÚ´æ×ÜÁ¿¡£Èç¹ûdwMaximumSizeÖ¸¶¨Îª·Ç0Öµ£¬ÔÚ¶ÑÖÐÉêÇëµÄ×î´óµ¥¸öÄÚ´æ¿é²»ÄÜ´óÓÚ7FFF8h£¨Ï൱ÓÚ524¡¡KB£©£¬dwMaximumSizeÖ¸¶¨0µÄ»°¾ÍûÓÐÕâ¸öÏÞÖÆ¡£

Èç¹ûÒ»¸ö˽ÓжѲ»ÔÙÐèÒªÁË£¬¿ÉÒÔͨ¹ýµ÷ÓÃHeapDestroyº¯Êý½«ËüÊÍ·Å£º

¡¡¡¡¡¡¡¡invoke¡¡¡¡HeapDestroy£¬hHeap

ÊÍ·Å˽ÓжѿÉÒÔÊͷŶÑÖаüº¬µÄËùÓÐÄÚ´æ¿é£¬Ò²¿ÉÒÔ½«¶ÑÕ¼ÓõÄÎïÀíÄÚ´æºÍ±£ÁôµÄµØÖ·¿Õ¼äÈ«²¿·µ»¹¸øϵͳ¡£Èç¹ûº¯ÊýÔËÐгɹ¦£¬·µ»ØÖµÊÇTRUE¡£µ±ÔÚ½ø³ÌÖÕÖ¹µÄʱºòûÓе÷ÓÃHeapDestroyº¯Êý½«Ë½ÓжÑÊÍ·Åʱ£¬ÏµÍ³»á×Ô¶¯ÊÍ·Å¡£

ËäÈ»ÔÚĬÈ϶ÑÖеÄÄÚ´æÉêÇëÖ÷ҪʹÓñê×¼ÄÚ´æ¹ÜÀíº¯Êý£¬¶ø¶Ñ¹ÜÀíº¯ÊýµÄÖ÷Òª¹ÜÀí¶ÔÏóÊÇ˽Óжѣ¬µ«ÊÇÈç¹û±à³ÌÕßÔ¸ÒâµÄ»°£¬Ò²¿ÉÒÔÓöѹÜÀíº¯ÊýÔÚĬÈ϶ÑÖзÖÅäÄڴ棬±Ï¾¹Ä¬È϶ÑÒ²ÊÇÒ»¸ö¶Ñ£¬µ«ÕâÑùµÄ»°Ê×ÏÈÐèÒªÓÐÒ»¸ö¾ä±úÀ´´ú±íĬÈ϶ѣ¬Ä¬È϶ѵľä±ú²»ÄÜÓÃHeapCreateÀ´´´½¨£¬µ«¿ÉÒÔÓÃGetProcessHeapº¯ÊýÀ´»ñÈ¡£¬Õâ¸öº¯ÊýûÓÐÊäÈë²ÎÊý£¬Èç¹ûÖ´Ðгɹ¦Ôò·µ»ØĬÈ϶ѵľä±ú¡£×¢Ò⣺Õâ¸ö¾ä±úÊÇ¡°»ñÈ¡¡±µÄ¶ø²»ÊÇ¡°´´½¨¡±µÄ£¬ËùÒÔ²»Äܵ÷ÓÃHeapDestroyÀ´ÊÍ·ÅËü£¬Èç¹û¶ÔËüµ÷ÓÃHeapDestroyº¯Êý£¬ÏµÍ³»á½«ËüºöÂÔ¡£

2¡£¡¡ÔÚ¶ÑÖзÖÅäºÍÊÍ·ÅÄÚ´æ¿é

Èç¹ûÒªÔÚ¶ÑÖзÖÅäÄÚ´æ¿é£¬¿ÉÒÔʹÓÃHeapAllocº¯Êý£º

¡¡¡¡¡¡¡¡invoke¡¡¡¡HeapAlloc£¬hHeap£¬dwFlags£¬dwBytes

¡¡¡¡¡¡¡¡¡£if¡¡¡¡¡¡¡¡¡¡eax¡¡&&¡¡£¨eax¡¡¡¶¡¡0c0000000h£©

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡mov¡¡¡¡¡¡¡¡¡¡lpMemory£¬eax

¡¡¡¡¡¡¡¡¡£endif

hHeap²ÎÊý¾ÍÊÇÇ°Ãæ´´½¨¶Ñʱ·µ»ØµÄ¶Ñ¾ä±ú£¨»òÕßʹÓÃGetProcessHeapº¯ÊýµÃµ½µÄĬÈ϶Ѿä±ú£©£¬ÓÃÀ´±íʾÔÚÄĸö¶ÑÖзÖÅäÄڴ棬dwBytesÊÇÐèÒª·ÖÅäµÄÄÚ´æ¿éµÄ×Ö½ÚÊý£¬dwFlagsÊDZêÖ¾£¬Ëü¿ÉÒÔÊÇÏÂÃæÖµµÄ×éºÏ£º

¡ñ¡¡¡¡¡¡HEAP_NO_SERIALIZE¡ª¡ªµ±Ê¹ÓÃHeapCreateʱָ¶¨ÁËHEAP_NO_SERIALIZE±êÖ¾£¬ÒÔºóÕâ¸ö¶ÑÖÐʹÓõÄËùÓÐHeapAllocº¯Êý¶¼²»½øÐжÀÕ¼¼ì²â¡£Èç¹ûʹÓÃHeapCreateʱûÓÐÖ¸¶¨HEAP_NO_SERIALIZE±êÖ¾£¬¿ÉÒÔÔÚÕâÀïʹÓÃHEAP_NO_SERIALIZE±êÖ¾µ¥¶ÀÖ¸¶¨¶Ô±¾´Î·ÖÅä²Ù×÷²»½øÐжÀÕ¼¼ì²â¡£

¡ñ¡¡¡¡¡¡HEAP_GENERATE¡¡_EXCEPTIONS¡ª¡ªÈç¹ûÉêÇëÄÚ´æʧ°Üº¯Êý·µ»Ø¾ßÌåµÄ³ö´íÔ­Òò£¬¶ø²»½ö·µ»ØÒ»¸öNULL¡£Í¬Ñù£¬µ±Ê¹ÓÃHeapCreateʱָ¶¨Á˴˱êÖ¾µÄÇé¿öÏ£¬ÔÚÕâÀï¾Í²»±ØÔÙÒ»´ÎÖ¸¶¨¡£

¡ñ¡¡¡¡¡¡HEAP_ZERO_MEMORY¡ª¡ª½«·ÖÅäµÄÄÚ´æÓÃ0³õʼ»¯¡£

µ±º¯Êý·ÖÅäÄÚ´æ³É¹¦µÄʱºò£¬·µ»ØÖµÊÇÖ¸ÏòÄÚ´æ¿éµÚÒ»¸ö×Ö½ÚµÄÖ¸Õ룬Èç¹û·ÖÅäÄÚ´æʧ°Ü£¬·µ»ØÖµÒªÊÓdwFlagsµÄÉèÖã¬Èç¹ûûÓÐÖ¸¶¨HEAP_GENERATE_EXCEPTIONS±êÖ¾£¬ÄÇô·µ»ØֵΪNULL£¬·ñÔò£¬·µ»ØÖµ¿ÉÄÜÊÇÏÂÃæµÄÊýÖµ£º

¡ñ¡¡¡¡¡¡STATUS_NO_MEMORY¡ª¡ªÈ¡ÖµÎª0C0000017h£¬±íʾÄÚ´æ²»¹»¡£

¡ñ¡¡¡¡¡¡STATUS_ACCESS_VIOLATION¡ª¡ªÈ¡ÖµÎª0C0000005h£¬±íʾ²ÎÊý²»ÕýÈ·»òÕ߶ѱ»ÆÆ»µ¡£

ÔÚ¶ÑÖзÖÅäµÄÄÚ´æ¿éÖ»ÄÜÊǹ̶¨µØÖ·µÄÄÚ´æ¿é£¬²»ÏñGlobalAllocº¯ÊýÒ»Ñù¿ÉÒÔ·ÖÅä¿ÉÒƶ¯µÄÄÚ´æ¿é¡£Èç¹ûÒªÊÍ·Å·ÖÅäµ½µÄÄÚ´æ¿é£¬¿ÉÒÔʹÓÃHeapFreeº¯Êý£º

¡¡¡¡¡¡¡¡invoke¡¡¡¡HeapFree£¬hHeap£¬dwFlags£¬lpMemory

hHeap²ÎÊýÊǶѾä±ú£¬lpMemoryÊÇHeapAllocº¯Êý·µ»ØµÄÄÚ´æ¿éÖ¸Õ룬dwFlags²ÎÊýÖÐÒ²¿ÉÒÔʹÓÃHEAP_NO_SERIALIZE±êÖ¾£¬º¬ÒåÓëʹÓÃHeapAllocʱÏàͬ¡£µ±º¯ÊýÖ´Ðгɹ¦µÄʱºò£¬·µ»ØֵΪ·Ç0Öµ£¬Ö´ÐÐʧ°ÜÔòº¯Êý·µ»Ø0¡£

¶ÔÓÚÓÃHeapAlloc·ÖÅäµÄÄÚ´æ¿é£¬Ò²¿ÉÒÔʹÓÃHeapReAllocÖØе÷Õû´óС£º

invoke¡¡¡¡HeapReAlloc£¬hHeap£¬dwFlags£¬lpMemory£¬dwBytes

¡¡¡¡¡¡¡¡¡£if¡¡¡¡¡¡¡¡¡¡eax¡¡&&¡¡£¨eax¡¡¡¶¡¡0c0000000h£©

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡mov¡¡¡¡¡¡¡¡¡¡lpMemory£¬eax

¡¡¡¡¡¡¡¡¡£endif



¡¡
À´Ô´£ºµç×Ó¹¤Òµ³ö°æÉç¡¡×÷ÕߣºÂÞÔƱò¡¡ÉÏÒ»Ò³¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡»ØÊéÄ¿¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ÏÂÒ»Ò³¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
ÉÏÒ»Ò³¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡»ØÊéÄ¿¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ÏÂÒ»Ò³¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
¡¡¡¡


µÚ10Õ¡¡ÄÚ´æ¹ÜÀíºÍÎļþ²Ù×÷


10¡£1¡¡ÄÚ¡¡´æ¡¡¹Ü¡¡Àí£¨6£©

¡¡¡¡¡¡¡¡
ÆäÖÐdwBytesÖ¸¶¨ÁËеĴóС£¬dwFlagsΪ±êÖ¾£¬¿ÉÒÔ×éºÏÖ¸¶¨µÄ±êÖ¾ÓУº

¡ñ¡¡¡¡¡¡HEAP_GENERATE_EXCEPTIONS¡ª¡ª²Î¼ûHeapAllocº¯ÊýµÄ˵Ã÷¡£

¡ñ¡¡¡¡¡¡HEAP_NO_SERIALIZE¡ª¡ª²Î¼ûHeapAllocº¯ÊýµÄ˵Ã÷¡£

¡ñ¡¡¡¡¡¡HEAP_ZERO_MEMORY¡ª¡ªµ±À©´óÄÚ´æ¿éµÄʱºò£¬½«ÐÂÔöµÄ²¿·Ö³õʼ»¯Îª0£¬µ±ËõСÄÚ´æµÄʱºò£¬±¾²ÎÊýÎÞЧ¡£

¡ñ¡¡¡¡¡¡HEAP_REALLOC_IN_PLACE_ONLY¡ª¡ªÓëGlobalReAllocº¯ÊýÀàËÆ£¬µ±ÄÚ´æ¿éµÄ¸ß´¦ÒѾ­±»ÆäËûÄÚ´æ¿éÕ¼¾ÝµÄʱºò£¬ÒªÀ©´óÄÚ´æ¿é±ØÐ뽫ËüÒƶ¯Î»Ö㬵±Ã»ÓÐÖ¸¶¨Õâ¸ö±êÖ¾µÄʱºò£¬º¯Êý»áÔÚÐèÒªµÄʱºò×Ô¶¯Òƶ¯ÄÚ´æ¿é£¬Èç¹ûÖ¸¶¨ÁËÕâ¸ö±êÖ¾£¬Ôò²»ÔÊÐíÄÚ´æ¿éÒƶ¯£¬Õâʱ£¬µ±ÄÚ´æ¿é¸ß´¦²»ÊÇ¿ÕÏеÄʱºò£¬º¯ÊýµÄÖ´Ðлáʧ°Ü¡£

Èç¹ûº¯ÊýÖ´Ðгɹ¦£¬·µ»ØÖµÊÇÖ¸ÏòÐÂÄÚ´æ¿éµÄÖ¸Õ룬ÏÔ¶øÒ×¼û£¬µ±ËõС»òÀ©´óÄÚ´æ¿éʱָ¶¨ÁËHEAP_REALLOC_IN_PLACE_ONLY±êÖ¾£¬ÔòÕâ¸öÖ¸Õë±Ø¶¨ºÍÔ­À´µÄÏàͬ£¬·ñÔòµÄ»°£¬Ëü¼ÈÓпÉÄܺÍÔ­À´µÄÖ¸ÕëÏàͬҲÓпÉÄܲ»Í¬¡£

3¡£¡¡ÆäËû¶Ñ¹ÜÀíº¯Êý

³ýÁËÉÏÃæµÄһЩº¯Êý£¬¶Ñ¹ÜÀíº¯ÊýÖл¹ÓÐHeapLock£¬HeapUnlock£¬GetProcessHeaps£¬Heappact£¬HeapSize£¬HeapValidateºÍHeapWalkµÈº¯Êý¡£

GetProcessHeapsº¯ÊýÓÃÀ´Áгö½ø³ÌÖÐËùÓеĶѣ¨×¢Ò⣺²»ÒªºÍÓÃÀ´»ñȡĬÈ϶Ѿä±úµÄGetProcessHeapº¯Êý¸ã»ì£©£¬HeapWalkÓÃÀ´ÁгöÒ»¸ö¶ÑÖÐËùÓеÄÄÚ´æ¿é£¬HeapValidateº¯ÊýÓÃÀ´¼ìÑéÒ»¸ö¶ÑÖÐËùÓÐÄÚ´æ¿éµÄÓÐЧÐÔ¡£Õâ3¸öº¯ÊýƽʱºÜÉÙʹÓã¬Ò»°ãÔÚµ÷ÊÔµÄʱºòʹÓá£

GetProcessHeapsº¯ÊýµÄÓ÷¨ÊÇ£º

¡¡¡¡¡¡¡¡invoke¡¡¡¡GetProcessHeaps£¬NumberOfHeaps£¬lpHeaps

ÆäÖÐlpHeapsÊÇÒ»¸öÖ¸Õ룬ָÏòÓÃÀ´½ÓÊնѾä±úµÄ»º³åÇø£¬NumberOfHeaps²ÎÊýÖ¸¶¨ÁËÕâ¸ö»º³åÇøÖпÉÒÔ´æ·Å¾ä±úµÄÊýÁ¿£¬ÏÔÈ»£¬»º³åÇøµÄ³¤¶ÈÓ¦¸ÃµÈÓÚNumberOfHeaps³ËÒÔ4×Ö½Ú¡£º¯ÊýÖ´Ðк󣬽ø³ÌÖÐËùÓжѵľä±úÈ«²¿·µ»Øµ½»º³åÇøÖУ¬ÆäÖÐÒ²°üÀ¨Ä¬È϶ѵľä±ú¡£

HeapWalkº¯ÊýµÄÓ÷¨ÊÇ£º

¡¡¡¡¡¡¡¡¡£repeat

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡invoke¡¡¡¡HeapWalk£¬hHeap£¬lpEntry

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡push¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡eax

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£»¼ì²â»º³åÇøÖеÄÄÚ´æ¿éÐÅÏ¢

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡pop¡¡eax

¡£until¡¡¡¡£¡eax

hHeapÊÇÐèÒª²Ù×÷µÄ¶Ñ¾ä±ú£¬lpEntryÖ¸ÏòÒ»¸ö°üº¬ÓÐPROCESS_HEAP_ENTRY½á¹¹µÄ»º³åÇø¡£µ÷ÓÃHeapWalkº¯Êýʱ£¬º¯Êýÿ´ÎÔÚPROCESS_HEAP_ENTRY½á¹¹Öзµ»ØÒ»¸öÄÚ´æ¿éµÄÐÅÏ¢£¬Èç¹û»¹ÓÐÆäËûÄÚ´æ¿é£¬º¯Êý·µ»ØTRUE£¬³ÌÐò¿ÉÒÔһֱѭ»·µ÷ÓÃHeapWalkº¯ÊýÖ±µ½º¯Êý·µ»ØFALSEΪֹ¡£ÔÚ¶àÏ̵߳ijÌÐòÖÐʹÓÃHeapWalk£¬±ØÐëÊ×ÏÈʹÓÃHeapLockº¯Êý½«¶ÑËø¶¨£¬·ñÔòµ÷Óûáʧ°Ü¡£

HeapValidateÓÃÀ´ÑéÖ¤¶ÑµÄÍêÕûÐÔ»ò¶ÑÖÐij¸öÄÚ´æ¿éµÄÍêÕûÐÔ£º

¡¡¡¡¡¡¡¡invoke¡¡¡¡HeapValidate£¬hHeap£¬dwFlags£¬lpMemory

ÆäÖÐhHeapÖ¸¶¨ÒªÑéÖ¤µÄ¶Ñ¡£Èç¹ûlpMemoryΪNULL£¬ÄÇôº¯Êý˳ÐòÑéÖ¤¶ÑÖÐËùÓеÄÄÚ´æ¿é£»Èç¹ûlpMemoryÖ¸¶¨ÁËÒ»¸öÄÚ´æ¿é£¬ÔòÖ»ÑéÖ¤Õâ¸öÄÚ´æ¿é¡£dwFlagsÊDZêÖ¾£¬¿ÉÒÔÖ¸¶¨HEAP_NO_SERIALIZE¡¡±êÖ¾¡£Èç¹ûÑéÖ¤½á¹ûÊÇËùÓеÄÄÚ´æ¿é¶¼ÍêºÃÎÞË𣬺¯Êý·µ»Ø·Ç0Öµ£¬·ñÔòº¯Êý·µ»Ø0¡£

HeapLockº¯ÊýºÍHeapUnlockº¯ÊýÓÃÀ´Ëø¶¨¶ÑºÍ½âËø¶Ñ¡£ÕâÁ½¸öº¯ÊýÖ÷ÒªÓÃÓÚÏ̵߳Äͬ²½£¬µ±ÔÚÒ»¸öÏß³ÌÖе÷ÓÃHeapLockº¯Êýʱ£¬Õâ¸öÏß³ÌÔÝʱ³ÉΪÕâ¸ö¶ÑµÄËùÓÐÕߣ¬Ò²¾ÍÊÇ˵ֻÓÐÕâ¸öÏß³ÌÄܶԶѽøÐвÙ×÷£¨°üÀ¨·ÖÅäÄÚ´æ¡¢ÊÍ·Å¡¢µ÷ÓÃHeapWalkµÈº¯Êý£©£¬ÔÚ±ðµÄÏß³ÌÖжÔÕâ¸ö¶ÑµÄ²Ù×÷»áµÈ´ýÔÚÄÇÀֱµ½ËùÓÐÕßÏ̵߳÷ÓÃHeapUnlock½âËøΪֹ¡£ÕâÁ½¸öº¯ÊýµÄÓï·¨ÈçÏ£º

¡¡¡¡¡¡¡¡invoke¡¡¡¡HeapLock£¬hHeap

¡¡¡¡¡¡¡¡invoke¡¡¡¡HeapUnlock£¬hHeap

Èç¹ûº¯ÊýÖ´Ðгɹ¦£¬·µ»ØֵΪ·Ç0Öµ£¬·ñÔòº¯Êý·µ»Ø0¡£Ò»°ãÀ´Ëµ£¬ºÜÉÙÔÚ³ÌÐòÖÐʹÓÃÕâÁ½¸öº¯Êý£¬¶ø×ÜÊÇʹÓÃHEAP_NO_SERIALIZE±êÖ¾À´½øÐÐͬ²½¿ØÖÆ£¬Ö¸¶¨ÁËÕâ¸ö±êÖ¾µÄ»°£¬HeapAlloc£¬HeapReAlloc£¬HeapSizeºÍHeapFreeµÈº¯Êý»áÔÚÄÚ²¿×Ô¼ºµ÷ÓÃHeapLockºÍHeapUnlockº¯Êý¡£

Heappactº¯ÊýÓÃÓںϲ¢¶ÑÖеĿÕÏÐÄÚ´æ¿é²¢ÊͷŲ»ÔÚʹÓÃÖеÄÄÚ´æÒ³Ã棺

¡¡¡¡¡¡¡¡invoke¡¡¡¡Heappact£¬hHeap£¬dwFlags

HeapSizeº¯Êý·µ»Ø¶ÑÖÐij¸öÄÚ´æ¿éµÄ´óС£¬Õâ¸ö´óС¾ÍÊÇʹÓÃHeapAllocÒÔ¼°HeapReAllocʱָ¶¨µÄ´óС£º

¡¡¡¡¡¡¡¡invoke¡¡¡¡HeapSize£¬hHeap£¬dwFlags£¬lpMemory

lpMemoryÖ¸¶¨ÁËÐèÒª·µ»Ø´óСµÄÄÚ´æ¿é£¬º¯ÊýµÄ·µ»ØÖµÊÇÄÚ´æ¿éµÄ´óС£¬Èç¹ûÖ´ÐÐʧ°Ü£¬º¯Êý·µ»Ø£¿1¡£

10¡£1¡£5¡¡¡¡ÐéÄâÄÚ´æ¹ÜÀíº¯Êý

²»¹Üij¸ö½ø³Ìʵ¼Ê¿ÉÓõÄÎïÀíÄÚ´æÊǶàÉÙ£¬Ã¿¸ö½ø³Ì¿ÉÒÔʹÓõĵØÖ·¿Õ¼ä×ÜÊÇ2¡¡GB£¬Óû§³ÌÐò²»±Ø¿¼ÂÇÒ»¸öÏ̵߳ØÖ·¶ÔÓ¦µÄÎïÀíÄڴ澿¾¹°²ÅÅÔÚʲôµØ·½¡ª¡ªÊÇÔÚÕæÕýµÄÎïÀíÄÚ´æÖУ¿ÔÚ´ÅÅ̽»»»ÎļþÖУ¿»¹ÊǸù±¾Ã»ÓÐÎïÀíÄÚ´æÓëÖ®¶ÔÓ¦¡£

Ò»¸ö½ø³ÌµÄÕû¸öµØÖ·¿Õ¼äÊǿ͹۴æÔڵģ¬µ«ÊÇ·ñÓÐÄÚ´æÓë¸Ã¶ÎµØÖ·¿Õ¼äÖеĵØÖ·Ïà¹ØÁªÊÇÁíÍâµÄÎÊÌ⣬Windows¸ºÔðÔÚÊʵ±µÄʱ¼ä°ÑÏ̵߳ØÖ·Ó³Éäµ½ÎïÀíÄÚ´æ»ò´ÅÅÌÉϵĽ»»»ÎļþÉÏ£¬Õâ¾ÍÊÇÐéÄâÄÚ´æµÄ»ù±¾¸ÅÄî¡£

ÔÚ³ÌÐòÔËÐеÄʱºò£¬½ø³ÌÖÐÿ¸öµØÖ·¶¼¿ÉÒÔ´¦ÓÚÏÂÁÐ3ÖÖ״̬µÄ1ÖÖÖУº

¡ñ¡¡¡¡¡¡Õ¼ÓÃ״̬¡ª¡ªÏ̵߳ØÖ·ÒѾ­Ó³É䵽ʵ¼ÊµÄÎïÀíÄÚ´æÖС£Ò²³ÆΪÒÑÌύ״̬¡£

¡ñ¡¡¡¡¡¡×ÔÓÉ״̬¡ª¡ªÃ»ÓÐÓ³Éäµ½ÎïÀíÄÚ´æÖУ¬Ï̵߳ØÖ·µ±Ç°Ò²Ã»Óб»³ÌÐòʹÓá£

¡ñ¡¡¡¡¡¡±£Áô״̬¡ª¡ªËäÈ»Ï̵߳ØַûÓÐÓ³Éäµ½ÎïÀíÄÚ´æÖУ¬µ«Ëü²»»á±»Ê¹Óã¬Ö±µ½³ÌÐòÏ£ÍûʹÓÃËüΪֹ¡£

½ø³Ì¿ªÊ¼µÄʱºò£¬ËùÓеØÖ·¶¼ÊÇ´¦ÓÚ×ÔÓÉ״̬µÄ£¬ÕâÒâζ×ÅËüÃǶ¼ÊÇ×ÔÓɿռ䲢ÇÒ¿ÉÒÔ±»Ìá½»µ½ÎïÀíÄڴ棬»òÕßΪ½«À´Ê¹Óöø±£ÁôÆðÀ´¡£ÈκÎ×ÔÓÉ״̬µØÖ·ÔÚÄܹ»±»Ê¹ÓÃÇ°£¬±ØÐëÊ×Ïȱ»·ÖÅäΪ±£Áô״̬»òÒÑÌύ״̬¡£

µ±Ê¹Óñê×¼ÄÚ´æ¹ÜÀíº¯Êý·ÖÅäÄÚ´æµÄʱºò£¬Óû§ÎÞ·¨Ö¸¶¨ÄÚ´æ¿éλÓÚÄĸöÏ̵߳ØÖ·£¬»òÕß²»ÒªÎ»ÓÚÄĸöÏ̵߳ØÖ·£¬¶øʹÓÃÐéÄâÄÚ´æ¹ÜÀíº¯Êý¿ÉÒÔ×öµ½ÕâÒ»µã¡£µ«ÕâÑù×öµÄÀíÓÉÊÇʲôÄØ£¿¿¼ÂÇÕâÑùÒ»ÖÖÇé¿ö£º³ÌÐòÐèÒªÒ»¸öÄÚ´æ¿éÓÃ×ö»º³åÇø£¬Ëæ×ųÌÐòµÄÔËÐУ¬Õâ¸öÄÚ´æ¿é¿ÉÄÜËæʱÐèÒªÀ©Õ¹£¬×î´ó¿ÉÄÜÀ©Õ¹Îª100¡¡MB´óС£¬ËùÒÔÏ£ÍûϵͳÔÚ·ÖÅäÆäËûÄÚ´æ¿éµÄʱºò²»ÒªÊ¹ÓÃÕâ¸öÄÚ´æ¿éºóÃæ100¡¡MB´óС·¶Î§ÄڵĵØÖ·¿Õ¼ä£¬ÕâÑù£¬¾Í¿ÉÒÔËæʱ½«ÄÚ´æ¿éÀ©´ó¶ø²»±ØÒƶ¯ËüµÄλÖá£

³ýÁËÕâÑùÒ»¸öÖ÷ÒªµÄÓÃ;Í⣬ÐéÄâÄÚ´æ¹ÜÀíº¯Êý»¹Ìṩת»»ÐéÄâµØÖ·¿Õ¼äҳ״̬µÄÄÜÁ¦£¬Ò»¸öÓ¦ÓóÌÐò¿ÉÒÔ°ÑÄÚ´æµÄ״̬´ÓÒÑÌá½»¸Ä±äΪ±£Áô£¬»ò°Ñ±£»¤µÄģʽ´Ó¡¡PAGE¡¡_READWRITE¡¡£¨¿É¶Áд£©¸Ä±äΪ¡¡PAGE_READONLY£¨Ö»¶Á£©£¬´Ó¶ø·ÀÖ¹¶Ôij¶ÎµØÖ·¿Õ¼äµÄд·ÃÎÊ£»Ó¦ÓóÌÐòÒ²¿ÉÒÔËø¶¨Ò»Ò³Äڴ棬²»ÈÃËü±»½»»»µ½´ÅÅÌÖС£

ÐéÄâÄÚ´æ¹ÜÀíº¯ÊýÊÇÒ»×éÃû×ÖÒÔVirtual¿ªÍ·µÄº¯Êý£¬Ö÷Òª°üÀ¨ÏÂÃ漸ÖÖ£º

¡ñ¡¡¡¡¡¡VirtualAllocºÍVirtualFree¡ª¡ª½øÐеØÖ·¿Õ¼äµÄ·ÖÅäºÍÊͷŹ¤×÷¡£

¡ñ¡¡¡¡¡¡VirtualLockºÍVirtualUnlock¡ª¡ª¶ÔÄÚ´æÒ³½øÐÐËø¶¨ºÍ½âËø¡£

¡ñ¡¡¡¡¡¡VirtualQuery»òVirtualQueryEx¡ª¡ª²éѯÄÚ´æÒ³µÄ״̬¡£

¡ñ¡¡¡¡¡¡VirtualProtect»òVirtualProtectEx¡ª¡ª¸Ä±äÄÚ´æÒ³µÄ±£»¤ÊôÐÔ¡£

1¡£¡¡±£ÁôºÍÊͷŵØÖ·¿Õ¼ä

±£Áô»òÌá½»Ò»¶ÎµØÖ·¿Õ¼ä£¬Ê¹ÓÃVirtualAllocº¯Êý£¬ÊÍ·Å»ò½â³ýÌá½»µØÖ·¿Õ¼ä£¬ÔòʹÓÃVirtualFreeº¯Êý¡£ÏÈÀ´¿´Virtualallocº¯ÊýµÄʹÓ÷½·¨£º

invoke¡¡¡¡VirtualAlloc£¬lpAddress£¬dwSize£¬flAllocationType£¬flProtect¡¡

lpAddress²ÎÊýÖ¸¶¨ÐèÒª±£Áô»òÌá½»µÄµØÖ·¿Õ¼äµÄλÖ㬲ÎÊý¿ÉÒÔʹÓÃNULLÖµÒ²¿ÉÒÔÖ¸¶¨Ò»¸ö¾ßÌåµÄµØÖ·¡£NULLÖµ±íʾÓɺ¯Êý×ÔÐÐÔÚij¸ö×î·½±ãµÄλÖñ£ÁôµØÖ··¶Î§£¬·ÇNULLÖµÖ¸¶¨ÁËÒ»¸ö׼ȷµÄ³õʼµØÖ·¡£Èç¹ûº¯Êý·µ»ØNULL£¬±íʾִÐÐʧ°Ü£¬·ñÔò·µ»ØÒ»¸öÖ¸Õ룬ָÏò±»±£ÁôµØÖ··¶Î§µÄ¿ªÊ¼Î»Öá£

dwSize²ÎÊý±íʾº¯ÊýÓ¦¸Ã·ÖÅäµÄµØÖ··¶Î§´óС£¬Ëü¿ÉÒÔÊÇ0¡¡B¡«2¡¡GBµÄÈÎÒâÖµ£¬µ«ÏµÍ³»á×Ô¶¯°ÑËü½øλµ½Ò»¸öÒ³ÃæµÄÕûÊý±¶´óС¡£ÁíÍ⣬ËäÈ»²ÎÊýµÄ×î´óÖµ¿ÉÒÔÖ¸¶¨Îª2¡¡GB£¬µ«Êµ¼ÊÉÏÄܹ»±»±£ÁôµÄ×î´óÖµÊǸýø³ÌÖÐ×î´óµÄÁ¬Ðø×ÔÓɵØÖ·¿Õ¼ä¡£

flAllocationType²ÎÊýÓÃÀ´¾ö¶¨ÈçºÎ·ÖÅäµØÖ·£¬Ëü¿ÉÒÔÊÇÒÔÏÂÈ¡ÖµµÄ×éºÏ£º

¡ñ¡¡¡¡¡¡MEM_MIT¡ª¡ªÎªÖ¸¶¨µØÖ·¿Õ¼äÌá½»ÎïÀíÄÚ´æ¡£

¡ñ¡¡¡¡¡¡MEM_RESERVE¡ª¡ª±£ÁôÖ¸¶¨µØÖ·¿Õ¼ä£¬²»·ÖÅäÎïÀíÄÚ´æ¡£

¡ñ¡¡¡¡¡¡MEM_TOP_DOWN¡ª¡ª¾¡¿ÉÄÜʹÓø߶˵ĵØÖ·¿Õ¼ä¡£

flProtect²ÎÊýÓÃÀ´Ö¸¶¨±£»¤µÄÀàÐÍ£¬Ëü¿ÉÒÔÊÇÒÔÏÂÈ¡ÖµÖ®Ò»£º

¡ñ¡¡¡¡¡¡PAGE_READONLY¡ª¡ªÎªÒÑÌá½»ÎïÀíÄÚ´æµÄµØÖ·¿Õ¼äÉ趨ֻ¶ÁÊôÐÔ¡£

¡ñ¡¡¡¡¡¡PAGE_READWRITE¡ª¡ªÎªÒÑÌá½»ÎïÀíÄÚ´æµÄµØÖ·¿Õ¼äÉ趨¿É¶ÁдÊôÐÔ¡£

¡ñ¡¡¡¡¡¡PAGE_EXECUTE¡ª¡ªÎªÒÑÌá½»ÎïÀíÄÚ´æµÄµØÖ·¿Õ¼äÉ趨¿ÉÖ´ÐÐÊôÐÔ¡£

¡ñ¡¡¡¡¡¡PAGE_EXECUTE_READ¡ª¡ªÎªÒÑÌá½»ÎïÀíÄÚ´æµÄµØÖ·¿Õ¼äÉ趨¿É¶ÁºÍ¿ÉÖ´ÐÐÊôÐÔ¡£

¡ñ¡¡¡¡¡¡PAGE_EXECUTE_READWRITE¡ª¡ªÎªÒÑÌá½»ÎïÀíÄÚ´æµÄµØÖ·¿Õ¼äÉ趨¿É¶Á¡¢¿ÉдºÍ¿ÉÖ´ÐÐÊôÐÔ¡£

¡ñ¡¡¡¡¡¡PAGE_NOACCESS¡ª¡ª½«±£ÁôµÄµØÖ·¿Õ¼äÉ趨Ϊ²»¿É´æȡģʽ¡£

VirtualFreeº¯ÊýµÄʹÓÃÓï·¨ÊÇ£º



¡¡
À´Ô´£ºµç×Ó¹¤Òµ³ö°æÉç¡¡×÷ÕߣºÂÞÔƱò¡¡ÉÏÒ»Ò³¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡»ØÊéÄ¿¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ÏÂÒ»Ò³¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
ÉÏÒ»Ò³¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡»ØÊéÄ¿¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ÏÂÒ»Ò³¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
¡¡¡¡


µÚ10Õ¡¡ÄÚ´æ¹ÜÀíºÍÎļþ²Ù×÷
·µ»ØĿ¼ ÉÏÒ»Ò³ ÏÂÒ»Ò³ »Øµ½¶¥²¿ ÔÞ£¨7£© ²È£¨6£©
δÔĶÁÍꣿ¼ÓÈëÊéÇ©ÒѱãÏ´μÌÐøÔĶÁ£¡
ÎÂÜ°Ìáʾ£º ο´Ð¡ËµµÄͬʱ·¢±íÆÀÂÛ£¬Ëµ³ö×Ô¼ºµÄ¿´·¨ºÍÆäËüС»ï°éÃÇ·ÖÏíÒ²²»´íŶ£¡·¢±íÊéÆÀ»¹¿ÉÒÔ»ñµÃ»ý·ÖºÍ¾­Ñé½±Àø£¬ÈÏÕæдԭ´´ÊéÆÀ ±»²ÉÄÉΪ¾«ÆÀ¿ÉÒÔ»ñµÃ´óÁ¿½ð±Ò¡¢»ý·ÖºÍ¾­Ñé½±ÀøŶ£¡