⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 enumdev.cpp

📁 含:分析物理磁盘的分区表和各分区的bootsector for bitlocker以及WINDOWS下设备枚举.
💻 CPP
字号:
#include <setupapi.h>
#include <devguid.h>
#include <regstr.h>
#pragma comment(lib,"Setupapi.lib")


int enumSysHdDevice(void)
{
 
    HDEVINFO hDevInfo;
    SP_DEVINFO_DATA DeviceInfoData;
    DWORD i;
 
    // 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 -1;
    }
    
    // Enumerate through all devices in Set.    
    DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
    for (i=0;SetupDiEnumDeviceInfo(hDevInfo,i,&DeviceInfoData);i++)
    {
        DWORD DataT;
        LPTSTR buffer = NULL;
        DWORD buffersize = 0;
        
        // 
        // Call function with null to begin with, 
        // then use the returned buffer size 
        // to Alloc the buffer. Keep calling until
        // success or an unknown failure.
        // 
        while (!SetupDiGetDeviceRegistryProperty(
            hDevInfo,
            &DeviceInfoData,
            SPDRP_DEVICEDESC,//SPDRP_FRIENDLYNAME,//SPDRP_HARDWAREID,//SPDRP_DEVICEDESC,
            &DataT,
            (PBYTE)buffer,
            buffersize,
            &buffersize))
        {
            if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
            {
                // Change the buffer size.
                if (buffer) 
                	LocalFree(buffer);
                buffer = (char*)LocalAlloc(LPTR,buffersize);
            }
            else
            {
                // Insert error handling here.
                break;
            }
        }

		printf("\n[%03d]: %s", i, buffer);
                
        if (buffer) 
        	LocalFree(buffer);
    }
    
    
    if ( GetLastError()!=NO_ERROR &&  GetLastError()!=ERROR_NO_MORE_ITEMS )
    {
        // Insert error handling here.
        return -1;
    }
    
    //  Cleanup
    SetupDiDestroyDeviceInfoList(hDevInfo); 
    return 0;
}    


char *TpmDeviceDescript[]={
	"Trusted Platform Module",
	"BitLocker Drive Encryption Filter Driver"
};

int DetectTpmDevice(void)
{
 
    HDEVINFO hDevInfo;
    SP_DEVINFO_DATA DeviceInfoData;
    DWORD i;
    int j, res = 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 -1;
    }
    
    // Enumerate through all devices in Set.    
    DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
    for (i=0;SetupDiEnumDeviceInfo(hDevInfo,i,&DeviceInfoData);i++)
    {
        DWORD DataT;
        LPTSTR buffer = NULL;
        DWORD buffersize = 0;
        
        // 
        // Call function with null to begin with, 
        // then use the returned buffer size 
        // to Alloc the buffer. Keep calling until
        // success or an unknown failure.
        // 
        while (!SetupDiGetDeviceRegistryProperty(
            hDevInfo,
            &DeviceInfoData,
            SPDRP_DEVICEDESC,//SPDRP_FRIENDLYNAME,//SPDRP_HARDWAREID,//SPDRP_DEVICEDESC,
            &DataT,
            (PBYTE)buffer,
            buffersize,
            &buffersize))
        {
            if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
            {
                // Change the buffer size.
                if (buffer) 
                	LocalFree(buffer);
                buffer = (char*)LocalAlloc(LPTR,buffersize);
            }
            else
            {
                // Insert error handling here.
                break;
            }
        }

		//printf("\n[%03d]: %s", i, buffer);
        for(j=0; j<sizeof(TpmDeviceDescript)/sizeof(char *); j++)
        {
        	if(!strncmp(TpmDeviceDescript[j], buffer, strlen(TpmDeviceDescript[j])))
        	{
        		res = 1;
        		goto DetectTpmDeviceEnd;
        	}
    	}        
        if (buffer) 
        	LocalFree(buffer);
    }
    
    
    if ( GetLastError()!=NO_ERROR &&  GetLastError()!=ERROR_NO_MORE_ITEMS )
    {
        // Insert error handling here.
        return -1;
    }

DetectTpmDeviceEnd:    
    //  Cleanup
    SetupDiDestroyDeviceInfoList(hDevInfo); 
    return res;
}    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -