HyperDbg Debugger
Loading...
Searching...
No Matches
pcitree.cpp File Reference

!pcitree command More...

#include "pch.h"

Functions

VOID CommandPcitreeHelp ()
 help of the !pcitree command
VOID CommandPcitree (vector< CommandToken > CommandTokens, string Command)
 !pcitree command handler

Variables

BOOLEAN g_IsKdModuleLoaded
 shows whether the kernel debugger (KD) module is loaded or not
BOOLEAN g_IsSerialConnectedToRemoteDebuggee
 Shows if the debugger was connected to remote debuggee over (A remote guest).

Detailed Description

!pcitree command

Author
Bj�rn Ruytenberg (bjorn.nosp@m.@bjo.nosp@m.rnweb.nosp@m..nl)
Version
0.10.3
Date
2024-10-31

Function Documentation

◆ CommandPcitree()

VOID CommandPcitree ( vector< CommandToken > CommandTokens,
string Command )

!pcitree command handler

Parameters
CommandTokens
Command
Returns
VOID
46{
47 BOOL Status;
48 ULONG ReturnedLength;
50
51 if (CommandTokens.size() != 1)
52 {
53 ShowMessages("incorrect use of the '%s'\n\n",
54 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
56 return;
57 }
58
59 //
60 // Send buffer
61 //
63 {
64 KdSendPcitreePacketToDebuggee(&PcitreePacket);
65 }
66 else
67 {
69
70 //
71 // Send IOCTL
72 //
73 Status = DeviceIoControl(
74 g_DeviceHandle, // Handle to device
75 IOCTL_PCIE_ENDPOINT_ENUM, // IO Control Code (IOCTL)
76 &PcitreePacket, // Input Buffer to driver.
78 &PcitreePacket, // Output Buffer from driver.
80 // buffer in bytes.
81 &ReturnedLength, // Bytes placed in buffer.
82 NULL // synchronous call
83 );
84
85 if (!Status)
86 {
87 ShowMessages("ioctl failed with code 0x%x\n", GetLastError());
88 return;
89 }
90
92 {
93 //
94 // Print PCI device tree
95 //
96 ShowMessages("%-12s | %-9s | %-17s | %s \n%s\n", "DBDF", "VID:DID", "Vendor Name", "Device Name", "----------------------------------------------------------------------");
97 for (UINT8 i = 0; i < (PcitreePacket.DeviceInfoListNum < DEV_MAX_NUM ? PcitreePacket.DeviceInfoListNum : DEV_MAX_NUM); i++)
98 {
99 Vendor * CurrentVendor = GetVendorById(PcitreePacket.DeviceInfoList[i].ConfigSpace.VendorId);
100 CHAR * CurrentVendorName = (CHAR *)"N/A";
101 CHAR * CurrentDeviceName = (CHAR *)"N/A";
102
103 if (CurrentVendor != NULL)
104 {
105 CurrentVendorName = CurrentVendor->VendorName;
106 Device * CurrentDevice = GetDeviceFromVendor(CurrentVendor, PcitreePacket.DeviceInfoList[i].ConfigSpace.DeviceId);
107
108 if (CurrentDevice != NULL)
109 {
110 CurrentDeviceName = CurrentDevice->DeviceName;
111 }
112 }
113
114 ShowMessages("%04x:%02x:%02x:%x | %04x:%04x | %-17.*s | %.*s\n",
115 0, // TODO: Add support for domains beyond 0000
116 PcitreePacket.DeviceInfoList[i].Bus,
117 PcitreePacket.DeviceInfoList[i].Device,
118 PcitreePacket.DeviceInfoList[i].Function,
119 PcitreePacket.DeviceInfoList[i].ConfigSpace.VendorId,
120 PcitreePacket.DeviceInfoList[i].ConfigSpace.DeviceId,
121 strnlen_s(CurrentVendorName, PCI_NAME_STR_LENGTH),
122 CurrentVendorName,
123 strnlen_s(CurrentDeviceName, PCI_NAME_STR_LENGTH),
124 CurrentDeviceName
125
126 );
127
128 FreeVendor(CurrentVendor);
129 }
131 }
132 else
133 {
134 //
135 // An err occurred, no results
136 //
137 ShowErrorMessage(PcitreePacket.KernelStatus);
138 }
139 }
140}
BOOLEAN g_IsSerialConnectedToRemoteDebuggee
Shows if the debugger was connected to remote debuggee over (A remote guest).
Definition globals.h:253
int BOOL
Definition BasicTypes.h:25
unsigned char UINT8
Definition BasicTypes.h:52
char CHAR
Definition BasicTypes.h:33
unsigned long ULONG
Definition BasicTypes.h:31
#define DEBUGGER_OPERATION_WAS_SUCCESSFUL
General value to indicate that the operation or request was successful.
Definition ErrorCodes.h:23
#define IOCTL_PCIE_ENDPOINT_ENUM
ioctl, to enumerate PCIe endpoints
Definition Ioctls.h:354
#define DEV_MAX_NUM
Definition Pcie.h:42
#define SIZEOF_DEBUGGEE_PCITREE_REQUEST_RESPONSE_PACKET
Definition RequestStructures.h:1639
struct _DEBUGGEE_PCITREE_REQUEST_RESPONSE_PACKET DEBUGGEE_PCITREE_REQUEST_RESPONSE_PACKET
Pcitree Request-Response Packet. Represents PCI device tree.
std::string GetCaseSensitiveStringFromCommandToken(CommandToken TargetToken)
Get case sensitive string from command token.
Definition common.cpp:467
BOOLEAN ShowErrorMessage(UINT32 Error)
shows the error message
Definition debugger.cpp:40
BOOLEAN KdSendPcitreePacketToDebuggee(PDEBUGGEE_PCITREE_REQUEST_RESPONSE_PACKET PcitreePacket)
Sends '!pcitree' command, including buffer, to the debuggee.
Definition kd.cpp:3592
#define ASSERT_MESSAGE_KD_NOT_LOADED
Definition common.h:29
#define AssertShowMessageReturnStmt(expr1, expr2, message1, message2, rc)
Definition common.h:59
#define AssertReturn
Definition common.h:19
#define ASSERT_MESSAGE_DRIVER_NOT_LOADED
Definition common.h:27
HANDLE g_DeviceHandle
Holds the global handle of device which is used to send the request to the kernel by IOCTL,...
Definition globals.h:481
BOOLEAN g_IsKdModuleLoaded
shows whether the kernel debugger (KD) module is loaded or not
Definition globals.h:22
Device * GetDeviceFromVendor(Vendor *VendorToUse, UINT16 DeviceId)
Returns Device entry corresponding to DeviceId.
Definition pci-id.cpp:339
Vendor * GetVendorById(UINT16 VendorId)
Returns Vendor entry, including corresponding devices and subdevices.
Definition pci-id.cpp:305
VOID FreePciIdDatabase()
Frees PciIdDatabaseBuffer.
Definition pci-id.cpp:288
VOID FreeVendor(Vendor *VendorToFree)
Frees Vendor and all of its members.
Definition pci-id.cpp:260
#define PCI_NAME_STR_LENGTH
Definition pci-id.h:15
VOID CommandPcitreeHelp()
help of the !pcitree command
Definition pcitree.cpp:26
UINT8 DeviceInfoListNum
Definition RequestStructures.h:1649
UINT32 KernelStatus
Definition RequestStructures.h:1648
PCI_DEV_MINIMAL DeviceInfoList[DEV_MAX_NUM]
Definition RequestStructures.h:1650
PORTABLE_PCI_CONFIG_SPACE_HEADER_MINIMAL ConfigSpace
Definition Pcie.h:137
UINT8 Bus
Definition Pcie.h:134
UINT8 Function
Definition Pcie.h:136
UINT8 Device
Definition Pcie.h:135
UINT16 VendorId
Definition Pcie.h:123
UINT16 DeviceId
Definition Pcie.h:124
Definition pci-id.h:26
CHAR DeviceName[PCI_NAME_STR_LENGTH]
Definition pci-id.h:28
Definition pci-id.h:34
CHAR VendorName[PCI_NAME_STR_LENGTH]
Definition pci-id.h:36

◆ CommandPcitreeHelp()

VOID CommandPcitreeHelp ( )

help of the !pcitree command

Returns
VOID
27{
28 ShowMessages("!pcitree : enumerates all PCIe endpoints on the debuggee.\n\n");
29
30 ShowMessages("syntax : \t!pcitree\n");
31
32 ShowMessages("\n");
33 ShowMessages("\t\te.g : !pcitree\n");
34}

Variable Documentation

◆ g_IsKdModuleLoaded

BOOLEAN g_IsKdModuleLoaded
extern

shows whether the kernel debugger (KD) module is loaded or not

◆ g_IsSerialConnectedToRemoteDebuggee

BOOLEAN g_IsSerialConnectedToRemoteDebuggee
extern

Shows if the debugger was connected to remote debuggee over (A remote guest).