截图 hook SBScreenshotManager


#1

最近才看这本书,发现我的iOS9.3.3上并没有SBScreenShotter的类,所以我看了自己class-dump的springboard,发现9上使用的是SBScreenshotManager,然后我用cycript调试成功的可以截图。然后有两个问题:

  1. 在cycript中我是用
cy# choose(SBScreenshotManager)
[#"<SBScreenshotManager: 0x14161d490>"]
cy# [#0x14161d490 saveScreenshots]

直接用choose获取的对象,如果是在编写tweak.xm的时候,该怎么获取该对象,因为在SBScreenshotManager类中我没有发现类似sharedInstance等的单例对象获取的方法,难道是自己创建吗?
2. 在make的时候告诉我没有saveScreenshots方法:

> Making all for tweak iosreproject…
==> Preprocessing Tweak.xm…
==> Compiling Tweak.xm (armv7)…
Tweak.xm:22:3: error: unknown type name 'SBScreenshotManager'

随后我在开头申明了这些:

@interface SBScreenshotManager: NSObject
- (void)saveScreenshots;
+ (id)sharedInstance;
@end

然后就是一长串错误😭

> Making all for tweak iosreproject…
==> Linking tweak iosreproject (armv7)…
ld: warning: object file (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0/lib/darwin/libclang_rt.ios.a(comparesf2.S.o)) was built for newer iOS version (6.0) than being linked (5.0)
ld: warning: object file (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0/lib/darwin/libclang_rt.ios.a(divmodsi4.S.o)) was built for newer iOS version (6.0) than being linked (5.0)
ld: warning: object file (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0/lib/darwin/libclang_rt.ios.a(switch16.S.o)) was built for newer iOS version (6.0) than being linked (5.0)
ld: warning: object file (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0/lib/darwin/libclang_rt.ios.a(switch32.S.o)) was built for newer iOS version (6.0) than being linked (5.0)
ld: warning: object file (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0/lib/darwin/libclang_rt.ios.a(switch8.S.o)) was built for newer iOS version (6.0) than being linked (5.0)
ld: warning: object file (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0/lib/darwin/libclang_rt.ios.a(switchu8.S.o)) was built for newer iOS version (6.0) than being linked (5.0)
ld: warning: object file (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0/lib/darwin/libclang_rt.ios.a(udivmodsi4.S.o)) was built for newer iOS version (6.0) than being linked (5.0)
ld: warning: object file (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0/lib/darwin/libclang_rt.ios.a(comparedf2.c.o)) was built for newer iOS version (6.0) than being linked (5.0)
ld: warning: object file (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0/lib/darwin/libclang_rt.ios.a(eprintf.c.o)) was built for newer iOS version (6.0) than being linked (5.0)
ld: warning: object file (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0/lib/darwin/libclang_rt.ios.a(extendhfsf2.c.o)) was built for newer iOS version (6.0) than being linked (5.0)
ld: warning: object file (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0/lib/darwin/libclang_rt.ios.a(int_util.c.o)) was built for newer iOS version (6.0) than being linked (5.0)
ld: warning: object file (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0/lib/darwin/libclang_rt.ios.a(mulodi4.c.o)) was built for newer iOS version (6.0) than being linked (5.0)
ld: warning: object file (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0/lib/darwin/libclang_rt.ios.a(mulosi4.c.o)) was built for newer iOS version (6.0) than being linked (5.0)
ld: warning: object file (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0/lib/darwin/libclang_rt.ios.a(muloti4.c.o)) was built for newer iOS version (6.0) than being linked (5.0)
ld: warning: object file (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0/lib/darwin/libclang_rt.ios.a(negdf2.c.o)) was built for newer iOS version (6.0) than being linked (5.0)
ld: warning: object file (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0/lib/darwin/libclang_rt.ios.a(negsf2.c.o)) was built for newer iOS version (6.0) than being linked (5.0)
ld: warning: object file (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0/lib/darwin/libclang_rt.ios.a(truncdfhf2.c.o)) was built for newer iOS version (6.0) than being linked (5.0)
ld: warning: object file (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0/lib/darwin/libclang_rt.ios.a(truncsfhf2.c.o)) was built for newer iOS version (6.0) than being linked (5.0)
ld: warning: object file (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0/lib/darwin/libclang_rt.ios.a(atomic_flag_clear.c.o)) was built for newer iOS version (6.0) than being linked (5.0)
ld: warning: object file (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0/lib/darwin/libclang_rt.ios.a(atomic_flag_clear_explicit.c.o)) was built for newer iOS version (6.0) than being linked (5.0)
ld: warning: object file (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0/lib/darwin/libclang_rt.ios.a(atomic_flag_test_and_set.c.o)) was built for newer iOS version (6.0) than being linked (5.0)
ld: warning: object file (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0/lib/darwin/libclang_rt.ios.a(atomic_flag_test_and_set_explicit.c.o)) was built for newer iOS version (6.0) than being linked (5.0)
ld: warning: object file (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0/lib/darwin/libclang_rt.ios.a(atomic_signal_fence.c.o)) was built for newer iOS version (6.0) than being linked (5.0)
ld: warning: object file (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0/lib/darwin/libclang_rt.ios.a(atomic_thread_fence.c.o)) was built for newer iOS version (6.0) than being linked (5.0)
ld: warning: object file (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.3.0/lib/darwin/libclang_rt.ios.a(emutls.c.o)) was built for newer iOS version (6.0) than being linked (5.0)
Undefined symbols for architecture armv7:
  "_OBJC_CLASS_$_SBScreenshotManager", referenced from:
      objc-class-ref in Tweak.xm.8dca27e2.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [/Users/susnm/Code/iosreproject/.theos/obj/debug/armv7/iosreproject.dylib] Error 1
make[2]: *** [/Users/susnm/Code/iosreproject/.theos/obj/debug/armv7/iosreproject.dylib] Error 2
make[1]: *** [internal-library-all_] Error 2
make: *** [iosreproject.all.tweak.variables] Error 2

#2
  1. 对,自己alloc

  2. 你那个sharedInstance是哪里来的?

  3. 报的warning貌似跟Makefile的设置有关,你看看是不是SDK version设置的有问题


#3

sharedInstance就是因为不知道我想试一下,idk版本的话我是iOS9.3的但是他下面的private frames我是用的iOS9.2的


#4

自己创建的话是用initWithDataSource吗?那cycripy中参数怎么得到的😊?


#5

直接[[XXX alloc] init]试试看,还不行的话,在initWithDataSource:下一个断点,看看系统是怎么初始化这个对象的


#6
  1. 估计不行,这样创建出来的时候,截图可以看到那个辅助小点会隐藏一下,跟截图一样的情况,但是实际是没有截图的,估计是少那个参数的原因。
  2. 还有报的warning错误,跟idk的version设置有关,但是我是make package install成功过的,只有在写完这个函数的时候开始报warning了

#7

objc_getClass(“类名”)


#8

没有反而是objc_getClass有错,找不到这个函数


#9

在objc/runtime.h里


#10

那应该不需要导入和申明吧?为什么还是报错,说没有这个方法?


#11

查看这篇博客http://www.lanvsblue.top/2016/09/16/press-home-to-screenshot-9.3.3/


#12

可以通过 SpringBoard 的属性 screenshotManager 拿到 SBScreenshotManager 的实例