Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: feat: add the ability to cancel params #43

Merged
merged 4 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions frida/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type DeviceInt interface {
Bus() *Bus
Manager() *DeviceManager
IsLost() bool
Params() (map[string]any, error)
Params(opts ...OptFunc) (map[string]any, error)
FrontmostApplication(scope Scope) (*Application, error)
EnumerateApplications(identifier string, scope Scope) ([]*Application, error)
ProcessByPID(pid int, scope Scope) (*Process, error)
Expand Down Expand Up @@ -113,19 +113,27 @@ func (d *Device) IsLost() bool {
}

// Params returns system parameters of the device
func (d *Device) Params() (map[string]any, error) {
if d.device != nil {
var err *C.GError
ht := C.frida_device_query_system_parameters_sync(d.device, nil, &err)
if err != nil {
return nil, &FError{err}
}
func (d *Device) Params(opts ...OptFunc) (map[string]any, error) {
o := &options{}
for _, opt := range opts { // <--- this all can become a helper func
opt(o)
}

params := gHashTableToMap(ht)
return d.params(o)
}

return params, nil
func (d *Device) params(opts *options) (map[string]any, error) {
if d.device == nil {
return nil, errors.New("could not obtain params for nil device")
}
return nil, errors.New("could not obtain params for nil device")

var err *C.GError
ht := C.frida_device_query_system_parameters_sync(d.device, opts.cancellable, &err)
if err != nil {
return nil, &FError{err}
}

return gHashTableToMap(ht), nil
}

// FrontmostApplication will return the frontmost application or the application in focus
Expand Down
26 changes: 26 additions & 0 deletions frida/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,32 @@ import (
"unsafe"
)

type Cancellable struct {
dylanhitt marked this conversation as resolved.
Show resolved Hide resolved
cancellable *C.GCancellable
}

func NewCancellable() *Cancellable {
return &Cancellable{
cancellable: C.g_cancellable_new(),
}
}

func (c *Cancellable) Cancel() {
C.g_cancellable_cancel(c.cancellable)
}

type options struct {
cancellable *C.GCancellable
}

type OptFunc func(o *options)

func WithCancel(cancel *Cancellable) OptFunc {
return func(o *options) {
o.cancellable = cancel.cancellable
}
}

// FError holds a pointer to GError
type FError struct {
error *C.GError
Expand Down
Loading