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.

相關文章
相關標籤/搜索