Skip to content

Commit

Permalink
Fix for incorrectly decoded module name
Browse files Browse the repository at this point in the history
The module name is now extracted from image_name instead of module_name which
 was empty in my tests using TTD
  • Loading branch information
lowleveldesign committed Jun 25, 2022
1 parent e3849f5 commit 8a1b0f4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 26 deletions.
2 changes: 2 additions & 0 deletions comon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ target_link_libraries(comon PRIVATE
target_compile_definitions(comon PRIVATE
EXT_MAJOR_VER=${comon_VERSION_MAJOR}
EXT_MINOR_VER=${comon_VERSION_MINOR}
EXT_PATCH_VER=${comon_VERSION_PATCH}
EXT_TWEAK_VER=${comon_VERSION_TWEAK}
)

set_target_properties(comon PROPERTIES
Expand Down
3 changes: 2 additions & 1 deletion comon/cohelp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ extern "C" HRESULT CALLBACK cohelp(IDebugClient *dbgclient, [[maybe_unused]] PCS
RETURN_IF_FAILED(dbgclient->QueryInterface(__uuidof(IDebugControl4), dbgcontrol.put_void()));

dbgcontrol->OutputWide(DEBUG_OUTPUT_NORMAL, L"==============================================================\n");
dbgcontrol->OutputWide(DEBUG_OUTPUT_NORMAL, L" comon v%d.%d - Copyright 2022 Sebastian Solnica\n", EXT_MAJOR_VER, EXT_MINOR_VER);
dbgcontrol->OutputWide(DEBUG_OUTPUT_NORMAL, L" comon v%d.%d.%d.%d - Copyright 2022 Sebastian Solnica\n", EXT_MAJOR_VER, EXT_MINOR_VER,
EXT_PATCH_VER, EXT_TWEAK_VER);
dbgcontrol->OutputWide(DEBUG_OUTPUT_NORMAL, L"==============================================================\n\n");

dbgcontrol->OutputWide(DEBUG_OUTPUT_NORMAL, LR"(Available commands:
Expand Down
1 change: 1 addition & 0 deletions comon/comonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ HRESULT comonitor::create_cobreakpoint(const CLSID &clsid, const IID &iid, DWORD

return S_OK;
} else {
_logger.log_error(L"Could not locate COM class metadata.", E_INVALIDARG);
return E_INVALIDARG;
}
}
Expand Down
43 changes: 18 additions & 25 deletions comon/dbgsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,47 +24,41 @@ using namespace comon_ext;

namespace fs = std::filesystem;

static const std::wstring_view combase_module_name{ L"combase" };

dbgsession::dbgsession() :
_dbgclient{ create_IDebugClient() },
_dbgcontrol{ _dbgclient.query<IDebugControl4>() },
_dbgsymbols{ _dbgclient.query<IDebugSymbols3>() },
_dbgsystemobjects{ _dbgclient.query<IDebugSystemObjects>() },
_cometa{ std::make_shared<cometa>(_dbgcontrol.get(), get_cometa_db_path()) },
_logger{ _dbgcontrol.get() },
_log_filter{ std::make_shared<cofilter>(cofilter::filter_type::Disabled) }
{
static const std::wstring_view combase_module_name{L"combase"};

dbgsession::dbgsession()
: _dbgclient{create_IDebugClient()}, _dbgcontrol{_dbgclient.query<IDebugControl4>()}, _dbgsymbols{_dbgclient.query<IDebugSymbols3>()},
_dbgsystemobjects{_dbgclient.query<IDebugSystemObjects>()}, _cometa{std::make_shared<cometa>(_dbgcontrol.get(),
get_cometa_db_path())},
_logger{_dbgcontrol.get()}, _log_filter{std::make_shared<cofilter>(cofilter::filter_type::Disabled)} {
THROW_IF_FAILED(_dbgclient->GetEventCallbacksWide(_prev_callback.put()));
THROW_IF_FAILED(_dbgclient->SetEventCallbacksWide(this));
}

HRESULT __stdcall dbgsession::Breakpoint(PDEBUG_BREAKPOINT2 bp) {
ULONG id;
if (SUCCEEDED(bp->GetId(&id))) {
if (auto monitor{ _monitors.find(get_active_process_id()) }; monitor != std::end(_monitors)) {
if (auto monitor{_monitors.find(get_active_process_id())}; monitor != std::end(_monitors)) {
return monitor->second.handle_breakpoint(id) ? DEBUG_STATUS_GO : DEBUG_STATUS_NO_CHANGE;
}
}
return DEBUG_STATUS_NO_CHANGE;
}

HRESULT __stdcall dbgsession::LoadModule([[maybe_unused]] ULONG64 image_file_handle,
ULONG64 base_offset,
[[maybe_unused]] ULONG module_size,
PCWSTR module_name,
[[maybe_unused]] PCWSTR image_name,
[[maybe_unused]] ULONG checksum,
ULONG timestamp) {
HRESULT __stdcall dbgsession::LoadModule([[maybe_unused]] ULONG64 image_file_handle, ULONG64 base_offset,
[[maybe_unused]] ULONG module_size, [[maybe_unused]] PCWSTR module_name,
[[maybe_unused]] PCWSTR image_name, [[maybe_unused]] ULONG checksum, ULONG timestamp) {

if (auto monitor{ _monitors.find(get_active_process_id()) }; monitor != std::end(_monitors)) {
monitor->second.handle_module_load(module_name, timestamp, base_offset);
if (fs::path image_path{image_name}; image_path.has_filename()) {
if (auto monitor{_monitors.find(get_active_process_id())}; monitor != std::end(_monitors)) {
monitor->second.handle_module_load(image_path.filename().c_str(), timestamp, base_offset);
}
}
return DEBUG_STATUS_NO_CHANGE;
}

HRESULT __stdcall dbgsession::UnloadModule([[maybe_unused]] PCWSTR image_base_name, ULONG64 image_base_addr) {
if (auto monitor{ _monitors.find(get_active_process_id()) }; monitor != std::end(_monitors)) {
if (auto monitor{_monitors.find(get_active_process_id())}; monitor != std::end(_monitors)) {
monitor->second.handle_module_unload(image_base_addr);
}
return DEBUG_STATUS_NO_CHANGE;
Expand All @@ -76,18 +70,17 @@ HRESULT __stdcall dbgsession::ExitProcess([[maybe_unused]] ULONG exit_code) {
}

void dbgsession::pause() noexcept {
if (auto monitor{ find_active_monitor() }; monitor) {
if (auto monitor{find_active_monitor()}; monitor) {
monitor->pause();
} else {
_logger.log_warning(L"Comon is not monitoring the current process.");
}
}

void dbgsession::resume() noexcept {
if (auto monitor{ find_active_monitor() }; monitor) {
if (auto monitor{find_active_monitor()}; monitor) {
monitor->resume();
} else {
_logger.log_warning(L"Comon is not monitoring the current process.");
}
}

0 comments on commit 8a1b0f4

Please sign in to comment.