Skip to content

Commit

Permalink
Address review issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmacete committed Jan 30, 2024
1 parent 86d5307 commit 1d9338f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 22 deletions.
11 changes: 9 additions & 2 deletions bindings/gumjs/gumquickmemory.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,12 +384,19 @@ GUMJS_DEFINE_FUNCTION (gumjs_memory_query_protection)
GumPageProtection prot;

if (!_gum_quick_args_parse (args, "p", &address))
return JS_EXCEPTION;
goto propagate_exception;

if (!gum_memory_query_protection (address, &prot))
return JS_EXCEPTION;
goto query_failed;

return _gum_quick_page_protection_new (ctx, prot);

query_failed:
_gum_quick_throw_literal (ctx, "failed to query address");

propagate_exception:
return JS_EXCEPTION;

}

GUMJS_DEFINE_FUNCTION (gumjs_memory_patch_code)
Expand Down
14 changes: 4 additions & 10 deletions bindings/gumjs/gumv8memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,18 +360,12 @@ GUMJS_DEFINE_FUNCTION (gumjs_memory_query_protection)
return;

if (!gum_memory_query_protection (address, &prot))
{
_gum_v8_throw_ascii_literal (isolate, "failed to query address");
return;
}

gchar prot_str[4] = "---";

if ((prot & GUM_PAGE_READ) != 0)
prot_str[0] = 'r';
if ((prot & GUM_PAGE_WRITE) != 0)
prot_str[1] = 'w';
if ((prot & GUM_PAGE_EXECUTE) != 0)
prot_str[2] = 'x';

info.GetReturnValue ().Set (_gum_v8_string_new_ascii (isolate, prot_str));
info.GetReturnValue ().Set (_gum_v8_page_protection_new (isolate, prot));
}

GUMJS_DEFINE_FUNCTION (gumjs_memory_patch_code)
Expand Down
30 changes: 20 additions & 10 deletions bindings/gumjs/gumv8value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1713,16 +1713,10 @@ _gum_v8_object_set_page_protection (Local<Object> object,
GumPageProtection prot,
GumV8Core * core)
{
gchar prot_str[4] = "---";

if ((prot & GUM_PAGE_READ) != 0)
prot_str[0] = 'r';
if ((prot & GUM_PAGE_WRITE) != 0)
prot_str[1] = 'w';
if ((prot & GUM_PAGE_EXECUTE) != 0)
prot_str[2] = 'x';

return _gum_v8_object_set_ascii (object, key, prot_str, core);
return _gum_v8_object_set (object,
key,
_gum_v8_page_protection_new (core->isolate, prot),
core);
}

GArray *
Expand Down Expand Up @@ -1811,6 +1805,22 @@ _gum_v8_memory_range_get (Local<Value> value,
return TRUE;
}

v8::Local<v8::String>
_gum_v8_page_protection_new (v8::Isolate * isolate,
GumPageProtection prot)
{
gchar prot_str[4] = "---";

if ((prot & GUM_PAGE_READ) != 0)
prot_str[0] = 'r';
if ((prot & GUM_PAGE_WRITE) != 0)
prot_str[1] = 'w';
if ((prot & GUM_PAGE_EXECUTE) != 0)
prot_str[2] = 'x';

return _gum_v8_string_new_ascii (isolate, prot_str);
}

gboolean
_gum_v8_page_protection_get (Local<Value> prot_val,
GumPageProtection * prot,
Expand Down
2 changes: 2 additions & 0 deletions bindings/gumjs/gumv8value.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ G_GNUC_INTERNAL GArray * _gum_v8_memory_ranges_get (v8::Local<v8::Value> value,
G_GNUC_INTERNAL gboolean _gum_v8_memory_range_get (v8::Local<v8::Value> value,
GumMemoryRange * range, GumV8Core * core);

G_GNUC_INTERNAL v8::Local<v8::String> _gum_v8_page_protection_new (
v8::Isolate * isolate, GumPageProtection prot);
G_GNUC_INTERNAL gboolean _gum_v8_page_protection_get (
v8::Local<v8::Value> prot_val, GumPageProtection * prot,
GumV8Core * core);
Expand Down

0 comments on commit 1d9338f

Please sign in to comment.