class MyViewController: UIViewController {} class MyView: UIView {} class MyModel: NSManagedObject {} class MyRuntimeUsingObject: NSObject {} class SomeClass { @objc func someFunc() {} }
Xcode project Zobfuskowany Xcode project Command line interface (standalone or as Xcode build step) Original Xcode project Obfuscated Xcode project (copy or inplace)
Original Xcode project Xcode project parsing Symbols identification Generation of new names Obfuscated Xcode project (copy or inplace) Renaming in the source files
Obfuscation verification Original Xcode project Xcode project parsing Symbols identification Generation of new names Obfuscated Xcode project Renaming in the source files Main command line interface
Obfuscation verification Original Xcode project Xcode project parsing Obfuscated Xcode project Main command line interface Swift compiler Symbols identification Generation of new names Renaming in the source files
1. create new folder in swift/tools 2. add add_swift_tool_subdirectory function to swift/tools/CMakeLists.txt 3. create new .cpp file with main function 4. create new CMakeLists.txt for your tool 5. add add_swift_host_tool function to swift/tools//CMakeLists.txt and define the source files, executable name and dependencies How to add new command line tool?
1. create new folders in swift/include/swift and swift/lib 2. add your .h interfaces to swift/include/swift/ 3. add your .cpp implementations to swift/lib/ 4. create CMakeLists.txt for your library at swift/lib//CMakeLists.txt with add_swift_library function that defines the source files, library name and dependencies 5. add add_subdirectory function to swift/lib/CMakeLists.txt How to add new library?
1. create new folder in swift/unittests 2. add your .cpp test source code to swift/unittests/ 3. create CMakeLists.txt for your unit tests at swift/unittests//CMakeLists.txt with add_swift_unittest function that defines the source files, executable name and dependencies 4. add add_subdirectory call to swift/unittests/CMakeLists.txt How to add unit tests?
1. create tool in swift/tools/ 2. (not required, but a good idea) create library for the underlying logic in swift/include/swift/ and swift/lib/ 3. add unit tests to swift/unittests/ 4. add integration tests to swift/tests/ How to create new compiler-based tool?
ParamDecl *Parameter = //given from SourceEntityWalker auto Name = Parameter ->getName().str().str(); CharSourceRange Range(Parameter ->getNameLoc(), Name.length());
auto &SourceManager = Current ->getASTContext().SourceMgr; auto BufferId = Current ->getBufferID().getValue(); std ::error_code Error; llvm ::raw_fd_ostream DescriptorStream(Path, Error, F_None); SourceEditOutputConsumer Editor(SourceManager, BufferId, DescriptorStream);
CharSourceRange Range = // computed slide ago auto ReplacingString = // replacement for range in code Editor ->ide ::SourceEditConsumer ::accept(SourceManager, Range, ReplacingString);
1. Get familiar with C++11 2. Use Xcode as IDE (works really well!) 3. Keep Swift compiler in sync with Xcode version 4. Don’t let the lack of compiler knowledge scare you away! Few last practical tips
Pros Cons Anything compiler can do, you can do too! Compiler libs are designed for compilation, not for your tool So many tools are available! No stable API, breaking changes all the time
Pros Cons Anything compiler can do, you can do too! Compiler libs are designed for compilation, not for your tool So many tools are available! No stable API, breaking changes all the time You can leverage the existing infrastructure
Pros Cons Anything compiler can do, you can do too! Compiler libs are designed for compilation, not for your tool So many tools are available! No stable API, breaking changes all the time You can leverage the existing infrastructure You must fit into the existing infrastructure
Pros Cons Anything compiler can do, you can do too! Compiler libs are designed for compilation, not for your tool So many tools are available! No stable API, breaking changes all the time You can leverage the existing infrastructure You must fit into the existing infrastructure Support for both Swift and Objective-C
Pros Cons Anything compiler can do, you can do too! Compiler libs are designed for compilation, not for your tool So many tools are available! No stable API, breaking changes all the time You can leverage the existing infrastructure You must fit into the existing infrastructure Support for both Swift and Objective-C There might be better alternatives
• https://github.com/PolideaPlayground/ SiriusObfuscator-SymbolExtractorAndRenamer • Documentation folder has a lot of notes on various implementation decisions, with details and motivation