Skip to content

Commit

Permalink
123123
Browse files Browse the repository at this point in the history
  • Loading branch information
nmoinvaz committed Dec 24, 2024
1 parent 634b430 commit 888556a
Showing 1 changed file with 54 additions and 53 deletions.
107 changes: 54 additions & 53 deletions execute_jscore6.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ typedef struct g_proxy_execute_jscore6_s {
GDestroyNotify destroy_notify, GType return_type, guint n_params, ...);
void (*jsc_value_object_set_property)(JSCValue *value, const char *name, JSCValue *property);
JSCValue *(*jsc_value_object_get_property)(JSCValue *value, const char *name);
// Exception functions
char* (*jsc_exception_report)(JSCException* exception);
} g_proxy_execute_jscore6_s;

g_proxy_execute_jscore6_s g_proxy_execute_jscore6;
Expand All @@ -63,40 +65,21 @@ static JSCValue *js_object_get_string_property(JSCValue *object, char *name) {
return NULL;
}

static void js_print_exception(JSCContext *context, JSCValue *exception) {
bool printed = false;

static void js_print_exception(JSCContext *context, JSCException *exception) {
if (!exception)
return;

if (g_proxy_execute_jscore6.jsc_value_is_object(exception)) {
int line = js_object_get_double_property(exception, "line");
JSCValue *message_string = js_object_get_string_property(exception, "message");
if (message_string) {
char *message = g_proxy_execute_jscore6.jsc_value_to_string(message_string);
if (message) {
printf("EXCEPTION: %s (line %d)\n", message, line);
free(message);
printed = true;
}
g_object_unref(message_string);
}
}

if (!printed) {
LOG_ERROR("Unable to print unknown exception object\n");
char *report = jsc_exception_report(exception);
if (report) {
printf("EXCEPTION: %s\n", report);
free(report);
return;
}
}

static JSCValue *proxy_execute_jscore6_dns_resolve(JSCContext *context, JSCValue *function, JSCValue *this_value,
size_t argument_count, const JSCValue **arguments, void *user_data) {
if (argument_count != 1)
return NULL;
if (!g_proxy_execute_jscore6.jsc_value_is_string(arguments[0]))
return NULL;
LOG_ERROR("Unable to print exception object\n");
}

char *host = g_proxy_execute_jscore6.jsc_value_to_string(context, arguments[0]);
static char *proxy_execute_jscore6_dns_resolve(const char *host) {
if (!host)
return NULL;

Expand All @@ -105,18 +88,10 @@ static JSCValue *proxy_execute_jscore6_dns_resolve(JSCContext *context, JSCValue
if (!address)
return NULL;

return g_proxy_execute_jscore6.jsc_value_new_string(context, address);
return address;
}

static JSCValue *proxy_execute_jscore6_dns_resolve_ex(JSCContext *context, JSCValue *function, JSCValue *this_value,
size_t argument_count, const JSCValue **arguments,
void *user_data) {
if (argument_count != 1)
return NULL;
if (!g_proxy_execute_jscore6.js_value_is_string(context, arguments[0]))
return NULL;

char *host = g_proxy_execute_jscore6.jsc_value_to_string(context, arguments[0]);
static char *proxy_execute_jscore6_dns_resolve_ex(const char *host) {
if (!host)
return NULL;

Expand All @@ -125,29 +100,25 @@ static JSCValue *proxy_execute_jscore6_dns_resolve_ex(JSCContext *context, JSCVa
if (!address)
return NULL;

return g_proxy_execute_jscore6.jsc_value_new_string(address);
return address;
}

static JSCValue *proxy_execute_jscore6_my_ip_address(JSCContext *context, JSCValue *function, JSCValue *this_value,
size_t argument_count, const JSCValue **arguments,
void *user_data) {
static char *proxy_execute_jscore6_my_ip_address(void) {
char *address = my_ip_address();
if (!address)
return NULL;

return g_proxy_execute_jscore6.jsc_value_new_string(context, address);
return address;
}

static JSCValue *proxy_execute_jscore6_my_ip_address_ex(JSCContext *context, JSCValue *function, JSCValue *this_value,
size_t argument_count, const JSCValue **arguments,
void *user_data) {
static char *proxy_execute_jscore6_my_ip_address_ex(void) {
char *addresses = my_ip_address_ex();
if (!addresses)
return NULL;

return g_proxy_execute_jscore6.jsc_value_new_string(context, addresses);
return addresses;
}

/*
bool proxy_execute_register_function(JSCContext *context, const char *name, GCallback callback) {
// Register native function with JavaScript engine
JSCValue *function =
Expand All @@ -160,12 +131,12 @@ bool proxy_execute_register_function(JSCContext *context, const char *name, GCal
JSCValue *global_object = jsc_context_get_global_object(context);
g_proxy_execute_jscore6.jsc_value_object_set_property(global_object, name, function);
return true;
}
}*/

bool proxy_execute_jscore6_get_proxies_for_url(void *ctx, const char *script, const char *url) {
proxy_execute_jscore6_s *proxy_execute = (proxy_execute_jscore6_s *)ctx;
JSCContext *global = NULL;
JSCValue *exception = NULL;
JSCException *exception = NULL;
char find_proxy[4096];
bool is_ok = false;

Expand All @@ -178,15 +149,40 @@ bool proxy_execute_jscore6_get_proxies_for_url(void *ctx, const char *script, co
goto jscore6gtk_execute_cleanup;
}

JSCValue *global_object = jsc_context_get_global_object(context);
// Register dnsResolve C function
if (!proxy_execute_register_function(global, "dnsResolve", proxy_execute_jscore6_dns_resolve))
JSCValue *function =
g_proxy_execute_jscore6.jsc_value_new_function(global, "dnsResolve", G_CALLBACK(proxy_execute_jscore6_dns_resolve), NULL, NULL,
G_TYPE_STRING, 1, G_TYPE_STRING);
if (!function) {
LOG_ERROR("Unable to hook native function for %s\n", "dnsResolve");
goto jscore6gtk_execute_cleanup;
if (!proxy_execute_register_function(global, "dnsResolveEx", proxy_execute_jscore6_dns_resolve_ex))
}
g_proxy_execute_jscore6.jsc_value_object_set_property(global_object, "dnsResolve", function);
function =
g_proxy_execute_jscore6.jsc_value_new_function(global, "dnsResolveEx", G_CALLBACK(proxy_execute_jscore6_dns_resolve), NULL, NULL,
G_TYPE_STRING, 1, G_TYPE_STRING);
if (!function) {
LOG_ERROR("Unable to hook native function for %s\n", "dnsResolveEx");
goto jscore6gtk_execute_cleanup;
if (!proxy_execute_register_function(global, "myIpAddress", proxy_execute_jscore6_my_ip_address))
}
g_proxy_execute_jscore6.jsc_value_object_set_property(global_object, "dnsResolveEx", function);
function =
g_proxy_execute_jscore6.jsc_value_new_function(global, "myIpAddress", G_CALLBACK(proxy_execute_jscore6_dns_resolve), NULL, NULL,
G_TYPE_STRING, 0);
if (!function) {
LOG_ERROR("Unable to hook native function for %s\n", "myIpAddress");
goto jscore6gtk_execute_cleanup;
if (!proxy_execute_register_function(global, "myIpAddressEx", proxy_execute_jscore6_my_ip_address_ex))
}
g_proxy_execute_jscore6.jsc_value_object_set_property(global_object, "myIpAddress", function);
function =
g_proxy_execute_jscore6.jsc_value_new_function(global, "myIpAddressEx", G_CALLBACK(proxy_execute_jscore6_dns_resolve), NULL, NULL,
G_TYPE_STRING, 0);
if (!function) {
LOG_ERROR("Unable to hook native function for %s\n", "myIpAddressEx");
goto jscore6gtk_execute_cleanup;
}
g_proxy_execute_jscore6.jsc_value_object_set_property(global_object, "myIpAddressEx", function);

// Load Mozilla's JavaScript PAC utilities to help process PAC files
g_proxy_execute_jscore6.jsc_context_evaluate(global, MOZILLA_PAC_JAVASCRIPT, -1);
Expand Down Expand Up @@ -351,6 +347,11 @@ bool proxy_execute_jscore6_global_init(void) {
dlsym(g_proxy_execute_jscore6.module, "jsc_value_object_set_property");
if (!g_proxy_execute_jscore6.jsc_value_object_set_property)
goto jscore6_init_error;
// Exception functions
g_proxy_execute_jscore6.jsc_exception_report =
dlsym(g_proxy_execute_jscore6.module, "jsc_exception_report");
if (!g_proxy_execute_jscore6.jsc_exception_report)
goto jscore6_init_error;

return true;

Expand Down

0 comments on commit 888556a

Please sign in to comment.