How to disable the keyboard and mouse via assembly

2019-09-25 07:27发布

I have tried to write an assembly code to hang the keyboard and mouse (I try with keyboard now) . I searched in everywhere nearly (in references and articles and the old topic here also) and almost all show the same code by fetch the address of INT 9 and create new interrupt then make it be called rather than the original interrupt(9) . That is my code i had written:

.model tiny    
.stack 100h
.data
    old_ISR dd ?
.code
main proc far
    mov ah,35h                ; get interrupt vector
    mov al,09                 ; for int 9  
    INT 21h  
    mov word ptr old_ISR,BX   ; address of original int9 saved  
    mov word ptr old_ISR,ES   ; in ES:BX
    mov ah,25h                ; set interrupt vector
    mov al,09h                ; for int 9
    mov DX,offset ISR         ;is pointing to my ISR
    INT 21h 

    mov ax,3100h       ; to make my program resident 
    mov dx,1           ; in the memory
    int 21h


ISR proc  
    push ax
    nop      ; do nothing
    pop  ax
    iret
ISR endp    

In ISR I do nothing because the main goal I aim to is to make the original int9 don't point to interrupt vector table that contain int9 but point to my ISR then the scancode will missed and that's what I want.... unfortunately for me that code does not work well at all and I don't know why! thanks for advise.

**************** Some modification ********************

.model tiny    
.stack 100h
.data
    old_ISR dd ?
.code
main proc far
    mov ax;@data  ;new modification
    mov ds,ax     ;new modification

    mov ah,35h                ; get interrupt vector
    mov al,09                 ; for int 9  
    INT 21h  
    mov word ptr old_ISR,BX   ; address of original int9 saved  
    mov word ptr old_ISR,ES   ; in ES:BX
    mov ah,25h                ; set interrupt vector
    mov al,09h                ; for int 9
    mov DX,offset ISR         ;is pointing to my ISR
    INT 21h 

    mov ax,3100h       ; to make my program resident 
    mov dx,1           ; in the memory
    int 21h
main endp  ; new modification

ISR proc  
    push ax
    nop      ; do nothing
    pop  ax
    iret
ISR endp
end          ; new modification

1条回答
做个烂人
2楼-- · 2019-09-25 08:05

For MSDOS/DOSBOX:

cli
mov al,2     ; disable IRQ 1
out 21h,al
sti

;------------- Main loop
P1:

in   al, 64h  ; get status
test al, 1
jz short NOKEY
test al, 20h  ; byte from PS2 mouse?
jnz short NOKEY
in   al, 60h
dec  al       ; exit if escape key pressed
jz HOME
; placeholder for checking more keys using a table of keys
NOKEY:

jmp P1
;------------------------
HOME:
cli
xor al, al    ; enable IRQ 1
out 21h, al
sti
mov ah, 1     ; clear keyboard buffer
int 16h
; placeholder for terminate program
查看更多
登录 后发表回答