about summary refs log tree commit diff
path: root/frida_mode/src/interceptor.c
blob: d2802752d7387c123093d4c4287966c712ded681 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "frida-gum.h"

#include "debug.h"

#include "interceptor.h"

void intercept(void *address, gpointer replacement, gpointer user_data) {

  GumInterceptor *interceptor = gum_interceptor_obtain();
  gum_interceptor_begin_transaction(interceptor);
  GumReplaceReturn ret =
      gum_interceptor_replace(interceptor, address, replacement, user_data);
  if (ret != GUM_REPLACE_OK) { FATAL("gum_interceptor_attach: %d", ret); }
  gum_interceptor_end_transaction(interceptor);

}

void unintercept(void *address) {

  GumInterceptor *interceptor = gum_interceptor_obtain();

  gum_interceptor_begin_transaction(interceptor);
  gum_interceptor_revert(interceptor, address);
  gum_interceptor_end_transaction(interceptor);
  gum_interceptor_flush(interceptor);

}

void unintercept_self(void) {

  GumInvocationContext *ctx = gum_interceptor_get_current_invocation();
  unintercept(ctx->function);

}