mirror of
https://github.com/palera1n/palera1n.git
synced 2026-12-06 08:14:49 +01:00
improve pongo usb
This commit is contained in:
1 parent
b07c28334b
commit
40b8c0e42f
6 files changed
+116
-61
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
SRC = $(shell pwd)
|
SRC = $(shell pwd)
|
||||||
DEP = $(SRC)/dep_root
|
DEP = $(SRC)/dep_root
|
||||||
CC = cc
|
CC = cc
|
||||||
CFLAGS += -mmacosx-version-min=10.8 -I$(DEP)/include -I/opt/procursus/include -I$(SRC)/include -I$(SRC) -Os -Wall -Wextra
|
CFLAGS += -mmacosx-version-min=10.8 -I$(DEP)/include -I/opt/procursus/include -I$(SRC)/include -I$(SRC) -O0 -g -Wall -Wextra
|
||||||
LIBS = $(DEP)/lib/libimobiledevice-1.0.a $(DEP)/lib/libirecovery-1.0.a $(DEP)/lib/libusbmuxd-2.0.a $(DEP)/lib/libplist-2.0.a $(DEP)/lib/libimobiledevice-glue-1.0.a -pthread
|
LIBS = $(DEP)/lib/libimobiledevice-1.0.a $(DEP)/lib/libirecovery-1.0.a $(DEP)/lib/libusbmuxd-2.0.a $(DEP)/lib/libplist-2.0.a $(DEP)/lib/libimobiledevice-glue-1.0.a -pthread
|
||||||
LIBS += $(DEP)/lib/libcrypto.35.tbd $(DEP)/lib/libssl.35.tbd $(DEP)/lib/libusb-1.0.a
|
LIBS += $(DEP)/lib/libcrypto.35.tbd $(DEP)/lib/libssl.35.tbd $(DEP)/lib/libusb-1.0.a
|
||||||
LIBS += -framework CoreFoundation -framework SystemConfiguration -framework IOKit -framework Security
|
LIBS += -framework CoreFoundation -framework SystemConfiguration -framework IOKit -framework Security
|
||||||
|
|||||||
+4
-1
@@ -18,7 +18,8 @@ typedef enum {
|
|||||||
LOG_ERROR = 1,
|
LOG_ERROR = 1,
|
||||||
LOG_WARNING = 2,
|
LOG_WARNING = 2,
|
||||||
LOG_INFO = 3,
|
LOG_INFO = 3,
|
||||||
LOG_VERBOSE = 4
|
LOG_VERBOSE = 4,
|
||||||
|
LOG_VERBOSE2 = 5
|
||||||
} log_level_t;
|
} log_level_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -75,4 +76,6 @@ usb_ret_t USBControlTransfer(usb_device_handle_t handle, uint8_t bmRequestType,
|
|||||||
usb_ret_t USBBulkUpload(usb_device_handle_t handle, void *data, uint32_t len);
|
usb_ret_t USBBulkUpload(usb_device_handle_t handle, void *data, uint32_t len);
|
||||||
const char *usb_strerror(usb_ret_t err);
|
const char *usb_strerror(usb_ret_t err);
|
||||||
int wait_for_pongo();
|
int wait_for_pongo();
|
||||||
|
int issue_pongo_command();
|
||||||
|
int upload_pongo_file();
|
||||||
#endif
|
#endif
|
||||||
@@ -144,6 +144,7 @@ void* connected_dfu_mode(struct irecv_device_info* info) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void device_event_cb(const usbmuxd_event_t *event, void *userdata) {
|
void device_event_cb(const usbmuxd_event_t *event, void *userdata) {
|
||||||
|
if (event->device.conn_type != CONNECTION_TYPE_USB) return;
|
||||||
switch (event->event) {
|
switch (event->event) {
|
||||||
case UE_DEVICE_ADD:
|
case UE_DEVICE_ADD:
|
||||||
LOG(LOG_VERBOSE, "Normal mode device connected");
|
LOG(LOG_VERBOSE, "Normal mode device connected");
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ void exec_checkra1n() {
|
|||||||
if (ret) {
|
if (ret) {
|
||||||
LOG(LOG_FATAL, "Cannot posix spawn %s: %d (%s)", checkra1n_path, errno, strerror(errno));
|
LOG(LOG_FATAL, "Cannot posix spawn %s: %d (%s)", checkra1n_path, errno, strerror(errno));
|
||||||
unlink(checkra1n_path);
|
unlink(checkra1n_path);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
unlink(checkra1n_path);
|
unlink(checkra1n_path);
|
||||||
waitpid(pid, NULL, 0);
|
waitpid(pid, NULL, 0);
|
||||||
|
|||||||
+25
-59
@@ -41,8 +41,7 @@ int p1_log(log_level_t loglevel, const char *fname, int lineno, const char *fxna
|
|||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
if (verbose >= 2)
|
if (verbose >= 2)
|
||||||
printf(BLU "%s:%d: " BMAG "%s(): \n--> " WHT, fname, lineno, fxname);
|
printf(BLU "%s:%d: " BMAG "%s(): \n--> " WHT, fname, lineno, fxname);
|
||||||
switch (loglevel)
|
switch (loglevel) {
|
||||||
{
|
|
||||||
case LOG_FATAL:
|
case LOG_FATAL:
|
||||||
printf(BRED "[!] " RED);
|
printf(BRED "[!] " RED);
|
||||||
break;
|
break;
|
||||||
@@ -55,12 +54,10 @@ int p1_log(log_level_t loglevel, const char *fname, int lineno, const char *fxna
|
|||||||
case LOG_INFO:
|
case LOG_INFO:
|
||||||
printf(BCYN "[Info] " CYN);
|
printf(BCYN "[Info] " CYN);
|
||||||
break;
|
break;
|
||||||
case LOG_VERBOSE:
|
|
||||||
if (verbose >= 1)
|
|
||||||
printf(BWHT "[Verbose] " WHT);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
assert(0);
|
assert(loglevel >= 0);
|
||||||
|
if (verbose >= (loglevel - 3))
|
||||||
|
printf(BWHT "[Verbose] " WHT);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (verbose >= 1 || loglevel < LOG_VERBOSE)
|
if (verbose >= 1 || loglevel < LOG_VERBOSE)
|
||||||
@@ -72,54 +69,14 @@ int p1_log(log_level_t loglevel, const char *fname, int lineno, const char *fxna
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int issue_pongo_command(usb_device_handle_t handle, char *command)
|
|
||||||
{
|
|
||||||
sleep(1);
|
|
||||||
int ret;
|
|
||||||
size_t len = strlen(command);
|
|
||||||
if (len > (CMD_LEN_MAX - 2)) {
|
|
||||||
LOG(LOG_ERROR, "Pongo command %s too long (max %d)", command, CMD_LEN_MAX - 2);
|
|
||||||
return EINVAL;
|
|
||||||
}
|
|
||||||
LOG(LOG_VERBOSE, "Executing PongoOS command: '%s'", command);
|
|
||||||
char buf[512];
|
|
||||||
snprintf(buf, 512, "%s\n", command);
|
|
||||||
len = strlen(buf);
|
|
||||||
ret = USBControlTransfer(handle, 0x21, 4, 1, 0, 0, NULL, NULL);
|
|
||||||
if (ret)
|
|
||||||
goto bad;
|
|
||||||
ret = USBControlTransfer(handle, 0x21, 3, 0, 0, (uint32_t)len, buf, NULL);
|
|
||||||
bad:
|
|
||||||
if (ret != USB_RET_SUCCESS) {
|
|
||||||
if (ret == USB_RET_NOT_RESPONDING)
|
|
||||||
return 0;
|
|
||||||
LOG(LOG_ERROR, "USB error: %s", usb_strerror(ret));
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int upload_pongo_file(usb_device_handle_t handle, unsigned char *buf, unsigned int buf_len)
|
|
||||||
{
|
|
||||||
int ret = 0;
|
|
||||||
ret = USBControlTransfer(handle, 0x21, 1, 0, 0, 4, &buf_len, NULL);
|
|
||||||
if (ret == USB_RET_SUCCESS) {
|
|
||||||
ret = USBBulkUpload(handle, buf, buf_len);
|
|
||||||
if (ret == USB_RET_SUCCESS) {
|
|
||||||
LOG(LOG_VERBOSE, "Uploaded %llu bytes to PongoOS", (unsigned long long)buf_len);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sleep(2);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int found_pongo = 0;
|
int found_pongo = 0;
|
||||||
|
|
||||||
void *pongo_usb_callback(void *arg)
|
void *pongo_usb_callback(void *arg)
|
||||||
{
|
{
|
||||||
if (found_pongo) return NULL;
|
if (found_pongo)
|
||||||
|
return NULL;
|
||||||
found_pongo = 1;
|
found_pongo = 1;
|
||||||
|
LOG(LOG_INFO, "Found PongoOS USB Device");
|
||||||
usb_device_handle_t handle = *(usb_device_handle_t *)arg;
|
usb_device_handle_t handle = *(usb_device_handle_t *)arg;
|
||||||
issue_pongo_command(handle, "fuse lock");
|
issue_pongo_command(handle, "fuse lock");
|
||||||
issue_pongo_command(handle, "sep auto");
|
issue_pongo_command(handle, "sep auto");
|
||||||
@@ -127,9 +84,12 @@ void *pongo_usb_callback(void *arg)
|
|||||||
issue_pongo_command(handle, "modload");
|
issue_pongo_command(handle, "modload");
|
||||||
issue_pongo_command(handle, "kpf_flags 0x00000000");
|
issue_pongo_command(handle, "kpf_flags 0x00000000");
|
||||||
issue_pongo_command(handle, "checkra1n_flags 0x00000000");
|
issue_pongo_command(handle, "checkra1n_flags 0x00000000");
|
||||||
if (enable_fakefs) {
|
if (enable_fakefs)
|
||||||
|
{
|
||||||
issue_pongo_command(handle, fakefs);
|
issue_pongo_command(handle, fakefs);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
strcat(xargs_cmd, " rootdev=md0");
|
strcat(xargs_cmd, " rootdev=md0");
|
||||||
upload_pongo_file(handle, ramdisk_dmg, ramdisk_dmg_len);
|
upload_pongo_file(handle, ramdisk_dmg, ramdisk_dmg_len);
|
||||||
issue_pongo_command(handle, "ramdisk");
|
issue_pongo_command(handle, "ramdisk");
|
||||||
@@ -137,7 +97,8 @@ void *pongo_usb_callback(void *arg)
|
|||||||
issue_pongo_command(handle, "overlay");
|
issue_pongo_command(handle, "overlay");
|
||||||
}
|
}
|
||||||
issue_pongo_command(handle, xargs_cmd);
|
issue_pongo_command(handle, xargs_cmd);
|
||||||
issue_pongo_command(handle, "bootx");
|
issue_pongo_command(handle, "kpf");
|
||||||
|
issue_pongo_command(handle, "bootux");
|
||||||
LOG(LOG_INFO, "Booting Kernel...");
|
LOG(LOG_INFO, "Booting Kernel...");
|
||||||
spin = false;
|
spin = false;
|
||||||
exit(0);
|
exit(0);
|
||||||
@@ -236,12 +197,14 @@ int main(int argc, char *argv[])
|
|||||||
usage(1);
|
usage(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (verbose >= 3) {
|
if (verbose >= 3)
|
||||||
|
{
|
||||||
irecv_set_debug_level(1);
|
irecv_set_debug_level(1);
|
||||||
idevice_set_debug_level(1);
|
idevice_set_debug_level(1);
|
||||||
putenv("LIBUSB_DEBUG=3");
|
putenv("LIBUSB_DEBUG=3");
|
||||||
}
|
}
|
||||||
if (verbose >= 4) putenv("LIBUSB_DEBUG=4");
|
if (verbose >= 4)
|
||||||
|
putenv("LIBUSB_DEBUG=4");
|
||||||
if (start_from_pongo == true)
|
if (start_from_pongo == true)
|
||||||
goto pongo;
|
goto pongo;
|
||||||
LOG(LOG_INFO, "Waiting for devices");
|
LOG(LOG_INFO, "Waiting for devices");
|
||||||
@@ -256,10 +219,13 @@ int main(int argc, char *argv[])
|
|||||||
return 0;
|
return 0;
|
||||||
pongo:
|
pongo:
|
||||||
spin = true;
|
spin = true;
|
||||||
if (do_pongo_sleep) sleep(2);
|
if (do_pongo_sleep)
|
||||||
else LOG(LOG_INFO, "Waiting for PongoOS devices...");
|
sleep(2);
|
||||||
|
else
|
||||||
|
LOG(LOG_INFO, "Waiting for PongoOS devices...");
|
||||||
wait_for_pongo();
|
wait_for_pongo();
|
||||||
while (spin) {
|
while (spin)
|
||||||
|
{
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -310,3 +310,87 @@ static void io_stop(stuff_t *stuff)
|
|||||||
exit(-1); // TODO: ok with libusb?
|
exit(-1); // TODO: ok with libusb?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void write_stdout(char *buf, uint32_t len)
|
||||||
|
{
|
||||||
|
while(len > 0) {
|
||||||
|
if (verbose >= 3) {
|
||||||
|
ssize_t s = write(1, buf, len);
|
||||||
|
if(s < 0) {
|
||||||
|
LOG(LOG_ERROR, "write: %s", strerror(errno));
|
||||||
|
pthread_exit(NULL);
|
||||||
|
}
|
||||||
|
buf += s;
|
||||||
|
len -= s;
|
||||||
|
} else break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int issue_pongo_command(usb_device_handle_t handle, char *command)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
size_t len = strlen(command);
|
||||||
|
char command_buf[512];
|
||||||
|
char stdout_buf[0x2000];
|
||||||
|
if (len > (CMD_LEN_MAX - 2))
|
||||||
|
{
|
||||||
|
LOG(LOG_ERROR, "Pongo command %s too long (max %d)", command, CMD_LEN_MAX - 2);
|
||||||
|
return EINVAL;
|
||||||
|
}
|
||||||
|
LOG(LOG_VERBOSE, "Executing PongoOS command: '%s'", command);
|
||||||
|
snprintf(command_buf, 512, "%s\n", command);
|
||||||
|
len = strlen(command_buf);
|
||||||
|
ret = USBControlTransfer(handle, 0x21, 4, 1, 0, 0, NULL, NULL);
|
||||||
|
if (ret)
|
||||||
|
goto bad;
|
||||||
|
ret = USBControlTransfer(handle, 0x21, 3, 0, 0, (uint32_t)len, command_buf, NULL);
|
||||||
|
uint32_t outpos = 0;
|
||||||
|
uint32_t outlen = 0;
|
||||||
|
uint8_t in_progress = 1;
|
||||||
|
while (in_progress) {
|
||||||
|
ret = USBControlTransfer(handle, 0xa1, 2, 0, 0, (uint32_t)sizeof(in_progress), &in_progress, NULL);
|
||||||
|
if (ret == USB_RET_SUCCESS)
|
||||||
|
{
|
||||||
|
ret = USBControlTransfer(handle, 0xa1, 1, 0, 0, 0x1000, stdout_buf + outpos, &outlen);
|
||||||
|
if (ret == USB_RET_SUCCESS)
|
||||||
|
{
|
||||||
|
write_stdout(stdout_buf + outpos, outlen);
|
||||||
|
outpos += outlen;
|
||||||
|
if (outpos > 0x1000)
|
||||||
|
{
|
||||||
|
memmove(stdout_buf, stdout_buf + outpos - 0x1000, 0x1000);
|
||||||
|
outpos = 0x1000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ret != USB_RET_SUCCESS)
|
||||||
|
{
|
||||||
|
goto bad;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bad:
|
||||||
|
if (ret != USB_RET_SUCCESS)
|
||||||
|
{
|
||||||
|
if (ret == USB_RET_NOT_RESPONDING)
|
||||||
|
return 0;
|
||||||
|
LOG(LOG_ERROR, "USB error: %s", usb_strerror(ret));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int upload_pongo_file(usb_device_handle_t handle, unsigned char *buf, unsigned int buf_len)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
ret = USBControlTransfer(handle, 0x21, 1, 0, 0, 4, &buf_len, NULL);
|
||||||
|
if (ret == USB_RET_SUCCESS)
|
||||||
|
{
|
||||||
|
ret = USBBulkUpload(handle, buf, buf_len);
|
||||||
|
if (ret == USB_RET_SUCCESS)
|
||||||
|
{
|
||||||
|
LOG(LOG_VERBOSE, "Uploaded %llu bytes to PongoOS", (unsigned long long)buf_len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user