//
//  XSHackIos.h
//  nochange
//
//  Created by mac on 2024/10/15.
//

#ifndef XSHackIos_h
#define XSHackIos_h

#import <UIKit/UIApplication.h>
#include <ftw.h>
#include <spawn.h>
#include <objc/runtime.h>
#include <dlfcn.h>
#import <UIKit/UIKit.h>
#include <sys/sysctl.h>
#import <sys/utsname.h>
#import <IOSurface/IOSurfaceObjC.h>
#import <IOSurface/IOSurfaceTypes.h>
#import <IOKit/IOKitLib.h>
#include <Security/SecBase.h>
#import <Security/Security.h>



typedef struct __SecTask *SecTaskRef;
typedef struct __SecTrust *SecTrustRef;

// 定义私有 API
@interface SecTask : NSObject
+ (SecTaskRef)createWithAuditToken:(audit_token_t)token;
+ (SecTaskRef)createWithPID:(pid_t)pid;
- (CFTypeRef)copyValueForEntitlement:(CFStringRef)entitlement error:(CFErrorRef*)error;
@end


OBJC_EXTERN UIImage *_UICreateScreenUIImage(void);
OBJC_EXTERN void CARenderServerRenderDisplay(kern_return_t a, CFStringRef b, IOSurfaceRef surface, int x, int y);
OBJC_EXTERN kern_return_t IOSurfaceLock(IOSurfaceRef buffer, IOSurfaceLockOptions options, uint32_t *seed);
OBJC_EXTERN kern_return_t IOSurfaceUnLock(IOSurfaceRef buffer, IOSurfaceLockOptions options, uint32_t *seed);
OBJC_EXTERN IOSurfaceRef IOSurfaceCreate(CFDictionaryRef dictionary);
OBJC_EXTERN CGImageRef UICreateCGImageFromIOSurface(IOSurfaceRef surface);
OBJC_EXTERN SecTaskRef SecTaskCreateFromSelf(CFAllocatorRef);
OBJC_EXTERN CFTypeRef SecTaskCopyValueForEntitlement(SecTaskRef, CFStringRef entitlement, CFErrorRef*);
// 定义函数指针类型
// 定义函数指针类型
typedef Boolean (*SecTaskSetEntitlementsPtr)(SecTaskRef task, CFDictionaryRef entitlements);

@interface SBApplication : NSObject {
}
@property (nonatomic, retain, readonly) NSString *displayIdentifier NS_DEPRECATED_IOS(4_0, 8_0);
@property (nonatomic, retain, readonly) NSString *bundleIdentifier NS_AVAILABLE_IOS(8_0); // Technically available in iOS 5 as well (https://github.com/MP0w/iOS-Headers/blob/master/iOS5.0/SpringBoard/SB.h#L143) and even iOS 4, but you probably don't want to use that (see: Camera/Photos).
@property (nonatomic, retain, readonly) NSString *displayName;

- (void)activate;

@end

@interface SBApplicationController : NSObject
+ (id)sharedInstance;
- (SBApplication *)applicationWithBundleIdentifier:(NSString *)bundleID;
@end

@interface SpringBoard : NSObject
- (NSArray *)activeAlertItems;
- (id)_accessibilityFrontMostApplication;
- (void)_simulateHomeButtonPress;
@end

@interface UIImage (Private)
+ (UIImage *)_applicationIconImageForBundleIdentifier:(NSString *)bundleIdentifier format:(int)format scale:(CGFloat)scale;
@end

@interface SBLockScreenManager
+(id)sharedInstance;
-(void)unlockUIFromSource:(int)source withOptions:(id)options;
@property(readonly, assign) BOOL isUILocked;
@end


@interface SBUserAgent : NSObject
+ (id)sharedUserAgent;
- (void)lockAndDimDevice;
- (void)undimScreen;
- (void)unlockDevice;
@end

@interface SBUIController : NSObject
+ (id)sharedInstance;
- (BOOL)isOnLockScreen;
@end



@interface FBSSystemService : NSObject
+ (id)sharedService;
- (void)openApplication:(NSString *)bundleID
            options:(NSDictionary *)options
            clientPort:(mach_port_t)clientPort
            withResult:(void(^)(NSError *error))callback;
@end



int XSRuncmd(char *args[]);

void XSSystem(const char *cmd);
NSString* XSFrontMostAppId(void);
int XSReboot(void);
int XSKillApp(NSString *appexe);
int XSKillAppByName(NSString *pkgName);
int XSBringAppForeground(NSString *appIdentifier);
void activateApp(NSString *bundleID);
void bringAppToForeground(NSString *bundleID);
UIImage* XSCcaptureScreen2(void);
NSArray* XSGetApps(void);
void XSRemoteUnlock(void);
void XSClearAll(NSString *appId);
NSString* XSGetAppInfoPath(NSString *app);
NSDictionary* XSGetAppInfo(NSString *appInfoPlist);
void XSSaveAppInfo(NSDictionary *dic, NSString *appInfoPath);
BOOL injectEntitlementsWithOptions(NSDictionary *options, NSError **error);
BOOL verifyEntitlement(NSString *entitlementName);
void injectNetworkPermissions(void);
pid_t system2(const char * command, int * infp, int * outfp);

void getAllButtons(void);
#endif /* XSHackIos_h */
