diff --git a/Makefile b/Makefile index d6d7be8..b1df0b6 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,8 @@ CC ?= cc CFLAGS += -I$(DEP)/include -I$(DEP)/include/ncursestw -I$(SRC)/include -I$(SRC) CFLAGS += -Wall -Wextra -DPALERAIN_VERSION=\"2.0.0\" -Wall -Wextra -Wno-unused-parameter CFLAGS += -Wno-unused-variable -I$(SRC)/src -LIBS += $(DEP)/lib/libimobiledevice-1.0.a $(DEP)/lib/libirecovery-1.0.a $(DEP)/lib/libusbmuxd-2.0.a $(DEP)/lib/libimobiledevice-glue-1.0.a $(DEP)/lib/libplist-2.0.a -pthread +LIBS += $(DEP)/lib/libimobiledevice-1.0.a $(DEP)/lib/libirecovery-1.0.a $(DEP)/lib/libusbmuxd-2.0.a +LIBS += $(DEP)/lib/libimobiledevice-glue-1.0.a $(DEP)/lib/libplist-2.0.a -pthread ifeq ($(TARGET_OS),) TARGET_OS = $(shell uname -s) endif @@ -20,7 +21,7 @@ CFLAGS += -fdata-sections -ffunction-sections LDFLAGS += -static -no-pie -Wl,--gc-sections endif LIBS += $(DEP)/lib/libmbedtls.a $(DEP)/lib/libmbedcrypto.a $(DEP)/lib/libmbedx509.a $(DEP)/lib/libreadline.a -LIBS += $(DEP)/lib/libusb-1.0.a $(DEP)/lib/libncursestw.a +LIBS += $(DEP)/lib/libusb-1.0.a $(DEP)/lib/libncursestw.a $(DEP)/lib/libmenutw.a ifeq ($(DEV_BUILD),1) CFLAGS += -O0 -g -DDEV_BUILD -fsanitize=address -fno-omit-frame-pointer -fsanitize-address-use-after-return=runtime diff --git a/include/tui.h b/include/tui.h index 98264fd..b38e3ca 100644 --- a/include/tui.h +++ b/include/tui.h @@ -14,15 +14,18 @@ #include #include -struct button { - char name[0x10]; -}; +#define MAIN_OPTIONS "Options" +#define MAIN_START "Start" +#define MAIN_EXIT "Exit" -struct button_list { - uint8_t count; - uint8_t current; - uint8_t height; - struct button buttons[]; +enum tui_screens { + ERROR_SCREEN = -1, + EXIT_SCREEN = 0, + MAIN_SCREEN = 1, + OPTIONS_SCREEN = 2, + ENTER_DFU_SCREEN = 3, + JAILBREAKING_SCREEN = 4, + ENTER_RECOVERY_SCREEN = 5 }; #endif diff --git a/src/pongo_helper.c b/src/pongo_helper.c index 0814816..0625f8d 100644 --- a/src/pongo_helper.c +++ b/src/pongo_helper.c @@ -29,9 +29,9 @@ void *pongo_usb_callback(void *arg) { if (found_pongo) return NULL; found_pongo = 1; - strncat(xargs_cmd, " rootdev=md0", 0x270); + strncat(xargs_cmd, " rootdev=md0", 0x270 - strlen(xargs_cmd) - 1); if (checkrain_option_enabled(palerain_flags, palerain_option_setup_rootful)) { - strncat(xargs_cmd, " wdt=-1", 0x270); + strncat(xargs_cmd, " wdt=-1", 0x270 - strlen(xargs_cmd) - 1); } LOG(LOG_INFO, "Found PongoOS USB Device"); usb_device_handle_t handle = *(usb_device_handle_t *)arg; diff --git a/src/window.c b/src/window.c index 40aebc7..f3e5769 100644 --- a/src/window.c +++ b/src/window.c @@ -1,6 +1,8 @@ #define NCURSES_WIDECHAR 1 -#include +#include +#include +#include #include #include #include @@ -10,79 +12,117 @@ #include #include #include +#include #include #include #define MSG_COLOR 1 #define ICON_COLOR 2 -#define COLOR_GREY init_color(0, 300, 300, 300) +#define BUTTON_COLOR_ON 3 +#define COLOR_GREY init_color(30, 300, 300, 300) -struct button_list main_menu_buttons = { - .count = 3, - .current = 2, - .height = 22, - .buttons = { - { .name = "Exit" }, - { .name = "Start" }, - { .name = "Options "}, - }, -}; +ITEM* main_buttons[4]; +MENU* main_menu; -int show_buttons(struct button_list* list) { - uint8_t start = 78; - char button_buf[0x20]; - for (uint8_t i = 0; i < list->count; i++) { - start -= (strlen(list->buttons[i].name) + 5); - snprintf(button_buf, 0x20, "[ %s ] ", list->buttons[i].name); - mvaddstr(list->height, start, button_buf); - } - return 0; -} - -int main_menu() { +int display_main_menu() { + int ret = -1; mvaddstr(1, 2, "Welcome to palera1n!"); move(2,1); whline(stdscr, ACS_HLINE, 80 - 2); - if (has_colors() == TRUE) { - start_color(); - init_pair(MSG_COLOR, COLOR_YELLOW, COLOR_BLACK); - init_pair(ICON_COLOR, COLOR_GREY, COLOR_BLACK); - } move(5,2); attron(COLOR_PAIR(MSG_COLOR)); - mvaddstr(3,2, "Connect your iPhone, iPad, or iPod Touch"); - mvaddstr(4,2, "to begin."); + mvaddstr(4,2, "Connect your iPhone, iPad, or iPod Touch"); + mvaddstr(5,2, "to begin."); attroff(COLOR_PAIR(MSG_COLOR)); attron(COLOR_PAIR(ICON_COLOR)); - mvaddwstr(5, 43, L"MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM"); - mvaddwstr(6, 43, L"MMMMMMMMMMMMMWNOddONWMMMMMMMMMMMMM"); - mvaddwstr(7, 43, L"MMMMMMMMMMMMWNx. .xNWMMMMMMMMMMMM"); - mvaddwstr(8, 43, L"MMMMMMMMMMMMW0;....;OWMMMMMMMMMMMM"); - mvaddwstr(9, 43, L"MMMMMMMMMMMMW0;....;OWMMMMMMMMMMMM"); - mvaddwstr(10, 43, L"MMMMMMMMMMMWXo'.....lKWMMMMMMMMMMM"); - mvaddwstr(11, 43, L"MMMMMMMMMMWNkc;'....'dNWMMMMMMMMMM"); - mvaddwstr(12, 43, L"MMMMMMMMMMN0dc:,''''.:ONWMMMMMMMMM"); - mvaddwstr(13, 43, L"MMMMMMMMMWKxllc;,'''',lKWMMMMMMMMM"); - mvaddwstr(14, 43, L"MMMMMMMMWNkoolc;,,,,;;:xXWMMMMMMMM"); - mvaddwstr(15, 43, L"MMMMMMMMW0olllc;,,,,,,,:OWMMMMMMMM"); - mvaddwstr(16, 43, L"MMMMMMMMNOollc:,'....'';xNMMMMMMMM"); - mvaddwstr(17, 43, L"MMMMMMMMW0dllc:,''''''':OWMMMMMMMM"); - mvaddwstr(18, 43, L"MMMMMMMMWN0dc::;;,,,,,cONWMMMMMMMM"); - mvaddwstr(19, 43, L"MMMMMMMMMMWXOxoc::cldkXWMMMMMMMMMM"); - mvaddwstr(20, 43, L"MMMMMMMMMMMMWWNNXXNNWWMMMMMMMMMMMM"); - mvaddwstr(21, 43, L"MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM"); + mvaddwstr(2, 43, L" MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM "); + mvaddwstr(3, 44, L"MMMMMMMMMMMMMWNOddONWMMMMMMMMMMMMM"); + mvaddwstr(4, 44, L"MMMMMMMMMMMMWNx. .xNWMMMMMMMMMMMM"); + mvaddwstr(5, 44, L"MMMMMMMMMMMMW0;....;OWMMMMMMMMMMMM"); + mvaddwstr(6, 44, L"MMMMMMMMMMMMW0;....;OWMMMMMMMMMMMM"); + mvaddwstr(7, 44, L"MMMMMMMMMMMWXo'.....lKWMMMMMMMMMMM"); + mvaddwstr(8, 44, L"MMMMMMMMMMWNkc;'....'dNWMMMMMMMMMM"); + mvaddwstr(9, 44, L"MMMMMMMMMMN0dc:,''''.:ONWMMMMMMMMM"); + mvaddwstr(10, 44, L"MMMMMMMMMWKxllc;,'''',lKWMMMMMMMMM"); + mvaddwstr(11, 44, L"MMMMMMMMWNkoolc;,,,,;;:xXWMMMMMMMM"); + mvaddwstr(12, 44, L"MMMMMMMMW0olllc;,,,,,,,:OWMMMMMMMM"); + mvaddwstr(13, 44, L"MMMMMMMMNOollc:,'....'';xNMMMMMMMM"); + mvaddwstr(14, 44, L"MMMMMMMMW0dllc:,''''''':OWMMMMMMMM"); + mvaddwstr(15, 44, L"MMMMMMMMWN0dc::;;,,,,,cONWMMMMMMMM"); + mvaddwstr(16, 44, L"MMMMMMMMMMWXOxoc::cldkXWMMMMMMMMMM"); + mvaddwstr(17, 44, L"MMMMMMMMMMMMWWNNXXNNWWMMMMMMMMMMMM"); + mvaddwstr(18, 44, L"MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM"); + mvaddstr(7, 2, "Made by: Nick Chan, Mineek, Tom, Nebula,"); + mvaddstr(8, 2, "llsc12, Nathan"); + move(9, 2); + whline(stdscr, ACS_HLINE, 40); + mvaddstr(10, 2, "Thanks to: nyuszika7h, Procursus Team"); + mvaddstr(11, 2, "dora2ios, m1sta, Serena, xerub, tihmstar"); + mvaddstr(12, 2, "sbingner, checkra1n team (Siguza, Axi0mx"); + mvaddstr(13, 2, "argp et al.)"); + move(14, 2); + whline(stdscr, ACS_HLINE, 40); + mvaddstr(19, 2, "palera1n is NOT affinated with checkra1n"); + mvaddstr(20, 2, "Note: Backup your stuff. Use at your own risk."); + mvaddstr(19, 78 - strlen("@palera1n"), "@palera1n"); + mvaddstr(20, 78 - strlen("https://palera.in"), "https://palera.in"); attroff(COLOR_PAIR(ICON_COLOR)); move(21,1); whline(stdscr, ACS_HLINE, 80 - 2); - show_buttons(&main_menu_buttons); + move(22, 40); + + main_buttons[0] = new_item(MAIN_OPTIONS, ""); + main_buttons[1] = new_item(MAIN_START, ""); + main_buttons[2] = new_item(MAIN_EXIT, ""); + main_buttons[3] = NULL; + main_menu = new_menu(main_buttons); + item_opts_off(main_buttons[1], O_SELECTABLE); + set_menu_format(main_menu, 1, 40); + set_menu_sub(main_menu, derwin(stdscr, 0, 0, 22, 50)); + post_menu(main_menu); + raw(); + while (1) { + uint8_t target = 0; + int ch = getch(); + if (ch == KEY_LEFT) { + menu_driver(main_menu, REQ_LEFT_ITEM); + } else if (ch == KEY_RIGHT) { + menu_driver(main_menu, REQ_RIGHT_ITEM); + } else if (ch == 10) { + if (!(item_opts(current_item(main_menu)) & O_SELECTABLE)) continue; + // fprintf(stderr, "Button %s pressed\n", current_item(main_menu)->name.str); + if (!strcmp(current_item(main_menu)->name.str, MAIN_EXIT)) { + ret = EXIT_SCREEN; + } else if (!strcmp(current_item(main_menu)->name.str, MAIN_START)) { + ret = ENTER_RECOVERY_SCREEN; + } else if (!strcmp(current_item(main_menu)->name.str, MAIN_OPTIONS)) { + ret = OPTIONS_SCREEN; + } + goto end; + } + refresh(); + } +end: + noraw(); refresh(); - return 0; + return ret; } +int display_enter_dfu_screen() { return JAILBREAKING_SCREEN; } +int display_enter_recovery_screen() { return ENTER_DFU_SCREEN; } +int display_options_screen() { return MAIN_SCREEN; } +int display_jailbreaking_screen() { return EXIT_SCREEN; } + int init_window() { setlocale(LC_ALL, NULL); initscr(); + if (has_colors() == TRUE) { + start_color(); + init_pair(MSG_COLOR, COLOR_YELLOW, COLOR_BLACK); + init_pair(ICON_COLOR, COLOR_WHITE, COLOR_BLACK); + init_pair(BUTTON_COLOR_ON, COLOR_BLACK, COLOR_WHITE); + } int height, width; getmaxyx(stdscr, height, width); if (width < 80 || height < 24) { @@ -97,7 +137,7 @@ int init_window() { noecho(); keypad(stdscr, TRUE); box(stdscr, 0, 0); - mvaddstr(0, 80 - strlen("[ palera1n version " PALERAIN_VERSION " ]") - 3 , "[ palera1n version " PALERAIN_VERSION " ]"); + mvaddstr(0, 80 - strlen("[palera1n version " PALERAIN_VERSION "]") - 2 , "[palera1n version " PALERAIN_VERSION "]"); return 0; } @@ -107,10 +147,37 @@ int destroy_window() { } int tui() { - int ret; - ret = init_window(); - main_menu(); - sleep(5); + int ret = MAIN_SCREEN; + init_window(); + while (1) { + switch (ret) { + case ERROR_SCREEN: + goto out; + break; + case EXIT_SCREEN: + goto out; + break; + case MAIN_SCREEN: + ret = display_main_menu(); + break; + case OPTIONS_SCREEN: + ret = display_options_screen(); + break; + case ENTER_RECOVERY_SCREEN: + ret = display_enter_recovery_screen(); + break; + case ENTER_DFU_SCREEN: + ret = display_enter_dfu_screen(); + break; + case JAILBREAKING_SCREEN: + ret = display_jailbreaking_screen(); + break; + default: + assert(0); + goto out; + } + } +out: destroy_window(); return ret; }