2013年10月13日 星期日

windbg local mode study

It will call dbgeng!LocalLiveKernelTargetInfo::InitDriver and then create kldbgdrv.sys in the c:\Windows\System32 folder.

2013年10月5日 星期六

PCI address to Device manager device description

TCHAR buf[MAX_DEVICE_ID_LEN];  // (Dynamically size this instead?)

PTSTR DriverNameToDeviceDesc (UCHAR bn, UCHAR dn, UCHAR fn, BOOLEAN DeviceId)
{
HDEVINFO  hDevInfo;
    SP_DEVINFO_DATA  DeviceInfoData;
    DWORD  i;
BOOL r;
int j=0;


    //  Create  a  HDEVINFO  with  all  present  devices.      
hDevInfo  =  SetupDiGetClassDevs(NULL,
               0,  //  Enumerator
               0,
               DIGCF_PRESENT    |  DIGCF_ALLCLASSES  );
 
    if  (hDevInfo  ==  INVALID_HANDLE_VALUE)
    {
               //  Insert  error  handling  here.
               return  NULL;
    }
       
    //  Enumerate  through  all  devices  in  Set.
    DWORD  DataT;
    DWORD  buffersize  =  0;
    DeviceInfoData.cbSize  =  sizeof(SP_DEVINFO_DATA);
   
for  (i=0;SetupDiEnumDeviceInfo(hDevInfo,i,
               &DeviceInfoData);i++)
    {
 
           if(SetupDiGetDeviceRegistryProperty(
                       hDevInfo,
                       &DeviceInfoData,
                       SPDRP_BUSNUMBER,
                       &DataT,
                       (PBYTE)buf,
                       MAX_DEVICE_ID_LEN,
                       &buffersize))
  {
  if(buffersize == 4 && (UCHAR) buf[0] == bn)
  {
   if(SetupDiGetDeviceRegistryProperty(
                       hDevInfo,
                       &DeviceInfoData,
                       SPDRP_ADDRESS,
                       &DataT,
                       (PBYTE)buf,
                       MAX_DEVICE_ID_LEN,
                       &buffersize))
{
if (buffersize == 4 && (UCHAR) buf[0] == fn && (UCHAR) buf[2] == dn)
{
if(SetupDiGetDeviceRegistryProperty(
hDevInfo,
&DeviceInfoData,
SPDRP_DEVICEDESC,
&DataT,
(PBYTE)buf,
MAX_DEVICE_ID_LEN,
&buffersize))
{
return buf;
}
else
{
SetupDiDestroyDeviceInfoList(hDevInfo);
return NULL;
}
}
}
}
  }
}
    //    Cleanup
    SetupDiDestroyDeviceInfoList(hDevInfo);  
    return  NULL;
}