WPD API检测设备是否是电话?

问题描述 投票:13回答:2

编辑:请求完整的源代码。下面是一个准系统实现,以便复制该错误。删除内容枚举,但无论如何崩溃都会在第一个对象调用上发生。在这种情况下,WPD_DEVICE_OBJECT_ID对象。

LINK TO CPP(Bug从第103行开始)

LINK TO QMAKE.PRO(我正在使用Qt)


在我的项目中,我使用WPD API来读取移动设备的内容。我遵循API到tee并成功实现了内容枚举。

但是,如果连接了USB驱动器,WPD API有时也会将其检测为设备。无论如何,我的程序将继续进行内容枚举。我不希望这样。我只想枚举移动设备。

问题是在内容枚举期间,当我的程序试图检索USB驱动器上的对象的属性时,它会崩溃。以下是崩溃详情:

Problem Event Name: BEX
Application Name:   UniversalMC.exe
Application Version:    0.0.0.0
Application Timestamp:  5906a8a3
Fault Module Name:  MSVCR100.dll
Fault Module Version:   10.0.40219.325
Fault Module Timestamp: 4df2be1e
Exception Offset:   0008af3e
Exception Code: c0000417
Exception Data: 00000000
OS Version: 6.1.7601.2.1.0.768.3
Locale ID:  1033
Additional Information 1:   185e
Additional Information 2:   185ef2beb7eb77a8e39d1dada57d0d11
Additional Information 3:   a852
Additional Information 4:   a85222a7fc0721be22726bd2ca6bc946

此次调用发生崩溃:

hr = pObjectProperties->GetStringValue(WPD_OBJECT_ORIGINAL_FILE_NAME, &objectName);

hr返回FAILED然后我的程序崩溃了。

经过一些研究,我发现异常代码c0000417意味着发生了缓冲区溢出?如果我错了,请纠正我,但这是WPD API中的漏洞吗?如果是这样,我怎么能提前发现该设备不是移动设备?

谢谢你的时间!

c++ debugging exception buffer-overflow wpd
2个回答
2
投票

我最终付钱给某人帮助我查明问题。

问题是根对象(WPD_DEVICE_OBJECT_ID)无论如何都不会返回对象名称(对于所有设备都不是)。

解决方案是简单地从根对象开始内容枚举,并仅检查其子项的名称。在我最初的实现中,我假设每个对象都有一个名称,但显然情况并非如此。根对象是例外。

这是一个片段:

CComPtr<IEnumPortableDeviceObjectIDs> pEnumObjectIDs;

// Print the object identifier being used as the parent during enumeration.
//qDebug("%ws\n",pszObjectID);

// Get an IEnumPortableDeviceObjectIDs interface by calling EnumObjects with the
// specified parent object identifier.
hr = pContent->EnumObjects(0,               // Flags are unused
                                   WPD_DEVICE_OBJECT_ID,     // Starting from the passed in object
                                   NULL,            // Filter is unused
                                   &pEnumObjectIDs);

// Enumerate content starting from the "DEVICE" object.
if (SUCCEEDED(hr))
{
    // Loop calling Next() while S_OK is being returned.
    while(hr == S_OK)
    {
        DWORD  cFetched = 0;
        PWSTR  szObjectIDArray[NUM_OBJECTS_TO_REQUEST] = {0};
        hr = pEnumObjectIDs->Next(NUM_OBJECTS_TO_REQUEST,   // Number of objects to request on each NEXT call
                                  szObjectIDArray,          // Array of PWSTR array which will be populated on each NEXT call
                                  &cFetched);               // Number of objects written to the PWSTR array
        if (SUCCEEDED(hr))
        {
            // Traverse the results of the Next() operation and recursively enumerate
            // Remember to free all returned object identifiers using CoTaskMemFree()
            for (DWORD dwIndex = 0; dwIndex < cFetched; dwIndex++)
            {
                //RECURSIVE CONTENT ENUMERATION CONTINUES HERE
                //OBJECT NAME CHECKING CONTINUES IN THE RECURSIVE FUNCTION

                // Free allocated PWSTRs after the recursive enumeration call has completed.
                CoTaskMemFree(szObjectIDArray[dwIndex]);
                szObjectIDArray[dwIndex] = NULL;
            }
        }
    }

}

解决方案正是示例项目显示的内容,但是,我错误地检查了根对象的名称。所以不要这样做。


0
投票

如果没有“原始文件名”,请获取对象名称

hr = pObjectProperties->GetStringValue(WPD_OBJECT_ORIGINAL_FILE_NAME, &objectName);

if(FAILED(hr)) {
   hr = pObjectProperties->GetStringValue(WPD_OBJECT_NAME, &objectName);
}
© www.soinside.com 2019 - 2024. All rights reserved.