HyperDbg Debugger
Loading...
Searching...
No Matches
pci-id.h File Reference

PCI ID-related data structures. More...

Go to the source code of this file.

Classes

struct  SubDevice
struct  Device
struct  Vendor

Macros

#define PCI_ID_AS_STR_LENGTH   (sizeof(UINT16) * 2)
#define PCI_NAME_STR_LENGTH   255
#define PCI_ID_DATABASE_PATH   "constants\\pci.ids"

Typedefs

typedef struct SubDevice SubDevice
typedef struct Device Device
typedef struct Vendor Vendor

Functions

VendorGetVendorById (UINT16 VendorId)
 Returns Vendor entry, including corresponding devices and subdevices.
void FreeVendor (Vendor *VendorToFree)
 Frees Vendor and all of its members.
void FreePciIdDatabase ()
 Frees PciIdDatabaseBuffer.
DeviceGetDeviceFromVendor (Vendor *VendorToUse, UINT16 DeviceId)
 Returns Device entry corresponding to DeviceId.
SubDeviceGetSubDeviceFromDevice (Device *DeviceToUse, UINT16 SubVendorId, UINT16 SubDeviceId)
 Returns SubDevice entry corresponding to SubVendorId and DeviceId.

Detailed Description

PCI ID-related data structures.

Author
Bj�rn Ruytenberg (bjorn.nosp@m.@bjo.nosp@m.rnweb.nosp@m..nl)
Version
0.12
Date
2024-12-04

Macro Definition Documentation

◆ PCI_ID_AS_STR_LENGTH

#define PCI_ID_AS_STR_LENGTH   (sizeof(UINT16) * 2)

◆ PCI_ID_DATABASE_PATH

#define PCI_ID_DATABASE_PATH   "constants\\pci.ids"

◆ PCI_NAME_STR_LENGTH

#define PCI_NAME_STR_LENGTH   255

Typedef Documentation

◆ Device

typedef struct Device Device

◆ SubDevice

typedef struct SubDevice SubDevice

◆ Vendor

typedef struct Vendor Vendor

Function Documentation

◆ FreePciIdDatabase()

void FreePciIdDatabase ( )

Frees PciIdDatabaseBuffer.

Returns
VOID
289{
290 if (PciIdDatabaseBuffer != NULL)
291 {
292 free(PciIdDatabaseBuffer);
293 PciIdDatabaseBuffer = NULL;
294 }
295}
NULL()
Definition test-case-generator.py:530

◆ FreeVendor()

void FreeVendor ( Vendor * VendorToFree)

Frees Vendor and all of its members.

Parameters
VendorToFree
Returns
VOID
261{
262 if (VendorToFree == NULL)
263 return;
264
265 Device * CurrentDevice = VendorToFree->Devices;
266 while (CurrentDevice)
267 {
268 SubDevice * CurrentSubDevice = CurrentDevice->SubDevices;
269
270 while (CurrentSubDevice)
271 {
272 SubDevice * NextSubDevice = CurrentSubDevice->Next;
273 free(CurrentSubDevice);
274 CurrentSubDevice = NextSubDevice;
275 }
276
277 Device * NextDevice = CurrentDevice->Next;
278 free(CurrentDevice);
279 CurrentDevice = NextDevice;
280 }
281}
Definition pci-id.h:26
SubDevice * SubDevices
Definition pci-id.h:29
struct Device * Next
Definition pci-id.h:30
Definition pci-id.h:18
struct SubDevice * Next
Definition pci-id.h:22
Device * Devices
Definition pci-id.h:37

◆ GetDeviceFromVendor()

Device * GetDeviceFromVendor ( Vendor * VendorToUse,
UINT16 DeviceId )

Returns Device entry corresponding to DeviceId.

Parameters
VendorToUse
DeviceId
Returns
Device
340{
341 Device * CurrentDevice = NULL;
342 if (!VendorToUse)
343 {
344 return NULL;
345 }
346
347 CurrentDevice = VendorToUse->Devices;
348 while (CurrentDevice != NULL)
349 {
350 if (CurrentDevice->DeviceId == DeviceId)
351 {
352 return CurrentDevice;
353 }
354 CurrentDevice = CurrentDevice->Next;
355 }
356 return NULL;
357}
UINT16 DeviceId
Definition pci-id.h:27

◆ GetSubDeviceFromDevice()

SubDevice * GetSubDeviceFromDevice ( Device * DeviceToUse,
UINT16 SubVendorId,
UINT16 SubDeviceId )

Returns SubDevice entry corresponding to SubVendorId and DeviceId.

Parameters
DeviceToUse
SubVendorId
SubDeviceId
Returns
SubDevice
369{
370 SubDevice * CurrentSubDevice = NULL;
371 if (!DeviceToUse)
372 {
373 return NULL;
374 }
375
376 CurrentSubDevice = DeviceToUse->SubDevices;
377 while (CurrentSubDevice != NULL)
378 {
379 if (CurrentSubDevice->SubVendorId == SubVendorId && CurrentSubDevice->SubDeviceId == SubDeviceId)
380 {
381 return CurrentSubDevice;
382 }
383 CurrentSubDevice = CurrentSubDevice->Next;
384 }
385 return NULL;
386}
UINT16 SubDeviceId
Definition pci-id.h:20
UINT16 SubVendorId
Definition pci-id.h:19

◆ GetVendorById()

Vendor * GetVendorById ( UINT16 VendorId)

Returns Vendor entry, including corresponding devices and subdevices.

Use FreeVendor() on returned Vendor pointer after usage. First call will initialize database - call FreeDatabase() once done querying.

Parameters
VendorId
Returns
Vendor
306{
307 CHAR VendorIdAsStr[5];
308 CHAR ExecutablePath[MAX_PATH];
309 HMODULE hModule = GetModuleHandle(NULL);
310
311 snprintf(VendorIdAsStr, sizeof(VendorIdAsStr), "%04X", VendorId);
312 GetModuleFileName(hModule, ExecutablePath, sizeof(ExecutablePath));
313
314 // Extract executable name
315 CHAR * ExecutableName = strrchr(ExecutablePath, '\\');
316 if (ExecutableName != NULL)
317 {
318 ExecutableName++;
319 }
320 else
321 {
322 ExecutableName = ExecutablePath;
323 }
324
325 // Swap executable name for PCI_ID_DATABASE_PATH
326 strncpy(ExecutableName, PCI_ID_DATABASE_PATH, sizeof(PCI_ID_DATABASE_PATH));
327
328 return GetVendorByIdStr(ExecutablePath, ToLower(VendorIdAsStr));
329}
char CHAR
Definition BasicTypes.h:33
CHAR * ToLower(CHAR *Str)
Converts passed string to lowercase.
Definition pci-id.cpp:45
Vendor * GetVendorByIdStr(const CHAR *Filename, const CHAR *VendorId)
Get Vendor by PCI ID, encoded in ASCII. Do not call directly - use GetVendorById() instead.
Definition pci-id.cpp:90
#define PCI_ID_DATABASE_PATH
Definition pci-id.h:44