【问题标题】:How to disable the keyboard and mouse via assembly code如何通过汇编代码禁用键盘和鼠标
【发布时间】:2016-03-21 20:57:52
【问题描述】:

我尝试编写一个汇编代码来挂起键盘和鼠标(我现在尝试使用键盘)。我几乎到处搜索(在参考资料和文章以及这里的旧主题中)并且几乎所有都通过获取 INT 9 的地址并创建新的中断然后调用它而不是原始的 interrupt(9) 来显示相同​​的代码。那是我写的代码:

.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    

在 ISR 中我什么都不做,因为我的主要目标是使原始 int9 不指向包含 int9 的中断向量表,而是指向我的 ISR,然后扫描码将丢失,这就是我想要的... . 对我来说不幸的是,代码根本无法正常工作,我不知道为什么! 感谢您的建议。

****************一些修改********************

.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

【问题讨论】:

  • 我担心的一个问题是您是在尝试制作 EXE 程序还是 COM 程序。您使用的模型 TINY 暗示您可能正在生成一个 COM 程序(但您没有设置 COM 程序所需的 ORG 之类的 ORG 100h),但是您设置了一个仅适用于 EXE 的堆栈。您没有设置也表示 COM 程序的 DS 寄存器。你能告诉我们你用来组装和链接这段代码的命令吗?您打算制作 EXE 或 COM 程序吗?
  • 是的,您可能正在运行 16 位版本的 TASM。无法运行任何程序的 16 位版本。您需要从 DOSBox 之类的工具中运行 TASM。如果您运行的是 32 位版本的 Windows,您将能够运行它。但是,即使你确实让它工作了,如果你正在尝试这样做,它也不会禁用所有 Winodws 的键盘。
  • DOSBox 是一个软件(不是DOS 窗口)。您从哪里安装 TASM?
  • 组装不是问题。如果要禁用所有 Windows 8 的鼠标或键盘,则不能使用 DOS 程序来执行此操作(无论它们是用汇编还是其他语言编写的)。我认为你需要开始着眼于编写 Windows 软件,而不是 DOS。 DOS 程序无法接管所有 Windows 8(即使您使用的是 32 位版本)。 DOS 程序(在 320 位 Windows 上)只能在 DOS 会话中接管鼠标和键盘,仅此而已。在 64 位 Windows 上,DOS 程序甚至无法运行
  • 你可以找到很多 - 使用谷歌。

标签: assembly keyboard mouse dos interrupt


【解决方案1】:

对于 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

【讨论】:

  • 谢谢,但我不希望它仅用于 DOSBOX,但我希望它用于所有窗口。
  • @mostafayasin:你知道从 NT 派生的 Windows 版本是适当的保护模式操作系统,它不只是让用户程序挂钩中断向量,对吗?您需要编写内核模式设备驱动程序或其他东西。不过,这可能适用于在 Windows 下运行的 DOS 程序,在它们的模拟 DOS 环境中。
  • @PeterCordes 您可能对制作设备驱动程序有一些正确的说法,但为此我可以获得设备驱动程序来控制通过特定端口连接的特定设备,如果我编写了内核设备驱动程序将无法满足我的需求,因为我想在系统运行期间禁用和启用特定设备而无需重新启动操作系统。这可以通过 KMDF 实现吗?我不这么认为。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-10-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-06
  • 1970-01-01
  • 2015-09-03
相关资源
最近更新 更多