www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/03/21/07:44:45

From: "A.Appleyard" <A DOT APPLEYARD AT fs2 DOT mt DOT umist DOT ac DOT uk>
To: DJGPP AT delorie DOT com
Date: Thu, 21 Mar 1996 12:31:31 GMT
Subject: Re: Hooking interrupts
Message-ID: <A692957842@fs2.mt.umist.ac.uk>

  I wrote (Hooking interrupts):-
> In djgpp, IS there an easy way of hooking an interrupt? ...
  Sorry: I just found an example in \djgpp\docs\djgpp\libc\libc.tex of how to
do this. I just wrote this. (I still use v1. Would it work under v2?)
  ............................................
#include<stdio.h>
#include<dpmi.h>
#include<go32.h>
#include<dos.h>
#include<pc.h>
#include<keys.h>
#define Regs _go32_dpmi_registers
#define Addr _go32_dpmi_seginfo
/*-----*//* grabbing the N interrupt */
Addr hook_interrupt(int N, void(*func)(Regs*)) {Addr old_handler,new_handler;
_go32_dpmi_get_protected_mode_interrupt_vector(N, &old_handler);
new_handler.pm_offset = (int)func; new_handler.pm_selector = _go32_my_cs();
_go32_dpmi_chain_protected_mode_interrupt_vector(N, &new_handler);
return old_handler;}
/*-----*/
void unhook_interrupt(int N, Addr*old_handler){
_go32_dpmi_set_protected_mode_interrupt_vector(0x21, old_handler);}
/*-----*/
unsigned int AX[2048]; volatile int call21 = 0;
void func(Regs*R) { AX[call21++]=R->x.ax; }
/*-----*/
main() {Addr old_handler; int i;
old_handler = hook_interrupt(0x21, func);
printf("printing this should get int21 called\n");
unhook_interrupt(0x21, &old_handler);
printf("%1d int21 calls:",call21);
for(i=0;i<call21;i++) printf(" 0x%04x",AX[i]); printf("\n");}
  ............................................
  and it duly printed
4 int21 calls: 0xff03 0x4a01 0x4400 0x4038
  which seem in that order to be turbo_assist(), change length of memory area,
get device info, print.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019