From d3567b04ca6e494b728a0ac30e27b4dd729ffc21 Mon Sep 17 00:00:00 2001 From: Cameron Lowell Palmer Date: Thu, 28 Feb 2019 11:20:32 +0100 Subject: [PATCH] Add CMake to the project (#220) --- .gitignore | 2 + CMakeLists.txt | 26 ++++++ Clutch/CMakeLists.txt | 161 +++++++++++++++++++++++++++++++++ Clutch/Info.plist.in | 37 ++++++++ Clutch/MiniZip/CMakeLists.txt | 36 ++++++++ cmake/AddFramework.cmake | 14 +++ cmake/DebugUtils.cmake | 38 ++++++++ cmake/iphoneos.toolchain.cmake | 44 +++++++++ 8 files changed, 358 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 Clutch/CMakeLists.txt create mode 100644 Clutch/Info.plist.in create mode 100644 Clutch/MiniZip/CMakeLists.txt create mode 100644 cmake/AddFramework.cmake create mode 100644 cmake/DebugUtils.cmake create mode 100644 cmake/iphoneos.toolchain.cmake diff --git a/.gitignore b/.gitignore index fd0eb2c2..cd72a19b 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,8 @@ DerivedData/ *.xccheckout *.moved-aside !Podfile.lock +.idea +cmake-build-debug # OS junk .DS_Store diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..369eabf0 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required( VERSION 3.8 ) + +project( Clutch ) + +set( PRODUCT_NAME Clutch ) +set( EXECUTABLE_NAME Clutch ) +set( PRODUCT_BUNDLE_IDENTIFIER kjc.Clutch ) +set( MACOSX_BUNDLE_SHORT_VERSION_STRING "2.0.4" ) +set( MACOSX_BUNDLE_BUNDLE_VERSION "1" ) +set( DEVICE_FAMILY "1,2" ) +set( DEPLOYMENT_TARGET 8.0 CACHE STRING "" ) +set( CODE_SIGN_IDENTITY "iPhone Developer" ) + +if( NOT CMAKE_BUILD_TYPE ) + set( CMAKE_BUILD_TYPE Release ) +endif( NOT CMAKE_BUILD_TYPE ) + +if( CMAKE_BUILD_TYPE STREQUAL Debug ) + add_definitions( -DDEBUG ) +endif() + +include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ) + +include( cmake/DebugUtils.cmake ) +include( cmake/AddFramework.cmake ) +add_subdirectory( Clutch ) diff --git a/Clutch/CMakeLists.txt b/Clutch/CMakeLists.txt new file mode 100644 index 00000000..5ad5f5eb --- /dev/null +++ b/Clutch/CMakeLists.txt @@ -0,0 +1,161 @@ +cmake_minimum_required( VERSION 3.8 ) + +set( SOURCE_COMMANDS + ClutchCommands.h + ClutchCommands.m ) +source_group( "Commands" FILES ${SOURCE_COMMANDS} ) +list( APPEND SOURCE_FILES ${SOURCE_COMMANDS} ) + +set( SOURCE_OPERATIONS + ZipOperation.h + ZipOperation.m + BundleDumpOperation.h + BundleDumpOperation.m + FinalizeDumpOperation.h + FinalizeDumpOperation.m ) +source_group( "Operations" FILES ${SOURCE_OPERATIONS} ) +list( APPEND SOURCE_FILES ${SOURCE_OPERATIONS} ) + +set( SOURCE_DUMPERS + ASLRDisabler.h + ASLRDisabler.m + ARMDumper.h + ARMDumper.m + ARM64Dumper.h + ARM64Dumper.m + FrameworkDumper.h + FrameworkDumper.m + Framework64Dumper.h + Framework64Dumper.m + FrameworkLoader.h + FrameworkLoader.m ) +source_group( "Dumpers" FILES ${SOURCE_DUMPERS} ) +list( APPEND SOURCE_FILES ${SOURCE_DUMPERS} ) + +set( SOURCE_PROTOCOL_PARENT_DUMPER + BinaryDumpProtocol.h + Dumper.h + Dumper.m ) +source_group( "Dumpers\\Protocol + Parent Dumper" FILES ${SOURCE_PROTOCOL_PARENT_DUMPER} ) +list( APPEND SOURCE_FILES ${SOURCE_PROTOCOL_PARENT_DUMPER} ) + +set( SOURCE_APPLICATION + Application.h + Application.m + Extension.h + Extension.m + Framework.h + Framework.m ) +source_group( "Application" FILES ${SOURCE_APPLICATION} ) +list( APPEND SOURCE_FILES ${SOURCE_APPLICATION} ) + +set( SOURCE_CLUTCH_BUNDLE + Binary.h + Binary.m + ClutchBundle.h + ClutchBundle.m ) +source_group( "Application\\ClutchBundle" FILES ${SOURCE_CLUTCH_BUNDLE} ) +list( APPEND SOURCE_FILES ${SOURCE_CLUTCH_BUNDLE} ) + +set( SOURCE_MAIN + KJApplicationManager.h + KJApplicationManager.m + Device.h + Device.m + main.m + ClutchPrint.h + ClutchPrint.m ) +source_group( "" FILES ${SOURCE_MAIN} ) +list( APPEND SOURCE_FILES ${SOURCE_MAIN} ) + +set( PRECOMPILED_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/Clutch-Prefix.pch ) +set( SOURCE_SUPPORTING_FILES + ../LSApplicationProxy.h + ${PRECOMPILED_HEADER} + SCInfoBuilder.h + SCInfoBuilder.m + sha1.c + sha1.h + Clutch.entitlements + mach_vm.h + NSTask.h + scinfo.h + scinfo.m + LSApplicationWorkspace.h + FBApplicationInfo.h + Info.plist + NSFileHandle+Private.h + NSFileHandle+Private.m + NSBundle+Clutch.h + NSBundle+Clutch.m ) +source_group( "Supporting Files" FILES ${SOURCE_SUPPORTING_FILES} ) +list( APPEND SOURCE_FILES ${SOURCE_SUPPORTING_FILES} ) + +set( SOURCE_OPTOOL + optool.h + optool-defines.h + optool-headers.h + optool-headers.m + optool-operations.h + optool-operations.m + NSData+Reading.h + NSData+Reading.m ) +source_group( "Supporting Files\\optools" FILES ${SOURCE_OPTOOL} ) +list( APPEND SOURCE_FILES ${SOURCE_OPTOOL} ) + +set( SOURCE_ZIP + ZipArchive.h + ZipArchive.m ) +source_group( "Supporting Files\\Zip" FILES ${SOURCE_ZIP} ) +list( APPEND SOURCE_FILES ${SOURCE_ZIP} ) + +set( RESOURCE_SCRIPTS + move_and_sign.sh ) +source_group( "scripts" FILES ${RESOURCE_SCRIPTS} ) +list( APPEND SOURCE_FILES ${RESOURCE_SCRIPTS} ) + +configure_file( Clutch.entitlements Clutch.entitlements COPYONLY ) +configure_file( Info.plist.in Info.plist COPYONLY ) + +add_subdirectory( MiniZip ) + +add_executable( Clutch MACOSX_BUNDLE ${SOURCE_FILES} $ ) +AddFramework( Clutch Foundation ) +AddFramework( Clutch UIKit ) +AddFramework( Clutch MobileCoreServices ) +target_include_directories( Clutch PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ) + +if( CMAKE_GENERATOR STREQUAL Xcode ) +set_target_properties( Clutch + PROPERTIES + MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist.in" + XCODE_ATTRIBUTE_SDKROOT iphoneos + XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "${PRODUCT_BUNDLE_IDENTIFIER}" + XCODE_ATTRIBUTE_CODE_SIGN_STYLE "Manual" + XCODE_ATTRIBUTE_CODE_SIGN_INJECT_BASE_ENTITLEMENTS YES + XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET ${DEPLOYMENT_TARGET} + XCODE_ATTRIBUTE_ARCHS "$(ARCHS_STANDARD)" + XCODE_ATTRIBUTE_ENABLE_BITCODE YES + XCODE_ATTRIBUTE_SKIP_INSTALL YES + XCODE_ATTRIBUTE_CLANG_ENABLE_MODULES YES + XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT dwarf-with-dsym + XCODE_ATTRIBUTE_GCC_PREFIX_HEADER "${PRECOMPILED_HEADER}" + XCODE_ATTRIBUTE_GCC_PRECOMPILE_PREFIX_HEADER YES + XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY ${DEVICE_FAMILY} + XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES + XCODE_ATTRIBUTE_INSTALL_PATH "$(LOCAL_APPS_DIR)" + XCODE_ATTRIBUTE_ENABLE_TESTABILITY YES + XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN YES ) +else() +target_compile_options( Clutch + PRIVATE + -include "${PRECOMPILED_HEADER}" + -miphoneos-version-min=${DEPLOYMENT_TARGET} + -fobjc-arc + -fmodules ) +endif() + +add_custom_command( TARGET Clutch POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/build" + COMMAND ${CMAKE_COMMAND} -E copy $ "${CMAKE_BINARY_DIR}/build/" + COMMAND codesign -fs- --entitlements "${CMAKE_CURRENT_BINARY_DIR}/Clutch.entitlements" "${CMAKE_BINARY_DIR}/build/Clutch" ) diff --git a/Clutch/Info.plist.in b/Clutch/Info.plist.in new file mode 100644 index 00000000..82554d94 --- /dev/null +++ b/Clutch/Info.plist.in @@ -0,0 +1,37 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 2.0.4 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + Stub + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + \ No newline at end of file diff --git a/Clutch/MiniZip/CMakeLists.txt b/Clutch/MiniZip/CMakeLists.txt new file mode 100644 index 00000000..f33ee643 --- /dev/null +++ b/Clutch/MiniZip/CMakeLists.txt @@ -0,0 +1,36 @@ +cmake_minimum_required( VERSION 3.8 ) + +project( MiniZip LANGUAGES C ) + +set( HEADERS_FILES + crypt.h + ioapi.h + unzip.h + zip.h ) + +set( SOURCE_FILES + ioapi.c + unzip.c + zip.c ) +source_group( "" FILES ${HEADERS_FILES} ${SOURCE_FILES} ) + +add_library( MiniZip OBJECT ${HEADERS_FILES} ${SOURCE_FILES} ) +target_include_directories( MiniZip PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ) + +if( CMAKE_GENERATOR STREQUAL Xcode ) +set_target_properties( MiniZip + PROPERTIES + XCODE_ATTRIBUTE_SDKROOT iphoneos + XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET ${DEPLOYMENT_TARGET} + XCODE_ATTIRBUTE_ENABLE_BITCODE YES + XCODE_ATTIRBUTE_SKIP_INSTALL YES + XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT dwarf-with-dsym + XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY ${DEVICE_FAMILY} + XCODE_ATTRIBUTE_INSTALL_PATH "$(LOCAL_APPS_DIR)" + XCODE_ATTRIBUTE_ENABLE_TESTABILITY YES + XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN YES ) +else() +target_compile_options( MiniZip + PRIVATE + -miphoneos-version-min=${DEPLOYMENT_TARGET} ) +endif() diff --git a/cmake/AddFramework.cmake b/cmake/AddFramework.cmake new file mode 100644 index 00000000..fe1bc624 --- /dev/null +++ b/cmake/AddFramework.cmake @@ -0,0 +1,14 @@ +macro( AddFramework TARGET NAME ) + find_library( FRAMEWORK_${NAME} + NAMES ${NAME} + PATHS ${CMAKE_OSX_SYSROOT}/System/Library + PATH_SUFFIXES Frameworks + CMAKE_FIND_FRAMEWORK only + NO_DEFAULT_PATH ) + if( ${FRAMEWORK_${NAME}} STREQUAL FRAMEWORK_${NAME}-NOTFOUND ) + message( ERROR ": Framework ${NAME} not found" ) + else() + target_link_libraries( ${TARGET} ${FRAMEWORK_${NAME}} ) + message( STATUS "Framework ${NAME} found at ${FRAMEWORK_${NAME}}" ) + endif() +endmacro( AddFramework ) diff --git a/cmake/DebugUtils.cmake b/cmake/DebugUtils.cmake new file mode 100644 index 00000000..403fed8e --- /dev/null +++ b/cmake/DebugUtils.cmake @@ -0,0 +1,38 @@ +function( DumpVariables ) + set( options MARK HCF ) + set( oneValueArgs ) + set( multiValueArgs VARS ) + cmake_parse_arguments( DumpVariables "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) + + get_cmake_property( _CMAKE_VARIABLES VARIABLES ) + set( MARK ${DumpVariables_MARK} ) + set( HCF ${DumpVariables_HCF} ) + if( DumpVariables_VARS ) + set( VARS "${DumpVariables_VARS}" ) + else() + set( VARS ${_CMAKE_VARIABLES} ) + endif() + + if( MARK ) + message( "" ) + message( "#####################" ) + message( "DumpVariables - BEGIN" ) + endif() + + foreach( _CMAKE_VARIABLE ${_CMAKE_VARIABLES} ) + if( _CMAKE_VARIABLE IN_LIST VARS ) + message( STATUS "${_CMAKE_VARIABLE}=${${_CMAKE_VARIABLE}}" ) + endif() + endforeach( _CMAKE_VARIABLE ) + + if( MARK ) + message( "DumpVariables - END" ) + message( "#####################" ) + message( "" ) + endif() + + if( HCF ) + message( FATAL_ERROR "HCF - DumpVariables" ) + endif() +endfunction( DumpVariables ) + diff --git a/cmake/iphoneos.toolchain.cmake b/cmake/iphoneos.toolchain.cmake new file mode 100644 index 00000000..3cde4525 --- /dev/null +++ b/cmake/iphoneos.toolchain.cmake @@ -0,0 +1,44 @@ +set( CMAKE_SYSTEM_NAME Darwin ) +set( SDK iphoneos CACHE STRING "" ) +set( CMAKE_OSX_ARCHITECTURES armv7 armv7s arm64 CACHE STRING "" ) + +execute_process( COMMAND xcrun --sdk ${SDK} --find clang + OUTPUT_VARIABLE CMAKE_C_COMPILER + OUTPUT_STRIP_TRAILING_WHITESPACE ) +set( CMAKE_C_COMPILER ${CMAKE_C_COMPILER} CACHE PATH "clang executable" ) + +execute_process( COMMAND xcrun --sdk ${SDK} --find clang++ + OUTPUT_VARIABLE CMAKE_CXX_COMPILER + OUTPUT_STRIP_TRAILING_WHITESPACE ) +set( CMAKE_CXX_COMPILER ${CMAKE_CXX_COMPILER} CACHE PATH "clang++ executable" ) + +execute_process( COMMAND xcrun --sdk ${SDK} --find swiftc + OUTPUT_VARIABLE CMAKE_Swift_COMPILER + OUTPUT_STRIP_TRAILING_WHITESPACE ) +set( CMAKE_Swift_COMPILER ${CMAKE_Swift_COMPILER} CACHE PATH "swiftc executable" ) + +execute_process( COMMAND xcrun --sdk ${SDK} --find libtool + OUTPUT_VARIABLE CMAKE_LIBTOOL + OUTPUT_STRIP_TRAILING_WHITESPACE ) +set( CMAKE_LIBTOOL ${CMAKE_LIBTOOL} CACHE PATH "libtool executable" ) + +execute_process( COMMAND xcrun --sdk ${SDK} --find strip + OUTPUT_VARIABLE CMAKE_STRIP + OUTPUT_STRIP_TRAILING_WHITESPACE ) +set( CMAKE_STRIP ${CMAKE_STRIP} CACHE PATH "strip executable" ) + +execute_process( COMMAND xcrun --sdk ${SDK} --show-sdk-path + OUTPUT_VARIABLE CMAKE_OSX_SYSROOT + OUTPUT_STRIP_TRAILING_WHITESPACE ) +set( CMAKE_OSX_SYSROOT ${CMAKE_OSX_SYSROOT} CACHE PATH "sysroot" ) + +set( CMAKE_CXX_COMPILER_WORKS TRUE ) +set( CMAKE_C_COMPILER_WORKS TRUE ) +set( CMAKE_Swift_COMPILER_WORKS TRUE ) + +set( CMAKE_FIND_FRAMEWORK FIRST ) +set( CMAKE_SYSTEM_FRAMEWORK_PATH ${CMAKE_OSX_SYSROOT}/System/Library/Frameworks ) + +set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER ) +set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) +set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )