rework screendumpLowFrame - now works

This commit is contained in:
Levent Duivel 2024-11-07 06:46:11 +05:00
parent 6c6e43abc0
commit 8a7ae31775
16 changed files with 146 additions and 123 deletions

View File

@ -0,0 +1,15 @@
INSTALL_TARGET_PROCESSES = SpringBoard
include $(THEOS)/makefiles/common.mk
TWEAK_NAME = screendumpbb
$(TWEAK_NAME)_FILES = Tweak.xm
#$(TWEAK_NAME)_ARCHS = arm64
#$(TWEAK_NAME)_FRAMEWORKS := IOSurface IOKit
#$(TWEAK_NAME)_PRIVATE_FRAMEWORKS := IOMobileFramebuffer IOSurface
#ADDITIONAL_OBJCFLAGS += -I../vncbuild/include -Iinclude
#ADDITIONAL_LDFLAGS += -Wl,-segalign,4000 -L../vncbuild/lib -lvncserver -lpng -llzo2 -ljpeg -lssl -lcrypto -lz
#ADDITIONAL_CFLAGS = -w
include $(THEOS_MAKE_PATH)/tweak.mk

View File

@ -1,12 +1,9 @@
#include <errno.h>
#include <substrate.h>
#include <rfb/rfb.h>
#import <errno.h>
#import <substrate.h>
#import <notify.h>
#import <UIKit/UIKit.h>
#import <rootless.h>
#undef NSLog
#define kSettingsPath @"/var/mobile/Library/Preferences/com.cosmosgenius.screendump.plist"
extern "C" UIImage* _UICreateScreenUIImage();
@ -19,13 +16,32 @@ static BOOL isBlackScreen;
@end
@implementation CapturerScreen
- (id)init
-(id)init
{
NSLog(@"screendump bb: CapturerScreen init");
self = [super init];
// [self start];
return self;
}
- (unsigned char *)pixelBRGABytesFromImageRef:(CGImageRef)imageRef
+(void)load
{
CapturerScreen* instance = [self sharedInstance];
[instance start];
}
+(instancetype)sharedInstance
{
static dispatch_once_t onceToken = 0;
__strong static CapturerScreen* sharedInstance = nil;
dispatch_once(&onceToken, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}
-(unsigned char *)pixelBRGABytesFromImageRef:(CGImageRef)imageRef
{
NSUInteger iWidth = CGImageGetWidth(imageRef);
@ -53,17 +69,18 @@ static BOOL isBlackScreen;
return imageBytes;
}
- (unsigned char *)pixelBRGABytesFromImage:(UIImage *)image
-(unsigned char *)pixelBRGABytesFromImage:(UIImage *)image
{
return [self pixelBRGABytesFromImageRef:image.CGImage];
}
- (void)start
-(void)start
{
dispatch_async(dispatch_get_main_queue(), ^(void){
NSLog(@"screendumpbb: setting capture timer every 0.4f");
[NSTimer scheduledTimerWithTimeInterval:0.4f target:self selector:@selector(capture) userInfo:nil repeats:YES];
});
}
- (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize
-(UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize
{
//UIGraphicsBeginImageContext(newSize);
UIGraphicsBeginImageContextWithOptions(newSize, NO, 1.0f);
@ -73,15 +90,19 @@ static BOOL isBlackScreen;
[image release];
return newImage;
}
- (void)capture
-(void)capture
{
NSLog(@"screendumpbb: capture");
@autoreleasepool {
NSLog(@"screendumpbb: capture - isBlackScreen: %d", isBlackScreen);
NSLog(@"screendumpbb: capture - isEnabled: %d", isEnabled);
if(isBlackScreen || !isEnabled) {
return;
}
UIImage* image = _UICreateScreenUIImage();
NSLog(@"screendumpbb: capture - got frame, now resizing...");
CGSize newS = CGSizeMake(image.size.width, image.size.height);
@ -96,19 +117,24 @@ static BOOL isBlackScreen;
size_t size = iWidth * iHeight * iBytesPerPixel;
unsigned char * bytes = [self pixelBRGABytesFromImageRef:imageRef];
NSLog(@"screendumpbb: capture - resize complete, got bytes");
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
@autoreleasepool {
NSLog(@"screendumpbb: capture - writing buffer...");
NSData *imageData = [NSData dataWithBytesNoCopy:bytes length:size freeWhenDone:YES];
[imageData writeToFile:@"//tmp/screendump_Buff.tmp" atomically:YES];
[@{@"width":@(iWidth), @"height":@(iHeight), @"size":@(size),} writeToFile:@"//tmp/screendump_Info.tmp" atomically:YES];
NSLog(@"screendumpbb: capture - notifying daemon");
notify_post("com.julioverne.screendump/frameChanged");
}
});
}
}
@end
/*
%hook SpringBoard
- (void)applicationDidFinishLaunching:(id)application
{
@ -117,7 +143,7 @@ static BOOL isBlackScreen;
[cap start];
}
%end
*/
static void screenDisplayStatus(CFNotificationCenterRef center, void* observer, CFStringRef name, const void* object, CFDictionaryRef userInfo)
{
@ -131,21 +157,29 @@ static void screenDisplayStatus(CFNotificationCenterRef center, void* observer,
} else {
isBlackScreen = NO;
}
NSLog(@"screendumpbb: screenDisplayStatus - isBlackScreen: %d", isBlackScreen);
}
static void loadPrefs(CFNotificationCenterRef center, void* observer, CFStringRef name, const void* object, CFDictionaryRef userInfo)
{
NSLog(@"screendumpbb: loadPrefs");
@autoreleasepool {
NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"com.cosmosgenius.screendump"];
isEnabled = [[defaults objectForKey:@"CCSisEnabled"]?:@NO boolValue];
NSLog(@"screendumpbb: loadPrefs - isEnabled: %d", isEnabled);
}
}
%ctor
{
NSLog(@"screendumpbb: ctor");
isEnabled = NO;
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, screenDisplayStatus, CFSTR("com.apple.iokit.hid.displayStatus"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
NSLog(@"screendumpbb: ctor 1");
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, loadPrefs, CFSTR("com.cosmosgenius.screendump/preferences.changed"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
NSLog(@"screendumpbb: ctor 2");
loadPrefs(NULL, NULL, NULL, NULL, NULL);
NSLog(@"screendumpbb: ctor 3");
}

View File

@ -0,0 +1,5 @@
{
Filter = {
Bundles = ( "com.apple.springboard" );
};
}

View File

@ -1,50 +1,14 @@
TARGET = iphone:16.5:14.0
export THEOS_PACKAGE_SCHEME = rootless
export ARCHS = arm64 arm64e
export TARGET = iphone:16.5:14.0
export GO_EASY_ON_ME = 1
export COPYFILE_DISABLE=1
include $(THEOS)/makefiles/common.mk
ifeq ($(THEOS_PACKAGE_SCHEME),rootless)
PACKAGE_BUILDNAME := rootless
else
PACKAGE_BUILDNAME := rootful
endif
TOOL_NAME = screendumpd
$(TOOL_NAME)_FILES = main.mm
export ARCHS = arm64
$(TOOL_NAME)_ARCHS = arm64
ARCHS = arm64
$(TOOL_NAME)_VALID_ARCHS = arm64
$(TOOL_NAME)_FRAMEWORKS := IOSurface IOKit
$(TOOL_NAME)_PRIVATE_FRAMEWORKS := IOMobileFramebuffer IOSurface
ifeq ($(THEOS_PACKAGE_SCHEME),rootless)
# Rootless
$(TOOL_NAME)_OBJCFLAGS += -Ivncbuild/include -Iinclude
$(TOOL_NAME)_LDFLAGS += -Wl,-segalign,4000 -Lvncbuild/lib -lvncserver -lpng -llzo2 -ljpeg -lssl -lcrypto -lz
$(TOOL_NAME)_INSTALL_PATH = /usr/libexec
else
# Rootful settings
$(TOOL_NAME)_OBJCFLAGS += -Ivncbuild/include -Iinclude
$(TOOL_NAME)_LDFLAGS += -Wl,-segalign,4000 -Lvncbuild/lib -lvncserver -lpng -llzo2 -ljpeg -lssl -lcrypto -lz
$(TOOL_NAME)_INSTALL_PATH = /usr/libexec
endif
$(TOOL_NAME)_CFLAGS = -w
$(TOOL_NAME)_CODESIGN_FLAGS = "-Sen.plist"
include $(THEOS_MAKE_PATH)/tool.mk
SUBPROJECTS += hooks
SUBPROJECTS += Capturer Server
include $(THEOS_MAKE_PATH)/aggregate.mk
ifeq ($(THEOS_PACKAGE_SCHEME),rootless)
after-screendumpd-stage::
$(ECHO_NOTHING) rm $(THEOS_STAGING_DIR)/Library/LaunchDaemons/com.julioverne.screendumpd.plist$(ECHO_END)
$(ECHO_NOTHING) mv $(THEOS_STAGING_DIR)/Library/LaunchDaemons/com.julioverne.screendumpd.rootless.plist $(THEOS_STAGING_DIR)/Library/LaunchDaemons/com.julioverne.screendumpd.plist$(ECHO_END)
$(ECHO_NOTHING)$(FAKEROOT) chown root:wheel $(THEOS_STAGING_DIR)/Library/LaunchDaemons/com.julioverne.screendumpd.plist$(ECHO_END)
else
after-screendumpd-stage::
$(ECHO_NOTHING) rm $(THEOS_STAGING_DIR)/Library/LaunchDaemons/com.julioverne.screendumpd.rootless.plist$(ECHO_END)
$(ECHO_NOTHING)$(FAKEROOT) chown root:wheel $(THEOS_STAGING_DIR)/Library/LaunchDaemons/com.julioverne.screendumpd.plist$(ECHO_END)
endif
$(ECHO_NOTHING)$(FAKEROOT) chown root:wheel $(THEOS_STAGING_DIR)/Library/LaunchDaemons/com.julioverne.screendumpd.plist$(ECHO_END)

View File

@ -0,0 +1,17 @@
include $(THEOS)/makefiles/common.mk
TOOL_NAME = screendumpd
$(TOOL_NAME)_FILES = main.mm
$(TOOL_NAME)_ARCHS = arm64
$(TOOL_NAME)_FRAMEWORKS := IOSurface IOKit
$(TOOL_NAME)_PRIVATE_FRAMEWORKS := IOMobileFramebuffer IOSurface
$(TOOL_NAME)_OBJCFLAGS += -I../vncbuild/include -Iinclude
$(TOOL_NAME)_LDFLAGS += -Wl,-segalign,4000 -L../vncbuild/lib -lvncserver -lpng -llzo2 -ljpeg -lssl -lcrypto -lz
$(TOOL_NAME)_INSTALL_PATH = /usr/libexec
$(TOOL_NAME)_CFLAGS = -w
$(TOOL_NAME)_CODESIGN_FLAGS = -Sentitlements.plist
include $(THEOS_MAKE_PATH)/tool.mk
after-screendumpd-stage::
$(ECHO_NOTHING)$(FAKEROOT) chown root:wheel $(THEOS_STAGING_DIR)/Library/LaunchDaemons/com.julioverne.screendumpd.plist$(ECHO_END)

View File

@ -1,4 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
@ -47,4 +46,4 @@
<key>com.apple.private.security.disk-device-access</key>
<true/>
</dict>
</plist>
</plist>

View File

@ -1,6 +1,6 @@
#include <errno.h>
#include <substrate.h>
#include <rfb/rfb.h>
#import <errno.h>
#import <substrate.h>
#import <rfb/rfb.h>
#import <Foundation/Foundation.h>
#import <IOSurface/IOSurfaceRef.h>
#import <rootless.h>
@ -47,7 +47,7 @@ typedef mach_port_t io_service_t;
typedef kern_return_t IOReturn;
typedef IOReturn IOMobileFramebufferReturn;
typedef io_service_t IOMobileFramebufferService;
extern "C" mach_port_t mach_task_self(void);
extern "C" mach_port_t mach_task_self();
extern "C" void IOSurfaceFlushProcessorCaches(IOSurfaceRef buffer);
extern "C" int IOSurfaceLock(IOSurfaceRef surface, uint32_t options, uint32_t *seed);
extern "C" int IOSurfaceUnlock(IOSurfaceRef surface, uint32_t options, uint32_t *seed);
@ -66,6 +66,7 @@ static void handleVNCPointer(int buttons, int x, int y, rfbClientPtr client);
static rfbBool VNCCheck(rfbClientPtr client, const char *data, int size)
{
NSLog(@"screendumpd: VNCCheck");
NSString *password = reinterpret_cast<NSString *>(screen->authPasswdData);
if(!password) {
return TRUE;
@ -82,6 +83,7 @@ static rfbBool VNCCheck(rfbClientPtr client, const char *data, int size)
static void VNCSetup()
{
NSLog(@"screendumpd: VNCSetup");
@autoreleasepool {
NSDictionary* frameInfo = [NSDictionary dictionaryWithContentsOfFile:@"//tmp/screendump_Info.tmp"]?:@{};
width = [frameInfo[@"width"]?:@(0) intValue];
@ -116,33 +118,47 @@ static void VNCSettings(bool shouldStart, NSString* password)
CCSPassword = password;
}
NSString *sEnabled = CCSisEnabled ? @"YES": @"NO";
NSLog(@"screendumpd: VNCSettings - is enabled - %@", sEnabled);
NSLog(@"screendumpd: VNCSettings - password - %@", CCSPassword);
VNCUpdateRunState(CCSisEnabled);
}
static void VNCUpdateRunState(bool shouldStart)
{
NSLog(@"screendumpd: VNCUpdateRunState");
if(screen == NULL) {
NSLog(@"screendumpd: VNCUpdateRunState - screen is nil");
return;
}
if(CCSPassword && CCSPassword.length) {
NSLog(@"screendumpd: VNCUpdateRunState - configured password");
screen->authPasswdData = (void *) CCSPassword;
} else {
NSLog(@"screendumpd: VNCUpdateRunState - set password to nil");
screen->authPasswdData = NULL;
}
NSLog(@"screendumpd: VNCUpdateRunState - vnc is running?");
if(shouldStart == isVNCRunning) {
NSLog(@"screendumpd: VNCUpdateRunState - vnc is running");
return;
}
NSLog(@"screendumpd: VNCUpdateRunState - vnc is not running");
if(shouldStart) {
NSLog(@"screendumpd: VNCUpdateRunState - rfbInitServer");
rfbInitServer(screen);
NSLog(@"screendumpd: VNCUpdateRunState - rfbRunEventLoop");
rfbRunEventLoop(screen, -1, true);
} else {
NSLog(@"screendumpd: VNCUpdateRunState - rfbShutdownServer");
rfbShutdownServer(screen, true);
}
isVNCRunning = shouldStart;
NSLog(@"screendumpd: VNCUpdateRunState - isVNCRunning: %d", isVNCRunning);
}
static void loadPrefs(void)
{
NSLog(@"screendumpd: load prefs");
@autoreleasepool {
NSDictionary* defaults = nil;
CFStringRef appID = CFSTR("com.cosmosgenius.screendump");
@ -152,7 +168,9 @@ static void loadPrefs(void)
CFRelease(keyList);
}
BOOL isEnabled = [[defaults objectForKey:@"CCSisEnabled"]?:@NO boolValue];
NSLog(@"screendumpd: prefs - is enabled - %d", isEnabled);
NSString *password = [defaults objectForKey:@"CCSPassword"];
NSLog(@"screendumpd: prefs - password - %@", password);
VNCSettings(isEnabled, password);
}
}
@ -164,22 +182,28 @@ static void VNCBlack()
static void upFrame()
{
NSLog(@"screendumpd: upFrame");
if(size_image == 0) {
NSLog(@"screendumpd: upFrame - size_image = 0");
VNCSetup();
}
if(screen == NULL) {
NSLog(@"screendumpd: upFrame - screen is nil");
return;
}
@try {
@autoreleasepool {
NSLog(@"screendumpd: upFrame - updating buffer...");
NSData *data = [[NSFileManager defaultManager] contentsAtPath:@"//tmp/screendump_Buff.tmp"];
memcpy(screen->frameBuffer, (void*)data.bytes, data.length);
NSLog(@"screendumpd: upFrame - updated buffer");
}
}@catch(NSException*e){
}
NSLog(@"screendumpd: upFrame - requesting to send a new frame");
rfbMarkRectAsModified(screen, 0, 0, width, height);
}
@ -188,6 +212,8 @@ extern "C" IOMobileFramebufferReturn IOMobileFramebufferGetMainDisplay(IOMobileF
int main(int argc, const char *argv[])
{
isVNCRunning = NO;
NSLog(@"screendumpd: main start");
CFNotificationCenterAddObserver(
CFNotificationCenterGetDarwinNotifyCenter(),
NULL, (CFNotificationCallback)loadPrefs,
@ -199,23 +225,27 @@ int main(int argc, const char *argv[])
NULL, (CFNotificationCallback)upFrame,
CFSTR("com.julioverne.screendump/frameChanged"),
NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
loadPrefs();
NSLog(@"screendumpd: main - vnc setup");
VNCSetup();
//VNCBlack();
NSLog(@"screendumpd: main - load prefs");
loadPrefs();
NSLog(@"screendumpd: main - loop");
[[NSRunLoop currentRunLoop] run];
NSLog(@"screendumpd: main - end");
return EXIT_SUCCESS;
}
#include <mach/mach.h>
#include <mach/mach_time.h>
#include <rfb/rfb.h>
#include <rfb/keysym.h>
#include "./include/IOKit/hid/IOHIDEventTypes.h"
#include "./include/IOKit/hidsystem/IOHIDUsageTables.h"
#import <mach/mach.h>
#import <mach/mach_time.h>
#import <rfb/rfb.h>
#import <rfb/keysym.h>
#import "./include/IOKit/hid/IOHIDEventTypes.h"
#import "./include/IOKit/hidsystem/IOHIDUsageTables.h"
typedef uint32_t IOHIDDigitizerTransducerType;

View File

@ -1,18 +0,0 @@
TARGET = iphone:16.5:14.0
include $(THEOS)/makefiles/common.mk
TWEAK_NAME = screendumpbb
$(TWEAK_NAME)_FILES = Tweak.xm
export ARCHS = arm64
$(TWEAK_NAME)_ARCHS = arm64
$(TWEAK_NAME)_FRAMEWORKS := IOSurface IOKit
$(TWEAK_NAME)_PRIVATE_FRAMEWORKS := IOMobileFramebuffer IOSurface
ADDITIONAL_OBJCFLAGS += -I../vncbuild/include -Iinclude
ADDITIONAL_LDFLAGS += -Wl,-segalign,4000 -L../vncbuild/lib -lvncserver -lpng -llzo2 -ljpeg -lssl -lcrypto -lz
ADDITIONAL_CFLAGS = -w
include $(THEOS_MAKE_PATH)/tweak.mk

View File

@ -1,7 +0,0 @@
{
Filter = {
Executables = (
"SpringBoard",
);
};
}

View File

@ -1,10 +1,8 @@
#!/bin/sh
if [ -L "/var/jb" ]; then
launchctl unload /var/jb/Library/LaunchDaemons/com.julioverne.screendumpd.plist
launchctl load /var/jb/Library/LaunchDaemons/com.julioverne.screendumpd.plist
else
launchctl unload /Library/LaunchDaemons/com.julioverne.screendumpd.plist
launchctl load /Library/LaunchDaemons/com.julioverne.screendumpd.plist
fi

View File

@ -6,4 +6,4 @@ else
launchctl unload /Library/LaunchDaemons/com.julioverne.screendumpd.plist
fi
exit 0;
exit 0;

View File

@ -0,0 +1,9 @@
#!/bin/sh
if [ -L "/var/jb" ]; then
launchctl unload /var/jb/Library/LaunchDaemons/com.julioverne.screendumpd.plist
else
launchctl unload /Library/LaunchDaemons/com.julioverne.screendumpd.plist
fi
exit 0;

View File

@ -6,7 +6,7 @@
<string>com.julioverne.screendumpd</string>
<key>ProgramArguments</key>
<array>
<string>/usr/libexec/screendumpd</string>
<string>/var/jb/usr/libexec/screendumpd</string>
</array>
<key>RunAtLoad</key>
<true/>

View File

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.julioverne.screendumpd</string>
<key>ProgramArguments</key>
<array>
<string>/var/jb/usr/libexec/screendumpd</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
</dict>
</plist>

View File

@ -1,7 +0,0 @@
{
Filter = {
Executables = (
"SpringBoard",
);
};
}