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; }
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); }