Article View: comp.os.msdos.programmer
Article #943Re: Why can't I hook INT 21h???
From: Duncan Murdoch
Date: Mon, 17 Aug 1992 20:31
Date: Mon, 17 Aug 1992 20:31
41 lines
2372 bytes
2372 bytes
In article <eoq.25.0@vthnw.cvm.msu.edu> eoq@vthnw.cvm.msu.edu (Edward Quillen) writes:
>In article <14339@mindlink.bc.ca> Charlie_Hutchins@mindlink.bc.ca (Charlie Hutchins) writes:
>>Okay, maybe someone could help me here. I am trying to write a TSR
>>that hooks interrupt 21h but whenever I try and hook that vector I
>>get an invalid command.com error and my system crashes.
>>void interrupt new21handler(void)
>>{
>> (old21handler)();
>>}
>>
>Please post replies to this ? because I've always wanted to hook INT 21h
>but have never been able to. Thanks!!!
This is the wrong way to intercept a service interrupt. Service interrupts
take arguments in the registers (and sometimes on the stack, but no INT
21h interrupts do this) and return results in the registers (and sometimes
on the stack).
The new21handler above probably changes the values in several registers
before the call, so it'll pass the wrong request to the old handler. It
restores the old register values from the stack when it returns; this wipes
out the result from the service.
Intercepting service interrupts is tricky. I've no idea how to do it in C,
but the basic idea is the following:
1. On entry, save the registers, and do any preprocessing.
2. Restore the registers; if necessary, restore the stack; call the
old handler. Note that if parameters are being passed on the stack,
you need to do some fiddling here to do the call without messing
up the stack frame.
3. When the old handler returns, save the registers, and do any
postprocessing.
4. Restore the returned register values, and return to the original
caller. You have to handle this return carefully: use RETF 2, not
IRET. Otherwise, you'll lose any status information being returned
in the flags.
Duncan Murdoch
dmurdoch@mast.queensu.ca
Technical Details
Message-ID:
<dmurdoch.46.714083466@mast.queensu.ca>Path:
arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!torn!news.ccs.queensu.ca!mast.queensu.ca!dmurdochReferences:
<14339@mindlink.bc.ca> <eoq.25.0@vthnw.cvm.msu.edu>Show Full Headers
Complete Article Headers
Newsgroups: comp.os.msdos.programmer Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!torn!news.ccs.queensu.ca!mast.queensu.ca!dmurdoch From: dmurdoch@mast.queensu.ca (Duncan Murdoch) Subject: Re: Why can't I hook INT 21h??? Message-ID: <dmurdoch.46.714083466@mast.queensu.ca> Lines: 41 Sender: news@knot.ccs.queensu.ca (Netnews control) Organization: Queen's University References: <14339@mindlink.bc.ca> <eoq.25.0@vthnw.cvm.msu.edu> Date: Mon, 17 Aug 1992 20:31:06 GMT