Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Take the compiler and run with it: a quick story of Swift obfuscator

Take the compiler and run with it: a quick story of Swift obfuscator

Imagine a group of people with no background in the compilers nor C++.
Imagine them coming across a wonderful open source project, such as the Swift compiler.
What could happen if they started playing with it? Hacking, adding changes left and right, taking parts and making them work the way they were never intended?
Surely, the output would be some gibberish without meaning!
This story really happened. Come to listen how and why. Sometimes the gibberish is exactly what you need.

Krzysztof Siejkowski

June 06, 2018
Tweet

More Decks by Krzysztof Siejkowski

Other Decks in Programming

Transcript

  1. Take the compiler
    and run with it
    A quick story of Swift obfuscator
    Krzysztof Siejkowski, @_siejkowski

    View Slide

  2. View Slide

  3. In software development,
    obfuscation is the deliberate act of
    creating source or machine code that
    is difficult for humans to understand
    — Wikipedia

    View Slide

  4. View Slide

  5. View Slide

  6. View Slide

  7. View Slide

  8. @objc
    NSObject

    View Slide

  9. View Slide

  10. Source
    code
    Binary
    Compilation
    Attacker
    Obfuscation

    View Slide

  11. Source
    code
    Obfuscated
    binary
    Compilation
    Attacker
    Obfuscation
    Example: iXGuard by GuardSquare

    View Slide

  12. Source
    code
    Obfuscated

    binary
    Obfuscating

    Compilation
    Attacker
    Obfuscation
    Example: Obfuscator-LLVM

    View Slide

  13. Obfuscated
    source
    code
    Obfuscated
    binary
    Compilation
    Attacker
    Obfuscation
    Example: ???

    View Slide

  14. View Slide

  15. View Slide

  16. Obfuscated
    source
    code
    Obfuscated
    binary
    Compilation
    Attacker
    Obfuscation
    Example: WE

    View Slide

  17. Source
    code
    Parse
    Find symbols
    Analyze symbols
    Obfuscated
    source
    code
    Rename

    View Slide

  18. Compiler ✨

    View Slide

  19. View Slide

  20. View Slide

  21. View Slide

  22. View Slide

  23. View Slide

  24. View Slide

  25. Swift compiler 

    as a library?

    View Slide

  26. swiftParse
    swiftDriver
    swiftAST
    swiftSyntax
    swiftBasic

    View Slide

  27. swiftParse
    swiftDriver
    swiftAST
    swiftSyntax
    swiftBasic

    View Slide

  28. swiftParse
    swiftDriver
    swiftAST
    swiftSyntax
    swiftBasic
    swift
    swift-syntax-
    test
    swift-refactor

    View Slide

  29. swiftParse
    swiftDriver
    swiftAST
    swiftSyntax
    swiftBasic
    swift
    swift-syntax-
    test
    swift-refactor

    View Slide

  30. swiftParse
    swiftDriver
    swiftAST
    swiftSyntax
    swiftBasic
    swiftObfuscation
    obfuscator-renamer
    obfuscator-symbol-
    extractor

    View Slide

  31. View Slide

  32. View Slide

  33. Source code
    MAGIC

    %
    Analyzed 

    source code

    View Slide

  34. swiftFrontend
    Source code
    CompilerInstance.
    performSema()
    Analyzed 

    source code

    View Slide

  35. View Slide

  36. swiftAST
    Analyzed 

    source code
    SourceFileWalker
    Symbols

    with locations

    View Slide

  37. Symbols 

    with locations
    MAGIC
    %
    Obfuscated
    source files

    View Slide

  38. swiftIDE
    Symbols 

    with locations
    SourceEngine &
    SourceManager
    Obfuscated
    source files

    View Slide

  39. View Slide

  40. View Slide

  41. Supports Not supports

    View Slide

  42. Supports Not supports
    DSYM file generation
    Multiple targets
    Some exotic Swift constructs

    View Slide

  43. Supports Not supports
    Renames in Storyboards and XIBs DSYM file generation
    Excluding configuration Multiple targets
    Simple integration (local & CI) Some exotic Swift constructs

    View Slide

  44. Open source
    github.com/Polidea/SiriusObfuscator

    View Slide

  45. View Slide

  46. Pros Cons
    Anything compiler can do, 

    you can do too!

    View Slide

  47. Pros Cons
    Anything compiler can do, 

    you can do too!
    No stable API, 

    breaking changes any time

    View Slide

  48. Pros Cons
    Anything compiler can do, 

    you can do too!
    No stable API, 

    breaking changes any time
    So many tools available!

    View Slide

  49. Pros Cons
    Anything compiler can do, 

    you can do too!
    No stable API, 

    breaking changes any time
    So many tools available!
    Compiler libs are designed for
    compilation, not for your needs

    View Slide

  50. Pros Cons
    Anything compiler can do, 

    you can do too!
    No stable API, 

    breaking changes any time
    So many tools available!
    Compiler libs are designed for
    compilation, not for your needs
    Support for both 

    Swift and Objective-C

    View Slide

  51. Pros Cons
    Anything compiler can do, 

    you can do too!
    No stable API, 

    breaking changes any time
    So many tools available!
    Compiler libs are designed for
    compilation, not for your needs
    Support for both 

    Swift and Objective-C
    Might be too much to support

    View Slide

  52. Alternatives
    • libSyntax
    • SourceKit
    • existing swift tools

    View Slide

  53. View Slide

  54. github.com/Polidea/SiriusObfuscator
    Documentation

    View Slide


  55. @KacperHarasim

    View Slide

  56. Thank you!
    @_siejkowski

    View Slide