5

Cycript is a console based application that is a blend of Objective-C and JavaScript. Cycript is very useful for dynamic analysis of iOS applications.

If you write any methods or the complete ipa with Swift is it still possible to hook the application on a jailbroken device? Or is Swift safe like "native C" Code on iOS ?

Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281
  • https://www.youtube.com/watch?v=Ii-02vhsdVk – user102008 Jul 22 '14 at 00:25
  • did i understand it right that there is no swizzling or hooking available any more? – user3859460 Jul 23 '14 at 11:23
  • I'm not sure what you mean by "hooking", but in that video they are to introspect in Swift classes. With `@objc` methods, you can still swizzle them with the Objective-C runtime; but that might only work for times when they are called through the Objective-C runtime (not sure). I don't think there's swizzling in general for native Swift methods. – user102008 Jul 23 '14 at 18:28
  • As far as I know Swift classes that inherit from NSObject, and it's subclasses use the objective-c runtime, and should work while classes that are pure swift use static function pointers rather than selectors. – o.uinn Aug 24 '14 at 03:17

1 Answers1

1

I'm not really familiar with Cycript but I have a little understanding of the Swift compiler.

Swift code will be more resistant to hooking but it should not be completely impossible. NSObject subclasses and Swift classes that are declared @objc should be as accessible as Objective-C code. Pure Swift code, especially in optimised builds would be harder to inject code into because they are often statically dispatched and in many cases will actually be inlined into the calling code.

Where code hasn't been inlined it may may be possible to patch the functions in memory themselves to jump to an alternative function but it wouldn't be as easy as just modifying function tables.

Where key functions have been inlined it may be possible to find and modify each usage if common patterns of code that could be identified and if the function is long enough it may be posible to patch in a jump to an alternate version but this would get really quite tricky.

Joseph Lord
  • 6,446
  • 1
  • 28
  • 32