We tested one of our iOS app with MobSF and the report highlighted that the binary has Runpath Search Path (#rpath) set.
In certain cases an attacker can abuse this feature to run arbitrary executable for code execution and privilege escalation.
I ran otool -L against the binary to check which dependencies are concerned. It turns out that all pods (Cocaopod) and and some system libraries are concerned.
name #rpath/Alamofire.framework/Alamofire (offset 24)
name #rpath/libswiftCoreAudio.dylib (offset 24)
name #rpath/libswiftCoreData.dylib (offset 24)
name #rpath/libswiftCoreFoundation.dylib (offset 24)
I wonder how to fix this issue. Cocoapods prints a warning if the project build setting Runpath Search Paths does not include $(inherited).
Is using #rpath considered harmful?
Any help/information appreciated.
The Runpath Search Path instructs the dynamic linker to search for a dynamic library (dylib) on an ordered list of paths, sort of like how Unix looks for binaries on $PATH.
If your application uses the Swift Package Manager, in order to compile the libraries without rpath you need to use some hidden build flags. On your local command line run:
Note the swift compiler option no-stdlib-rpath which disables rpath entries during compilation.
Configure your build settings so that the application is built with this configuration flag, e.g.: swift build -c release -Xswiftc -no-toolchain-stdlib-rpath.
Alternatively, if your application uses Cocoapods, you can first check the install directory of the pods:
And then use the following configuration on your Podfile:
For reference - MobSF IPA Binary Analysis
I would like to use existing Pascal source (no user interface) in an iOS app (Xcode project). So I need to create a static library, which I can then add to my iOS project.
Is there a way to create a static library (*.a) for the arm architecture within Delphi? Is there a compiler/linker option?
Or maybe there's another way to do this?
Edit:
I created a osx test project and used the library file from Dcp\OSX32 path and manually created the header file.
When I build the Xcode project I get the following error:
ld: warning: ignoring file /Path/lib/testlib.a, file was built for
archive which is not the architecture being linked (x86_64):
/Path/lib/testlib.a
lipo says:
lipo -info /Path/lib/testlib.a fatal error:
> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo:
> archive with no architecture specification: /Path/lib/testlib.a (can't
> determine architecture for it)
ar:
ar -t /Path/lib/testlib.a
/
//
/1
The /Path/lib/testlib.a file was generated with a Delphi Package Project. The file seems not usable in an Xcode project.
The documentation says that this is possible (with my emphasis).
RAD Studio generates a package static library file:
When you build a Delphi package for iOS Device or Android.
When you build a Delphi package for a desktop platform and you use the "Generate all C++Builder files (including package libs)" value for
the C/C++ Output file generation option in Project > Options > Delphi
Compiler > Output - C/C++.
When you build a C++ package and you enable the Generate static package library (.lib) option in Project > Options > C++ Linker.
A package static library file is a static library file generated from
a package. You use a static library in place of an import library when
your application does not use run-time packages. See Building Static
Packages.
The file name of your package static library file is:
<package>.lib for 32-bit Windows.
<package>.a for 64-bit Windows and Mac OS X.
lib<package>.a for iOS Device and Android.
When I tried to compile my XCode project with OpenCV 2.4 iOS using XCode 7 + iOS SDK 9, XCode complained that
ld:
'opencv2.framework/opencv2(alloc.o)'
does not contain bitcode. You must rebuild it with bitcode enabled
(Xcode setting ENABLE_BITCODE), obtain an updated library from the
vendor, or disable bitcode for this target. for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
and refused to link. After some googling, it turns out to be because Apple added a new feature named Bitcode for app optimization within App Store. While OpenCV iOS binary hasn't been updated to include Bitcode, it cannot pass the link stage.
Some reference pointed out a temporary solution to disable ENABLE_BITCODE so the linking could be done without Bitcode. This will prevent the app being compiled for Apple Watches because Bitcode is mandatory for Watch Apps. Therefore my question is, are there some (best easy) ways to compile iOS OpenCV with Bitcode enabled? (better with a download link for compiled framework)
After some search and trial, I figured out a way to compile OpenCV iOS from the source with Bitcode. A compiled binary is also provided here: [v3.0] [v2.4]. [Disclaimer: I am not responsible for the integrity of the compiled binary. Use at your own risk.]
The steps of compilation is basically the same as the official document, with only one extra step.
Download the code with git:
cd ~/<my_working_directory>
git clone https://github.com/Itseez/opencv.git
Make symbolic link for Xcode to let OpenCV build scripts find the compiler, header files etc.
cd /
sudo ln -s /Applications/Xcode.app/Contents/Developer Developer
[Key Step] Change the compilation script to add the extra option for Bitcode: edit ~/<my_working_directory>/opencv/platform/ios/build_framework.py, and locate the line containing -DCMAKE_C_FLAGS. Add a flag of -fembed-bitcode. For example, in the source I got, it's line 55, and will look like
"-DCMAKE_C_FLAGS=\"-Wno-implicit-function-declaration -fembed-bitcode\" " +
after the change. [ref]
Build OpenCV framework:
cd ~/<my_working_directory>
python opencv/platforms/ios/build_framework.py ios
If everything’s fine, a few minutes later you will get ~/<my_working_directory>/ios/opencv2.framework. You can add this framework to your Xcode projects.
P.S. Ask a question, even when you already know the answer is encouraged according to this post on Meta Stackchange.
OpenCV is precisely the kind of software (along with audio and video Codecs) that is likely to have hand-rolled ARM NEON optimisations. The documentation suggests that ~40 functions have had this treatment in OpenCV3.0.
If compiling for LLVM bit-code you'll get the generic (less optimised, implemented in C or C++) versions instead.
Use of Bitcode is optional - except when compiling for Apple watch, where it's hard to imagine you'd run computationally complex image processing anyway. If you're bundling a watch app, override the build setting for bitcode on it only.
Unity 4.6.5 project won't run on iOS simulator and I'm getting runtime error:
dyld: Symbol not found: _OBJC_CLASS_$_CBAnalytics
Referenced from: /Users/diverseconnection/Library/Developer/CoreSimulator/Devices/983BAC55-2713-423B-B5F3-C135ECCC2768/data/Containers/Bundle/Application/D4CAC0C7-E3D6-48F5-B264-E6EB715F9709/trouble.app/trouble
Expected in: flat namespace
in /Users/diverseconnection/Library/Developer/CoreSimulator/Devices/983BAC55-2713-423B-B5F3-C135ECCC2768/data/Containers/Bundle/Application/D4CAC0C7-E3D6-48F5-B264-E6EB715F9709/trouble.app/trouble
(lldb)
Any ideas how to fix it?
Well this error is usually rather broad as there can be number of causes. You can try these fixes
Add the correct libraries in the Link Binary With Libraries section of the Build Phases.
If you want to add a library outside of the default search path you can include the path in the Library Search Paths value in the Build Settings and add -l{library_name_without_lib_and_suffix} (eg. for libz.a use -lz) to the Other Linker Flags section of Build Settings.
You copy files into your project but forgot to check the target to add the files to. To resolve:
Open the Build Phases for the correct target, expand Compile Sources and add the missing .m files.
You include a static library that is built for another architecture like i386, the simulator on your host machine. To resolve:
If you have multiple library files from your libraries vendor to include in the project you need to include the one for the simulator (i386) and the one for the device (armv7 for example).
Optionally, you could create a fat static library that contains both architectures.
Also try this
Remove Build Active Architecture Only (build setting parameter key is 'ONLY_ACTIVE_ARCH') from all of your static libraries' project build settings or overwrite it with 'NO'
My project was working just fine until this morning. I was using xcode 4.3, and an older version of OpenCV (I'm not sure about the exact version). OSX was already 10.7.x, but not 10.7.5
Today, after upgrading OSX to 10.7.5, xcode to 4.5.2, and downloading OpenCV 2.4.3, I am getting the following linker errors when trying to build the project:
Undefined symbols for architecture armv7:
"_OBJC_CLASS_$_ALAssetsLibrary", referenced from:
objc-class-ref in opencv2(cap_ios_video_camera.o)
"cv::FeatureDetector::create(std::string const&)", referenced from:
-[ImageAnalyzer detectBlobs:] in ImageAnalyzer.o
"cv::FeatureDetector::detect(cv::Mat const&, std::vector >&, cv::Mat const&) const", referenced from:
-[ImageAnalyzer detectBlobs:] in ImageAnalyzer.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
In order to use the new opencv framework I removed the reference to the old framework, and referenced the project to the official prebuilt opencv2.framework downloaded from here.
I also removed the reference to libz.dylib, and added a reference to libc++.dylib instead.
Last step was to update the prefix file to the new framework. The relevant part in the prefix file now looks like this:
#ifdef __cplusplus
#import <opencv2/opencv.hpp>
#endif
It all narrowed down to these 4 linker errors I can't seem to get rid of. I tried using libstdc++.dylib, but I am getting even more errors. I also tried building OpenCV myself as explained here, but I am still getting the same errors as the prebuilt framework.
What did I miss? Is there anything else I need to change in my project?
UPDATE:
As seen here, setting the "C++ Standard Library" to "libc++ (LLVM C++ standard libray with C++ 11 support" yielded only one error:
clang: error: invalid deployment target for -stdlib=libc++ (requires iOS 5.0 or later)
Changing the deployment target to iOS 5 finally got my project to run again.
Does this mean OpenCV 2.4.3 doesn't work on iOS versions older than 5?
steps to compile and run c++ opencv 2.4.4 on mac os x lion 10.7.5 with cmake 2.8.10 and xcode 4.6.1
Having the right tools
download opencv-unix from http://sourceforge.net/projects/opencvlibrary/files/ and untar it wherever
download cmake .dmg from http://www.cmake.org/cmake/resources/software.html and install it
i am assuming you have xcode 4.6 on os x lion which includes the ios sdk 6.1
go to xcode preferences to download and install the Command Line Tools so you have g++ etc.
Use cmake to compile opencv
go to the extracted opencv folder
create a build directory
mkdir build
cd build
cmake -D WITH_TBB=OFF -D BUILD_NEW_PYTHON_SUPPORT=OFF -D BUILD_FAT_JAVA_LIB=OFF -D BUILD_TBB=OFF -D BUILD_EXAMPLES=ON -D CMAKE_CXX_COMPILER=g++ CMAKE_CC_COMPILER=gcc -D CMAKE_OSX_ARCHITECTURES=x86_64 -D BUILD_opencv_java=OFF -G "Unix Makefiles" ..
make -j8
sudo make install
from the build folder, go to bin/ and run one of the tests
./opencv_test_stitching
Create your own c++ opencv xcode project
fire up xcode and create a new xcode project
select Command Line Tool for the type of project under os x
open your project's build settings
under Architectures, set Architecture to 64-bit intel. also set Valid Architectures to x86_64
under Build Options, set Compiler for C/C++ to Default Compiler
under Search Paths, set Header Search Paths to /usr/local/include
also under Search Paths, set Library Search Paths to /usr/local/lib
under Apple LLVM compiler 4.2 - Language set C++ Standard Library to libstd++ (For OpenCV 2.4.6, Xcode 5, LLVM 5.0, and 10.8.5, set both language dialect and std library to "Compiler Default" instead of "libstd++")
Add the compiled opencv libraries to your project
go the the Build Phases tab next to Build Settings tab you were in
inside Link Binary With Libraries, click on the + sign and choose Add Other
hit the front slash / on your keyboard and enter /usr/local/lib
hit enter and select the libraries you want to use in your project
make sure you always select libopencv_core.2.4.4.dylib
hit enter and you will see the selected dylibs under your project
write some code
first lets organize the files, right click on your project blueprint icon and select New Group
name the new group opencv or whatever
drag the dylibs and drop them in that group
open main.cpp
copy code from any of the sample tests that came with opencv and paste it here
make sure all the required dylibs are added, for example, if you copied the opencv_test_stitching.cpp code into main.cpp, you will need to add the following libraries in the previous steps
libopencv_core.2.4.4.dylib
libopencv_highgui.2.4.4.dylib
libopencv_stitching.2.4.4.dylib
Cheers.
It seems that your project is missing the framework AssetsLibrary.
Select the top node in the project navigator. (The project and targets page with the build settings appears.)
Select the target.
Select Summary.
Scroll down to Linked Frameworks and Libraries.
Click the Plus icon at the end of the table and select AssetsLibrary.framework.
Click Add.
Then try to build it again.
Since I can't seem to get an answer regarding the versions (neither here nor at the OpenCV Q&A site), I'm going to post this as an answer, as it at least solved the issue. This is described here.
In your project's Build Settings, go down to the section Apple LLVM compiler 4.1-Language.
There:
Set C++ Language Dialect to Compiler Default
Set C++ Standard Libray to libc++ (LLVM C++ standard libray with C++ 11 support
After doing the above, I stopped getting those linker errors, and only got one error instead, which stated that only iOS 5 and above is supported. Changing the Deployment Target to 5.0 in the project summery did the trick.
On a final note, I'm still not sure what it means, regarding OpenCV 2.4.3's compatibility with iOS versions older than 5.
clang: error: invalid deployment target for -stdlib=libc++ (requires iOS 5.0 or later) to remove this error.
GoTo BuildSettings. Set c++ standard library to compiler default. The
error will get removed surely.
Just to get this into the postings somewhere in case someone else runs into the same thing. If you follow all the great advice aboutsetting the proper c++ library to link against for building an iOS app BUT still get the link errors for undefined symbols make sure your code files are set to compile as c++! That is rename your .m to .mm and .h to .hpp. It's the little things...
Instead of using terminal commands given in the opencv installation guide in official website, use the following commands to build opencv from terminal. Worked for me.
cd OpenCV-2.3.1
mkdir build
cd build
cmake -G "Unix Makefiles" ..
make
sudo make install
Go Xcode/General/Linked Frameworks and Libraries
Press "+" button
type: AssetsLibrary
Select "AssetsLibrary.framework" and import it
Done
Good luck!