├── Demo ├── AntiFishHookDemo │ ├── Assets.xcassets │ │ ├── Contents.json │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── AntiFishHookDemo-Bridging-Header.h │ ├── TestCase │ │ ├── PrintfTestHelp.h │ │ ├── PrintfTestHelp.m │ │ ├── Abort.swift │ │ ├── Printf.swift │ │ ├── Print.swift │ │ ├── Dladdr.swift │ │ ├── NSLog.swift │ │ └── Dlopen.swift │ ├── ViewController.swift │ ├── AppDelegate.swift │ ├── Info.plist │ └── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard ├── Pods │ ├── Target Support Files │ │ ├── Pods-AntiFishHookDemo │ │ │ ├── Pods-AntiFishHookDemo-frameworks-Debug-output-files.xcfilelist │ │ │ ├── Pods-AntiFishHookDemo-frameworks-Release-output-files.xcfilelist │ │ │ ├── Pods-AntiFishHookDemo.modulemap │ │ │ ├── Pods-AntiFishHookDemo-dummy.m │ │ │ ├── Pods-AntiFishHookDemo-frameworks-Debug-input-files.xcfilelist │ │ │ ├── Pods-AntiFishHookDemo-frameworks-Release-input-files.xcfilelist │ │ │ ├── Pods-AntiFishHookDemo-umbrella.h │ │ │ ├── Pods-AntiFishHookDemo.debug.xcconfig │ │ │ ├── Pods-AntiFishHookDemo.release.xcconfig │ │ │ ├── Pods-AntiFishHookDemo-Info.plist │ │ │ ├── Pods-AntiFishHookDemo-acknowledgements.markdown │ │ │ ├── Pods-AntiFishHookDemo-acknowledgements.plist │ │ │ └── Pods-AntiFishHookDemo-frameworks.sh │ │ ├── antiFishhook │ │ │ ├── antiFishhook.modulemap │ │ │ ├── antiFishhook-dummy.m │ │ │ ├── antiFishhook-prefix.pch │ │ │ ├── antiFishhook-umbrella.h │ │ │ ├── antiFishhook.debug.xcconfig │ │ │ ├── antiFishhook.release.xcconfig │ │ │ └── antiFishhook-Info.plist │ │ └── Pods-InsertDyld │ │ │ ├── Pods-InsertDyld.modulemap │ │ │ ├── Pods-InsertDyld-dummy.m │ │ │ ├── Pods-InsertDyld-umbrella.h │ │ │ ├── Pods-InsertDyld.debug.xcconfig │ │ │ ├── Pods-InsertDyld.release.xcconfig │ │ │ ├── Pods-InsertDyld-Info.plist │ │ │ ├── Pods-InsertDyld-acknowledgements.markdown │ │ │ └── Pods-InsertDyld-acknowledgements.plist │ ├── Manifest.lock │ ├── Local Podspecs │ │ └── antiFishhook.podspec.json │ └── Pods.xcodeproj │ │ ├── xcuserdata │ │ └── jintao.xcuserdatad │ │ │ └── xcschemes │ │ │ ├── xcschememanagement.plist │ │ │ ├── Pods-InsertDyld.xcscheme │ │ │ ├── Pods-AntiFishHookDemo.xcscheme │ │ │ └── antiFishhook.xcscheme │ │ └── project.pbxproj ├── AntiFishHookDemo.xcworkspace │ ├── xcuserdata │ │ └── jintao.xcuserdatad │ │ │ ├── UserInterfaceState.xcuserstate │ │ │ ├── xcdebugger │ │ │ └── Breakpoints_v2.xcbkptlist │ │ │ └── IDEFindNavigatorScopes.plist │ ├── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ └── contents.xcworkspacedata ├── AntiFishHookDemo.xcodeproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcuserdata │ │ │ └── jintao.xcuserdatad │ │ │ │ └── UserInterfaceState.xcuserstate │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ ├── xcuserdata │ │ └── jintao.xcuserdatad │ │ │ └── xcschemes │ │ │ └── xcschememanagement.plist │ ├── xcshareddata │ │ └── xcschemes │ │ │ └── AntiFishHookDemo.xcscheme │ └── project.pbxproj ├── InsertDyld │ ├── InsertDyld.xcodeproj │ │ ├── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ ├── xcuserdata │ │ │ │ └── jintao.xcuserdatad │ │ │ │ │ └── UserInterfaceState.xcuserstate │ │ │ └── xcshareddata │ │ │ │ └── IDEWorkspaceChecks.plist │ │ ├── xcuserdata │ │ │ └── jintao.xcuserdatad │ │ │ │ └── xcschemes │ │ │ │ └── xcschememanagement.plist │ │ └── project.pbxproj │ └── InsertDyld │ │ ├── InsertDyld.h │ │ ├── Info.plist │ │ └── FishHookTest.swift ├── Podfile.lock └── Podfile ├── antiFishhook.podspec ├── LICENSE ├── README.md └── Source ├── FishHook.swift └── AntiFishHook.swift /Demo/AntiFishHookDemo/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Demo/Pods/Target Support Files/Pods-AntiFishHookDemo/Pods-AntiFishHookDemo-frameworks-Debug-output-files.xcfilelist: -------------------------------------------------------------------------------- 1 | ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/antiFishhook.framework -------------------------------------------------------------------------------- /Demo/Pods/Target Support Files/Pods-AntiFishHookDemo/Pods-AntiFishHookDemo-frameworks-Release-output-files.xcfilelist: -------------------------------------------------------------------------------- 1 | ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/antiFishhook.framework -------------------------------------------------------------------------------- /Demo/AntiFishHookDemo/AntiFishHookDemo-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | // 2 | // Use this file to import your target's public headers that you would like to expose to Swift. 3 | // 4 | 5 | #include "PrintfTestHelp.h" 6 | -------------------------------------------------------------------------------- /Demo/Pods/Target Support Files/antiFishhook/antiFishhook.modulemap: -------------------------------------------------------------------------------- 1 | framework module antiFishhook { 2 | umbrella header "antiFishhook-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /Demo/Pods/Target Support Files/antiFishhook/antiFishhook-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_antiFishhook : NSObject 3 | @end 4 | @implementation PodsDummy_antiFishhook 5 | @end 6 | -------------------------------------------------------------------------------- /Demo/Pods/Target Support Files/Pods-InsertDyld/Pods-InsertDyld.modulemap: -------------------------------------------------------------------------------- 1 | framework module Pods_InsertDyld { 2 | umbrella header "Pods-InsertDyld-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /Demo/Pods/Target Support Files/Pods-InsertDyld/Pods-InsertDyld-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_Pods_InsertDyld : NSObject 3 | @end 4 | @implementation PodsDummy_Pods_InsertDyld 5 | @end 6 | -------------------------------------------------------------------------------- /Demo/Pods/Target Support Files/Pods-AntiFishHookDemo/Pods-AntiFishHookDemo.modulemap: -------------------------------------------------------------------------------- 1 | framework module Pods_AntiFishHookDemo { 2 | umbrella header "Pods-AntiFishHookDemo-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /Demo/AntiFishHookDemo.xcworkspace/xcuserdata/jintao.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TannerJin/anti-fishhook/HEAD/Demo/AntiFishHookDemo.xcworkspace/xcuserdata/jintao.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Demo/Pods/Target Support Files/Pods-AntiFishHookDemo/Pods-AntiFishHookDemo-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_Pods_AntiFishHookDemo : NSObject 3 | @end 4 | @implementation PodsDummy_Pods_AntiFishHookDemo 5 | @end 6 | -------------------------------------------------------------------------------- /Demo/AntiFishHookDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Demo/AntiFishHookDemo.xcworkspace/xcuserdata/jintao.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /Demo/InsertDyld/InsertDyld.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Demo/Pods/Target Support Files/Pods-AntiFishHookDemo/Pods-AntiFishHookDemo-frameworks-Debug-input-files.xcfilelist: -------------------------------------------------------------------------------- 1 | ${PODS_ROOT}/Target Support Files/Pods-AntiFishHookDemo/Pods-AntiFishHookDemo-frameworks.sh 2 | ${BUILT_PRODUCTS_DIR}/antiFishhook/antiFishhook.framework -------------------------------------------------------------------------------- /Demo/Pods/Target Support Files/Pods-AntiFishHookDemo/Pods-AntiFishHookDemo-frameworks-Release-input-files.xcfilelist: -------------------------------------------------------------------------------- 1 | ${PODS_ROOT}/Target Support Files/Pods-AntiFishHookDemo/Pods-AntiFishHookDemo-frameworks.sh 2 | ${BUILT_PRODUCTS_DIR}/antiFishhook/antiFishhook.framework -------------------------------------------------------------------------------- /Demo/AntiFishHookDemo.xcodeproj/project.xcworkspace/xcuserdata/jintao.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TannerJin/anti-fishhook/HEAD/Demo/AntiFishHookDemo.xcodeproj/project.xcworkspace/xcuserdata/jintao.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Demo/InsertDyld/InsertDyld.xcodeproj/project.xcworkspace/xcuserdata/jintao.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TannerJin/anti-fishhook/HEAD/Demo/InsertDyld/InsertDyld.xcodeproj/project.xcworkspace/xcuserdata/jintao.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Demo/AntiFishHookDemo.xcworkspace/xcuserdata/jintao.xcuserdatad/IDEFindNavigatorScopes.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Demo/Pods/Target Support Files/antiFishhook/antiFishhook-prefix.pch: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #else 4 | #ifndef FOUNDATION_EXPORT 5 | #if defined(__cplusplus) 6 | #define FOUNDATION_EXPORT extern "C" 7 | #else 8 | #define FOUNDATION_EXPORT extern 9 | #endif 10 | #endif 11 | #endif 12 | 13 | -------------------------------------------------------------------------------- /Demo/AntiFishHookDemo.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Demo/AntiFishHookDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Demo/InsertDyld/InsertDyld.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Demo/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - antiFishhook (1.0.0) 3 | 4 | DEPENDENCIES: 5 | - antiFishhook (from `../`) 6 | 7 | EXTERNAL SOURCES: 8 | antiFishhook: 9 | :path: "../" 10 | 11 | SPEC CHECKSUMS: 12 | antiFishhook: a842d3607919c70ae04f98a25c0ff4a7ff907a5b 13 | 14 | PODFILE CHECKSUM: ee07d929b8f320af8b83a1a3017d0dffd8ca5370 15 | 16 | COCOAPODS: 1.9.3 17 | -------------------------------------------------------------------------------- /Demo/Pods/Manifest.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - antiFishhook (1.0.0) 3 | 4 | DEPENDENCIES: 5 | - antiFishhook (from `../`) 6 | 7 | EXTERNAL SOURCES: 8 | antiFishhook: 9 | :path: "../" 10 | 11 | SPEC CHECKSUMS: 12 | antiFishhook: a842d3607919c70ae04f98a25c0ff4a7ff907a5b 13 | 14 | PODFILE CHECKSUM: ee07d929b8f320af8b83a1a3017d0dffd8ca5370 15 | 16 | COCOAPODS: 1.9.3 17 | -------------------------------------------------------------------------------- /Demo/AntiFishHookDemo.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Demo/Podfile: -------------------------------------------------------------------------------- 1 | # Uncomment the next line to define a global platform for your project 2 | # platform :ios, '9.0' 3 | workspace 'AntiFishHookDemo.xcworkspace' 4 | 5 | target 'AntiFishHookDemo' do 6 | use_frameworks! 7 | pod 'antiFishhook', :path => '../' 8 | end 9 | 10 | target 'InsertDyld' do 11 | use_frameworks! 12 | pod 'antiFishhook', :path => '../' 13 | project 'InsertDyld/InsertDyld.xcodeproj' 14 | end 15 | -------------------------------------------------------------------------------- /Demo/AntiFishHookDemo/TestCase/PrintfTestHelp.h: -------------------------------------------------------------------------------- 1 | // 2 | // Test.h 3 | // FishHookProtect 4 | // 5 | // Created by jintao on 2019/3/25. 6 | // Copyright © 2019 jintao. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface PrintfTestHelp : NSObject 14 | 15 | + (void)printf: (NSString *)str; 16 | 17 | + (void)antiFishhook; 18 | 19 | @end 20 | 21 | NS_ASSUME_NONNULL_END 22 | -------------------------------------------------------------------------------- /Demo/AntiFishHookDemo/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // AntiFishHookDemo 4 | // 5 | // Created by jintao on 2019/7/3. 6 | // Copyright © 2019 jintao. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | // Do any additional setup after loading the view. 16 | } 17 | 18 | } 19 | 20 | -------------------------------------------------------------------------------- /Demo/Pods/Target Support Files/antiFishhook/antiFishhook-umbrella.h: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #else 4 | #ifndef FOUNDATION_EXPORT 5 | #if defined(__cplusplus) 6 | #define FOUNDATION_EXPORT extern "C" 7 | #else 8 | #define FOUNDATION_EXPORT extern 9 | #endif 10 | #endif 11 | #endif 12 | 13 | 14 | FOUNDATION_EXPORT double antiFishhookVersionNumber; 15 | FOUNDATION_EXPORT const unsigned char antiFishhookVersionString[]; 16 | 17 | -------------------------------------------------------------------------------- /Demo/Pods/Target Support Files/Pods-InsertDyld/Pods-InsertDyld-umbrella.h: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #else 4 | #ifndef FOUNDATION_EXPORT 5 | #if defined(__cplusplus) 6 | #define FOUNDATION_EXPORT extern "C" 7 | #else 8 | #define FOUNDATION_EXPORT extern 9 | #endif 10 | #endif 11 | #endif 12 | 13 | 14 | FOUNDATION_EXPORT double Pods_InsertDyldVersionNumber; 15 | FOUNDATION_EXPORT const unsigned char Pods_InsertDyldVersionString[]; 16 | 17 | -------------------------------------------------------------------------------- /Demo/Pods/Target Support Files/Pods-AntiFishHookDemo/Pods-AntiFishHookDemo-umbrella.h: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #else 4 | #ifndef FOUNDATION_EXPORT 5 | #if defined(__cplusplus) 6 | #define FOUNDATION_EXPORT extern "C" 7 | #else 8 | #define FOUNDATION_EXPORT extern 9 | #endif 10 | #endif 11 | #endif 12 | 13 | 14 | FOUNDATION_EXPORT double Pods_AntiFishHookDemoVersionNumber; 15 | FOUNDATION_EXPORT const unsigned char Pods_AntiFishHookDemoVersionString[]; 16 | 17 | -------------------------------------------------------------------------------- /Demo/AntiFishHookDemo/TestCase/PrintfTestHelp.m: -------------------------------------------------------------------------------- 1 | // 2 | // Test.m 3 | // FishHookProtect 4 | // 5 | // Created by jintao on 2019/3/25. 6 | // Copyright © 2019 jintao. All rights reserved. 7 | // 8 | 9 | #import "PrintfTestHelp.h" 10 | #import "antiFishhook-Swift.h" 11 | 12 | @implementation PrintfTestHelp 13 | 14 | + (void)printf:(NSString *)str { 15 | const char *str2 = [str UTF8String]; 16 | printf("%s", str2); 17 | } 18 | 19 | + (void)antiFishhook { 20 | // resetSymbol(@"printf"); 21 | } 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /antiFishhook.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'antiFishhook' 3 | s.version = '1.0.0' 4 | s.summary = 'anti-fishhook' 5 | s.homepage = 'https://github.com/TannerJin/anti-fishhook' 6 | s.license = { :type => "MIT" } 7 | s.authors = { "jintao" => "2802009591@qq.com" } 8 | s.source = { :git => 'https://github.com/TannerJin/anti-fishhook.git', :tag => s.version } 9 | s.platform = :ios, '9.0' 10 | s.source_files = "Source/*.swift" 11 | s.framework = "Foundation" 12 | s.requires_arc = true 13 | s.swift_version = "4.2" 14 | end 15 | -------------------------------------------------------------------------------- /Demo/InsertDyld/InsertDyld/InsertDyld.h: -------------------------------------------------------------------------------- 1 | // 2 | // InsertDyld.h 3 | // InsertDyld 4 | // 5 | // Created by jintao on 2019/4/1. 6 | // Copyright © 2019 jintao. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for InsertDyld. 12 | FOUNDATION_EXPORT double InsertDyldVersionNumber; 13 | 14 | //! Project version string for InsertDyld. 15 | FOUNDATION_EXPORT const unsigned char InsertDyldVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /Demo/InsertDyld/InsertDyld.xcodeproj/xcuserdata/jintao.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | InsertDyld.xcscheme 8 | 9 | orderHint 10 | 3 11 | 12 | InsertDyld.xcscheme_^#shared#^_ 13 | 14 | orderHint 15 | 4 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Demo/Pods/Local Podspecs/antiFishhook.podspec.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "antiFishhook", 3 | "version": "1.0.0", 4 | "summary": "anti-fishhook", 5 | "homepage": "https://github.com/TannerJin/anti-fishhook", 6 | "license": { 7 | "type": "MIT" 8 | }, 9 | "authors": { 10 | "jintao": "2802009591@qq.com" 11 | }, 12 | "source": { 13 | "git": "https://github.com/TannerJin/anti-fishhook.git", 14 | "tag": "1.0.0" 15 | }, 16 | "platforms": { 17 | "ios": "9.0" 18 | }, 19 | "source_files": "Source/*.swift", 20 | "frameworks": "Foundation", 21 | "requires_arc": true, 22 | "swift_versions": "4.2", 23 | "swift_version": "4.2" 24 | } 25 | -------------------------------------------------------------------------------- /Demo/Pods/Target Support Files/antiFishhook/antiFishhook.debug.xcconfig: -------------------------------------------------------------------------------- 1 | CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/antiFishhook 2 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 3 | OTHER_LDFLAGS = $(inherited) -framework "Foundation" 4 | OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS 5 | PODS_BUILD_DIR = ${BUILD_DIR} 6 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 7 | PODS_ROOT = ${SRCROOT} 8 | PODS_TARGET_SRCROOT = ${PODS_ROOT}/../.. 9 | PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier} 10 | SKIP_INSTALL = YES 11 | USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES 12 | -------------------------------------------------------------------------------- /Demo/Pods/Target Support Files/antiFishhook/antiFishhook.release.xcconfig: -------------------------------------------------------------------------------- 1 | CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/antiFishhook 2 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 3 | OTHER_LDFLAGS = $(inherited) -framework "Foundation" 4 | OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS 5 | PODS_BUILD_DIR = ${BUILD_DIR} 6 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 7 | PODS_ROOT = ${SRCROOT} 8 | PODS_TARGET_SRCROOT = ${PODS_ROOT}/../.. 9 | PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier} 10 | SKIP_INSTALL = YES 11 | USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES 12 | -------------------------------------------------------------------------------- /Demo/AntiFishHookDemo.xcodeproj/xcuserdata/jintao.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | AntiFishHookDemo.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | A95B34EE22CBBAF50078B3D4 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Demo/InsertDyld/InsertDyld/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | 22 | 23 | -------------------------------------------------------------------------------- /Demo/AntiFishHookDemo/TestCase/Abort.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Abort.swift 3 | // AntiFishHookDemo 4 | // 5 | // Created by jintao on 2019/8/30. 6 | // Copyright © 2019 jintao. All rights reserved. 7 | // 8 | 9 | import antiFishhook 10 | import Foundation 11 | 12 | func testAbort() { 13 | typealias Method = @convention(thin) ()->() 14 | let newMethod: Method = { 15 | print("======> abort_fishhook success:") 16 | FishHookChecker.denyFishHook("abort") 17 | print("======> abort_antiFishhook test:") 18 | abort() // if crash, abort antiFishhook success 19 | } 20 | 21 | var oldMethod: UnsafeMutableRawPointer? 22 | 23 | print("\n======> abort_test:") 24 | FishHook.replaceSymbol("abort", newMethod: unsafeBitCast(newMethod, to: UnsafeMutableRawPointer.self), oldMethod: &oldMethod) 25 | abort() 26 | } 27 | -------------------------------------------------------------------------------- /Demo/Pods/Target Support Files/Pods-InsertDyld/Pods-InsertDyld.debug.xcconfig: -------------------------------------------------------------------------------- 1 | FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/antiFishhook" 2 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 3 | HEADER_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/antiFishhook/antiFishhook.framework/Headers" 4 | LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' '@executable_path/../../Frameworks' 5 | OTHER_LDFLAGS = $(inherited) -framework "Foundation" -framework "antiFishhook" 6 | OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS 7 | PODS_BUILD_DIR = ${BUILD_DIR} 8 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 9 | PODS_PODFILE_DIR_PATH = ${SRCROOT}/.. 10 | PODS_ROOT = ${SRCROOT}/../Pods 11 | USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES 12 | -------------------------------------------------------------------------------- /Demo/Pods/Target Support Files/Pods-InsertDyld/Pods-InsertDyld.release.xcconfig: -------------------------------------------------------------------------------- 1 | FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/antiFishhook" 2 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 3 | HEADER_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/antiFishhook/antiFishhook.framework/Headers" 4 | LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' '@executable_path/../../Frameworks' 5 | OTHER_LDFLAGS = $(inherited) -framework "Foundation" -framework "antiFishhook" 6 | OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS 7 | PODS_BUILD_DIR = ${BUILD_DIR} 8 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 9 | PODS_PODFILE_DIR_PATH = ${SRCROOT}/.. 10 | PODS_ROOT = ${SRCROOT}/../Pods 11 | USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES 12 | -------------------------------------------------------------------------------- /Demo/Pods/Target Support Files/Pods-AntiFishHookDemo/Pods-AntiFishHookDemo.debug.xcconfig: -------------------------------------------------------------------------------- 1 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES 2 | FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/antiFishhook" 3 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 4 | HEADER_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/antiFishhook/antiFishhook.framework/Headers" 5 | LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' 6 | OTHER_LDFLAGS = $(inherited) -framework "Foundation" -framework "antiFishhook" 7 | OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS 8 | PODS_BUILD_DIR = ${BUILD_DIR} 9 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 10 | PODS_PODFILE_DIR_PATH = ${SRCROOT}/. 11 | PODS_ROOT = ${SRCROOT}/Pods 12 | USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES 13 | -------------------------------------------------------------------------------- /Demo/Pods/Target Support Files/Pods-AntiFishHookDemo/Pods-AntiFishHookDemo.release.xcconfig: -------------------------------------------------------------------------------- 1 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES 2 | FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/antiFishhook" 3 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 4 | HEADER_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/antiFishhook/antiFishhook.framework/Headers" 5 | LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' 6 | OTHER_LDFLAGS = $(inherited) -framework "Foundation" -framework "antiFishhook" 7 | OTHER_SWIFT_FLAGS = $(inherited) -D COCOAPODS 8 | PODS_BUILD_DIR = ${BUILD_DIR} 9 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 10 | PODS_PODFILE_DIR_PATH = ${SRCROOT}/. 11 | PODS_ROOT = ${SRCROOT}/Pods 12 | USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES 13 | -------------------------------------------------------------------------------- /Demo/Pods/Pods.xcodeproj/xcuserdata/jintao.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | Pods-AntiFishHookDemo.xcscheme 8 | 9 | isShown 10 | 11 | orderHint 12 | 2 13 | 14 | Pods-InsertDyld.xcscheme 15 | 16 | isShown 17 | 18 | orderHint 19 | 3 20 | 21 | antiFishhook.xcscheme 22 | 23 | isShown 24 | 25 | orderHint 26 | 1 27 | 28 | 29 | SuppressBuildableAutocreation 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Demo/AntiFishHookDemo/TestCase/Printf.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Printf.swift 3 | // FishHookProtect 4 | // 5 | // Created by jintao on 2019/6/17. 6 | // Copyright © 2019 jintao. All rights reserved. 7 | // 8 | 9 | import InsertDyld 10 | import Foundation 11 | import antiFishhook 12 | 13 | typealias NewPrintfMethod = @convention(thin) (String, Any...) -> Void 14 | 15 | func newPrinf(str: String, arg: Any...) -> Void { 16 | print("I(printf) have been fishhook 😂") 17 | } 18 | 19 | func testPrintf() { 20 | print("======> printf_test:") 21 | 22 | let printf: NewPrintfMethod = newPrinf 23 | fishhookPrintf(newMethod: unsafeBitCast(printf, to: UnsafeMutableRawPointer.self)) 24 | PrintfTestHelp.printf("Hello World") 25 | 26 | print("begin time=>: ", mach_absolute_time()) 27 | FishHookChecker.denyFishHook("printf") 28 | print("end time=>:", mach_absolute_time()) 29 | PrintfTestHelp.printf("Hello World🚀🚀🚀\n") 30 | } 31 | 32 | 33 | -------------------------------------------------------------------------------- /Demo/Pods/Target Support Files/antiFishhook/antiFishhook-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | ${PRODUCT_BUNDLE_IDENTIFIER} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | ${PRODUCT_NAME} 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | ${CURRENT_PROJECT_VERSION} 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Demo/Pods/Target Support Files/Pods-InsertDyld/Pods-InsertDyld-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | ${PRODUCT_BUNDLE_IDENTIFIER} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | ${PRODUCT_NAME} 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | ${CURRENT_PROJECT_VERSION} 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Demo/Pods/Target Support Files/Pods-AntiFishHookDemo/Pods-AntiFishHookDemo-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | ${PRODUCT_BUNDLE_IDENTIFIER} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | ${PRODUCT_NAME} 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | ${CURRENT_PROJECT_VERSION} 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Demo/AntiFishHookDemo/TestCase/Print.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Print.swift 3 | // AntiFishHookDemo 4 | // 5 | // Created by jintao on 2020/12/12. 6 | // Copyright © 2020 jintao. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import antiFishhook 11 | 12 | func testPrint() { 13 | typealias MyPrint = @convention(thin) (Any..., String, String) ->Void 14 | func myPrint(_ items: Any..., separator: String = " ", terminator: String = "\n") { 15 | NSLog("I(print) have been fishhook 😂") 16 | } 17 | let myprint: MyPrint = myPrint 18 | let myPrintPointer = unsafeBitCast(myprint, to: UnsafeMutableRawPointer.self) 19 | var oldMethod: UnsafeMutableRawPointer? 20 | 21 | print("======> print_test:") 22 | // hook 23 | FishHook.replaceSymbol("$ss5print_9separator10terminatoryypd_S2StF", newMethod: myPrintPointer, oldMethod: &oldMethod) 24 | print("I(print) has not been hooked ???") 25 | 26 | // antiHook 27 | FishHookChecker.denyFishHook("$ss5print_9separator10terminatoryypd_S2StF") 28 | print("I(print) test success 🚀🚀🚀\n") 29 | } 30 | -------------------------------------------------------------------------------- /Demo/AntiFishHookDemo/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // AntiFishHookDemo 4 | // 5 | // Created by jintao on 2019/7/3. 6 | // Copyright © 2019 jintao. All rights reserved. 7 | // 8 | 9 | import antiFishhook 10 | import UIKit 11 | 12 | @UIApplicationMain 13 | class AppDelegate: UIResponder, UIApplicationDelegate { 14 | 15 | var window: UIWindow? 16 | 17 | 18 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 19 | 20 | // MARK: - print method 21 | testPrint() 22 | 23 | // MARK: - printf method 24 | testPrintf() 25 | 26 | // MARK: - dladdr method 27 | testDladdr() 28 | 29 | // MARK: - Swift Foudation.NSLog method 30 | testSwiftNSLog() 31 | 32 | // MARK: - dlopen method 33 | testDlopen() 34 | 35 | // MARK: - test abort method, will crash 36 | // testAbort() 37 | 38 | return true 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /Demo/InsertDyld/InsertDyld/FishHookTest.swift: -------------------------------------------------------------------------------- 1 | // 2 | // InserDyldFishHook.swift 3 | // InsertDyld 4 | // 5 | // Created by jintao on 2019/4/1. 6 | // Copyright © 2019 jintao. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import MachO 11 | import antiFishhook 12 | 13 | // fishhook all image's printf 14 | public func fishhookPrintf(newMethod: UnsafeMutableRawPointer) { 15 | var oldMethod: UnsafeMutableRawPointer? 16 | FishHook.replaceSymbol("printf", newMethod: newMethod, oldMethod: &oldMethod) 17 | } 18 | 19 | // fishhook AntiFishHookDemo's target symbol dladdr 20 | public func fishhookDladdr(newMethod: UnsafeMutableRawPointer) { 21 | var oldMethod: UnsafeMutableRawPointer? 22 | FishHook.replaceSymbol("dladdr", newMethod: newMethod, oldMethod: &oldMethod) 23 | } 24 | 25 | // fishhook all image's Swift.Foudation.NSLog 26 | public func fishhookSwiftFoudationNSLog(_ nslogSymbol: String, newMethod: UnsafeMutableRawPointer) { 27 | var oldMethod: UnsafeMutableRawPointer? 28 | FishHook.replaceSymbol(nslogSymbol, newMethod: newMethod, oldMethod: &oldMethod) 29 | } 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Tanner Jin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Demo/Pods/Target Support Files/Pods-InsertDyld/Pods-InsertDyld-acknowledgements.markdown: -------------------------------------------------------------------------------- 1 | # Acknowledgements 2 | This application makes use of the following third party libraries: 3 | 4 | ## antiFishhook 5 | 6 | MIT License 7 | 8 | Copyright (c) 2019 Tanner Jin 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | SOFTWARE. 27 | 28 | Generated by CocoaPods - https://cocoapods.org 29 | -------------------------------------------------------------------------------- /Demo/Pods/Target Support Files/Pods-AntiFishHookDemo/Pods-AntiFishHookDemo-acknowledgements.markdown: -------------------------------------------------------------------------------- 1 | # Acknowledgements 2 | This application makes use of the following third party libraries: 3 | 4 | ## antiFishhook 5 | 6 | MIT License 7 | 8 | Copyright (c) 2019 Tanner Jin 9 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy 11 | of this software and associated documentation files (the "Software"), to deal 12 | in the Software without restriction, including without limitation the rights 13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | copies of the Software, and to permit persons to whom the Software is 15 | furnished to do so, subject to the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | SOFTWARE. 27 | 28 | Generated by CocoaPods - https://cocoapods.org 29 | -------------------------------------------------------------------------------- /Demo/AntiFishHookDemo/TestCase/Dladdr.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Dladdr.swift 3 | // FishHookProtect 4 | // 5 | // Created by jintao on 2019/6/17. 6 | // Copyright © 2019 jintao. All rights reserved. 7 | // 8 | 9 | import MachO 10 | import InsertDyld 11 | import Foundation 12 | import antiFishhook 13 | 14 | typealias NewDladdrMethod = @convention(thin) (UnsafeRawPointer, UnsafeMutablePointer) -> Int32 15 | 16 | func newDladdr(a: UnsafeRawPointer, b: UnsafeMutablePointer) -> Int32 { 17 | return -999 18 | } 19 | 20 | func testDladdr() { 21 | print("\n======> dladdr_test:") 22 | 23 | let myDladdr: NewDladdrMethod = newDladdr 24 | fishhookDladdr(newMethod: unsafeBitCast(myDladdr, to: UnsafeMutableRawPointer.self)) 25 | verifyDladdr() 26 | 27 | FishHookChecker.denyFishHook("dladdr") 28 | verifyDladdr() 29 | } 30 | 31 | private func verifyDladdr() { 32 | class BaseTest { 33 | @objc func baseTest() { 34 | print("baseTest") 35 | } 36 | } 37 | 38 | if let testImp = class_getMethodImplementation(BaseTest.self, #selector(BaseTest.baseTest)) { 39 | var info = Dl_info() 40 | if dladdr(UnsafeRawPointer(testImp), &info) == -999 { 41 | print("I(dladdr) have been fishhook 😂") 42 | } else if dladdr(UnsafeRawPointer(testImp), &info) == 1 { 43 | print("dladdr method path: ", String(cString: info.dli_fname), "🚀🚀🚀") 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Demo/AntiFishHookDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AntiFishhook 2 | 3 | __AntiFishhook__ is an AntiHook library for [`fishhook`][fishhook] at runtime (make fishhook doesn't work) . 4 | include `fishhook` and `anti-fishhook` 5 | 6 | [fishhook]: https://github.com/facebook/fishhook 7 | [Swift Name Mangling]: https://www.mikeash.com/pyblog/friday-qa-2014-08-15-swift-name-mangling.html 8 | 9 | [How it's work](https://github.com/TannerJin/IOSSecuritySuite/blob/master/IOSSecuritySuite/FishHookChecker.swift#L13) 10 | 11 | ### Note 12 | 13 | Run or test in your phone(arm64) instend of simulator 14 | [`Swift Function name mangling`][Swift Name Mangling] 15 | 16 | ## Usage 17 | 18 | ### antiFishhook 19 | 20 | ```swift 21 | import antiFishhook 22 | 23 | FishHookChecker.denyFishHook("$s10Foundation5NSLogyySS_s7CVarArg_pdtF") // Swift's Foudation.NSLog 24 | NSLog("Hello AntiFishHook") 25 | 26 | FishHookChecker.denyFishHook("printf") // printf 27 | printf("Hello AntiFishHook") 28 | ``` 29 | 30 | 31 | ### fishhook 32 | 33 | ```swift 34 | typealias MyNSLog = @convention(thin) (_ format: String, _ args: CVarArg...) -> Void 35 | 36 | func myNSLog(_ format: String, _ args: CVarArg...) { 37 | print("Hello fishHook") 38 | } 39 | 40 | let selfNSLog: MyNSLog = myNSLog 41 | let selfNSLogPointer = unsafeBitCast(selfNSLog, to: UnsafeMutableRawPointer.self) 42 | var origNSLogPointer: UnsafeMutableRawPointer? 43 | 44 | FishHook.replaceSymbol("$s10Foundation5NSLogyySS_s7CVarArg_pdtF", newMethod: selfNSLogPointer, oldMethod: &origNSLogPointer) 45 | 46 | NSLog("Hello World") 47 | // will print Hello fishHook 48 | 49 | ``` 50 | 51 | ### Suggestion 52 | 53 | Use by adding source file to your project instend of pod 54 | -------------------------------------------------------------------------------- /Demo/AntiFishHookDemo/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Demo/AntiFishHookDemo/TestCase/NSLog.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NSLog.swift 3 | // FishHookProtect 4 | // 5 | // Created by jintao on 2019/6/17. 6 | // Copyright © 2019 jintao. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import antiFishhook 11 | import InsertDyld 12 | 13 | typealias NewSwiftNSLog = @convention(thin) (_ format: String, _ args: CVarArg...) -> Void 14 | 15 | func newNSLog(_ format: String, _ args: CVarArg...) { 16 | print("I(swift_nslog) has been fishhook 😂") 17 | } 18 | 19 | func testSwiftNSLog() { 20 | print("\n======> Swift_Foudation.NSLog test:") 21 | 22 | let nslogSymbol = "$s10Foundation5NSLogyySS_s7CVarArg_pdtF" 23 | 24 | let myNSLog: NewSwiftNSLog = newNSLog 25 | fishhookSwiftFoudationNSLog(nslogSymbol, newMethod: unsafeBitCast(myNSLog, to: UnsafeMutableRawPointer.self)) 26 | NSLog("Swift's NSLog has not been fishhook。。。") 27 | 28 | FishHookChecker.denyFishHook(nslogSymbol) 29 | NSLog("Swift NSLog test success🚀🚀🚀") 30 | } 31 | 32 | public func swift_demangle(_ mangledName: String) -> String? { 33 | let cname = mangledName.withCString({ $0 }) 34 | if let demangledName = get_swift_demangle(mangledName: cname, mangledNameLength: UInt(mangledName.utf8.count), outputBuffer: nil, outputBufferSize: nil, flags: 0) { 35 | return String(cString: demangledName) 36 | } 37 | return nil 38 | } 39 | 40 | // swift_demangle: Swift/Swift libraries/SwiftDemangling/Header Files/Demangle.h 41 | @_silgen_name("swift_demangle") 42 | private func get_swift_demangle(mangledName: UnsafePointer?, 43 | mangledNameLength: UInt, 44 | outputBuffer: UnsafeMutablePointer?, 45 | outputBufferSize: UnsafeMutablePointer?, 46 | flags: UInt32 47 | ) -> UnsafeMutablePointer? 48 | -------------------------------------------------------------------------------- /Demo/AntiFishHookDemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /Demo/AntiFishHookDemo/TestCase/Dlopen.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Dlopen.swift 3 | // FishHookProtect 4 | // 5 | // Created by jintao on 2019/6/17. 6 | // Copyright © 2019 jintao. All rights reserved. 7 | // 8 | 9 | import MachO 10 | import Foundation 11 | import antiFishhook 12 | 13 | typealias NewDlopen = @convention(thin) (_ path: UnsafePointer?, _ mode: Int32) -> UnsafeMutableRawPointer? 14 | 15 | func newDlopen(_ path: UnsafePointer!, _ mode: Int32) -> UnsafeMutableRawPointer? { 16 | return nil 17 | } 18 | 19 | func testDlopen() { 20 | print("\n======> dlopen_test:") 21 | 22 | let myDlopen: NewDlopen = newDlopen 23 | fishhookDlopen(newMethod: unsafeBitCast(myDlopen, to: UnsafeMutableRawPointer.self)) 24 | verifyDlopen() 25 | 26 | resetDlopen() 27 | verifyDlopen() 28 | } 29 | 30 | private func verifyDlopen() { 31 | let handle = dlopen("/usr/lib/libc.dylib", RTLD_NOW) 32 | 33 | if handle == nil { 34 | print("I(dlopen) have been fishhook 😂") 35 | } else { 36 | print("dlopen test success🚀🚀🚀") 37 | } 38 | } 39 | 40 | private func fishhookDlopen(newMethod: UnsafeMutableRawPointer) { 41 | var oldMethod: UnsafeMutableRawPointer? 42 | FishHook.replaceSymbol("dlopen", newMethod: newMethod, oldMethod: &oldMethod) 43 | 44 | for i in 0..<_dyld_image_count() { 45 | if let cName = _dyld_get_image_name(i), String(cString: cName).contains("AntiFishHookDemo"), let image = _dyld_get_image_header(i) { 46 | 47 | FishHook.replaceSymbol("dlopen", at: image, imageSlide: _dyld_get_image_vmaddr_slide(i), newMethod: newMethod, oldMethod: &oldMethod) 48 | break 49 | } 50 | } 51 | } 52 | 53 | private func resetDlopen() { 54 | for i in 0..<_dyld_image_count() { 55 | if let cName = _dyld_get_image_name(i), String(cString: cName).contains("AntiFishHookDemo"), let image = _dyld_get_image_header(i) { 56 | 57 | FishHookChecker.denyFishHook("dlopen", at: image, imageSlide: _dyld_get_image_vmaddr_slide(i)) 58 | break 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Demo/Pods/Pods.xcodeproj/xcuserdata/jintao.xcuserdatad/xcschemes/Pods-InsertDyld.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 43 | 44 | 50 | 51 | 53 | 54 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /Demo/Pods/Pods.xcodeproj/xcuserdata/jintao.xcuserdatad/xcschemes/Pods-AntiFishHookDemo.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 43 | 44 | 50 | 51 | 53 | 54 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /Demo/Pods/Target Support Files/Pods-InsertDyld/Pods-InsertDyld-acknowledgements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreferenceSpecifiers 6 | 7 | 8 | FooterText 9 | This application makes use of the following third party libraries: 10 | Title 11 | Acknowledgements 12 | Type 13 | PSGroupSpecifier 14 | 15 | 16 | FooterText 17 | MIT License 18 | 19 | Copyright (c) 2019 Tanner Jin 20 | 21 | Permission is hereby granted, free of charge, to any person obtaining a copy 22 | of this software and associated documentation files (the "Software"), to deal 23 | in the Software without restriction, including without limitation the rights 24 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 25 | copies of the Software, and to permit persons to whom the Software is 26 | furnished to do so, subject to the following conditions: 27 | 28 | The above copyright notice and this permission notice shall be included in all 29 | copies or substantial portions of the Software. 30 | 31 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 32 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 33 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 34 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 35 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 36 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 37 | SOFTWARE. 38 | 39 | License 40 | MIT 41 | Title 42 | antiFishhook 43 | Type 44 | PSGroupSpecifier 45 | 46 | 47 | FooterText 48 | Generated by CocoaPods - https://cocoapods.org 49 | Title 50 | 51 | Type 52 | PSGroupSpecifier 53 | 54 | 55 | StringsTable 56 | Acknowledgements 57 | Title 58 | Acknowledgements 59 | 60 | 61 | -------------------------------------------------------------------------------- /Demo/Pods/Pods.xcodeproj/xcuserdata/jintao.xcuserdatad/xcschemes/antiFishhook.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 43 | 44 | 45 | 46 | 52 | 53 | 55 | 56 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /Demo/Pods/Target Support Files/Pods-AntiFishHookDemo/Pods-AntiFishHookDemo-acknowledgements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreferenceSpecifiers 6 | 7 | 8 | FooterText 9 | This application makes use of the following third party libraries: 10 | Title 11 | Acknowledgements 12 | Type 13 | PSGroupSpecifier 14 | 15 | 16 | FooterText 17 | MIT License 18 | 19 | Copyright (c) 2019 Tanner Jin 20 | 21 | Permission is hereby granted, free of charge, to any person obtaining a copy 22 | of this software and associated documentation files (the "Software"), to deal 23 | in the Software without restriction, including without limitation the rights 24 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 25 | copies of the Software, and to permit persons to whom the Software is 26 | furnished to do so, subject to the following conditions: 27 | 28 | The above copyright notice and this permission notice shall be included in all 29 | copies or substantial portions of the Software. 30 | 31 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 32 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 33 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 34 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 35 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 36 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 37 | SOFTWARE. 38 | 39 | License 40 | MIT 41 | Title 42 | antiFishhook 43 | Type 44 | PSGroupSpecifier 45 | 46 | 47 | FooterText 48 | Generated by CocoaPods - https://cocoapods.org 49 | Title 50 | 51 | Type 52 | PSGroupSpecifier 53 | 54 | 55 | StringsTable 56 | Acknowledgements 57 | Title 58 | Acknowledgements 59 | 60 | 61 | -------------------------------------------------------------------------------- /Demo/AntiFishHookDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Demo/AntiFishHookDemo.xcodeproj/xcshareddata/xcschemes/AntiFishHookDemo.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 42 | 48 | 49 | 50 | 51 | 52 | 62 | 64 | 70 | 71 | 72 | 73 | 79 | 81 | 87 | 88 | 89 | 90 | 92 | 93 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /Source/FishHook.swift: -------------------------------------------------------------------------------- 1 | // 2 | // FishHook.swift 3 | // FishHookProtect 4 | // 5 | // Created by jintao on 2019/3/28. 6 | // Copyright © 2019 jintao. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import MachO 11 | 12 | #if arch(arm64) 13 | // MARK: - FishHook 14 | public class FishHook { 15 | @inline(__always) 16 | public static func replaceSymbol(_ symbol: String, 17 | newMethod: UnsafeMutableRawPointer, 18 | oldMethod: inout UnsafeMutableRawPointer?) { 19 | for imgIndex in 0..<_dyld_image_count() { 20 | if let image = _dyld_get_image_header(imgIndex) { 21 | replaceSymbolAtImage(image, imageSlide: _dyld_get_image_vmaddr_slide(imgIndex), symbol: symbol, newMethod: newMethod, oldMethod: &oldMethod) 22 | } 23 | } 24 | } 25 | 26 | @inline(__always) 27 | public static func replaceSymbol(_ symbol: String, 28 | at image: UnsafePointer, 29 | imageSlide slide: Int, 30 | newMethod: UnsafeMutableRawPointer, 31 | oldMethod: inout UnsafeMutableRawPointer?) { 32 | replaceSymbolAtImage(image, imageSlide: slide, symbol: symbol, newMethod: newMethod, oldMethod: &oldMethod) 33 | } 34 | 35 | @inline(__always) 36 | private static func replaceSymbolAtImage(_ image: UnsafePointer, 37 | imageSlide slide: Int, 38 | symbol: String, 39 | newMethod: UnsafeMutableRawPointer, 40 | oldMethod: inout UnsafeMutableRawPointer?) { 41 | var linkeditCmd: UnsafeMutablePointer! 42 | var dataCmd: UnsafeMutablePointer! 43 | var symtabCmd: UnsafeMutablePointer! 44 | var dynamicSymtabCmd: UnsafeMutablePointer! 45 | 46 | guard var curCmdPointer = UnsafeMutableRawPointer(bitPattern: UInt(bitPattern: image)+UInt(MemoryLayout.size)) else { return } 47 | 48 | for _ in 0..(OpaquePointer(curCmd)) 63 | } else if curCmd.pointee.cmd == LC_DYSYMTAB { 64 | dynamicSymtabCmd = UnsafeMutablePointer(OpaquePointer(curCmd)) 65 | } 66 | 67 | curCmdPointer = curCmdPointer + Int(curCmd.pointee.cmdsize) 68 | } 69 | 70 | if linkeditCmd == nil || symtabCmd == nil || dynamicSymtabCmd == nil || dataCmd == nil { 71 | return 72 | } 73 | 74 | let linkedBase = slide + Int(linkeditCmd.pointee.vmaddr) - Int(linkeditCmd.pointee.fileoff) 75 | let symtab = UnsafeMutablePointer(bitPattern: linkedBase + Int(symtabCmd.pointee.symoff)) 76 | let strtab = UnsafeMutablePointer(bitPattern: linkedBase + Int(symtabCmd.pointee.stroff)) 77 | let indirectsym = UnsafeMutablePointer(bitPattern: linkedBase + Int(dynamicSymtabCmd.pointee.indirectsymoff)) 78 | 79 | if symtab == nil || strtab == nil || indirectsym == nil { 80 | return 81 | } 82 | 83 | for tmp in 0...size + MemoryLayout.size*Int(tmp)).assumingMemoryBound(to: section_64.self) 85 | 86 | // symbol_pointers sections 87 | if curSection.pointee.flags == S_LAZY_SYMBOL_POINTERS { 88 | replaceSymbolPointerAtSection(curSection, symtab: symtab!, strtab: strtab!, indirectsym: indirectsym!, slide: slide, symbolName: symbol, newMethod: newMethod, oldMethod: &oldMethod) 89 | } 90 | if curSection.pointee.flags == S_NON_LAZY_SYMBOL_POINTERS { 91 | replaceSymbolPointerAtSection(curSection, symtab: symtab!, strtab: strtab!, indirectsym: indirectsym!, slide: slide, symbolName: symbol, newMethod: newMethod, oldMethod: &oldMethod) 92 | } 93 | } 94 | } 95 | 96 | @inline(__always) 97 | private static func replaceSymbolPointerAtSection(_ section: UnsafeMutablePointer, 98 | symtab: UnsafeMutablePointer, 99 | strtab: UnsafeMutablePointer, 100 | indirectsym: UnsafeMutablePointer, 101 | slide: Int, 102 | symbolName: String, 103 | newMethod: UnsafeMutableRawPointer, 104 | oldMethod: inout UnsafeMutableRawPointer?) { 105 | let indirectSymVmAddr = indirectsym.advanced(by: Int(section.pointee.reserved1)) 106 | let sectionVmAddr = UnsafeMutablePointer(bitPattern: slide+Int(section.pointee.addr)) 107 | 108 | if sectionVmAddr == nil { 109 | return 110 | } 111 | 112 | for tmp in 0...size { 113 | let curIndirectSym = indirectSymVmAddr.advanced(by: tmp) 114 | if curIndirectSym.pointee == INDIRECT_SYMBOL_ABS || curIndirectSym.pointee == INDIRECT_SYMBOL_LOCAL { 115 | continue 116 | } 117 | let curStrTabOff = symtab.advanced(by: Int(curIndirectSym.pointee)).pointee.n_un.n_strx 118 | let curSymbolName = strtab.advanced(by: Int(curStrTabOff+1)) 119 | 120 | if String(cString: curSymbolName) == symbolName { 121 | oldMethod = sectionVmAddr!.advanced(by: tmp).pointee 122 | sectionVmAddr!.advanced(by: tmp).initialize(to: newMethod) 123 | break 124 | } 125 | } 126 | } 127 | } 128 | #endif 129 | -------------------------------------------------------------------------------- /Demo/Pods/Target Support Files/Pods-AntiFishHookDemo/Pods-AntiFishHookDemo-frameworks.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | set -u 4 | set -o pipefail 5 | 6 | function on_error { 7 | echo "$(realpath -mq "${0}"):$1: error: Unexpected failure" 8 | } 9 | trap 'on_error $LINENO' ERR 10 | 11 | if [ -z ${FRAMEWORKS_FOLDER_PATH+x} ]; then 12 | # If FRAMEWORKS_FOLDER_PATH is not set, then there's nowhere for us to copy 13 | # frameworks to, so exit 0 (signalling the script phase was successful). 14 | exit 0 15 | fi 16 | 17 | echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 18 | mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 19 | 20 | COCOAPODS_PARALLEL_CODE_SIGN="${COCOAPODS_PARALLEL_CODE_SIGN:-false}" 21 | SWIFT_STDLIB_PATH="${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}" 22 | 23 | # Used as a return value for each invocation of `strip_invalid_archs` function. 24 | STRIP_BINARY_RETVAL=0 25 | 26 | # This protects against multiple targets copying the same framework dependency at the same time. The solution 27 | # was originally proposed here: https://lists.samba.org/archive/rsync/2008-February/020158.html 28 | RSYNC_PROTECT_TMP_FILES=(--filter "P .*.??????") 29 | 30 | # Copies and strips a vendored framework 31 | install_framework() 32 | { 33 | if [ -r "${BUILT_PRODUCTS_DIR}/$1" ]; then 34 | local source="${BUILT_PRODUCTS_DIR}/$1" 35 | elif [ -r "${BUILT_PRODUCTS_DIR}/$(basename "$1")" ]; then 36 | local source="${BUILT_PRODUCTS_DIR}/$(basename "$1")" 37 | elif [ -r "$1" ]; then 38 | local source="$1" 39 | fi 40 | 41 | local destination="${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 42 | 43 | if [ -L "${source}" ]; then 44 | echo "Symlinked..." 45 | source="$(readlink "${source}")" 46 | fi 47 | 48 | # Use filter instead of exclude so missing patterns don't throw errors. 49 | echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --links --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${destination}\"" 50 | rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --links --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${destination}" 51 | 52 | local basename 53 | basename="$(basename -s .framework "$1")" 54 | binary="${destination}/${basename}.framework/${basename}" 55 | 56 | if ! [ -r "$binary" ]; then 57 | binary="${destination}/${basename}" 58 | elif [ -L "${binary}" ]; then 59 | echo "Destination binary is symlinked..." 60 | dirname="$(dirname "${binary}")" 61 | binary="${dirname}/$(readlink "${binary}")" 62 | fi 63 | 64 | # Strip invalid architectures so "fat" simulator / device frameworks work on device 65 | if [[ "$(file "$binary")" == *"dynamically linked shared library"* ]]; then 66 | strip_invalid_archs "$binary" 67 | fi 68 | 69 | # Resign the code if required by the build settings to avoid unstable apps 70 | code_sign_if_enabled "${destination}/$(basename "$1")" 71 | 72 | # Embed linked Swift runtime libraries. No longer necessary as of Xcode 7. 73 | if [ "${XCODE_VERSION_MAJOR}" -lt 7 ]; then 74 | local swift_runtime_libs 75 | swift_runtime_libs=$(xcrun otool -LX "$binary" | grep --color=never @rpath/libswift | sed -E s/@rpath\\/\(.+dylib\).*/\\1/g | uniq -u) 76 | for lib in $swift_runtime_libs; do 77 | echo "rsync -auv \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\"" 78 | rsync -auv "${SWIFT_STDLIB_PATH}/${lib}" "${destination}" 79 | code_sign_if_enabled "${destination}/${lib}" 80 | done 81 | fi 82 | } 83 | 84 | # Copies and strips a vendored dSYM 85 | install_dsym() { 86 | local source="$1" 87 | warn_missing_arch=${2:-true} 88 | if [ -r "$source" ]; then 89 | # Copy the dSYM into the targets temp dir. 90 | echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${DERIVED_FILES_DIR}\"" 91 | rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${DERIVED_FILES_DIR}" 92 | 93 | local basename 94 | basename="$(basename -s .dSYM "$source")" 95 | binary_name="$(ls "$source/Contents/Resources/DWARF")" 96 | binary="${DERIVED_FILES_DIR}/${basename}.dSYM/Contents/Resources/DWARF/${binary_name}" 97 | 98 | # Strip invalid architectures so "fat" simulator / device frameworks work on device 99 | if [[ "$(file "$binary")" == *"Mach-O "*"dSYM companion"* ]]; then 100 | strip_invalid_archs "$binary" "$warn_missing_arch" 101 | fi 102 | 103 | if [[ $STRIP_BINARY_RETVAL == 1 ]]; then 104 | # Move the stripped file into its final destination. 105 | echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --links --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${DERIVED_FILES_DIR}/${basename}.framework.dSYM\" \"${DWARF_DSYM_FOLDER_PATH}\"" 106 | rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --links --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${DERIVED_FILES_DIR}/${basename}.dSYM" "${DWARF_DSYM_FOLDER_PATH}" 107 | else 108 | # The dSYM was not stripped at all, in this case touch a fake folder so the input/output paths from Xcode do not reexecute this script because the file is missing. 109 | touch "${DWARF_DSYM_FOLDER_PATH}/${basename}.dSYM" 110 | fi 111 | fi 112 | } 113 | 114 | # Copies the bcsymbolmap files of a vendored framework 115 | install_bcsymbolmap() { 116 | local bcsymbolmap_path="$1" 117 | local destination="${BUILT_PRODUCTS_DIR}" 118 | echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${bcsymbolmap_path}" "${destination}"" 119 | rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${bcsymbolmap_path}" "${destination}" 120 | } 121 | 122 | # Signs a framework with the provided identity 123 | code_sign_if_enabled() { 124 | if [ -n "${EXPANDED_CODE_SIGN_IDENTITY:-}" -a "${CODE_SIGNING_REQUIRED:-}" != "NO" -a "${CODE_SIGNING_ALLOWED}" != "NO" ]; then 125 | # Use the current code_sign_identity 126 | echo "Code Signing $1 with Identity ${EXPANDED_CODE_SIGN_IDENTITY_NAME}" 127 | local code_sign_cmd="/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} ${OTHER_CODE_SIGN_FLAGS:-} --preserve-metadata=identifier,entitlements '$1'" 128 | 129 | if [ "${COCOAPODS_PARALLEL_CODE_SIGN}" == "true" ]; then 130 | code_sign_cmd="$code_sign_cmd &" 131 | fi 132 | echo "$code_sign_cmd" 133 | eval "$code_sign_cmd" 134 | fi 135 | } 136 | 137 | # Strip invalid architectures 138 | strip_invalid_archs() { 139 | binary="$1" 140 | warn_missing_arch=${2:-true} 141 | # Get architectures for current target binary 142 | binary_archs="$(lipo -info "$binary" | rev | cut -d ':' -f1 | awk '{$1=$1;print}' | rev)" 143 | # Intersect them with the architectures we are building for 144 | intersected_archs="$(echo ${ARCHS[@]} ${binary_archs[@]} | tr ' ' '\n' | sort | uniq -d)" 145 | # If there are no archs supported by this binary then warn the user 146 | if [[ -z "$intersected_archs" ]]; then 147 | if [[ "$warn_missing_arch" == "true" ]]; then 148 | echo "warning: [CP] Vendored binary '$binary' contains architectures ($binary_archs) none of which match the current build architectures ($ARCHS)." 149 | fi 150 | STRIP_BINARY_RETVAL=0 151 | return 152 | fi 153 | stripped="" 154 | for arch in $binary_archs; do 155 | if ! [[ "${ARCHS}" == *"$arch"* ]]; then 156 | # Strip non-valid architectures in-place 157 | lipo -remove "$arch" -output "$binary" "$binary" 158 | stripped="$stripped $arch" 159 | fi 160 | done 161 | if [[ "$stripped" ]]; then 162 | echo "Stripped $binary of architectures:$stripped" 163 | fi 164 | STRIP_BINARY_RETVAL=1 165 | } 166 | 167 | install_artifact() { 168 | artifact="$1" 169 | base="$(basename "$artifact")" 170 | case $base in 171 | *.framework) 172 | install_framework "$artifact" 173 | ;; 174 | *.dSYM) 175 | # Suppress arch warnings since XCFrameworks will include many dSYM files 176 | install_dsym "$artifact" "false" 177 | ;; 178 | *.bcsymbolmap) 179 | install_bcsymbolmap "$artifact" 180 | ;; 181 | *) 182 | echo "error: Unrecognized artifact "$artifact"" 183 | ;; 184 | esac 185 | } 186 | 187 | copy_artifacts() { 188 | file_list="$1" 189 | while read artifact; do 190 | install_artifact "$artifact" 191 | done <$file_list 192 | } 193 | 194 | ARTIFACT_LIST_FILE="${BUILT_PRODUCTS_DIR}/cocoapods-artifacts-${CONFIGURATION}.txt" 195 | if [ -r "${ARTIFACT_LIST_FILE}" ]; then 196 | copy_artifacts "${ARTIFACT_LIST_FILE}" 197 | fi 198 | 199 | if [[ "$CONFIGURATION" == "Debug" ]]; then 200 | install_framework "${BUILT_PRODUCTS_DIR}/antiFishhook/antiFishhook.framework" 201 | fi 202 | if [[ "$CONFIGURATION" == "Release" ]]; then 203 | install_framework "${BUILT_PRODUCTS_DIR}/antiFishhook/antiFishhook.framework" 204 | fi 205 | if [ "${COCOAPODS_PARALLEL_CODE_SIGN}" == "true" ]; then 206 | wait 207 | fi 208 | -------------------------------------------------------------------------------- /Demo/InsertDyld/InsertDyld.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 9E19AE381E8DFCFC2D9B1919 /* Pods_InsertDyld.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 287D178ED5709A309905ED85 /* Pods_InsertDyld.framework */; }; 11 | A95052B02251FE9000BFBC53 /* InsertDyld.h in Headers */ = {isa = PBXBuildFile; fileRef = A95052AE2251FE9000BFBC53 /* InsertDyld.h */; settings = {ATTRIBUTES = (Public, ); }; }; 12 | A95052B72251FEBE00BFBC53 /* FishHookTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = A95052B62251FEBE00BFBC53 /* FishHookTest.swift */; }; 13 | A95B34E522CBBA880078B3D4 /* antiFishhook.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A95B34E422CBBA880078B3D4 /* antiFishhook.framework */; }; 14 | /* End PBXBuildFile section */ 15 | 16 | /* Begin PBXFileReference section */ 17 | 0729E6988353829E18A5ADBE /* Pods-InsertDyld.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-InsertDyld.release.xcconfig"; path = "../Pods/Target Support Files/Pods-InsertDyld/Pods-InsertDyld.release.xcconfig"; sourceTree = ""; }; 18 | 287D178ED5709A309905ED85 /* Pods_InsertDyld.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_InsertDyld.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 19 | A95052AB2251FE9000BFBC53 /* InsertDyld.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = InsertDyld.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 20 | A95052AE2251FE9000BFBC53 /* InsertDyld.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = InsertDyld.h; sourceTree = ""; }; 21 | A95052AF2251FE9000BFBC53 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 22 | A95052B62251FEBE00BFBC53 /* FishHookTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FishHookTest.swift; sourceTree = ""; }; 23 | A95B34E422CBBA880078B3D4 /* antiFishhook.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = antiFishhook.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 24 | E6249167321D0F899E89EA65 /* Pods-InsertDyld.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-InsertDyld.debug.xcconfig"; path = "../Pods/Target Support Files/Pods-InsertDyld/Pods-InsertDyld.debug.xcconfig"; sourceTree = ""; }; 25 | /* End PBXFileReference section */ 26 | 27 | /* Begin PBXFrameworksBuildPhase section */ 28 | A95052A82251FE9000BFBC53 /* Frameworks */ = { 29 | isa = PBXFrameworksBuildPhase; 30 | buildActionMask = 2147483647; 31 | files = ( 32 | A95B34E522CBBA880078B3D4 /* antiFishhook.framework in Frameworks */, 33 | 9E19AE381E8DFCFC2D9B1919 /* Pods_InsertDyld.framework in Frameworks */, 34 | ); 35 | runOnlyForDeploymentPostprocessing = 0; 36 | }; 37 | /* End PBXFrameworksBuildPhase section */ 38 | 39 | /* Begin PBXGroup section */ 40 | 4B1BEF7BD88FAB1154E867DE /* Pods */ = { 41 | isa = PBXGroup; 42 | children = ( 43 | E6249167321D0F899E89EA65 /* Pods-InsertDyld.debug.xcconfig */, 44 | 0729E6988353829E18A5ADBE /* Pods-InsertDyld.release.xcconfig */, 45 | ); 46 | name = Pods; 47 | sourceTree = ""; 48 | }; 49 | A95052A12251FE9000BFBC53 = { 50 | isa = PBXGroup; 51 | children = ( 52 | A95052AD2251FE9000BFBC53 /* InsertDyld */, 53 | A95052AC2251FE9000BFBC53 /* Products */, 54 | AC4EFFF0F09E5DC5F75798B9 /* Frameworks */, 55 | 4B1BEF7BD88FAB1154E867DE /* Pods */, 56 | ); 57 | sourceTree = ""; 58 | }; 59 | A95052AC2251FE9000BFBC53 /* Products */ = { 60 | isa = PBXGroup; 61 | children = ( 62 | A95052AB2251FE9000BFBC53 /* InsertDyld.framework */, 63 | ); 64 | name = Products; 65 | sourceTree = ""; 66 | }; 67 | A95052AD2251FE9000BFBC53 /* InsertDyld */ = { 68 | isa = PBXGroup; 69 | children = ( 70 | A95052AE2251FE9000BFBC53 /* InsertDyld.h */, 71 | A95052AF2251FE9000BFBC53 /* Info.plist */, 72 | A95052B62251FEBE00BFBC53 /* FishHookTest.swift */, 73 | ); 74 | path = InsertDyld; 75 | sourceTree = ""; 76 | }; 77 | AC4EFFF0F09E5DC5F75798B9 /* Frameworks */ = { 78 | isa = PBXGroup; 79 | children = ( 80 | A95B34E422CBBA880078B3D4 /* antiFishhook.framework */, 81 | 287D178ED5709A309905ED85 /* Pods_InsertDyld.framework */, 82 | ); 83 | name = Frameworks; 84 | sourceTree = ""; 85 | }; 86 | /* End PBXGroup section */ 87 | 88 | /* Begin PBXHeadersBuildPhase section */ 89 | A95052A62251FE9000BFBC53 /* Headers */ = { 90 | isa = PBXHeadersBuildPhase; 91 | buildActionMask = 2147483647; 92 | files = ( 93 | A95052B02251FE9000BFBC53 /* InsertDyld.h in Headers */, 94 | ); 95 | runOnlyForDeploymentPostprocessing = 0; 96 | }; 97 | /* End PBXHeadersBuildPhase section */ 98 | 99 | /* Begin PBXNativeTarget section */ 100 | A95052AA2251FE9000BFBC53 /* InsertDyld */ = { 101 | isa = PBXNativeTarget; 102 | buildConfigurationList = A95052B32251FE9000BFBC53 /* Build configuration list for PBXNativeTarget "InsertDyld" */; 103 | buildPhases = ( 104 | 510C04264F59DA5CB432AC4D /* [CP] Check Pods Manifest.lock */, 105 | A95052A62251FE9000BFBC53 /* Headers */, 106 | A95052A72251FE9000BFBC53 /* Sources */, 107 | A95052A82251FE9000BFBC53 /* Frameworks */, 108 | A95052A92251FE9000BFBC53 /* Resources */, 109 | ); 110 | buildRules = ( 111 | ); 112 | dependencies = ( 113 | ); 114 | name = InsertDyld; 115 | productName = InsertDyld; 116 | productReference = A95052AB2251FE9000BFBC53 /* InsertDyld.framework */; 117 | productType = "com.apple.product-type.framework"; 118 | }; 119 | /* End PBXNativeTarget section */ 120 | 121 | /* Begin PBXProject section */ 122 | A95052A22251FE9000BFBC53 /* Project object */ = { 123 | isa = PBXProject; 124 | attributes = { 125 | LastUpgradeCheck = 1110; 126 | ORGANIZATIONNAME = jintao; 127 | TargetAttributes = { 128 | A95052AA2251FE9000BFBC53 = { 129 | CreatedOnToolsVersion = 10.0; 130 | LastSwiftMigration = 1110; 131 | }; 132 | }; 133 | }; 134 | buildConfigurationList = A95052A52251FE9000BFBC53 /* Build configuration list for PBXProject "InsertDyld" */; 135 | compatibilityVersion = "Xcode 9.3"; 136 | developmentRegion = en; 137 | hasScannedForEncodings = 0; 138 | knownRegions = ( 139 | en, 140 | ); 141 | mainGroup = A95052A12251FE9000BFBC53; 142 | productRefGroup = A95052AC2251FE9000BFBC53 /* Products */; 143 | projectDirPath = ""; 144 | projectRoot = ""; 145 | targets = ( 146 | A95052AA2251FE9000BFBC53 /* InsertDyld */, 147 | ); 148 | }; 149 | /* End PBXProject section */ 150 | 151 | /* Begin PBXResourcesBuildPhase section */ 152 | A95052A92251FE9000BFBC53 /* Resources */ = { 153 | isa = PBXResourcesBuildPhase; 154 | buildActionMask = 2147483647; 155 | files = ( 156 | ); 157 | runOnlyForDeploymentPostprocessing = 0; 158 | }; 159 | /* End PBXResourcesBuildPhase section */ 160 | 161 | /* Begin PBXShellScriptBuildPhase section */ 162 | 510C04264F59DA5CB432AC4D /* [CP] Check Pods Manifest.lock */ = { 163 | isa = PBXShellScriptBuildPhase; 164 | buildActionMask = 2147483647; 165 | files = ( 166 | ); 167 | inputFileListPaths = ( 168 | ); 169 | inputPaths = ( 170 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock", 171 | "${PODS_ROOT}/Manifest.lock", 172 | ); 173 | name = "[CP] Check Pods Manifest.lock"; 174 | outputFileListPaths = ( 175 | ); 176 | outputPaths = ( 177 | "$(DERIVED_FILE_DIR)/Pods-InsertDyld-checkManifestLockResult.txt", 178 | ); 179 | runOnlyForDeploymentPostprocessing = 0; 180 | shellPath = /bin/sh; 181 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; 182 | showEnvVarsInLog = 0; 183 | }; 184 | /* End PBXShellScriptBuildPhase section */ 185 | 186 | /* Begin PBXSourcesBuildPhase section */ 187 | A95052A72251FE9000BFBC53 /* Sources */ = { 188 | isa = PBXSourcesBuildPhase; 189 | buildActionMask = 2147483647; 190 | files = ( 191 | A95052B72251FEBE00BFBC53 /* FishHookTest.swift in Sources */, 192 | ); 193 | runOnlyForDeploymentPostprocessing = 0; 194 | }; 195 | /* End PBXSourcesBuildPhase section */ 196 | 197 | /* Begin XCBuildConfiguration section */ 198 | A95052B12251FE9000BFBC53 /* Debug */ = { 199 | isa = XCBuildConfiguration; 200 | buildSettings = { 201 | ALWAYS_SEARCH_USER_PATHS = NO; 202 | CLANG_ANALYZER_NONNULL = YES; 203 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 204 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 205 | CLANG_CXX_LIBRARY = "libc++"; 206 | CLANG_ENABLE_MODULES = YES; 207 | CLANG_ENABLE_OBJC_ARC = YES; 208 | CLANG_ENABLE_OBJC_WEAK = YES; 209 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 210 | CLANG_WARN_BOOL_CONVERSION = YES; 211 | CLANG_WARN_COMMA = YES; 212 | CLANG_WARN_CONSTANT_CONVERSION = YES; 213 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 214 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 215 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 216 | CLANG_WARN_EMPTY_BODY = YES; 217 | CLANG_WARN_ENUM_CONVERSION = YES; 218 | CLANG_WARN_INFINITE_RECURSION = YES; 219 | CLANG_WARN_INT_CONVERSION = YES; 220 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 221 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 222 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 223 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 224 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 225 | CLANG_WARN_STRICT_PROTOTYPES = YES; 226 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 227 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 228 | CLANG_WARN_UNREACHABLE_CODE = YES; 229 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 230 | CODE_SIGN_IDENTITY = "iPhone Developer"; 231 | COPY_PHASE_STRIP = NO; 232 | CURRENT_PROJECT_VERSION = 1; 233 | DEBUG_INFORMATION_FORMAT = dwarf; 234 | ENABLE_STRICT_OBJC_MSGSEND = YES; 235 | ENABLE_TESTABILITY = YES; 236 | GCC_C_LANGUAGE_STANDARD = gnu11; 237 | GCC_DYNAMIC_NO_PIC = NO; 238 | GCC_NO_COMMON_BLOCKS = YES; 239 | GCC_OPTIMIZATION_LEVEL = 0; 240 | GCC_PREPROCESSOR_DEFINITIONS = ( 241 | "DEBUG=1", 242 | "$(inherited)", 243 | ); 244 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 245 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 246 | GCC_WARN_UNDECLARED_SELECTOR = YES; 247 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 248 | GCC_WARN_UNUSED_FUNCTION = YES; 249 | GCC_WARN_UNUSED_VARIABLE = YES; 250 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 251 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 252 | MTL_FAST_MATH = YES; 253 | ONLY_ACTIVE_ARCH = YES; 254 | SDKROOT = iphoneos; 255 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 256 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 257 | VERSIONING_SYSTEM = "apple-generic"; 258 | VERSION_INFO_PREFIX = ""; 259 | }; 260 | name = Debug; 261 | }; 262 | A95052B22251FE9000BFBC53 /* Release */ = { 263 | isa = XCBuildConfiguration; 264 | buildSettings = { 265 | ALWAYS_SEARCH_USER_PATHS = NO; 266 | CLANG_ANALYZER_NONNULL = YES; 267 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 268 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 269 | CLANG_CXX_LIBRARY = "libc++"; 270 | CLANG_ENABLE_MODULES = YES; 271 | CLANG_ENABLE_OBJC_ARC = YES; 272 | CLANG_ENABLE_OBJC_WEAK = YES; 273 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 274 | CLANG_WARN_BOOL_CONVERSION = YES; 275 | CLANG_WARN_COMMA = YES; 276 | CLANG_WARN_CONSTANT_CONVERSION = YES; 277 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 278 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 279 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 280 | CLANG_WARN_EMPTY_BODY = YES; 281 | CLANG_WARN_ENUM_CONVERSION = YES; 282 | CLANG_WARN_INFINITE_RECURSION = YES; 283 | CLANG_WARN_INT_CONVERSION = YES; 284 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 285 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 286 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 287 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 288 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 289 | CLANG_WARN_STRICT_PROTOTYPES = YES; 290 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 291 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 292 | CLANG_WARN_UNREACHABLE_CODE = YES; 293 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 294 | CODE_SIGN_IDENTITY = "iPhone Developer"; 295 | COPY_PHASE_STRIP = NO; 296 | CURRENT_PROJECT_VERSION = 1; 297 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 298 | ENABLE_NS_ASSERTIONS = NO; 299 | ENABLE_STRICT_OBJC_MSGSEND = YES; 300 | GCC_C_LANGUAGE_STANDARD = gnu11; 301 | GCC_NO_COMMON_BLOCKS = YES; 302 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 303 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 304 | GCC_WARN_UNDECLARED_SELECTOR = YES; 305 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 306 | GCC_WARN_UNUSED_FUNCTION = YES; 307 | GCC_WARN_UNUSED_VARIABLE = YES; 308 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 309 | MTL_ENABLE_DEBUG_INFO = NO; 310 | MTL_FAST_MATH = YES; 311 | SDKROOT = iphoneos; 312 | SWIFT_COMPILATION_MODE = wholemodule; 313 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 314 | VALIDATE_PRODUCT = YES; 315 | VERSIONING_SYSTEM = "apple-generic"; 316 | VERSION_INFO_PREFIX = ""; 317 | }; 318 | name = Release; 319 | }; 320 | A95052B42251FE9000BFBC53 /* Debug */ = { 321 | isa = XCBuildConfiguration; 322 | baseConfigurationReference = E6249167321D0F899E89EA65 /* Pods-InsertDyld.debug.xcconfig */; 323 | buildSettings = { 324 | CLANG_ENABLE_MODULES = YES; 325 | CODE_SIGN_IDENTITY = ""; 326 | CODE_SIGN_STYLE = Automatic; 327 | DEFINES_MODULE = YES; 328 | DEVELOPMENT_TEAM = 4W4C99Z87Y; 329 | DYLIB_COMPATIBILITY_VERSION = 1; 330 | DYLIB_CURRENT_VERSION = 1; 331 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 332 | INFOPLIST_FILE = InsertDyld/Info.plist; 333 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 334 | LD_RUNPATH_SEARCH_PATHS = ( 335 | "$(inherited)", 336 | "@executable_path/Frameworks", 337 | "@loader_path/Frameworks", 338 | ); 339 | PRODUCT_BUNDLE_IDENTIFIER = jin.InsertDyld; 340 | PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; 341 | SKIP_INSTALL = YES; 342 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 343 | SWIFT_VERSION = 4.2; 344 | TARGETED_DEVICE_FAMILY = "1,2"; 345 | VALID_ARCHS = arm64; 346 | }; 347 | name = Debug; 348 | }; 349 | A95052B52251FE9000BFBC53 /* Release */ = { 350 | isa = XCBuildConfiguration; 351 | baseConfigurationReference = 0729E6988353829E18A5ADBE /* Pods-InsertDyld.release.xcconfig */; 352 | buildSettings = { 353 | CLANG_ENABLE_MODULES = YES; 354 | CODE_SIGN_IDENTITY = ""; 355 | CODE_SIGN_STYLE = Automatic; 356 | DEFINES_MODULE = YES; 357 | DEVELOPMENT_TEAM = 4W4C99Z87Y; 358 | DYLIB_COMPATIBILITY_VERSION = 1; 359 | DYLIB_CURRENT_VERSION = 1; 360 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 361 | INFOPLIST_FILE = InsertDyld/Info.plist; 362 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 363 | LD_RUNPATH_SEARCH_PATHS = ( 364 | "$(inherited)", 365 | "@executable_path/Frameworks", 366 | "@loader_path/Frameworks", 367 | ); 368 | PRODUCT_BUNDLE_IDENTIFIER = jin.InsertDyld; 369 | PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; 370 | SKIP_INSTALL = YES; 371 | SWIFT_VERSION = 4.2; 372 | TARGETED_DEVICE_FAMILY = "1,2"; 373 | VALID_ARCHS = arm64; 374 | }; 375 | name = Release; 376 | }; 377 | /* End XCBuildConfiguration section */ 378 | 379 | /* Begin XCConfigurationList section */ 380 | A95052A52251FE9000BFBC53 /* Build configuration list for PBXProject "InsertDyld" */ = { 381 | isa = XCConfigurationList; 382 | buildConfigurations = ( 383 | A95052B12251FE9000BFBC53 /* Debug */, 384 | A95052B22251FE9000BFBC53 /* Release */, 385 | ); 386 | defaultConfigurationIsVisible = 0; 387 | defaultConfigurationName = Debug; 388 | }; 389 | A95052B32251FE9000BFBC53 /* Build configuration list for PBXNativeTarget "InsertDyld" */ = { 390 | isa = XCConfigurationList; 391 | buildConfigurations = ( 392 | A95052B42251FE9000BFBC53 /* Debug */, 393 | A95052B52251FE9000BFBC53 /* Release */, 394 | ); 395 | defaultConfigurationIsVisible = 0; 396 | defaultConfigurationName = Debug; 397 | }; 398 | /* End XCConfigurationList section */ 399 | }; 400 | rootObject = A95052A22251FE9000BFBC53 /* Project object */; 401 | } 402 | -------------------------------------------------------------------------------- /Demo/AntiFishHookDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 51; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 7EFE685A87327E9026B35743 /* Pods_AntiFishHookDemo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C21AC4DC82D9A834A6D03DD9 /* Pods_AntiFishHookDemo.framework */; }; 11 | A91D91F42318CA9B00813AD0 /* Abort.swift in Sources */ = {isa = PBXBuildFile; fileRef = A91D91F32318CA9B00813AD0 /* Abort.swift */; }; 12 | A95B34F322CBBAF50078B3D4 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A95B34F222CBBAF50078B3D4 /* AppDelegate.swift */; }; 13 | A95B34F522CBBAF50078B3D4 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A95B34F422CBBAF50078B3D4 /* ViewController.swift */; }; 14 | A95B34F822CBBAF50078B3D4 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A95B34F622CBBAF50078B3D4 /* Main.storyboard */; }; 15 | A95B34FA22CBBAF60078B3D4 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A95B34F922CBBAF60078B3D4 /* Assets.xcassets */; }; 16 | A95B34FD22CBBAF60078B3D4 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A95B34FB22CBBAF60078B3D4 /* LaunchScreen.storyboard */; }; 17 | A95B350D22CBBBB40078B3D4 /* Dlopen.swift in Sources */ = {isa = PBXBuildFile; fileRef = A95B350922CBBBB40078B3D4 /* Dlopen.swift */; }; 18 | A95B350E22CBBBB40078B3D4 /* NSLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = A95B350A22CBBBB40078B3D4 /* NSLog.swift */; }; 19 | A95B350F22CBBBB40078B3D4 /* Dladdr.swift in Sources */ = {isa = PBXBuildFile; fileRef = A95B350B22CBBBB40078B3D4 /* Dladdr.swift */; }; 20 | A95B351022CBBBB40078B3D4 /* Printf.swift in Sources */ = {isa = PBXBuildFile; fileRef = A95B350C22CBBBB40078B3D4 /* Printf.swift */; }; 21 | A95B351322CBBBC30078B3D4 /* PrintfTestHelp.m in Sources */ = {isa = PBXBuildFile; fileRef = A95B351222CBBBC30078B3D4 /* PrintfTestHelp.m */; }; 22 | A9645C3D2583A70E00B10D67 /* InsertDyld.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A9645C3C2583A70E00B10D67 /* InsertDyld.framework */; }; 23 | A9645C3E2583A70E00B10D67 /* InsertDyld.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = A9645C3C2583A70E00B10D67 /* InsertDyld.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 24 | A9645C612584BB2100B10D67 /* Print.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9645C602584BB2100B10D67 /* Print.swift */; }; 25 | /* End PBXBuildFile section */ 26 | 27 | /* Begin PBXCopyFilesBuildPhase section */ 28 | A95B351722CBBC6C0078B3D4 /* Embed Frameworks */ = { 29 | isa = PBXCopyFilesBuildPhase; 30 | buildActionMask = 2147483647; 31 | dstPath = ""; 32 | dstSubfolderSpec = 10; 33 | files = ( 34 | A9645C3E2583A70E00B10D67 /* InsertDyld.framework in Embed Frameworks */, 35 | ); 36 | name = "Embed Frameworks"; 37 | runOnlyForDeploymentPostprocessing = 0; 38 | }; 39 | /* End PBXCopyFilesBuildPhase section */ 40 | 41 | /* Begin PBXFileReference section */ 42 | 6742C61F627160A76D2A78EF /* Pods-AntiFishHookDemo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AntiFishHookDemo.debug.xcconfig"; path = "Target Support Files/Pods-AntiFishHookDemo/Pods-AntiFishHookDemo.debug.xcconfig"; sourceTree = ""; }; 43 | A91D91F32318CA9B00813AD0 /* Abort.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Abort.swift; sourceTree = ""; }; 44 | A95B34EF22CBBAF50078B3D4 /* AntiFishHookDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AntiFishHookDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 45 | A95B34F222CBBAF50078B3D4 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 46 | A95B34F422CBBAF50078B3D4 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 47 | A95B34F722CBBAF50078B3D4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 48 | A95B34F922CBBAF60078B3D4 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 49 | A95B34FC22CBBAF60078B3D4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 50 | A95B34FE22CBBAF60078B3D4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 51 | A95B350522CBBBA00078B3D4 /* AntiFishHookDemo-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "AntiFishHookDemo-Bridging-Header.h"; sourceTree = ""; }; 52 | A95B350922CBBBB40078B3D4 /* Dlopen.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Dlopen.swift; sourceTree = ""; }; 53 | A95B350A22CBBBB40078B3D4 /* NSLog.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSLog.swift; sourceTree = ""; }; 54 | A95B350B22CBBBB40078B3D4 /* Dladdr.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Dladdr.swift; sourceTree = ""; }; 55 | A95B350C22CBBBB40078B3D4 /* Printf.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Printf.swift; sourceTree = ""; }; 56 | A95B351122CBBBC30078B3D4 /* PrintfTestHelp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PrintfTestHelp.h; sourceTree = ""; }; 57 | A95B351222CBBBC30078B3D4 /* PrintfTestHelp.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PrintfTestHelp.m; sourceTree = ""; }; 58 | A9645C3C2583A70E00B10D67 /* InsertDyld.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = InsertDyld.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 59 | A9645C602584BB2100B10D67 /* Print.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Print.swift; sourceTree = ""; }; 60 | B6BCA58A1DD2C3D5AE63D8EF /* Pods-AntiFishHookDemo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AntiFishHookDemo.release.xcconfig"; path = "Target Support Files/Pods-AntiFishHookDemo/Pods-AntiFishHookDemo.release.xcconfig"; sourceTree = ""; }; 61 | C21AC4DC82D9A834A6D03DD9 /* Pods_AntiFishHookDemo.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_AntiFishHookDemo.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 62 | /* End PBXFileReference section */ 63 | 64 | /* Begin PBXFrameworksBuildPhase section */ 65 | A95B34EC22CBBAF50078B3D4 /* Frameworks */ = { 66 | isa = PBXFrameworksBuildPhase; 67 | buildActionMask = 2147483647; 68 | files = ( 69 | A9645C3D2583A70E00B10D67 /* InsertDyld.framework in Frameworks */, 70 | 7EFE685A87327E9026B35743 /* Pods_AntiFishHookDemo.framework in Frameworks */, 71 | ); 72 | runOnlyForDeploymentPostprocessing = 0; 73 | }; 74 | /* End PBXFrameworksBuildPhase section */ 75 | 76 | /* Begin PBXGroup section */ 77 | 1F0FF394B691361333B1BC47 /* Pods */ = { 78 | isa = PBXGroup; 79 | children = ( 80 | 6742C61F627160A76D2A78EF /* Pods-AntiFishHookDemo.debug.xcconfig */, 81 | B6BCA58A1DD2C3D5AE63D8EF /* Pods-AntiFishHookDemo.release.xcconfig */, 82 | ); 83 | path = Pods; 84 | sourceTree = ""; 85 | }; 86 | A95B34E622CBBAF50078B3D4 = { 87 | isa = PBXGroup; 88 | children = ( 89 | A95B34F122CBBAF50078B3D4 /* AntiFishHookDemo */, 90 | A95B34F022CBBAF50078B3D4 /* Products */, 91 | 1F0FF394B691361333B1BC47 /* Pods */, 92 | C397C3335B9650638D35A622 /* Frameworks */, 93 | ); 94 | sourceTree = ""; 95 | }; 96 | A95B34F022CBBAF50078B3D4 /* Products */ = { 97 | isa = PBXGroup; 98 | children = ( 99 | A95B34EF22CBBAF50078B3D4 /* AntiFishHookDemo.app */, 100 | ); 101 | name = Products; 102 | sourceTree = ""; 103 | }; 104 | A95B34F122CBBAF50078B3D4 /* AntiFishHookDemo */ = { 105 | isa = PBXGroup; 106 | children = ( 107 | A95B350422CBBB550078B3D4 /* TestCase */, 108 | A95B34F222CBBAF50078B3D4 /* AppDelegate.swift */, 109 | A95B34F422CBBAF50078B3D4 /* ViewController.swift */, 110 | A95B350522CBBBA00078B3D4 /* AntiFishHookDemo-Bridging-Header.h */, 111 | A95B34F622CBBAF50078B3D4 /* Main.storyboard */, 112 | A95B34F922CBBAF60078B3D4 /* Assets.xcassets */, 113 | A95B34FB22CBBAF60078B3D4 /* LaunchScreen.storyboard */, 114 | A95B34FE22CBBAF60078B3D4 /* Info.plist */, 115 | ); 116 | path = AntiFishHookDemo; 117 | sourceTree = ""; 118 | }; 119 | A95B350422CBBB550078B3D4 /* TestCase */ = { 120 | isa = PBXGroup; 121 | children = ( 122 | A95B351122CBBBC30078B3D4 /* PrintfTestHelp.h */, 123 | A95B351222CBBBC30078B3D4 /* PrintfTestHelp.m */, 124 | A95B350C22CBBBB40078B3D4 /* Printf.swift */, 125 | A95B350B22CBBBB40078B3D4 /* Dladdr.swift */, 126 | A95B350A22CBBBB40078B3D4 /* NSLog.swift */, 127 | A95B350922CBBBB40078B3D4 /* Dlopen.swift */, 128 | A91D91F32318CA9B00813AD0 /* Abort.swift */, 129 | A9645C602584BB2100B10D67 /* Print.swift */, 130 | ); 131 | path = TestCase; 132 | sourceTree = ""; 133 | }; 134 | C397C3335B9650638D35A622 /* Frameworks */ = { 135 | isa = PBXGroup; 136 | children = ( 137 | A9645C3C2583A70E00B10D67 /* InsertDyld.framework */, 138 | C21AC4DC82D9A834A6D03DD9 /* Pods_AntiFishHookDemo.framework */, 139 | ); 140 | name = Frameworks; 141 | sourceTree = ""; 142 | }; 143 | /* End PBXGroup section */ 144 | 145 | /* Begin PBXNativeTarget section */ 146 | A95B34EE22CBBAF50078B3D4 /* AntiFishHookDemo */ = { 147 | isa = PBXNativeTarget; 148 | buildConfigurationList = A95B350122CBBAF60078B3D4 /* Build configuration list for PBXNativeTarget "AntiFishHookDemo" */; 149 | buildPhases = ( 150 | 35C039EF6A47EBE0C65D8636 /* [CP] Check Pods Manifest.lock */, 151 | A95B34EB22CBBAF50078B3D4 /* Sources */, 152 | A95B34EC22CBBAF50078B3D4 /* Frameworks */, 153 | A95B34ED22CBBAF50078B3D4 /* Resources */, 154 | 296909BFF80846C3A906715B /* [CP] Embed Pods Frameworks */, 155 | A95B351722CBBC6C0078B3D4 /* Embed Frameworks */, 156 | ); 157 | buildRules = ( 158 | ); 159 | dependencies = ( 160 | ); 161 | name = AntiFishHookDemo; 162 | productName = AntiFishHookDemo; 163 | productReference = A95B34EF22CBBAF50078B3D4 /* AntiFishHookDemo.app */; 164 | productType = "com.apple.product-type.application"; 165 | }; 166 | /* End PBXNativeTarget section */ 167 | 168 | /* Begin PBXProject section */ 169 | A95B34E722CBBAF50078B3D4 /* Project object */ = { 170 | isa = PBXProject; 171 | attributes = { 172 | LastSwiftUpdateCheck = 1020; 173 | LastUpgradeCheck = 1020; 174 | ORGANIZATIONNAME = jintao; 175 | TargetAttributes = { 176 | A95B34EE22CBBAF50078B3D4 = { 177 | CreatedOnToolsVersion = 10.2.1; 178 | LastSwiftMigration = 1020; 179 | }; 180 | }; 181 | }; 182 | buildConfigurationList = A95B34EA22CBBAF50078B3D4 /* Build configuration list for PBXProject "AntiFishHookDemo" */; 183 | compatibilityVersion = "Xcode 9.3"; 184 | developmentRegion = en; 185 | hasScannedForEncodings = 0; 186 | knownRegions = ( 187 | en, 188 | Base, 189 | ); 190 | mainGroup = A95B34E622CBBAF50078B3D4; 191 | productRefGroup = A95B34F022CBBAF50078B3D4 /* Products */; 192 | projectDirPath = ""; 193 | projectRoot = ""; 194 | targets = ( 195 | A95B34EE22CBBAF50078B3D4 /* AntiFishHookDemo */, 196 | ); 197 | }; 198 | /* End PBXProject section */ 199 | 200 | /* Begin PBXResourcesBuildPhase section */ 201 | A95B34ED22CBBAF50078B3D4 /* Resources */ = { 202 | isa = PBXResourcesBuildPhase; 203 | buildActionMask = 2147483647; 204 | files = ( 205 | A95B34FD22CBBAF60078B3D4 /* LaunchScreen.storyboard in Resources */, 206 | A95B34FA22CBBAF60078B3D4 /* Assets.xcassets in Resources */, 207 | A95B34F822CBBAF50078B3D4 /* Main.storyboard in Resources */, 208 | ); 209 | runOnlyForDeploymentPostprocessing = 0; 210 | }; 211 | /* End PBXResourcesBuildPhase section */ 212 | 213 | /* Begin PBXShellScriptBuildPhase section */ 214 | 296909BFF80846C3A906715B /* [CP] Embed Pods Frameworks */ = { 215 | isa = PBXShellScriptBuildPhase; 216 | buildActionMask = 2147483647; 217 | files = ( 218 | ); 219 | inputFileListPaths = ( 220 | "${PODS_ROOT}/Target Support Files/Pods-AntiFishHookDemo/Pods-AntiFishHookDemo-frameworks-${CONFIGURATION}-input-files.xcfilelist", 221 | ); 222 | name = "[CP] Embed Pods Frameworks"; 223 | outputFileListPaths = ( 224 | "${PODS_ROOT}/Target Support Files/Pods-AntiFishHookDemo/Pods-AntiFishHookDemo-frameworks-${CONFIGURATION}-output-files.xcfilelist", 225 | ); 226 | runOnlyForDeploymentPostprocessing = 0; 227 | shellPath = /bin/sh; 228 | shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-AntiFishHookDemo/Pods-AntiFishHookDemo-frameworks.sh\"\n"; 229 | showEnvVarsInLog = 0; 230 | }; 231 | 35C039EF6A47EBE0C65D8636 /* [CP] Check Pods Manifest.lock */ = { 232 | isa = PBXShellScriptBuildPhase; 233 | buildActionMask = 2147483647; 234 | files = ( 235 | ); 236 | inputFileListPaths = ( 237 | ); 238 | inputPaths = ( 239 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock", 240 | "${PODS_ROOT}/Manifest.lock", 241 | ); 242 | name = "[CP] Check Pods Manifest.lock"; 243 | outputFileListPaths = ( 244 | ); 245 | outputPaths = ( 246 | "$(DERIVED_FILE_DIR)/Pods-AntiFishHookDemo-checkManifestLockResult.txt", 247 | ); 248 | runOnlyForDeploymentPostprocessing = 0; 249 | shellPath = /bin/sh; 250 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; 251 | showEnvVarsInLog = 0; 252 | }; 253 | /* End PBXShellScriptBuildPhase section */ 254 | 255 | /* Begin PBXSourcesBuildPhase section */ 256 | A95B34EB22CBBAF50078B3D4 /* Sources */ = { 257 | isa = PBXSourcesBuildPhase; 258 | buildActionMask = 2147483647; 259 | files = ( 260 | A95B351322CBBBC30078B3D4 /* PrintfTestHelp.m in Sources */, 261 | A95B351022CBBBB40078B3D4 /* Printf.swift in Sources */, 262 | A95B350D22CBBBB40078B3D4 /* Dlopen.swift in Sources */, 263 | A95B350F22CBBBB40078B3D4 /* Dladdr.swift in Sources */, 264 | A95B350E22CBBBB40078B3D4 /* NSLog.swift in Sources */, 265 | A95B34F522CBBAF50078B3D4 /* ViewController.swift in Sources */, 266 | A91D91F42318CA9B00813AD0 /* Abort.swift in Sources */, 267 | A9645C612584BB2100B10D67 /* Print.swift in Sources */, 268 | A95B34F322CBBAF50078B3D4 /* AppDelegate.swift in Sources */, 269 | ); 270 | runOnlyForDeploymentPostprocessing = 0; 271 | }; 272 | /* End PBXSourcesBuildPhase section */ 273 | 274 | /* Begin PBXVariantGroup section */ 275 | A95B34F622CBBAF50078B3D4 /* Main.storyboard */ = { 276 | isa = PBXVariantGroup; 277 | children = ( 278 | A95B34F722CBBAF50078B3D4 /* Base */, 279 | ); 280 | name = Main.storyboard; 281 | sourceTree = ""; 282 | }; 283 | A95B34FB22CBBAF60078B3D4 /* LaunchScreen.storyboard */ = { 284 | isa = PBXVariantGroup; 285 | children = ( 286 | A95B34FC22CBBAF60078B3D4 /* Base */, 287 | ); 288 | name = LaunchScreen.storyboard; 289 | sourceTree = ""; 290 | }; 291 | /* End PBXVariantGroup section */ 292 | 293 | /* Begin XCBuildConfiguration section */ 294 | A95B34FF22CBBAF60078B3D4 /* Debug */ = { 295 | isa = XCBuildConfiguration; 296 | buildSettings = { 297 | ALWAYS_SEARCH_USER_PATHS = NO; 298 | CLANG_ANALYZER_NONNULL = YES; 299 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 300 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 301 | CLANG_CXX_LIBRARY = "libc++"; 302 | CLANG_ENABLE_MODULES = YES; 303 | CLANG_ENABLE_OBJC_ARC = YES; 304 | CLANG_ENABLE_OBJC_WEAK = YES; 305 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 306 | CLANG_WARN_BOOL_CONVERSION = YES; 307 | CLANG_WARN_COMMA = YES; 308 | CLANG_WARN_CONSTANT_CONVERSION = YES; 309 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 310 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 311 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 312 | CLANG_WARN_EMPTY_BODY = YES; 313 | CLANG_WARN_ENUM_CONVERSION = YES; 314 | CLANG_WARN_INFINITE_RECURSION = YES; 315 | CLANG_WARN_INT_CONVERSION = YES; 316 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 317 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 318 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 319 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 320 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 321 | CLANG_WARN_STRICT_PROTOTYPES = YES; 322 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 323 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 324 | CLANG_WARN_UNREACHABLE_CODE = YES; 325 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 326 | CODE_SIGN_IDENTITY = "iPhone Developer"; 327 | COPY_PHASE_STRIP = NO; 328 | DEBUG_INFORMATION_FORMAT = dwarf; 329 | ENABLE_STRICT_OBJC_MSGSEND = YES; 330 | ENABLE_TESTABILITY = YES; 331 | GCC_C_LANGUAGE_STANDARD = gnu11; 332 | GCC_DYNAMIC_NO_PIC = NO; 333 | GCC_NO_COMMON_BLOCKS = YES; 334 | GCC_OPTIMIZATION_LEVEL = 0; 335 | GCC_PREPROCESSOR_DEFINITIONS = ( 336 | "DEBUG=1", 337 | "$(inherited)", 338 | ); 339 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 340 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 341 | GCC_WARN_UNDECLARED_SELECTOR = YES; 342 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 343 | GCC_WARN_UNUSED_FUNCTION = YES; 344 | GCC_WARN_UNUSED_VARIABLE = YES; 345 | IPHONEOS_DEPLOYMENT_TARGET = 12.2; 346 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 347 | MTL_FAST_MATH = YES; 348 | ONLY_ACTIVE_ARCH = YES; 349 | SDKROOT = iphoneos; 350 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 351 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 352 | }; 353 | name = Debug; 354 | }; 355 | A95B350022CBBAF60078B3D4 /* Release */ = { 356 | isa = XCBuildConfiguration; 357 | buildSettings = { 358 | ALWAYS_SEARCH_USER_PATHS = NO; 359 | CLANG_ANALYZER_NONNULL = YES; 360 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 361 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 362 | CLANG_CXX_LIBRARY = "libc++"; 363 | CLANG_ENABLE_MODULES = YES; 364 | CLANG_ENABLE_OBJC_ARC = YES; 365 | CLANG_ENABLE_OBJC_WEAK = YES; 366 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 367 | CLANG_WARN_BOOL_CONVERSION = YES; 368 | CLANG_WARN_COMMA = YES; 369 | CLANG_WARN_CONSTANT_CONVERSION = YES; 370 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 371 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 372 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 373 | CLANG_WARN_EMPTY_BODY = YES; 374 | CLANG_WARN_ENUM_CONVERSION = YES; 375 | CLANG_WARN_INFINITE_RECURSION = YES; 376 | CLANG_WARN_INT_CONVERSION = YES; 377 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 378 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 379 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 380 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 381 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 382 | CLANG_WARN_STRICT_PROTOTYPES = YES; 383 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 384 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 385 | CLANG_WARN_UNREACHABLE_CODE = YES; 386 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 387 | CODE_SIGN_IDENTITY = "iPhone Developer"; 388 | COPY_PHASE_STRIP = NO; 389 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 390 | ENABLE_NS_ASSERTIONS = NO; 391 | ENABLE_STRICT_OBJC_MSGSEND = YES; 392 | GCC_C_LANGUAGE_STANDARD = gnu11; 393 | GCC_NO_COMMON_BLOCKS = YES; 394 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 395 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 396 | GCC_WARN_UNDECLARED_SELECTOR = YES; 397 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 398 | GCC_WARN_UNUSED_FUNCTION = YES; 399 | GCC_WARN_UNUSED_VARIABLE = YES; 400 | IPHONEOS_DEPLOYMENT_TARGET = 12.2; 401 | MTL_ENABLE_DEBUG_INFO = NO; 402 | MTL_FAST_MATH = YES; 403 | SDKROOT = iphoneos; 404 | SWIFT_COMPILATION_MODE = wholemodule; 405 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 406 | VALIDATE_PRODUCT = YES; 407 | }; 408 | name = Release; 409 | }; 410 | A95B350222CBBAF60078B3D4 /* Debug */ = { 411 | isa = XCBuildConfiguration; 412 | baseConfigurationReference = 6742C61F627160A76D2A78EF /* Pods-AntiFishHookDemo.debug.xcconfig */; 413 | buildSettings = { 414 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 415 | CLANG_ENABLE_MODULES = YES; 416 | CODE_SIGN_STYLE = Automatic; 417 | DEVELOPMENT_TEAM = 4W4C99Z87Y; 418 | INFOPLIST_FILE = AntiFishHookDemo/Info.plist; 419 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 420 | LD_RUNPATH_SEARCH_PATHS = ( 421 | "$(inherited)", 422 | "@executable_path/Frameworks", 423 | ); 424 | PRODUCT_BUNDLE_IDENTIFIER = com.AntiFishHookDemo; 425 | PRODUCT_NAME = "$(TARGET_NAME)"; 426 | SWIFT_OBJC_BRIDGING_HEADER = "AntiFishHookDemo/AntiFishHookDemo-Bridging-Header.h"; 427 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 428 | SWIFT_VERSION = 5.0; 429 | TARGETED_DEVICE_FAMILY = "1,2"; 430 | VALID_ARCHS = arm64; 431 | }; 432 | name = Debug; 433 | }; 434 | A95B350322CBBAF60078B3D4 /* Release */ = { 435 | isa = XCBuildConfiguration; 436 | baseConfigurationReference = B6BCA58A1DD2C3D5AE63D8EF /* Pods-AntiFishHookDemo.release.xcconfig */; 437 | buildSettings = { 438 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 439 | CLANG_ENABLE_MODULES = YES; 440 | CODE_SIGN_STYLE = Automatic; 441 | DEVELOPMENT_TEAM = 4W4C99Z87Y; 442 | INFOPLIST_FILE = AntiFishHookDemo/Info.plist; 443 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 444 | LD_RUNPATH_SEARCH_PATHS = ( 445 | "$(inherited)", 446 | "@executable_path/Frameworks", 447 | ); 448 | PRODUCT_BUNDLE_IDENTIFIER = com.AntiFishHookDemo; 449 | PRODUCT_NAME = "$(TARGET_NAME)"; 450 | SWIFT_OBJC_BRIDGING_HEADER = "AntiFishHookDemo/AntiFishHookDemo-Bridging-Header.h"; 451 | SWIFT_VERSION = 5.0; 452 | TARGETED_DEVICE_FAMILY = "1,2"; 453 | VALID_ARCHS = arm64; 454 | }; 455 | name = Release; 456 | }; 457 | /* End XCBuildConfiguration section */ 458 | 459 | /* Begin XCConfigurationList section */ 460 | A95B34EA22CBBAF50078B3D4 /* Build configuration list for PBXProject "AntiFishHookDemo" */ = { 461 | isa = XCConfigurationList; 462 | buildConfigurations = ( 463 | A95B34FF22CBBAF60078B3D4 /* Debug */, 464 | A95B350022CBBAF60078B3D4 /* Release */, 465 | ); 466 | defaultConfigurationIsVisible = 0; 467 | defaultConfigurationName = Release; 468 | }; 469 | A95B350122CBBAF60078B3D4 /* Build configuration list for PBXNativeTarget "AntiFishHookDemo" */ = { 470 | isa = XCConfigurationList; 471 | buildConfigurations = ( 472 | A95B350222CBBAF60078B3D4 /* Debug */, 473 | A95B350322CBBAF60078B3D4 /* Release */, 474 | ); 475 | defaultConfigurationIsVisible = 0; 476 | defaultConfigurationName = Release; 477 | }; 478 | /* End XCConfigurationList section */ 479 | }; 480 | rootObject = A95B34E722CBBAF50078B3D4 /* Project object */; 481 | } 482 | -------------------------------------------------------------------------------- /Source/AntiFishHook.swift: -------------------------------------------------------------------------------- 1 | // 2 | // FishHookProtection.swift 3 | // FishHookProtect 4 | // 5 | // Created by jintao on 2019/3/25. 6 | // Copyright © 2019 jintao. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import MachO 11 | 12 | #if arch(arm64) 13 | @inline(__always) 14 | private func readUleb128(ptr: inout UnsafeMutablePointer, end: UnsafeMutablePointer) -> UInt64 { 15 | var result: UInt64 = 0 16 | var bit = 0 17 | var readNext = true 18 | 19 | repeat { 20 | if ptr == end { 21 | assert(false, "malformed uleb128") 22 | } 23 | let slice = UInt64(ptr.pointee & 0x7f) 24 | if bit > 63 { 25 | assert(false, "uleb128 too big for uint64") 26 | } else { 27 | result |= (slice << bit) 28 | bit += 7 29 | } 30 | readNext = ((ptr.pointee & 0x80) >> 7) == 1 31 | ptr += 1 32 | } while (readNext) 33 | return result 34 | } 35 | 36 | @inline(__always) 37 | private func readSleb128(ptr: inout UnsafeMutablePointer, end: UnsafeMutablePointer) -> Int64 { 38 | var result: Int64 = 0 39 | var bit: Int = 0 40 | var byte: UInt8 41 | 42 | repeat { 43 | if (ptr == end) { 44 | assert(false, "malformed sleb128") 45 | } 46 | byte = ptr.pointee 47 | result |= (((Int64)(byte & 0x7f)) << bit) 48 | bit += 7 49 | ptr += 1 50 | } while (byte & 0x80) == 1 51 | 52 | // sign extend negative numbers 53 | if ( (byte & 0x40) != 0 ) { 54 | result |= -1 << bit 55 | } 56 | return result 57 | } 58 | 59 | public class FishHookChecker { 60 | @inline(__always) 61 | static public func denyFishHook(_ symbol: String) { 62 | var symbolAddress: UnsafeMutableRawPointer? 63 | 64 | for imgIndex in 0..<_dyld_image_count() { 65 | if let image = _dyld_get_image_header(imgIndex) { 66 | if symbolAddress == nil { 67 | _ = SymbolFound.lookSymbol(symbol, at: image, imageSlide: _dyld_get_image_vmaddr_slide(imgIndex), symbolAddress: &symbolAddress) 68 | } 69 | if let symbolPointer = symbolAddress { 70 | var oldMethod: UnsafeMutableRawPointer? 71 | FishHook.replaceSymbol(symbol, at: image, imageSlide: _dyld_get_image_vmaddr_slide(imgIndex), newMethod: symbolPointer, oldMethod: &oldMethod) 72 | } 73 | } 74 | } 75 | } 76 | 77 | @inline(__always) 78 | static public func denyFishHook(_ symbol: String, at image: UnsafePointer, imageSlide slide: Int) { 79 | var symbolAddress: UnsafeMutableRawPointer? 80 | 81 | if SymbolFound.lookSymbol(symbol, at: image, imageSlide: slide, symbolAddress: &symbolAddress), let symbolPointer = symbolAddress { 82 | var oldMethod: UnsafeMutableRawPointer? 83 | FishHook.replaceSymbol(symbol, at: image, imageSlide: slide, newMethod: symbolPointer, oldMethod: &oldMethod) 84 | } 85 | } 86 | } 87 | 88 | // MARK: - SymbolFound 89 | internal class SymbolFound { 90 | static private let BindTypeThreadedRebase = 102 91 | 92 | @inline(__always) 93 | static func lookSymbol(_ symbol: String, at image: UnsafePointer, imageSlide slide: Int, symbolAddress: inout UnsafeMutableRawPointer?) -> Bool { 94 | // target cmd 95 | var linkeditCmd: UnsafeMutablePointer! 96 | var dyldInfoCmd: UnsafeMutablePointer! 97 | var allLoadDylds = [String]() 98 | 99 | guard var curCmdPointer = UnsafeMutableRawPointer(bitPattern: UInt(bitPattern: image)+UInt(MemoryLayout.size)) else { 100 | return false 101 | } 102 | // all cmd 103 | for _ in 0.. 0) { 134 | if let lazyBindInfoCmd = UnsafeMutablePointer(bitPattern: UInt(linkeditBase + UInt64(dyldInfoCmd.pointee.lazy_bind_off))), 135 | lookLazyBindSymbol(symbol, symbolAddr: &symbolAddress, lazyBindInfoCmd: lazyBindInfoCmd, lazyBindInfoSize: lazyBindSize, allLoadDylds: allLoadDylds) { 136 | return true 137 | } 138 | } 139 | 140 | // look by NonLazyBindInfo 141 | let bindSize = Int(dyldInfoCmd.pointee.bind_size) 142 | if (bindSize > 0) { 143 | if let bindCmd = UnsafeMutablePointer(bitPattern: UInt(linkeditBase + UInt64(dyldInfoCmd.pointee.bind_off))), 144 | lookBindSymbol(symbol, symbolAddr: &symbolAddress, bindInfoCmd: bindCmd, bindInfoSize: bindSize, allLoadDylds: allLoadDylds) { 145 | return true 146 | } 147 | } 148 | 149 | return false 150 | } 151 | 152 | // LazySymbolBindInfo 153 | @inline(__always) 154 | private static func lookLazyBindSymbol(_ symbol: String, symbolAddr: inout UnsafeMutableRawPointer?, lazyBindInfoCmd: UnsafeMutablePointer, lazyBindInfoSize: Int, allLoadDylds: [String]) -> Bool { 155 | var ptr = lazyBindInfoCmd 156 | let lazyBindingInfoEnd = lazyBindInfoCmd.advanced(by: Int(lazyBindInfoSize)) 157 | var ordinal: Int = -1 158 | var foundSymbol = false 159 | var addend = 0 160 | var type: Int32 = 0 161 | 162 | Label: while ptr < lazyBindingInfoEnd { 163 | let immediate = Int32(ptr.pointee) & BIND_IMMEDIATE_MASK 164 | let opcode = Int32(ptr.pointee) & BIND_OPCODE_MASK 165 | ptr += 1 166 | 167 | switch opcode { 168 | case BIND_OPCODE_DONE: 169 | continue 170 | // ORDINAL DYLIB 171 | case BIND_OPCODE_SET_DYLIB_ORDINAL_IMM: 172 | ordinal = Int(immediate) 173 | case BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB: 174 | ordinal = Int(readUleb128(ptr: &ptr, end: lazyBindingInfoEnd)) 175 | case BIND_OPCODE_SET_DYLIB_SPECIAL_IMM: 176 | if immediate == 0 { 177 | ordinal = 0 178 | } else { 179 | ordinal = Int(BIND_OPCODE_MASK | immediate) 180 | } 181 | // symbol 182 | case BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM: 183 | let symbolName = String(cString: ptr + 1) 184 | if (symbolName == symbol) { 185 | foundSymbol = true 186 | } 187 | while ptr.pointee != 0 { 188 | ptr += 1 189 | } 190 | ptr += 1 // '00' 191 | case BIND_OPCODE_SET_TYPE_IMM: 192 | type = immediate 193 | continue 194 | // sleb 195 | case BIND_OPCODE_SET_ADDEND_SLEB: 196 | addend = Int(readSleb128(ptr: &ptr, end: lazyBindingInfoEnd)) 197 | // uleb 198 | case BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB, BIND_OPCODE_ADD_ADDR_ULEB: 199 | _ = readUleb128(ptr: &ptr, end: lazyBindingInfoEnd) 200 | // bind action 201 | case BIND_OPCODE_DO_BIND: 202 | if (foundSymbol) { 203 | break Label 204 | } else { 205 | continue 206 | } 207 | default: 208 | assert(false, "bad lazy bind opcode") 209 | return false 210 | } 211 | } 212 | 213 | assert(ordinal <= allLoadDylds.count) 214 | 215 | if (foundSymbol && ordinal >= 0 && allLoadDylds.count > 0), ordinal <= allLoadDylds.count, type != BindTypeThreadedRebase { 216 | let imageName = allLoadDylds[ordinal-1] 217 | var tmpSymbolAddress: UnsafeMutableRawPointer? 218 | if lookExportedSymbol(symbol, exportImageName: imageName, symbolAddress: &tmpSymbolAddress), let symbolPointer = tmpSymbolAddress { 219 | symbolAddr = symbolPointer + addend 220 | return true 221 | } 222 | } 223 | 224 | return false 225 | } 226 | 227 | // NonLazySymbolBindInfo 228 | @inline(__always) 229 | private static func lookBindSymbol(_ symbol: String, symbolAddr: inout UnsafeMutableRawPointer?, bindInfoCmd: UnsafeMutablePointer, bindInfoSize: Int, allLoadDylds: [String]) -> Bool { 230 | var ptr = bindInfoCmd 231 | let bindingInfoEnd = bindInfoCmd.advanced(by: Int(bindInfoSize)) 232 | var ordinal: Int = -1 233 | var foundSymbol = false 234 | var addend = 0 235 | var type: Int32 = 0 236 | 237 | Label: while ptr < bindingInfoEnd { 238 | let immediate = Int32(ptr.pointee) & BIND_IMMEDIATE_MASK 239 | let opcode = Int32(ptr.pointee) & BIND_OPCODE_MASK 240 | ptr += 1 241 | 242 | switch opcode { 243 | case BIND_OPCODE_DONE: 244 | break Label 245 | // ORDINAL DYLIB 246 | case BIND_OPCODE_SET_DYLIB_ORDINAL_IMM: 247 | ordinal = Int(immediate) 248 | case BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB: 249 | ordinal = Int(readUleb128(ptr: &ptr, end: bindingInfoEnd)) 250 | case BIND_OPCODE_SET_DYLIB_SPECIAL_IMM: 251 | if immediate == 0 { 252 | ordinal = 0 253 | } else { 254 | ordinal = Int(Int8(BIND_OPCODE_MASK | immediate)) 255 | } 256 | // symbol 257 | case BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM: 258 | let symbolName = String(cString: ptr + 1) 259 | if (symbolName == symbol) { 260 | foundSymbol = true 261 | } 262 | while ptr.pointee != 0 { 263 | ptr += 1 264 | } 265 | ptr += 1 // '00' 266 | case BIND_OPCODE_SET_TYPE_IMM: 267 | type = immediate 268 | continue 269 | // sleb 270 | case BIND_OPCODE_SET_ADDEND_SLEB: 271 | addend = Int(readSleb128(ptr: &ptr, end: bindingInfoEnd)) 272 | // uleb 273 | case BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB, BIND_OPCODE_ADD_ADDR_ULEB: 274 | _ = readUleb128(ptr: &ptr, end: bindingInfoEnd) 275 | // do bind action 276 | case BIND_OPCODE_DO_BIND, BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED: 277 | if (foundSymbol) { 278 | break Label 279 | } 280 | case BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB: 281 | if (foundSymbol) { 282 | break Label 283 | } else { 284 | _ = readUleb128(ptr: &ptr, end: bindingInfoEnd) 285 | } 286 | case BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB: 287 | if (foundSymbol) { 288 | break Label 289 | } else { 290 | _ = readUleb128(ptr: &ptr, end: bindingInfoEnd) // count 291 | _ = readUleb128(ptr: &ptr, end: bindingInfoEnd) // skip 292 | } 293 | case BIND_OPCODE_THREADED: 294 | switch immediate { 295 | case BIND_SUBOPCODE_THREADED_SET_BIND_ORDINAL_TABLE_SIZE_ULEB: 296 | _ = readUleb128(ptr: &ptr, end: bindingInfoEnd) 297 | case BIND_SUBOPCODE_THREADED_APPLY: 298 | if (foundSymbol) { 299 | // ImageLoaderMachO::bindLocation case BIND_TYPE_THREADED_REBASE 300 | assert(false, "maybe bind_type is BIND_TYPE_THREADED_REBASE, don't handle") 301 | return false 302 | } 303 | continue Label 304 | default: 305 | assert(false, "bad bind subopcode") 306 | return false 307 | } 308 | default: 309 | assert(false, "bad bind opcode") 310 | return false 311 | } 312 | } 313 | 314 | assert(ordinal <= allLoadDylds.count) 315 | if (foundSymbol && ordinal >= 0 && allLoadDylds.count > 0), ordinal <= allLoadDylds.count, type != BindTypeThreadedRebase { 316 | let imageName = allLoadDylds[ordinal-1] 317 | var tmpSymbolAddress: UnsafeMutableRawPointer? 318 | if lookExportedSymbol(symbol, exportImageName: imageName, symbolAddress: &tmpSymbolAddress), let symbolPointer = tmpSymbolAddress { 319 | symbolAddr = symbolPointer + addend 320 | return true 321 | } 322 | } 323 | 324 | return false 325 | } 326 | 327 | // ExportSymbol 328 | @inline(__always) 329 | private static func lookExportedSymbol(_ symbol: String, exportImageName: String, symbolAddress: inout UnsafeMutableRawPointer?) -> Bool { 330 | var rpathImage: String? 331 | // @rpath 332 | if (exportImageName.contains("@rpath")) { 333 | rpathImage = exportImageName.components(separatedBy: "/").last 334 | } 335 | 336 | for index in 0..<_dyld_image_count() { 337 | // imageName 338 | let currentImageName = String(cString: _dyld_get_image_name(index)) 339 | if let tmpRpathImage = rpathImage { 340 | if (!currentImageName.contains(tmpRpathImage)) { 341 | continue 342 | } 343 | } else if (String(cString: _dyld_get_image_name(index)) != exportImageName) { 344 | continue 345 | } 346 | 347 | if let pointer = _lookExportedSymbol(symbol, image: _dyld_get_image_header(index), imageSlide: _dyld_get_image_vmaddr_slide(index)) { 348 | // found 349 | symbolAddress = UnsafeMutableRawPointer(mutating: pointer) 350 | return true 351 | } else { 352 | // not found, look at ReExport dylibs 353 | var allReExportDylibs = [String]() 354 | 355 | if let currentImage = _dyld_get_image_header(index), 356 | var curCmdPointer = UnsafeMutableRawPointer(bitPattern: UInt(bitPattern: currentImage)+UInt(MemoryLayout.size)) { 357 | 358 | for _ in 0.., imageSlide slide: Int) -> UnsafeMutableRawPointer? { 387 | // target cmd 388 | var linkeditCmd: UnsafeMutablePointer! 389 | var dyldInfoCmd: UnsafeMutablePointer! 390 | var exportCmd: UnsafeMutablePointer! 391 | 392 | guard var curCmdPointer = UnsafeMutableRawPointer(bitPattern: UInt(bitPattern: image)+UInt(MemoryLayout.size)) else { 393 | return nil 394 | } 395 | // cmd 396 | for _ in 0.. UnsafeMutableRawPointer in 438 | let machO = image.withMemoryRebound(to: Int8.self, capacity: 1, { $0 }) 439 | let symbolAddress = machO.advanced(by: Int(readUleb128(ptr: &symbolLocation, end: end))) 440 | return UnsafeMutableRawPointer(mutating: symbolAddress) 441 | } 442 | 443 | switch flags & UInt64(EXPORT_SYMBOL_FLAGS_KIND_MASK) { 444 | case UInt64(EXPORT_SYMBOL_FLAGS_KIND_REGULAR): 445 | // runResolver is false by bind or lazyBind 446 | return returnSymbolAddress() 447 | case UInt64(EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL): 448 | if (flags & UInt64(EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER) != 0) { 449 | return nil 450 | } 451 | return returnSymbolAddress() 452 | case UInt64(EXPORT_SYMBOL_FLAGS_KIND_ABSOLUTE): 453 | if (flags & UInt64(EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER) != 0) { 454 | return nil 455 | } 456 | return UnsafeMutableRawPointer(bitPattern: UInt(readUleb128(ptr: &symbolLocation, end: end))) 457 | default: 458 | break 459 | } 460 | } 461 | 462 | return nil 463 | } 464 | 465 | // ExportSymbol 466 | @inline(__always) 467 | static private func lookExportedSymbolByTrieWalk(targetSymbol: String, start: UnsafeMutablePointer, end: UnsafeMutablePointer, currentLocation location: UnsafeMutablePointer, currentSymbol: String) -> UnsafeMutablePointer? { 468 | var ptr = location 469 | 470 | while ptr <= end { 471 | // terminalSize 472 | var terminalSize = UInt64(ptr.pointee) 473 | ptr += 1 474 | if terminalSize > 127 { 475 | ptr -= 1 476 | terminalSize = readUleb128(ptr: &ptr, end: end) 477 | } 478 | if terminalSize != 0 { 479 | return currentSymbol == targetSymbol ? ptr : nil 480 | } 481 | 482 | // children 483 | let children = ptr.advanced(by: Int(terminalSize)) 484 | if children >= end { 485 | // end 486 | return nil 487 | } 488 | let childrenCount = children.pointee 489 | ptr = children + 1 490 | 491 | // nodes 492 | for _ in 0..