Function hooking in Swift
github.com
Function hooking in Swift
1–9 of 9 posts
Re: Function hooking in Swift
#2Re: Function hooking in Swift
#3Re: Function hooking in Swift
#4Very interesting write-up, thanks! Makes me want to get back into C programming :) How did you manage to learn all of this stuff, for a new, closed-source and relatively undocumented (e.g. @asmname) language?
About the @asmname thing: you can easily dump every default Swift module using a REPL command:
repl> :print_module Swift
There you can find a lot of interesting language lexems and more, so all you have to do is to try using them in your code until you don't figure it out ;)
Re: Function hooking in Swift
#5----
Consistently being able to hook functions in Swift is going to be a pain in release mode optimizations, as the Swift compiler does aggressive inlining.
Re: Function hooking in Swift
#6Re: Function hooking in Swift
#7This is for struct alignment to address boundaries. It's fairly typical C and results in some performance optimizations.
Re: Function hooking in Swift
#8From https://developer.apple.com/library/prerelease/ios/documenta... :
You use function types just like any other types in Swift. For example, you can define a constant or variable to be of a function type and assign an appropriate function to that variable:
var mathFunction: (Int, Int) -> Int = addTwoInts
mathFunction can now be passed around, fed in as a parameter in another function, etc. mathFunction is for all purposes a function pointer.
Re: Function hooking in Swift
#9I've seen this concern that there are no function pointers in swift, and it seems to come from a misunderstanding on what it means for functions to be first class. From https://developer.apple.com/library/prerelease/ios/documenta... : You use function types just like any other types in Swift. For example, you can define a constant or variable to be of a function type and assign an appropriate function to that variabl…