;=========================================================; ;=========== Sub Routine ==========================; ; edi : Ãâ·ÂÇÒ È­¸é À§Ä¡ ; esi : ½ºÆ®¸µÀÇ Æ÷ÀÎÅÍ printf: push edi push eax ; ¸ÕÀú ÀÖ´ø eax °ªÀ» ½ºÅÿ¡ º¸Á¸ÇØ ³õ´Â´Ù. push es mov ax, VideoSelector mov es, ax printf_loop: mov al, byte [esi] ; esi °¡ °¡¸®Å°´Â ÁÖ¼Ò¿¡¼­ ¹®ÀÚ¸¦ Çϳª °¡Á®¿Â´Ù. mov byte [es:edi], al ; ¹®ÀÚ¸¦ È­¸é¿¡ ³ªÅ¸³½´Ù. inc edi ; 0ÀÌ ¾Æ´Ï¶ó¸é, edi ¸¦ 1 Áõ°¡½ÃÄÑ, mov byte [es:edi], 0x03 ; ¹®ÀÚÀÇ »ö°ú ¹è°æ»öÀÇ °ªÀ» ³Ö´Â´Ù. inc esi ; ´ÙÀ½ ¹®ÀÚ¸¦ ²¨³»±â À§ÇØ esi ¸¦ Çϳª Áõ°¡½ÃŲ´Ù. inc edi ; È­¸é¿¡ ´ÙÀ½ ¹®ÀÚ¸¦ ³ªÅ¸³»±â À§ÇØ edi¸¦ Áõ°¡½ÃŲ´Ù. or al, al jz printf_end jmp printf_loop ; ·çÇÁ¸¦ µ·´Ù. printf_end: pop es pop eax pop edi ret REGISTER :db "00000000",0 .str_eax db "EAX=0x",0 .str_ebx db "EBX=0x",0 .str_ecx db "ECX=0x",0 .str_edx db "EDX=0x",0 .str_esi db "ESI=0x",0 .str_edi db "EDI=0x",0 .str_ebp db "EBP=0x",0 .str_exp db "ESP=0x",0 .str_eip db "EIP=0x",0 .str_efl db "EFL=0x",0 ;============================================================= hexcode: db '0123456789ABCDEF' dump_string1: db ' == DUMP REGISTERS ==============' db '=================================',0 .line1: db ' = EAX = ' .reax: times 8 db 0 db ' EBX = ' .rebx: times 8 db 0 db ' ECX = ' .recx: times 8 db 0 db ' EDX = ' .redx: times 9 db 0 ;---------------------- .line2: db ' = EBP = ' .rebp: times 8 db 0 db ' ESP = ' .resp: times 8 db 0 db ' ESI = ' .resi: times 8 db 0 db ' EDI = ' .redi: times 9 db 0 ;------------------------- .line3: db ' = CS= ' .rcs: times 4 db 0 db ' DS= ' .rds: times 4 db 0 db ' ES= ' .res: times 4 db 0 db ' FS= ' .rfs: times 4 db 0 db ' GS= ' .rgs: times 4 db 0 db ' SS= ' .rss: times 4 db 0 times 4 db ' ' db 0 ;---------------------- .line4: db ' = EIP = ' .reip: times 8 db 0 db ' EFLAGS = ' .reflags: times 8 db 0 times 29 db ' ' db 0 dump_string1_end: ;================================================= dump_register: ; ; ·¹Áö½ºÅÍ ´ýÇÁ ; ¿øÀúÀÛÀÚ : Written by J. H. Lee. ; ; [ESP] = ss ; [ESP+4] = gs ; [ESP+8] = fs ; [ESP+12] = es ; [ESP+16] = ds ; [ESP+20] = esp ; [ESP+24] = edi ; [ESP+28] = esi ; [ESP+32] = ebp ; [ESP+36] = ebx ; [ESP+40] = edx ; [ESP+44] = ecx ; [ESP+48] = eax ; [ESP+52] = eflags ; [ESP+56] = cs ; [ESP+60] = eip ; -------------------------------------------- ; Update : sonumb ; date : 2008³â 1¿ù 10ÀÏ ¸ñ¿äÀÏ ¿ÀÈÄ 4:33:04 ; ³»¿ë : ÇѺûÃâÆÇ»ç, 'OS Ä¿³ÎÀÇ ±¸Á¶¿Í ¿ø¸®' ¿¡ ¸Â°Ô ¼öÁ¤ ; push cs pushfd push eax mov eax,esp push ecx push edx push ebx add eax,28+8 push ebp push esi push edi push eax ; push esp (call Àü ½ºÅà Æ÷ÀÎÅÍ À§Ä¡) push ds push es push fs push gs push ss ;-- Dump mov eax,[esp+48] mov edi,dump_string1.reax call dumpreg_32bit mov eax,[esp+36] mov edi,dump_string1.rebx call dumpreg_32bit mov eax,[esp+44] mov edi,dump_string1.recx call dumpreg_32bit mov eax,[esp+40] mov edi,dump_string1.redx call dumpreg_32bit mov eax,[esp+32] mov edi,dump_string1.rebp call dumpreg_32bit mov eax,[esp+20] mov edi,dump_string1.resp call dumpreg_32bit mov eax,[esp+28] mov edi,dump_string1.resi call dumpreg_32bit mov eax,[esp+24] mov edi,dump_string1.redi call dumpreg_32bit mov eax,[esp+56] mov edi,dump_string1.rcs call dumpreg_16bit mov eax,[esp+16] mov edi,dump_string1.rds call dumpreg_16bit mov eax,[esp+12] mov edi,dump_string1.res call dumpreg_16bit mov eax,[esp+8] mov edi,dump_string1.rfs call dumpreg_16bit mov eax,[esp+4] mov edi,dump_string1.rgs call dumpreg_16bit mov eax,[esp] mov edi,dump_string1.rss call dumpreg_16bit mov eax,[esp+52] mov edi,dump_string1.reflags call dumpreg_32bit mov eax,[esp+60] mov edi,dump_string1.reip call dumpreg_32bit ;--- print ---------------------------- mov eax, 160 mov esi,dump_string1 mov edi, 80*2*20 + 2*11 ; Ãâ·Â À§Ä¡. È­¸é ³¡¿¡¼­ 5¹ø° ÁÙ call printf mov esi,dump_string1.line1 add edi, eax ; ÇÑ ¶óÀÎ Áõ°¡. call printf mov esi,dump_string1.line2 add edi, eax call printf mov esi,dump_string1.line3 add edi, eax call printf mov esi,dump_string1.line4 add edi, eax call printf add esp,24 pop edi pop esi pop ebp pop ebx pop edx pop ecx pop eax add esp,8 ret ;================================================= ;================================================= PrintHex: ; -- edi : È­¸é À§Ä¡. ; -- eax : value push edi mov edi, REGISTER call dumpreg_32bit lea esi, [REGISTER] pop edi call printf ret ;================================================ ;================================================= PrintDbg: ; -- Debug ¹®ÀÚ¿­ Ãâ·Â ; -- ·¹Áö½ºÅÍ ´ýÇÁ Ãâ·Â À­ÀÚ¸®¿¡ Ãâ·Â.. push esi push edi msg_dbg db " ** Debug : 0 **",0 lea esi, [msg_dbg] mov edi, 80*2*19+ 2*60 call printf cmp byte [msg_dbg+12], '9' jnz .inc mov byte [msg_dbg+12], '0' jmp .end .inc: inc byte [msg_dbg+12] .end: pop edi pop esi ret ;=============================================== ;================================================= Delay_msec: ; -- ¹Ð¸® ¼¼ÄÁµå ´ÜÀ§·Î µô·¹ÀÌ ; -- ecx : msec .lp: call .subDelay loop .lp ret .subDelay: push ecx mov ecx, 0xaafff .@lp: nop nop nop loop .@lp pop ecx ret ;=============================================== ;================================================= dumpreg_32bit: ; 32ºñÆ® dump ; IN : eax = value, edi = output address ; Destroyed : eax,bl,ecx,edx push eax push ebx push ecx push edx mov ecx,8 .dumprun: movzx edx,al and dl,0xf mov bl,[hexcode+edx] shr eax,4 mov [edi+ecx-1],bl loop .dumprun pop edx pop ecx pop ebx pop eax ret ;================================================= ;================================================= dumpreg_16bit: ; 16ºñÆ® dump ; IN : ax = value, edi = output address ; Destroyed ; eax,bl,ecx,edx push ebx push ecx push edx mov ecx,4 .dumprun: movzx edx,al and dl,0xf mov bl,[hexcode+edx] shr eax,4 mov [edi+ecx-1],bl loop .dumprun pop edx pop ecx pop ebx ret ;================================================= dump_msginit: ; Ãʱâ Ãâ·Â ¸Þ½ÃÁö : ÁÖ¼Ò Áõ°¡·®. .line1: db ' ADDR HEX ASCII ',0 .line2: db '------------ -------------------------------------------- -------------------',0 .endl: db '------------ -------------------------------------------- -------------------',0 .end: dump_msgdata: ; °¢ ÁÙº°·Î Ãâ·ÂÇÒ ¸Þ½ÃÁö .line1: db ' 0x' .str_addr: times 14 db ' ' .str_hex: times 44 db ' ' .str_ascii: times (18) db ' ' db 0 .end: ;================================================= dump_memory: ; ESI = ´ýÇÁÇÒ µ¥ÀÌÅÍ ÁÖ¼Ò ; word ´ÜÀ§·Î 3ÁÙ¸¸ Ãâ·Â ; ; %define STACKVARS 4 ; ·¹Áö½ºÅÍ ½ºÅÃÀ¸·Î ¹Ð¾î³Ö±â push eax push ebx push ecx push edx push ebp push esi push edi %if STACKVARS==0 sub esp,STACKVARS %endif ; Ãʱ⠸޽ÃÁö Ãâ·Â push esi mov eax , 80*2*1 lea esi, [dump_msginit.line1] mov edi,0 ; EDX = Ãâ·Â·®(¹ÙÀÌÆ®) call printf lea esi, [dump_msginit.line2] ; ECX = Ãâ·ÂÁÖ¼Ò mov edi,eax call printf pop esi ; 3-line counter mov ecx, 3 mov eax , 80*2*1 .loop: call sub_dump_mem add esi,0x10 push esi add eax, 160 ; È­¸éÃâ·ÂÀÛ¾÷ ¼öÇà lea esi,[dump_msgdata] mov edi,eax call printf pop esi loop .loop ; ¸¶Áö¸· ÁÙ Ãâ·Â lea esi,[dump_msginit.endl] add edi,160 call printf ; ½ºÅÿ¡ µé¾î°£ ·¹Áö½ºÅÍ º¹±¸ %if STACKVARS==0 add esp,STACKVARS %endif pop edi pop esi pop ebp pop edx pop ecx pop ebx pop eax ret %undef STACKVARS ;======================================= sub_dump_mem: ; -- esi : ´ýÇÁÇÒ ÁÖ¼Ò ; -- pushad pushfd .repeat: ; ÁÖ¼Ò °ª ¹®ÀÚ·Î ¹Ù²Ù±â. mov eax, esi lea edi, [dump_msgdata.str_addr] call dumpreg_32bit ; ascii ÀúÀå Çϱâ mov ecx, 16 lea edi,[dump_msgdata.str_ascii] .dump_ascii: mov al, byte[esi+ecx-1] cmp al, ' ' jae .cmp_exclamation jmp .invalid_char .cmp_exclamation: cmp al, '~' jae .invalid_char ; valid_char mov byte[edi+ecx-1], al jmp .end_dump_ascii .invalid_char: mov byte[edi+ecx-1], '.' .end_dump_ascii: loop .dump_ascii ; data¸¦ ¹®ÀÚ·Î ¹Ù²Ù¾îÁÖ±â lea edi,[dump_msgdata.str_hex] mov ecx, 4 .rep_hex: mov eax, dword[esi] call dumpreg_16bit add edi, 5 call dumpreg_16bit add edi, 5 add esi, 4 loop .rep_hex popfd popad ret ;===================================================