²Ä¤G¤Q¤­³¹¡@¸U°ê½X¡]¤G¡^

³o¤@³¹¤p¤ì°¸¥´ºâ½s¼g¤@­ÓÀ³¥Îµ{¦¡¡AA2U.ASM¡A¥¦¯à°÷§â¤¤¤å¦r¡B­^¤å¦r¥À¡Bªü©Ô§B¼Æ¦r©Î²Å¸¹Âà´«¦¨¥H UCS¡Ð2 ½s½Xªí¥Ü¡CA2U ¬O¤@ºØ¤u¨ãµ{¦¡¡A¥i¥H¥Î¨Ó¼¶¼g¥H²Õ¦X»y¨¥¬°¶}µo¤u¨ã¡A¦Ó¥B¨ä¦r¦ê¬°¸U°ê½X½s½XªºÀ³¥Îµ{¦¡¡C¨Ò¦p¡A­n¦bÀ³¥Îµ{¦¡¤¤©w¸q¤@¦r¦ê¡u¤¤µØ¥Á°ê¡v¡A°õ¦æ A2U «á¥Í¦¨¤U¹Ï¥ªÃ䪺¹ï¸Ü²° ¦b¤W­±ªº¿é¤J¦r¦ê½s¿è®Ø¿é¤J¤å¦r«á¡A«ö¤U¡uÂà´«¡v«ö¶s«á¡A´N·|¦b©³¤Uªº¿é¥X¦r¦ê½s¿è®Ø¤º¥X²{Âà´««áªºµ²ªG¡A¥¦­Ì´N¬O¹ïÀ³¡u¤¤µØ¥Á°ê¡v¥|¦rªº UCS¡Ð2 ½s½X¡A¨£¤W¹Ï¥kÃä¹ï¸Ü²°¡CµM«á¥i¥H«ö¤U¡u½Æ»s¡v«ö¶s±Nµ²ªG½Æ»s¨ì°Å¶Kï¡AµM«á´N¥i¥H¦bÀ³¥Îµ{¦¡ªº­ì©l½X¤¤¶K¤W³o¤@¦ê¤Q¤»¶i¦ì¼Æ¡A¬Æ¦Ü«á­±ÁÙ¦³µù¸Ñ»¡©ú³o¦ê¤Q¤»¶i¦ì¼Æ¬O¤°»ò¡C¬O¤£¬O«Ü¤è«K¡H


­ì²z

©I¥s ANSI »P¼e¦r¤¸ª©¥»ªº Win64 API

A2U ªº­ì²z¨ä¹ê«Ü²³æ¡A¨Ã¨S¦³·Q¹³¤¤ªº§xÃø¡C«e­±´£¹L¡A¦³Ãö³B²z¤å¦rªº Win64 API ³£¦³¨â­Óª©¥»¡AANSI ª©¥»»P¼e¦r¤¸ª©¥»¡C¤@¯ë¦Ó¨¥¡A¦pªGÀ³¥Îµ{¦¡¤ä´©¸U°ê½X¡A¨º»ò³£À³¸Ó©I¥s¼e¦r¤¸ª©ªº Win64 API¡A§_«h©I¥s ANSI ª©ªº¡C¦ý³o¨Ã«DÅK«ß¡A¨Æ¹ê¤W­n©I¥s­þ¤@ºØª©¥»ªº Win64 API¡A¨ä¹êÀ³¥Îµ{¦¡¥i¥H¦Û¦æ¨M©w¡C¬Æ¦Ü¥i¥H¦b¤@À³¥Îµ{¦¡©Ò©I¥sªº Win64 API¡A¦³¨Ç¬O ANSI ª©¡A¦³¨Ç¬O¼e¦r¤¸ª©¡C

°²¦p¦b­ì©lµ{¦¡¤¤¤@¶}©l¡A¨S¦³«Å§i

UNICODE EQU 1

¨º»ò©I¥s³B²z¤å¦rªº Win64 API ³£¬O ANSI ª©¡A¦pªG­n©I¥s¼e¦r¤¸ª©¡A¥i¥H¦Û¦æ©ó API ¨ç¦¡¦WºÙ¤§«á¦Û¦æ¥[¤J¡uW¡v§Y¥i¡C

A2U ´NÄÝ©ó³oºØ±¡§Î¡C¨Ï¥ÎªÌ©ó¿é¤J¦r¦ê½s¿è®Ø¤º¿é¤J¤å¦r¡A¥i¥H¸g¥Ñ GetWindowTextW »P GetWindowTextA ¨ú±o¿é¤J¤å¦r¡A«eªÌ¬O UCS¡Ð2 ½s½X¡A«áªÌ¬O ANSI ½s½X¡C³oùØ¥²¶·ª½±µ«ü©w©I¥sªº¨ç¦¡¦WºÙ¡A³o¦WºÙµ²§Àªº¡uW¡v¤£¯à¬Ù²¤¡A¡uA¡v«o¥i¥H¬Ù²¤¡C³o¬O¦]¬°¨S«Å§i¡uUNICODE EQU 1¡v¡A©Ò¥H GetWindowText µ¥©ó GetWindowTextA¡C

¥H¤W­±¬°¨Ò¡A¦pªG¨Ï¥ÎªÌ¿é¤J¡u¤¤µØ¥Á°ê¡v¦r¦ê¡A¨º»ò A2U ±N¨äÅܦ¨¡u DW 4e2dh,83efh,6c11h,570bh,0 ;¤¤µØ¥Á°ê¡v¡C¦b¡u DW ¡v»P¡u;¤¤µØ¥Á°ê¡v¤§¶¡ªº¤@³s¦ê¤Q¤»¶i¦ì¼Æ­È¦r¦ê¡A¬O¸g¥Ñ GetWindowTextW ¨ú±oªº¸U°ê½X¦r¤¸­pºâ±o¨ìªº¡F¨ä«áªº¡u;¤¤µØ¥Á°ê¡v«h¬O¸g¥Ñ GetWindowTextA ¨ú±oªº ANSI ¦r¤¸±o¨ìªº¡C

¥Ñ GetWindowTextW »P GetWindowTextA ¨ú±oªº¸ê®Æ­n©ñ¦b­þ¨à©O¡HA2U ¥i¥H¦b .DATA °Ï¬qùطdzƤ@¶ô°O¾ÐÅéªÅ¶¡¡A¨Ñ¥¦­Ì¨Ï¥Î¡C¦ý³oºØ¤èªk¤£¤Ó¦n¡A¦]¬°¼¶¼g­ì©lµ{¦¡®É¡A¨Ã¤£ª¾¹D¨Ï¥ÎªÌ¿é¤J¦h¤Ö¤å¦r¡CA2U ±Ä¥Î¥t¤@ºØ¤èªk¡A¦V§@·~¨t²Î¥Ó½Ð°t¸m°O¾ÐÅé¨Ó¦s©ñ¥¦­Ì¡C

¦³Ãö¦V Windows ´£¥X°t¸m°O¾ÐÅ骺¤è¦¡¡A´£¨Ñ¤F¦n´XºØ¤è¦¡¡A¥i¥Hªá¶O³\¦h½g´T¸Ô²Ó´y­z¡C¤£¹L³o­Óºô­¶¥u¬O¤Jªù¡A©Ò¥H¤]¥u¬O²²¤´y­z¨âºØ°O¾ÐÅéºÞ²z¤è¦¡¡G①¥þ°ì°O¾ÐÅé¡B②°ï¿n¡C

GlobalAlloc API

¦V Windows ¥Ó½Ð°t¸m°O¾ÐÅé¡A¦­¦b Windows 3.1 ®É¥N´N¦³¡A¨º®É­Ô°O¾ÐÅ馳¨âºØÃþ«¬¡A¥þ°ì¡]global¡^»P§½³¡¡]local¡^ªº¡A«eªÌ©Ò±o¨ìªº°O¾ÐÅé¦b¥t¤@°Ï¬q¡A«áªÌ¦b¦P¤@°Ï¬q¡C¨ì¤F Windows 95 ¥H¤Î¨ä«áªºª©¥»¡A¨C­ÓÀ³¥Îµ{¦¡³£¦³¦Û¤v¿W¥ßªº 4GB °O¾ÐÅé¡A¤£¦A°Ï¤À¥þ°ì»P§½³¡¡CÀ³¥Îµ{¦¡¦V Windows ­n¨D°t¸m°O¾ÐÅé¡A³q±`¬O©I¥s GlobalAlloc¡AÁöµM¦b Win64 API ¤¤ÁÙ¬O¦³ LocalAlloc¡AÀ³¥Îµ{¦¡¤´µM¥i¥H©I¥s¥¦¡F¤£¹L LocalAlloc ¤º«o¬O©I¥s GlobalAlloc ¨Ó°t¸m°O¾Ð¡C©³¤U¶È»¡©ú GlobalAlloc¡C

GlobalAlloc ¥Î©ó°t¸m¥þ°ì°O¾ÐÅé¡A³oùØÁöµM¥Î¡u¥þ°ì¡v¤G¦r¡A¦ý¨ä¹ê´N¬O°t¸m¤@¶ô°O¾ÐÅé¡A¡u¥þ°ì¡v¤G¦r¬O¨S¤°»ò·N¸qªº¡CGlobalAlloc ªº­ì«¬¬O¡G

invoke  GlobalAlloc,\
        uFlags,\        ; object allocation attributes
        dwBytes         ; number of bytes to allocate

uFlags ¬O«ü©w°t¸m°O¾ÐÅ骺ÄÝ©Ê¡A¥i¥H¦³¤U­±´XºØ±¡§Î¡G

uFlags¼Æ­È»¡©ú
GMEM_FIXED0¤À°t©T©w°O¾ÐÅé°Ï¶ô¡C¤À°tªº°O¾ÐÅé°Ï¶ô¤£·|²¾°Ê¡AGlobalAlloc ªð¦^®É¡A¦^¶Ç­È´N¬O©Ò¤À°tªº°O¾ÐÅé°Ï¶ôªº°_©l¦ì§}¡C
GMEM_MOVEABLE2¤À°t¥i²¾°Ê°O¾ÐÅé°Ï¶ô¡C¥²¶·¨Ï¥Î GlobalAlloc ªº¦^¶Ç­È§@¬° GlobalLock ªº°Ñ¼Æ¶i¦æÂê©w¡A¤~¯àÀò¨ú°O¾ÐÅé°Ï¶ôªº°_©l¦ì§}¡C
GMEM_ZEROINIT40h±N¤À°tªº°O¾ÐÅé°Ï¶ô¤º©Ò¦³¦ì¤¸²Õ³£³]¬°¹s¡C
GHND42h¬Û·í©ó GMEM_MOVEABLE »P GMEM_ZEROINIT¡C
GPTR40h¬Û·í©ó GMEM_FIXED »P GMEM_ZEROINIT

¦pªG GlobalAlloc °õ¦æ¥¢±Ñ¡A¦^¶Ç­È¬O 0¡A¥i©I¥s GetLastError ¨ú±o¿ù»~½X¡C¦pªG GlobalAlloc °õ¦æ¦¨¥\¡A¨º»ò¦^¶Ç­È¬O°O¾ÐÅé°Ï¶ô¥N½X¡A¥i¤À¬°¨âºØ±¡§Î¡G

①¡G¦pªG uFlags ¬O GMEM_FIXED ©Î GPTR ªº¸Ü¡A¨º»ò°O¾ÐÅé°Ï¶ô¥N½X´N¬O¦ì§}¡A¦¹¦ì§}´N¬O¨t²Î©Ò¤À°tªº°O¾ÐÅé¦ì§}¡AÀ³¥Îµ{¦¡¥i¥Hª½±µ¨Ï¥Î¡C
②¡G¦pªG uFlags ¬O GMEM_MOVEABLE ©Î GHND ªº¸Ü¡A¨º»ò°O¾ÐÅé°Ï¶ô¥N½X¨Ã¤£¬O¨t²Î©Ò¤À°tªº¦ì§}¡A¥²¶·¥H¦¹°O¾ÐÅé°Ï¶ô¥N½X¬°°Ñ¼Æ©I¥s GlobalLock ¶i¦æÂê©w¡AGlobalLock ªº¦^¶Ç­È¤~¬O°O¾ÐÅé°Ï¶ôªº°_©l¦ì§}¡Cµ¥¦s¨ú§¹¤§«á¡A»Ý©I¥s GlobalUnlock ¸Ñ°£Âê©w¡C³o»ò°µªº­ì¦]¬O¦­´Á°O¾ÐÅé»ù®æ«Ü°ª¡A¹q¸£°t³Æªº°O¾ÐÅ餣¦h¡A§@·~¨t²Î·|±N³\¦h¥¼¨Ï¥Îªº¤p®e¶q°O¾ÐÅé°Ï¶ô¦X¨Ö§Î¦¨¸û¤jªº°O¾ÐÅé°Ï¶ô¡A°t¸mµ¹À³¥Îµ{¦¡¨Ï¥Î¥H¸`¬Ù°O¾ÐÅé¡A¦b³o¹Lµ{¤¤¥²¶·²¾°Ê°O¾ÐÅé°Ï¶ô¡A³o´N¬O¥i²¾°Ê°O¾ÐÅé°Ï¶ôªº°_·½¡C

¤£½×©T©w©Î¥i²¾°Êªº°O¾ÐÅé°Ï¶ô¡A¦b¤£¨Ï¥Î¤§«á³£¥²¶·©I¥s GlobalFree ÄÀ©ñ°O¾ÐÅé°Ï¶ô¡C¦¹¥~¡AGlobalAlloc »P¨ä¥L°O¾ÐÅéºÞ²z¨ç¦¡¡A¨Ò¦p HeapAlloc¡A¤ñ¸û°_¨Ó®Ä²v¸û®t¡A¥B¥\¯à¸û¤Ö¡C©Ò¥H·L³n«Øij¡AÀ³¥Îµ{¦¡À³¸Ó¨Ï¥Î HeapAlloc¡CµM¦Ó¡AGlobalAlloc ¤´µM¾Õªø»P DDE¡B°Å¶Kï¨ç¦¡©M OLE ¸ê®Æª«¥ó¤@°_¨Ï¥Î¡C

GlobalFree API

·íÀ³¥Îµ{¦¡¤w¤£»Ý­n GlobalAlloc ©Î GlobalReAlloc ©Ò°t¸mªº°O¾ÐÅé°Ï¶ô®É¡A©I¥s GlobalFree ÄÀ©ñ³o¶ô°O¾ÐÅéªÅ¶¡¡A¥¦ªº¥Îªk¬O¡G

invoke  GlobalFree,\
        hMem            ; handle to the global memory object

hMem ¬O°O¾ÐÅé°Ï¶ô¥N½X¡A¥¦¬O GlobalAlloc ©Î GlobalReAlloc ªº¦^¶Ç­È¡C¦pªG GlobalFree °õ¦æ¦¨¥\¡A¦^¶Ç­È¬° 0¡F§_«h¦^¶Ç­È´N¬O­ì°Ñ¼Æ¡C

¥t¤@ºØ°O¾ÐÅéºÞ²z¤è¦¡¡G°ï¿n¡]Heap¡^

°ï¿n³o­Ó¦W¦r¨ú±o«Ü©_©Ç¡A¦ý¬O¥i¥H§â¥¦·Q¦¨¬O¤@ºØ°O¾ÐÅé¡C°ï¿n¥i¥H¤À¬°¨âºØ¡G①¹w³]°ï¿n¡]default process heap¡^»P②¨p¦³°ï¿n¡]private heap¡^¡C

·í Windows §@·~¨t²Î°õ¦æÀ³¥Îµ{¦¡®É¡A³£·|¬°¸ÓÀ³¥Îµ{¦¡«Ø¥ß¹w³]°ï¿n¡C¹w³]°ï¿n³q±`¬Oµ¹¨t²Î¨Ï¥Îªº¡A¨Ò¦p¨Ï¥ÎªÌ°õ¦æ ANSI ª©ªºÀ³¥Îµ{¦¡¨Ã¥B¿é¤J¤å¦r®É¡A³o¨Ç¤å¦r¬O ANSI ½s½X¡C¦Ó¦b Windows XP ¥H¤Î¨ä«áªº§@·~¨t²Î®Ö¤ß¬O¥Î¸U°ê½X½s½X¡A³o®É­Ô¨t²Î·|¦Û°Ê§â¿é¤Jªº¤å¦rÂàÅܬ°¸U°ê½X¡C¦bÂà´«¹Lµ{¤¤¡A»Ý­n°O¾ÐÅé®É¥Î¨ìªº´N¬O¹w³]°ï¿n¡C¨º»òÀ³¥Îµ{¦¡¬O§_¥i¥H¨Ï¥Î¹w³]°ï¿n©O¡Hµª®×¬O¥i¥Hªº¡A¦ý³o¼Ë®e©ö³y¦¨²V¶Ã¡C

°ò©ó¤W­z­ì¦]¡A¥H¤Î®Ä²v¡AÀ³¥Îµ{¦¡¤]¥i¥H«Ø¥ß¦Û¤vªº¨p¦³°ï¿n¡Cª`·N¡I¹w³]°ï¿n¬O Windows «Ø¥ßªº¡AÀ³¥Îµ{¦¡¥u¬O±N¥¦®³¨Ó¨Ï¥Î¦Ó¤w¡A©Ò¥H¬O©I¥s GetProcessHeap¡A¥Î Get ¨Ã«D Create¡F¦Ó¨p¦³°ï¿n«o¬O¦Û¦æ«Ø¥ßªº¡A©Ò¥H¬O©I¥s HeapCreate¡A«D Get¡C©³¤U¥ý¤¶²Ð¦p¦ó¦V Windows Àò±o¹w³]°ï¿nªº¥N½X¥H¤Î«Ø¥ß¨p¦³°ï¿n¡C

GetProcessHeap API

¦pªG­n¨Ï¥Î¹w³]°ï¿nªº¸Ü¡A¥²¶·¥ý©I¥s GetProcessHeap¡A¥¦¨S¦³°Ñ¼Æ¡G

invoke  GetProcessHeap

¦pªG¥¢±Ñ¡A¦^¶Ç­È¬O¹s¡A¥i¥H©I¥s GetLastError ±o¨ì¿ù»~¥N½X¡F¦pªG©I¥s¦¨¥\¡A¦^¶Ç­È¬O¸ÓÀ³¥Îµ{¦¡ªº¹w³]°ï¿n¥N½X¡C±o¨ì¦¹°ï¿n¥N½X«áÁÙ¥²¶·¦V Windows ¥Ó½Ð¡A¦b¦¹°ï¿n¤º¤À°t°O¾ÐÅé°Ï¶ô¡A¤~¯à¯u¥¿¨Ï¥Î°O¾ÐÅé¡A©I¥s HeapAlloc ¥i¥H¹F¦¨¦¹¥Ø¼Ð¡C

HeapCreate API

HeapCreate ¥Î©ó«Ø¥ß¨p¦³°ï¿n¡A¥¦ªº­ì«¬¬O¡G

invoke  HeapCreate,\
        flOptions,\     ; heap allocation flag
        dwInitialSize,\ ; initial heap size
        dwMaximumSize   ; maximum heap size

¦pªG HeapCreate °õ¦æ¥¢±Ñ¦^¶Ç­È¬O 0¡F¦pªG HeapCreate °õ¦æ¦¨¥\¦^¶Ç­È¬O¨p¦³°ï¿n¥N½X¡AÁÙ¶·¦V Windows ¥Ó½Ð¡A¦b¦¹°ï¿n¤º¤À°t°O¾ÐÅé°Ï¶ô¡A¤~¯à¯u¥¿¨Ï¥Î°O¾ÐÅé¡A¦P¼Ë¬O©I¥s HeapAlloc ¹F¦¨¦¹¥Ø¼Ð¡CHeapCreate ªº¤T­Ó°Ñ¼Æ·N¸q¦p¤U¡G

①¡BflOptions¡G¥Î¨Ó«ü¥Ü©Ò«Ø¥ßªº°ï¿n©Ê½è¡A¥i¥H¬O¤U­±ªº±¡§Î¡G
flOptions¼Æ­È»¡©ú
HEAP_NO_SERIALIZE1¦b¥u¦³¤@­Ó°õ¦æºü©Î¦h­Ó°õ¦æºü¦ý¥u¦³¤@­Ó°õ¦æºü©I¥s¸Ó¯S©w°ï¿n¨ç¼Æ®É¡A¨Ï¥Î HEAP_NO_SERIALIZE ¥i¼W¥[®Ä²v¡C
HEAP_GENERATE_EXCEPTIONS4·í¦b°ï¿n¤º¤À°t°O¾ÐÅé°Ï¶ôµo¥Í¿ù»~®É¡A²£¥Í¨Ò¥~¡]exception¡^¦Ó«D¶Ç¦^¹s¡C¨£µy«áªº HeapAlloc¡C
HEAP_CREATE_ENABLE_EXECUTE40000h¦b¹w³]ªº±¡§Î¤U¡A©Ò«Ø¥ßªº°ï¿n¤£½×¨ä¤º®e¬°¦ó¡A³£¬O¤£¥i°õ¦æªº¡A³o¬O¬°¤F¼W±j¨t²Îªº¦w¥þ©Ê¡C¦ý¦pªG«ü©w¤F HEAP_CREATE_ENABLE_EXECUTE¡A«h¥i¥H°õ¦æ¨ä¤ºªº¾÷±ñ½X¡C
00¦pªG³£¤£»Ý­n¤W­±¤TºØ±¡§Î¡A¥i¥H³]¬° 0¡C
②¡BdwInitialSize¡G°ï¿nªºªì©l¤j¤p¡A¤]´N¬O°ï¿n¤@¶}©lªº¤j¤p¡A¥H¦ì¤¸²Õ¬°³æ¦ì¡C¦ý¬O¨t²Î·|¹ï¦¹¤j¤p¶i¦æ½Õ¾ã¡A½Õ¾ã¤è¦¡¬O±N¦¹¤j¤pµL±ø¥ó¶i¤J¨Ï¨ä¦h¤@­Ó¤À­¶¡C³q±`¨Ó»¡¡A°O¾ÐÅé¤@­Ó¤À­¶¤j¤p¬O 1000h¡A¤]´N¬O 4096 ­Ó¦ì¤¸²Õ¡C¨Ò¦p§â dwInitialSize ³]¬° 1100h¡A³o¼Ëªº¸Ü¶W¹L¤@­Ó¤À­¶¦ý¤£¨ì¨â­Ó¤À­¶¡A©Ò¥H¨t²Î·|§â dwInitialSize Åܬ° 2000h¡F¦P²z¡A¦pªG dwInitialSize ³]¬° 2FFFh¡A¨t²Î·|½Õ¾ã¬° 3000h¡F¦ý¦pªG dwInitialSize ¤p©ó 1000h¡A¨t²Î³£·|§â dwInitialSize Åܬ° 2000h¡C
③¡BdwMaximumSize¡G°ï¿n¤j¤pªº¤W­­¡A³æ¦ì¬O¦ì¤¸²Õ¡C¨t²Î¤]·|¹ï¦¹¤W­­½Õ¾ã¡A¨Ï¨äµL±ø¥ó¶i¤J¡A¤èªk¸ò dwInitialSize ¬Û¦P¡C­è¶}©l«Ø¥ß°ï¿n®É¡A°ï¿nªº¤j¤p¤j¬ù¬O dwInitialSize¡F¦ý¬O¦b°ï¿n¤º¦h¦¸¤À°t°O¾ÐÅé°Ï¶ô¤§«á¡A¦pªG°O¾ÐÅé°Ï¶ôÁ`¤j¤p¶W¹L dwInitialSize ®É¡A¨t²Î·|¦Û°ÊÂX¤j°ï¿n¡A¦ý³Ì¤j¤£¯à¶W¹L dwMaximumSize¡AºÙ¬°¡u¤£¥i¦¨ªø¡vªº°ï¿n¡C¦pªG dwMaximumSize ¬°¹s¡A³o¼Ëªº¸Ü°ï¿nªº¤W­­¶È¨ü¥i¥Î°O¾ÐÅ骺­­¨î¡AºÙ¬°¡u¥i¦¨ªø¡vªº°ï¿n¡C

¦³Ãö HEAP_NO_SERIALIZE ªº´y­z¡Aµy«á¦b HeapAlloc ·|¦A¤@°_»¡©ú¡C

HeapAlloc API

HeapAlloc ¥Î©ó¦V¨t²Î¥Ó½Ð¤À°t¦ì©ó°ï¿n¤ºªº°O¾ÐÅé°Ï¶ô¡A¨t²Î·|±q°ï¿n¤¤¤À°t¤@¶ô°O¾ÐÅé°Ï¶ôµ¹À³¥Îµ{¦¡¨Ï¥Î¡CHeapAlloc ªº­ì«¬¬O¡G

invoke  HeapAlloc,\
        hHeap,\         ; handle to the private heap block
        dwFlags,\       ; heap allocation control flags
        dwBytes         ; number of bytes to allocate
①hHeap¡GhHeap ¬O°ï¿n¥N½X¡A¥u¯à¬O GetProcessHeap ©Î HeapCreate ªº¦^¶Ç­È¡C
②dwFlags¡G¥Î¨Ó«ü¥Ü©Ò¤À°tªº°O¾ÐÅé°Ï¶ô©Ê½è¡A¥i¥H¬O¤U­±ªº±¡§Î¡G
dwFlags¼Æ­È»¡©ú
HEAP_NO_SERIALIZE1¦pªG©I¥s HeapCreate ®É¤w«ü©w HEAP_NO_SERIALIZE¡A©I¥s HeapAlloc ®É´N¤£»Ý¦A«ü©w¦¹¿ï¶µ¡A¦]¬°¤À°t¨ìªº°O¾ÐÅé°Ï¶ô·|©µÄò°ï¿nªº©Ê½è¡C
HEAP_GENERATE_EXCEPTIONS4¦pªG©I¥s HeapCreate ®É¤w«ü©w HEAP_GENERATE_EXCEPTIONS¡A©I¥s HeapAlloc ®É´N¤£»Ý¦A«ü©w¦¹¿ï¶µ¡A¦]¬°¤À°t¨ìªº°O¾ÐÅé°Ï¶ô·|©µÄò°ï¿nªº©Ê½è¡C
HEAP_ZERO_MEMORY8§â¤À°t¨ìªº°O¾ÐÅé°Ï¶ô¤º®e³]¬°¹s¡C
00¦pªG³£¤£»Ý­n¤W­±¤TºØ±¡§Î¡A´N¥i¥H§â dwFlags ³]¬° 0¡C

©I¥s HeapCreate ©Î HeapAlloc ®É¡A¦pªG¤£«ü©w HEAP_NO_SERIALIZE¡A¾Þ§@°ï¿nªº¹w³]±¡ªp¬O§Ç¦C¤Æªº¡]serialization¡^¡A¨º¤°»ò¬O§Ç¦C¤Æ©O¡H

·í©I¥s°ï¿n¨ç¦¡¾Þ§@°ï¿n¡A¨Ò¦p©I¥s HeapAlloc ¤À°t°O¾ÐÅé°Ï¶ô®É¡A·|¥ý¦b°ï¿n¤º´M§ä¬O§_¦³³sÄòªÅ¶¡¨¬¥H¤À°t°O¾ÐÅé¡A¦pªG§äµÛ¤F¤~§â³o¶ôªÅ¶¡¤À°t¥X¨Ó¡AµM«á¦A¼Ð°O³o¶ô°O¾ÐÅé°Ï¶ô¤w¨Ï¥Î¡C¦pªGÀ³¥Îµ{¦¡¦³¦h­Ó°õ¦æºü¡A´N¦³¥i¯à¦b²Ä¤@­Ó°õ¦æºü¤w§ä¨ì¨¬°÷ªº°O¾ÐÅé°Ï¶ô¦ý©|¥¼¼Ð¥Ü¸Ó°O¾ÐÅé°Ï¶ô¤w¨Ï¥Î¡A¥t¤@­Ó°õ¦æºü¤]§ä¨ì¤F¬Û¦Pªº°O¾ÐÅé°Ï¶ô¡C©ó¬O³y¦¨¨â­Ó°õ¦æºü¦s¨ú¬Û¦Pªº°O¾ÐÅé¦Ó¬Û¤¬¤zÂZ¡Aµo¥Í³oºØ±¡§Î´N·|²£¥Í¿ù»~¡AºÙ¬°°O¾ÐÅé·lÃa¡]heap corruption¡^¡C

¬°¤F¹w¨¾³oºØ¿ù»~¡A¾Þ§@°ï¿n®É¨t²Î·|¦Û°Ê±N³o¨Ç¾Þ§@±Æ¥X¶¶§Ç¡A¨C¦¸¥u¦³¤@­Ó°õ¦æºü¯à¾Þ§@°ï¿n¡Aµ¥¸Ó°õ¦æºü¾Þ§@§¹²¦«á¡A¦A´«¤U¤@­Ó¡C³oºØ±¡§ÎºÙ¬°§Ç¦C¤Æ¡C·íµM³oºØ±¡§Î·|³y¦¨®Ä²v¤U­°¡C¦pªGÀ³¥Îµ{¦¡¥u¦³¤@­Ó°õ¦æºü¡A´N¤£»Ý¾á¤ß³oºØ°ÝÃD¡A¥i¥H«ü©w HEAP_NO_SERIALIZE ¼W¥[³t²v¡C
③dwBytes¡G­n¤À°tªº°O¾ÐÅé°Ï¶ô¦ì¤¸²Õ­Ó¼Æ¡C¦pªG°ï¿n¬O¡u¤£¥i¦¨ªø¡vªº¡AdwBytes ¥²¶·¤p©ó 7FFF8h¡C

¦pªG HeapAlloc °õ¦æ¦¨¥\¡A¦^¶Ç­È¬O¤À°t¨ìªº°O¾ÐÅé°Ï¶ô°_©l¦ì§}¡AÀ³¥Îµ{¦¡¥i§Q¥Î¦¹¦ì§}¦s¨ú¸Ó°O¾ÐÅé°Ï¶ô¡A¤]¯à¥H¦¹¦ì§}¬°°Ñ¼Æ©I¥s HeapFree ÄÀ©ñ°O¾ÐÅé°Ï¶ô¡C¦pªG HeapAlloc °õ¦æ¥¢±Ñ¡A¥B¨S¦³«ü©w HEAP_GENERATE_EXCEPTIONS¡A¦^¶Ç­È¬O¹s¡F¦pªG¦³«ü©w HEAP_GENERATE_EXCEPTIONS¡A¥i¯à·|²£¥Í¤Uªí¤¤ªº¤@­Ó¨Ò¥~ª¬ªp¡A¦p»Ý¸Ô²Ó¸ê°T¡A½Ð°Ñ¾\ GetExceptionCode¡C

¨Ò¥~ª¬ªp»¡©ú
STATUS_NO_MEMORY¦]¬°¯Ê¤Ö¥i¥Îªº°O¾ÐÅé©Î°ï¿n·l·´¡C
STATUS_ACCESS_VIOLATION¦]¬°°ï¿n·l·´©Î¨ç¦¡°Ñ¼Æ¤£¥¿½T¡C

HeapFree API

ÄÀ©ñ HeapAlloc ©Î HeapReAlloc ©Ò°t¸mªº°O¾ÐÅé°Ï¶ô¡A­ì«¬¬O¡G

invoke  HeapFree,\
        hHeap,\         ; handle to the heap
        dwFlags,\       ; heap freeing flags
        lpMem           ; pointer to the memory to free

hHeap ¬O°ï¿n¥N½X¡A«ü¥X­nÄÀ©ñªº°O¾ÐÅé°Ï¶ô¦ì©ó­þ¤@­Ó°ï¿n¤º¡A¥¦¬O HeapCreate ©Î GetProcessHeap ªº¦^¶Ç­È¡CdwFlags ªº·N¸q»P HeapCreate ªº flOptions °Ñ¼Æ¬Û¦P¡A½Ð¦Û¦æ°Ñ¾\¡ClpMem ­nÄÀ©ñªº°O¾ÐÅé°Ï¶ô¦ì§}¡A¥¦¬O HeapAlloc ©Î HeapReAlloc ªº¦^¶Ç­È¡C¦pªG HeapFree °õ¦æ¦¨¥\¡A«h¦^¶Ç­È¬°«D¹s¡F¦pªG°õ¦æ¥¢±Ñ¡A¦^¶Ç­È¬°¹s¡A©I¥s GetLastError ¥H¨ú±o§ó¦h¸ê°T¡C

¤@¥¹©I¥s HeapFree ¦¨¥\¤§«á¡A³QÄÀ©ñªº°O¾ÐÅé°Ï¶ô¤º®e¦³¥i¯à¤w³Q­×§ï¡A©Ò¥H¤£À³¸Ó¦A¥h¦s¨ú¥¦¡C¦pªG¹ï¬Û¦Pªº lpMem ©I¥s¨â¦¸ HeapFree ¥i¯à·|³y¦¨°ï¿n·´·l¡A­nÂÔ·V¡C

HeapDestroy API

¹ï©óÀ³¥Îµ{¦¡¤w¤£¦A»Ý­nªº¨p¦³°ï¿n¡AÀ³¸Ó©I¥s HeapDestroy ºR·´±¼¡A¥H¸`¬Ù¨t²Î¸ê·½¡CHeapDestroy ªº­ì«¬¬O¡G

invoke  HeapDestroy,\
        hHeap           ; handle to the heap

hHeap ¬O­nºR·´ªº°ï¿n¥N½X¡CHeapDestroy ¥u¯àºR·´¨p¦³°ï¿n¡F¹w³]°ï¿n¬OµLªkºR·´¡A°£«Dµ²§ôÀ³¥Îµ{¦¡¡C¦pªG¨p¦³°ï¿n¤º¦³³\¦h©I¥s HeapAlloc ©Î HeapReAlloc ¥Í¦¨ªº°O¾ÐÅé°Ï¶ô¥¼ÄÀ©ñ¡A¤]¥i¥Hª½±µ©I¥s HeapDestroy ¤@¦¸´N¥þ³¡ºR·´¡C


¸Ñ»¡ A2U

A2U.ASM¡BA2U.RC¡BA2U.EXE.MANIFEST ­ì©l½X

A2U ªº¦WºÙ¬O ANSI ¦r¤¸Åܦ¨¸U°ê½X¦r¤¸¡]ANSI to unicode ¤§·N¡^¡A­ì©lµ{¦¡¦p¤U¡G

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
;A2U§â¦ì©ó¿é¤J½s¿è®Ø¤ºªº¦r¦êÅܦ¨¸U°ê½X¡AÅã¥Ü©ó¤U¤èªº¿é¥X½s¿è®Ø¡C¿é¥X½s¿è®Ø
;¤º¬O¸U°ê½X¦r¤¸©Ò¥Nªíªº¤Q¤»¶i¦ì¼Æ­È¡A¨ä«á¬O¤¤¤å¦rµù¸Ñ¡C¨Ò¦p¨Ï¥ÎªÌ¿é¤J¡u³o
;¬O¸U°ê½X¡v¡A¿é¥X½s¿è®ØÅܦ¨(;¤§«áªº¤¤¤åµù¸Ñ¦Û²Ä80­Ó¦ì¤¸²Õ¶}©l)
; DW 9019h,662fh,842ch,570bh,78bch,0       ;³o¬O¸U°ê½X

OPTION  CASEMAP:NONE
OPTION  WIN64:3

IDD_DLG  EQU 1000
IDE_IN   EQU 1001
IDE_OUT  EQU 1002
IDB_CNVT EQU 1003
IDB_COPY EQU 1004
IDB_QUIT EQU 1005
ID_ICON  EQU 1006

INCLUDE      WINDOWS.INC
INCLUDE      COMMCTRL.INC
INCLUDELIB   KERNEL32.LIB
INCLUDELIB   USER32.LIB
INCLUDELIB   COMCTL32.LIB

;*******************************************************************************
.CONST
sDW     DB      "        DW "
szFmtN  DB      "%xh,",0
szFmtZ  DB      "0%xh,",0
;*******************************************************************************
.DATA
hInst   DQ      ?   ;¼Ò²Õ¥N½X
hEdtIn  DQ      ?   ;¿é¤J¦r¦ê½s¿è®Ø¥N½X
hEdtOut DQ      ?   ;¿é¥X¦r¦ê½s¿è®Ø¥N½X
;*******************************************************************************
.CODE
;-------------------------------------------------------------------------------
cnvt    PROC    USES rsi rdi r12 r13 r14 r15
        LOCAL   hHeap:QWORD,pMemA:QWORD,pMemW:QWORD,pMemO:QWORD
        LOCAL   len:DWORD,cbIn:DWORD,cbOut:DWORD,col:DWORD
        LOCAL   buffer[32]:BYTE ;¥Î©ó¼È®É¦s©ñhEdtOut³Ì«á­±ªºµù¸Ñ
;­pºâ©Ò»Ý­n±o°ï¿nªÅ¶¡¡A¬°¿é¤J¦r¦ê½s¿è®Ø¤ºªº¦r¤¸¼Æ­¼¥H4¡A¦A¥[¤W¿é¥X½s¿è®Ø©Ò»ÝªÅ¶¡
        invoke  GetWindowTextLengthW,hEdtIn
        or      eax,eax   ;EAX¡×hEdtIn½s¿è®Ø¤º¦r¦êªº¦r¤¸¼Æ
        jz      exit
        inc     eax       ;EAX¥[¤@¬O¬°¤F¦bµ²§À¥[¤W0
        mov     r8d,eax
        shl     r8d,1     ;R8D¡×»Ý¦h¤Ö¦ì¤¸²Õ¤~¯à®e¯ÇhEdtIn¤ºªº¦r¦ê
        mov     cbIn,r8d  ;pMemA¡BpMemW¦³¦h¤Ö¦ì¤¸²Õ¡A¨âªÌ¬Û¦P
        mov     r10d,11
        sub     rdx,rdx
        div     r10d      ;hEdtOut¨C¦æ¤j¬ù¦³11­Ó¤¤¤å¦r
        inc     eax       ;¤£ºÞ¯à§_¾ã°£¡A³£¼W¥[¤@¦æ
        shl     eax,7     ;hEdtOut¨C¦æ¤j¬ù¤@¦Ê¹s´X­Ó¦ì¤¸²Õ¡A©Ò¥H­¼¥H128¸û§Ö
        mov     cbOut,eax ;pMemO¦³¦h¤Ö¦ì¤¸²Õ
        shl     r8d,1     ;­¼¥H2¬O¦]¬°pMemA¡BpMemWªø«×¤@¼Ë
        add     eax,r8d
        mov     hHeap,RV(HeapCreate,0,eax,0)
;¥Ñ°ï¿n¤¤¤À°t¤T¶ô°O¾ÐÅépMemA¡BpMemW¡BpMemO¡A¤À§O¦s©ñ¿é¤J¦r¦ê½s¿è®Ø¤º®eªºANSI¦r¦ê
;¡B¼e¦r¤¸¦r¦ê¥H¤Î¿é¥X¦r¦ê½s¿è®Øªº¤º®e
        mov     pMemA,RV(HeapAlloc,hHeap,HEAP_ZERO_MEMORY,cbIn)
        mov     r12,rax   ;R12¥Î©ó«ü¦V¿é¤J½s¿è®Ø¥HANSI½s½Xªº¤º®e«ü¼Ð
        mov     pMemW,RV(HeapAlloc,hHeap,HEAP_ZERO_MEMORY,cbIn)
        mov     r13,rax   ;R13¥Î©ó«ü¦V¿é¤J½s¿è®Ø¥H¼e¦r¤¸½s½Xªº¤º®e«ü¼Ð
        mov     pMemO,RV(HeapAlloc,hHeap,HEAP_ZERO_MEMORY,cbOut)
        mov     rdi,pMemO
;Ū¨ú¿é¤J¦r¦ê½s¿è®Øªº¤º®e¨â¦¸¡A¤À§O¥HANSI¦r¦ê¡B¼e¦r¤¸¦r¦ê¦s¤JpMemA¡BpMemW¤º
        mov     r8d,cbIn
        shr     r8d,1
        invoke  GetWindowTextW,hEdtIn,pMemW,r8d
        mov     len,eax
        invoke  GetWindowTextLengthA,hEdtIn
        inc     eax
        invoke  GetWindowTextA,hEdtIn,pMemA,eax
;¶}©l³B²zpMemW¡BpMemAªº¤º®e¡C¨C¦¸¨ú¥XpMemW¤ºªº¤@­Ó¦r¤¸¡A¦¹¬°¼e¦r¤¸¡A¨C¦r¤¸¨â¦ì¤¸²Õ
    ;hEdtOut¤@¦æªº¶}©l³£¬O¡u DW ¡v¡A¨Ã³]R14¬°buffer¦ì§}¡B¨ÏcolÂk¹s
bgn_ln: mov     rcx,SIZEOF sDW
        mov     rsi,OFFSET sDW
        mov     col,ecx
        rep     movsb
        lea     r14,buffer
    ;Ū¨ú¦bpMemW¤ºR13©Ò«ü¦ì§}¤Wªº¦r¤¸¡A¦¹¦r¤¸¬°¸U°ê½X¡AŪ¨ú«á¦s©óR15W¡A©I¥swsprintf
    ;±N¨äÂà´«¬°¤Q¤»¶i¦ì¼Æ­È¦r¦ê¡A¶ñ¤J¡u DW ¡v»Pµù¸Ñ¤§¶¡ªº°Ï°ì¤º
next:   movzx   r15,WORD PTR [r13]
    .if r15w>=0a000h      ;­YR15W¤j©ó©Îµ¥©ó0A000h¡A¥²¶·¦b¤Q¤»¶i¦ì¼Æ­È«e¥[¡u0¡v
        lea     rdx,szFmtZ;§_«h²ÕĶ¾¹·|»~»{¬°¬OÅܼƦWºÙ
    .else
        lea     rdx,szFmtN
    .endif
        invoke  wsprintf,rdi,rdx,r15d
        mov     r10,rax
        add     r10d,col
    ;Àˬd¤Q¤»¶i¦ìªº¼Æ­È¦r¦ê¬O§_¤w¹F²Ä80®æ
        cmp     r10d,80
        ja      end_ln    ;¦pªG¦³¡A¸õ¦Üend_ln
        add     rdi,rax
        add     r13,2
        mov     col,r10d
    ;§â¦bpMemA¤ºR12©Ò«ü¦ì§}¤Wªº¦r¤¸¦s¤Jbuffer¤ºR14©Ò«üªº¦ì§}¤W
        mov     dx,[r12]
    .if r15w<100h
        mov     [r14],dl ;¦pªGR15W<100¡Aªí¥ÜDX¬O­^¤å¦r¥À©Îªü©Ô§B¼Æ¦r¡A¶È»Ý§â¤@­Ó¦ì
        inc     r12      ;¤¸²Õ²¾¦ÜR14©Ò«üªº¦ì§}¤W
        inc     r14
    .else
        mov     [r14],dx ;§_«hDX¬OBig5½s½Xªº¤¤¤å¦r¡AÀ³²¾°Ê¨â­Ó¦ì¤¸²Õ
        add     r12,2
        add     r14,2
    .endif
        dec     len      ;ÀˬdpMemW¤¤ÁÙ¦³¨S¦³¥¼³B²zªº¦r¤¸
        jnz     next     ;­Ylenµ¥©ó0¡Aªí¥Ü©Ò¦³¦bpMemW¤ºªº¦r¤¸³£³B²z§¹¦¨¡A¨º
        mov     ax,2030h ;»ò¥ý¦s¤J¡u 0¡v¡A¦A©ó¤Q¤»¶i¦ì¼Æ­È¤§«á¦Ü²Ä80®æ¤§¶¡¶ñ
        stosw            ;¤JªÅ¥Õ¡A³Ì«á±Nbuffer¤ºªº¸ê®Æ²¾¦ÜEDI©Ò«ü¦ì§}
        add     col,2
    ;©ó¤Q¤»¶i¦ìªº¼Æ­È¦r¦ê¤§«á¦Ü²Ä80®æ¤§¶¡¡A¶ñ¤JªÅ¥Õ
end_ln: mov     rcx,81
        dec     rdi      ;°£¥h¡u,¡v
        sub     ecx,col
        jle     no_blk   ;¦pªGRCXµ¥©ó¹s©Î¤p©ó¹s¡A´N¤£»Ý­n¶ñ¤WªÅ¥Õ
        mov     al," "   ;¥Ñcol¦Ü²Ä80®æ³£­n¶ñ¤WªÅ¥Õ
        rep     stosb
no_blk: mov     al,";"   ;¡u;¡v¬Oµù¸Ñªº¶}©l
        stosb
    ;§âbufferªº¤º®e²¾¦ÜRDI©Ò«ü¦ì§}(bufferªº¤º®e¬Oµù¸Ñ)
        lea     rsi,buffer
        mov     rcx,r14
        sub     rcx,rsi
        rep     movsb
        mov     ax,0a0dh ;´«¦æ¤ÎÂk¦ì¦r¤¸
        stosw
        cmp     len,0    ;­Ylenµ¥©ó0¡Aªí¥Ü¥þ³¡³B²z§¹¦¨
        jnz     bgn_ln
        mov     BYTE PTR [rdi-2],0
        invoke  SetWindowText,hEdtOut,pMemO
        invoke  HeapDestroy,hHeap
exit:   ret
cnvt    ENDP
;-------------------------------------------------------------------------------
DlgProc PROC    hDlg:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
.if uMsg==WM_INITDIALOG
      ;³]©w¹ï¸Ü²°¼ÐÃDÄ檺¹Ï¥Ü
        invoke  SendMessage,hDlg,WM_SETICON,ICON_SMALL,RV(LoadIcon,hInst,ID_ICON)
      ;Àò±o¿é¤J½s¿è®Ø¡B¿é¥X½s¿è®Ø¥N½X
        mov     hEdtIn,RV(GetDlgItem,hDlg,IDE_IN)
        mov     hEdtOut,RV(GetDlgItem,hDlg,IDE_OUT)

.elseif uMsg==WM_COMMAND
        mov     rax,r8  ;R8W¡×ÃѧO½X
        shr     rax,10h ;AX¡×³qª¾½X
  .if ax==BN_CLICKED
    .if r8w==IDB_QUIT
        jmp     quit
    .elseif r8w==IDB_CNVT
        call    cnvt        
    .elseif r8w==IDB_COPY
        invoke  GetWindowTextLength,hEdtOut        ;ÀˬdhEdtOut½s¿è®Ø¤º¬O§_¦³¤å¦r
      .if eax!=0
        invoke  SendMessage,hEdtOut,EM_SETSEL,0,-1 ;¿ï¾ÜhEdtOut½s¿è®Ø©Ò¦³¤å¦r
        invoke  SendMessage,hEdtOut,WM_COPY,0,0    ;½Æ»s¨ì°Å¶K鷺
      .endif
    .endif
  .endif

.elseif uMsg==WM_CLOSE
quit:   invoke  EndDialog,hDlg,0

.else   ;¨ä¥L¥¼³B²zªº°T®§ªð¦^ FALSE
        xor     rax,rax
        ret
 
.endif  ;¤w³B²zªº°T®§¡Aªð¦^ TRUE
        mov     rax,1
        ret
DlgProc ENDP
;-------------------------------------------------------------------------------
main    PROC
        call    InitCommonControls
        mov     hInst,RV(GetModuleHandle,0)
        invoke  DialogBoxParam,hInst,IDD_DLG,0,OFFSET DlgProc,0
        invoke  ExitProcess,0
main    ENDP
;*******************************************************************************
END     main

©³¤U¬O A2U.RC¡G

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "RESOURCE.H"

#define MANIFEST 24
#define IDD_DLG  1000
#define IDE_IN   1001
#define IDE_OUT  1002
#define IDB_CNVT 1003
#define IDB_COPY 1004
#define IDB_QUIT 1005
#define ID_ICON  1006

IDD_DLG  DIALOGEX 340,150,228,104
CAPTION "Big5½XÂà´«¦¨Unicode"
FONT 10,"Courier New",400,0,0
STYLE WS_VISIBLE|WS_OVERLAPPEDWINDOW
BEGIN
  LTEXT    "¿é¤J¦r¦ê¡G",1,3,3,40,10
  EDITTEXT IDE_IN ,45, 3,177,39,ES_AUTOVSCROLL|ES_MULTILINE
  LTEXT    "¿é¥X¦r¦ê¡G",2,3,45,40,10
  EDITTEXT IDE_OUT,45,45,177,39,ES_MULTILINE|ES_AUTOHSCROLL|ES_AUTOVSCROLL|ES_READONLY
  DEFPUSHBUTTON "Âà´«",IDB_CNVT, 69,88,45,12
  PUSHBUTTON    "½Æ»s",IDB_COPY,123,88,45,12
  PUSHBUTTON    "Â÷¶}",IDB_QUIT,177,88,45,12
END

1 MANIFEST "a2u.exe.manifest"

ID_ICON ICON  "unicode.ico"

©³¤U¬O A2U.EXE.MANIFEST¡G

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity
    type="win32"
    name="AtHome.Wanker.A2U"
    version="1.0.0.0"
    processorArchitecture="amd64"
  />
  <dependency>
    <dependentAssembly>
      <assemblyIdentity
        type="win32"
        name="Microsoft.Windows.Common-Controls"
        version="6.0.0.0"
        processorArchitecture="amd64"
        publicKeyToken="6595b64144ccf1df"
        language="*"
      />
    </dependentAssembly>
  </dependency>
</assembly>

§â¤W­z A2U.ASM¡BA2U.RC¡BA2U.EXE.MANIFEST ³£¦s¤J¡uE:\HomePage\SOURCE\Win64\UNICODE¡v¤l¥Ø¿ý¤º¡AµM«á¶}±Ò¡u©R¥O´£¥Ü¦r¤¸¡v¡A¿é¤J¤U­±«ü¥O²ÕĶ»P³sµ²¡G

Microsoft Windows [ª©¥» 10.0.19045.5131]
(c) Microsoft Corporation. µÛ§@Åv©Ò¦³¡A¨Ã«O¯d¤@¤ÁÅv§Q¡C

C:\Users\wanker>set include=c:\uasm\include [Enter]

C:\Users\wanker>set lib=c:\uasm\lib64 [Enter]

C:\Users\wanker>path c:\uasm;c:\uasm\bin64 [Enter]

C:\Users\wanker>e: [Enter]

E:\>cd HomePage\SOURCE\Win64\UNICODE [Enter]

E:\HomePage\SOURCE\Win64\UNICODE>uasm64 -win64 a2u.asm [Enter]
UASM v2.57, Aug 10 2024, Masm-compatible assembler.
Portions Copyright (c) 1992-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.

a2u.asm: 176 lines, 3 passes, 366 ms, 0 warnings, 0 errors

E:\HomePage\SOURCE\Win64\UNICODE>rc a2u.rc [Enter]
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Copyright (C) Microsoft Corporation.  All rights reserved.


E:\HomePage\SOURCE\Win64\UNICODE>link a2u.res a2u.obj [Enter]
Microsoft (R) Incremental Linker Version 14.25.28614.0
Copyright (C) Microsoft Corporation.  All rights reserved.


E:\HomePage\SOURCE\Win64\UNICODE>

¸Ñ»¡ cnvt °Æµ{¦¡

A2U.ASM ³Ì­«­nªº³¡¤À´N¬O cnvt °Æµ{¦¡¡A©Ò¥Hª½±µ¤Á¤J¥DÃD¡A¥ý¸Ñ»¡ cnvt °Æµ{¦¡¡C

¶i¤J cnvt °Æµ{¦¡ªº²Ä¤@±ø«ü¥O¦b²Ä 41 ¦æ¡A¬O©I¥s GetWindowTextLengthW ¨D¥X¿é¤J¦r¦ê½s¿è®Ø¤ºªº¦r¤¸­Ó¼Æ¡C¿é¤J¦r¦ê½s¿è®Øªº¥N½X¬O hEdtIn¡A¦b²Ä 138 ¦æ©I¥s GetDlgItem ¥i¥H±o¨ì¡Cª`·N¡IGetWindowTextLengthW «á¦³­Ó¡uW¡v¡Aªí¥Ü¬O¥H¸U°ê½X½s½X¥h­pºâ¦r¤¸­Ó¼Æ¡C¨Ò¦p°²¦p¨Ï¥ÎªÌ¿é¤J¡u­»¯ó«ÕÄõ¡v¡A¨º»ò¦^¶Ç­È´N¬O 4¡A»Ý­n 8 ­Ó¦ì¤¸²ÕªºªÅ¶¡¤~¯à®e¯Ç hEdtIn ªº¤å¦r¡F°²¦p¿é¤Jªº¬O¡uVanilla Orchid¡v¡A¨º´N¦³ 14 ­Ó¦r¤¸¡A»Ý 28 ­Ó¦ì¤¸²ÕªºªÅ¶¡¡C

±µ¤U¨Ó­n©I¥s HeapCreate «Ø¥ß¨p¦³°ï¿n¡A¦p¦¨¥\«Ø¥ß°ï¿n¥N½X¦s©ó hHeap ¤º¡A³o­Ó¨p¦³°ï¿n¤º»Ý­n®e¯Ç¤T­Ó°O¾ÐÅé°Ï¶ô¡G
¡@¡@①°_©l¦ì§}¬° pMemW ªº°O¾ÐÅé°Ï¶ô¡AÀx¦s hEdtIn ¤ºªº¦r¦ê¡A¦¹¦r¦ê¥H¸U°ê½X½s½X¦Ó¦¨¡C
¡@¡@②°_©l¦ì§}¬° pMemA ªº°O¾ÐÅé°Ï¶ô¡AÀx¦s hEdtIn ¤ºªº¦r¦ê¡A¦¹¦r¦ê¥H ANSI ½s½X¦Ó¦¨¡C
¡@¡@③°_©l¦ì§}¬° pMemO ªº°O¾ÐÅé°Ï¶ô¡AÀx¦s A2U ³B²z hEdtIn ªº³Ì«áµ²ªG¡A¤]¬O¿é¥X½s¿è®Øªº¤º®e¡C
¦]¬° hHeap ­n®e¯Ç³o¤T­Ó°O¾ÐÅé°Ï¶ô¡A©Ò¥H§â¥¦ªºªì©l¤j¤p³]¬°³o¤T­Ó°O¾ÐÅé°Ï¶ô¤j¤p¤§©M¡C¡]¦¹¤j¤p¥H¦ì¤¸²Õ¬°³æ¦ì¡^

¥ý»¡©ú¦p¦ó±o¨ì pMemW °O¾ÐÅé°Ï¶ô»Ý­n¦h¤Ö¦ì¤¸²Õ¡C«e­±´£¹L©I¥s GetWindowTextLengthW §Y¥i±o¨ì¦b hEdtIn ¤ºªº¦r¤¸­Ó¼Æ¡A¦]¬°¬O©I¥s¼e¦r¤¸ª©¥»¡A©Ò¥H©Ò±oªº¦r¤¸¼Æ¬O«ü¥H¸U°ê½X½s½X©Ò±oªº¦r¤¸¼Æ¡A¥i¬O¨Ã¤£¥]§t¹s¡C¬°¤Fªí¥Ü¦r¦êªºµ²§À©Ò¥H A2U §â©I¥s GetWindowTextLengthW ªº¦^¶Ç­È¦A¥[¤@¡A¥HÀx¦s 0¡C¦Ó¨C­Ó¸U°ê½X¦r¤¸¦û¤F¨â­Ó¦ì¤¸²Õ¡A¥²¶·¦A­¼¥H 2 ¤~¬O pMemW ªº¤j¤p¡A³o¬O¥H¦ì¤¸²Õ¬°³æ¦ì¡C­¼¥H 2 ¥i¥H¥Î¦V¥ª²¾¤@­Ó¦ì¤¸¡A¥ç§Y¡uSHL R8D,1¡v¥N´À¡]²Ä 46 ¦æ¡^¡C³Ì«á§âµ²ªG¦s©ó cbIn ÅܼƤº¡C³o¬qµ{¦¡¦b²Ä 42¡ã47 ¦æ¡C

¦b A2U ùز¤Æ¤F³]©w pMemA ªº¤j¤p¡CÁÙ°O±o¶Ü¡H¥Î ANSI ½s½Xªº¦r¤¸¡A­^¤å¦r¥À¦û¤F¤@­Ó¦ì¤¸²Õ¡A¤¤¤å¦r¦û¥Î¤F¨â­Ó¦ì¤¸²Õ¡]³o¨àªº¤¤¤å¦r¬O¬Û®e©ó ANSI ½s½Xªº Big5 ½s½X¡A¨£«e¤@³¹¡^¡A¦Ó pMemA ªº¤j¤p¥i¥H¤ñ¹ê»Ú©Ò»Ý¤j¡A«o¤£¥i¤ñ¸û¤p¡A§_«h´N·|µo¥Í¿ù»~¡C¹ï¤ñ«e­±»¡¸U°ê½X½s½Xªº­^¤å¦r¥À¦û¤F¨â­Ó¦ì¤¸²Õ¡A¤@©w¤ñ¸û¦h¡A©Ò¥Hª½±µ¨Ï pMemA °O¾ÐÅé°Ï¶ô¤j¤p¡]¥H¦ì¤¸²Õ¬°³æ¦ì¡^¡A¤]µ¥©ó cbIn¡C

ÁٳѤU­n­pºâ¥X pMemO ªº¤j¤p¡AÁ|­Ó¨Ò¤l¥i¯à¤ñ¸û¦nÁA¸Ñ¡C°²¦p¦b hEdtIn ¤º¨Ï¥ÎªÌ¿é¤Jªº¦r¦ê¬O¡u°Û¤Eºq¡A§uÂ÷ÄÌ¡A·¡Ãã¼g¦Ë²¡C¡v¡A¨º»ò¦b hEdtOut ªº¦r¦ê¦p¤U¹Ï©Ò¥Ü¡G ³o¤]¬O pMemO ªº¤º®e¡C·íµM¦b pMemO ¤ºªº¦r¤¸¨Ì§Ç±Æ¦n¨Ã¤£·|´«¤U¤@¦C¡AA2U ¥²¶·¦Û¦æ¥[¤W´«¦æ¤ÎÂk¦ì¦r¤¸¡]¹Ï¤G¨Ã¥¼Åã¥Ü³o¨â­Ó¦r¤¸¡^¡A¤~¥i¥H¦b hEdtOut Åã¥Ü¦p¤W¹Ïªº¼Ë¤l¡C¹Ï¤G¤¤ªº¡uDW¡v«e«áªº²HÂŦâ¤è®Ø¥NªíªÅ¥Õ¡F¤¤¶¡¬O¡u°Û¤Eºq¡A§uÂ÷ÄÌ¡A·¡Ãã¼g¦Ë²¡C¡vÂà´«¦¨¤Q¤»¶i¦ì«á§Î¦¨ªº¼Æ­È¡A©h¥BºÙ¬°¤Q¤»¶i¦ì¼Æ­È¦r¦ê¡F³Ì«á­±¬Oµù¸Ñ¡C¥Ñ¹Ï¤G¬Ý¨Ó¡A¤@¦æ³Ì¦h 11 ­Ó¦r¡A¥[¤W¡u DW ¡v¥H¤Î«á­±ªº¤¤¤åµù¸Ñ¡B´«¦æ¤ÎÂk¦ì¦r¤¸¡A¨C¦æ¬ù¤@¦Ê¹s¾l­Ó¦ì¤¸²Õ¡C¹çÄ@¦hºâ¤@¨Ç¤]¤£­nºâ¤Ó¤Ö¦Óµo¥Í¿ù»~¡A©Ò¥H°²³]¨C¤@¦æ¦³ 128 ­Ó¦ì¤¸²Õ¡C²Ä 50 ¦æ¥ý§â hEdtIn ¤ºªº¦r¤¸¼Æ¡]¥]§tµ²§À°O¸¹ªº 0¡^°£¥H 11¡A©Ò±oªº°Ó¥[¤@¡]¾l¤Uªº¦r¤¸¤]­n¦û¤@¦æ¡^¡A´N±o¨ì hEdtOut ·|¦³´X¦æ¡F¦A­¼¥H 128¡]¥i¥H¥Î¦V¥ª²¾ 7 ­Ó¦ì¤¸´À¥N¡^¡A±o¨ìªº´N¬O pMemO ªº¤j¤p¡A¦s©ó cbOut ¤º¡A¥H¦ì¤¸²Õ¬°³æ¦ì¡A¨£²Ä 48¡ã53 ¦æ¡C³Ì«á±o¨ì¨p¦³°ï¿nªºªì©l¤j¤p¡A¬° cbIn¡Ñ2¡ÏcbOut¡A¨£ 54¡ã55 ¦æ¡C

¨p¦³°ï¿n©M°O¾ÐÅé°Ï¶ô¤j¤p³£¤wºâ¥X¡A±µ¤U¨Óªº²Ä 56¡ã64 ¦æ´N¬O«Ø¥ß¨p¦³°ï¿n»P¦b¦¹°ï¿n¤º¤À°t°O¾ÐÅé°Ï¶ô¡Cª`·N¡I¦b²Ä 56 ¦æ¡A©I¥s HeapCreate «Ø¥ß¨p¦³°ï¿n®É¡A§â¥¦³]¬°¡u¥i¦¨ªø¡vªº°ï¿n¡A³o¼Ë¤ñ¸û¦³¼u©Ê¡C

A2U ¥Î R12¡BR13¡BRDI ¤T­Ó¼È¦s¾¹§@¬°«ü¼Ð¡A¤À§O«ü¦V pMemA¡BpMemW¡BpMemO °O¾ÐÅé°Ï¶ô¡C¨C·íŪ¨ú pMemA ¤ºªº¤@­Ó¦r¤¸¡AR12 ·|µø­^¤å¦r¥À©Î¤¤¤å¦r¦Ó¼W¥[¤@©Î¤G¡A«ü¦V¤U¦¸­nŪ¨úªº¦r¤¸¡F¨C¦¸Åª¨ú pMemW ¤ºªº¤@­Ó¦r¤¸¡AR13 ·|ÀH¤§¼W¥[¤G¡F¨C¦¸§â¸ê®Æ¼g¤J pMemO¡ARDI ·|ÀHµÛ¼g¤J¦h¤Ö¦ì¤¸²Õ´N¼W¥[¦h¤Ö¡C

¬°¤°»ò¥Î³o¤T­Ó¼È¦s¾¹§@¬°«ü¼Ð¡A¤£¥t³]¤T­ÓÅܼƧ@¬°«ü¼Ð¡H­ì¦]¦b©ó¥¦­Ì¬O¤£Åܪº¼È¦s¾¹¡A¦b©I¥s Win64 API ¤§«á¡A¨ä­È¤]¤£§ïÅÜ¡A©Ò¥H§Y¨Ï¦b©I¥s wsprintf ¤§«á¡A¤]¯à«O«ù¨ä«ü¼Ð¡C­n¹F¨ì³o­Ó¥Øªº¡A¥i¥H¦b²Ä 36 ¦æ¨Ï¥Î USES ¿ï¶µ¡A¦b¨ä¤§«á©Ò¦C¥X¨Óªº¼È¦s¾¹¡A³£·|¦b cnvt °Æµ{¦¡¤@¶}©l±N¨ä±À¤J°ïÅ|¡A¦Ó¦bµ²§ô cnvt «e¦A¥Ñ°ïÅ|¨ú¦^­ì­È¡C

¦b±µ¤U¥h»¡©ú¤§«e¡A§â pMemA¡BpMemW¡BpMemO ¤T­Ó°O¾ÐÅé°Ï¶ô¾ã²z¦¨¤Uªí¡G

°O¾ÐÅé°Ï¶ô½s½X¤è¦¡¨C¦r¤¸¦û¦h¤Ö¦ì¤¸²Õ«ü¼Ð
pMemAANSI­^¤å¦r¡G¤@­Ó¦ì¤¸²Õ
¤¤¤å¦r¡G¨â­Ó¦ì¤¸²Õ
R12
pMemWUCS¡Ð2¨â­Ó¦ì¤¸²ÕR13
pMemOANSI­^¤å¦r¡G¤@­Ó¦ì¤¸²Õ
¤¤¤å¦r¡G¨â­Ó¦ì¤¸²Õ
RDI

²Ä 65¡ã72 ¦æ¡AŪ¨ú hEdtIn ªº¤º®e¨â¦¸¡A²Ä¤@¦¸¬O§â hEdtIn ¤ºªº¦r¤¸¥H UCS¡Ð2 ªº½s½XŪ¥X¦s©ó pMemW ¤º¡A²Ä¤G¦¸«h¬O¥H ANSI ªº½s½X¤è¦¡Åª¥X¦s¤J pMemA ùØ­±¡C±µ¤U¨Ó¶i¤J cnvt ³Ì­«­nªº³¡¤À¡G¶i¤J°j°é§â pMemA¡BpMemW °O¾ÐÅé°Ï¶ôªº¤º®eÂà´«¦¨¹Ï¤Gªº¼Ë¤l¡A¨Ã¦s¤J pMemO °O¾ÐÅé°Ï¶ô¤º¡Aª½¦Ü len Åܬ°¹s¬°¤î¡]len ¬O pMemW ¤º©Ò§tªº¦r¤¸­Ó¼Æ¡^¡C¨ä¬yµ{¹Ï¦p¥k¡G

³oùØ¥ý»¡©ú col Åܼƪº·N¸q¡C°Ñ¦Ò¹Ï¤Gªº¶À¦â¦r¥iª¾¡A¥¦¬O¥Î¨Ó°O¿ý¬Y¤@¦C¤w¦s¤J´X­Ó¦ì¤¸²Õªº¸ê®Æ¡A¦]¬° hEdtOut ¤ºªº½s½X¬O ANSI¡A©Ò¥H¤]¥Nªí³o¤@¦C¤w¦s¤J´X­Ó¦r¤¸¡C³]¸m col Åܼƪº¥Øªº¬O­n­pºâ¦b¤°»ò®É­Ô­n´«¤U¤@¦C¡C©³¤U»¡©ú cnvt ³Ì­«­nªº³¡¤À¡A°Ñ¦Ò¥k¹Ï①¡ã②¡]A2U.ASM ²Ä 75¡ã78 ¦æ¡^¡A¨C¤@¦C¤@¶}©l¬O§â¡u DW ¡v¦r¦ê¦s¤J pMemO °O¾ÐÅé°Ï¶ô¤º RDI ©Ò«üªº¦ì§}¤W¡A¦Ó¡u DW ¡v¦r¦ê¦³ 11 ­Ó¦r¤¸¡A©Ò¥H¨C¦Cªº¤@¶}©l¡Acol ´Nµ¥©ó 11¡]¤]´N¬O¡uSIZEOF sDW¡v¡A¨ä¤¤ªºªÅ¥Õ¨Ã¨S§¹¥þªí¥Ü¥X¨Ó¡^¡C

³oùØÁÙ³]©w R14 ¬° buffer ªº¦ì§}¡Abuffer ¬O¥Î¨Ó¼È®É¦s©ñµù¸Ñ¡CA2U ¬O¦b¦P¤@¦¸°j°é¤ºÅª¨ú pMemW ¤ºªº UCS¡Ð2 ¦r¤¸¥H¤ÎŪ¨ú¦b pMemA ¤ºªº ANSI ¦r¤¸¡AÁ|­Ó¨Ò¤l»¡©ú¸û©öÁA¸Ñ¡C°²¦p¨Ï¥ÎªÌ¦b hEdtIn ¤¤¿é¤J¡u¤¤µØ¥Á°ê=ROC¡v¡A¨º»ò¦b pMemW »P pMemA ¤¤ªº¤º®e¤À§O¬O¡G²Ä¤@¦¸°õ¦æ°j°é®É¡AA2U ¥ýŪ¨ú UCS¡Ð2 ½s½Xªº¡u¤¤¡v¦r¡A4e2dh¡A±N¨ä´«¦¨¤Q¤»¶i¦ì¼Æ­È¦r¦ê¦s©ó pMemO ¤º RDI ©Ò«ü¦ì§}¡]¹Ï¤T④¡ã⑥¡AA2U.ASM ²Ä 82¡ã88 ¦æ¡^¡AµM«á§â R10D ³]¬° col¡A¦A§â R10D ¥[¤W­è­è¦s¤Jªº¤Q¤»¶i¦ì¼Æ­È¦r¦ê¦³´X­Ó¦ì¤¸²Õ¡AÀˬd R10D ¬O§_¶W¹L 80¡]¹Ï¤T⑦¡ã⑧¡AA2U.ASM ²Ä 89¡ã92 ¦æ¡^¡C¦pªG¨S¦³¡A´N§â RDI¡BR13¡Bcol ³]¬°¥¿½T­È¨ÃŪ¨ú pMemA ¤¤ªº Big5 ½X 0a4a4h¡A±N¨ä¦s¤J buffer ¤¤ R14 ©Ò«üªº¦ì§}¤W¡]¹Ï¤T⑨¡ã⑩¡AA2U.ASM ²Ä 94¡ã107 ¦æ¡^¡C

¦b³o¦¸°j°é°õ¦æ¤¤¡A§â¤Q¤»¶i¦ì¼Æ­È¦r¦ê¦s©ó RDI ©Ò«ü¦ì§}¡A¤]§â Big5 ½X¦s©ó R14 ©Ò«üªº¦ì§}¡C³o¼Ë´N§¹¦¨¤@­Ó¦r¤¸ªº³B²z¡A¨Ï len ´î¤@¡A§Y¹Ï¤G⑪¡ã⑫¡]A2U.ASM ²Ä 108¡ã109 ¦æ¡^¡C¦p¦¹¡A¨C¦¸°j°é³£³B²z¦b pMemW »P pMemA ªº¦r¤¸¦U¤@­Ó¡Aª½¦Ü©Ò¦³¦r¤¸³£³B²z§¹²¦¡Alen ¤]·|´î¦Ü 0¡A³o®É­n§â¦r¤¸¡u"0"¡v¦s¤J¡A§@¬°¦r¦êªºµ²§À¡A¹Ï¤Gªº⑬¡]A2U.ASM ²Ä 110¡ã111 ¦æ¡^¡C

³o®É¤£½× col ¦³¨S¦³¨ì¹F 80¡A³£­n§â³Ì«á¤@¦C¼È®É¦s©ñ©ó buffer ¤ºªº ANSI ¦r¤¸²¾¦Ü RDI ©Ò«ü¦ì§}¡CÁÙ¦³¤@ºØ±¡§Î¡A¤]­n§¹¦¨¦P¼Ëªº¨Æ¡A¨º´N¬O¦pªG col µ¥©ó 80 ©Î¶W¹L 80 ®É¤]­n°µ¦P¼Ëªº¨Æ¡A§Y¥k¹Ï⑮¡AA2U.ASM ²Ä 122¡ã126 ¦æ¡C·íµM¦b³o¤§«e¡A­n¥ÎªÅ¥Õ¶ñ¥R¦Ü²Ä 80 ®æ¡A³o¬qµ{¦¡¦b A2U.ASM ²Ä 113¡ã119 ¦æ¡C

¤W­±¸ÑÄÀ¤F A2U.ASM ³Ì­«­nªº³¡¤À¡A°£¤FÁٳѤ@¤p³¡¤À¥¼¸ÑÄÀ¡A¨S¦b¹Ï¤G¤¤µe¥X¨Ó¡C³o¤@¤p³¡¤À¬O¦b A2U.ASM ªº²Ä 97¡ã107 ¦æ¡A±q pMemA ¤¤ R12 ©Ò«üªº¦ì§}¤¤¨ú¥X¤@¦r¤¸¡A¦s©ó buffer ¤¤ R14 ©Ò«ü¦ì§}¤¤®É¡A³o¤@¦r¤¸¦³¥i¯à¬O¤@­Ó¦ì¤¸²Õ¡A¤]¥i¯à¬O¨â­Ó¦ì¤¸²Õ¡C¨ú¨M©ó³o­Ó¦r¤¸¬O­þ¤@ºØ¤å¦r¡A¦pªG¬O­^¤å¤Îªü©Ô§B¼Æ¦r¡A«h¦r¤¸¦û¤@­Ó¦ì¤¸²Õ¡F¦pªG¬O¤¤¤å¦r¡A«h¦û¨â­Ó¦ì¤¸²Õ¡C¨º»ò­n¦p¦ó§P§O©O¡HA2U.ASM ©Ò±Ä¥Îªº¤èªk¬O¡A¦b¬Û¹ïÀ³ªº pMemW ¤¤ªº¦r¤¸¥i´£¨Ñ½u¯Á¡A¦pªG¬O«eªÌ¡A¨º»ò°ª¦ì¤¸²Õ¬O¹s¡F¦pªG¬O«áªÌ¡A°ª¦ì¤¸²Õ¤£¬O¹s¡C

¦b cnvt ³Ì«á­±¡A´N¬O§â pMemO ªº¤º®e³]¬° hEdtOut ªº¤º®e¡A¥H¤ÎºR·´°ï¿n¡CºR·´°ï¿n«e¡A¤£»Ý­n¤@¤@ÄÀ©ñ°ï¿n¤ºªº¤T­Ó°O¾ÐÅé°Ï¶ô¡C

½Æ»s½s¿è®Ø©Ò¿ï¤º®e¦Ü°Å¶Kï

¨Ï¥ÎªÌ«ö¤U A2U ¹ï¸Ü²°ªº½Æ»s«ö¶s¡A·|§â hEdtOut ¤º®e½Æ»s¨ì°Å¶K鷺¡C³o¬O«ç»ò°µ¨ìªº©O¡H¦b A2U.ASM ²Ä 154¡ã157 ¦æÄÄ©ú³o¥ó¨Æ¡C­º¥ý©I¥s GetWindowTextLength API Àˬd hEdtOut ¤º®eªºªø«×¬O§_¬°¹s¡A¦pªG¬°¹sªí¥Ü hEdtOut ¨S¦³¤º®e¡A¤£»Ý³B²z¡C

GetWindowTextLength API

GetWindowTextLength ¥Î©ó­pºâµøµ¡¼ÐÃDÄ榳¦h¤Ö­Ó¦r¤¸¡A¦]¬°±±¨î¶µ¤]¬Oµøµ¡ªº¤@ºØ¡A©Ò¥H¥¦¤]¥i¥H­pºâ±±¨î¶µ¤ºªº¦r¤¸­Ó¼Æ¡C¥¦ªº­ì«¬¬O¡G

invoke  GetWindowTextLength,\
        hWnd            ; handle of window or control with text

hWnd ¬O­n¨ú±o¦r¤¸­Ó¼Æªºµøµ¡¥N½X©Î±±¨î¶µ¥N½X¡C¦pªG GetWindowTextLength °õ¦æ¦¨¥\¡A¦^¶Ç­È¬O¦r¤¸­Ó¼Æ¡F¦pªG hWnd ¼ÐÃDÄæ¨S¦³¤å¦r¡A¦^¶Ç­È¬O¹s¡C¦b¬Y¨Ç±¡§Î¤U¡A¤×¨ä¬OÂù¦ì¤¸²Õ¦r¤¸¶°¡]DBCS¡^¡A¨ú±oªº¦r¤¸­Ó¼Æ¥i¯à·|¤ñ¹ê»Ú±o¦h¡C

EM_SETSEL °T®§

°²¦p¹ï½s¿è®Øµo¥X EM_SETSEL °T®§ªº¸Ü¡A´N¯à³]©w½s¿è®Ø¤º¿ï¨úªº¤å¦r¡C¤èªk¬O©I¥s SendMessage¡G

invoke  SendMessage,hEdit,EM_SETSEL,wParam,lParam

EM_SETSEL ¨S¦³¦^¶Ç­È¡CwParam ¬°¿ï¨ú¶}©lªº¦r¤¸¦ì¸m¡]³Ì«e­±¬O¦ì¸m¹s¡^¡AlParam ¬°¿ï¨úµ²§ôªº¦r¤¸«á¤@­Ó¦ì¸m¡C¦pªG wParam ¬° 0 ¥B lParam ¬°¡Ð1¡A«h·|¿ï¨ú½s¿è®Ø¤¤ªº©Ò¦³¤å¦r¡C¦pªG wParam ¬°¡Ð1¡A«h·|±N¥Ø«eªº¿ï¨ú½d³ò¨ú®ø¡C¦pªG¶}©lªº¦r¤¸¦ì¸m¤ñµ²§ô¤j¡A¨º»ò¨t²Î·|¦Û°Ê½Õ¾ã¡A¥H¸û¤pªº¬°¶}©l¦ì¸m¡A¸û¤jªº¬°µ²§ô¦ì¸m¡C

¨Ò¦p½s¿è®Øªº¥N½X¬O hEdit¡A¦Ó¨ä¤ºªº¤å¦r¬O¡u¯É­¸¿P¡AÁcªáµº¡Aºì©ñÆA¦p¥P¡C¡v¡AµM«á©I¥s SendMessage¡G

invoke  SendMessage,hEdit,EM_SETSEL,4,9

¨º»ò¿ï¨úªº¤å¦r¬O¡uÁcªáµº¡Aºì¡v¡C³o¬O¦]¬°¡u¯É¡vªº¦ì¸m¬O¹s¡A¡u­¸¡vªº¦ì¸m¬O¤@¡A©Ò¥H¦ì¸m¥|¬O¡uÁc¡v¡F¦Ó¦ì¸m¤E¬O¡u©ñ¡v¡A¦ý³o¬O¿ï¨úµ²§ô¦ì¸mªº«á¤@­Ó¦ì¸m¡A©Ò¥H¦ì¸m¤K¤~¬O¿ï¨ú¦r¤¸ªºµ²§ô¦ì¸m¡A¥¦¬O¡uºì¡v¡C°²¦p¼g¦¨¤U­±µ{¦¡½X¡G

invoke  SendMessage,hEdit,EM_SETSEL,9,4

µ²ªG¤´µM¤@¼Ë¡C

WM_COPY °T®§

À³¥Îµ{¦¡¥i¥Hµo°e WM_COPY °T®§µ¹½s¿è®Ø¡B²³æ«¬½Æ¦X®Ø»P¤U©Ô«¬½Æ¦X®Ø¡A³o¼Ëªº¸Ü·|§â³o¤TºØ±±¨î¶µ¤¤³Q¿ï¨úªº¤å¦r¡A¥H CF_TEXT ®æ¦¡½Æ»s¨ì°Å¶Kï¤W¡C©I¥s®É¡AwParam »P lParam §¡¤£¨Ï¥Î¡AÀ³³]¬°¹s¡C¨Ò¦p½s¿è®Øªº¥N½X¬O hEdit¡A¨º»ò©³¤Uªºµ{¦¡¡G

invoke  SendMessage,hEdit,WM_COPY,0,0

¯à§â hEdit ¤¤¿ï¨úªº¤å¦r½Æ»s¨ì°Å¶K襤¡C


«á¸Ü

¦³¤F A2U ¤§«á¡A­n¥Î²Õ¦X»y¨¥¼¶¼g¸U°ê½XÀ³¥Îµ{¦¡¡A¤£¦A¬OÃø¨Æ¤F¡C