Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rework hooks in pluginex class #1711

Closed
wants to merge 7 commits into from

Conversation

1ndahous3
Copy link
Contributor

@1ndahous3 1ndahous3 commented Sep 15, 2023

This improvement implements storing hooks in the pluginex base class, so that almost all plugins no longer need to store hook objects (inherited from BaseHook) in their own containers.

Hooks were typically stored in plugin members in two ways:

  • separate pointers (std::unique_ptr<libhook::SyscallHook> some_func_hook;)
  • map (std::map<uint64_t, std::unique_ptr<libhook::ReturnHook>> ret_hooks with the key calculated by the make_hook_id()), which also breaks some plugins (Hooks on nested functions are broken #1712)

Hooks are now by default saved in the pluginex::hooks map with a unique key (hook address), so there are additional methods to remove or register (i.e. take ownership of an existing hook previously created with the save = false flag) hook.

So, the key changes:

  • pluginex methods for creating hooks (eg createReturnHook()) now return raw pointers (instead of 'std::unique_ptr') and have a bool save flag (true by default).
  • removed custom maps and std::unique_ptrs in varoius plugins.
  • now return hooks are removed from their callbacks (*_ret_cb()) using the backward reference in params (this->remove_hook(params->hook_);).
  • if the plugin needs to perform more complex manipulations with the hook, it can store the raw pointer during creation to later delete it (by passing the pointer to plugin->remove_hook()) or just read the information via dereference.
  • the plugin can pass the bool = false flag, then it is responsible for storing/deleting the hook (usually in this case the raw pointer is instantly wrapped in std::unique_ptr).

Also made a small refactoring related to containers in different classes (std::map -> std::unordered_map, std::vector -> std::unordered_set, etc.).

@drakvuf-jenkins
Copy link
Collaborator

Can one of the admins verify this patch?

src/plugins/plugins_ex.h Dismissed Show resolved Hide resolved
src/plugins/plugins_ex.h Dismissed Show resolved Hide resolved
@1ndahous3 1ndahous3 marked this pull request as ready for review September 18, 2023 13:27
@1ndahous3 1ndahous3 marked this pull request as draft September 19, 2023 09:05
@tklengyel
Copy link
Owner

This PR will need a rebase. Closing it for now as there hasn't been any progress in months, feel free to reopen.

@tklengyel tklengyel closed this Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants