-
Notifications
You must be signed in to change notification settings - Fork 23
/
Cydia.mm
77 lines (61 loc) · 2.31 KB
/
Cydia.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* Cydia Substrate - Powerful Code Insertion Platform
* Copyright (C) 2008-2011 Jay Freeman (saurik)
*/
/* GNU Lesser General Public License, Version 3 {{{ */
/*
* Substrate is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Substrate is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Substrate. If not, see <http://www.gnu.org/licenses/>.
**/
/* }}} */
#include <Foundation/Foundation.h>
#include <mach/mach_init.h>
#include <mach/vm_map.h>
#include <stdio.h>
#include "Common.hpp"
#include "Cydia.hpp"
void FinishCydia(const char *finish) {
if (finish == NULL)
return;
const char *cydia(getenv("CYDIA"));
if (cydia == NULL)
return;
// XXX: I think I'd like to rewrite this code using C++
int fd([[[[NSString stringWithUTF8String:cydia] componentsSeparatedByString:@" "] objectAtIndex:0] intValue]);
FILE *fout(fdopen(fd, "w"));
fprintf(fout, "finish:%s\n", finish);
fclose(fout);
}
ForkBugStatus DetectForkBug() {
mach_port_t self(mach_task_self());
int page(getpagesize());
volatile uint8_t *data(reinterpret_cast<volatile uint8_t *>(&fopen));
uintptr_t base(reinterpret_cast<uintptr_t>(data) / page * page);
vm_protect(self, base, page, FALSE, VM_PROT_READ | VM_PROT_WRITE | VM_PROT_COPY);
data[0] = data[0];
vm_protect(self, base, page, FALSE, VM_PROT_READ | VM_PROT_EXECUTE | VM_PROT_COPY);
pid_t pid(fork());
if (pid == 0) {
fopen("/tmp/fork", "rb");
_exit(EXIT_SUCCESS);
}
int status;
if (_syscall(waitpid(pid, &status, 0) == -1)) {
fprintf(stderr, "waitpid() -> %d\n", errno);
return ForkBugUnknown;
}
if (WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS)
return ForkBugMissing;
else
// XXX: consider checking for a killed status, and returning ForBugUnknown if not
return ForkBugPresent;
}