Skip to content

Commit

Permalink
Remove all watchers on process exit
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-michaud committed Jul 11, 2020
1 parent 91f3ad9 commit d2d82e3
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions HookCase/HookCase/HookCase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7510,6 +7510,7 @@ hook_t *find_cast_hook(uint64_t unique_pid)
}

void free_watcher(watcher_t *watcherp);
bool unset_watcher(vm_map_t proc_map, watcher_t *watcherp);

void remove_process_hooks(uint64_t unique_pid)
{
Expand All @@ -7536,16 +7537,25 @@ void remove_process_hooks(uint64_t unique_pid)
}
all_hooks_unlock_write();

vm_map_t proc_map = task_map_for_proc(current_proc());

all_watchers_lock_write();
watcher_t *watcherp = NULL;
watcher_t *tmp_watcherp = NULL;
LIST_FOREACH_SAFE(watcherp, &g_all_watchers, list_entry, tmp_watcherp) {
if (watcherp->unique_pid == unique_pid) {
LIST_REMOVE(watcherp, list_entry);
if (proc_map) {
unset_watcher(proc_map, watcherp);
}
free_watcher(watcherp);
}
}
all_watchers_unlock_write();

if (proc_map) {
vm_map_deallocate(proc_map);
}
}

bool process_has_hooks(uint64_t unique_pid)
Expand Down

0 comments on commit d2d82e3

Please sign in to comment.