Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
123 lines (102 loc) · 3.43 KB
/
Copy pathmain.cpp
File metadata and controls
123 lines (102 loc) · 3.43 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <string>
#include <thread>
#include <vector>
#include "bridge.hpp"
#include "device.hpp"
#include "downgrade.hpp"
#include "logger.hpp"
#include "rw.hpp"
#include "shell.hpp"
#include "utils.hpp"
int main(int argc, char* argv[]) {
bool interactive = false;
bool skip_wait = false;
std::vector<std::string> command_args;
for (int i = 1; i < argc; ++i) {
std::string arg = argv[i];
if (arg == "-i") {
interactive = true;
} else if (arg == "-v") {
Logger::set_level(LogLevel::L_DEBUG);
} else if (arg == "-s") {
skip_wait = true;
} else {
command_args.push_back(arg);
}
}
PSVR2Device usb;
if (command_args.size() > 0 && command_args[0] == "downgrade") {
usb.connect(true);
do_downgrade(usb);
return 0;
}
LOG_INFO << "[1/3] Connecting to PSVR2...\n";
if (!usb.connect()) {
if (usb.has_firmware_mismatch()) {
return 1;
}
LOG_ERROR << "[-] Device not found. Check USB.\n";
return 1;
}
LOG_INFO << "[+] Connected.\n";
KernelRW krw(&usb);
// Give it 10 tries. It can happen that we don't get the sauth heap.
for (int i = 0; i < 10; i++) {
LOG_INFO << "[2/3] Setting up read...\n";
if (!krw.setup_read()) {
LOG_ERROR << "[-] Exploit init failed. Rebooting HMD to try again...\n";
usb.force_reboot();
} else {
break;
}
bool connected = false;
for (int i = 0; i < 10; i++) {
std::this_thread::sleep_for(std::chrono::seconds(1));
connected = usb.connect();
if (connected) {
break;
}
}
if (!connected) {
if (usb.has_firmware_mismatch()) {
return 1;
}
LOG_ERROR << "[-] Unable to reconnect to HMD. Check your USB connections.\n";
}
}
LOG_INFO << "[3/3] Setting up write...\n";
if (!krw.setup_write()) {
LOG_WARN << "[!] Write unavailable - rebooting.\n";
usb.force_reboot();
return 1;
}
krw.setup_jb_env();
PSVR2Bridge bridge(usb.get_handle());
bridge.upload(Utils::get_executable_relative_path("busybox"), "/tmp/busybox");
bridge.shell("/tmp/busybox mkdir /tmp/bin");
bridge.shell("/tmp/busybox --install /tmp/bin");
// Start interactive shell
PSVR2Shell shell(&usb, &krw, &bridge);
if (interactive) {
try {
shell.cmdloop();
} catch (...) {
LOG_INFO << "[*] Bye.\n";
}
} else {
if (!command_args.empty()) {
shell.execute_command(command_args);
} else {
LOG_ERROR << "[-] No command specified. Applying jailbreak patches.\n";
shell.execute_command({"upload", Utils::get_executable_relative_path("patcher"), "/tmp/patcher"});
shell.execute_command({"shell", "/tmp/patcher"});
shell.execute_command({"shell", "echo", "\"pwmLEDx 2 2 0 3 0 0 0 0 0 0 0 100 1800 0 200 0 0\"", ">", "/sys/devices/platform/soc/10010000.pwrap/10010000.pwrap:mt3615/mtk_pwm_intf/pwm_manus"});
usb.disconnect();
LOG_ERROR << "[*] Jailbreak patch commands sent. Make sure the output above was successful.\n";
if (!skip_wait) {
std::this_thread::sleep_for(std::chrono::seconds(8));
}
}
}
return 0;
}