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

feat: provide interface frida.Device #29

Merged
merged 2 commits into from
Jan 25, 2024

Conversation

dylanhitt
Copy link
Contributor

Provide the interface of frida.Device. Pretty similar to what was just done with frida.DeviceManager electing to only return the interface to the caller.

Discussion point:

You may notice I elected to change the implementation over to DeviceImpl. I did this so it would preserve the current godoc. In the case of DeviceManager I forgot that unexporting implementation would not allow for godoc parsing. For example you will not find any of the functions on the latest godoc: https://pkg.go.dev/github.com/frida/frida-go@v0.7.0/frida#DeviceManager. You will only find the interface.

I would say this leaves two options.

  1. Reexport deviceManager as DeviceManagerImpl (like how this MR does it).
  2. Take the approach the stdlib does with crypto/cipher: https://pkg.go.dev/crypto/cipher#AEAD. Where the docs are provided in the interface definition. (If this is the option chosen. I'll change this PR to reflect and unexport DeviceImpl as device).

I'm not married too either direction. Number 2 doesn't feel too great from the end user side. Number 1 does expose the struct, but in reality most users would just call the New func and go about their business. However, either I think adding comments with the interface (like number 2) is a nice touch in general and would be nice to do.

…e to the caller

Expose the concrete type of DeviceManager so the end user can mock it
however they see fit. I.E the go saying of "Accept Interfaces, Return Structs".
However, return a frida.Device Interface when DeviceManager/Portal is
being used for access to provide the end user a mockable interface.
@dylanhitt
Copy link
Contributor Author

dylanhitt commented Jan 25, 2024

Changed this up a bit after looking through other CGO libs/the std lib/reading. I still think adhering to the go.dev suggestion that is important:

Do not define interfaces on the implementor side of an API “for mocking”; instead, design the API so that it can be tested using the public API of the real implementation.

Which I don't mind slapping an interface into packages, IMO the caller should be able to do whatever they want. Whether they want to use the concrete type and declare their own interface or use the one provided by the package.

However do to the nature of this API returning an interface in the case of device from DeviceManager/Portal feels really nice (as there is literally no other way for the caller to mock the functionality easily. Returning the concrete type in this case requires the user to wrap everything returned with their own struct which doesn't feel good at all). I think this is where the go proverb of "CGO is not go" comes into play 😆.

Looking forward to the feedback. Apologies for the spam from working through this.

@dylanhitt dylanhitt changed the title WIP: feat: provide interface frida.Device feat: provide interface frida.Device Jan 25, 2024
@NSEcho
Copy link
Member

NSEcho commented Jan 25, 2024

Hi and thanks for such big changes. I like this one more than the previous one honestly, because it kinda keeps the same semantic without breaking any functionality.

@NSEcho NSEcho merged commit 6e73be3 into frida:main Jan 25, 2024
2 checks passed
@dylanhitt dylanhitt deleted the feat/device-interface branch January 25, 2024 23:42
@dylanhitt
Copy link
Contributor Author

Yes, I hate having to suffix interfaces with Int. But whatcha gonna do. Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants