Skip to content
This repository was archived by the owner on Oct 15, 2021. It is now read-only.

Calling Swift functions/methods #4

Open
maltek opened this issue Feb 14, 2018 · 1 comment
Open

Calling Swift functions/methods #4

maltek opened this issue Feb 14, 2018 · 1 comment

Comments

@maltek
Copy link
Owner

maltek commented Feb 14, 2018

At some point, we also want to be able to call Swift functions. I guess that means for every unique function signature, we need to dynamically generate a wrapper function using the low-level Arm64Writer that puts all parameters in all the right registers according to the Swift calling convention.

Maybe we could also add a Swift calling convention to frida-gum, but I'm not sure how that would make things easier.

@maltek
Copy link
Owner Author

maltek commented Mar 29, 2018

While I've found some working workarounds for the moment, I already found two issues with the missing calling convention when implementing toString in #1:

  • In AARCH64, when a return value is returned in memory, the callee says where to store such a value by setting the r8 ("indirect result") register. Frida does this correctly when we tell it to call a function returning a large enough struct. But it also immediately converts the return value into the JavaScript equivalents of the defined struct. In Swift, however, we sometimes need to call e.g. destructors or move constructors before that happens. On other platforms this is no problem, because the pointer to the memory of the return value is usually just passed as the first parameter - so we could just manage the allocation ourselves and tell Frida the function has one more parameter and returns void.
  • For methods, Swift uses the x20 register on AARCH64 and the r10 register on ARMv7 to pass the pointer to self. (Or at least it does for the one method I've looked at for the moment.) As far as iOS's C calling convention is concerned, those are not used for parameters, so we can't set it using Frida's existing calling conventions.

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

No branches or pull requests

1 participant