Setup a hook on the entry and return it. You MUST keep a reference to the hook while the hook is enabled. :param callback: the hook .. note:: see :ref:`hook_protocol` :rtype: :class:`windows.hooks.IATHook` .. warning:: Thi
(self, callback, types=None)
| 162 | return '<{0} "{1}" ordinal {2}>'.format(self.__class__.__name__, self.name, self.ord) |
| 163 | |
| 164 | def set_hook(self, callback, types=None): |
| 165 | """Setup a hook on the entry and return it. |
| 166 | You MUST keep a reference to the hook while the hook is enabled. |
| 167 | |
| 168 | :param callback: the hook |
| 169 | |
| 170 | .. note:: |
| 171 | |
| 172 | see :ref:`hook_protocol` |
| 173 | |
| 174 | :rtype: :class:`windows.hooks.IATHook` |
| 175 | |
| 176 | .. warning:: |
| 177 | |
| 178 | This works only for PEFile with the current process as target. |
| 179 | """ |
| 180 | if self.target is not None: |
| 181 | raise NotImplementedError("Setting hook in remote process (use python code injection)") |
| 182 | |
| 183 | hook = hooks.IATHook(self, callback, types) |
| 184 | import weakref |
| 185 | self.whook = weakref.ref(hook, self.on_destroy) |
| 186 | self.hook = hook |
| 187 | hook.enable() |
| 188 | return hook |
| 189 | |
| 190 | def on_destroy(self, *args): |
| 191 | # We cannot know if the hook was enabled here.. |