首页 > 编程 > ASM > 正文

汇编语言自定义int9中断程序

2019-11-10 18:47:50
字体:
来源:转载
供稿:网友
代码解释如下:
;改变int9中断例程改变它的中断处理程序assume cs:codestack segment	db 128 dup(0)stack endscode segment	start:			mov ax,stack				mov ss,ax				mov sp,128				call cpy_new_int9							;复制自定义的int9程序				call save_int9								;保存原有的int9程序的入口地址:cs:ip				call set_new_int9							;设置中断向量表loopInput:		mov ax,100h				jmp loopInput				call set_old_int9							;原来的int9的中断程序入口地址恢复				mov ax,4c00h				int 21h;========================================================	;恢复int9本来的中断向量表set_old_int9:	mov ax,0				mov es,ax				cli				mov Word ptr es:[9*4],[200h]				mov word ptr es:[9*4+2],[202h]				sti				ret;========================================================   ;设置新的中断向量表set_new_int9:	push ax				push es								mov ax,0				mov es,ax				cli											;屏蔽外中断				mov word ptr es:[9*4],7E00h				mov word ptr es:[9*4+2],0				sti				pop es				pop ax				ret;========================================================	;保存原来的int9中断程序的地址,ip与cs到0000:0200处save_int9:		push ax				push es				mov ax,0				mov es,ax				cli				push es:[9*4]				pop es:[200h]				push es:[9*4+2]				pop es:[202h]				sti				pop es				pop ax				ret;========================================================	;新的int9中断处理程序new_int9:		push ax				in al,60h									;读取60h号端口接受到的一个扫描码				pushf				call dword ptr cs:[200h]					;因为这段代码是要复制到0000:0200h,所以cs = 0000,将原来的int9的中断处理程序的地址保存到栈中				cmp al,3Bh									;按下的是否是F1键				jne new_int9Ret				call change_colornew_int9Ret:	pop ax				iret										;pop ip,pop cs,popf ,执行完这句,cs:ip = 0000:0200h,程序其实就去执行int9的中断处理程序去了		;========================================================change_color:	push ax				push es				push cx				push bx								mov ax,0B800h				mov es,ax				mov cx,2000				mov bx,1changeColor:	inc byte ptr es:[bx]				add bx,2				loop changeColor								pop bx				pop cx				pop es				pop ax				retnew_int9End:	nop						;========================================================	;复制int9程序,将ds:si处的程序复制到es:di处,cpy_new_int9:	mov ax,cs				mov ds,ax				mov si,offset new_int9				mov di,7E00h				mov ax,0				mov es,ax				mov cx, offset new_int9End - offset new_int9	;复制的次数				cld											;cf  = 0 ,每次操作后si、di递增				rep movsb				ret;========================================================			code endsend start
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选