STDMETHODIMP CDotNetInfoParser::Parse(VARIANT *v, IVariantObject** ppVariantObject) { CHECK_E_POINTER(v); if(v->vt != VT_BSTR) return E_INVALIDARG; CComPtr<IPluginManager> pPluginManager; RETURN_IF_FAILED(HrGetPluginManager(&pPluginManager)); RETURN_IF_FAILED(pPluginManager->CoCreateInstance(CLSID_VariantObject, IID_IVariantObject, (LPVOID*)ppVariantObject)); CComPtr<IVariantObject> pVariantObject = *ppVariantObject; RETURN_IF_FAILED(HrAddColumn(pPluginManager, pVariantObject, VAR_KEY, L"Property")); RETURN_IF_FAILED(HrAddColumn(pPluginManager, pVariantObject, VAR_VALUE, L"Value")); CComPtr<IObjCollection> pObjectCollection; RETURN_IF_FAILED(HrCoCreateInstance(CLSID_ObjectCollection, &pObjectCollection)); CComBSTR bstrResult = v->bstrVal; CString strResult = bstrResult; int nTokenPos = 0; int nObjects = 0; while (nTokenPos >= 0) { CString strLine = strResult.Tokenize(L"\n", nTokenPos); static std::wregex regex(L" +([^:]+): +(.+)"); std::wsmatch matches; auto str = std::wstring(strLine); if (!std::regex_search(str, matches, regex) || matches.size() != 3) continue; int index = 1; auto strKey = matches[index++].str(); auto strValue = matches[index++].str(); CComPtr<IVariantObject> pVariantObjectValue; RETURN_IF_FAILED(pPluginManager->CoCreateInstance(CLSID_VariantObject, IID_IVariantObject, (LPVOID*)&pVariantObjectValue)); RETURN_IF_FAILED(pVariantObjectValue->SetVariantValue(VAR_KEY, &CComVar(strKey.c_str()))); RETURN_IF_FAILED(pVariantObjectValue->SetVariantValue(VAR_VALUE, &CComVar(strValue.c_str()))); RETURN_IF_FAILED(pObjectCollection->AddObject(pVariantObjectValue)); nObjects++; } if(!nObjects) return E_FAIL; CComPtr<IVariantTable> pVariantTable; RETURN_IF_FAILED(HrWrapToVariantTable(pPluginManager, pVariantObject, pObjectCollection, &pVariantTable)); CComVar vObjects(pVariantTable); RETURN_IF_FAILED(pVariantObject->SetVariantValue(ObjectModel::Metadata::TableObject::ObjectsObject, &vObjects)); RETURN_IF_FAILED(pVariantObject->SetVariantValue(VAR_RESULT, v)); return S_OK; }
STDMETHODIMP CHeapStatParser::Parse(VARIANT *v, IVariantObject** ppVariantObject) { CHECK_E_POINTER(v); if(v->vt != VT_BSTR) return E_INVALIDARG; CComPtr<IPluginManager> pPluginManager; RETURN_IF_FAILED(HrGetPluginManager(&pPluginManager)); RETURN_IF_FAILED(pPluginManager->CoCreateInstance(CLSID_VariantObject, IID_IVariantObject, (LPVOID*)ppVariantObject)); CComPtr<IVariantObject> pVariantObject = *ppVariantObject; HrAddColumn(pPluginManager, pVariantObject, ObjectModel::Metadata::Object::Id, L"MT", VT_BSTR, 100); HrAddColumn(pPluginManager, pVariantObject, VAR_COUNT, L"Count", VT_I4, 100); HrAddColumn(pPluginManager, pVariantObject, VAR_TOTALSIZE, L"TotalSize", VT_I8, 100); HrAddColumn(pPluginManager, pVariantObject, VAR_CLASSNAME, L"ClassName"); CComPtr<IObjCollection> pObjectCollection; RETURN_IF_FAILED(HrCoCreateInstance(CLSID_ObjectCollection, &pObjectCollection)); CComBSTR bstrResult = v->bstrVal; CString strResult = bstrResult; int nTokenPos = 0; bool readyToParse = false; int nObjects = 0; while (nTokenPos >= 0) { CString strLine = strResult.Tokenize(L"\n", nTokenPos); if(strLine.Find(L" MT") != -1) { readyToParse = true; continue; } if(!readyToParse) continue; if(strLine.Find(L"Total ") != -1) break; static std::wregex regex(L"(\\S+) +(\\S+) +(\\S+) +(.+)"); std::wsmatch matches; auto str = std::wstring(strLine); if (!std::regex_search(str, matches, regex) || matches.size() != 5) continue; int index = 1; auto strId = matches[index++].str(); auto count = boost::lexical_cast<int>(matches[index++].str()); auto totalSize = boost::lexical_cast<long long>(matches[index++].str()); auto strClassName = matches[index++].str(); if (strClassName.find(L"Free") != std::wstring::npos) continue; CComPtr<IVariantObject> pVariantObjectValue; RETURN_IF_FAILED(pPluginManager->CoCreateInstance(CLSID_VariantObject, IID_IVariantObject, (LPVOID*)&pVariantObjectValue)); RETURN_IF_FAILED(pVariantObjectValue->SetVariantValue(ObjectModel::Metadata::Object::Id, &CComVar(strId.c_str()))); RETURN_IF_FAILED(pVariantObjectValue->SetVariantValue(VAR_COUNT, &CComVar(count))); RETURN_IF_FAILED(pVariantObjectValue->SetVariantValue(VAR_TOTALSIZE, &CComVar(totalSize))); RETURN_IF_FAILED(pVariantObjectValue->SetVariantValue(VAR_CLASSNAME, &CComVar(strClassName.c_str()))); RETURN_IF_FAILED(pObjectCollection->AddObject(pVariantObjectValue)); nObjects++; } if(!nObjects) return E_FAIL; CComPtr<IVariantTable> pVariantTable; RETURN_IF_FAILED(HrWrapToVariantTable(pPluginManager, pVariantObject, pObjectCollection, &pVariantTable)); CComVar vObjects(pVariantTable); RETURN_IF_FAILED(pVariantObject->SetVariantValue(ObjectModel::Metadata::TableObject::ObjectsObject, &vObjects)); RETURN_IF_FAILED(pVariantObject->SetVariantValue(VAR_RESULT, v)); return S_OK; }
STDMETHODIMP CObjectValuesParser::Parse(VARIANT *v, IVariantObject** ppVariantObject) { CHECK_E_POINTER(v); if(v->vt != VT_BSTR) return E_INVALIDARG; CComPtr<IPluginManager> pPluginManager; RETURN_IF_FAILED(HrGetPluginManager(&pPluginManager)); RETURN_IF_FAILED(pPluginManager->CoCreateInstance(CLSID_VariantObject, IID_IVariantObject, (LPVOID*)ppVariantObject)); CComPtr<IVariantObject> pVariantObject = *ppVariantObject; HrAddColumn(pPluginManager, pVariantObject, VAR_MT, L"MT", VT_BSTR, 100); HrAddColumn(pPluginManager, pVariantObject, VAR_FIELD, L"Field", VT_BSTR, 100); HrAddColumn(pPluginManager, pVariantObject, VAR_OFFSET, L"Offset", VT_BSTR, 100); HrAddColumn(pPluginManager, pVariantObject, VAR_TYPE, L"Type"); HrAddColumn(pPluginManager, pVariantObject, VAR_VT, L"VT"); HrAddColumn(pPluginManager, pVariantObject, VAR_ATTR, L"Attr"); HrAddColumn(pPluginManager, pVariantObject, ObjectModel::Metadata::Object::Id, L"Value"); HrAddColumn(pPluginManager, pVariantObject, VAR_NAME, L"Name"); CComPtr<IObjCollection> pObjectCollection; RETURN_IF_FAILED(HrCoCreateInstance(CLSID_ObjectCollection, &pObjectCollection)); CComBSTR bstrResult = v->bstrVal; CString strResult = bstrResult; int nTokenPos = 0; bool readyToParse = false; int nObjects = 0; while (nTokenPos >= 0) { CString strLine = strResult.Tokenize(L"\n", nTokenPos); if(strLine.Find(L" MT") != -1) { readyToParse = true; continue; } if(!readyToParse) continue; std::wsmatch matches; static std::wregex regex(L"(\\S+) +(\\S+) +(\\S+) +(\\S+) +(\\S+) +(\\S+) +(\\S+) +(\\S+)"); auto str = std::wstring(strLine); if (!std::regex_search(str, matches, regex) || matches.size() != 9) continue; int index = 1; auto strMt = matches[index++].str(); auto strField = matches[index++].str(); auto strOffset = matches[index++].str(); auto strType = matches[index++].str(); auto strVt = matches[index++].str(); auto strAttr = matches[index++].str(); auto strValue = matches[index++].str(); auto strName = matches[index++].str(); if(strName.empty()) continue; CComPtr<IVariantObject> pVariantObjectValue; RETURN_IF_FAILED(pPluginManager->CoCreateInstance(CLSID_VariantObject, IID_IVariantObject, (LPVOID*)&pVariantObjectValue)); RETURN_IF_FAILED(pVariantObjectValue->SetVariantValue(VAR_MT, &CComVar(strMt.c_str()))); RETURN_IF_FAILED(pVariantObjectValue->SetVariantValue(VAR_FIELD, &CComVar(strField.c_str()))); RETURN_IF_FAILED(pVariantObjectValue->SetVariantValue(VAR_OFFSET, &CComVar(strOffset.c_str()))); RETURN_IF_FAILED(pVariantObjectValue->SetVariantValue(VAR_TYPE, &CComVar(strType.c_str()))); RETURN_IF_FAILED(pVariantObjectValue->SetVariantValue(VAR_VT, &CComVar(strVt.c_str()))); RETURN_IF_FAILED(pVariantObjectValue->SetVariantValue(VAR_ATTR, &CComVar(strAttr.c_str()))); RETURN_IF_FAILED(pVariantObjectValue->SetVariantValue(ObjectModel::Metadata::Object::Id, &CComVar(strValue.c_str()))); RETURN_IF_FAILED(pVariantObjectValue->SetVariantValue(VAR_NAME, &CComVar(strName.c_str()))); RETURN_IF_FAILED(pObjectCollection->AddObject(pVariantObjectValue)); nObjects++; } CComPtr<IVariantTable> pVariantTable; RETURN_IF_FAILED(HrWrapToVariantTable(pPluginManager, pVariantObject, pObjectCollection, &pVariantTable)); CComVar vObjects(pVariantTable); RETURN_IF_FAILED(pVariantObject->SetVariantValue(ObjectModel::Metadata::TableObject::ObjectsObject, &vObjects)); RETURN_IF_FAILED(pVariantObject->SetVariantValue(VAR_RESULT, v)); return S_OK; }
STDMETHODIMP CObjectsParser::Parse(VARIANT *v, IVariantObject** ppVariantObject) { CHECK_E_POINTER(v); if(v->vt != VT_BSTR) return E_INVALIDARG; CComPtr<IPluginManager> pPluginManager; RETURN_IF_FAILED(HrGetPluginManager(&pPluginManager)); RETURN_IF_FAILED(pPluginManager->CoCreateInstance(CLSID_VariantObject, IID_IVariantObject, (LPVOID*)ppVariantObject)); CComPtr<IVariantObject> pVariantObject = *ppVariantObject; HrAddColumn(pPluginManager, pVariantObject, ObjectModel::Metadata::Object::Id, L"Address", VT_BSTR, 100); HrAddColumn(pPluginManager, pVariantObject, ObjectModel::Metadata::Object::Key, L"MT", VT_BSTR, 100); HrAddColumn(pPluginManager, pVariantObject, ObjectModel::Metadata::Object::Value, L"Size", VT_BSTR, 100); CComPtr<IObjCollection> pObjectCollection; RETURN_IF_FAILED(HrCoCreateInstance(CLSID_ObjectCollection, &pObjectCollection)); CComBSTR bstrResult = v->bstrVal; CString strResult = bstrResult; int nTokenPos = 0; bool readyToParse = false; int nObjects = 0; while (nTokenPos >= 0) { CString strLine = strResult.Tokenize(L"\n", nTokenPos); if(strLine.Find(L" Address") != -1) { readyToParse = true; continue; } if(!readyToParse) continue; if(strLine.Find(L"object ") != -1) break; if(strLine.Find(L"Statistics:") != -1) break; if(strLine.Find(L"total ") != -1) break; std::wsmatch matches; static std::wregex regex(L"(\\S+) +(\\S+) +(\\S+)"); auto str = std::wstring(strLine); if (!std::regex_search(str, matches, regex) || matches.size() != 4) continue; int index = 1; auto strAddress = matches[index++].str(); auto strMt = matches[index++].str(); auto strSize = matches[index++].str(); if(strSize.empty()) continue; CComPtr<IVariantObject> pVariantObjectValue; RETURN_IF_FAILED(pPluginManager->CoCreateInstance(CLSID_VariantObject, IID_IVariantObject, (LPVOID*)&pVariantObjectValue)); RETURN_IF_FAILED(pVariantObjectValue->SetVariantValue(ObjectModel::Metadata::Object::Id, &CComVar(strAddress.c_str()))); RETURN_IF_FAILED(pVariantObjectValue->SetVariantValue(ObjectModel::Metadata::Object::Key, &CComVar(strMt.c_str()))); RETURN_IF_FAILED(pVariantObjectValue->SetVariantValue(ObjectModel::Metadata::Object::Value, &CComVar(strSize.c_str()))); RETURN_IF_FAILED(pObjectCollection->AddObject(pVariantObjectValue)); nObjects++; } if(!nObjects) return E_FAIL; CComPtr<IVariantTable> pVariantTable; RETURN_IF_FAILED(HrWrapToVariantTable(pPluginManager, pVariantObject, pObjectCollection, &pVariantTable)); CComVar vObjects(pVariantTable); RETURN_IF_FAILED(pVariantObject->SetVariantValue(ObjectModel::Metadata::TableObject::ObjectsObject, &vObjects)); RETURN_IF_FAILED(pVariantObject->SetVariantValue(VAR_RESULT, v)); return S_OK; }