From bd7da745469aea054e82186613b52437f986d553 Mon Sep 17 00:00:00 2001 From: Nick Chan Date: Sat, 28 Jan 2023 20:41:18 +0800 Subject: [PATCH] build ncurses with more stuff --- .github/workflows/build.yml | 10 ++ Makefile | 4 +- {src => include}/common.h | 8 +- include/tui.h | 28 ++++++ xxd-embedded.h => include/xxd-embedded.h | 0 src/Makefile | 2 +- src/main.c | 6 ++ src/optparse.c | 12 ++- src/window.c | 116 +++++++++++++++++++++++ 9 files changed, 179 insertions(+), 7 deletions(-) rename {src => include}/common.h (97%) create mode 100644 include/tui.h rename xxd-embedded.h => include/xxd-embedded.h (100%) create mode 100644 src/window.c diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index db412c5..7793df2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -133,6 +133,11 @@ jobs: --with-build-cppflags="${{ env.CPPFLAGS_FOR_BUILD }}" \ --with-build-ldflags="${{ env.LDFLAGS_FOR_BUILD }}" \ --with-pthread \ + --enable-const \ + --enable-ext-colors \ + --enable-ext-mouse \ + --enable-ext-putwin \ + --enable-wattr-macros \ --disable-overwrite \ --without-debug \ --without-tests \ @@ -458,6 +463,11 @@ jobs: --with-build-cpp="cc -E" \ --with-build-cppflags=" " \ --with-build-ldflags=" " \ + --enable-const \ + --enable-ext-colors \ + --enable-ext-mouse \ + --enable-ext-putwin \ + --enable-wattr-macros \ --with-pthread \ --disable-overwrite \ --without-debug \ diff --git a/Makefile b/Makefile index bc680e8..3305e52 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ SRC = $(shell pwd) DEP = $(SRC)/dep_root STRIP = strip CC ?= cc -CFLAGS += -I$(DEP)/include -I$(SRC)/include -I$(SRC) -Wall -Wextra -DPALERAIN_VERSION=\"2.0.0\" -Wall -Wextra -Wno-unused-parameter -Wno-unused-variable +CFLAGS += -I$(DEP)/include -I$(DEP)/include/ncursestw -I$(SRC)/include -I$(SRC) -Wall -Wextra -DPALERAIN_VERSION=\"2.0.0\" -Wall -Wextra -Wno-unused-parameter -Wno-unused-variable 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 ifeq ($(TARGET_OS),) TARGET_OS = $(shell uname -s) @@ -18,7 +18,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 +LIBS += $(DEP)/lib/libusb-1.0.a $(DEP)/lib/libncursestw.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/src/common.h b/include/common.h similarity index 97% rename from src/common.h rename to include/common.h index 224f2c8..48245f7 100644 --- a/src/common.h +++ b/include/common.h @@ -21,6 +21,11 @@ #define USB_RET_SUCCESS LIBUSB_SUCCESS #define USB_RET_NOT_RESPONDING LIBUSB_ERROR_OTHER #define USB_RET_IO LIBUSB_ERROR_IO + +#ifndef PALERAIN_VERSION +#define PALERAIN_VERSION "2.0.0" +#endif + #if defined(__APPLE__) #include #include @@ -97,7 +102,7 @@ extern int spin, demote; extern char* pongo_path; extern bool dfuhelper_only; -extern bool pongo_exit; +extern bool pongo_exit, use_tui; extern pthread_t dfuhelper_thread, pongo_thread; extern int pongo_thr_running, dfuhelper_thr_running; @@ -150,5 +155,6 @@ const char *usb_strerror(usb_ret_t err); int wait_for_pongo(); int issue_pongo_command(); int upload_pongo_file(); +int tui(); int optparse(int argc, char* argv[]); #endif \ No newline at end of file diff --git a/include/tui.h b/include/tui.h new file mode 100644 index 0000000..98264fd --- /dev/null +++ b/include/tui.h @@ -0,0 +1,28 @@ +#ifndef TUI_H +#define TUI_H +#define NCURSES_WIDECHAR 1 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct button { + char name[0x10]; +}; + +struct button_list { + uint8_t count; + uint8_t current; + uint8_t height; + struct button buttons[]; +}; + +#endif diff --git a/xxd-embedded.h b/include/xxd-embedded.h similarity index 100% rename from xxd-embedded.h rename to include/xxd-embedded.h diff --git a/src/Makefile b/src/Makefile index eac2f9b..e852167 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,7 +1,7 @@ all: palera1n OBJECTS = main.o dfuhelper.o devhelper.o lockdown_helper.o exec_checkra1n.o -OBJECTS += pongo_usb.o optparse.o override_file.o pongo_helper.o log.o +OBJECTS += pongo_usb.o optparse.o override_file.o pongo_helper.o log.o window.o OBJECTS += xxd-checkra1n.o xxd-checkra1n-kpf-pongo.o xxd-ramdisk.dmg.o OBJECTS += xxd-binpack.dmg.o diff --git a/src/main.c b/src/main.c index 5b95782..0890be1 100644 --- a/src/main.c +++ b/src/main.c @@ -81,6 +81,7 @@ int build_checks() { } bool dfuhelper_only = false, pongo_exit = false, start_from_pongo = false, palerain_version = false; +bool use_tui = false; int palera1n(int argc, char *argv[]) { int ret = 0; @@ -90,6 +91,11 @@ int palera1n(int argc, char *argv[]) { if (palerain_version) goto normal_exit; if (start_from_pongo == true) goto pongo; + if (use_tui) { + ret = tui(); + if (ret) goto cleanup; + else goto normal_exit; + } LOG(LOG_INFO, "Waiting for devices"); do_pongo_sleep = 1; pthread_t dfuhelper_thread; diff --git a/src/optparse.c b/src/optparse.c index 913a586..f2116e2 100644 --- a/src/optparse.c +++ b/src/optparse.c @@ -12,6 +12,7 @@ #include #include "common.h" + static struct option longopts[] = { {"setup-fakefs", no_argument, NULL, 'c'}, {"setup-fakefs-forced", no_argument, NULL, 'C'}, @@ -34,13 +35,14 @@ static struct option longopts[] = { {"override-ramdisk", required_argument, NULL, 'r'}, {"override-kpf", required_argument, NULL, 'K'}, {"disable-ohio", no_argument, NULL, 'O'}, + {"tui", no_argument, NULL, 't'}, {NULL, 0, NULL, 0} }; static int usage(int e, char* prog_name) { fprintf(stderr, - "Usage: %s [-cCDhpPvVldsOL] [-e boot arguments] [-f root device] [-k Pongo image] [-o overlay file] [-r ramdisk file] [-K KPF file]\n" + "Usage: %s [-cCDhpPvVldsOLt] [-e boot arguments] [-f root device] [-k Pongo image] [-o overlay file] [-r ramdisk file] [-K KPF file]\n" "Copyright (C) 2023, palera1n team, All Rights Reserved.\n\n" "iOS/iPadOS 15+ arm64 jailbreaking tool\n\n" "\t--version\t\t\t\tPrint version\n" @@ -64,7 +66,8 @@ static int usage(int e, char* prog_name) "\t-o, --override-overlay \t\tOverride overlay\n" "\t-r, --override-ramdisk \t\tOverride ramdisk\n" "\t-K, --override-kpf \t\tOverride kernel patchfinder\n" - "\t-O, --disable-ohio\t\t\tDisable Ohio\n", + "\t-O, --disable-ohio\t\t\tDisable Ohio\n" + "\t-t, --tui\t\t\t\tTerminal user interface\n", prog_name); exit(e); } @@ -72,7 +75,7 @@ static int usage(int e, char* prog_name) int optparse(int argc, char* argv[]) { int opt; int index; - while ((opt = getopt_long(argc, argv, "cCDhpvVldsOLe:f:o:r:K:k:", longopts, NULL)) != -1) + while ((opt = getopt_long(argc, argv, "cCDhpvVldsOLte:f:o:r:K:k:", longopts, NULL)) != -1) { switch (opt) { case 'c': @@ -163,6 +166,9 @@ int optparse(int argc, char* argv[]) { case 'O': ohio = false; break; + case 't': + use_tui = true; + break; case checkrain_option_force_revert: checkrain_flags |= checkrain_option_force_revert; break; diff --git a/src/window.c b/src/window.c new file mode 100644 index 0000000..5aada9c --- /dev/null +++ b/src/window.c @@ -0,0 +1,116 @@ +#define NCURSES_WIDECHAR 1 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "common.h" +#include "tui.h" + +#define MSG_COLOR 1 +#define ICON_COLOR 2 +#define COLOR_GREY init_color(0, 300, 300, 300) + +struct button_list main_menu_buttons = { + .count = 3, + .current = 2, + .height = 22, + .buttons = { + { .name = "Exit" }, + { .name = "Start" }, + { .name = "Options "}, + }, +}; + +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() { + 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."); + 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"); + attroff(COLOR_PAIR(ICON_COLOR)); + move(21,1); + whline(stdscr, ACS_HLINE, 80 - 2); + show_buttons(&main_menu_buttons); + refresh(); + return 0; +} + +int init_window() { + setlocale(LC_ALL, NULL); + initscr(); + int height, width; + getmaxyx(stdscr, height, width); + if (width < 80 || height < 24) { + LOG(LOG_ERROR, "Terminal size must be at least 80x24"); + return -1; + } + if (has_colors() == FALSE) { + LOG(LOG_VERBOSE2, "Terminal without color support detected"); + } + resizeterm(24, 80); + cbreak(); + noecho(); + keypad(stdscr, TRUE); + box(stdscr, 0, 0); + mvaddstr(0, 80 - strlen("[ palera1n version " PALERAIN_VERSION " ]") - 3 , "[ palera1n version " PALERAIN_VERSION " ]"); + return 0; +} + +int destroy_window() { + endwin(); + return 0; +} + +int tui() { + int ret; + ret = init_window(); + main_menu(); + sleep(5); + destroy_window(); + return ret; +}