// Author: Martin Lee #include <stdio.h> #include <conio.h> #include <dos.h> #define getvect(n) _dos_getvect(n) #define setvect(n,v) {\ _disable();\ _dos_setvect(n,v);\ _enable();\ } #define HOOKVECTOR 0x7F int sig; void interrupt (*origin_int)(); void interrupt handle_7Fh(void) { sig=1; //_chain_intr( origin_int); // not execute original vector } void hook_int(void) { origin_int = getvect(HOOKVECTOR); setvect (HOOKVECTOR, handle_7Fh); } void restore_int(void) { setvect(HOOKVECTOR,origin_int); } void main() { sig = 0; hook_int(); printf("Before int 7fh, sig = %d\n", sig); __asm int 7Fh printf("After int 7fh, sig = %d\n", sig); restore_int(); }
----------------------執行結果-----------------------------
Before int 7fh, sig = 0
After int 7fh, sig = 1