This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
32,851 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// DiaHelper.cpp : Defines the functions for the static library. | ||
// | ||
|
||
#include "pch.h" | ||
#include "DiaHelper.h" | ||
|
||
HMODULE g_hDiaDll; | ||
|
||
bool DiaSession::OpenImage(PCWSTR path) { | ||
return OpenCommon(path, true); | ||
} | ||
|
||
bool DiaSession::OpenPdb(PCWSTR path) { | ||
return OpenCommon(path, false); | ||
} | ||
|
||
void DiaSession::Close() { | ||
m_spSession.Release(); | ||
} | ||
|
||
std::wstring DiaSession::LastError() const { | ||
CComBSTR text; | ||
return m_spSource && S_OK == m_spSource->get_lastError(&text) ? text.m_str : L""; | ||
} | ||
|
||
DiaSymbol DiaSession::GlobalScope() const { | ||
if (m_spSession == nullptr) | ||
return DiaSymbol(nullptr); | ||
|
||
CComPtr<IDiaSymbol> spSym; | ||
m_spSession->get_globalScope(&spSym); | ||
return DiaSymbol(spSym); | ||
} | ||
|
||
std::vector<DiaSymbol> DiaSession::FindChildren(DiaSymbol const& parent, SymbolTag tag, PCWSTR name, CompareOptions options) const { | ||
std::vector<DiaSymbol> symbols; | ||
CComPtr<IDiaEnumSymbols> spEnum; | ||
if (SUCCEEDED(m_spSession->findChildren(parent.m_spSym, (enum SymTagEnum)tag, name, (DWORD)options, &spEnum))) { | ||
LONG count = 0; | ||
spEnum->get_Count(&count); | ||
ULONG ret; | ||
for (LONG i = 0; i < count; i++) { | ||
CComPtr<IDiaSymbol> sym; | ||
spEnum->Next(1, &sym, &ret); | ||
ATLASSERT(sym); | ||
if (sym == nullptr) | ||
break; | ||
symbols.push_back(DiaSymbol(sym)); | ||
} | ||
} | ||
return symbols; | ||
} | ||
|
||
bool DiaSession::OpenCommon(PCWSTR path, bool image) { | ||
if (g_hDiaDll == nullptr) { | ||
g_hDiaDll = ::LoadLibrary(L"msdia140.dll"); | ||
} | ||
CComPtr<IDiaDataSource> spSource; | ||
HRESULT hr; | ||
if (g_hDiaDll) { | ||
// | ||
// implement CoCreateInstance manually to make sure our msdia DLL is loaded | ||
// | ||
auto dgco = (decltype(::DllGetClassObject)*)::GetProcAddress(g_hDiaDll, "DllGetClassObject"); | ||
if (!dgco) | ||
return false; | ||
|
||
CComPtr<IClassFactory> spCF; | ||
if (FAILED(dgco(__uuidof(DiaSource), __uuidof(IClassFactory), reinterpret_cast<void**>(&spCF)))) | ||
return false; | ||
|
||
hr = spCF->CreateInstance(nullptr, __uuidof(IDiaDataSource), reinterpret_cast<void**>(&spSource)); | ||
} | ||
else { | ||
hr = spSource.CoCreateInstance(__uuidof(DiaSource)); | ||
} | ||
if (FAILED(hr)) | ||
return false; | ||
if (image) | ||
hr = spSource->loadDataForExe(path, nullptr, nullptr); | ||
else | ||
hr = spSource->loadDataFromPdb(path); | ||
if (FAILED(hr)) | ||
return false; | ||
|
||
CComPtr<IDiaSession> spSession; | ||
hr = spSource->openSession(&spSession); | ||
if (FAILED(hr)) | ||
return false; | ||
|
||
m_spSession = spSession; | ||
m_spSource = spSource; | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#pragma once | ||
|
||
#include "dia2.h" | ||
#include "DiaSymbol.h" | ||
#include <optional> | ||
#include <vector> | ||
#include <string> | ||
|
||
enum class CompareOptions { | ||
None = 0, | ||
CaseSensitive = 0x1, | ||
CaseInsensitive = 0x2, | ||
FNameExt = 0x4, | ||
RegularExpression = 0x8, | ||
UndecoratedName = 0x10, | ||
CaseInRegularExpression = (RegularExpression | CaseInsensitive) | ||
}; | ||
DEFINE_ENUM_FLAG_OPERATORS(CompareOptions); | ||
|
||
class DiaSession { | ||
public: | ||
bool OpenImage(PCWSTR path); | ||
bool OpenPdb(PCWSTR path); | ||
void Close(); | ||
std::wstring LastError() const; | ||
|
||
DiaSymbol GlobalScope() const; | ||
std::vector<DiaSymbol> FindChildren(DiaSymbol const& parent, SymbolTag tag = SymbolTag::Null, PCWSTR name = nullptr, | ||
CompareOptions options = CompareOptions::None) const; | ||
|
||
private: | ||
bool OpenCommon(PCWSTR path, bool image); | ||
|
||
private: | ||
CComPtr<IDiaSession> m_spSession; | ||
CComPtr<IDiaDataSource> m_spSource; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup Label="ProjectConfigurations"> | ||
<ProjectConfiguration Include="Debug|Win32"> | ||
<Configuration>Debug</Configuration> | ||
<Platform>Win32</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="Release|Win32"> | ||
<Configuration>Release</Configuration> | ||
<Platform>Win32</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="Debug|x64"> | ||
<Configuration>Debug</Configuration> | ||
<Platform>x64</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="Release|x64"> | ||
<Configuration>Release</Configuration> | ||
<Platform>x64</Platform> | ||
</ProjectConfiguration> | ||
</ItemGroup> | ||
<PropertyGroup Label="Globals"> | ||
<VCProjectVersion>16.0</VCProjectVersion> | ||
<Keyword>Win32Proj</Keyword> | ||
<ProjectGuid>{d1e93c91-d2d9-460b-a00e-1dcabaafcb9f}</ProjectGuid> | ||
<RootNamespace>DiaHelper</RootNamespace> | ||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> | ||
</PropertyGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | ||
<ConfigurationType>StaticLibrary</ConfigurationType> | ||
<UseDebugLibraries>true</UseDebugLibraries> | ||
<PlatformToolset>v143</PlatformToolset> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | ||
<ConfigurationType>StaticLibrary</ConfigurationType> | ||
<UseDebugLibraries>false</UseDebugLibraries> | ||
<PlatformToolset>v143</PlatformToolset> | ||
<WholeProgramOptimization>true</WholeProgramOptimization> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> | ||
<ConfigurationType>StaticLibrary</ConfigurationType> | ||
<UseDebugLibraries>true</UseDebugLibraries> | ||
<PlatformToolset>v143</PlatformToolset> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | ||
<ConfigurationType>StaticLibrary</ConfigurationType> | ||
<UseDebugLibraries>false</UseDebugLibraries> | ||
<PlatformToolset>v143</PlatformToolset> | ||
<WholeProgramOptimization>true</WholeProgramOptimization> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | ||
<ImportGroup Label="ExtensionSettings"> | ||
</ImportGroup> | ||
<ImportGroup Label="Shared"> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<PropertyGroup Label="UserMacros" /> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<ConformanceMode>true</ConformanceMode> | ||
<PrecompiledHeader>Use</PrecompiledHeader> | ||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> | ||
<LanguageStandard>stdcpp20</LanguageStandard> | ||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem> | ||
</SubSystem> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<FunctionLevelLinking>true</FunctionLevelLinking> | ||
<IntrinsicFunctions>true</IntrinsicFunctions> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<ConformanceMode>true</ConformanceMode> | ||
<PrecompiledHeader>Use</PrecompiledHeader> | ||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> | ||
<LanguageStandard>stdcpp20</LanguageStandard> | ||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem> | ||
</SubSystem> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<ConformanceMode>true</ConformanceMode> | ||
<PrecompiledHeader>Use</PrecompiledHeader> | ||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> | ||
<LanguageStandard>stdcpp20</LanguageStandard> | ||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem> | ||
</SubSystem> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<FunctionLevelLinking>true</FunctionLevelLinking> | ||
<IntrinsicFunctions>true</IntrinsicFunctions> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<ConformanceMode>true</ConformanceMode> | ||
<PrecompiledHeader>Use</PrecompiledHeader> | ||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> | ||
<LanguageStandard>stdcpp20</LanguageStandard> | ||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem> | ||
</SubSystem> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemGroup> | ||
<ClInclude Include="DiaHelper.h" /> | ||
<ClInclude Include="DiaSymbol.h" /> | ||
<ClInclude Include="pch.h" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClCompile Include="DiaHelper.cpp" /> | ||
<ClCompile Include="DiaSymbol.cpp" /> | ||
<ClCompile Include="pch.cpp"> | ||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader> | ||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader> | ||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader> | ||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader> | ||
</ClCompile> | ||
</ItemGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||
<ImportGroup Label="ExtensionTargets"> | ||
</ImportGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup> | ||
<Filter Include="Source Files"> | ||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> | ||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions> | ||
</Filter> | ||
<Filter Include="Header Files"> | ||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> | ||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions> | ||
</Filter> | ||
<Filter Include="Resource Files"> | ||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> | ||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> | ||
</Filter> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClInclude Include="pch.h"> | ||
<Filter>Header Files</Filter> | ||
</ClInclude> | ||
<ClInclude Include="DiaHelper.h"> | ||
<Filter>Header Files</Filter> | ||
</ClInclude> | ||
<ClInclude Include="DiaSymbol.h"> | ||
<Filter>Header Files</Filter> | ||
</ClInclude> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClCompile Include="DiaHelper.cpp"> | ||
<Filter>Source Files</Filter> | ||
</ClCompile> | ||
<ClCompile Include="pch.cpp"> | ||
<Filter>Source Files</Filter> | ||
</ClCompile> | ||
<ClCompile Include="DiaSymbol.cpp"> | ||
<Filter>Source Files</Filter> | ||
</ClCompile> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "pch.h" | ||
#include "DiaSymbol.h" | ||
|
||
DiaSymbol::DiaSymbol(IDiaSymbol* sym) : m_spSym(sym) { | ||
} | ||
|
||
DiaSymbol::operator bool() const { | ||
return m_spSym != nullptr; | ||
} | ||
|
||
std::wstring DiaSymbol::Name() const { | ||
CComBSTR name; | ||
return S_OK == m_spSym->get_name(&name) ? name.m_str : L""; | ||
} | ||
|
||
uint32_t DiaSymbol::Id() const { | ||
uint32_t id = 0; | ||
m_spSym->get_symIndexId((DWORD*)&id); | ||
return id; | ||
} | ||
|
||
int32_t DiaSymbol::Offset() const { | ||
int32_t offset; | ||
m_spSym->get_offset((LONG*)&offset); | ||
return offset; | ||
} | ||
|
||
LocationKind DiaSymbol::Location() const { | ||
DWORD loc = 0; | ||
m_spSym->get_locationType(&loc); | ||
return static_cast<LocationKind>(loc); | ||
} | ||
|
||
SymbolTag DiaSymbol::Tag() const { | ||
DWORD tag = 0; | ||
m_spSym->get_symTag(&tag); | ||
return SymbolTag(tag); | ||
} | ||
|
||
DataItemKind DiaSymbol::Kind() const { | ||
DWORD kind = 0; | ||
m_spSym->get_dataKind(&kind); | ||
return static_cast<DataItemKind>(kind); | ||
} |
Oops, something went wrong.