ReactOS  0.4.14-dev-323-g6fe6a88
GetDeviceIdentifier.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS DirectX
4  * FILE: dll/directx/ddraw/Ddraw/GetDeviceIdentifier.c
5  * PURPOSE: IDirectDraw7 Implementation
6  * PROGRAMMER: Magnus Olsen
7  *
8  */
9 
10 /* TODO
11  * We need adding digital signature detections for the drivers
12  * and count out which level the signtature driver got, the value
13  * shall be save to pDDDI->dwWHQLLevel, But I do not known how todo
14  * this part yet, That is only missing feature in this functions
15  *
16  * Write a UML digram for this api
17  */
18 
19 #include "rosdraw.h"
20 
21 #include <string.h>
22 
23 /* For DirectDraw 4 - 6 */
27 {
28  HRESULT retVal = DD_OK;
29  DDDEVICEIDENTIFIER2 pDDDI2;
30 
31  ZeroMemory(&pDDDI2,sizeof(DDDEVICEIDENTIFIER2));
32 
33  _SEH2_TRY
34  {
35  memcpy(&pDDDI2 , pDDDI, sizeof(DDDEVICEIDENTIFIER));
36 
38 
39  if (IsBadWritePtr(pDDDI, sizeof(DDDEVICEIDENTIFIER)))
40  {
41  retVal = DDERR_INVALIDPARAMS;
42  }
43  else
44  {
45  memcpy(pDDDI , &pDDDI2, sizeof(DDDEVICEIDENTIFIER) );
46  }
47  }
49  {
50  retVal = DD_FALSE;
51  }
52  _SEH2_END;
53 
54  return retVal;
55 }
56 
60 {
62 
63  BOOL found = FALSE;
64  DWORD iDevNum = 0;
65  DISPLAY_DEVICEA DisplayDeviceA;
66  HKEY hKey;
67  DWORD lpType = 0;
68  DWORD strSize = MAX_DDDEVICEID_STRING;
69  char *pdest;
70  char* pcCnvEnd;
71  long *lpdata;
72 
74 
76 
77  _SEH2_TRY
78  {
79  if ( (IsBadWritePtr( pDDDI, sizeof(DDDEVICEIDENTIFIER2) ) ) ||
81  {
82  retVal = DDERR_INVALIDPARAMS;
84  }
85 
86  /* now we can start getting the driver data */
87 
88  while (1)
89  {
90  ZeroMemory(&DisplayDeviceA,sizeof(DISPLAY_DEVICEA));
91 
92  DisplayDeviceA.cb = sizeof(DISPLAY_DEVICEA);
93 
94  if ( EnumDisplayDevicesA( NULL, iDevNum, &DisplayDeviceA, 0) == 0)
95  {
96  retVal = DDERR_INVALIDPARAMS;
97  break;
98  }
99 
100  if (_stricmp(DisplayDeviceA.DeviceName, This->lpLcl->lpGbl->cDriverName) != 0)
101  {
102  /* if we got another device like hardware mpeg decoder or video card or another drv */
103  found = TRUE;
104  }
105  else if (DisplayDeviceA.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
106  {
107  /* double check if it primary driver we just found */
108  if (!_stricmp( This->lpLcl->lpGbl->cDriverName, "DISPLAY"))
109  {
110  /* yeah we found it */
111  found = TRUE;
112  }
113  }
114 
115  if (found != FALSE)
116  {
117  /* we found our driver now we start setup it */
118  if (!_strnicmp(DisplayDeviceA.DeviceKey,"\\REGISTRY\\Machine\\",18))
119  {
120  if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, &DisplayDeviceA.DeviceKey[18], 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS )
121  {
122 
123  if (RegQueryValueExA(hKey, "InstalledDisplayDrivers",0, &lpType, (LPBYTE)pDDDI->szDriver, &strSize) != ERROR_SUCCESS)
124  {
126  }
127  else
128  {
129  strcat(pDDDI->szDriver,".dll");
130  }
131  RegCloseKey(hKey);
132  }
133 
134  strcpy( pDDDI->szDescription, DisplayDeviceA.DeviceString);
135  pDDDI->liDriverVersion.HighPart = 0;
136  pDDDI->liDriverVersion.LowPart = 0;
137 
138  pdest = strstr(DisplayDeviceA.DeviceID,"REV_");
139  pDDDI->dwRevision = strtol ( &pdest[4], &pcCnvEnd, 16);
140 
141  pdest = strstr(DisplayDeviceA.DeviceID,"SUBSYS_");
142  pDDDI->dwSubSysId = strtol ( &pdest[7], &pcCnvEnd, 16);
143 
144  pdest = strstr(DisplayDeviceA.DeviceID,"DEV_");
145  pDDDI->dwDeviceId = strtol ( &pdest[4], &pcCnvEnd, 16);
146 
147  pdest = strstr(DisplayDeviceA.DeviceID,"VEN_");
148  pDDDI->dwVendorId =strtol ( &pdest[4], &pcCnvEnd, 16);
149 
150  /* Count out the guidDeviceIdentifier */
151  memcpy(&pDDDI->guidDeviceIdentifier, &CLSID_DirectDraw,sizeof(GUID));
152 
153  pDDDI->guidDeviceIdentifier.Data1 ^= pDDDI->dwVendorId;
154 
155  lpdata = (long *)&pDDDI->guidDeviceIdentifier.Data2;
156  *lpdata ^= pDDDI->dwDeviceId;
157 
158  lpdata = (long *)&pDDDI->guidDeviceIdentifier.Data4;
159  *lpdata = (*lpdata ^ pDDDI->dwSubSysId) ^ pDDDI->liDriverVersion.LowPart;
160 
161  lpdata = (long *)&pDDDI->guidDeviceIdentifier.Data4[4];
162  *lpdata = (*lpdata ^ pDDDI->dwRevision) ^ pDDDI->liDriverVersion.HighPart;
163 
164  /* FIXME pDDDI->dwWHQLLevel
165  * we leave this with no informations, I do not known
166  * if program care for it, I mark this api done, and
167  * tested, no bugs was found in it
168  */
169  pDDDI->dwWHQLLevel = 0;
170  retVal = DD_OK;
171  }
172 
173  break;
174  }
175 
176  iDevNum++;
177  }
178 
179  }
181  {
182  retVal = DD_FALSE;
183  }
184  _SEH2_END;
185 
187  return retVal;
188 }
#define DX_WINDBG_trace()
Definition: rosdraw.h:262
CRITICAL_SECTION ddcs
Definition: main.c:14
LONG WINAPI RegQueryValueExA(_In_ HKEY hkeyorg, _In_ LPCSTR name, _In_ LPDWORD reserved, _Out_opt_ LPDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ LPDWORD count)
Definition: reg.c:4023
#define TRUE
Definition: types.h:120
#define MAX_DDDEVICEID_STRING
Definition: ddraw.h:201
BOOL NTAPI IsBadWritePtr(IN LPVOID lp, IN UINT_PTR ucb)
Definition: except.c:885
#define ERROR_SUCCESS
Definition: deptool.c:10
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
#define DDGDI_GETHOSTIDENTIFIER
Definition: ddraw.h:202
CHAR DeviceString[128]
Definition: wingdi.h:2806
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
LONG WINAPI RegOpenKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD ulOptions, _In_ REGSAM samDesired, _Out_ PHKEY phkResult)
Definition: reg.c:3331
#define ZeroMemory
Definition: winbase.h:1642
CHAR DeviceName[32]
Definition: wingdi.h:2805
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define _stricmp
Definition: cat.c:22
_SEH2_TRY
Definition: create.c:4250
HRESULT WINAPI Main_DirectDraw_GetDeviceIdentifier7(LPDDRAWI_DIRECTDRAW_INT This, LPDDDEVICEIDENTIFIER2 pDDDI, DWORD dwFlags)
#define DD_OK
Definition: ddraw.h:186
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
unsigned int BOOL
Definition: ntddk_ex.h:94
_Check_return_ _CRTIMP int __cdecl _strnicmp(_In_reads_or_z_(_MaxCount) const char *_Str1, _In_reads_or_z_(_MaxCount) const char *_Str2, _In_ size_t _MaxCount)
CHAR DeviceKey[128]
Definition: wingdi.h:2809
BOOL WINAPI EnumDisplayDevicesA(LPCSTR lpDevice, DWORD iDevNum, PDISPLAY_DEVICEA lpDisplayDevice, DWORD dwFlags)
Definition: display.c:23
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
struct _DISPLAY_DEVICEA DISPLAY_DEVICEA
#define DISPLAY_DEVICE_PRIMARY_DEVICE
Definition: wingdi.h:1397
char szDescription[MAX_DDDEVICEID_STRING]
Definition: ddraw.h:1346
LONG HRESULT
Definition: typedefs.h:77
#define WINAPI
Definition: msvc.h:8
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
HRESULT WINAPI Main_DirectDraw_GetDeviceIdentifier(LPDDRAWI_DIRECTDRAW_INT This, LPDDDEVICEIDENTIFIER pDDDI, DWORD dwFlags)
#define DD_FALSE
Definition: ddraw.h:187
char szDriver[MAX_DDDEVICEID_STRING]
Definition: ddraw.h:1345
_SEH2_END
Definition: create.c:4424
DWORD StateFlags
Definition: wingdi.h:2807
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
CHAR DeviceID[128]
Definition: wingdi.h:2808
_Check_return_ long __cdecl strtol(_In_z_ const char *_Str, _Out_opt_ _Deref_post_z_ char **_EndPtr, _In_ int _Radix)
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
#define _SEH2_LEAVE
Definition: filesup.c:20
#define DDERR_INVALIDPARAMS
Definition: ddraw.h:79
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12