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

📄 pnpdump.c

📁 ReactOS是一些高手根据Windows XP的内核编写出的类XP。内核实现机理和API函数调用几乎相同。甚至可以兼容XP的程序。喜欢研究系统内核的人可以看一看。
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
 * pnpdump - PnP BIOS information dumper
 */

#include <windows.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

#include <ntddk.h>

#include <pshpack1.h>

typedef struct _CM_PNP_BIOS_DEVICE_NODE
{
  USHORT Size;
  UCHAR Node;
  ULONG ProductId;
  UCHAR DeviceType[3];
  USHORT DeviceAttributes;
} CM_PNP_BIOS_DEVICE_NODE,*PCM_PNP_BIOS_DEVICE_NODE;

typedef struct _CM_PNP_BIOS_INSTALLATION_CHECK
{
  UCHAR Signature[4];             // $PnP (ascii)
  UCHAR Revision;
  UCHAR Length;
  USHORT ControlField;
  UCHAR Checksum;
  ULONG EventFlagAddress;         // Physical address
  USHORT RealModeEntryOffset;
  USHORT RealModeEntrySegment;
  USHORT ProtectedModeEntryOffset;
  ULONG ProtectedModeCodeBaseAddress;
  ULONG OemDeviceId;
  USHORT RealModeDataBaseAddress;
  ULONG ProtectedModeDataBaseAddress;
} CM_PNP_BIOS_INSTALLATION_CHECK, *PCM_PNP_BIOS_INSTALLATION_CHECK;

#include <poppack.h>

typedef struct _PNP_ID_NAME_
{
  char *PnpId;
  char *DeviceName;
} PNP_ID_NAME, *PPNP_ID_NAME;


static char Hex[] = "0123456789ABCDEF";

static PNP_ID_NAME PnpName[] =
{
  /* Interrupt Controllers */
  {"PNP0000", "AT Interrupt Controller"},
  {"PNP0001", "EISA Interrupt Controller"},
  {"PNP0002", "MCA Interrupt Controller"},
  {"PNP0003", "APIC"},
  {"PNP0004", "Cyrix SLiC MP Interrupt Controller"},

  /* Timers */
  {"PNP0100", "AT Timer"},
  {"PNP0101", "EISA Timer"},
  {"PNP0102", "MCA Timer"},

  /* DMA Controllers */
  {"PNP0200", "AT DMA Controller"},
  {"PNP0201", "EISA DMA Controller"},
  {"PNP0202", "MCA DMA Controller"},

  /* Keyboards */
  {"PNP0300", "IBM PC/XT Keyboard (83 keys)"},
  {"PNP0301", "IBM PC/AT Keyboard (86 keys)"},
  {"PNP0302", "IBM PC/XT Keyboard (84 keys)"},
  {"PNP0303", "IBM Enhanced (101/102 keys)"},
  {"PNP0304", "Olivetti Keyboard (83 keys)"},
  {"PNP0305", "Olivetti Keyboard (102 keys)"},
  {"PNP0306", "Olivetti Keyboard (86 keys)"},
  {"PNP0307", "Microsoft Windows(R) Keyboard"},
  {"PNP0308", "General Input Device Emulation Interface (GIDEI) legacy"},
  {"PNP0309", "Olivetti Keyboard (A101/102 key)"},
  {"PNP030A", "AT&T 302 keyboard"},
  {"PNP030B", "Reserved by Microsoft"},
  {"PNP0320", "Japanese 101-key keyboard"},
  {"PNP0321", "Japanese AX keyboard"},
  {"PNP0322", "Japanese 106-key keyboard A01"},
  {"PNP0323", "Japanese 106-key keyboard 002/003"},
  {"PNP0324", "Japanese 106-key keyboard 001"},
  {"PNP0325", "Japanese Toshiba Desktop keyboard"},
  {"PNP0326", "Japanese Toshiba Laptop keyboard"},
  {"PNP0327", "Japanese Toshiba Notebook keyboard"},
  {"PNP0340", "Korean 84-key keyboard"},
  {"PNP0341", "Korean 86-key keyboard"},
  {"PNP0342", "Korean Enhanced keyboard"},
  {"PNP0343", "Korean Enhanced keyboard 101b"},
  {"PNP0343", "Korean Enhanced keyboard 101c"},
  {"PNP0344", "Korean Enhanced keyboard 103"},

  /* Parallel Ports */
  {"PNP0400", "Standard LPT printer port"},
  {"PNP0401", "ECP printer port"},

  /* Serial Ports */
  {"PNP0500", "Standard PC COM port"},
  {"PNP0501", "16550A-compatible COM port"},
  {"PNP0510", "Generic IRDA-compatible port"},

  /* Harddisk Controllers */
  {"PNP0600", "Generic ESDI/ATA/IDE harddisk controller"},
  {"PNP0601", "Plus Hardcard II"},
  {"PNP0602", "Plus Hardcard IIXL/EZ"},
  {"PNP0603", "Generic IDE supporting Microsoft Device Bay Specification"},

  /* Floppy Controllers */
  {"PNP0700", "PC standard floppy disk controller"},
  {"PNP0701", "Standard floppy controller supporting MS Device Bay Specification"},

  /* obsolete devices */
  {"PNP0800", "Microsoft Sound System compatible device"},

  /* Display Adapters */
  {"PNP0900", "VGA Compatible"},
  {"PNP0901", "Video Seven VRAM/VRAM II/1024i"},
  {"PNP0902", "8514/A Compatible"},
  {"PNP0903", "Trident VGA"},
  {"PNP0904", "Cirrus Logic Laptop VGA"},
  {"PNP0905", "Cirrus Logic VGA"},
  {"PNP0906", "Tseng ET4000"},
  {"PNP0907", "Western Digital VGA"},
  {"PNP0908", "Western Digital Laptop VGA"},
  {"PNP0909", "S3 Inc. 911/924"},
  {"PNP090A", "ATI Ultra Pro/Plus (Mach 32)"},
  {"PNP090B", "ATI Ultra (Mach 8)"},
  {"PNP090C", "XGA Compatible"},
  {"PNP090D", "ATI VGA Wonder"},
  {"PNP090E", "Weitek P9000 Graphics Adapter"},
  {"PNP090F", "Oak Technology VGA"},
  {"PNP0910", "Compaq QVision"},
  {"PNP0911", "XGA/2"},
  {"PNP0912", "Tseng Labs W32/W32i/W32p"},
  {"PNP0913", "S3 Inc. 801/928/964"},
  {"PNP0914", "Cirrus Logic 5429/5434 (memory mapped)"},
  {"PNP0915", "Compaq Advanced VGA (AVGA)"},
  {"PNP0916", "ATI Ultra Pro Turbo (Mach64)"},
  {"PNP0917", "Reserved by Microsoft"},
  {"PNP0918", "Matrox MGA"},
  {"PNP0919", "Compaq QVision 2000"},
  {"PNP091A", "Tseng W128"},
  {"PNP0930", "Chips & Technologies Super VGA"},
  {"PNP0931", "Chips & Technologies Accelerator"},
  {"PNP0940", "NCR 77c22e Super VGA"},
  {"PNP0941", "NCR 77c32blt"},
  {"PNP09FF", "Plug and Play Monitors (VESA DDC)"},

  /* Peripheral Buses */
  {"PNP0A00", "ISA Bus"},
  {"PNP0A01", "EISA Bus"},
  {"PNP0A02", "MCA Bus"},
  {"PNP0A03", "PCI Bus"},
  {"PNP0A04", "VESA/VL Bus"},
  {"PNP0A05", "Generic ACPI Bus"},
  {"PNP0A06", "Generic ACPI Extended-IO Bus (EIO bus)"},

  /* System devices */
  {"PNP0800", "AT-style speaker sound"},
  {"PNP0B00", "AT Real-Time Clock"},
  {"PNP0C00", "Plug and Play BIOS (only created by the root enumerator)"},
  {"PNP0C01", "System Board"},
  {"PNP0C02", "General Plug and Play motherboard registers."},
  {"PNP0C03", "Plug and Play BIOS Event Notification Interrupt"},
  {"PNP0C04", "Math Coprocessor"},
  {"PNP0C05", "APM BIOS (Version independent)"},
  {"PNP0C06", "Reserved for identification of early Plug and Play BIOS implementation"},
  {"PNP0C07", "Reserved for identification of early Plug and Play BIOS implementation"},
  {"PNP0C08", "ACPI system board hardware"},
  {"PNP0C09", "ACPI Embedded Controller"},
  {"PNP0C0A", "ACPI Control Method Battery"},
  {"PNP0C0B", "ACPI Fan"},
  {"PNP0C0C", "ACPI power button device"},
  {"PNP0C0D", "ACPI lid device"},
  {"PNP0C0E", "ACPI sleep button device"},
  {"PNP0C0F", "PCI interrupt link device"},
  {"PNP0C10", "ACPI system indicator device"},
  {"PNP0C11", "ACPI thermal zone"},
  {"PNP0C12", "Device Bay Controller"},

  /* PCMCIA Controllers */
  {"PNP0E00", "Intel 82365-Compatible PCMCIA Controller"},
  {"PNP0E01", "Cirrus Logic CL-PD6720 PCMCIA Controller"},
  {"PNP0E02", "VLSI VL82C146 PCMCIA Controller"},
  {"PNP0E03", "Intel 82365-compatible CardBus controller"},

  /* Mice */
  {"PNP0F00", "Microsoft Bus Mouse"},
  {"PNP0F01", "Microsoft Serial Mouse"},
  {"PNP0F02", "Microsoft InPort Mouse"},
  {"PNP0F03", "Microsoft PS/2-style Mouse"},
  {"PNP0F04", "Mouse Systems Mouse"},
  {"PNP0F05", "Mouse Systems 3-Button Mouse (COM2)"},
  {"PNP0F06", "Genius Mouse (COM1)"},
  {"PNP0F07", "Genius Mouse (COM2)"},
  {"PNP0F08", "Logitech Serial Mouse"},
  {"PNP0F09", "Microsoft BallPoint Serial Mouse"},
  {"PNP0F0A", "Microsoft Plug and Play Mouse"},
  {"PNP0F0B", "Microsoft Plug and Play BallPoint Mouse"},
  {"PNP0F0C", "Microsoft-compatible Serial Mouse"},
  {"PNP0F0D", "Microsoft-compatible InPort-compatible Mouse"},
  {"PNP0F0E", "Microsoft-compatible PS/2-style Mouse"},
  {"PNP0F0F", "Microsoft-compatible Serial BallPoint-compatible Mouse"},
  {"PNP0F10", "Texas Instruments QuickPort Mouse"},
  {"PNP0F11", "Microsoft-compatible Bus Mouse"},
  {"PNP0F12", "Logitech PS/2-style Mouse"},
  {"PNP0F13", "PS/2 Port for PS/2-style Mice"},
  {"PNP0F14", "Microsoft Kids Mouse"},
  {"PNP0F15", "Logitech bus mouse"},
  {"PNP0F16", "Logitech SWIFT device"},
  {"PNP0F17", "Logitech-compatible serial mouse"},
  {"PNP0F18", "Logitech-compatible bus mouse"},
  {"PNP0F19", "Logitech-compatible PS/2-style Mouse"},
  {"PNP0F1A", "Logitech-compatible SWIFT Device"},
  {"PNP0F1B", "HP Omnibook Mouse"},
  {"PNP0F1C", "Compaq LTE Trackball PS/2-style Mouse"},
  {"PNP0F1D", "Compaq LTE Trackball Serial Mouse"},
  {"PNP0F1E", "Microsoft Kids Trackball Mouse"},
  {"PNP0F1F", "Reserved by Microsoft Input Device Group"},
  {"PNP0F20", "Reserved by Microsoft Input Device Group"},
  {"PNP0F21", "Reserved by Microsoft Input Device Group"},
  {"PNP0F22", "Reserved by Microsoft Input Device Group"},
  {"PNP0F23", "Reserved by Microsoft Input Device Group"},
  {"PNP0FFF", "Reserved by Microsoft Systems"},

  /* List Terminator */
  {NULL, NULL}
};


/* FUNCTIONS ****************************************************************/

static char *
GetDeviceName(char *PnpId)
{
  PPNP_ID_NAME IdName;

  IdName = PnpName;
  while (IdName->PnpId != NULL)
    {
      if (!strcmp(IdName->PnpId, PnpId))
	return IdName->DeviceName;

      IdName++;
    }

  return "Unknown Device";
}


LONG
GetPnpKey(PHKEY PnpKey)
{
  LONG lError;
  char szBuffer[80];
  HKEY hAdapterKey;
  HKEY hBusKey;
  DWORD dwBus;
  DWORD dwType;
  DWORD dwSize;

  *PnpKey = 0;

  lError = RegOpenKey(HKEY_LOCAL_MACHINE,
		      "HARDWARE\\DESCRIPTION\\System\\MultifunctionAdapter",
		      &hAdapterKey);
  if (lError != ERROR_SUCCESS)
    return 0;

  /* Enumerate buses */
  for (dwBus = 0; ; dwBus++)
    {
      sprintf(szBuffer, "%lu", dwBus);

      lError = RegOpenKey(hAdapterKey,
			  szBuffer,
			  &hBusKey);
      if (lError != ERROR_SUCCESS)
	{
	  RegCloseKey(hAdapterKey);
	  return lError;
	}

      dwSize = 80;
      lError = RegQueryValueEx(hBusKey,
			       "Identifier",
			       NULL,
			       &dwType,
			       (LPBYTE)szBuffer,
			       &dwSize);
      if (lError != ERROR_SUCCESS)
	{
	  RegCloseKey(hBusKey);
	  RegCloseKey(hAdapterKey);
	  return lError;
	}

      if (dwType == REG_SZ && stricmp(szBuffer, "pnp bios") == 0)
	{
	  *PnpKey = hBusKey;
	  RegCloseKey(hAdapterKey);
	  return ERROR_SUCCESS;
	}

      RegCloseKey(hBusKey);
    }

  return 1;
}


static VOID
PnpDecodeIrq(unsigned char *Ptr)
{
  USHORT IrqMask;
  int i;

  IrqMask = *Ptr;
  Ptr++;
  IrqMask |= (*Ptr << 8);

  printf("      IRQs:");

  for (i = 0; i < 16; i++)
    {
      if (IrqMask & (1 << i))
	{
	  printf(" %u", i);
	}
    }

  printf("\n");
}


static VOID
PnpDecodeDma(unsigned char *Ptr)
{
  unsigned char DmaChannel;
  unsigned char DmaStatus;
  int i;

  DmaChannel = *Ptr;
  Ptr++;
  DmaStatus = *Ptr;

  printf("      DMAs:");

  for (i = 0; i < 8; i++)
    {
      if (DmaChannel & (1 << i))
	{
	  printf(" %u", i);
	}
    }

  printf("\n");
}


static VOID
PnpDecodeIoPort(unsigned char *Ptr)
{
  USHORT MinBase;
  USHORT MaxBase;
  UCHAR Align;
  UCHAR Length;

  // Info = *Ptr;
  Ptr++;
  MinBase = *Ptr;
  Ptr++;
  MinBase += (*Ptr << 8);
  Ptr++;
  MaxBase = *Ptr;
  Ptr++;
  MaxBase += (*Ptr << 8);
  Ptr++;
  Align = *Ptr;
  Ptr++;
  Length = *Ptr;

  printf("  I/O Port descriptor\n");
  printf("    MinBase 0x%x  MaxBase 0x%x  Align %u  Length %u\n",
	 MinBase, MaxBase, Align, Length);
}


static VOID
PnpDecodeFixedIoPort(unsigned char *Ptr)
{
  USHORT IoPort;
  UCHAR Length;

  IoPort = *Ptr;
  Ptr++;
  IoPort += (*Ptr << 8);
  Ptr++;
  Length = *Ptr;

  printf("  Fixed I/O Port descriptor\n");
  printf("    PortBase 0x%hx  Length 0x%x\n",
	 IoPort, Length);

#if 0
  if (Length == 1)
    {
      printf("  Fixed location I/O Port descriptor: 0x%x\n",
	     IoPort);
    }
  else
    {
      printf("  Fixed location I/O Port descriptor: 0x%x - 0x%x\n",
	     IoPort,
	     IoPort + Length - 1);
    }
#endif
}


static VOID
PnpDecodeMemory16(unsigned char *Ptr)

⌨️ 快捷键说明

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