home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_02_06 / 2n06034a < prev    next >
Text File  |  1991-04-11  |  4KB  |  122 lines

  1.  
  2.                Listing 1, Initialization Interface
  3.                -----------------------------------
  4.  
  5. /*
  6. **  INIT.C
  7. **  Initialization Interface Module
  8. **  for the Non-Intrusive Monitor
  9. **  (to be linked into the TSR)
  10. **
  11. **  Written in MicroSoft C version 6.00
  12. **  Build String:
  13. **    cl demo.c init.c
  14. **
  15. **  Written By:  John R. Naleszkiewicz
  16. **        Date:  March 15, 1991
  17. **     Version:  1.00
  18. */
  19.  
  20. #include <stdio.h>
  21. #include <dos.h>
  22. #include <process.h>
  23.  
  24.  
  25. /* the interrupt vector number used to gain entry into TSR */
  26. #define  INT_VECTOR    0x68
  27.  
  28. /* The entry point function's prototype statement */
  29. void _interrupt far TSR_entry( unsigned _es, unsigned _ds,
  30.                                unsigned _di, unsigned _si,
  31.                                unsigned _bp, unsigned _sp,
  32.                                unsigned _bx, unsigned _dx,
  33.                                unsigned _cx, unsigned _ax,
  34.                                unsigned _ip, unsigned _cs,
  35.                                unsigned flags );
  36.  
  37. /* place to save the old interrupt vector */
  38. void     (_interrupt _far *oldVector)(void);
  39.  
  40. /* The variable declarations to be monitored */
  41. extern int      every_tick;
  42. extern int      every_sec;
  43. extern int      every_3_sec;
  44. extern long     long_every_10_sec;
  45. extern char     alphabet;
  46. extern char     * special_string;
  47.  
  48. /* This structure defines which variables are monitored */
  49. static struct Variable_Struct {
  50.   char far * name;           /*  Far Pointer to Variable Name  */
  51.   unsigned char type;        /*  Variable Type  */
  52.   unsigned char indirect;    /*  Indirection Count  */
  53.   unsigned short ind_flag;   /*  Indirection Type Flag  */
  54.   void far * var;            /*  Far Pointer to Variable  */
  55. }  element[] = {
  56.   "every_tick",        2, 0, 0, &every_tick,
  57.   "every_sec",         2, 0, 0, &every_sec,
  58.   "every_3_sec",       2, 0, 0, &every_3_sec,
  59.   "long_every_10_sec", 3, 0, 0, &long_every_10_sec,
  60.   "alphabet",          0, 0, 0, &alphabet,
  61.   "special_string",    1, 1, 0, &special_string,
  62. };
  63.  
  64.  
  65. /* NOTICE: the register order is different for Turbo C */
  66.  
  67. void _interrupt far TSR_entry( unsigned _es, unsigned _ds,
  68.                                unsigned _di, unsigned _si,
  69.                                unsigned _bp, unsigned _sp,
  70.                                unsigned _bx, unsigned _dx,
  71.                                unsigned _cx, unsigned _ax,
  72.                                unsigned _ip, unsigned _cs,
  73.                                unsigned flags )
  74. {
  75.   if( oldVector != NULL )
  76.     oldVector();  /* invoke the old vector first */
  77.  
  78.   /* Function 0, Data Block Format ID Number */
  79.   if( _ax == 0 )
  80.     _ax = 01;
  81.  
  82.   /* Function 1, Number of Variables being Monitored */
  83.   else if( _ax == 1 )
  84.     _ax = (sizeof(element) / sizeof(struct Variable_Struct));
  85.  
  86.   /* Function 2, Address of the Variable_Struct Array */
  87.   else if( _ax = 2 ) {
  88.     _ax = ((long) &element & 0xffff);
  89.     _dx = ((long) &element >> 16) & 0xffff;
  90.   }
  91. }
  92.  
  93.  
  94. static int hooked = 0;
  95.  
  96. void entry_hook()
  97. {
  98.   if( !hooked ) {
  99.     /* Get the old interrupt vector */
  100.     oldVector = _dos_getvect( INT_VECTOR );  
  101.  
  102.     /* Set the interrupt vector to the new function */
  103.     _dos_setvect( INT_VECTOR, TSR_entry );
  104.  
  105.     /* Set the Hooked Flag */
  106.     hooked = 1;
  107.   }
  108. }
  109.  
  110. void entry_unhook()
  111. {
  112.   if( hooked ) {
  113.     /* Restore the old interrupt vector before quiting */
  114.     _dos_setvect( INT_VECTOR, oldVector );
  115.  
  116.     /* Reset the Hooked Flag */
  117.     hooked = 0;
  118.   }
  119. }
  120.  
  121.  
  122.