objective-c-runtime :利用运行时特性,对保护属性的修改和获取 &XPC

前言

http://wiki.jikexueyuan.com/p...
objective-c-runtimehtml

<script async class="speakerdeck-embed" data-id="4f54dc912b27ce002100de53" data-ratio="1.33333333333333" src="//speakerdeck.com/assets/embed.js"></script>
  • XPC

https://objccn.io/issue-14-4/
https://thecyberwire.com/even...ios

devzkndeMacBook-Pro:Versions devzkn$  find /System/Library/Frameworks -name \*.xpc
/System/Library/Frameworks/Automator.framework/Versions/A/XPCServices/com.apple.automator.runner.xpc
/System/Library/Frameworks/SafariServices.framework/Versions/A/XPCServices/com.apple.SafariServices.ExtensionHelper.xpc
/System/Library/Frameworks/SafariServices.framework/Versions/A/XPCServices/com.apple.SafariServices.xpc
/System/Library/Frameworks/Metal.framework/Versions/A/XPCServices/MTLCompilerService.xpc
/System/Library/Frameworks/Quartz.framework/Versions/A/Frameworks/PDFKit.framework/Versions/A/XPCServices/com.apple.PDFKit.PDFFileRefsValidator.xpc
/System/Library/Frameworks/Quartz.framework/Versions/A/Frameworks/PDFKit.framework/Versions/A/XPCServices/com.apple.PDFKit.PDFFileRefsValidator.xpc/Contents/XPCServices/com.apple.PDFKit.PDFFileRefsExtractor.xpc
/System/Library/Frameworks/Quartz.framework/Versions/A/Frameworks/QuickLookUI.framework/Versions/A/XPCServices/QuickLookUIService.xpc
/System/Library/Frameworks/Quartz.framework/Versions/A/Frameworks/ImageKit.framework/Versions/A/XPCServices/com.apple.ImageKit.RecentPictureService.xpc
/System/Library/Frameworks/CoreMediaIO.framework/Versions/A/XPCServices/com.apple.cmio.registerassistantservice.xpc
/System/Library/Frameworks/PCSC.framework/Versions/A/XPCServices/com.apple.ctkpcscd.xpc
/System/Library/Frameworks/PreferencePanes.framework/Versions/A/XPCServices/com.apple.Localization.SetDefaultsService.xpc
/System/Library/Frameworks/PreferencePanes.framework/Versions/A/XPCServices/cacheAssistant.xpc
/System/Library/Frameworks/MediaToolbox.framework/Versions/A/XPCServices/MTPluginFormatReader.xpc
/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/HIServices.framework/Versions/A/XPCServices/com.apple.hiservices-xpcservice.xpc
/System/Library/Frameworks/IOKit.framework/Versions/A/XPCServices/ioserviceauthorized.xpc
/System/Library/Frameworks/IOKit.framework/Versions/A/XPCServices/IOServiceAuthorizeAgent.xpc
/System/Library/Frameworks/Security.framework/Versions/A/XPCServices/XPCKeychainSandboxCheck.xpc
/System/Library/Frameworks/Security.framework/Versions/A/XPCServices/authd.xpc
/System/Library/Frameworks/Security.framework/Versions/A/XPCServices/com.apple.CodeSigningHelper.xpc
/System/Library/Frameworks/Security.framework/Versions/A/XPCServices/XPCTimeStampingService.xpc
/System/Library/Frameworks/MediaLibrary.framework/Versions/A/XPCServices/com.apple.MediaLibraryService.xpc
/System/Library/Frameworks/CoreMedia.framework/Versions/A/XPCServices/com.apple.CMValidateMovieDataReferenceService.xpc
/System/Library/Frameworks/ColorSync.framework/Versions/A/XPCServices/com.apple.ColorSyncXPCAgent.xpc
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/DictionaryServices.framework/Versions/A/XPCServices/com.apple.DictionaryServiceHelper.xpc
/System/Library/Frameworks/WebKit.framework/Versions/A/XPCServices/com.apple.WebKit.Networking.xpc
/System/Library/Frameworks/WebKit.framework/Versions/A/XPCServices/com.apple.WebKit.Databases.xpc

利用运行时API 进行属性的获取和修改

  • 修改属性
Ivar m_searchBar = class_getInstanceVariable(objc_getClass("FindContactSearchViewCellInfo"), "m_searchBar");
    object_setIvar(cellInfo, m_searchBar, bar);
  • 获取属性
Ivar ivardata_inputEncData = class_getInstanceVariable(objc_getClass("TenpayPasswordCtrl"), "_inputEncData");
    NSMutableArray  *_inputEncData = object_getIvar(m_textField, ivardata_inputEncData);

利用运行时特性,对保护属性的修改和获取git

Objective-C运行时定义了几种重要的类型。

  • Class:定义Objective-C类
  • Ivar:定义对象的实例变量,包括类型和名字。
  • Protocol:定义正式协议。
  • objc_property_t:定义属性。叫这个名字多是为了防止和Objective-C 1.0中的用户类型冲突,那时候尚未属性。
  • Method:定义对象方法或类方法。这个类型提供了方法的名字(就是选择器)、参数数量和类型,以及返回值(这些信息合起来称为方法的签名),还有一个指向代码的函数指针(也就是方法的实现)。
  • SEL:定义选择器。选择器是方法名的惟一标识符。
  • IMP:定义方法实现。这只是一个指向某个函数的指针,该函数接受一个对象、一个选择器和一个可变长参数列表(varargs),返回一个对象

操做保护的属性

Ivar m_arrVerifyContactWrap = class_getInstanceVariable(objc_getClass("CContactVerifyLogic"), "m_arrVerifyContactWrap");
                object_setIvar(logic, m_arrVerifyContactWrap, @[wrap]);
Ivar ivar = class_getInstanceVariable(objc_getClass("MMNewSessionMgr"), "m_arrSession");
        m_arrSession = object_getIvar(sessionManager, ivar);

参考文章

https://github.com/facebook/f...
monitoring ivar changes in Objective-C, specially directly ivar accessgithub

codesourse/BigBang
qhd/ANYMethodLogobjective-c

视奸一个类的ivar改变(配合BigBang/ANYMethodLog口味更佳)shell

https://github.com/zhangkn/Meowswift

AppleScript

https://objccn.io/issue-14-2/sass

在 10.8 山狮中, Apple 引入了一个新的抽象类 NSUserScriptTask。有三个具体的子类实现让你分别能够运行 Unix shell 命令 (NSUserUnixTask),Automator 工做流 (NSUserAutomatorTask) 以及咱们最喜好的 AppleScript(NSUserAppleScriptTask)。教程的接下来的部分将会专一于最后一类,由于这也是最经常使用的类。
https://www.objc.io/issues/14...安全

XPC

XPC 是 OS X 下的一种 IPC (进程间通讯) 技术, 它实现了权限隔离, 使得 App Sandbox 更加完备.session

XPC 目的是提升 App 的安全性和稳定性。XPC 让进程间通讯变得更容易,让咱们可以相对容易地将 App 拆分红多个进程的模式。更进一步的是,XPC 管理了这些进程的生命周期,当咱们须要与子进程通讯的时候,子进程已经被 XPC 给运行起来了。

@class NSXPCConnection, NSXPCListener, NSXPCInterface, NSXPCListenerEndpoint;
% find /System/Library/Frameworks -name \*.xpc
devzkndeMacBook-Pro:Versions devzkn$ find /Applications  -name \*.xpc
/Applications/QuickTime Player.app/Contents/XPCServices/com.apple.quicktimeplayer.SharedPrefsVendor.xpc
/Applications/Xcode8.3.3.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/Library/Frameworks/XCTest.framework/XPCServices/xctestSymbolicator.xpc
/Applications/Xcode.app/Contents/Frameworks/IDEFoundation.framework/Versions/A/XPCServices/com.apple.dt.Xcode.RootDebuggingXPCService.xpc
/Applications/Hopper Disassembler v4.app/Contents/XPCServices/Assembler.xpc
/Applications/Hopper Disassembler v4.app/Contents/XPCServices/LocalDebugger.xpc
/Applications/Hopper Disassembler v4.app/Contents/XPCServices/PluginLoader.xpc
/Applications/Safari.app/Contents/XPCServices/com.apple.Safari.BrowserDataImportingService.xpc
/Applications/Utilities/Activity Monitor.app/Contents/XPCServices/com.apple.activitymonitor.helper.xpc
/Applications/Utilities/System Information.app/Contents/XPCServices/CloudStorageUIHelper.xpc
/Applications/Utilities/System Information.app/Contents/XPCServices/CloudStorageHelper.xpc
/Applications/Utilities/System Information.app/Contents/XPCServices/MessagesHelper.xpc
/Applications/FaceTime.app/Contents/XPCServices/FaceTimeNotificationCenterService.xpc
/Applications/Keynote.app/Contents/XPCServices/com.apple.iWork.MovieCompatibilityConverter.xpc
/Applications/Keynote.app/Contents/XPCServices/com.apple.iWork.PICTConverter.xpc
/Applications/Keynote.app/Contents/XPCServices/com.apple.iWork.ExternalResourceAccessor.xpc
/Applications/Keynote.app/Contents/XPCServices/com.apple.iWork.ExternalResourceAccessor.xpc/Contents/XPCServices/com.apple.iWork.TCMovieExtractor.xpc
/Applications/Keynote.app/Contents/XPCServices/com.apple.iWork.ExternalResourceAccessor.xpc/Contents/XPCServices/com.apple.iWork.TCMovieExtractor.xpc/Contents/XPCServices/com.apple.iWork.TCMovieExtractor.TCUtilities32.xpc
/Applications/Keynote.app/Contents/XPCServices/com.apple.iWork.ExternalResourceAccessor.xpc/Contents/XPCServices/com.apple.iWork.ExternalResourceValidator.xpc
/Applications/Keynote.app/Contents/XPCServices/com.apple.iWork.BitmapTracer.xpc
/Applications/Keynote.app/Contents/XPCServices/com.apple.iWork.TCUtilities32.xpc
/Applications/Pages.app/Contents/XPCServices/com.apple.iWork.MovieCompatibilityConverter.xpc
/Applications/Pages.app/Contents/XPCServices/com.apple.iWork.PICTConverter.xpc
/Applications/Pages.app/Contents/XPCServices/com.apple.iWork.ExternalResourceAccessor.xpc
/Applications/Pages.app/Contents/XPCServices/com.apple.iWork.ExternalResourceAccessor.xpc/Contents/XPCServices/com.apple.iWork.TCMovieExtractor.xpc
/Applications/Pages.app/Contents/XPCServices/com.apple.iWork.ExternalResourceAccessor.xpc/Contents/XPCServices/com.apple.iWork.TCMovieExtractor.xpc/Contents/XPCServices/com.apple.iWork.TCMovieExtractor.TCUtilities32.xpc
/Applications/Pages.app/Contents/XPCServices/com.apple.iWork.ExternalResourceAccessor.xpc/Contents/XPCServices/com.apple.iWork.ExternalResourceValidator.xpc
/Applications/Pages.app/Contents/XPCServices/com.apple.iWork.BitmapTracer.xpc
/Applications/Pages.app/Contents/XPCServices/com.apple.iWork.TCUtilities32.xpc
/Applications/OmniGraffle.app/Contents/XPCServices/com.omnigroup.GraffleLayout.xpc
/Applications/OmniGraffle.app/Contents/Frameworks/OmniSoftwareUpdate.framework/Versions/2009A/XPCServices/com.omnigroup.OmniSoftwareUpdate.OSUInstallerService.xpc
/Applications/Photos.app/Contents/XPCServices/com.apple.Photos.librarychooserservice.xpc
/Applications/Messages.app/Contents/XPCServices/com.apple.DownloadFolderImporter.xpc
/Applications/iTunes.app/Contents/XPCServices/VisualizerService.xpc
/Applications/Sketch.app/Contents/XPCServices/com.bohemiancoding.sketch3.migration.xpc
/Applications/Sketch.app/Contents/XPCServices/com.andymatuschak.Sparkle.SandboxService.xpc
/Applications/System Preferences.app/Contents/XPCServices/InstallHelper.xpc

Swift in Xcode 6 moves away from this architecture1, combining all these source code manipulation features into a separate process that communicates with Xcode through XPC: sourcekitd. This XPC daemon is launched whenever Xcode 6 loads any Swift code.

https://github.com/jpsim/Swif...

https://speakerdeck.com/jpsim...

[你懂js,就立马学会swift][6]

Realm

is a mobile database: a replacement for Core Data & SQLite https://realm.io

Install CocoaPods 1.1.0 or later.
Run pod repo update to make CocoaPods aware of the latest available Realm versions.
In your Podfile, add pod 'Realm' to your app target and pod 'Realm/Headers' to your test target.
From the command line, run pod install.
Use the .xcworkspace file generated by CocoaPods to work on your project!
If using Realm with Swift, drag the file at Swift/RLMSupport.swift into the File Navigator of your Xcode project, checking the Copy items if needed checkbox.

Simple Swift wrapper for Keychain that works on iOS, watchOS, tvOS and macOS.

相关文章
相关标签/搜索