Skip to content

Commit

Permalink
!cobp command removed
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Solnica committed Jan 14, 2023
1 parent a18984d commit 80b134b
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 106 deletions.
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ Check [**the documentation**](https://wtrace.net/documentation/comon) to learn m
- shows the current monitoring status. It also lists all the virtual tables registered
for a given process providing their IIDs and CLSIDs
!cobp <clsid> <iid> <method_name>
- creates a breakpoint on a method (identified by its name) in a given COM
interface (IID) in a given COM class (CLSID)
!cobp <clsid> <iid< <method_num>
- creates a breakpoint on a method (identified by its index) in a given COM
interface (IID) in a given COM class (CLSID)
!coreg <clsid> <iid> <vtable_address>
- manually add a virtual table address to the COM monitor and bind them with
a given COM interface (IID) and COM class (CLSID)
Expand Down
7 changes: 0 additions & 7 deletions comon/cohelp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,6 @@ extern "C" HRESULT CALLBACK cohelp(IDebugClient * dbgclient, [[maybe_unused]] PC
- shows the current monitoring status. It also lists all the virtual tables registered
for a given process providing their IIDs and CLSIDs
!cobp <clsid> <iid> <method_name>
- creates a breakpoint on a method (identified by its name) in a given COM
interface (IID) in a given COM class (CLSID)
!cobp <clsid> <iid< <method_num>
- creates a breakpoint on a method (identified by its index) in a given COM
interface (IID) in a given COM class (CLSID)
!coreg <clsid> <iid> <vtable_address>
- manually add a virtual table address to the COM monitor and bind them with
a given COM interface (IID) and COM class (CLSID)
Expand Down
59 changes: 0 additions & 59 deletions comon/comonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,65 +98,6 @@ std::variant<comonitor::module_info, HRESULT> comonitor::get_module_info(ULONG64
return module_info{ std::wstring{ buffer.get(), static_cast<size_t>(m.ModuleNameSize) - 1 }, m.TimeDateStamp, m.Size };
}

HRESULT comonitor::create_cobreakpoint(const CLSID& clsid, const IID& iid, DWORD method_num, std::wstring_view method_display_name) {
assert(method_num >= 0);
if (auto vtable{ _cotype_with_vtables.find({ clsid, iid }) }; vtable != std::end(_cotype_with_vtables)) {
ULONG64 addr{};
RETURN_IF_FAILED(_cc.read_pointer(vtable->second + method_num * _cc.get_pointer_size(), addr));

IDebugBreakpoint2* brk{};
RETURN_IF_FAILED(_dbgcontrol->AddBreakpoint2(DEBUG_BREAKPOINT_CODE, DEBUG_ANY_ID, &brk));
RETURN_IF_FAILED(brk->SetOffset(addr));

auto clsid_name{ _cometa->resolve_class_name(clsid) };
auto iid_name{ _cometa->resolve_type_name(iid) };
auto cmd{ std::format(
L".printf /D \"== Method <b>{} [{}]</b> called on a COM object (CLSID: <b>{:b} ({})</b>, IID <b>{:b} ({})</b>) ==\"; .echo",
method_display_name, method_num, iid, iid_name ? *iid_name : L"N/A", clsid, clsid_name ? *clsid_name : L"N/A") };
RETURN_IF_FAILED(brk->SetCommandWide(cmd.c_str()));

ULONG brk_id{};
RETURN_IF_FAILED(brk->GetId(&brk_id));
RETURN_IF_FAILED(brk->AddFlags(DEBUG_BREAKPOINT_ENABLED));

return S_OK;
} else {
_logger.log_error(L"Could not locate COM class metadata.", E_INVALIDARG);
return E_INVALIDARG;
}
}

HRESULT comonitor::create_cobreakpoint(const CLSID& clsid, const IID& iid, DWORD method_num) {
if (method_num < 0) {
return E_INVALIDARG;
}

auto cotype{ _cometa->resolve_type(iid) };

std::wstring method_name{};
if (cotype && cotype->methods_available) {
if (auto methods{ _cometa->get_type_methods(iid) }; methods && methods->size() > method_num) {
method_name = methods->at(method_num);
}
}
return create_cobreakpoint(clsid, iid, method_num, method_name);
}

HRESULT comonitor::create_cobreakpoint(const CLSID& clsid, const IID& iid, std::wstring_view method_name) {
if (auto methods{ _cometa->get_type_methods(iid) }; methods) {
if (auto res{ std::ranges::find(*methods, method_name) }; res != std::end(*methods)) {
auto method_num = static_cast<DWORD>(res - std::begin(*methods));
return create_cobreakpoint(clsid, iid, method_num, method_name);
} else {
_logger.log_error(L"Could not resolve the method name.", E_INVALIDARG);
return E_INVALIDARG;
}
} else {
_logger.log_error(L"No methods found for the type.", E_INVALIDARG);
return E_INVALIDARG;
}
}

void comonitor::try_adding_synthetic_symbols(const IID& iid, ULONG64 vtable_addr) const {
auto iid_name{ _cometa->resolve_type_name(iid) };

Expand Down
2 changes: 0 additions & 2 deletions comon/comonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ class comonitor {

void log_com_call_error(const CLSID& clsid, const IID& iid, std::wstring_view caller_name, HRESULT result_code);

HRESULT create_cobreakpoint(const CLSID& clsid, const IID& iid, DWORD method_num, std::wstring_view method_display_name);

/* Breakpoints handling */
void handle_coquery_return(const coquery_single_return_breakpoint& brk);

Expand Down
30 changes: 0 additions & 30 deletions comon/ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,36 +173,6 @@ extern "C" HRESULT CALLBACK cometa(IDebugClient * dbgclient, PCSTR args) {
}
}

extern "C" HRESULT CALLBACK cobp(IDebugClient * dbgclient, PCSTR args) {
wil::com_ptr_t<IDebugControl4> dbgcontrol;
RETURN_IF_FAILED(dbgclient->QueryInterface(__uuidof(IDebugControl4), dbgcontrol.put_void()));

auto vargs{ split_args(args) };

if (vargs.size() < 3) {
dbgcontrol->OutputWide(DEBUG_OUTPUT_ERROR, L"ERROR: invalid arguments. Run !cohelp to check the syntax.\n");
return E_INVALIDARG;
}

CLSID clsid;
RETURN_IF_FAILED(try_parse_guid(widen(vargs[0]), clsid));
IID iid;
RETURN_IF_FAILED(try_parse_guid(widen(vargs[1]), iid));

if (auto monitor{ g_dbgsession.find_active_monitor() }; monitor) {
try {
DWORD method_num{ std::stoul(vargs[2]) };
return monitor->create_cobreakpoint(clsid, iid, method_num);
} catch (const std::invalid_argument&) {
// we will try with a method name
return monitor->create_cobreakpoint(clsid, iid, widen(vargs[2]));
}
} else {
dbgcontrol->OutputWide(DEBUG_OUTPUT_ERROR, monitor_not_enabled_error);
return E_FAIL;
}
}

extern "C" HRESULT CALLBACK cobl([[maybe_unused]] IDebugClient * dbgclient, [[maybe_unused]] PCSTR args) {
wil::com_ptr_t<IDebugControl4> dbgcontrol;
RETURN_IF_FAILED(dbgclient->QueryInterface(__uuidof(IDebugControl4), dbgcontrol.put_void()));
Expand Down
1 change: 0 additions & 1 deletion comon/ext.def
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ EXPORTS
DebugExtensionUninitialize

cometa
cobp
cobl
cobd
cohelp
Expand Down

0 comments on commit 80b134b

Please sign in to comment.