需要 hook Springboard,代码很简单。
// 我是用 lldb 调试的所以大家将近看一下,稍微改改就能用了。
id $a = [[[_SBMainScreenScreenshotProvider alloc] init] captureScreenshot];
id $b = UIImagePNGRepresentation($a, 0.3);
[$b writeToFile:@"/var/mobile/Documents/aaa.png" atomically:YES];
// (lldb) po id $a = [[[_SBMainScreenScreenshotProvider alloc] init] captureScreenshot]; id $b = UIImagePNGRepresentation($a, 0.3); [$b writeToFile:@"/var/mobile/Documents/aaa.png" atomically:YES];
8 个赞
haojimo
(好寂寞)
3
那个 HOOK 其他程序要怎么调用啊!
我尝试使用
void * sp = dlopen("/System/Library/PrivateFrameworks/SpringBoard.framework/SpringBoard", RTLD_LAZY); 显然是失败的 我是个新新手。。
可以先给 SB 写一个 Tweak,另外写一个 Tool,使用 Tool 给 SB 的 Tweak 发送一个 IPC 信息,然后就可以了
1 个赞
为什么不 hook SpringBoard?能说一下原因吗?
不 hook SB 的话可能就要从硬件渲染那里入手了,那里比较复杂,我看别人实现过但我不想那么做。
之所以 hook SB 是因为我想找一个简单,且能在任何情况下都能正确截图的代码。
haojimo
(好寂寞)
7
因为我觉得很繁琐 我已经找到更简单直接的方式!
UIKIT_EXTERN CGImageRef UICreateCGImageFromIOSurface(IOSurfaceRef);
IOSurfaceRef ioSurfaceRef = (__bridge IOSurfaceRef)([UIWindow performSelector:@selector(createScreenIOSurface)]);
CGImageRef cgImageRef = UICreateCGImageFromIOSurface(ioSurfaceRef);
UIImage *Image=[UIImage imageWithCGImage:cgImageRef];
CFRelease(ioSurfaceRef);
CGImageRelease(cgImageRef);
1 个赞
haojimo
(好寂寞)
10
上面的例子已经可以拿到 图片对象啦 想怎么操作都行啦
nu11
(null)
11
我看成了,深夜给大家提供一个iOS 截图。
[图片][图片][图片][图片][图片][图片][图片][图片][图片][图片][图片][图片][图片][图片][图片][图片][图片][图片][图片][图片][图片][图片][图片][图片][图片][图片][图片][图片][图片][图片][图片][图片][图片][图片][图片][图片][图片][图片]
zhouxihi
(Zhouxihi)
12
ios14.5上用这个截图转png大小是0, 该怎么解决呢
目前手上没有 iOS 14.5 的设备,如果这个办法不行的话尝试使用 IOSurface
去获取目前渲染的屏幕。
1 个赞