Пример #1
0
void
gum_spinlock_init (GumSpinlock * spinlock)
{
  GumSpinlockImpl * self = (GumSpinlockImpl *) spinlock;
  GumX86Writer cw;
  gpointer try_again_label = "gum_spinlock_try_again";
  gpointer beach_label = "gum_spinlock_beach";

  self->is_held = FALSE;

  self->code = gum_alloc_n_pages (1, GUM_PAGE_RWX);

  gum_x86_writer_init (&cw, self->code);

  self->acquire_impl = GUM_POINTER_TO_FUNCPTR (GumSpinlockAcquireFunc,
      gum_x86_writer_cur (&cw));
  gum_x86_writer_put_mov_reg_u32 (&cw, GUM_REG_EDX, 1);

  gum_x86_writer_put_label (&cw, try_again_label);
  gum_x86_writer_put_mov_reg_u32 (&cw, GUM_REG_EAX, 0);
  gum_x86_writer_put_lock_cmpxchg_reg_ptr_reg (&cw, GUM_REG_RCX, GUM_REG_EDX);
  gum_x86_writer_put_jcc_short_label (&cw, GUM_X86_JZ, beach_label,
      GUM_NO_HINT);

  gum_x86_writer_put_pause (&cw);
  gum_x86_writer_put_jmp_short_label (&cw, try_again_label);

  gum_x86_writer_put_label (&cw, beach_label);
  gum_x86_writer_put_ret (&cw);

  gum_x86_writer_free (&cw);
}
Пример #2
0
static void
test_memory_access_monitor_fixture_setup (TestMAMonitorFixture * fixture,
                                          gconstpointer data)
{
  fixture->range.base_address = GUM_ADDRESS (gum_alloc_n_pages (2, GUM_PAGE_RWX));
  fixture->range.size = 2 * gum_query_page_size ();
  fixture->offset_in_first_page = gum_query_page_size () / 2;
  fixture->offset_in_second_page =
      fixture->offset_in_first_page + gum_query_page_size ();
  *((guint8 *) fixture->range.base_address) = 0xc3; /* ret instruction */
  fixture->nop_function_in_first_page =
      GUM_POINTER_TO_FUNCPTR (GCallback, fixture->range.base_address);

  fixture->number_of_notifies = 0;

  fixture->monitor = NULL;
}
Пример #3
0
void
lowlevel_helpers_init (void)
{
  GumX86Writer cw;

  g_assert (clobber_test_function == NULL);

  clobber_test_function = GUM_POINTER_TO_FUNCPTR (ClobberTestFunc,
      gum_alloc_n_pages (1, GUM_PAGE_RWX));
  gum_x86_writer_init (&cw, (gpointer) (gsize) clobber_test_function);
  gum_x86_writer_put_nop (&cw);
  gum_x86_writer_put_nop (&cw);
  gum_x86_writer_put_nop (&cw);
  gum_x86_writer_put_nop (&cw);
  gum_x86_writer_put_nop (&cw);
  gum_x86_writer_put_ret (&cw);
  gum_x86_writer_free (&cw);
}
Пример #4
0
void
frida_agent_auto_ignorer_intercept_thread_creation (FridaAgentAutoIgnorer * self,
    GumInvocationContext * ic)
{
  NativeThreadFunc thread_func;

  thread_func = GUM_POINTER_TO_FUNCPTR (NativeThreadFunc, gum_invocation_context_get_nth_argument (ic, 2));
  if (GUM_MEMORY_RANGE_INCLUDES (&self->agent_range, GUM_ADDRESS (thread_func)))
  {
    FridaAutoInterceptContext * ctx;

    ctx = g_slice_new (FridaAutoInterceptContext);
    ctx->interceptor = g_object_ref (self->interceptor);
    ctx->thread_func = thread_func;
    ctx->thread_data = gum_invocation_context_get_nth_argument (ic, 3);
    gum_invocation_context_replace_nth_argument (ic, 2, GUM_FUNCPTR_TO_POINTER (frida_agent_auto_ignorer_thread_create_proxy));
    gum_invocation_context_replace_nth_argument (ic, 3, ctx);
  }
}