www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/07/20/12:31:31

From: Jin <GoldCode AT yahoo DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Problem hooking DOS int 21h
Date: Mon, 20 Jul 1998 09:21:12 -0700
Lines: 79
Message-ID: <35B36E78.2BC87A6C@yahoo.com>
NNTP-Posting-Host: jinhehui.stanford.edu
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Hi:

I need to hook DOS interrupt before running other program, so I can
monitor
the program's console output without redirection (with redirection, the
output
will not be displayed on the console).  The problem is, after hooking
DOS,
the functions spawn*, exec* and system no longer work.

Is there anyone tell me how to make the following codes work?

Thanks in advance.


JIN


/***START test.c ***/

#include <dpmi.h>
#include <go32.h>
#include <crt0.h>
#include <stdlib.h>


int _crt0_startup_flags = _CRT0_FLAG_LOCK_MEMORY;


_go32_dpmi_seginfo  old_int21_vector;
_go32_dpmi_registers  my_int21_regs;
_go32_dpmi_seginfo  my_int21_info;

/*
 * This function is called only within our int 21h handler
 */
static
void call_dos(_go32_dpmi_registers *r)
{
 r->x.cs = old_int21_vector.rm_segment;
 r->x.ip = old_int21_vector.rm_offset;
 _go32_dpmi_simulate_fcall_iret(r);
}


int grab_dos()
{
 _go32_dpmi_get_real_mode_interrupt_vector(0x21, &old_int21_vector);
 my_int21_info.pm_offset = (int) call_dos;
 if(
_go32_dpmi_allocate_real_mode_callback_iret(&my_int21_info,&my_int21_regs)

    || _go32_dpmi_set_real_mode_interrupt_vector(0x21, &my_int21_info) )

 {
  return 1;
 }

 return 0;
}

void release_dos(void)
{
 _go32_dpmi_set_real_mode_interrupt_vector(0x21, &old_int21_vector);
 _go32_dpmi_free_real_mode_callback(&my_int21_info);
}


int main()
{
 if( grab_dos() == 0 ) {
  system("dir");
  release_dos();
 }
 return 0;
}



- Raw text -


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