2013-08-19 03:17:33 +00:00
|
|
|
// main.mm boilerplate
|
2024-05-21 12:48:28 +00:00
|
|
|
//
|
|
|
|
// Overview
|
|
|
|
//
|
|
|
|
// main.mm: JIT enablement, starting the next step
|
|
|
|
// AppDelegate.mm: Runs NativeInit, launches the main ViewController
|
|
|
|
// ViewController.mm: The main application window
|
2013-02-17 14:04:44 +00:00
|
|
|
|
|
|
|
#import <UIKit/UIKit.h>
|
2020-02-23 09:27:25 +00:00
|
|
|
#import <dlfcn.h>
|
|
|
|
#import <mach/mach.h>
|
2023-12-10 12:06:25 +00:00
|
|
|
#import <mach-o/loader.h>
|
|
|
|
#import <mach-o/getsect.h>
|
2020-02-23 09:27:25 +00:00
|
|
|
#import <pthread.h>
|
2023-12-10 12:06:25 +00:00
|
|
|
#import <spawn.h>
|
2022-04-02 23:07:51 +00:00
|
|
|
#import <signal.h>
|
2013-08-19 03:17:33 +00:00
|
|
|
#import <string>
|
2014-02-12 09:26:53 +00:00
|
|
|
#import <stdio.h>
|
|
|
|
#import <stdlib.h>
|
2016-08-28 16:10:26 +00:00
|
|
|
#import <sys/syscall.h>
|
2023-12-10 12:06:25 +00:00
|
|
|
#import <sys/utsname.h>
|
2014-05-22 06:20:43 +00:00
|
|
|
#import <AudioToolbox/AudioToolbox.h>
|
2013-02-17 14:04:44 +00:00
|
|
|
|
|
|
|
#import "AppDelegate.h"
|
2017-09-04 07:05:46 +00:00
|
|
|
#import "PPSSPPUIApplication.h"
|
2018-02-22 11:04:12 +00:00
|
|
|
#import "ViewController.h"
|
2013-02-17 14:04:44 +00:00
|
|
|
|
2021-02-21 21:02:11 +00:00
|
|
|
#include "Common/MemoryUtil.h"
|
2020-10-04 08:30:18 +00:00
|
|
|
#include "Common/System/NativeApp.h"
|
|
|
|
#include "Common/System/System.h"
|
2023-03-22 15:20:30 +00:00
|
|
|
#include "Common/System/Request.h"
|
2021-02-21 21:02:11 +00:00
|
|
|
#include "Common/StringUtils.h"
|
2020-10-04 08:04:01 +00:00
|
|
|
#include "Common/Profiler/Profiler.h"
|
2023-07-20 09:26:20 +00:00
|
|
|
#include "Core/Config.h"
|
2023-12-10 12:06:25 +00:00
|
|
|
#include "Common/Log.h"
|
2023-02-01 16:03:12 +00:00
|
|
|
#include "UI/DarwinFileSystemServices.h"
|
2013-09-06 08:12:48 +00:00
|
|
|
|
2024-05-02 18:41:56 +00:00
|
|
|
// Compile out all the hackery in app store builds.
|
|
|
|
#if !PPSSPP_PLATFORM(IOS_APP_STORE)
|
|
|
|
|
2023-12-10 12:06:25 +00:00
|
|
|
struct cs_blob_index {
|
|
|
|
uint32_t type;
|
|
|
|
uint32_t offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct cs_superblob {
|
|
|
|
uint32_t magic;
|
|
|
|
uint32_t length;
|
|
|
|
uint32_t count;
|
|
|
|
struct cs_blob_index index[];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct cs_entitlements {
|
|
|
|
uint32_t magic;
|
|
|
|
uint32_t length;
|
|
|
|
char entitlements[];
|
|
|
|
};
|
|
|
|
|
2020-02-23 09:27:25 +00:00
|
|
|
static int (*csops)(pid_t pid, unsigned int ops, void * useraddr, size_t usersize);
|
|
|
|
static boolean_t (*exc_server)(mach_msg_header_t *, mach_msg_header_t *);
|
|
|
|
static int (*ptrace)(int request, pid_t pid, caddr_t addr, int data);
|
|
|
|
|
2021-03-01 21:40:55 +00:00
|
|
|
#define CS_OPS_STATUS 0 /* return status */
|
2023-12-10 14:34:26 +00:00
|
|
|
#define CS_KILL 0x00000200 /* kill process if it becomes invalid */
|
2021-03-01 21:40:55 +00:00
|
|
|
#define CS_DEBUGGED 0x10000000 /* process is currently or has previously been debugged and allowed to run with invalid pages */
|
2023-12-10 14:34:26 +00:00
|
|
|
#define PT_TRACE_ME 0 /* child declares it's being traced */
|
|
|
|
#define PT_SIGEXC 12 /* signals as exceptions for current_proc */
|
2021-03-01 21:40:55 +00:00
|
|
|
#define ptrace(a, b, c, d) syscall(SYS_ptrace, a, b, c, d)
|
|
|
|
|
2023-12-10 12:06:25 +00:00
|
|
|
static void *exception_handler(void *argument) {
|
|
|
|
mach_port_t port = *(mach_port_t *)argument;
|
|
|
|
mach_msg_server(exc_server, 2048, port, 0);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NSDictionary *parse_entitlements(const void *entitlements, size_t length) {
|
|
|
|
char *copy = (char *)malloc(length);
|
|
|
|
memcpy(copy, entitlements, length);
|
|
|
|
|
|
|
|
// strip out psychic paper entitlement hiding
|
|
|
|
if (@available(iOS 13.5, *)) {
|
|
|
|
} else {
|
|
|
|
static const char *needle = "<!---><!-->";
|
|
|
|
char *found = strnstr(copy, needle, length);
|
|
|
|
if (found) {
|
|
|
|
memset(found, ' ', strlen(needle));
|
2021-03-01 21:40:55 +00:00
|
|
|
}
|
2023-12-10 12:06:25 +00:00
|
|
|
}
|
|
|
|
NSData *data = [NSData dataWithBytes:copy length:length];
|
|
|
|
free(copy);
|
|
|
|
|
|
|
|
return [NSPropertyListSerialization propertyListWithData:data
|
|
|
|
options:NSPropertyListImmutable
|
|
|
|
format:nil
|
|
|
|
error:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
static NSDictionary *app_entitlements(void) {
|
|
|
|
// Inspired by codesign.c in Darwin sources for Security.framework
|
|
|
|
|
|
|
|
// Find our mach-o header
|
|
|
|
Dl_info dl_info;
|
|
|
|
if (dladdr((const void *)app_entitlements, &dl_info) == 0)
|
|
|
|
return nil;
|
|
|
|
if (dl_info.dli_fbase == NULL)
|
|
|
|
return nil;
|
|
|
|
char *base = (char *)dl_info.dli_fbase;
|
|
|
|
struct mach_header_64 *header = (struct mach_header_64 *)dl_info.dli_fbase;
|
|
|
|
if (header->magic != MH_MAGIC_64)
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
// Simulator executables have fake entitlements in the code signature. The real entitlements can be found in an __entitlements section.
|
|
|
|
size_t entitlements_size;
|
|
|
|
uint8_t *entitlements_data = getsectiondata(header, "__TEXT", "__entitlements", &entitlements_size);
|
|
|
|
if (entitlements_data != NULL) {
|
|
|
|
NSData *data = [NSData dataWithBytesNoCopy:entitlements_data
|
|
|
|
length:entitlements_size
|
|
|
|
freeWhenDone:NO];
|
|
|
|
return [NSPropertyListSerialization propertyListWithData:data
|
|
|
|
options:NSPropertyListImmutable
|
|
|
|
format:nil
|
|
|
|
error:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the LC_CODE_SIGNATURE
|
|
|
|
struct load_command *lc = (struct load_command *) (base + sizeof(*header));
|
|
|
|
struct linkedit_data_command *cs_lc = NULL;
|
|
|
|
for (uint32_t i = 0; i < header->ncmds; i++) {
|
|
|
|
if (lc->cmd == LC_CODE_SIGNATURE) {
|
|
|
|
cs_lc = (struct linkedit_data_command *) lc;
|
|
|
|
break;
|
2021-03-01 21:40:55 +00:00
|
|
|
}
|
2023-12-10 12:06:25 +00:00
|
|
|
lc = (struct load_command *) ((char *) lc + lc->cmdsize);
|
|
|
|
}
|
|
|
|
if (cs_lc == NULL)
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
// Read the code signature off disk, as it's apparently not loaded into memory
|
|
|
|
NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingFromURL:NSBundle.mainBundle.executableURL error:nil];
|
|
|
|
if (fileHandle == nil)
|
|
|
|
return nil;
|
|
|
|
[fileHandle seekToFileOffset:cs_lc->dataoff];
|
|
|
|
NSData *csData = [fileHandle readDataOfLength:cs_lc->datasize];
|
|
|
|
[fileHandle closeFile];
|
|
|
|
const struct cs_superblob *cs = (const struct cs_superblob *)csData.bytes;
|
|
|
|
if (ntohl(cs->magic) != 0xfade0cc0)
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
// Find the entitlements in the code signature
|
|
|
|
for (uint32_t i = 0; i < ntohl(cs->count); i++) {
|
|
|
|
struct cs_entitlements *ents = (struct cs_entitlements *) ((char *) cs + ntohl(cs->index[i].offset));
|
|
|
|
if (ntohl(ents->magic) == 0xfade7171) {
|
|
|
|
return parse_entitlements(ents->entitlements, ntohl(ents->length) - offsetof(struct cs_entitlements, entitlements));
|
2021-03-01 21:40:55 +00:00
|
|
|
}
|
|
|
|
}
|
2023-12-10 12:06:25 +00:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NSDictionary *cached_app_entitlements(void) {
|
|
|
|
static NSDictionary *entitlements = nil;
|
|
|
|
if (!entitlements) {
|
|
|
|
entitlements = app_entitlements();
|
|
|
|
}
|
|
|
|
return entitlements;
|
|
|
|
}
|
2021-03-01 21:40:55 +00:00
|
|
|
|
2023-12-10 12:06:25 +00:00
|
|
|
bool jb_has_container(void) {
|
|
|
|
NSDictionary *entitlements = cached_app_entitlements();
|
|
|
|
return ![entitlements[@"com.apple.private.security.no-sandbox"] boolValue];
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *childArgv[] = {NULL, "debugme", NULL};
|
|
|
|
|
|
|
|
bool jb_spawn_ptrace_child(int argc, char **argv) {
|
|
|
|
int ret; pid_t pid;
|
|
|
|
|
|
|
|
if (argc > 1 && strcmp(argv[1], childArgv[1]) == 0) {
|
|
|
|
ret = ptrace(PT_TRACE_ME, 0, NULL, 0);
|
|
|
|
NSLog(@"child: ptrace(PT_TRACE_ME) %d", ret);
|
|
|
|
exit(ret);
|
|
|
|
}
|
|
|
|
if (jb_has_container()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
childArgv[0] = argv[0];
|
|
|
|
if ((ret = posix_spawnp(&pid, argv[0], NULL, NULL, (char *const *)childArgv, NULL)) != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2020-02-23 09:27:25 +00:00
|
|
|
}
|
2019-10-15 01:22:00 +00:00
|
|
|
|
2023-12-10 12:06:25 +00:00
|
|
|
bool jb_has_jit_entitlement(void) {
|
|
|
|
NSDictionary *entitlements = cached_app_entitlements();
|
|
|
|
return [entitlements[@"dynamic-codesigning"] boolValue];
|
2020-02-23 09:27:25 +00:00
|
|
|
}
|
2019-10-15 01:22:00 +00:00
|
|
|
|
2023-12-10 12:06:25 +00:00
|
|
|
bool jb_has_cs_disabled(void) {
|
|
|
|
int flags;
|
|
|
|
return !csops(getpid(), CS_OPS_STATUS, &flags, sizeof(flags)) && (flags & ~CS_KILL) == flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define _COMM_PAGE_START_ADDRESS (0x0000000FFFFFC000ULL) /* In TTBR0 */
|
|
|
|
#define _COMM_PAGE_APRR_SUPPORT (_COMM_PAGE_START_ADDRESS+0x10C)
|
|
|
|
|
|
|
|
static bool is_device_A12_or_newer(void) {
|
|
|
|
// devices without APRR are definitely < A12
|
|
|
|
char aprr_support = *(volatile char *)_COMM_PAGE_APRR_SUPPORT;
|
|
|
|
if (aprr_support == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// we still have A11 devices that support APRR
|
|
|
|
struct utsname systemInfo;
|
|
|
|
if (uname(&systemInfo) != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// iPhone 8, 8 Plus, and iPhone X
|
|
|
|
if (strncmp("iPhone10,", systemInfo.machine, 9) == 0) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool jb_has_cs_execseg_allow_unsigned(void) {
|
|
|
|
NSDictionary *entitlements = cached_app_entitlements();
|
|
|
|
if (@available(iOS 14.2, *)) {
|
|
|
|
if (@available(iOS 14.4, *)) {
|
|
|
|
return false; // iOS 14.4 broke it again
|
|
|
|
}
|
|
|
|
// technically we need to check the Code Directory and make sure
|
|
|
|
// CS_EXECSEG_ALLOW_UNSIGNED is set but we assume that it is properly
|
|
|
|
// signed, which should reflect the get-task-allow entitlement
|
|
|
|
return is_device_A12_or_newer() && [entitlements[@"get-task-allow"] boolValue];
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool jb_has_debugger_attached(void) {
|
|
|
|
int flags;
|
|
|
|
return !csops(getpid(), CS_OPS_STATUS, &flags, sizeof(flags)) && flags & CS_DEBUGGED;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool jb_enable_ptrace_hack(void) {
|
|
|
|
bool debugged = jb_has_debugger_attached();
|
|
|
|
|
|
|
|
// Thanks to this comment: https://news.ycombinator.com/item?id=18431524
|
|
|
|
// We use this hack to allow mmap with PROT_EXEC (which usually requires the
|
|
|
|
// dynamic-codesigning entitlement) by tricking the process into thinking
|
|
|
|
// that Xcode is debugging it. We abuse the fact that JIT is needed to
|
|
|
|
// debug the process.
|
|
|
|
if (ptrace(PT_TRACE_ME, 0, NULL, 0) < 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ptracing ourselves confuses the kernel and will cause bad things to
|
|
|
|
// happen to the system (hangs…) if an exception or signal occurs. Setup
|
|
|
|
// some "safety nets" so we can cause the process to exit in a somewhat sane
|
|
|
|
// state. We only need to do this if the debugger isn't attached. (It'll do
|
|
|
|
// this itself, and if we do it we'll interfere with its normal operation
|
|
|
|
// anyways.)
|
|
|
|
if (!debugged) {
|
|
|
|
// First, ensure that signals are delivered as Mach software exceptions…
|
|
|
|
ptrace(PT_SIGEXC, 0, NULL, 0);
|
|
|
|
|
|
|
|
// …then ensure that this exception goes through our exception handler.
|
|
|
|
// I think it's OK to just watch for EXC_SOFTWARE because the other
|
|
|
|
// exceptions (e.g. EXC_BAD_ACCESS, EXC_BAD_INSTRUCTION, and friends)
|
|
|
|
// will end up being delivered as signals anyways, and we can get them
|
|
|
|
// once they're resent as a software exception.
|
|
|
|
mach_port_t port = MACH_PORT_NULL;
|
|
|
|
mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &port);
|
|
|
|
mach_port_insert_right(mach_task_self(), port, port, MACH_MSG_TYPE_MAKE_SEND);
|
|
|
|
task_set_exception_ports(mach_task_self(), EXC_MASK_SOFTWARE, port, EXCEPTION_DEFAULT, THREAD_STATE_NONE);
|
|
|
|
pthread_t thread;
|
|
|
|
pthread_create(&thread, NULL, exception_handler, (void *)&port);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2019-10-15 01:22:00 +00:00
|
|
|
}
|
2024-05-02 18:41:56 +00:00
|
|
|
#endif
|
2015-11-03 18:57:10 +00:00
|
|
|
|
2023-03-22 22:25:00 +00:00
|
|
|
float g_safeInsetLeft = 0.0;
|
|
|
|
float g_safeInsetRight = 0.0;
|
|
|
|
float g_safeInsetTop = 0.0;
|
|
|
|
float g_safeInsetBottom = 0.0;
|
2020-03-31 16:45:39 +00:00
|
|
|
|
2022-08-13 09:15:21 +00:00
|
|
|
// We no longer need to judge if jit is usable or not by according to the ios version.
|
2023-12-10 12:06:25 +00:00
|
|
|
static bool g_jitAvailable = true;
|
|
|
|
//static int g_iosVersionMinor;
|
|
|
|
|
2022-08-13 09:56:27 +00:00
|
|
|
static int g_iosVersionMajor;
|
2022-08-13 18:42:05 +00:00
|
|
|
static std::string version;
|
2015-11-03 18:57:10 +00:00
|
|
|
|
2013-09-04 09:29:38 +00:00
|
|
|
std::string System_GetProperty(SystemProperty prop) {
|
|
|
|
switch (prop) {
|
2019-03-27 02:01:20 +00:00
|
|
|
case SYSPROP_NAME:
|
2022-08-13 09:56:27 +00:00
|
|
|
return StringFromFormat("iOS %s", version.c_str());
|
2019-03-27 02:01:20 +00:00
|
|
|
case SYSPROP_LANGREGION:
|
2022-08-13 09:15:21 +00:00
|
|
|
return [[[NSLocale currentLocale] objectForKey:NSLocaleIdentifier] UTF8String];
|
2023-07-20 07:56:51 +00:00
|
|
|
case SYSPROP_BUILD_VERSION:
|
|
|
|
return PPSSPP_GIT_VERSION;
|
2019-03-27 02:01:20 +00:00
|
|
|
default:
|
|
|
|
return "";
|
2013-09-04 09:29:38 +00:00
|
|
|
}
|
2013-08-19 03:17:33 +00:00
|
|
|
}
|
|
|
|
|
2021-01-06 15:37:04 +00:00
|
|
|
std::vector<std::string> System_GetPropertyStringVec(SystemProperty prop) {
|
|
|
|
switch (prop) {
|
2021-01-09 22:45:49 +00:00
|
|
|
case SYSPROP_TEMP_DIRS:
|
2021-01-06 15:37:04 +00:00
|
|
|
default:
|
|
|
|
return std::vector<std::string>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-05 09:07:57 +00:00
|
|
|
int64_t System_GetPropertyInt(SystemProperty prop) {
|
2016-08-28 16:07:54 +00:00
|
|
|
switch (prop) {
|
2019-03-27 02:01:20 +00:00
|
|
|
case SYSPROP_AUDIO_SAMPLE_RATE:
|
|
|
|
return 44100;
|
|
|
|
case SYSPROP_DEVICE_TYPE:
|
|
|
|
return DEVICE_TYPE_MOBILE;
|
2021-02-21 21:02:11 +00:00
|
|
|
case SYSPROP_SYSTEMVERSION:
|
|
|
|
return g_iosVersionMajor;
|
2019-03-27 02:01:20 +00:00
|
|
|
default:
|
|
|
|
return -1;
|
2017-04-30 00:35:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-05 17:04:07 +00:00
|
|
|
float System_GetPropertyFloat(SystemProperty prop) {
|
|
|
|
switch (prop) {
|
|
|
|
case SYSPROP_DISPLAY_REFRESH_RATE:
|
|
|
|
return 60.f;
|
2020-03-31 16:45:39 +00:00
|
|
|
case SYSPROP_DISPLAY_SAFE_INSET_LEFT:
|
|
|
|
return g_safeInsetLeft;
|
|
|
|
case SYSPROP_DISPLAY_SAFE_INSET_RIGHT:
|
|
|
|
return g_safeInsetRight;
|
|
|
|
case SYSPROP_DISPLAY_SAFE_INSET_TOP:
|
|
|
|
return g_safeInsetTop;
|
|
|
|
case SYSPROP_DISPLAY_SAFE_INSET_BOTTOM:
|
|
|
|
return g_safeInsetBottom;
|
2020-01-05 17:04:07 +00:00
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-30 00:35:12 +00:00
|
|
|
bool System_GetPropertyBool(SystemProperty prop) {
|
|
|
|
switch (prop) {
|
2024-05-10 08:39:58 +00:00
|
|
|
case SYSPROP_HAS_FILE_BROWSER:
|
|
|
|
return true;
|
|
|
|
case SYSPROP_HAS_FOLDER_BROWSER:
|
|
|
|
return true;
|
2023-02-02 13:54:50 +00:00
|
|
|
case SYSPROP_HAS_OPEN_DIRECTORY:
|
|
|
|
return false;
|
2019-03-27 02:01:20 +00:00
|
|
|
case SYSPROP_HAS_BACK_BUTTON:
|
|
|
|
return false;
|
2023-11-06 23:44:43 +00:00
|
|
|
case SYSPROP_HAS_ACCELEROMETER:
|
|
|
|
return true;
|
2024-05-20 16:33:35 +00:00
|
|
|
case SYSPROP_HAS_KEYBOARD:
|
|
|
|
return true;
|
|
|
|
case SYSPROP_KEYBOARD_IS_SOFT:
|
|
|
|
// If a hardware keyboard is connected, and we add support, we could return false here.
|
|
|
|
return true;
|
2019-03-27 02:01:20 +00:00
|
|
|
case SYSPROP_APP_GOLD:
|
2017-04-05 14:21:08 +00:00
|
|
|
#ifdef GOLD
|
2019-03-27 02:01:20 +00:00
|
|
|
return true;
|
2017-04-05 14:21:08 +00:00
|
|
|
#else
|
2019-03-27 02:01:20 +00:00
|
|
|
return false;
|
2017-04-05 14:21:08 +00:00
|
|
|
#endif
|
2021-02-21 21:02:11 +00:00
|
|
|
case SYSPROP_CAN_JIT:
|
2023-12-10 12:06:25 +00:00
|
|
|
return g_jitAvailable;
|
2024-05-03 15:54:57 +00:00
|
|
|
case SYSPROP_LIMITED_FILE_BROWSING:
|
2024-05-05 12:13:10 +00:00
|
|
|
#if PPSSPP_PLATFORM(IOS_APP_STORE)
|
|
|
|
return true;
|
|
|
|
#else
|
2024-05-03 15:54:57 +00:00
|
|
|
return false; // But will return true in app store builds.
|
2024-05-05 12:13:10 +00:00
|
|
|
#endif
|
2023-07-20 14:01:51 +00:00
|
|
|
#ifndef HTTPS_NOT_AVAILABLE
|
|
|
|
case SYSPROP_SUPPORTS_HTTPS:
|
|
|
|
return true;
|
|
|
|
#endif
|
2019-03-27 02:01:20 +00:00
|
|
|
default:
|
|
|
|
return false;
|
2016-08-28 16:07:54 +00:00
|
|
|
}
|
2015-01-11 18:30:25 +00:00
|
|
|
}
|
2014-07-20 10:11:50 +00:00
|
|
|
|
2023-03-21 10:10:09 +00:00
|
|
|
void System_Notify(SystemNotification notification) {
|
|
|
|
switch (notification) {
|
2024-05-06 10:11:54 +00:00
|
|
|
default: break;
|
2023-03-21 10:10:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-06 10:04:45 +00:00
|
|
|
bool System_MakeRequest(SystemRequestType type, int requestId, const std::string ¶m1, const std::string ¶m2, int64_t param3, int64_t param4) {
|
2023-03-22 15:20:30 +00:00
|
|
|
switch (type) {
|
2023-03-22 21:07:29 +00:00
|
|
|
case SystemRequestType::EXIT_APP:
|
|
|
|
exit(0);
|
|
|
|
// The below seems right, but causes hangs. See #12140.
|
|
|
|
// dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
// [sharedViewController shutdown];
|
|
|
|
// exit(0);
|
|
|
|
// });
|
|
|
|
break;
|
2023-03-22 16:57:28 +00:00
|
|
|
case SystemRequestType::BROWSE_FOR_FILE:
|
2023-03-22 15:20:30 +00:00
|
|
|
{
|
2023-03-22 16:57:28 +00:00
|
|
|
DarwinDirectoryPanelCallback callback = [requestId] (bool success, Path path) {
|
2023-03-22 15:20:30 +00:00
|
|
|
if (success) {
|
2023-03-22 16:57:28 +00:00
|
|
|
g_requestManager.PostSystemSuccess(requestId, path.c_str());
|
2023-03-22 15:20:30 +00:00
|
|
|
} else {
|
|
|
|
g_requestManager.PostSystemFailure(requestId);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
DarwinFileSystemServices services;
|
2023-03-22 16:57:28 +00:00
|
|
|
services.presentDirectoryPanel(callback, /* allowFiles = */ true, /* allowDirectories = */ false);
|
|
|
|
return true;
|
2023-03-22 15:20:30 +00:00
|
|
|
}
|
2023-03-22 16:57:28 +00:00
|
|
|
case SystemRequestType::BROWSE_FOR_FOLDER:
|
|
|
|
{
|
|
|
|
DarwinDirectoryPanelCallback callback = [requestId] (bool success, Path path) {
|
|
|
|
if (success) {
|
|
|
|
g_requestManager.PostSystemSuccess(requestId, path.c_str());
|
|
|
|
} else {
|
|
|
|
g_requestManager.PostSystemFailure(requestId);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
DarwinFileSystemServices services;
|
|
|
|
services.presentDirectoryPanel(callback, /* allowFiles = */ false, /* allowDirectories = */ true);
|
|
|
|
return true;
|
2023-03-22 15:20:30 +00:00
|
|
|
}
|
2023-03-22 21:49:38 +00:00
|
|
|
case SystemRequestType::CAMERA_COMMAND:
|
|
|
|
if (!strncmp(param1.c_str(), "startVideo", 10)) {
|
|
|
|
int width = 0, height = 0;
|
|
|
|
sscanf(param1.c_str(), "startVideo_%dx%d", &width, &height);
|
|
|
|
setCameraSize(width, height);
|
|
|
|
startVideo();
|
|
|
|
} else if (!strcmp(param1.c_str(), "stopVideo")) {
|
|
|
|
stopVideo();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case SystemRequestType::GPS_COMMAND:
|
|
|
|
if (param1 == "open") {
|
|
|
|
startLocation();
|
2023-03-22 22:25:00 +00:00
|
|
|
} else if (param1 == "close") {
|
2023-03-22 21:49:38 +00:00
|
|
|
stopLocation();
|
|
|
|
}
|
|
|
|
return true;
|
2023-03-22 21:55:53 +00:00
|
|
|
case SystemRequestType::SHARE_TEXT:
|
|
|
|
{
|
|
|
|
NSString *text = [NSString stringWithUTF8String:param1.c_str()];
|
|
|
|
[sharedViewController shareText:text];
|
|
|
|
return true;
|
|
|
|
}
|
2024-05-20 16:33:35 +00:00
|
|
|
case SystemRequestType::NOTIFY_UI_EVENT:
|
|
|
|
{
|
|
|
|
switch ((UIEventNotification)param3) {
|
|
|
|
case UIEventNotification::POPUP_CLOSED:
|
|
|
|
[sharedViewController hideKeyboard];
|
|
|
|
break;
|
|
|
|
case UIEventNotification::TEXT_GOTFOCUS:
|
|
|
|
[sharedViewController showKeyboard];
|
|
|
|
break;
|
|
|
|
case UIEventNotification::TEXT_LOSTFOCUS:
|
|
|
|
[sharedViewController hideKeyboard];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2024-05-20 13:38:04 +00:00
|
|
|
/*
|
|
|
|
// Not 100% sure the threading is right
|
|
|
|
case SystemRequestType::COPY_TO_CLIPBOARD:
|
|
|
|
{
|
|
|
|
@autoreleasepool {
|
|
|
|
[UIPasteboard generalPasteboard].string = @(param1.c_str());
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
2024-05-20 12:27:42 +00:00
|
|
|
case SystemRequestType::SET_KEEP_SCREEN_BRIGHT:
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
INFO_LOG(SYSTEM, "SET_KEEP_SCREEN_BRIGHT: %d", (int)param3);
|
|
|
|
[[UIApplication sharedApplication] setIdleTimerDisabled: (param3 ? YES : NO)];
|
|
|
|
});
|
|
|
|
return true;
|
2023-03-22 21:49:38 +00:00
|
|
|
default:
|
|
|
|
return false;
|
2023-03-22 15:20:30 +00:00
|
|
|
}
|
2023-03-22 11:26:14 +00:00
|
|
|
}
|
|
|
|
|
2024-01-19 12:44:49 +00:00
|
|
|
void System_Toast(std::string_view text) {}
|
2015-12-17 21:41:50 +00:00
|
|
|
void System_AskForPermission(SystemPermission permission) {}
|
2022-07-10 20:34:44 +00:00
|
|
|
|
2015-12-17 21:41:50 +00:00
|
|
|
PermissionStatus System_GetPermissionStatus(SystemPermission permission) { return PERMISSION_STATUS_GRANTED; }
|
|
|
|
|
2024-05-07 10:41:21 +00:00
|
|
|
#if !PPSSPP_PLATFORM(IOS_APP_STORE)
|
2014-05-22 07:54:09 +00:00
|
|
|
FOUNDATION_EXTERN void AudioServicesPlaySystemSoundWithVibration(unsigned long, objc_object*, NSDictionary*);
|
2024-05-07 10:41:21 +00:00
|
|
|
#endif
|
2014-05-22 07:54:09 +00:00
|
|
|
|
2021-03-01 21:40:55 +00:00
|
|
|
BOOL SupportsTaptic() {
|
2019-03-27 02:01:20 +00:00
|
|
|
// we're on an iOS version that cannot instantiate UISelectionFeedbackGenerator, so no.
|
2021-03-01 21:40:55 +00:00
|
|
|
if(!NSClassFromString(@"UISelectionFeedbackGenerator")) {
|
2019-03-27 02:01:20 +00:00
|
|
|
return NO;
|
|
|
|
}
|
2020-01-05 17:04:07 +00:00
|
|
|
|
2019-03-27 02:01:20 +00:00
|
|
|
// http://www.mikitamanko.com/blog/2017/01/29/haptic-feedback-with-uifeedbackgenerator/
|
|
|
|
// use private API against UIDevice to determine the haptic stepping
|
|
|
|
// 2 - iPhone 7 or above, full taptic feedback
|
|
|
|
// 1 - iPhone 6S, limited taptic feedback
|
|
|
|
// 0 - iPhone 6 or below, no taptic feedback
|
|
|
|
NSNumber* val = (NSNumber*)[[UIDevice currentDevice] valueForKey:@"feedbackSupportLevel"];
|
|
|
|
return [val intValue] >= 2;
|
2018-01-14 18:38:04 +00:00
|
|
|
}
|
|
|
|
|
2023-03-21 09:42:23 +00:00
|
|
|
void System_Vibrate(int mode) {
|
2021-03-01 21:40:55 +00:00
|
|
|
if (SupportsTaptic()) {
|
2019-03-27 02:01:20 +00:00
|
|
|
PPSSPPUIApplication* app = (PPSSPPUIApplication*)[UIApplication sharedApplication];
|
|
|
|
if(app.feedbackGenerator == nil)
|
|
|
|
{
|
|
|
|
app.feedbackGenerator = [[UISelectionFeedbackGenerator alloc] init];
|
|
|
|
[app.feedbackGenerator prepare];
|
|
|
|
}
|
|
|
|
[app.feedbackGenerator selectionChanged];
|
2021-03-01 21:40:55 +00:00
|
|
|
} else {
|
2024-05-07 10:41:21 +00:00
|
|
|
#if !PPSSPP_PLATFORM(IOS_APP_STORE)
|
2019-03-27 02:01:20 +00:00
|
|
|
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
|
|
|
|
NSArray *pattern = @[@YES, @30, @NO, @2];
|
2020-01-05 17:04:07 +00:00
|
|
|
|
2019-03-27 02:01:20 +00:00
|
|
|
dictionary[@"VibePattern"] = pattern;
|
|
|
|
dictionary[@"Intensity"] = @2;
|
2020-01-05 17:04:07 +00:00
|
|
|
|
2019-03-27 02:01:20 +00:00
|
|
|
AudioServicesPlaySystemSoundWithVibration(kSystemSoundID_Vibrate, nil, dictionary);
|
2024-05-07 10:41:21 +00:00
|
|
|
#endif
|
2019-03-27 02:01:20 +00:00
|
|
|
}
|
2013-10-13 19:12:36 +00:00
|
|
|
}
|
|
|
|
|
2013-02-17 14:04:44 +00:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2022-08-13 18:42:05 +00:00
|
|
|
version = [[[UIDevice currentDevice] systemVersion] UTF8String];
|
2022-08-13 09:56:27 +00:00
|
|
|
if (2 != sscanf(version.c_str(), "%d", &g_iosVersionMajor)) {
|
2021-02-21 21:02:11 +00:00
|
|
|
// Just set it to 14.0 if the parsing fails for whatever reason.
|
|
|
|
g_iosVersionMajor = 14;
|
|
|
|
}
|
|
|
|
|
2024-05-02 18:41:56 +00:00
|
|
|
#if PPSSPP_PLATFORM(IOS_APP_STORE)
|
|
|
|
g_jitAvailable = false;
|
|
|
|
#else
|
|
|
|
// Hacky hacks to try to enable JIT by pretending to be a debugger.
|
|
|
|
csops = reinterpret_cast<decltype(csops)>(dlsym(dlopen(nullptr, RTLD_LAZY), "csops"));
|
|
|
|
exc_server = reinterpret_cast<decltype(exc_server)>(dlsym(dlopen(NULL, RTLD_LAZY), "exc_server"));
|
|
|
|
ptrace = reinterpret_cast<decltype(ptrace)>(dlsym(dlopen(NULL, RTLD_LAZY), "ptrace"));
|
|
|
|
// see https://github.com/hrydgard/ppsspp/issues/11905
|
|
|
|
|
2023-12-10 12:06:25 +00:00
|
|
|
if (jb_spawn_ptrace_child(argc, argv)) {
|
|
|
|
INFO_LOG(SYSTEM, "JIT: ptrace() child spawn trick\n");
|
|
|
|
} else if (jb_has_jit_entitlement()) {
|
|
|
|
INFO_LOG(SYSTEM, "JIT: found entitlement\n");
|
|
|
|
} else if (jb_has_cs_disabled()) {
|
|
|
|
INFO_LOG(SYSTEM, "JIT: CS_KILL disabled\n");
|
|
|
|
} else if (jb_has_cs_execseg_allow_unsigned()) {
|
|
|
|
INFO_LOG(SYSTEM, "JIT: CS_EXECSEG_ALLOW_UNSIGNED set\n");
|
|
|
|
} else if (jb_enable_ptrace_hack()) {
|
|
|
|
INFO_LOG(SYSTEM, "JIT: ptrace() hack supported\n");
|
|
|
|
} else {
|
|
|
|
INFO_LOG(SYSTEM, "JIT: ptrace() hack failed\n");
|
|
|
|
g_jitAvailable = false;
|
|
|
|
}
|
2022-08-13 09:15:21 +00:00
|
|
|
|
2024-05-02 18:41:56 +00:00
|
|
|
// Tried checking for JIT support here with AllocateExecutableMemory and ProtectMemoryPages,
|
|
|
|
// but it just succeeds, and then fails when you try to execute from it.
|
|
|
|
|
|
|
|
// So, we'll just resort to a version check.
|
|
|
|
// TODO: This seems outdated.
|
2023-12-10 12:06:25 +00:00
|
|
|
/*
|
2021-03-01 12:04:55 +00:00
|
|
|
if (g_iosVersionMajor > 14 || (g_iosVersionMajor == 14 && g_iosVersionMinor >= 4)) {
|
2021-02-21 21:02:11 +00:00
|
|
|
g_jitAvailable = false;
|
|
|
|
} else {
|
|
|
|
g_jitAvailable = true;
|
|
|
|
}
|
2021-03-01 21:40:55 +00:00
|
|
|
*/
|
2024-05-02 18:41:56 +00:00
|
|
|
#endif
|
2020-01-05 17:04:07 +00:00
|
|
|
|
2022-04-02 23:07:51 +00:00
|
|
|
// Ignore sigpipe.
|
|
|
|
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
|
|
|
|
perror("Unable to ignore SIGPIPE");
|
|
|
|
}
|
2024-05-02 18:41:56 +00:00
|
|
|
PROFILE_INIT();
|
2022-04-02 23:07:51 +00:00
|
|
|
|
2013-02-17 14:04:44 +00:00
|
|
|
@autoreleasepool {
|
2018-01-02 02:51:18 +00:00
|
|
|
return UIApplicationMain(argc, argv, NSStringFromClass([PPSSPPUIApplication class]), NSStringFromClass([AppDelegate class]));
|
2013-02-17 14:04:44 +00:00
|
|
|
}
|
|
|
|
}
|
2024-05-20 14:12:25 +00:00
|
|
|
|