Skip to content

Commit c81113a

Browse files
committed
Switch to registration-free COM for hookcheck
1 parent 3ce2cc1 commit c81113a

File tree

5 files changed

+22
-11
lines changed

5 files changed

+22
-11
lines changed

utils/hookcheck.exe

0 Bytes
Binary file not shown.

utils/src/hookcheck/hookcheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ int wmain(int argc, wchar_t* argv[])
159159
using enum PdbAnalyzer::LoadError;
160160

161161
case DiaSdkNotFound:
162-
message = L"Failed to create DIA data source. Is DIA SDK installed?";
162+
message = L"Failed to create DIA data source";
163163
break;
164164
case PdbNotLoadable:
165165
message = L"Failed to load the PDB file";

utils/src/hookcheck/pdb-analyzer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <array>
2121

2222
#include <dia2.h>
23+
#include <diacreate.h>
2324

2425
#pragma comment(lib, "diaguids.lib")
2526

@@ -151,7 +152,7 @@ auto PdbAnalyzer::LoadPdb(const std::wstring& pdb) -> std::pair<LoadError, HRESU
151152
{
152153
using enum LoadError;
153154

154-
HRESULT hr = CoCreateInstance(CLSID_DiaSource, nullptr, CLSCTX_INPROC_SERVER, IID_IDiaDataSource, (void**)&m_dataSource);
155+
HRESULT hr = NoRegCoCreate(L"" MSDIA_DLL, CLSID_DiaSource, IID_IDiaDataSource, (void**)&m_dataSource);
155156

156157
if (FAILED(hr))
157158
return std::make_pair(DiaSdkNotFound, hr);

utils/src/hookcheck/premake5.lua

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ project "hookcheck"
4242
if errc ~= 0 then error("DIA SDK not found") end
4343
print("[+] Using ".. diaSdkRoot)
4444

45+
includedirs { path.join(diaSdkRoot, "include") }
46+
libdirs { path.join(diaSdkRoot, "lib", "amd64") }
47+
4548
-- Copy all *.dll files in <VS>/DIA SDK/bin/amd64 to the build directory
4649
runtimeDlls = os.matchfiles(path.join(diaSdkRoot, "bin", "amd64", "*.dll"))
4750
for i = 1, #runtimeDlls do
@@ -51,5 +54,10 @@ project "hookcheck"
5154
postbuildcommands(runtimeDlls)
5255
end
5356

54-
includedirs { path.join(diaSdkRoot, "include") }
55-
libdirs { path.join(diaSdkRoot, "lib", "amd64") }
57+
-- Make the source code independent of the version inside the DLL name
58+
msdiaDll = os.matchfiles(path.join(diaSdkRoot, "bin", "amd64", "msdia*.dll"))
59+
msdiaDll = msdiaDll[1]
60+
if not msdiaDll then error("msdia*.dll not found") end
61+
msdiaDll = path.getname(msdiaDll)
62+
defines { "MSDIA_DLL=" .. ("%q"):format(msdiaDll) }
63+
print("[+] Using ".. msdiaDll)

utils/src/hookcheck/utility.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,34 @@ using HRESULT = long;
1919

2020
void Trim(std::wstring& input);
2121

22-
template <typename...Args>
22+
template <typename... Args>
2323
void PrintLn(const std::wformat_string<Args...> fmt, Args&&... args)
2424
{
2525
std::wcout << std::format(fmt, std::forward<Args>(args)...) << std::endl;
2626
}
2727

28-
template <typename...Args>
28+
template <typename... Args>
2929
void PrintWarningLn(const std::wformat_string<Args...> fmt, Args&&... args)
3030
{
3131
std::wcerr << L"Warning: " << std::format(fmt, std::forward<Args>(args)...) << std::endl;
3232
}
3333

34-
template <typename...Args>
34+
template <typename... Args>
3535
void PrintErrorLn(const std::wformat_string<Args...> fmt, Args&&... args)
3636
{
3737
std::wcerr << L"Error: " << std::format(fmt, std::forward<Args>(args)...) << std::endl;
3838
}
3939

40-
template <typename...Args>
40+
template <typename... Args>
4141
void PrintWarningLn(const HRESULT hr, const std::wformat_string<Args...> fmt, Args&&... args)
4242
{
43-
std::wcerr << std::format(L"Warning (0x{:08x}): ", hr) << std::format(fmt, std::forward<Args>(args)...) << std::endl;
43+
std::wcerr << std::format(L"Warning (0x{:08x}): ", static_cast<unsigned long>(hr))
44+
<< std::format(fmt, std::forward<Args>(args)...) << std::endl;
4445
}
4546

46-
template <typename...Args>
47+
template <typename... Args>
4748
void PrintErrorLn(const HRESULT hr, const std::wformat_string<Args...> fmt, Args&&... args)
4849
{
49-
std::wcerr << std::format(L"Error (0x{:08x}): ", hr) << std::format(fmt, std::forward<Args>(args)...) << std::endl;
50+
std::wcerr << std::format(L"Error (0x{:08x}): ", static_cast<unsigned long>(hr))
51+
<< std::format(fmt, std::forward<Args>(args)...) << std::endl;
5052
}

0 commit comments

Comments
 (0)