diff --git a/screendump/FrameUpdater.h b/screendump/FrameUpdater.h new file mode 100644 index 0000000..eecd452 --- /dev/null +++ b/screendump/FrameUpdater.h @@ -0,0 +1,8 @@ +#import + +@interface FrameUpdater : NSObject +@property (nonatomic, retain) NSTimer* myTimer; +@property (nonatomic) BOOL isEnabled; +- (void)startFrameLoop; +- (void)stopFrameLoop; +@end diff --git a/screendump/Makefile b/screendump/Makefile index 6868bd0..0c1d3db 100644 --- a/screendump/Makefile +++ b/screendump/Makefile @@ -1,10 +1,8 @@ -DEBUG=0 -FINALPACKAGE=1 - -THEOS_PACKAGE_SCHEME = rootless - -TARGET = iphone:14.5:14.5 -ARCHS = arm64 +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 diff --git a/screendump/main.mm b/screendump/main.mm index 7ba76ec..4c811d6 100755 --- a/screendump/main.mm +++ b/screendump/main.mm @@ -1,8 +1,10 @@ -#include -#include -#include -#include -#include +#import +#import +#import +#import +#import + +#import "FrameUpdater.h" #define kSettingsPath @"/var/mobile/Library/Preferences/com.cosmosgenius.screendump.plist" @@ -63,7 +65,7 @@ extern "C" IOMobileFramebufferReturn IOMobileFramebufferGetLayerDefaultSurface(I extern "C" IOMobileFramebufferReturn IOMobileFramebufferCopyLayerDisplayedSurface(IOMobileFramebufferRef pointer, int surface, IOSurfaceRef *buffer); extern "C" IOMobileFramebufferReturn IOMobileFramebufferOpen(IOMobileFramebufferService service, mach_port_t owningTask, unsigned int type, IOMobileFramebufferRef *pointer); extern "C" IOMobileFramebufferReturn IOMobileFramebufferGetMainDisplay(IOMobileFramebufferRef *pointer); -extern "C" mach_port_t mach_task_self(void); +extern "C" mach_port_t mach_task_self(); static IOSurfaceAcceleratorRef accelerator; static IOSurfaceRef static_buffer; @@ -72,8 +74,6 @@ static void VNCUpdateRunState(bool shouldStart); static void handleVNCKeyboard(rfbBool down, rfbKeySym key, rfbClientPtr client); static void handleVNCPointer(int buttons, int x, int y, rfbClientPtr client); -static BOOL isLoopFrame; - static rfbBool VNCCheck(rfbClientPtr client, const char *data, int size) { NSString *password = reinterpret_cast(screen->authPasswdData); @@ -93,12 +93,6 @@ static rfbBool VNCCheck(rfbClientPtr client, const char *data, int size) static IOSurfaceRef screenSurface = NULL; static IOMobileFramebufferRef framebufferConnection = NULL; -@interface FrameUpdater : NSObject -@property (nonatomic, retain) NSTimer* myTimer; -- (void)startFrameLoop; -- (void)stopFrameLoop; -@end - static void VNCSetup() { if(!screenSurface) { @@ -115,8 +109,8 @@ static void VNCSetup() //width = size.width/2; //height = size.height/2; - width = prefferW==0?IOSurfaceGetWidth(screenSurface):prefferW; - height = prefferW==0?IOSurfaceGetHeight(screenSurface):prefferH; + width = prefferW == 0 ? IOSurfaceGetWidth(screenSurface) : prefferW; + height = prefferW == 0 ? IOSurfaceGetHeight(screenSurface) : prefferH; size_image = IOSurfaceGetAllocSize(screenSurface); bytesPerRow = IOSurfaceGetBytesPerRow(screenSurface); @@ -161,6 +155,7 @@ static void VNCSettings(bool shouldStart, NSString* password) CCSPassword = password; } NSString *sEnabled = CCSisEnabled ? @"YES": @"NO"; + [[FrameUpdater shared] setIsEnabled:CCSisEnabled]; VNCUpdateRunState(CCSisEnabled); } @@ -172,28 +167,20 @@ static void VNCUpdateRunState(bool shouldStart) return; } - - if(CCSPassword && CCSPassword.length) { + if (CCSPassword && CCSPassword.length) { screen->authPasswdData = (void *) CCSPassword; } else { screen->authPasswdData = NULL; } - if(shouldStart == isVNCRunning) { + if (shouldStart == isVNCRunning) { return; } - if(shouldStart) { + if (shouldStart) { rfbInitServer(screen); rfbRunEventLoop(screen, -1, true); - - isLoopFrame = YES; - [[FrameUpdater shared] startFrameLoop]; - - } else { - isLoopFrame = NO; - + } else { [[FrameUpdater shared] stopFrameLoop]; - rfbShutdownServer(screen, true); } isVNCRunning = shouldStart; @@ -222,36 +209,43 @@ static void loadPrefs(void) static uint32_t oldSeed; -@implementation FrameUpdater -{ - NSOperationQueue *q; +@implementation FrameUpdater { + NSOperationQueue *_q; + BOOL _isLoopFrame; } @synthesize myTimer; -+ (id)shared +@synthesize isEnabled; + ++(id)shared { - static __strong FrameUpdater* initFrame; - if(!initFrame) { - initFrame = [[[self class] alloc] init]; - } - return initFrame; + static dispatch_once_t onceToken = 0; + __strong static FrameUpdater* sharedInstance = nil; + dispatch_once(&onceToken, ^{ + sharedInstance = [[self alloc] init]; + }); + return sharedInstance; } -- (id)init + +-(id)init { - self = [super init]; - - q = [[NSOperationQueue alloc] init]; - + if ((self = [super init])) + { + _q = [[NSOperationQueue alloc] init]; + _isLoopFrame = NO; + isEnabled = NO; + } return self; } -- (void)_upFrameLoop + +-(void)_upFrameLoop { - if(isLoopFrame && CCSisEnabled) { + if (_isLoopFrame && isEnabled) { //check if screen changed uint32_t newSeed = IOSurfaceGetSeed(screenSurface); if(oldSeed != newSeed && rfbIsActive(screen)) { oldSeed = newSeed; - [q addOperationWithBlock: ^{ + [_q addOperationWithBlock: ^{ IOSurfaceAcceleratorTransferSurface(accelerator, screenSurface, static_buffer, NULL, NULL, NULL, NULL); rfbMarkRectAsModified(screen, 0, 0, width, height); }]; @@ -260,30 +254,36 @@ static uint32_t oldSeed; [self stopFrameLoop]; } } -- (void)stopFrameLoop + +-(void)stopFrameLoop { if(myTimer && [myTimer isValid]) { dispatch_async(dispatch_get_main_queue(), ^(void){ [myTimer invalidate]; + _isLoopFrame = NO; }); } } -- (void)startFrameLoop + +-(void)startFrameLoop { if(size_image == 0) { VNCSetup(); } [self stopFrameLoop]; + _isLoopFrame = YES; dispatch_async(dispatch_get_main_queue(), ^(void){ myTimer = [NSTimer scheduledTimerWithTimeInterval:1/400 target:self selector:@selector(_upFrameLoop) userInfo:nil repeats:YES]; }); } + -(void)dealloc { [self stopFrameLoop]; } @end + static void restartServer() { exit(0); @@ -307,12 +307,12 @@ int main(int argc, const char *argv[]) } -#include -#include -#include -#include -#include "./include/IOKit/hid/IOHIDEventTypes.h" -#include "./include/IOKit/hidsystem/IOHIDUsageTables.h" +#import +#import +#import +#import +#import "./include/IOKit/hid/IOHIDEventTypes.h" +#import "./include/IOKit/hidsystem/IOHIDUsageTables.h" typedef uint32_t IOHIDDigitizerTransducerType;