⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tsrlist.c

📁 Dos6.0
💻 C
📖 第 1 页 / 共 2 页
字号:
/*********************************************************************
 * Microsoft Diagnostics Version 2.0
 *
 * A diagnostic utility to detect as much useful information about a
 *   customer's computer system as is possible.
 *
 * Microsoft Diagnostics:  We detect the World.
 *
 * TSRLIST.C - TSR Program detection routines.
 *********************************************************************/


/* Include Files */

#include "msd.h"


/* Made global to this file.  This prevents filling the structure with */
/*   more TSR info than was previously allocated (on the extremely odd */
/*   case of finding more TSRs when we actually get the driver info    */
/*   than when we counted up how many there were.  Under multitasking  */
/*   systems, the addition of a new TSR installing while this program  */
/*   is running is a rare, though potential, possibility.              */

WORD wTsrCount = 0;        /* The number of TSRs installed in memory */


/*********************************************************************
 * GetTsrInfoSize - Gets number of bytes required to store the data
 *                  about the TSRs installed in the system.
 *
 * Returns:  The bytes required for the structure.
 *********************************************************************/

WORD GetTsrInfoSize (VOID)
{
  CHAR FAR * fpMcbHeader    = NULL;   /* Pointer to the MCB header         */
  CHAR FAR * fpDeviceMemory = NULL;   /* Pointer into device driver memory */
  DWORD      dwNextDeviceMemory = 0;  /* Pointer into next device driver   */
                                      /*   memory                          */
  DWORD      dwNextMcbHeader = 0;     /* Pointer to next MCB header        */
  WORD FAR * fwWordPointer  = NULL;   /* WORD pointer to obtain WORD data  */
                                      /*   from the MCB.                   */
  WORD wMcbParagraphs = 0;            /* Size of the MCB in paragraphs     */
  BOOL fEndOfList = FALSE;            /* TRUE when last MCB accounted for  */


  /* Zero out the TSR count */
  wTsrCount = 0;

  /* Add the UMB chain to the DOS MCB chain */
  LinkUmbToDosChain (TRUE);

  /* Point to the first MCB */

  fpMcbHeader = FindFirstMcbHeader();

  /* Count MCBs until the MCB type is 'Z'  */
  /*   ('Z' signifies the end of the list) */

  while (fEndOfList == FALSE)
    {
      ++wTsrCount;

      /* Get the size of the MCB */

      fwWordPointer  = (WORD FAR *) (fpMcbHeader + 1);
      wMcbParagraphs = fwWordPointer[1];

      /* Determine if this was the last MCB */

      if (*fpMcbHeader == 'Z')
        fEndOfList = TRUE;
      else
        {
          /* Determine if there are device drivers in this list */
          if (wDosMajor >= 4 && wDosMajor < 10 &&
              fpMcbHeader[8] == 'S' && fpMcbHeader[9] == 'D')
            {
              fpDeviceMemory = (CHAR FAR *)
                             ((((DWORD) FP_SEG (fpMcbHeader) + 1) << 16) + 0);

              /* Is this a valid DOS data area subsegment control block */
              while (strchr ("DEIFXCBLS", fpDeviceMemory[0]))
                {
                  /* If this is one we are interested in, */
                  /*   bump the TSR count                 */
                  /* if (fpDeviceMemory[0] == 'D' || fpDeviceMemory[0] == 'I') */
                    ++wTsrCount;

                  /* Point to the next device */
                  fwWordPointer      = (WORD FAR *) (fpDeviceMemory + 1);
                  dwNextDeviceMemory = *fwWordPointer;
                  fwWordPointer      = (WORD FAR *) (fpDeviceMemory + 3);
                  dwNextDeviceMemory += *fwWordPointer;
                  fpDeviceMemory     = (CHAR FAR *) (dwNextDeviceMemory << 16);
                }
            }

          /* Point to the next MCB */
          dwNextMcbHeader = (DWORD) fpMcbHeader +
                            ((DWORD) (wMcbParagraphs + 1) << 16);
          fpMcbHeader     = (CHAR FAR *) dwNextMcbHeader;
        }
    }

  /* Account for the zeroed out TSR record at the end of the struct */
  ++wTsrCount;

  /* Set the UMB/DOS MCB chain back to normal */
  LinkUmbToDosChain (FALSE);

  /* Return the number of bytes required to store the structure */
  return (wTsrCount * sizeof (TSR_PROGRAMS_STRUCT));
}


/*********************************************************************
 * GetTsrInfo - Fills the TSR_PROGRAMS_STRUCT with information about
 *              the TSR programs installed in the system.
 *
 * Returns:  The bytes required for the structure.
 *********************************************************************/

BOOL GetTsrInfo (TSR_PROGRAMS_STRUCT *pTsrStruct, BOOL fMinimumInfo)
{
  CHAR FAR * fpMcbHeader     = NULL;  /* Pointer to the MCB header         */
  DWORD      dwNextMcbHeader = 0;     /* Pointer to next MCB header        */
  CHAR FAR * fpPspAddress    = NULL;  /* Address of the MCB's PSP          */
  CHAR FAR * fpParentPspAddress = NULL; /* Address of parent's PSP         */
  CHAR FAR * fpTsrName       = NULL;  /* Points to TSR program's name      */
                                      /*   environment (for program name)  */
  CHAR FAR * fpCommandLine   = NULL;  /* Command line parameters           */
  WORD wMcbParagraphs        = 0;     /* Size of the MCB in paragraphs     */

  CHAR FAR * fpDeviceMemory  = NULL;  /* Pointer into device driver subMCB */
  CHAR FAR * fpDeviceStruct  = NULL;  /* Pointer to device driver itself   */
  DWORD      dwNextDeviceMemory = 0;  /* Pointer into next device driver   */
                                      /*   memory                          */
  WORD FAR * fwWordPointer   = NULL;  /* WORD pointer to obtain WORD data  */
                                      /*   from the MCB.                   */
  WORD i = 0;                         /* Looping variable                  */
  WORD wIndex;                        /* Index to structure                */
  BOOL fEndOfList = FALSE;            /* TRUE when last MCB accounted for  */
  WORD wCharCount = 0;                /* Number of characters in the       */
                                      /*   command line.                   */


  /* There is no minimum info to return from this routine */

  if (fMinimumInfo)
    return (FALSE);


  /* Add the UMB chain to the DOS MCB chain */
  LinkUmbToDosChain (TRUE);

  /* Point to the first MCB */
  fpMcbHeader = FindFirstMcbHeader();

  /* Count MCBs until the MCB type is 'Z'  */
  /*   ('Z' signifies the end of the list) */

  for (wIndex = 0; wIndex < wTsrCount - 1 && fEndOfList == FALSE; ++wIndex)
    {
      /* Store the address of the MCB */

      pTsrStruct[wIndex].wAddress = FP_SEG (fpMcbHeader);


      /* Get the size of the MCB */

      fwWordPointer  = (WORD FAR *) (fpMcbHeader + 1);
      wMcbParagraphs = fwWordPointer[1];

      pTsrStruct[wIndex].dwBlockSize = (DWORD) wMcbParagraphs << 4;

      /* Caluclate PSP and parent's PSP */

      fpPspAddress  = (CHAR FAR *) ((DWORD) fwWordPointer[0] << 16);
      fwWordPointer = (WORD FAR *) (fpPspAddress + 16);
      fpParentPspAddress = (CHAR FAR *) ((DWORD) *fwWordPointer << 16);


      /* Get the MCB's Owner's name */

      /* If the PSP Segment is 0000H it's free,     */
      /*   if it's 0008H, it's the DOS System Area. */

      if (FP_SEG (fpPspAddress) == 0x0000)
        {
          strcpy (pTsrStruct[wIndex].szTsrName, pszFreeMemory);
          pTsrStruct[wIndex].szParameters[0] = '\0';
        }
      else if (FP_SEG (fpPspAddress) == 0x0008)
        {
          /* Determine if it is the device driver area, etc */

          if (wDosMajor >= 4 && wDosMajor < 10)
            {
              /* "SC" is System Code / Locked out UMBs */
              if (wDosMajor >= 5 &&
                  fpMcbHeader[8] == 'S' && fpMcbHeader[9] == 'C')
                {
                  /* If the address + block size > A0000, it's */
                  /*   a locked out region.                    */

                  if (((DWORD) (pTsrStruct[wIndex].wAddress) << 4) +
                      pTsrStruct[wIndex].dwBlockSize > 0xA0000)
                    strcpy (pTsrStruct[wIndex].szTsrName, pszExcludedUmbArea);
                  else
                    strcpy (pTsrStruct[wIndex].szTsrName, pszDosSystemCode);
                  pTsrStruct[wIndex].szParameters[0] = '\0';
                }
              /* "SD" is System Data / Device Drivers, etc */
              else if (wDosMajor == 4 || (wDosMajor >= 5 &&
                       fpMcbHeader[8] == 'S' && fpMcbHeader[9] == 'D'))
                {
                  strcpy (pTsrStruct[wIndex].szTsrName, pszDosSystemData);
                  pTsrStruct[wIndex].szParameters[0] = '\0';

                  fpDeviceMemory = (CHAR FAR *)
                                 ((((DWORD) FP_SEG (fpMcbHeader) + 1) << 16) + 0);

                  /* Is this a valid DOS data area subsegment control block */
                  for (++wIndex;
                       strchr ("DEIFXCBLS", fpDeviceMemory[0]) &&
                       wIndex < wTsrCount - 1 && fEndOfList == FALSE;
                       ++wIndex)
                    {
                      pTsrStruct[wIndex].szParameters[0] = '\0';

                      switch (fpDeviceMemory[0])
                        {
                          case 'D':
                          case 'I':
                            /* If this is a device driver or installable */
                            /*   file system, put the device name and    */
                            /*   device filename into the structure.     */

                            /* Address */
                            fwWordPointer = (WORD FAR *) (fpDeviceMemory + 1);
                            pTsrStruct[wIndex].wAddress = *fwWordPointer;

                            /* Point to the Device Name */
                            fpDeviceStruct = (CHAR FAR *)
                                             (((DWORD) (*fwWordPointer)) << 16);

                            /* Size */
                            fwWordPointer = (WORD FAR *) (fpDeviceMemory + 3);
                            pTsrStruct[wIndex].dwBlockSize =
                                ((DWORD) (*fwWordPointer)) << 4;

                            /* Device Filename */
                            pTsrStruct[wIndex].szTsrName[0] = ' ';
                            pTsrStruct[wIndex].szTsrName[1] = ' ';
                            _fmemcpy (&(pTsrStruct[wIndex].szTsrName[2]),
                                      &fpDeviceMemory[8], 8);
                            pTsrStruct[wIndex].szTsrName[10] = '\0';

                            /* Device Name */
                            fwWordPointer = (WORD FAR *) (fpDeviceStruct + 4);
                            if (*fwWordPointer & 0x8000)
                              {
                                /* Character Device */

                                _fmemcpy (pTsrStruct[wIndex].szParameters,
                                          &fpDeviceStruct[10], 8);
                                pTsrStruct[wIndex].szParameters[8] = '\0';
                              }
                            else
                              {
                                /* Block Device */

                                strcpy (pTsrStruct[wIndex].szParameters,
                                        pszBlockDevice);
                              }

                            break;

                          case 'E':
                            strcpy (pTsrStruct[wIndex].szTsrName,
                                    pszDeviceAppenage);

                            /* Address */
                            fwWordPointer = (WORD FAR *) (fpDeviceMemory + 1);
                            pTsrStruct[wIndex].wAddress = *fwWordPointer;

                            /* Size */
                            fwWordPointer = (WORD FAR *) (fpDeviceMemory + 3);
                            pTsrStruct[wIndex].dwBlockSize =
                                ((DWORD) (*fwWordPointer)) << 4;

                            break;

                          case 'F':
                            strcpy (pTsrStruct[wIndex].szTsrName,
                                    pszFileHandles);

                            /* Address */
                            fwWordPointer = (WORD FAR *) (fpDeviceMemory + 1);
                            pTsrStruct[wIndex].wAddress = *fwWordPointer;

                            /* Size */
                            fwWordPointer = (WORD FAR *) (fpDeviceMemory + 3);
                            pTsrStruct[wIndex].dwBlockSize =
                                ((DWORD) (*fwWordPointer)) << 4;

                            break;

                          case 'X':
                            strcpy (pTsrStruct[wIndex].szTsrName,
                                    pszFCBS);

                            /* Address */
                            fwWordPointer = (WORD FAR *) (fpDeviceMemory + 1);
                            pTsrStruct[wIndex].wAddress = *fwWordPointer;

                            /* Size */
                            fwWordPointer = (WORD FAR *) (fpDeviceMemory + 3);
                            pTsrStruct[wIndex].dwBlockSize =
                                ((DWORD) (*fwWordPointer)) << 4;

                            break;

                          case 'C':
                          case 'B':
                            strcpy (pTsrStruct[wIndex].szTsrName,
                                    pszBuffers);

                            /* Address */
                            fwWordPointer = (WORD FAR *) (fpDeviceMemory + 1);
                            pTsrStruct[wIndex].wAddress = *fwWordPointer;

                            /* Size */
                            fwWordPointer = (WORD FAR *) (fpDeviceMemory + 3);
                            pTsrStruct[wIndex].dwBlockSize =
                                ((DWORD) (*fwWordPointer)) << 4;

                            break;

                          case 'L':
                            strcpy (pTsrStruct[wIndex].szTsrName,
                                    pszDirectories);

                            /* Address */
                            fwWordPointer = (WORD FAR *) (fpDeviceMemory + 1);
                            pTsrStruct[wIndex].wAddress = *fwWordPointer;

                            /* Size */
                            fwWordPointer = (WORD FAR *) (fpDeviceMemory + 3);
                            pTsrStruct[wIndex].dwBlockSize =
                                ((DWORD) (*fwWordPointer)) << 4;

                            break;

                          case 'S':
                            strcpy (pTsrStruct[wIndex].szTsrName,
                                    pszStacksArea);

                            /* Address */
                            fwWordPointer = (WORD FAR *) (fpDeviceMemory + 1);
                            pTsrStruct[wIndex].wAddress = *fwWordPointer;

                            /* Size */
                            fwWordPointer = (WORD FAR *) (fpDeviceMemory + 3);
                            pTsrStruct[wIndex].dwBlockSize =
                                ((DWORD) (*fwWordPointer)) << 4;

                            break;
                        }

                      /* Point to the next device */
                      fwWordPointer      = (WORD FAR *) (fpDeviceMemory + 1);
                      dwNextDeviceMemory = *fwWordPointer;
                      fwWordPointer      = (WORD FAR *) (fpDeviceMemory + 3);
                      dwNextDeviceMemory += *fwWordPointer;
                      fpDeviceMemory     = (CHAR FAR *) (dwNextDeviceMemory << 16);
                    }
                  --wIndex;
                }
              /* We'll call this the DOS System Area, otherwise */
              else
                {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -