Skip to content

Commit

Permalink
libusermode: use tid from proc_data instead of thread_id (#1726)
Browse files Browse the repository at this point in the history
  • Loading branch information
disaykin authored Oct 12, 2023
1 parent bed7d79 commit ee0bc46
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
15 changes: 2 additions & 13 deletions src/libusermode/userhook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,12 @@ proc_data_t get_proc_data(drakvuf_t drakvuf, const drakvuf_trap_info_t* info)
*/
static dll_t* get_pending_dll(drakvuf_t drakvuf, drakvuf_trap_info* info, userhook* plugin)
{
uint32_t thread_id;
if (!drakvuf_get_current_thread_id(drakvuf, info, &thread_id))
return nullptr;

proc_data_t proc_data = get_proc_data(drakvuf, info);
if (auto it = plugin->loaded_dlls.find(proc_data.pid); it != plugin->loaded_dlls.end())
{
for (auto& dll_meta : it->second)
{
if (!dll_meta.v.is_hooked && dll_meta.v.thread_id == thread_id)
if (!dll_meta.v.is_hooked && dll_meta.v.tid == proc_data.tid)
return &dll_meta;
}
}
Expand Down Expand Up @@ -236,17 +232,10 @@ static dll_t* create_dll_meta(drakvuf_t drakvuf, drakvuf_trap_info* info, userho
return nullptr;
}

uint32_t thread_id;
if (!drakvuf_get_current_thread_id(drakvuf, info, &thread_id))
{
PRINT_DEBUG("[USERHOOK] Failed to get TID\n");
return nullptr;
}

dll_t dll_meta =
{
.v.dtb = info->regs->cr3,
.v.thread_id = thread_id,
.v.tid = proc_data.tid,
.v.real_dll_base = (mmvad->starting_vpn << 12),
.v.mmvad = *mmvad,
.v.is_hooked = false
Expand Down
2 changes: 1 addition & 1 deletion src/libusermode/userhook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ struct dll_view_t
{
// relevant while loading
addr_t dtb;
uint32_t thread_id;
uint32_t tid;
addr_t real_dll_base;
mmvad_info_t mmvad;
bool is_hooked;
Expand Down

0 comments on commit ee0bc46

Please sign in to comment.