Skip to content

Commit

Permalink
refactor: Ctx -> WithContext
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanhitt committed Oct 15, 2024
1 parent 2cf1acc commit c5056c5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions frida/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion frida/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions frida/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c5056c5

Please sign in to comment.