From c5056c5853cb66e9dd01faac43612d5457974838 Mon Sep 17 00:00:00 2001 From: dylanhitt Date: Tue, 15 Oct 2024 13:41:28 -0400 Subject: [PATCH] refactor: Ctx -> WithContext --- frida/device.go | 16 ++++++++-------- frida/misc.go | 2 +- frida/session.go | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/frida/device.go b/frida/device.go index 7c47b28..82b7572 100644 --- a/frida/device.go +++ b/frida/device.go @@ -20,7 +20,7 @@ type DeviceInt interface { Manager() *DeviceManager IsLost() bool Params(opts ...OptFunc) (map[string]any, error) - ParamsCtx(ctx context.Context) (map[string]any, error) + ParamsWithContext(ctx context.Context) (map[string]any, error) FrontmostApplication(scope Scope) (*Application, error) EnumerateApplications(identifier string, scope Scope, opts ...OptFunc) ([]*Application, error) ProcessByPID(pid int, scope Scope) (*Process, error) @@ -37,7 +37,7 @@ type DeviceInt interface { Resume(pid int) error Kill(pid int) error Attach(val any, sessionOpts *SessionOptions, opts ...OptFunc) (*Session, error) - AttachCtx(ctx context.Context, val any, opts *SessionOptions) (*Session, error) + AttachWithContext(ctx context.Context, val any, opts *SessionOptions) (*Session, error) InjectLibraryFile(target any, path, entrypoint, data string) (uint, error) InjectLibraryBlob(target any, byteData []byte, entrypoint, data string) (uint, error) OpenChannel(address string) (*IOStream, error) @@ -115,11 +115,11 @@ func (d *Device) IsLost() bool { return false } -// ParamsCtx runs Params but with context. +// ParamsWithContext runs Params but with context. // This function will properly handle cancelling the frida operation. // It is advised to use this rather than handling Cancellable yourself. -func (d *Device) ParamsCtx(ctx context.Context) (map[string]any, error) { - rawParams, err := handleCtx(ctx, func(c *Cancellable, doneC chan any, errC chan error) { +func (d *Device) ParamsWithContext(ctx context.Context) (map[string]any, error) { + rawParams, err := handleWithContext(ctx, func(c *Cancellable, doneC chan any, errC chan error) { params, err := d.Params(WithCancel(c)) if err != nil { errC <- err @@ -472,11 +472,11 @@ func (d *Device) Kill(pid int) error { return handleGError(err) } -// AttachCtx runs Attach but with context. +// AttachWithContext runs Attach but with context. // This function will properly handle cancelling the frida operation. // It is advised to use this rather than handling Cancellable yourself. -func (d *Device) AttachCtx(ctx context.Context, val any, sessionOpts *SessionOptions) (*Session, error) { - rawSession, err := handleCtx(ctx, func(c *Cancellable, doneC chan any, errC chan error) { +func (d *Device) AttachWithContext(ctx context.Context, val any, sessionOpts *SessionOptions) (*Session, error) { + rawSession, err := handleWithContext(ctx, func(c *Cancellable, doneC chan any, errC chan error) { session, err := d.Attach(val, sessionOpts, WithCancel(c)) if err != nil { errC <- err diff --git a/frida/misc.go b/frida/misc.go index 66b70a8..424df1b 100644 --- a/frida/misc.go +++ b/frida/misc.go @@ -118,7 +118,7 @@ func ScriptMessageToMessage(message string) (*Message, error) { return &m, nil } -func handleCtx(ctx context.Context, f func(c *Cancellable, done chan any, errC chan error)) (any, error) { +func handleWithContext(ctx context.Context, f func(c *Cancellable, done chan any, errC chan error)) (any, error) { doneC := make(chan any, 1) errC := make(chan error, 1) diff --git a/frida/session.go b/frida/session.go index 5b262a6..10acecb 100644 --- a/frida/session.go +++ b/frida/session.go @@ -19,11 +19,11 @@ func (s *Session) IsDetached() bool { return int(detached) == 1 } -// DetachCtx runs Detach but with context. +// DetachWithContext runs Detach but with context. // This function will properly handle cancelling the frida operation. // It is advised to use this rather than handling Cancellable yourself. -func (s *Session) DetachCtx(ctx context.Context) error { - _, err := handleCtx(ctx, func(c *Cancellable, done chan any, errC chan error) { +func (s *Session) DetachWithContext(ctx context.Context) error { + _, err := handleWithContext(ctx, func(c *Cancellable, done chan any, errC chan error) { errC <- s.Detach(WithCancel(c)) }) return err