obfuscator-llvm / obfuscator

3.93k stars 1.18k forks source link

bcf crash when build objective-c file #79

Open fighting300 opened 7 years ago

fighting300 commented 7 years ago

CompileC /Users/leon/Library/Developer/Xcode/DerivedData/QPatch-gvmpfbziiefwslesfbaeoapqwxkb/Build/Intermediates/QPatch.build/Debug-iphoneos/QPatch.build/Objects-normal/armv7/QTradeStart.o QPatch/Patch/Patch/QTradeStart.m normal armv7 objective-c com.apple.compilers.llvm.obfuscator.4_0 cd /Users/leon/Desktop/Code/ComCode/Patch/qpatch export LANG=en_US.US-ASCII export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" /Users/leon/Desktop/Code/GitCode/build/bin/clang -x objective-c -arch armv7 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu99 -fobjc-arc -fmodules -fmodules-cache-path=/Users/leon/Library/Developer/Xcode/DerivedData/ModuleCache -fmodules-prune-interval=86400 -fmodules-prune-after=345600 -fbuild-session-file=/Users/leon/Library/Developer/Xcode/DerivedData/ModuleCache/Session.modulevalidation -fmodules-validate-once-per-build-session -Wnon-modular-include-in-framework-module -Werror=non-modular-include-in-framework-module -Wno-trigraphs -fpascal-strings -O0 -fno-common -Wno-missing-field-initializers -Wno-missing-prototypes -Werror=return-type -Wunreachable-code -Wno-implicit-atomic-properties -Werror=deprecated-objc-isa-usage -Werror=objc-root-class -Wno-arc-repeated-use-of-weak -Wduplicate-method-match -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wuninitialized -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wundeclared-selector -Wno-deprecated-implementations -DDEBUG=1 -DBETA_BUILD=1 -DOBJC_OLD_DISPATCH_PROTOTYPES=0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.3.sdk -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -miphoneos-version-min=6.0 -g -Wno-sign-conversion -Wno-infinite-recursion -fembed-bitcode-marker -iquote /Users/leon/Library/Developer/Xcode/DerivedData/QPatch-gvmpfbziiefwslesfbaeoapqwxkb/Build/Intermediates/QPatch.build/Debug-iphoneos/QPatch.build/QPatch-generated-files.hmap -I/Users/leon/Library/Developer/Xcode/DerivedData/QPatch-gvmpfbziiefwslesfbaeoapqwxkb/Build/Intermediates/QPatch.build/Debug-iphoneos/QPatch.build/QPatch-own-target-headers.hmap -I/Users/leon/Library/Developer/Xcode/DerivedData/QPatch-gvmpfbziiefwslesfbaeoapqwxkb/Build/Intermediates/QPatch.build/Debug-iphoneos/QPatch.build/QPatch-all-target-headers.hmap -iquote /Users/leon/Library/Developer/Xcode/DerivedData/QPatch-gvmpfbziiefwslesfbaeoapqwxkb/Build/Intermediates/QPatch.build/Debug-iphoneos/QPatch.build/QPatch-project-headers.hmap -I/Users/leon/Library/Developer/Xcode/DerivedData/QPatch-gvmpfbziiefwslesfbaeoapqwxkb/Build/Products/Debug-iphoneos/include -I/Users/leon/Library/Developer/Xcode/DerivedData/QPatch-gvmpfbziiefwslesfbaeoapqwxkb/Build/Intermediates/QPatch.build/Debug-iphoneos/QPatch.build/DerivedSources/armv7 -I/Users/leon/Library/Developer/Xcode/DerivedData/QPatch-gvmpfbziiefwslesfbaeoapqwxkb/Build/Intermediates/QPatch.build/Debug-iphoneos/QPatch.build/DerivedSources -F/Users/leon/Library/Developer/Xcode/DerivedData/QPatch-gvmpfbziiefwslesfbaeoapqwxkb/Build/Products/Debug-iphoneos -mllvm -bcf -mllvm -bcf_prob=10 -include /Users/leon/Desktop/Code/ComCode/Patch/qpatch/QPatch/QTrade-Prefix.pch -c /Users/leon/Desktop/Code/ComCode/Patch/qpatch/QPatch/Patch/Patch/QTradeStart.m -o /Users/leon/Library/Developer/Xcode/DerivedData/QPatch-gvmpfbziiefwslesfbaeoapqwxkb/Build/Intermediates/QPatch.build/Debug-iphoneos/QPatch.build/Objects-normal/armv7/QTradeStart.o

0 clang-4.0 0x000000011031ec68 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40 1 clang-4.0 0x000000011031f216 SignalHandler(int) + 342 2 libsystem_platform.dylib 0x00007fffb8626b3a _sigtramp + 26 3 libsystem_platform.dylib 0x00007fd1c3899f02 _sigtramp + 187118562 4 clang-4.0 0x000000010feed472 llvm::FPPassManager::runOnFunction(llvm::Function&) + 530 5 clang-4.0 0x000000010feed673 llvm::FPPassManager::runOnModule(llvm::Module&) + 51 6 clang-4.0 0x000000010feedb0a llvm::legacy::PassManagerImpl::run(llvm::Module&) + 922 7 clang-4.0 0x00000001104ae929 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayout const&, llvm::Module, clang::BackendAction, std::__1::unique_ptr<llvm::raw_pwrite_stream, std::__1::default_delete >) + 10793 8 clang-4.0 0x000000011063378b clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) + 1019 9 clang-4.0 0x0000000110e30202 clang::ParseAST(clang::Sema&, bool, bool) + 466 10 clang-4.0 0x0000000110835693 clang::FrontendAction::Execute() + 67 11 clang-4.0 0x00000001107f73f8 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 1080 12 clang-4.0 0x0000000110875393 clang::ExecuteCompilerInvocation(clang::CompilerInstance) + 5251 13 clang-4.0 0x000000010f15377b cc1_main(llvm::ArrayRef<char const>, char const, void*) + 1355 14 clang-4.0 0x000000010f15210a main + 10266 15 libdyld.dylib 0x00007fffb8417235 start + 1 16 libdyld.dylib 0x0000000000000092 start + 1203670622 Stack dump:

  1. Program arguments: /Users/leon/Desktop/Code/GitCode/build/bin/clang-4.0 -cc1 -triple thumbv7-apple-ios6.0.0 -emit-obj -mrelax-all -fembed-bitcode=marker -disable-free -disable-llvm-verifier -discard-value-names -main-file-name QTradeStart.m -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -target-cpu cortex-a8 -target-feature +soft-float-abi -target-abi apcs-gnu -mfloat-abi soft -target-linker-version 278.4 -dwarf-column-info -debug-info-kind=standalone -dwarf-version=2 -debugger-tuning=lldb -coverage-notes-file /Users/leon/Library/Developer/Xcode/DerivedData/QPatch-gvmpfbziiefwslesfbaeoapqwxkb/Build/Intermediates/QPatch.build/Debug-iphoneos/QPatch.build/Objects-normal/armv7/QTradeStart.gcno -resource-dir /Users/leon/Desktop/Code/GitCode/build/bin/../lib/clang/4.0.1 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.3.sdk -iquote /Users/leon/Library/Developer/Xcode/DerivedData/QPatch-gvmpfbziiefwslesfbaeoapqwxkb/Build/Intermediates/QPatch.build/Debug-iphoneos/QPatch.build/QPatch-generated-files.hmap -iquote /Users/leon/Library/Developer/Xcode/DerivedData/QPatch-gvmpfbziiefwslesfbaeoapqwxkb/Build/Intermediates/QPatch.build/Debug-iphoneos/QPatch.build/QPatch-project-headers.hmap -include /Users/leon/Desktop/Code/ComCode/Patch/qpatch/QPatch/QTrade-Prefix.pch -D DEBUG=1 -D BETA_BUILD=1 -D OBJC_OLD_DISPATCH_PROTOTYPES=0 -I /Users/leon/Library/Developer/Xcode/DerivedData/QPatch-gvmpfbziiefwslesfbaeoapqwxkb/Build/Intermediates/QPatch.build/Debug-iphoneos/QPatch.build/QPatch-own-target-headers.hmap -I /Users/leon/Library/Developer/Xcode/DerivedData/QPatch-gvmpfbziiefwslesfbaeoapqwxkb/Build/Intermediates/QPatch.build/Debug-iphoneos/QPatch.build/QPatch-all-target-headers.hmap -I /Users/leon/Library/Developer/Xcode/DerivedData/QPatch-gvmpfbziiefwslesfbaeoapqwxkb/Build/Products/Debug-iphoneos/include -I /Users/leon/Library/Developer/Xcode/DerivedData/QPatch-gvmpfbziiefwslesfbaeoapqwxkb/Build/Intermediates/QPatch.build/Debug-iphoneos/QPatch.build/DerivedSources/armv7 -I /Users/leon/Library/Developer/Xcode/DerivedData/QPatch-gvmpfbziiefwslesfbaeoapqwxkb/Build/Intermediates/QPatch.build/Debug-iphoneos/QPatch.build/DerivedSources -F/Users/leon/Library/Developer/Xcode/DerivedData/QPatch-gvmpfbziiefwslesfbaeoapqwxkb/Build/Products/Debug-iphoneos -O0 -Wnon-modular-include-in-framework-module -Werror=non-modular-include-in-framework-module -Wno-trigraphs -Wno-missing-field-initializers -Wno-missing-prototypes -Werror=return-type -Wunreachable-code -Wno-implicit-atomic-properties -Werror=deprecated-objc-isa-usage -Werror=objc-root-class -Wno-arc-repeated-use-of-weak -Wduplicate-method-match -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wuninitialized -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wundeclared-selector -Wno-deprecated-implementations -Wprotocol -Wdeprecated-declarations -Wno-sign-conversion -Wno-infinite-recursion -std=gnu99 -fdebug-compilation-dir /Users/leon/Desktop/Code/ComCode/Patch/qpatch -ferror-limit 19 -fmacro-backtrace-limit 0 -fmessage-length 0 -stack-protector 1 -fallow-half-arguments-and-returns -fblocks -fmodules -fimplicit-module-maps -fmodules-cache-path=/Users/leon/Library/Developer/Xcode/DerivedData/ModuleCache -fmodules-prune-interval=86400 -fmodules-prune-after=345600 -fbuild-session-timestamp=1502442987000000000 -fmodules-validate-once-per-build-session -fobjc-runtime=ios-6.0.0 -fencode-extended-block-signature -fobjc-arc -fobjc-exceptions -fexceptions -fsjlj-exceptions -fpascal-strings -fmax-type-align=16 -fno-common -fdiagnostics-show-option -fdiagnostics-show-note-include-stack -mllvm -bcf -mllvm -bcf_prob=10 -o /Users/leon/Library/Developer/Xcode/DerivedData/QPatch-gvmpfbziiefwslesfbaeoapqwxkb/Build/Intermediates/QPatch.build/Debug-iphoneos/QPatch.build/Objects-normal/armv7/QTradeStart.o -x objective-c /Users/leon/Desktop/Code/ComCode/Patch/qpatch/QPatch/Patch/Patch/QTradeStart.m
  2. parser at end of file
  3. Code generation
  4. Running pass 'Function Pass Manager' on module '/Users/leon/Desktop/Code/ComCode/Patch/qpatch/QPatch/Patch/Patch/QTradeStart.m'.
  5. Running pass 'SJLJ Exception Handling preparation' on function '@"__26+[QTradeStart startEngine]_block_invoke.244"' clang-4.0: error: unable to execute command: Segmentation fault: 11 clang-4.0: error: clang frontend command failed due to signal (use -v to see invocation) Obfuscator-LLVM clang version 4.0.1 (based on Obfuscator-LLVM 4.0.1) Target: arm-apple-darwin16.7.0 Thread model: posix InstalledDir: /Users/leon/Desktop/Code/GitCode/build/bin clang-4.0: note: diagnostic msg: PLEASE submit a bug report to http://o-llvm.org and include the crash backtrace, preprocessed source, and associated run script. clang-4.0: note: diagnostic msg:

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT: Preprocessed source(s) and associated run script(s) are located at: clang-4.0: note: diagnostic msg: /var/folders/mv/srjjf32s64j5jcjj8tz79kdw0000gn/T/QTradeStart-e11669.m clang-4.0: note: diagnostic msg: /var/folders/mv/srjjf32s64j5jcjj8tz79kdw0000gn/T/QTradeStart-e11669.cache clang-4.0: note: diagnostic msg: /var/folders/mv/srjjf32s64j5jcjj8tz79kdw0000gn/T/QTradeStart-e11669.sh clang-4.0: note: diagnostic msg: /var/folders/mv/srjjf32s64j5jcjj8tz79kdw0000gn/T/QTradeStart-e11669.crash clang-4.0: note: diagnostic msg:


Command /Users/leon/Desktop/Code/GitCode/build/bin/clang failed with exit code 254

fighting300 commented 7 years ago

seem like ollvm donnot support "@synchronized"。。。

xelzmm commented 7 years ago

@fighting300 bcf DOES NOT support llvm invoke instruction.

try...catch, synchronized and few other language internal implementations would generate invoke instruction.

You can filter out functions that contains InvokeInst before running bcf, just like what fla does.

jackson5sec commented 4 years ago

Any other information on how to troubleshoot this? Having the same issue and lowering bcf_prob to near 0 fixes it. @xelzmm Are you suggesting adding logic in the obfuscator.cpp file to ignore those invokes?

xelzmm commented 4 years ago

3 ways to fix this:

  1. skip BCF on functions that contain Invoke instructions.
  2. skip BCF on blocks beginning with LandingPad instruction, which is normal dest of a Invoke instruction, and cannot be cloned due to context restrictions.
  3. split the block right after LandingPad instruction, keep the instructions before it and only create bogus block for the newly created block after LandingPad.

1&2 just skip and ignore the problem which will make BCF useless on some code but 3 actually do resolve the issue.

jackson5sec commented 4 years ago

@xelzmm assuming you mean this: https://github.com/obfuscator-llvm/obfuscator/blob/llvm-4.0/lib/Transforms/Obfuscation/BogusControlFlow.cpp#L180-L183 recompiled it with some logic to skip on that invoke instruction but seems to still be hanging with bcf_prob higher than about 20. compiles fine on smaller projects/functions

for (Function::iterator i = F.begin(); i != F.end(); ++i) {
        BasicBlock *bb = &*i;
        if (!(isa<InvokeInst>(bb->getTerminator()))) {
          basicBlocks.push_back(&*i);
        }
      }
xelzmm commented 4 years ago

if you want to skip some blocks instead of the whole function, then skip the normalDest of InvokeInst, which should be a block containing LandingPadInst, not Invoke block itself.