home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 4.ddi / TOOLS.4 / TCTSRC1.EXE / ISSENSE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  2.7 KB  |  96 lines

  1. /**
  2. *
  3. * Name        issense -- Detect an installed interrupt service routine
  4. *               (ISR)
  5. *
  6. * Synopsis    pctrl = issense(ptr,pident);
  7. *
  8. *        ISRCTRL far *pctrl
  9. *                  Address of ISR control block, or
  10. *                  (FARNIL) if not found.
  11. *        void far *ptr      Far pointer to potential ISR entry point.
  12. *        char *pident      Pointer to array of 16 bytes of
  13. *                  identifying information
  14. *
  15. * Description    This function examines the contents of memory pointed to
  16. *        by an interrupt vector to see whether it contains a
  17. *        particular Turbo C TOOLS, LIGHT TOOLS, or C TOOLS PLUS
  18. *        ISR control block.  If so, the function returns the
  19. *        address of the found ISR control block; if not, the
  20. *        function returns FARNIL.
  21. *
  22. *        The ISR control block contains the information necessary
  23. *        to disable the ISR and to remove the program that
  24. *        contains it.
  25. *
  26. * Limitation    This version does NOT trace chains of "cascaded" ISRs.
  27. *        That is, if the ISR pointed to by ptr is not the desired
  28. *        ISR but merely passes control to the desired ISR, the
  29. *        desired ISR will not be found.
  30. *
  31. * Returns    pctrl          Address of ISR control block, or
  32. *                  FARNIL if not found.
  33. *
  34. * Version    6.00 (C)Copyright Blaise Computing Inc. 1986,1987,1989
  35. *
  36. **/
  37.  
  38. #include <dos.h>
  39. #include <string.h>
  40.  
  41. #include <bintrupt.h>
  42.  
  43. ISRCTRL far *issense(ptr,pident)
  44. void far   *ptr;
  45. const char *pident;
  46. {
  47.     unsigned int offset;
  48.     ISRCTRL far *ptest;
  49.     int      i;
  50.  
  51.     if (ptr == FARNIL)
  52.     return FARNIL;
  53.  
  54.     offset = utoff(ptr);
  55.  
  56.     /* Make sure that the control block does not straddle a segment   */
  57.     /* boundary.  Notice that this computation requires that          */
  58.     /* sizeof(ISRCTRL) be at least 2 (which it is).              */
  59.  
  60.     if (   offset <  ICB_ENTRY_OFFSET
  61.     || offset >= (unsigned) 0xffff - sizeof(ISRCTRL) + 2)
  62.     return FARNIL;
  63.  
  64.     /* If this vector points to a Turbo C TOOLS, C TOOLS PLUS          */
  65.     /* or LIGHT TOOLS interrupt service routine, then the          */
  66.     /* actual item pointed to is at offset ICB_ENTRY_OFFSET in an     */
  67.     /* ISRCTRL structure.                          */
  68.  
  69.     ptest = uttofar (utseg(ptr),offset - ICB_ENTRY_OFFSET,ISRCTRL);
  70.  
  71.     /* Check for signature word in ISRCTRL structure.              */
  72.  
  73.     if (ptest->signature != ICB_SIGNATURE)
  74.     return FARNIL;
  75.  
  76.     /* Confirm signature by checking its one's-complement.            */
  77.  
  78.     if (ptest->sign2 != (unsigned) ~ICB_SIGNATURE)
  79.     return FARNIL;
  80.  
  81.     /* Check identifying "string".                                    */
  82.  
  83.     for (i = 0;
  84.      (i < sizeof (ptest->ident)) &&
  85.      (ptest->ident[i] == pident[i]);
  86.      i++)
  87.     ;
  88.  
  89.     if (i < sizeof (ptest->ident))
  90.     return FARNIL;
  91.  
  92.     /* Fall through:  all tests passed, this is the desired ISR.      */
  93.  
  94.     return ptest;
  95. }
  96.