Skip to content

Commit

Permalink
interceptor: Add get_live_replacement_invocation()
Browse files Browse the repository at this point in the history
Intended for language bindings that want to find the matching
InvocationContext given the replacement function's address.
  • Loading branch information
oleavr committed May 10, 2024
1 parent e5928a7 commit 8af54ef
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
20 changes: 19 additions & 1 deletion gum/guminterceptor.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2008-2022 Ole André Vadla Ravnås <oleavr@nowsecure.com>
* Copyright (C) 2008-2024 Ole André Vadla Ravnås <oleavr@nowsecure.com>
* Copyright (C) 2008 Christian Berentsen <jc.berentsen@gmail.com>
* Copyright (C) 2024 Francesco Tamagni <mrmacete@protonmail.ch>
*
Expand Down Expand Up @@ -705,6 +705,24 @@ gum_interceptor_get_current_invocation (void)
return &entry->invocation_context;
}

GumInvocationContext *
gum_interceptor_get_live_replacement_invocation (gpointer replacement_function)
{
InterceptorThreadContext * interceptor_ctx;
GumInvocationStackEntry * entry;

interceptor_ctx = get_interceptor_thread_context ();
entry = gum_invocation_stack_peek_top (interceptor_ctx->stack);
if (entry == NULL)
return NULL;
if (!entry->calling_replacement)
return NULL;
if (replacement_function != entry->function_ctx->replacement_function)
return NULL;

return &entry->invocation_context;
}

GumInvocationStack *
gum_interceptor_get_current_stack (void)
{
Expand Down
4 changes: 3 additions & 1 deletion gum/guminterceptor.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2008-2022 Ole André Vadla Ravnås <oleavr@nowsecure.com>
* Copyright (C) 2008-2024 Ole André Vadla Ravnås <oleavr@nowsecure.com>
* Copyright (C) 2008 Christian Berentsen <jc.berentsen@gmail.com>
* Copyright (C) 2024 Francesco Tamagni <mrmacete@protonmail.ch>
*
Expand Down Expand Up @@ -62,6 +62,8 @@ GUM_API void gum_interceptor_end_transaction (GumInterceptor * self);
GUM_API gboolean gum_interceptor_flush (GumInterceptor * self);

GUM_API GumInvocationContext * gum_interceptor_get_current_invocation (void);
GUM_API GumInvocationContext * gum_interceptor_get_live_replacement_invocation (
gpointer replacement_function);
GUM_API GumInvocationStack * gum_interceptor_get_current_stack (void);

GUM_API void gum_interceptor_ignore_current_thread (GumInterceptor * self);
Expand Down

0 comments on commit 8af54ef

Please sign in to comment.