📄 ddpdb.c
字号:
char *p; int i; Trace("entering GetWin9xDeviceID... "); /* we want to look through the ENUM\BIOS, ENUM\ISAPNP, and ENUM\PCI * trees for devices of the DISPLAY class. For each display device * we find we will ask the Device manager if it is active. */ for (i = 0; i < ENUM_MAX; i++) { HKEY hBusKey; /* construct a string for the current key: */ strcpy(szCurrentKey, REGSTR_KEY_ENUM); strcat(szCurrentKey, "\\"); strcat(szCurrentKey, szEnum_Name[i]); Trace("\nopenining LOCAL_MACHINE key:"); Trace(szCurrentKey); /* start reading the devices */ if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, szCurrentKey, 0, KEY_READ, &hBusKey) == ERROR_SUCCESS) { ULONG32 dwDevNodeEnumIndex = 0; Trace("opened;"); /* Enumerate all of the devices on the bus */ while (1) { HKEY hDeviceNodeKey; memset(szCurrentDeviceNode, 0, sizeof(szCurrentDeviceNode)); cbData = sizeof(szCurrentDeviceNode) - 1; if (RegEnumKeyEx(hBusKey, dwDevNodeEnumIndex, szCurrentDeviceNode, &cbData, NULL, NULL, NULL, NULL) != ERROR_SUCCESS) break; /* construct a string for current device node: */ strcpy(szCurrentKey,REGSTR_KEY_ENUM); strcat(szCurrentKey, "\\"); strcat(szCurrentKey, szEnum_Name[i]); strcat(szCurrentKey, "\\"); strcat(szCurrentKey, szCurrentDeviceNode); Trace("opening device node:"); Trace(szCurrentKey); /* get the registry key for the current device node */ if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, szCurrentKey, 0, KEY_READ, &hDeviceNodeKey) == ERROR_SUCCESS) { ULONG32 dwHWDeviceEnumIndex = 0; Trace("opened;"); /* enumerate all of the hardware devices in this Device Node */ while (1) { HKEY hHWDeviceKey; int nBaseKeyLength; memset(szCurrentDevice, 0, sizeof(szCurrentDevice)); cbData = sizeof(szCurrentDevice) - 1; if (RegEnumKeyEx(hDeviceNodeKey, dwHWDeviceEnumIndex, szCurrentDevice, &cbData, NULL, NULL, NULL, NULL) != ERROR_SUCCESS) break; /* get the registry key for the current hardware device */ nBaseKeyLength = strlen(szCurrentKey); /* append currect device name: */ strcat(szCurrentKey, "\\"); strcat(szCurrentKey, szCurrentDevice); Trace("opening device named:"); Trace(szCurrentKey); if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, szCurrentKey, 0, KEY_READ, &hHWDeviceKey) == ERROR_SUCCESS) { Trace("opened;"); /* ask if this device is a "DISPLAY" device by checking it's class */ cbData = sizeof(szClass); szClass[0] = 0; Trace("quering class of this device: "); if (RegQueryValueEx(hHWDeviceKey, "Class", 0, &ulType, (LPBYTE) szClass, &cbData) == ERROR_SUCCESS) { Trace("obtained:"); Trace(szClass); /* is it Display??? */ if (!stricmp(szClass, "DISPLAY")) { Trace("looks like a display adapter!!"); /* if it is a display device then we want to find out if it is * the active device for this class. */ memset(szSoftwareKey, 0, sizeof(szSoftwareKey)); cbData = sizeof(szSoftwareKey) - 1; /* create a string for Device ID: */ strcpy(szDeviceID, szEnum_Name[i]); strcat(szDeviceID, "\\"); strcat(szDeviceID, szCurrentDeviceNode); strcat(szDeviceID, "\\"); strcat(szDeviceID, szCurrentDevice); Trace("quering device ID:"); Trace(szDeviceID); /* get the registry key name for the software key for the device, * if it is not null and this is the active device then we are done. */ if (RegQueryValueEx(hHWDeviceKey, "Driver", 0, &ulType, (LPBYTE) szSoftwareKey, &cbData) == ERROR_SUCCESS && szSoftwareKey[0] != '0' && DevNodeIsActive(szDeviceID)) /* Call Config Manager in 16-bit code */ { Trace("device found!!!:"); /* close all open keys and continue processing... */ RegCloseKey(hHWDeviceKey); RegCloseKey(hDeviceNodeKey); RegCloseKey(hBusKey); goto cont; } } } /* close hardware device key: */ RegCloseKey(hHWDeviceKey); } /* reset the key to the base for the next time through the loop: */ memset (szCurrentKey + nBaseKeyLength, 0, sizeof(szCurrentKey) - nBaseKeyLength); /* move to next device key */ dwHWDeviceEnumIndex ++; } /* close device node key: */ RegCloseKey(hDeviceNodeKey); } /* move to the next device node */ dwDevNodeEnumIndex ++; } /* close bus key: */ RegCloseKey(hBusKey); } } Trace("exiting GetWin9xDeviceID (device not found):"); /* not found: */ return FALSE;cont: /* get Vendor ID: */ if ((p = strstr(szDeviceID, "VEN_")) != 0) lpddID->dwVendorId = hex2uint (p + strlen("VEN_"), 4); /* get DeviceID: */ if ((p = strstr(szDeviceID, "DEV_")) != 0) lpddID->dwDeviceId = hex2uint (p + strlen("DEV_"), 4); /* get Revision #: */ if ((p = strstr(szDeviceID, "REV_")) != 0) lpddID->dwRevision = hex2uint (p + strlen("REV_"), 4); /* if we found the software key, we want to go get the Driver description * and the driver file name: */ /* create a software key string: */ strcpy(szCurrentKey, REGSTR_PATH_CLASS); strcat(szCurrentKey, "\\"); strcat(szCurrentKey, szSoftwareKey); Trace("opening software key:"); Trace(szCurrentKey); if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, szCurrentKey, 0, KEY_READ, &hSoftwareKey) == ERROR_SUCCESS) { /* use external buffer: */ char* szAdapterString = lpddID->szDescription; cbData = MAX_DDDEVICEID_STRING; Trace("opened;"); /* query device description: */ RegQueryValueEx(hSoftwareKey, "DriverDesc", 0, &ulType, (LPBYTE)szAdapterString, &cbData); /* close software key; */ RegCloseKey(hSoftwareKey); } /* now look in the Default key for the driver file name */ strcat(szCurrentKey, "\\DEFAULT"); if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, szCurrentKey, 0, KEY_READ, &hSoftwareKey) == ERROR_SUCCESS) { char* szDisplayDriverName = lpddID->szDriver; cbData = MAX_DDDEVICEID_STRING; /* query driver name: */ RegQueryValueEx(hSoftwareKey, "drv", 0, &ulType, (LPBYTE)szDisplayDriverName, &cbData); /* close software key: */ RegCloseKey(hSoftwareKey); /* get the file version: */ if (GetSystemDirectory(pDLLPath, _MAX_PATH) != 0) { strcat(pDLLPath, "\\"); strcat(pDLLPath, szDisplayDriverName); Trace("trying to get a file version:"); /* query file version: */ GetFileVersion(pDLLPath, lpddID); } } Trace("exiting GetWin9xDeviceID:"); return TRUE;}/*********************************** * Utilities: **************************************/#ifdef DUMP/* a simple database creation program: */int main (int argc, char *argv[]){ FILE *fp; int s; /* check arguments: */ if (argc < 2) { fprintf (stderr, "Use:\n\tDDPDB <file name>\n"); exit (EXIT_FAILURE); } /* create a file: */ if ((fp = fopen (argv[1], "wb+")) == NULL) { fprintf (stderr, "Cannot open database file.\n"); exit (EXIT_FAILURE); } /* calculate the size of file: */ s = 16 + DDPDB.dwNumProfiles * sizeof(DDDEVICEPROFILE); /* dump raw data: */ if (fwrite((void*)&DDPDB, 1, s, fp) != s) { fprintf (stderr, "Write error (out of disk space?).\n"); exit (EXIT_FAILURE); } /* close file: */ fclose(fp); exit (EXIT_SUCCESS);}#endif /* DUMP */#ifdef IMPORT/* a profile generation program: */int main (){ OSVERSIONINFO osVersion; LPDIRECTDRAW lpDD; LPDIRECTDRAW4 lpDD4; DDDEVICEIDENTIFIER ddID; /* DirectDraw & Win95 info */ char szChipType[MAXCHIPTYPE]; /* NT info */ /* try to load DirectDraw library: */ if (DirectDrawCreate (NULL, &lpDD, NULL) != DD_OK) { printf ("Cannot create DirectDraw object!"); exit(EXIT_FAILURE); } /* check if we are runnning NT: */ memset(&osVersion,0, sizeof(OSVERSIONINFO)); osVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); if (GetVersionEx(&osVersion) && osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT) { /* try to get WinNT device information: */ if (!GetWinNTDeviceID (&ddID, szChipType)) { fprintf (stderr, "Cannot get NT driver info\n"); exit (EXIT_FAILURE); } /* print header: */ printf ("\tVER_PLATFORM_WIN32_NT,\n"); } else { /* Win9x: */#ifndef IMPORT /* try to get DirectDraw device identifier: */ memset (&ddID, 0, sizeof (DDDEVICEIDENTIFIER)); if ( (IDirectDraw_QueryInterface(lpDD, &IID_IDirectDraw4, (void**)&lpDD4) != DD_OK || IDirectDraw4_GetDeviceIdentifier(lpDD4, &ddID, DDGDI_GETHOSTIDENTIFIER) != DD_OK) && /* try to gather Win9x device information manually: */ !GetWin9xDeviceID (&ddID)) { fprintf (stderr, "Cannot get Win9x driver info\n"); exit (EXIT_FAILURE); } /* print header: */ printf( "\tVER_PLATFORM_WIN32_WINDOWS,\n");#else printf( "Need more work to run this tool on win95 machines.....\n" );#endif } /* dump description: */ ddID.szDescription[MAXDESCRIPT-1] = '\0'; printf ("\t{\"%s\",\n", ddID.szDescription); /* dump driver: */ ddID.szDriver[MAXDRIVER-1] = '\0'; printf ("\t \"%s\",\n", ddID.szDriver); /* driver version: */ printf ("\t 0x%x,0x%x,\n", ddID.liDriverVersion.LowPart, ddID.liDriverVersion.HighPart); if (osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT) { /* dump: WinNT vars:*/ printf ("\t 0x%x, 0x%x, 0x%x, 0x%x, \n", *(DWORD*)(szChipType), *(DWORD*)(szChipType+4), *(DWORD*)(szChipType+8), *(DWORD*)(szChipType+12)); printf ("\t {0x%x,0x%x,0x%x,{0x%x,0x%x,0x%x,0x%x,0x%x,0x%x,0x%x,0x%x}}\n", *(DWORD*)(szChipType+16), *(WORD*)(szChipType+20), *(WORD*)(szChipType+22), szChipType[24], szChipType[25], szChipType[26], szChipType[27], szChipType[28], szChipType[29], szChipType[30], szChipType[31]); } else { /* dump: Win9x vars:*/ printf ("\t 0x%x, 0x%x, 0x%x, 0x%x, \n", ddID.dwVendorId, ddID.dwDeviceId, ddID.dwSubSysId, ddID.dwRevision); printf ("\t {0x%x,0x%x,0x%x,{0x%x,0x%x,0x%x,0x%x,0x%x,0x%x,0x%x,0x%x}}\n", ddID.guidDeviceIdentifier.Data1, ddID.guidDeviceIdentifier.Data2, ddID.guidDeviceIdentifier.Data3, ddID.guidDeviceIdentifier.Data4[0], ddID.guidDeviceIdentifier.Data4[1], ddID.guidDeviceIdentifier.Data4[2], ddID.guidDeviceIdentifier.Data4[3], ddID.guidDeviceIdentifier.Data4[4], ddID.guidDeviceIdentifier.Data4[5], ddID.guidDeviceIdentifier.Data4[6], ddID.guidDeviceIdentifier.Data4[7]); } exit (EXIT_SUCCESS);}#endif /* IMPORT *//* ddpdb.c -- end of file */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -