³o¤@³¹ùØ¡A¤p¤ì°¸±N¼¶¼g¤@Óµ{¦¡¡ADRAWTXT.ASM¡A°õ¦æ¦¹µ{¦¡®É·|²£¥Í¤@Óµøµ¡¡A°²¦p¨Ï¥ÎªÌ«ö¤U¤@ÓÁä®É¡A¥¦·|§â¨Ï¥ÎªÌ©Ò«ö¤UÁä©Ò¥Nªíªº ASCII ¦r¤¸Åã¥Ü¦bµøµ¡ùØ¡C¨Ò¦p¡A±z«ö¤U¡yP¡zÁä¡A¨º»ò¥¦·|Åã¥Ü¡G
GDI ¬O Windows ¨t²Î¥Î¨Ó§@¬°À³¥Îµ{¦¡»P¿Ã¹õ¡B¦Lªí¾÷¤§¶¡ªº¬É±¡AºÙ¬°¹Ï§Î¸Ë¸m¬É± ( graphics device interface¡AÁY¼g¬° GDI )¡C³oӬɱ¤@ºÝ³s±µ¿Ã¹õ¡B¦Lªí¾÷µ¥µwÅé©PÃä³]³Æ¡A¥t¤@ºÝ³s±µµÛ§ÚÌ©Ò¼¶¼gªºÀ³¥Îµ{¦¡¡C
ÁöµM¨C¤@®a¼t°Ó©Ò¥Í²£ªº²£«~¤£¦P¡A¨äÅX°Êµ{¦¡¤]¤£¤@¼Ë¡A¤£¹L¨C®a¼t°ÓªºÅX°Êµ{¦¡³£¯àª½±µ¨Ï³o¨Ç²£«~¥¿±`¤u§@¡C¦P®É³o¨ÇÅX°Êµ{¦¡¤]¥²¶·²Å¦X GDI ©Ò³W©wªº³W½d¡C¥t¤@¤è±¡AÀ³¥Îµ{¦¡¨Ï¥Î GDI ¨ç¦¡¤]¥²¶·¿í¦u¤@©wªº³W«h¡A¤]´N¬O«ü¿í¦u¦U°Ñ¼Æªº³W©w¤Îµy«á´£¨ìªº³W«h¡C
´«¥y¸Ü»¡¡A¥un§ÚÌ©Ò¼¶¼gªºµ{¦¡¿í¦u GDI ªº³W«h¡A´N¯à«Ü²³æªº¦b¿Ã¹õ©Î¦Lªí¾÷Åã¥Ü¥X¹Ï§Î¨Ó¡C¥t¤@¤è±¡AGDI ¦P®É¤]n¨DµwÅé¼t°Ó©Ò´£¨ÑªºÅX°Êµ{¦¡¤]¥²¶·¿í¦u¤@©wªº³W½d¡A³o¼Ëµ{¦¡³]p®v¤£¥²¥hÃö¤ß¨Ï¥ÎªÌ¬O¨Ï¥Î¨º¤@®a¼t°Óªº¿Ã¹õ¡B¦Lªí¾÷¡C©Ò¥H GDI ¬O¤@Ó»PµwÅéµLÃöªºµ{¦¡¬É±¡C
Windows ¨t²Î¬O¤@Ó¦h¤u¨t²Î¡A¦P¤@®É¶¡ùØ¡A¥i¯à¦³¦n´XÓµ{¦¡¦@¥Î¤@ӿùõ©Î¦Lªí¾÷¡A©Ò¥H·íµ{¦¡¦V¿Ã¹õ¡B¦Lªí¾÷¿é¥X®É¡AGDI ÁÙ¥²¶·°µ¨ó½Õ¤u§@§_«h¥²·|²£¥Í¤j¶Ã¡CGDI ªº°µªk¬O¨Ï³o¨Çµ{¦¡¥ý¿é¥X¨ì¤@ÓµêÀÀ¸Ë¸m¡A³oÓµêÀÀ¸Ë¸m´N¬O³]³Æ¤º®e( device context¡AÁY¼g¬° DC )¡A¦Ó¨C¤@ÓÀ³¥Îµ{¦¡n¿é¥X¸ê®Æ¨ì¿Ã¹õ©Î¦Lªí¾÷®É¥²¶·¦V Windows ¨t²Î¨ú±o³\¥i¡A°²¦p¦¨¥\ªº¸Ü¨t²Î«K·|¶Ç¦^¤@Ó³]³Æ¤º®e¥N½X¡C
³]³Æ¤º®e¬O¤@ӫܤjªº¸ê®Æµ²ºc¡A¥]§t¤F¤@²Õ¹Ï§Îª«¥ó ( graphic objects¡A¹Ï§Îª«¥ó¥]§tµ§¡Bµ§¨êµ¥µ¥¡A±z¥i¥H§â¥¦Ì·Q¹³¦¨¬O¤@²Õµ{¦¡¡At³dµe¥XÂI½u¼g¥X¦r¡B¶ñ¤WÃC¦âªº¤u¨ãµ¥µ¥ ) ¥H¤Î¬ÛÃöÄÝ©Ê¡A´«¥y¸Ü»¡¡A¹ïÅã¥Ü¾¹¨ÓÁ¿¡A±z¥i¥H§â³]³Æ¤º®e·Q¹³¦¨Àx¦s³oÓµøµ¡ùتº¹Ï§Î¤º®e¤Îµe¥X¹Ï§Îªºµ{¦¡¡C
¸Õ·Q¡A¤@Ó 800*600 ªºµøµ¡¦³¦h¤Ö¸ê®Æ¡A°²¦p¦P®É¶}±Ò¦n´XÓµøµ¡¡A¨º»ò©Ò®ø¯Óªº¸ê·½¥²©w«Ü¥iÆ[¡C¦]¬°³]³Æ¤º®e©Ò¦û¥ÎªºªÅ¶¡¤Î¸ê·½¬O¦p¦¹¥¨¤j¡A©Ò¥HÀ³¥Îµ{¦¡¦¬¨ìn¿é¥X¸ê®Æ¨ì¿Ã¹õªº°T®§ ( §Y WM_PAINT¡Aµy«á»¡©ú ) «á¡A¶}±Ò¤@Ó³]³Æ¤º®e¡A·í§¹¦¨«á¡A¥²¶·¦b¦^¨ì°T®§´`Àô¤§«eÄÀ©ñ³oÓ³]³Æ¤º®e¡C
¦b Windows §@·~¨t²Î¤U¡AÅã¥Ü¤@Ó¦r¦ê¡A¨Ã¤£¹³¦b DOS ¤U³o¼Ë²³æ¡Cº¥ý DOS ¬O¤å¦r¼Ò¦¡¡Aµ{¦¡¬O¥HÃþ¦ü¥´¦r¾÷ªº¤è¦¡¡A¤@Ó¦r¤@Ó¦r¦L¥X¨Óªº¡F¦Ó Windows ¨t²Î¬O¦b¹Ï§Î¼Ò¦¡¡A¨CÓ¦r¬O¥Ñ³\¦hªºÂI²Õ¦¨¡A¬O¤@ÂI¤@ÂI´yø¡C©¯¦n³oÓ²Ó¸`¬O¥Ñ¨t²ÎÀ°§Ú̧¹¦¨¡A·íµM±z¦pªG·Q±±¨î¨C¤@ÓÂI¡A¤]¦³ API ¥i¥HÀ°±z¹F¦¨¥Øªº¡C
²Ä¤G¡ADOS ¨t²Î¬O¤@¦¸¥u¦³¤@Óµ{¦¡°õ¦æ¡A¿Ã¹õ³Q³oÓµ{¦¡¿W¦û¡A·ín¦L¥X¦r¦ê®É¤£¥Î¦Ò¼{¨ä¥Lµ{¦¡¡A¦ý¬O Windows ¨t²Î¬O¦h¤u§@·~¨t²Î¡A¦b¿Ã¹õ¤W¥i¯à¦P®ÉÅã¥Ü³\¦hµøµ¡¡A³o¨Çµøµ¡¦@¥Î¤@ӿùõ¡A©Ò¥H·í¬Y¤@Óµ{¦¡nÅã¥Ü¦r¦ê®É¡A¥²¶·¦Ò¼{³oÓµ{¦¡ªºµøµ¡¬O§_³Q¨ä¥Lµøµ¡¾B»\¡A°²¦p³Q¨ä¥Lµøµ¡¾B»\¬O§_¶È¾B»\³¡¥÷¦Ó¥uÅã¥Ü³¡¥÷¦r¦êµ¥µ¥¡C
Ãö©ó²Ä¤GÓ°ÝÃD¡AGDI ¬O§Q¥Î«Ã¸ªº¤è¦¡¨Ó¸Ñ¨M¡C¨C·í¨Ï¥ÎªÌ§â¤@Óµøµ¡²¾¨ì¥t¤@Óµøµ¡¤W±¡A©ÎªÌ§ïÅܵøµ¡ªº¤j¤p ( ¥]¬AÁY¨ì³Ì¤p©Î©ñ¨ì³Ì¤j¡B©ÎªÌ§ïÅܵøµ¡ªø«×¡B¼e«× )¡A©ÎªÌ«ö¤U¤u¨ã¦Cªº¿ï³æ¡A©ÎªÌ·Æ¹«´å¼Ð²¾°Ê¬ï¹L¤u§@°Ï¡A¥Î±²¶b±²°Ê¤u§@°Ï®Éµ¥µ¥¡A³o¨Ç±¡§Îµo¥Í®É Windows ¨t²Î³£¯à¹îı¡A¨Ã¥Bµo¥X¤@Ó WM_PAINT µ¹¸Óµøµ¡¡A§i¶D¸Óµøµ¡»Ýn«·sø»s¤F¡C·íµMµ{¦¡¤]¥i¥H¹ï¦Û¤vµo¥X WM_PAINT °T®§¡A±j¢¦Û¤v«Ã¸¡A¨Ò¦p©I¥s InvalidateRect API¡C¨ä¥LÁÙ¦³¤@¨Ç API ¤]·|²£¥Í WM_PAINT¡A¹³ UpdateWindow¡A³q±`µøµ¡ªº²Ä¤@Ó WM_PAINT °T®§¬O UpdateWindow µo¥Xªº¡C
·íµøµ¡¨ç¦¡¦¬¨ì WM_PAINT ®É¡A¥²¶·«·sø»sµøµ¡¡A¦ý¦³®É§Ų́䣧Ʊæ«Ã¸¾ãÓµøµ¡¡A¦]¬°¨º¼Ë¤Ó®ø¯Ó¸ê·½¤S¤Ó®ö¶O®É¶¡¤F¡C©Ò¥H Windows ¥u«·sø»s³¡¥÷³Q¾B»\©ÎªÌ»Ýn«·sø»sªº³¡¥÷´N¥i¥H¤F¡A³oÓ°Ï°ìºÙ¬°¡yµL®Ä°Ï°ì¡z¡C¨º»òµL®Ä°Ï°ì¦³¦h¤j¤S¦ì©ó¤u§@°Ïªº¨ºùØ©O¡H³oÓ°ÝÃD«Ü½ÆÂø¡A¦]¬°¦³³\¦h¦UºØ¤£¦Pªº±¡ªp¡A¦ý¬O³o¨Ç³£¥æ¥Ñ¨t²Î¸Ñ¨M¤F¡C·í¨t²Îµo¥X WM_PAINT «á³Qµøµ¡¨ç¦¡©Ò³B²z®É¡A¤@¯ë¦Ó¨¥¬O¥ý©I¥s BeginPaint API ¨ç¼Æ¡A¦¹¨ç¼Æ·|¶Ç¦^¤@Óµ²ºcÅé¡A¦¹µ²ºcÅé§t¦³µL®Ä°Ï°ì¡C©ÎªÌ¤]¥i¥H©I¥s GetUpdateRect API ª½±µ¨ú±o¦¹µøµ¡ªºµL®Ä°Ï°ì¡C
·íµ{¦¡©I¥s BeginPaint API ®É¡ABeginPaint ·|§â¾ãÓ¤u§@°Ï³]¬°¦³®Ä¡C°²¦p±z¤£·Q³B²z WM_PAINT °T®§¡A¨º»ò´N¥æ¥Ñ DefWindowProc ³B²z¡A¤d¸U¤£¯à¼g¦¨
cmp uMsg,WM_PAINT jnz next_WM1 jmp exit ¡K¡K¡K next_WM1: ;¨ä¥L°T®§ exit: xor eax,eax ret
³o¼Ëªí¥Ü§AÁöµM³B²z WM_PAINT¡A¦ý¹ê»Ú¤W¤u§@°Ï¤´¦³µL®Ä°Ï°ì¡A©Ò¥H¨t²Î·|µo²{³oÓµL®Ä°Ï°ì¥¼³B²z¡A©ó¬O¦A°e¤@¦¸ WM_PAINT¡A¦ýµ{¦¡¤´µLªk§âµL®Ä°Ï°ì²M°£¡A¨t²Î·|¤@ª½¹ï§Aªºµøµ¡µo¥X WM_PAINT ªº°T®§¡C
¦b¿Ã¹õ¤W¦P¤@®É¶¡ùØ¡A¥i¯à¦³¦n´XÓµøµ¡¡A¥i¬O¤@¯ë¹q¸£¥u¦³¤@ÓÁä½L¡A©Ò¥H¥u¦³¥¿¦b¨Ï¥Îªºµøµ¡¯à°÷±µ¦¬¨ìÁä½Lªº«öÁä¡C©Ò¿×¥¿¦b¨Ï¥Îªºµøµ¡¡A¨ä¹ê¬O«Ü®e©ö¤À¿ëªº¡A¥¦ªº¼ÐÃDÄæ¬O°ª«G«×ªº¡A©ÎªÌ±z¤]¥i¥H»¡¬O¿Ã¹õ³Ì¤W¼hªºµøµ¡¡C·í¨Ï¥ÎªÌ«ö¤UÁä½L¤¤ªº¤@ÓÁä®É¡A¨t²Î·|¤À¿ë¨Ï¥ÎªÌ©Ò«ö¤UÁä¬O¤@¯ë«öÁäÁÙ¬O¨t²Î«öÁä¡A©Ò¿×¨t²Î«öÁä¬O«ü¹³ F10 Áä¡BAlt Áäµ¥¡A¦¹®É¨t²Î·|µo¥X WM_SYSKEYDOWN¡A©ñ¶}¨t²ÎÁä®É¡A·|µo¥X WM_SYSKEYUP °T®§¡C¦ý°£«D¦³¯S§Oªº¥Øªº¡A¤@¯ë«Ü¤Ö³B²z¨t²Î«öÁä¡A¦Ó³oÓµ{¦¡§ÚÌ¥u³B²z¤@¯ë«öÁä¡C
°²¦p¨Ï¥ÎªÌ«ö¤U¤@¯ë«öÁ䪺¸Ü¡A¨t²Î·|µo¥X WM_KEYDOWN °T®§µ¹¥¿¦b¨Ï¥Îªºµøµ¡¡A·í¨Ï¥ÎªÌ©ñ¶}¸ÓÁä®É¡A¨t²Î·|µo¥X WM_KEYUP °T®§¡AWM_KEYDOWN¡BWM_KEYUP °T®§¤¤ªº wParam ¤¤¦s¦³µêÀÀÁä½X ( Virtual-Key Codes )¡C©Ò¿×µêÀÀÁä½X¬O Windows ¨t²Î¤º©Ò©w¸qªº¡AÁä½L¤Wªº¨CÓ«öÁä³£¦³¿W¤@µL¤Gªº¼ÆÈ¡A§Y¬°µêÀÀÁä½X¡C´«¥y¸Ü»¡¡AWindows ´N¬O¾aµêÀÀÁä½X¨Ó§PÂ_¨Ï¥ÎªÌ«ö¤U¨º¤@ÓÁä¡A©Î©ñ¶}¨º¤@ÓÁä¡C^¤å¦r¥À«öÁ䪺µêÀÀÁä½X¨ä¹ê´N¬O^¤å¤j¼gªº ASCII ½X¡AÁä½L¤W¤èªº¼Æ¦rÁ䪺µêÀÀÁä½X´N¬Oªü©Ô§B¼Æ¦rªº ASCII ½X¡A¦Ü©ó¨ä¥L«öÁä¥i¥H°Ñ¦Ò Win32 Programmer's Reference¡C
ÁöµM Windows ½á¤©¨CÓÁä¿W¤@µL¤GªºµêÀÀÁä½X¡A¦ý¬OµêÀÀÁä½X¨Ã¥¼¦Ò¼{¨Ï¥ÎªÌ¿é¤J¤j¤p¼gªº±¡§Î¡C¨Ò¦p¡A¦pªG¨Ï¥ÎªÌ¦b CapsLock ¿Oº¶·Àªº±¡§Î¤U«ö¤U¡yA¡zÁä¡Aªí¥Ü¿é¤Jªº¬O¡ya¡z¦r¤¸¡A¦ý¬O¦b CapsLock ¿O«Gªº±¡§Î¤U«ö¤U¡yA¡zÁä©Î¬O¦b CapsLock º¶·À¤U¡A¦P®É«ö¤U Shift Áä»P¡yA¡zÁä¡Aªí¥Ü¿é¤Jªº¬O¡yA¡z¦r¤¸¡C³o¨âºØ±¡§Î¡A¦b¨t²Î¤º³¡³£¬Oªí¥Ü¨Ï¥ÎªÌ«ö¤U¡yA¡zÁä¡A¤£ºÞ¬O§_¦P®É«ö¤U Shift Áä¡A¤]¤£ºÞ CapsLock ¿O¸¹¬O§_«GµÛ¡AWM_KEYDOWN ©Î WM_KEYUP ªº wParam ³£·|¶Ç¨Ó¡yA¡zÁ䪺µêÀÀÁä½X¡A©Ò¥Hª½±µ³B²z WM_KEYDOWN ©M WM_KEYUP ÁÙ±o°Ñ¦Ò¨ä¥L¸ê®Æ¤~¯àª¾¹D±z«öªº¬O¤j¼g©Î¤p¼g¡C
¦ý¥u¦b¯S®í±¡§Î®É¡A§Ṳ́~ª½±µ³B²z WM_KEYDOWN ©M WM_KEYUP¡A¤@¯ë§ÚÌ¥i¥H¸g¥Ñ TranslateMessage API §â WM_KEYDOWN »P WM_KEYUP °T®§Â½Ä¶¦¨ WM_CHAR °T®§¡ATranslateMesage ·|¦Û°Ê°t¦X CapsLock »P Shift Á䪺ª¬ªp¥h§PÂ_«öÁä¬O¤j¼g©Î¤p¼g¡AµM«á¦s¦b WM_CHAR ùØ¡A³o¼Ë¦b WM_CHAR ùرªº wParam ´N¬O±z«öÁä®ÉÔªºª¬ªp¬O¤j¼g©Î¤p¼g¡C
.386 .model flat,stdcall option casemap:none include windows.inc include user32.inc include kernel32.inc includelib user32.lib includelib kernel32.lib WndProc proto :HWND,:UINT,:WPARAM,:LPARAM DrawStr proto :DWORD,:DWORD ;12 «Å§i DrawStr ¨ç¦¡ì«¬ .DATA ClassName db 'SimpleWinClass',0 AppName db '«öÁä»P¦^À³',0 ;16 ¼ÐÃDÄ檺¦r¦ê MyText db '±z«ö¤U¤F Áä¡C',0 ;17 ±N©ó¤u§@°Ïø»sªº¦r¦ê hInstance HINSTANCE ? hwnd HWND ? CommandLine LPSTR ? wc WNDCLASSEX <30h,?,?,0,0,?,?,?,?,0,offset ClassName,?> msg MSG <?> .CODE start: invoke GetModuleHandle,NULL mov hInstance,eax invoke GetCommandLine mov wc.style,CS_HREDRAW or CS_VREDRAW mov wc.lpfnWndProc,offset WndProc mov eax,hInstance mov wc.hInstance,eax mov wc.hbrBackground,COLOR_WINDOW+1 invoke LoadIcon,NULL,IDI_APPLICATION mov wc.hIcon,eax mov wc.hIconSm,eax invoke LoadCursor,NULL,IDC_ARROW mov wc.hCursor,eax invoke RegisterClassEx,offset wc invoke CreateWindowEx,NULL,offset ClassName,offset AppName,\ WS_OVERLAPPEDWINDOW,0,0,200,100,0,0,hInstance,NULL mov hwnd,eax invoke ShowWindow,hwnd,SW_SHOWDEFAULT invoke UpdateWindow,hwnd gt_msg: invoke GetMessage,offset msg,NULL,0,0 or eax,eax jz wm_qut invoke TranslateMessage,offset msg invoke DispatchMessage,offset msg jmp gt_msg wm_qut: mov eax,msg.wParam invoke ExitProcess,eax WndProc proc hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM cmp uMsg,WM_PAINT ;55 Àˬd¬O§_ WM_PAINT °T®§ jne not_paint ;56 §_¡A¸õ¨ì²Ä 61 ¦æ mov eax,offset MyText invoke DrawStr,eax,hWnd ;58 ©I¥s°Æµ{¦¡ jmp exit not_paint: ;61 cmp uMsg,WM_CHAR ;62 Àˬd¬O§_«ö¤UÁä jne not_keyinput ;63 §_¡A¸õ¨ì²Ä 70 ¦æ mov eax,wParam ;64 ±o¨ì«öÁä ASCII ¦r¤¸ mov edx,offset MyText+9 ;65 ¨ú±o¦r¦ê¤¤«öÁä¦r¤¸ªº¦ì§} mov [edx],al ;66 ¶ñ¤J ASCII ¦r¤¸ invoke InvalidateRect,hWnd,0,1 ;67 ³]©w¬°µL®Ä°Ï°ì jmp exit not_keyinput: ;70 cmp uMsg,WM_DESTROY jne default invoke PostQuitMessage,NULL jmp exit ;74 default: invoke DefWindowProc,hWnd,uMsg,wParam,lParam ret exit: xor eax,eax ret ;80 ¦^¨ì¥Dµ{¦¡ WndProc endp DrawStr proc AddrSt:DWORD,hWin:DWORD ;83 DrawStr °Æµ{¦¡¶}©l LOCAL hDevCont:HDC ;84 °Ï°ìÅܼơA¦s DC ¥N½X LOCAL PS:PAINTSTRUCT ;85 °Ï°ìÅܼơA¦s LOCAL rectagl:RECT ;86 invoke BeginPaint,hWin,ADDR PS ;87 mov hDevCont,eax ;88 invoke GetClientRect,hWin,ADDR rectagl ;89 invoke DrawText,hDevCont,AddrSt,-1,\ ;90 ADDR rectagl,DT_SINGLELINE ;91 invoke EndPaint,hWin,ADDR PS ;92 ret DrawStr endp end start
³oÓµ{¦¡©M¤W¤@³¹®t¤£¦h¡A¥u¬O¦bµøµ¡¨ç¦¡ ( window procedure ) ùئh¤F¨âÓ°T®§¬O³oÓµ{¦¡¸û¦³¿³½ì¦Ón³B²zªº¡A³o¨âÓ°T®§¬O WM_CHAR ©M WM_PAINT¡C²Ä 55 ¦æ¨ì²Ä 59 ¦æÀˬd¬O§_»Ýn«Ã¸¡AY»Ýn«Ã¸«h°õ¦æ²Ä 58 ¦æ CALL DrawStr¡ADrawStr ¬O«·sø»s¦r¦êªº°Æµ{¦¡¡A¨ä°Æµ{¦¡¦b²Ä 83 ¦æ¨ì²Ä 94 ¦æ¡C
²Ä 61 ¦æ¨ì²Ä 68 ¦æ¬OÀˬd¬O§_«ö¤UÁä¡AY¬°¬O«h³B²z¤§¡F²Ä 70 ¦æ¨ì²Ä 74 ¦æ«h¬O³B²z°h¥Xµ{¦¡ªº°T®§¡F²Ä 76 ¦æ¨ì²Ä 80 ¦æ¬O¤º©w³B²z°T®§ªº DefWindowProc ³¡¥÷¡C¦]¬°¤j³¡¤À³£©M¤W¤@³¹¬Û¦P¡A©Ò¥H¤p¤ì°¸¶È´N·s¼W©Î«nªº³¡¥÷»¡©ú¡C
µ{¦¡²Ä 62 ¦æÀˬd°T®§¬O§_¬° WM_CHAR¡A¦pªG¬Oªº¸Ü¡A¦³¨â¶µ¤u§@n§¹¦¨¡C²Ä¤@¬O¨ú±o«öÁ䪺 ASCII ¦r¤¸¨Ã¶ñ¤J¦r¦êùØ¡A«Ý¤U¤@¦¸°T®§°j°é®É¦L¥X©ó¿Ã¹õ¡A³o¤u§@¥Ñµ{¦¡²Ä 64 ¨ì 66 ¦æ§¹¦¨¡C²Ä¤G¬O§âµøµ¡³]¬°µL®Ä°Ï¡A¥Ñµ{¦¡²Ä 67 ¦æªº InvalidateRect API §¹¦¨¡C
³oÓ API ¬O¥Î¨Ó³]©wµL®Ä°Ï°ìªº¡A¨ä¥Îªk¦p¤U¡G
BOOL InvalidateRect( HWND hWnd, // handle of window with changed update region CONST RECT *lpRect, // address of rectangle coordinates BOOL bErase // erase-background flag );
hWnd ¬O«ün³]©wµL®Ä°Ïªº¨ºÓµøµ¡ªºµøµ¡¥N½X¡AlpRect ¬O«ü¸Óµøµ¡¤¤n³]©w¨º¤@¶ô°Ï°ì¬°µL®Ä°Ï°ì¡A lpRect ¬O¤@Ó¦ì§}«ü¼Ð¡A¥¦«ü¦V¤@ÓºÙ¬° RECT ªºµ²ºcÅé¡A¸Óµ²ºcÅé¬O«ü©w¤@¶ôªø¤è§Î°Ï°ì¡A´yz¦p¤U¡G
RECT struc left DD ? ;ªø¤è§Î¥ª¤W¨¤ªº x ®y¼Ð top DD ? ;ªø¤è§Î¥ª¤W¨¤ªº y ®y¼Ð right DD ? ;ªø¤è§Î¥k¤U¨¤ªº x ®y¼Ð bottom DD ? ;ªø¤è§Î¥k¤U¨¤ªº y ®y¼Ð RECT ends
lpRect ¤]¥i¥H¬O¹s¡A°²¦p¬O¹sªº¸Ü¡Aªí¥Ü¤u§@°Ïªº©Ò¦³½d³ò³£¬OµL®Ä°Ï°ì¡C³Ì«á¤@Ó°Ñ¼Æ bErase ¬Oªí¥Ü¬O§_²M°£I´º¡A¹sªº¸Üªí¥Ü¤£²M°£¡A«D¹sªí¥Ün²M°£I´º¡A¦b©I¥s BeginPaint ®É¡AI´º´N·|³Q²M°£¡CInvalidateRect ¦³¶Ç¦^È¡A¦pªG³]©w¦¨¥\¶Ç¦^Ȭ°«D¹s¡A¥¢±Ñ¶Ç¦^Ȭ°¹s¡C
·íµ{¦¡³]©w¤@¶ôµL®Ä°Ï°ì®É¡A¨t²Î·|¹îı¦Óµo¥X¤@Ó WM_PAINT °T®§¶ñ¤J¸Óµøµ¡ªº°T®§¦î¦CùØ¡Aµ¥«Ý¸Óµøµ¡ªº°T®§°j°é´£¨ú¡C¦Ó«áµ{¦¡Ä~Äò°õ¦æ¡A¸õ¨ì²Ä 79 ¦æªð¦^ Windows ¨t²Î¡Aµ¥¨ì°õ¦æ¤U¤@¦¸ªº°T®§´`Àô®É´N¯à¦¬¨ì WM_PAINT °T®§¡AµM«á¸g¥Ñ¦^©I¾÷¨î¦A¦¸¶i¤Jµøµ¡¨ç¦¡¡A¦bµ{¦¡²Ä 59 ¦æÀˬd¨ì°T®§¬O WM_PAINT ®É¡A´N°õ¦æ DrawStr °Æµ{¦¡¡C
©Ò¥HÅo¡A¦b¦¬¨ì WM_PAINT ¤§«á¤£¥i¦A©I¥s InvalidateRect¡A³o¼Ë·|¤£Â_¦a²£¥Í WM_PAINT °T®§¡A¥HP©ó¶^¤J¤@ÓµL½a°j°é¡C
·í§Ú̪ºµ{¦¡¦¬¨ì WM_PAINT ®É¡Aªí¥Üµøµ¡n«·sø»s¡A³o¬qµ{¦¡³£¶°¤¤¦b DrawStr °Æµ{¦¡ùØ¡CDrawStr ªºì«¬«Å§i¦b²Ä 12 ¦æ¡A²Ä¤@ӰѼƬOn¦L¥Xªº¦r¦ê¦ì§}¡A²Ä¤GӰѼƬOµøµ¡¥N½X¡C©³¤U¨Ó¤ÀªR DrawStr °Æµ{¦¡¡C
«e¤T¦æ¬O©w¸q¤TÓ°Ï°ìÅܼơA³o¤TÓ°Ï°ìÅܼƬO hDevCont¡BPS¡Brectagl¡A¥¦Ì¬O¦b DrawStr °Æµ{¦¡¤¤·|¨Ï¥Î¨ìªºÅܼơA¦³Ãö°Ï°ìÅܼƪºÆ[©À½Ð¬Ý©³¤U LOCAL °²«ü¥Oªº»¡©ú¡C
LOCAL ¬O¥Î¨Ó¦b°Æµ{¦¡ùØ©w¸qÅܼƪº°²«ü¥O¡A©Ò¿×¦b°Æµ{¦¡ùØ©w¸qªºÅܼƬO«ü³oÓÅܼƶȦb°Æµ{¦¡¤¤¥i¥H¨Ï¥Î¥¦¡A¦b°Æµ{¦¡¥H¥~«h¤£¯à¨Ï¥Î¡A§_«h·|¥X²{
error A2006: undefined symbol : ÅܼƦW
ªº¿ù»~¡C¹³³oºØ¥u¦³¦b°Æµ{¦¡½d³ò¤º¤~¥i¥H¨Ï¥ÎªºÅܼƺ٤§¬°¡y°Ï°ìÅܼơz¡A»P°Ï°ìÅܼƬ۹諸ºÙ¬°¡y¥þ°ìÅܼơz¡A¥þ°ìÅܼƬO¾ãÓµ{¦¡¤¤³£¥i¥H¦s¨úªº¡C¦Ü©ó¬°¦ó¥u¯à°÷¦b°Æµ{¦¡ªº½d³ò¨Ï¥Î¥H¤Î¬°¦ó¨Ï¥Î°Ï°ìÅܼƪº²z¥Ñ¡A¤p¤ì°¸µy«á¦A»¡©ú¡C¦]¬°¦b°Æµ{¦¡¥~ªº°Ï°ìÅܼƬOµL®Äªº¡A©Ò¥H¤£¦P°Æµ{¦¡ªº°Ï°ìÅܼƦWºÙ¥i¥H¬O¬Û¦Pªº¡C²{¦b¥ý¨Ó¬Ý¥¦ªº»yªk¡G
LOCAL ÅܼƦW[«½Æ¦¸¼Æ]:¸ê®Æ«¬ºA
«½Æ¦¸¼Æ¦³ÂI¹³ dup¡A¥u¤£¹L dup ¬O¥Î¦b©w¸q¥þ°ìÅܼơA°²¦p¤£«½Æªº¸Ü¡A[«½Æ¦¸¼Æ]¥i¬Ù²¤¡C¸ê®Æ«¬ºA¬O¥u³oÓÅܼƪºªø«×¡A¨Ò¦pÂù¦r²Õ¥Î DWORD¡A¦r²Õ¥Î WORD¡A¦ì¤¸²Õ¥Î BYTE¡A¤]¥i¥H¨Ï¥Îµ²ºcÅé¡CLOCAL °²«ü¥O¥u¯à©ñ¦b PROC «Å§i¤§«á¡A¨ä¥L«ü¥O¶}©l¤§«e¡C©³¤U¨Ó¬Ý¬Ý´XÓ¨Ò¤l¡A°²¦p¦³Óµ{¦¡¤ù¬q¼g¦¨
.code start: invoke MyProc invoke ExitProcess,0 MyProc proc local p:dword local q:dword local r:word mov p,01234567h mov q,89abcdefh mov r,400h ret MyProc endp
³o¼Ë¡A²ÕĶ«á¦A¥Î Soft-ICE ¸ü¤J«á«ö¤U F8 Áä¡AµM«áÆ[¹îµ{¦¡½Xªº¼Ë¤l¦p¤U¡G
00401000 E807000000 CALL 0040100C ¡÷©I¥s MyProc 00401005 6A00 PUSH 00 00401007 E81C000000 CALL KERNEL32!ExitProcess 0040100C 55 PUSH EBP ¡÷MyProc ¶}©l³B 0040100D 8BEC MOV EBP,ESP 0040100F 83C4F4 ADD ESP,-0C 00401012 C745FC67452301 MOV DWORD PTR [EBP-04],01234567 00401019 C745F8EFCDAB89 MOV DWORD PTR [EBP-08],89ABCDEF 00401020 66C745F60004 MOV WORD PTR [EBP-0A],400 00401026 C9 LEAVE 00401027 C3 RET ¡÷MyProc µ²§ô³B
§ÚÌ¥ý§ä¨ì MyProc °Æµ{¦¡±q¦ì§} 40100C ¨ì 401027¡A¦A¤ñ¸ûì©lµ{¦¡»P¾÷±ñ½X¡Aµo²{²ÕĶ¾¹·|¦b²ÕĶ®É§â LOCAL °²«ü¥Oªº±Ôz¦AÃB¥~¥[¤W
PUSH EBP MOV EBP,ESP ADD ESP,-XXXX
³o¤T±ø«ü¥O¡C«e¨â±ø«ü¥O¬O«O¦s EBP ¼È¦s¾¹¡A¦]¬°¦b°Æµ{¦¡ùØ¡AEBP n°µ¬°¦s¨ú°Ñ¼Æ¤§¥Î ( °Ñ¦Ò²Ä¤@³¹ªºµù¤C )¡C²Ä¤T±ø«ü¥O«h¬O¦b°ïÅ|¤¤¹w¯d¤@¨ÇªÅ¶¡¡Aµ¹°Ï°ìÅܼƦs©ñ¤§¥Î¡CESP «ü¦V°ïÅ|³Ì°ª¦ì§}ªº¦a¤è¡A¤§«á¦³¼ÆȳQ±À¤J°ïÅ|¡AESP ´N´î¤Ö¡C°²¦p¨Ï ESP ´î¥h¬Y¤@¼ÆÈ¡A´N·|¨Ï¤U¤@¦¸ªº PUSH ©Î CALL «ü¥O¡A¦s¤J¬Y¼Æ¨ì°ïÅ|®É¡A¦b¸û§C¦ì§}¦s¤J¦¹¼Æ¡C³o¼Ë¤@¨Ó¡A·|¨Ï°ïÅ|ªÅ¤U¤@¨ÇªÅ¶¡¡A³o¨ÇªÅ¶¡´Nµ¹°Ï°ìÅܼƨϥΡC·ín¦s¨ú°Ï°ìÅܼƮɡA´N¾a EBP ¨Ó·í«ü¼Ð¡A¦¹¥~¡A¦b 80386 CPU ¬O¥H 32 ¦ì¤¸¨Ó§@¬°¦s¨ú³æ¦ì¡A¬GÁöµM¤Wz°Æµ{¦¡¥u¥Î¥h 10 Ӧ줸²Õ ( p¡Bq ¦U¦û 4 Ӧ줸²Õ¡Ar ¦û¨âӦ줸²Õ ) ªº°Ï°ìÅܼơA¦ý¬O°ïÅ|ÁÙ¬O«O¯d¤F 12 Ӧ줸²Õªº¤j¤pµ¹°Ï°ìÅܼơAÁöµM®ö¶O¤F¦ý¬O«o¯à¥[§Ö³t«×¡C¦³Ãö LOCAL ªº¸Ô²Ó¹Lµ{½Ð¤Î°ïÅ|¾Þ§@½Ð°Ñ¦Ò¤U¹Ï¡C
±µ¤U¨Óªº¤TÓ«ü¥O¬O§â p¡Bq¡Br ¤TÓ°Ï°ìÅܼƶñ¤J¹ïÀ³ªº°ïÅ|°Ï¡A¦p¤U¹Ï¤¡B¤»¡B¤C¡C±µ¤U¨Ó¬O LEAVE «ü¥O¡ALEAVE ¥ý¨Ï ESP ¤§Èµ¥©ó EBP¡A©ó¬O ESP ȵ¥©ó 0063FE34¡AµM«á¦A±q°ïÅ|¼u¥X¤@ÓÂù¦r²Õ¦s©ó EBP¡A©ó¬O EBP «ì´_ìÈ¡A¦Ó ESP ¤]«ü¦V¦^¨ì¥Dµ{¦¡±N°õ¦æªº«ü¥O¦ì§}¡A¦p¤U¹Ï¤K¡A³o®Éì¨Ó¦b°ïÅ|ªº°Ï°ìÅܼƴN³Q©ß±ó¤F¡C
¬°¦ó¨Ï¥Î°Ï°ìÅܼƩO¡H°Ï°ìÅܼƦ³¤@¨Ç¨î¡A¥¦¤£¯à¦A°Æµ{¦¡¥H¥~ªº¦a¤è¨Ï¥Î¡A³o¼Ë¤£¬Oµ¹µ{¦¡³\¦h¨î¶Ü¡Hì¦]¬O³o¼Ëªº¡G·íµ{¦¡¤pªº®ÉÔ¡A±zÀ³¸Ó¥i¥H¬Ý±o¥Xµ{¦¡¬O¦p¦ó¹B§@ªº¡A§Y¨Ï¤é«ánºûÅ@¡A¤]¤£ºâ¤Ó§xÃø¡C¦ý¬O·í¦¨¬OÅܱoÃe¤j¥B½ÆÂø®É¡An«Ü§Ö¬Ý¥Xµ{¦¡¯ßµ¸´N¤£®e©ö¤F¡A³o®É¦³¨Çµ{¦¡³]p®v´£¥X¤@ÓÆ[©À¡A¥ĻƱæ¯à°÷§â¨ã¦³¬Y¨Ç¥\¯àªºµ{¦¡¤ù¬q¼g¦¨°Æµ{¦¡ªº§Î¦¡¡A¤£¶È¦p¦¹ÁÙ¶i¤@¨Bn¨D³oӰƵ{¦¡³Ì¦n¯à¥u¦³¿é¤J°Ñ¼Æ§â¸ê®Æ¶Ç»¼¶i¨Ó¡AµM«á¸g¹L°Æµ{¦¡³B²z§âµ²ªG¶Ç¦^¥Dµ{¦¡´N¦n¡A¤£n¦A¦³¨ä¥L³¡¥÷©M¥Dµ{¦¡¦³²o³s¡A¤]´N¬O»¡¡A¦b³oӰƵ{¦¡¤¤¦pªG¥²¶·¥Î¨ìÅܼơA³oÓÅܼƳ̦n¥u¯à³Q³oӰƵ{¦¡¦s¨ú¡A°²¦p¦¹ÅܼƳQ°Æµ{¦¡¥H¥~ªºµ{¦¡¦s¨ú·|³y¦¨³\¦h¤zÂZ¡A°£¿ù¤]¤£©ö¡A³o¤]´N¬O¬°¤°»ò§Ų́ϥΰϰìÅܼƪºì¦]¡C³oÓÆ[©À´N¬O¼Æ¦~«e ( ¬ù 1990 ¦~¥N ) ¬y¦æªºµ²ºc¤ÆÆ[©À¡C
©³¤U¬Ý¬Ý²Ä 87 ¦æªº invoke BeginPaint¡C¦ý¦b³o¤§«e¡A¥ý¬Ý¬Ý ADDR °²«ü¥O¡C
ADDR ©M OFFSET ³£¬O¨ú±o¦ì§}ªº°²«ü¥O¡A¨âªÌµy¦³¤£¦P¡COFFSET ¬O¥Î¦b²ÕĶ®É¤w¸g½T©w¦ì§}ªº¦a¤è¡A¨Ò¦p¨ú±o¦b¸ê®Æ¬q¤¤ªºÅܼƦì§}¡C¦ý¬O¦b°ïÅ|ùتº°Ï°ìÅܼơA²ÕĶ®ÉÁÙ¤£ª¾¹D¦ì§} ( ¦]¬°¨º®ÉÁÙ¤£ª¾¹D¦b¦¹¤§«e°ïÅ|³Q¨Ï¥Î¤F¦h¤Ö )¡A³o®É´N¤£¯à¥Î OFFSET ¨Ó¨ú±o¦ì§}¡A¥²¶·¥Î ADDR¡C¨º»ò ADDR ¬O«ç»ò¨ú±o°Ï°ìÅܼƪº¦ì§}©O¡H
ì¨Ó²ÕĶ¾¹·|§â ADDR ½Ķ¦¨
LEA EAX,ÅܼÆ
©Ò¥H EAX «K¦s¦³¸Ó°Ï°ìÅܼƪº¦ì§}¡A¤§«á«K¥Î EAX ¥h¨ú¥N ¡yADDR Åܼơz¡C¨Ò¦pµ{¦¡²Ä 87 ¦æªº
invoke BeginPaint,hWin,ADDR PS
¸g¹L²ÕĶ«á´NÅܦ¨¡G
LEA EAX,[EBP-44] PUSH EAX PUSH DWORD PTR [EBP+0C] CALL USER32!BeginPaint
¤W±¯»¬õ¦âªº³¡¥÷¬O ADDR ²ÕĶ«áªºµ²ªG¡A²ÕĶ«á PS µ²ºcÅéÅܼƪº¦ì§}«K©ñ¦b EAX ùØ¡A©Ò¥H¦A§â EAX ±À¤J°ïÅ|ùØ¡A´N§¹¦¨¨ú±o PS Åܼƪº¦ì§}¤Î¬° BeginPaint API ¶Ç»¼°Ñ¼Æ¡C
BeginPaint API ¬O¥Î¨Ó·Ç³Æø¹Ï®É¨Ï¥Î¡A¨ä»yªk¦p¤U¡G
HDC BeginPaint( HWND hwnd, // handle to window LPPAINTSTRUCT lpPaint // pointer to structure for paint information );
BeginPaint ¦³¨âӰѼơA²Ä¤@Ó¬Oµøµ¡¥N½X¡A²Ä¤GÓ¬O¤@Âù¦r²Õ¤j¤pªº¼ÆÈ¡A¦¹¼Æ«ü¦Vµ²ºcÅé¡APAINTSTRUCT¡Aªº¦ì§}¡C°²¦p©I¥s¦¨¥\¡A¦b eax ·|¶Ç¦^³]³Æ¤º®e¥N½X¡A¤p¤ì°¸§â¥¦¦s©ó°Ï°ìÅÜ¼Æ hDevCont ùØ¡C¦Ü©ó PAINTSTRUCT µ²ºcÅ骺¤º®e¦p¤U¡G
PAINTSTRUCT STRUC hdc dd ? fErase dd ? rcPaint RECT <?> fRestore dd ? fIncUpdate dd ? rgbReserved db 32 dup (?) PAINTSTRUCT ENDS
hdc ¬O³]³Æ¤º®e¥N½X»P BeginPaint ªº¶Ç¦^ȬۦP¡CfErase ¬O¥Î¨Óªí¥Ü¬O§_¹ïµL®Ä°Ï°ìªºI´º¤W¦â¡An¤W¦âªº¸Ü¥Î TRUE¡A¤£¤W¦â¥Î FALSE¡CrcPaint ¬O¥t¤@Óµ²ºcÅé¡ARECT¡A¦¹µ²ºcÅé«ü©w¤F¤@¶ô¯x§Î½d³ò¡A¦b©I¥s BeginPaint ¤§«á¡A¨t²Î·|§âµL®Ä°Ïªº½d³ò¶ñ¤J rcPaint µ²ºcÅé¡A¦A¶Ç¦^µ¹§Ú̪ºµ{¦¡¡CfRestore¡BfIncUpdate¡BrgbReserved ³£«O¯dµ¹¨t²Î¨Ï¥Î¡C
BeginPaint ·|¶}±Ò¤@Ó³]³Æ¤º®e¡A·íø¹Ï§¹²¦¡AÀ³¸Ó§â¥¦Ãö³¬¡A¤@¯ë¬O¨Ï¥Î EndPaint ¨Ó³B²z¡A´«¥y¸Ü»¡ BeginPaint »P EndPaint À³¸Ó¦¨¹ï·f°t¡CEndPaint »yªk¬O
BOOL EndPaint( HWND hWnd, // handle to window CONST PAINTSTRUCT *lpPaint // pointer to structure for paint data );
EndPaint ªº°Ñ¼Æ©M BeginPaint ¬Û¦P¡C¤@¯ëµ{¦¡nø¹Ï®Éªº°µªk¦³¨âºØ¡A²Ä¤@ºØ¬O¹³¤U±¦b WM_PAINT °T®§¤¤¨Ï¥Î¡G
invoke BeginPaint,hWin,ADDR PS ¡K¡K ¡K¡K ;ø¹Ïµ{¦¡ invoke EndPaint,hWin,ADDR PS
BeginPaint ©M EndPaint ¨âÓ API ¨Ó¶}±Ò©MÄÀ©ñ³]³Æ¤º®e¡C¤]¥i¥H¨Ï¥Î²Ä¤GºØ¤èªk¡A¥Î GetDC ©M ReleaseDC ¨Ó³B²z¡C
GetClientRect ¬O¥Î¨Ó¨ú±o¤u§@°Ïªº¤j¤p¡A¨ä¨ç¦¡ì«¬¬°
BOOL GetClientRect( HWND hWnd, // handle of window LPRECT lpRect // address of structure for client coordinates );
hWnd ¬On¨ú±o¤u§@°Ïªºµøµ¡¥N½X¡AlpRect ¬O«ü¦V¤@Ó RECT µ²ºcÅé¦ì§}¡A·í GetClientRect °õ¦æ§¹«á·|¶Ç¦^¨Ó¥ª¤W¨¤©M¥k¤U¨¤ªº®y¼Ð¡A¨Ã¦s©ó lpRect ©Ò«ü¦ì§}ªºµ²ºcÅ餺¡C¤@¯ë¦Ó¨¥¡A¤u§@°Ïªº¥ª¤W¨¤®y¼Ð¬O (0¡A0)¡A©Ò¥H¥k¤U¨¤®y¼Ð¨ä¹ê´N¬O¤u§@°Ïªºªø»P¼e¡C
³oÓ API ¬O¥Î¨Ó§â¦r¦ê¥H«ü©wªº¤è¦¡Åã¥Ü¦b¬YÓªº°Ï°ì¤º¡A¨ä쫬¬°¡G
int DrawText( HDC hDC, // handle to device context LPCTSTR lpString, // pointer to string to draw int nCount, // string length, in characters LPRECT lpRect, // pointer to structure with formatting dimensions UINT uFormat // text-drawing flags );
¨ä¹ê³oÓµ{¦¡¡A¨Ã¨S¦³¥²n¨Ï¥Î GetClientRect¡A¦]¬°·í©I¥s BeginPaint ®É¡A¨t²Î´N¤w¸gª¾¹DµL®Ä°Ïªº½d³ò¡A§ÚÌ¥u»Ýn«Ã¸µL®Ä°Ï´N¥i¥H¤F¡CÁÙ¦³¤@ÂI²z¥Ñ¡A°²¨Ï¨C¦¸³£«Ã¸¾ãÓ¤u§@°Ï¡A¨º»ò¬O«Ü¯Ó¶O¸ê·½ªº¡A³oÂI¦b¹ê»Ú¼¶¼gµ{¦¡®ÉÀ³¸Ó®É®É°O±o¡C§ïÅܫ᪺ DrawStr °Æµ{¦¡¦p¤U¡G
DrawStr proc AddrSt:DWORD,hWin:DWORD LOCAL hDevCont:HDC LOCAL PS:PAINTSTRUCT invoke BeginPaint,hWin,ADDR PS mov hDevCont,eax invoke DrawText,hDevCont,AddrSt,-1,ADDR PS.rcPaint,DT_SINGLELINE invoke EndPaint,hWin,ADDR PS ret DrawStr endp
·í§Ú̹ê»Ú¼¶¼gµ{¦¡®É¡A°£¿ù¤j·§¬O¤£¥iÁקKªº¤@Àô¡A¤p¤ì°¸±N¥H³oÓ DRAWTXT.EXE ¬°¨Ò»¡©ú¦p¦ó¦b DRAWTXT.EXE ùتºµøµ¡¨ç¦¡³]©w¤¤Â_ÂI¡C¬°¦ón§ä¨ìµøµ¡¨ç¦¡©O¡A³o¬O¦]¬°¥Dµ{¦¡ªº¼gªk³£¬O©T©wªº¡A©Ò¥H·|²£¥Í¿ù»~ªº¾÷·|´X¥G¨S¦³¡A¦Óµøµ¡¨ç¦¡¦]¨CÓµ{¦¡¤£¦P¡A©Ò¥H¥X¿ùªº¾÷·|¤j¡A¦]¦¹°£¿ùªº«ÂIÀ³¸Ó©ñ¦bµøµ¡¨ç¦¡¡C
§ÚÌ©ÒnÃö¤ßªº¬O°T®§¶Ç¤Jµøµ¡¨ç¦¡ªº®É¾÷¥H¤Îµøµ¡¨ç¦¡¹ï°T®§³B²z¤è¦¡¡Cn¹F¨ì³oӥتº¡A¤@¯ë¬O¦bµøµ¡¨ç¦¡ªº¶i¤JÂI©Î¬O¨CÓ°T®§¶i¤JÂI³]©w¤¤Â_ÂI¡A³o¼Ë¤~¯àÀˬd°T®§¬O§_¥¿½T³B²z¡C©³¤U»¡©ú¥Î Sofit¡ÐICE ªº Symbol Loader ¸ü¤J DRAWTXT.EXE¡G
º¥ý¥Ñ¨t²Î¥ª¤U¨¤ªº¡y¶}©l¡z«ö¶s¡A°õ¦æ Symbol Loader¡A¿ï¾Ü¿ï³æ¡yFile¡z¡÷¡yOpen Module¡K¡z¡A¤Á´«¨ì DRAWTXT.EXE ©Ò¦b¸ê®Æ§¨¡A¶}±Ò¥¦¡C
²Ä¤G¡A¦A¿ï¾Ü Symbol Loader ¿ï³æ¤Wªº¡yModule¡z¡÷¡yLoad¡z¡A«ö¤U¡y¬O¡zªº«ö¶s¡A©¿²¤§ä¤£¨ì²Å¸¹ÀɪºÄµ§i¡A¶i¤J Soft¡ÐICE °£¿ùµe±¡C
²Ä¤T¡A«ö¤U¡yF8¡zÁä³æ¨B°lÂܨì§Ú̪º²Ä¤G¦æµ{¦¡½X¡AµM«á¿é¤J¡yu¡z«ü¥O¡A´M§ä DRAWTXT.EXE ªºµøµ¡¨ç¦¡¡C¨º»ò¡An¦p¦ó¤~¯à§ä¨ìµøµ¡¨ç¦¡¶i¤JÂI©O¡H±zÆ[¹î¤@¤Uì©lµ{¦¡¤¤¥Dµ{¦¡ªºµ²§À¬O
invoke ExitProcess,eax
µøµ¡¨ç¦¡ªº¶i¤JÂI´N¬O¤U¤@¦æ«ü¥O¡AÀ³¸Ó¤£Ãø§ä¨ì¡C±z¥i¥H¿é¤J¡yu¡z«ü¥O¥hÆ[¹î¡A³oÓ«ü¥O¬O Sofit¡ÐICE ªº«ü¥O¡A·N«ä¬O¤Ï²ÕĶ ( unassemble )¡A¥Îªk©M DEBUG/SYMDEB Ãþ¦ü¡C
¨ä»yªk¬O
U [¦ì§} Lªø«×]
¡y¦ì§}¡z©M¡yLªø«×¡z³£¥i¥H¬Ù²¤¡A¦pªG¬Ù²¤¦ì§}ªº¸Ü¡A¨º»ò Sofit¡ÐICE ±N±qµ{¦¡½Xµøµ¡³Ì«á¤@Ó«ü¥Oªº¤U¤@Ó«ü¥O¶}©l¤Ï²ÕĶ¡A¡yLªø«×¡z¦pªG¬Ù²¤ªº¸Ü¡ASofit¡ÐICE ±N¤Ï²ÕĶ¾ãÓµ{¦¡½Xµøµ¡¡C¨Ì·Óè¤~©ÒÁ¿ªº¤èªk§ä invoke ExitProcess,eax ¤U¤@¦æ«ü¥O¡A´N¬Oµøµ¡¨ç¦¡¡AÀ³¸Ó·|§ä¨ìµøµ¡¨ç¦¡¦b¦ì§} 004010E9 ³B¡G
004010E9 55 PUSH EBP 004010EA 8BEC MOV EBP,ESP 004010EC 837D0C0F CMP DWORD PTR [EBP+0C],0F 004010F0 7510 JNZ 00401102 004010F2 B81A304000 MOV EAX,0040301A ¡÷³B²z WM_PAINT 004010F7 FF7508 PUSH DWORD PTR [EBP+08] 004010FA 50 PUSH EAX 004010FB E84D000000 CALL 0040114D 00401100 EB45 JMP 00401147 00401102 817D0C02010000 CMP DWORD PTR [EBP+0C],00000102 00401109 7518 JNZ 00401123 0040110B 8B4510 MOV EAX,[EBP+10] ¡÷³B²z WM_CHAR 0040110E BA23304000 MOV EDX,00403023 00401113 8802 MOV [EDX],AL 00401115 6A01 PUSH 01 00401117 6A00 PUSH 00 00401119 FF7508 PUSH DWORD PTR [EBP+08] 0040111C E8A1000000 CALL USER32!InvalidateRect 00401121 EB24 JMP 00401147 00401123 837D0C02 CMP DWORD PTR [EBP+0C],02 00401127 7509 JNZ 00401132 00401129 6A00 PUSH 00 ¡÷³B²zWM_DESTROY 0040112B E8A4000000 CALL USER32!PostQuitMessage 00401130 EB15 JMP 00401147 00401132 FF7514 PUSH DWORD PTR [EBP+14] ¡÷¤º©wªº³B²z°T®§µ{¦¡ 00401135 FF7510 PUSH DWORD PTR [EBP+10] 00401138 FF750C PUSH DWORD PTR [EBP+0C] 0040113B FF7508 PUSH DWORD PTR [EBP+08] 0040113E E85B000000 CALL USER32!DefWindowProcA 00401143 C9 LEAVE 00401144 C21000 RET 0010 00401147 33C0 XOR EAX,EAX 00401149 C9 LEAVE 0040114A C21000 RET 0010
§ä¨ìµøµ¡¨ç¦¡¤§«á¡A¤U¤@¨BÀ³¸Ó¬O¦b¨C¤@Ó³B²z°T®§ªº¦a¤è³]¥ß¤¤Â_ÂI¡C¦b Sofit¡ÐICE ¦³Ãö¤¤Â_ÂIªº«ü¥O¦³¤@¸s¡A³£¬O¥H¡yB¡z¶}©l¡A¥]¬A³]¥ß¤¤Â_ÂI¡B²M°£¤¤Â_ÂI¡B¦C¥X¤¤Â_ÂIµ¥¡A¦Ó³]©wªº¤¤Â_ÂI¤S¦³¦]¬°°õ¦æ¨ì¬Y¤@¦ì§}¦Ó°±¤U¨Ó¡B¦s¨ú¬Y¤@¦ì§}¦Ó°±¤î¡B¦s¨ú¬Y¤@¿é¥X¤J°ð¦Ó°±¤îµ¥µ¥¡A°±¤U¨Ó«á Soft¡ÐICE ·|Åã¥Ü¥X·í®É«áªº¼È¦s¾¹¡B°O¾ÐÅ餺®eµ¥±¡§Î¥H¨Ñµ{¦¡³]p®v°£¿ùªº°Ñ¦Ò¡A¥i»¡¥\¯à±j¤j¡C¦¹³B¤p¤ì°¸¤¶²Ð BPX¡C
BPX ¬O«üµ{¦¡°õ¦æ¨ì¬Y¦ì§}´N·|°±¤U¨Ó¨Ã¶i¤J Sofit¡ÐICE °£¿ùµe±¡A¨ä»yªk¬O
BPX [¦ì§}]
DRAWTXT.EXE ªºµøµ¡¨ç¦¡¶È³B²z¤TÓ°T®§¡AWM_CHAR¡BWM_PAINT¡BWM_DESTROY¡A¦Ó WM_DESTROY À³¸Ó¤£»Ýn°£¿ù¡A°²¨Ï¤p¤ì°¸¦b 004010F2 ³oÓ¦ì§}³]¥ß¤¤Â_ÂI¡A¦b Soft¡ÐICE ªº©R¥Oµøµ¡¤U¿é¤J
bpx 4010f2 [Enter]
¦¹®É±z·|¬Ý¨ì¦b Soft¡ÐICE µ{¦¡½Xµøµ¡ªº
004010F2 B81A304000 MOV EAX,0040301A
Åܦ¨¤ÑÂŦâ¡Aªí¥Ü¤¤Â_ÂI¤w³]¥ß¦n¤F¡C±µ¤U¨Ó¦b Soft¡ÐICE ¤¤¿é¤J¡yg¡z«ü¥O¡A±z·|¬Ý¨£¿Ã¹õ¤W°h¥X Soft¡ÐICE µe±¡A¥X²{ DRAWTXT.EXE µøµ¡¡A¦ý°¨¤W¤S¦^¨ì Soft¡ÐICE µe±¡C³o¬O¦]¬° UpdateWindow ¤]·|°e¥X WM_PAINT °T®§¡C
µM«á±z¦A¿é¤J¡yg¡z«ü¥O¡A¤S·|°h¥X Soft¡ÐICE¡A¦ý³o®É¨Ã¤£·|¥ß§Y¦^¨ì Soft¡ÐICE¡A¦ý¬O·í±z«ö¤U¥ô·NÁä®É¡A¤S·|¦^¨ì Soft¡ÐICE µe±¡A³o¬O¦]¬°¦b«ö¤UÁ䤧«e¡Aµ{¦¡¤£·|¦¬¨ì WM_PAINT °T®§¡A©Ò¥H¤£·|¤¤Â_¡A¦ý«ö¤U¥ô·NÁä¡Aµ{¦¡·|¦Û¤v°e¥X¤@Ó WM_PAINT µ¹¦Û¤v¡A©Ò¥H·|¶i¤J Soft¡ÐICE °£¿ùµe±¡C
¦¹«á¨C¦¸¦¬¨ì WM_PAINT °T®§¡A³£·|¶i¤J Soft¡ÐICE °£¿ùµe±¡C¨Ò¦p¡A§ïÅܵøµ¡¤j¤p¡BÁY¨ì³Ì¤p«áÁÙìµ¥¡A¤]·|¦]¬°¨t²Î¹ï DRAWTXT.EXE µo¥X WM_PAINT¡A©Ò¥H¤]·|¶i¤J Soft¡ÐICE °£¿ùµe±¡C
·Qn²M°£¤¤Â_ÂI¡A¥i¥H°õ¦æ BC «ü¥O¡C¨ä»yªk¬O
BC ¤¤Â_ÂI½s¸¹¦Cªí©Î¡y*¡z
¨C·í§Ú̫إߤ@Ó¤¤Â_ÂI®É¡ASoft¡ÐICE ·|·Ó«Ø¥ß¥ý«áµ¹¨CÓ¤¤Â_ÂI½s¸¹¡A¦¹½s¸¹¥Ñ 0 ¶}©l¡A·í¤£»Ýn¦¹¤¤Â_ÂI®É¡A¥i¥H¥Î¡yBC ¤¤Â_ÂI½s¸¹¡z²M°£¤§¡C°²¦p±z¥Î¡yBC *¡z¡A«h·|²M°£©Ò¦³¤¤Â_ÂI¡C¨Ò¦p¡A¤p¤ì°¸²{¦b¤£n°»´ú³B²z WM_PAINT ªºµ{¦¡¡A´N¤U
bc 0
¦]¬°¶È³]¥ß¤@Ó¤¤Â_ÂI¡A©Ò¥H¸Ó¤¤Â_ÂI½s¸¹¬°¹s¡C°²¦p¤w¸g«Ø¥ßªº¤¤Â_ÂI¤Ó¦h¡A¥i¥Î BL ¬d¸ß¡C
BL ¬O§â©Ò¦³ªº¤¤Â_ÂIªº½s¸¹¤¤Â_¦ì§}¦C¥X¨Ó¡C
³oÓ«ü¥O©M DEBUG/SYMDEB ¬Û¦ü¡A°õ¦æ«ü¥Oªº·N«ä¡A¨ä»yªk¬O
G [=¦ì§}] [¦ì§}]
¦³¡y=¡zªº¦ì§}¬O«ü±q³oÓ¦ì§}¶}©l°õ¦æ¡A°²¦p¦¹¦ì§}¬Ù²¤ªº¸Üªí¥Ü±q²{¦bªº EIP ¦ì§}¶}©l°õ¦æ¡C¦Ó«á±¨S¦³µ¥©óªº¦ì§}¬O«ü°õ¦æ¨ì¦¹³B°±¤î¡A¦pªG¬Ù²¤ªº¸Ü´N·|¨ì³]©w¤¤Â_ÂI³B°±¤î¡A°²¦p¨S³]©w¤¤Â_ÂIªº¸Ü¡A´NµLªk°±¤î¤F¡C