[fix] Crash/Stuck application when wmi does not return parameter for a QuerySink
[impl] Implement support to retrieve mainboardSerialNum
This commit is contained in:
parent
6342f75392
commit
f3b9b82464
@ -10,6 +10,7 @@ struct SystemParamTypes
|
||||
static const std::string diskSerialNum;
|
||||
static const std::string osId;
|
||||
static const std::string nicMac;
|
||||
static const std::string mainboardSerialNum;
|
||||
};
|
||||
|
||||
typedef std::map<std::string, std::string> SystemParams;
|
||||
|
||||
@ -77,12 +77,22 @@ ParamHash fletcher64(const std::string& input)
|
||||
return intToHex(resInt);
|
||||
}
|
||||
|
||||
int countUniqueCharacters(std::string_view str)
|
||||
{
|
||||
std::set<char> chars;
|
||||
for (auto ch : str)
|
||||
{
|
||||
chars.insert(ch);
|
||||
}
|
||||
return chars.size();
|
||||
}
|
||||
|
||||
SystemParams skipEmptyParams(const SystemParams& systemParams)
|
||||
{
|
||||
SystemParams result;
|
||||
for (const auto& entry : systemParams)
|
||||
{
|
||||
if (!entry.second.empty())
|
||||
if (!entry.second.empty() && entry.second.length() > 1 && countUniqueCharacters(entry.second) > 1)
|
||||
{
|
||||
result[entry.first] = entry.second;
|
||||
}
|
||||
|
||||
@ -5,3 +5,4 @@ const std::string SystemParamTypes::computerUUID{ "computerUUID" };
|
||||
const std::string SystemParamTypes::diskSerialNum{ "diskSerialNum" };
|
||||
const std::string SystemParamTypes::osId{ "osId" };
|
||||
const std::string SystemParamTypes::nicMac{ "nicMac" };
|
||||
const std::string SystemParamTypes::mainboardSerialNum{ "mainboardSerialNum" };
|
||||
|
||||
@ -98,8 +98,6 @@ namespace
|
||||
IWbemClassObject __RPC_FAR *__RPC_FAR *apObjArray
|
||||
) override
|
||||
{
|
||||
std::vector<std::vector<std::string>> result;
|
||||
|
||||
for (int i = 0; i < lObjectCount; i++)
|
||||
{
|
||||
std::vector<std::string> lineResult;
|
||||
@ -123,11 +121,9 @@ namespace
|
||||
lineResult.push_back(convertBSTRToMBS(V_BSTR(&varName)));
|
||||
}
|
||||
|
||||
result.push_back(lineResult);
|
||||
m_result.push_back(lineResult);
|
||||
}
|
||||
|
||||
m_resultPromise.set_value(std::move(result));
|
||||
|
||||
return WBEM_S_NO_ERROR;
|
||||
}
|
||||
|
||||
@ -144,6 +140,7 @@ namespace
|
||||
EnterCriticalSection(&m_threadLock);
|
||||
m_bDone = true;
|
||||
LeaveCriticalSection(&m_threadLock);
|
||||
m_resultPromise.set_value(std::move(m_result));
|
||||
}
|
||||
else if (lFlags == WBEM_STATUS_PROGRESS)
|
||||
{
|
||||
@ -175,6 +172,7 @@ namespace
|
||||
mutable CRITICAL_SECTION m_threadLock; // for thread safety
|
||||
const std::string m_wmiClass;
|
||||
const Fields_type m_fields;
|
||||
std::vector<std::vector<std::string>> m_result;
|
||||
std::promise<Result_type> m_resultPromise;
|
||||
};
|
||||
|
||||
@ -294,9 +292,10 @@ namespace detail
|
||||
{
|
||||
auto biosFuture = queryWmiInfo("Win32_BIOS", { "SerialNumber" });
|
||||
auto computerSystemProductFuture = queryWmiInfo("Win32_ComputerSystemProduct", { "UUID" });
|
||||
auto diskDriveFuture = queryWmiInfo("Win32_DiskDrive", { "SerialNumber" });
|
||||
auto diskDriveFuture = queryWmiInfo("Win32_DiskDrive", { "SerialNumber" }, "DeviceId = \"\\\\\\\\.\\\\PHYSICALDRIVE0\"");
|
||||
auto osFuture = queryWmiInfo("Win32_OperatingSystem", { "SerialNumber" });
|
||||
auto nicFuture = queryWmiInfo("Win32_NetworkAdapter", { "MACAddress" }, "PhysicalAdapter = TRUE");
|
||||
auto mainboardFuture = queryWmiInfo("Win32_BaseBoard", { "SerialNumber" });
|
||||
|
||||
SystemParams result;
|
||||
result[SystemParamTypes::biosSerialNum] = processBiosData(biosFuture.get());
|
||||
@ -304,6 +303,7 @@ namespace detail
|
||||
result[SystemParamTypes::diskSerialNum] = processDiskDrive(diskDriveFuture.get());
|
||||
result[SystemParamTypes::osId] = processOs(osFuture.get());
|
||||
result[SystemParamTypes::nicMac] = processNic(nicFuture.get());
|
||||
result[SystemParamTypes::mainboardSerialNum] = processMainBoard(mainboardFuture.get());
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -347,27 +347,56 @@ namespace detail
|
||||
|
||||
static std::string processBiosData(const QueryResult_type& biosInfo)
|
||||
{
|
||||
return biosInfo[0][0];
|
||||
if (biosInfo.size() > 0)
|
||||
{
|
||||
return biosInfo[0][0];
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
static std::string processComputerSystemProductData(const QueryResult_type& csInfo)
|
||||
{
|
||||
return csInfo[0][0];
|
||||
if (csInfo.size() > 0)
|
||||
{
|
||||
return csInfo[0][0];
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
static std::string processDiskDrive(const QueryResult_type& csInfo)
|
||||
{
|
||||
return csInfo[0][0];
|
||||
if (csInfo.size() > 0)
|
||||
{
|
||||
return csInfo[0][0];
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
static std::string processOs(const QueryResult_type& csInfo)
|
||||
{
|
||||
return csInfo[0][0];
|
||||
if (csInfo.size() > 0)
|
||||
{
|
||||
return csInfo[0][0];
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
static std::string processNic(const QueryResult_type& csInfo)
|
||||
{
|
||||
return csInfo[0][0];
|
||||
if (csInfo.size() > 0)
|
||||
{
|
||||
return csInfo[0][0];
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
static std::string processMainBoard(const QueryResult_type& csInfo)
|
||||
{
|
||||
if (csInfo.size() > 0)
|
||||
{
|
||||
return csInfo[0][0];
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user