-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds more features to FridaService along with some
refactoring
- Loading branch information
Showing
6 changed files
with
508 additions
and
378 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package frida | ||
|
||
/* | ||
#include <frida-core.h> | ||
static void add_key_val_to_builder(GVariantBuilder *builder, char * key, GVariant *variant) | ||
{ | ||
g_variant_builder_add(builder, "{sv}", key, variant); | ||
} | ||
*/ | ||
import "C" | ||
import ( | ||
"fmt" | ||
"reflect" | ||
) | ||
|
||
// goToGVariant converts go types to GVariant representation | ||
func goToGVariant(data any) *C.GVariant { | ||
return parse(reflect.ValueOf(data)) | ||
} | ||
|
||
func parse(v reflect.Value) *C.GVariant { | ||
for v.Kind() == reflect.Ptr || v.Kind() == reflect.Interface { | ||
v = v.Elem() | ||
} | ||
switch v.Kind() { | ||
case reflect.Array, reflect.Slice: | ||
for i := 0; i < v.Len(); i++ { | ||
parse(v.Index(i)) | ||
} | ||
return C.g_variant_new_string(C.CString("array")) | ||
case reflect.Map: | ||
var builder C.GVariantBuilder | ||
C.g_variant_builder_init(&builder, C.G_VARIANT_TYPE_VARDICT) | ||
for _, k := range v.MapKeys() { | ||
val := parse(v.MapIndex(k)) | ||
C.add_key_val_to_builder(&builder, C.CString(k.String()), val) | ||
} | ||
variant := C.g_variant_builder_end(&builder) | ||
return variant | ||
case reflect.String: | ||
return C.g_variant_new_string(C.CString(v.String())) | ||
case reflect.Bool: | ||
if v.Interface().(bool) { | ||
return C.g_variant_new_boolean(C.gboolean(1)) | ||
} else { | ||
return C.g_variant_new_boolean(C.gboolean(0)) | ||
} | ||
default: | ||
msg := fmt.Sprintf("type \"%s\" not implemented", v.Kind().String()) | ||
panic(msg) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,40 @@ | ||
package frida | ||
|
||
//#include <frida-core.h> | ||
import "C" | ||
|
||
type ServiceInt interface { | ||
/*#include <frida-core.h> | ||
#include <stdio.h> | ||
static GVariant * new_variant_from_c_string(const char * val, FridaService * svc) | ||
{ | ||
GVariantBuilder builder; | ||
g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT); | ||
g_variant_builder_add(&builder, "{sv}", "method", g_variant_new_string("takeScreenshot")); | ||
GVariant * variant = g_variant_builder_end(&builder); | ||
return variant; | ||
} | ||
/* | ||
FridaService * frida_device_open_service_finish (FridaDevice * self, | ||
GAsyncResult * result, | ||
GError ** error); | ||
FridaService * frida_device_open_service_sync (FridaDevice * self, | ||
const gchar * address, GCancellable * cancellable, GError ** error); | ||
*/ | ||
import "C" | ||
|
||
type ServiceInt interface { | ||
} | ||
|
||
// Service represents Service from frida-core | ||
type Service struct { | ||
service *C.FridaService | ||
} | ||
|
||
func (s *Service) Request(req any) (any, error) { | ||
variant := goToGVariant(req) | ||
|
||
var gerr *C.GError | ||
resp := C.frida_service_request_sync(s.service, variant, nil, &gerr) | ||
if gerr != nil { | ||
return nil, &FError{gerr} | ||
} | ||
|
||
return gVariantToGo(resp), nil | ||
} |
Oops, something went wrong.