Exemple #1
0
static gboolean
gum_kernel_scan_context_emit_match (GumAddress address,
                                    gsize size,
                                    GumKernelScanContext * self)
{
  GumDukCore * core = self->core;
  GumDukScope scope;
  duk_context * ctx;
  gboolean proceed;

  ctx = _gum_duk_scope_enter (&scope, core);

  duk_push_heapptr (ctx, self->on_match);

  _gum_duk_push_uint64 (ctx, address, core);
  duk_push_number (ctx, size);

  proceed = TRUE;

  if (_gum_duk_scope_call (&scope, 2))
  {
    if (duk_is_string (ctx, -1))
      proceed = strcmp (duk_require_string (ctx, -1), "stop") != 0;
  }
  duk_pop (ctx);

  _gum_duk_scope_leave (&scope);

  return proceed;
}
static gboolean
gum_duk_exception_handler_on_exception (GumExceptionDetails * details,
                                        gpointer user_data)
{
  GumDukExceptionHandler * handler = user_data;
  GumDukCore * core = handler->core;
  GumDukScope scope;
  duk_context * ctx;
  GumDukCpuContext * cpu_context;
  gboolean handled = FALSE;

  ctx = _gum_duk_scope_enter (&scope, core);

  _gum_duk_push_exception_details (ctx, details, core, &cpu_context);

  duk_push_heapptr (ctx, handler->callback);
  duk_dup (ctx, -2);
  if (_gum_duk_scope_call (&scope, 1))
  {
    if (duk_is_boolean (ctx, -1))
      handled = duk_require_boolean (ctx, -1);
  }

  _gum_duk_cpu_context_make_read_only (cpu_context);

  duk_pop_2 (ctx);

  _gum_duk_scope_leave (&scope);

  return handled;
}
Exemple #3
0
static void
gum_duk_invocation_listener_dispose (GumDukInvocationListener * self)
{
  GumDukCore * core = self->module->core;
  GumDukScope scope;

  _gum_duk_scope_enter (&scope, core);
  _gum_duk_release_heapptr (self->ctx, self->object);
  _gum_duk_scope_leave (&scope);
}
Exemple #4
0
static void
gum_duk_invocation_listener_on_enter (GumInvocationListener * listener,
                                      GumInvocationContext * ic)
{
  GumDukInvocationListener * self = GUM_DUK_INVOCATION_LISTENER_CAST (listener);

  if (gum_script_backend_is_ignoring (
      gum_invocation_context_get_thread_id (ic)))
    return;

  if (self->on_enter != NULL)
  {
    GumDukInterceptor * module = self->module;
    GumDukCore * core = module->core;
    duk_context * ctx = core->ctx;
    GumDukScope scope;
    GumDukInvocationContext * jic;
    GumDukInvocationArgs * args;

    _gum_duk_scope_enter (&scope, core);

    jic = _gum_duk_interceptor_obtain_invocation_context (module);
    _gum_duk_invocation_context_reset (jic, ic);

    args = gum_duk_interceptor_obtain_invocation_args (module);
    gum_duk_invocation_args_reset (args, ic);

    duk_push_heapptr (ctx, self->on_enter);
    duk_push_heapptr (ctx, jic->object);
    duk_push_heapptr (ctx, args->object);
    _gum_duk_scope_call_method (&scope, 1);
    duk_pop (ctx);

    gum_duk_invocation_args_reset (args, NULL);
    gum_duk_interceptor_release_invocation_args (module, args);

    _gum_duk_invocation_context_reset (jic, NULL);
    if (self->on_leave != NULL)
    {
      *GUM_LINCTX_GET_FUNC_INVDATA (ic, GumDukHeapPtr) = jic;
    }
    else
    {
      _gum_duk_interceptor_release_invocation_context (module, jic);
    }

    _gum_duk_scope_leave (&scope);
  }
}
Exemple #5
0
static void
gum_duk_invocation_listener_on_leave (GumInvocationListener * listener,
                                      GumInvocationContext * ic)
{
  GumDukInvocationListener * self = GUM_DUK_INVOCATION_LISTENER_CAST (listener);

  if (gum_script_backend_is_ignoring (
      gum_invocation_context_get_thread_id (ic)))
    return;

  if (self->on_leave != NULL)
  {
    GumDukInterceptor * module = self->module;
    GumDukCore * core = module->core;
    duk_context * ctx = core->ctx;
    GumDukScope scope;
    GumDukInvocationContext * jic;
    GumDukInvocationReturnValue * retval;

    _gum_duk_scope_enter (&scope, core);

    jic = (self->on_enter != NULL)
        ? *GUM_LINCTX_GET_FUNC_INVDATA (ic, GumDukInvocationContext *)
        : NULL;
    if (jic == NULL)
    {
      jic = _gum_duk_interceptor_obtain_invocation_context (module);
    }
    _gum_duk_invocation_context_reset (jic, ic);

    retval = gum_duk_interceptor_obtain_invocation_return_value (module);
    gum_duk_invocation_return_value_reset (retval, ic);

    duk_push_heapptr (ctx, self->on_leave);
    duk_push_heapptr (ctx, jic->object);
    duk_push_heapptr (ctx, retval->object);
    _gum_duk_scope_call_method (&scope, 1);
    duk_pop (ctx);

    gum_duk_invocation_return_value_reset (retval, NULL);
    gum_duk_interceptor_release_invocation_return_value (module, retval);

    _gum_duk_invocation_context_reset (jic, NULL);
    _gum_duk_interceptor_release_invocation_context (module, jic);

    _gum_duk_scope_leave (&scope);
  }
Exemple #6
0
static void
gum_kernel_scan_context_run (GumKernelScanContext * self)
{
  GumDukCore * core = self->core;
  GumDukScope script_scope;
  duk_context * ctx;

  gum_kernel_scan (&self->range, self->pattern,
      (GumMemoryScanMatchFunc) gum_kernel_scan_context_emit_match, self);

  ctx = _gum_duk_scope_enter (&script_scope, core);

  duk_push_heapptr (ctx, self->on_complete);
  _gum_duk_scope_call (&script_scope, 0);
  duk_pop (ctx);

  _gum_duk_scope_leave (&script_scope);
}
Exemple #7
0
static void
gum_kernel_scan_context_free (GumKernelScanContext * self)
{
  GumDukCore * core = self->core;
  GumDukScope scope;
  duk_context * ctx;

  ctx = _gum_duk_scope_enter (&scope, core);

  _gum_duk_unprotect (ctx, self->on_match);
  if (self->on_error != NULL)
    _gum_duk_unprotect (ctx, self->on_error);
  _gum_duk_unprotect (ctx, self->on_complete);

  _gum_duk_core_unpin (core);
  _gum_duk_scope_leave (&scope);

  gum_match_pattern_free (self->pattern);

  g_slice_free (GumKernelScanContext, self);
}