diff --git a/src/gui_alerts.cpp b/src/gui_alerts.cpp new file mode 100644 index 0000000..576a36b --- /dev/null +++ b/src/gui_alerts.cpp @@ -0,0 +1,67 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// 50/50 chance this will be removed for in-window alerts +#if __APPLE__ +#include +#define IDOK 1 +#define IDCANCEL 2 +#define AL kCFUserNotificationNoteAlertLevel +#elif _WIN32 +#include +#include +#elif __linux__ +// #include +#elif BSD +#elif __ANDROID__ +#else +#endif + +void send_alert(const char *title, const char *msg) { +#if __APPLE__ + CFStringRef header_ref = CFStringCreateWithCString(NULL, title, strlen(title)); + CFStringRef message_ref = CFStringCreateWithCString(NULL, msg, strlen(msg)); + // CFStringRef url_ref = CFStringCreateWithCString( NULL, "", strlen("") ); + CFURLRef icon_ref = CFURLCreateWithString(kCFAllocatorDefault, NULL, NULL); + CFOptionFlags result; + + CFUserNotificationDisplayAlert(0, AL, icon_ref, NULL, NULL, header_ref, message_ref, NULL, NULL, NULL, &result); + CFRelease(header_ref); + CFRelease(message_ref); +#elif _WIN32 + MessageBox(0, msg, title, MB_OK); +#elif __linux__ + char line[256]; + FILE *fp; + + fp=popen("zenity --version","r"); + if (fp==NULL) { + perror("Pipe returned a error"); + } else { + while (fgets(line,sizeof(line),fp)) printf("%s",line); + pclose(fp); + } + + char *str_msg = (char*)malloc(40+strlen(title)+strlen(msg)+1); + sprintf(str_msg, "zenity --info --title '%s' --text '%s'", title, msg); + fp=popen(str_msg, "r"); + + if (fp==NULL) { + perror("Pipe returned a error"); + } else { + printf("Exit code: %i\n",WEXITSTATUS(pclose(fp))); + } +#elif BSD +#elif __ANDROID__ +#else +#endif +} diff --git a/src/gui_design.cpp b/src/gui_design.cpp new file mode 100644 index 0000000..1948905 --- /dev/null +++ b/src/gui_design.cpp @@ -0,0 +1,372 @@ +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + + +/* ----------------- [ Animation Varibles ] ----------------- */ + +float btn_w = 0.0f; +float btn_h = 0.0f; +float btn_x = 0.0f; +float btn_y = 0.0f; +float box_w = 0.0f; +float box_h = 0.0f; +float box_x = 0.0f; +float box_y = 0.0f; + + +/* ----------------- [ UI Init/Reset ] ----------------- */ + +void init_colors() { + auto &colors = ImGui::GetStyle().Colors; + colors[ImGuiCol_WindowBg] = ImVec4{0.21f, 0.23f, 0.31f, 1.0f}; + colors[ImGuiCol_MenuBarBg] = ImVec4{0.16f, 0.16f, 0.21f, 1.0f}; + + // Border + colors[ImGuiCol_Border] = ImVec4{0.44f, 0.37f, 0.61f, 0.0f}; + colors[ImGuiCol_BorderShadow] = ImVec4{0.0f, 0.0f, 0.0f, 0.0f}; + + // Text + colors[ImGuiCol_Text] = ImVec4{1.0f, 1.0f, 1.0f, 1.0f}; + colors[ImGuiCol_TextDisabled] = ImVec4{0.5f, 0.5f, 0.5f, 1.0f}; + + // Headers + colors[ImGuiCol_Header] = ImVec4{0.13f, 0.13f, 0.17, 1.0f}; + colors[ImGuiCol_HeaderHovered] = ImVec4{0.19f, 0.2f, 0.25f, 1.0f}; + colors[ImGuiCol_HeaderActive] = ImVec4{0.16f, 0.16f, 0.21f, 1.0f}; + + // Buttons + colors[ImGuiCol_Button] = ImVec4{0.9f, 0.9f, 0.9f, 1.0f}; + colors[ImGuiCol_ButtonHovered] = ImVec4{0.9f, 0.9f, 0.9f, 1.0f}; + colors[ImGuiCol_ButtonActive] = ImVec4{0.9f, 0.9f, 0.9f, 1.0f}; + colors[ImGuiCol_CheckMark] = ImVec4{0.9f, 0.9f, 0.9f, 1.0f}; + + // Popups + colors[ImGuiCol_PopupBg] = ImVec4{0.1f, 0.1f, 0.13f, 0.92f}; + + // Slider + colors[ImGuiCol_SliderGrab] = ImVec4{0.44f, 0.37f, 0.61f, 0.54f}; + colors[ImGuiCol_SliderGrabActive] = ImVec4{0.74f, 0.58f, 0.98f, 0.54f}; + + // Frame BG + colors[ImGuiCol_FrameBg] = ImVec4{0.13f, 0.13f, 0.15f, 0.7f}; + colors[ImGuiCol_FrameBgHovered] = ImVec4{0.13f, 0.13f, 0.15f, 0.7f}; + colors[ImGuiCol_FrameBgActive] = ImVec4{0.13f, 0.13f, 0.15f, 0.7f}; + + // Tabs + colors[ImGuiCol_Tab] = ImVec4{0.16f, 0.16f, 0.21f, 1.0f}; + colors[ImGuiCol_TabHovered] = ImVec4{0.24, 0.24f, 0.32f, 1.0f}; + colors[ImGuiCol_TabActive] = ImVec4{0.2f, 0.22f, 0.27f, 1.0f}; + colors[ImGuiCol_TabUnfocused] = ImVec4{0.16f, 0.16f, 0.21f, 1.0f}; + colors[ImGuiCol_TabUnfocusedActive] = ImVec4{0.16f, 0.16f, 0.21f, 1.0f}; + + // Title + colors[ImGuiCol_TitleBg] = ImVec4{0.16f, 0.16f, 0.21f, 1.0f}; + colors[ImGuiCol_TitleBgActive] = ImVec4{0.16f, 0.16f, 0.21f, 1.0f}; + colors[ImGuiCol_TitleBgCollapsed] = ImVec4{0.16f, 0.16f, 0.21f, 1.0f}; + + // Scrollbar + colors[ImGuiCol_ScrollbarBg] = ImVec4{0.1f, 0.1f, 0.13f, 1.0f}; + colors[ImGuiCol_ScrollbarGrab] = ImVec4{0.16f, 0.16f, 0.21f, 1.0f}; + colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4{0.19f, 0.2f, 0.25f, 1.0f}; + colors[ImGuiCol_ScrollbarGrabActive] = ImVec4{0.24f, 0.24f, 0.32f, 1.0f}; + + // Seperator + colors[ImGuiCol_Separator] = ImVec4{0.44f, 0.37f, 0.61f, 1.0f}; + colors[ImGuiCol_SeparatorHovered] = ImVec4{0.74f, 0.58f, 0.98f, 1.0f}; + colors[ImGuiCol_SeparatorActive] = ImVec4{0.84f, 0.58f, 1.0f, 1.0f}; + + // Resize Grip + colors[ImGuiCol_ResizeGrip] = ImVec4{0.44f, 0.37f, 0.61f, 0.29f}; + colors[ImGuiCol_ResizeGripHovered] = ImVec4{0.74f, 0.58f, 0.98f, 0.29f}; + colors[ImGuiCol_ResizeGripActive] = ImVec4{0.84f, 0.58f, 1.0f, 0.29f}; + + // Docking + colors[ImGuiCol_DockingPreview] = ImVec4{0.44f, 0.37f, 0.61f, 1.0f}; +} + +void init_style() { + auto &style = ImGui::GetStyle(); + style.TabRounding = 0; + style.ScrollbarRounding = 0; + style.WindowRounding = 0; + style.GrabRounding = 0; + style.FrameRounding = 20; + style.PopupRounding = 0; + style.ChildRounding = 0; +} + +void reset_design() { + ImGui::SetCursorPos(ImVec2(0, 0)); + init_colors(); + init_style(); +} + +void reset_views() { + waiting_for_device = false; + unsupported_device = false; + supported_device = false; + recovery_wait = false; + jailbreak = false; + enter_dfu = false; + dfu_helper = false; +} + + + +/* ----------------- [ UI Element Styles ] ----------------- */ + +void image_btn_style() { + auto &colors = ImGui::GetStyle().Colors; + colors[ImGuiCol_Button] = ImVec4{1.0f, 1.0f, 1.0f, 1.0f}; + colors[ImGuiCol_ButtonHovered] = ImVec4{0.95f, 0.95f, 0.95f, 1.0f}; + colors[ImGuiCol_ButtonActive] = ImVec4{0.95f, 0.95f, 0.95f, 1.0f}; + colors[ImGuiCol_CheckMark] = ImVec4{0.95f, 0.95f, 0.95f, 1.0f}; + colors[ImGuiCol_Text] = ImVec4{0.1f, 0.1f, 0.1f, 1.0f}; +} + +void image_btn_style_alt() { + auto &colors = ImGui::GetStyle().Colors; + colors[ImGuiCol_Button] = ImVec4{0.0f, 0.0f, 0.0f, 0.0f}; + colors[ImGuiCol_ButtonHovered] = ImVec4{0.0f, 0.0f, 0.0f, 0.0f}; + colors[ImGuiCol_ButtonActive] = ImVec4{0.0f, 0.0f, 0.0f, 0.0f}; + colors[ImGuiCol_CheckMark] = ImVec4{0.0f, 0.0f, 0.0f, 0.0f}; + colors[ImGuiCol_Text] = ImVec4{0.0f, 0.0f, 0.0f, 0.0f}; +} + + + +/* ----------------- [ IDK Anymore ] ----------------- */ + +std::string addstr2(const char *str1, const char *str2) { + size_t str1_len = strlen(str1); + size_t str2_len = strlen(str2); + int buf_size = (int)str1_len + (int)str2_len + 1; + char buffer[buf_size]; + sprintf(buffer, str1, str2); + return buffer; +} + +std::string addstr3(const char *str1, const char *str2, const char *str3) { + size_t str1_len = strlen(str1); + size_t str2_len = strlen(str2); + size_t str3_len = strlen(str3); + int buf_size = (int)str1_len + (int)str2_len + (int)str3_len + 1; + char buffer[buf_size]; + sprintf(buffer, str1, str2, str3); + return buffer; +} + +std::string addstr4(const char *str1, const char *str2, const char *str3, const char *str4) { + size_t str1_len = strlen(str1); + size_t str2_len = strlen(str2); + size_t str3_len = strlen(str3); + size_t str4_len = strlen(str4); + int buf_size = (int)str1_len + (int)str2_len + (int)str3_len + (int)str4_len + 1; + char buffer[buf_size]; + sprintf(buffer, str1, str2, str3, str4); + return buffer; +} + + + +/* ----------------- [ UI Colors ] ----------------- */ + +ImVec4 hex_color(int hex, float alpha) { + float r = ((hex >> 16) & 0xFF) / 255.0f; + float g = ((hex >> 8) & 0xFF) / 255.0f; + float b = ((hex) & 0xFF) / 255.0f; + + return ImVec4{r, g, b, alpha}; +} + +ImColor hex_imcolor(int hex, float alpha) { + float r = ((hex >> 16) & 0xFF) / 255.0f; + float g = ((hex >> 8) & 0xFF) / 255.0f; + float b = ((hex) & 0xFF) / 255.0f; + + return ImColor{r, g, b, alpha}; +} + + + +/* ----------------- [ UI Element States ] ----------------- */ + +bool is_hovered(const char* id, int w, int h) { + ImGuiContext& g = *GImGui; + ImGuiWindow* window = ImGui::GetCurrentWindow(); + ImGuiID btn_id = window->GetID(id); + const ImRect bb(window->DC.CursorPos, ImVec2(window->DC.CursorPos.x + w, window->DC.CursorPos.x + h)); + bool hovered = false; + ImGui::ButtonBehavior(bb,btn_id,&hovered,NULL); + return hovered; +} + +bool is_pressed(const char* id, int w, int h) { + ImGuiContext& g = *GImGui; + ImGuiWindow* window = ImGui::GetCurrentWindow(); + ImGuiID btn_id = window->GetID(id); + const ImRect bb(window->DC.CursorPos, ImVec2(window->DC.CursorPos.x + w, window->DC.CursorPos.x + h)); + bool pressed = false; + ImGui::ButtonBehavior(bb,btn_id,NULL,&pressed); + return pressed; +} + + + +/* ----------------- [ Common UI Types ] ----------------- */ + +void label(const char *text, ImVec2 location, ImVec4 color, int font) { + auto &style = ImGui::GetStyle(); + ImGuiIO &io = ImGui::GetIO(); + + ImGui::SetCursorPos(location); + ImGui::PushFont(io.Fonts->Fonts[font]); + + auto &colors = ImGui::GetStyle().Colors; + colors[ImGuiCol_Text] = color; + + + ImGui::Text(text); + ImGui::PopFont(); + reset_design(); +} + +void draw_box(ImVec2 location, ImVec2 size, ImVec4 color, float radius) { + auto &colors = ImGui::GetStyle().Colors; + auto &style = ImGui::GetStyle(); + + float temp_rounding = style.FrameRounding; + ImVec4 temp_color_idle = colors[ImGuiCol_FrameBg]; + ImVec4 temp_color_hover = colors[ImGuiCol_FrameBgHovered]; + ImVec4 temp_color_active = colors[ImGuiCol_FrameBgActive]; + + style.FrameRounding = radius; + colors[ImGuiCol_FrameBg] = color; + colors[ImGuiCol_FrameBgHovered] = color; + colors[ImGuiCol_FrameBgActive] = color; + + ImGui::SetCursorPos(location); + ImGui::ProgressBar(0.0f, size, ""); + + style.FrameRounding = temp_rounding; + colors[ImGuiCol_FrameBg] = temp_color_idle; + colors[ImGuiCol_FrameBgHovered] = temp_color_hover; + colors[ImGuiCol_FrameBgActive] = temp_color_active; +} + + + +/* ----------------- [ Animation Systems ] ----------------- */ + +void anim_btn(const char* id, ImVec2 size, ImVec2 size_to, ImVec2 pos, ImVec2 pos_to) { + ImGuiIO &io = ImGui::GetIO(); + float global = 25.0f; + bool new_w_positive,new_h_positive,new_x_positive,new_y_positive = false; + float new_w,new_h,new_x,new_y = 0.0f; + float lrg_size,lrg_pos,lrg = 0.0f; + + if (size.x > size_to.x) {new_w = size.x - size_to.x; new_w_positive = false;} + else {new_w = size_to.x - size.x; new_w_positive = true;} + if (size.y > size_to.y) {new_h = size.y - size_to.y; new_h_positive = false;} + else {new_h = size_to.y - size.y;new_h_positive = true;} + if (pos.x > pos_to.x) {new_x = pos.x - pos_to.x; new_x_positive = false;} + else {new_x = pos_to.x - pos.x;new_x_positive = true;} + if (pos.y > pos_to.y) {new_y = pos.y - pos_to.y; new_y_positive = false;} + else {new_y = pos_to.y - pos.y;new_y_positive = true;} + + if (new_w > new_h) lrg_size = new_w; + else lrg_size = new_h; + if (new_x > new_y) lrg_pos = new_x; + else lrg_pos = new_y; + if (lrg_size > lrg_pos) lrg = lrg_size; + else lrg = lrg_pos; + + if (new_w_positive) {if (btn_w < size_to.x) btn_w += (new_w / lrg) * global * io.DeltaTime;} + else {if (btn_w > size_to.x) btn_w -= (new_w / lrg) * global * io.DeltaTime;} + if (new_h_positive) {if (btn_h < size_to.y) btn_h += (new_h / lrg) * global * io.DeltaTime;} + else {if (btn_h > size_to.y) btn_h -= (new_h / lrg) * global * io.DeltaTime;} + if (new_x_positive) {if (btn_x < pos_to.x) btn_x += (new_x / lrg) * global * io.DeltaTime;} + else {if (btn_x > pos_to.x) btn_x -= (new_x / lrg) * global * io.DeltaTime;} + if (new_y_positive) {if (btn_y < pos_to.y) btn_y += (new_y / lrg) * global * io.DeltaTime;} + else {if (btn_y > pos_to.y) btn_y -= (new_y / lrg) * global * io.DeltaTime;} +} + +void anim_box(const char* id, ImVec2 size, ImVec2 size_to, ImVec2 pos, ImVec2 pos_to) { + ImGuiIO &io = ImGui::GetIO(); + float global = 500.0f; + bool new_w_positive,new_h_positive,new_x_positive,new_y_positive = false; + float new_w,new_h,new_x,new_y = 0.0f; + float lrg_size,lrg_pos,lrg = 0.0f; + + if (size.x > size_to.x) {new_w = size.x - size_to.x; new_w_positive = false;} + else {new_w = size_to.x - size.x; new_w_positive = true;} + if (size.y > size_to.y) {new_h = size.y - size_to.y; new_h_positive = false;} + else {new_h = size_to.y - size.y;new_h_positive = true;} + if (pos.x > pos_to.x) {new_x = pos.x - pos_to.x; new_x_positive = false;} + else {new_x = pos_to.x - pos.x;new_x_positive = true;} + if (pos.y > pos_to.y) {new_y = pos.y - pos_to.y; new_y_positive = false;} + else {new_y = pos_to.y - pos.y;new_y_positive = true;} + + if (new_w > new_h) lrg_size = new_w; + else lrg_size = new_h; + if (new_x > new_y) lrg_pos = new_x; + else lrg_pos = new_y; + if (lrg_size > lrg_pos) lrg = lrg_size; + else lrg = lrg_pos; + + if (new_w_positive) {if (box_w < size_to.x) box_w += (new_w / lrg) * global * io.DeltaTime;} + else {if (box_w > size_to.x) box_w -= (new_w / lrg) * global * io.DeltaTime;} + if (new_h_positive) {if (box_h < size_to.y) box_h += (new_h / lrg) * global * io.DeltaTime;} + else {if (box_h > size_to.y) box_h -= (new_h / lrg) * global * io.DeltaTime;} + if (new_x_positive) {if (box_x < pos_to.x) box_x += (new_x / lrg) * global * io.DeltaTime;} + else {if (box_x > pos_to.x) box_x -= (new_x / lrg) * global * io.DeltaTime;} + if (new_y_positive) {if (box_y < pos_to.y) box_y += (new_y / lrg) * global * io.DeltaTime;} + else {if (box_y > pos_to.y) box_y -= (new_y / lrg) * global * io.DeltaTime;} +} + +static inline ImVec2 operator+(const ImVec2 &lhs, const ImVec2 &rhs) { + return ImVec2(lhs.x + rhs.x, lhs.y + rhs.y); +} + +void ImageRotated(ImTextureID tex_id, ImVec2 center, ImVec2 size, float angle) { + ImDrawList *draw_list = ImGui::GetWindowDrawList(); + float cos_a = cosf(angle); + float sin_a = sinf(angle); + + ImVec2 pos[4] = { + center + ImRotate(ImVec2(-size.x * 0.5f, -size.y * 0.5f), cos_a, sin_a), + center + ImRotate(ImVec2(+size.x * 0.5f, -size.y * 0.5f), cos_a, sin_a), + center + ImRotate(ImVec2(+size.x * 0.5f, +size.y * 0.5f), cos_a, sin_a), + center + ImRotate(ImVec2(-size.x * 0.5f, +size.y * 0.5f), cos_a, sin_a)}; + + ImVec2 uvs[4] = { + ImVec2(0.0f, 0.0f), + ImVec2(1.0f, 0.0f), + ImVec2(1.0f, 1.0f), + ImVec2(0.0f, 1.0f)}; + + draw_list->AddImageQuad(tex_id, pos[0], pos[1], pos[2], pos[3], uvs[0], uvs[1], uvs[2], uvs[3], IM_COL32_WHITE); +} + +void rotate_image(const char *image, ImVec2 pos, ImVec2 size, float angle, float speed) { + ImGuiIO &io = ImGui::GetIO(); + ImTextureID image_texture = HelloImGui::ImTextureIdFromAsset(image); + + static float image_angle = angle; + image_angle += io.DeltaTime * speed; + ImVec2 image_center = ImVec2(pos.x, pos.y); + + ImGui::SetCursorPos(pos); + ImageRotated(image_texture, image_center, size, image_angle); +} diff --git a/src/gui_device.cpp b/src/gui_device.cpp new file mode 100644 index 0000000..a06ad88 --- /dev/null +++ b/src/gui_device.cpp @@ -0,0 +1,133 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +extern "C" { + #include + #include +} + + +/* + This will all be removed and merged + into devhelper.c and dfuhelper.c + later on, so for now it stays ig +*/ + + +irecv_device_event_context_t irecvctx_gui = NULL; +usbmuxd_subscription_context_t usbmuxdctx_gui = NULL; +int device_status = DISCONNECTED; +devinfo_t dev; +char const *udid_gui; + +int connected_normal_mode_gui(const usbmuxd_device_info_t *usbmuxd_device) { + int ret; + ret = devinfo_cmd(&dev, usbmuxd_device->udid); + if (ret != 0) { + LOG(LOG_ERROR, "Unable to get device information"); + return 0; + } + udid_gui = usbmuxd_device->udid; + device_status = NORMAL; + if (strcmp(dev.CPUArchitecture, "arm64")) { + LOG(LOG_WARNING, "Ignoring non-arm64 device..."); + return -1; + } + if (!strncmp(dev.productType, "iPhone10,", strlen("iPhone10,"))) { + if (!checkrain_option_enabled(host_flags, host_option_device_info)) + LOG(LOG_VERBOSE2, "Product %s requires passcode to be disabled", dev.productType); + unsigned char passcode_state = 0; + ret = passstat_cmd(&passcode_state, usbmuxd_device->udid); + if (ret != 0) { + LOG(LOG_ERROR, "Failed to get passcode state"); + devinfo_free(&dev); + return -1; + } + if (passcode_state) { + LOG(LOG_ERROR, "Passcode must be disabled on this device"); + if (!checkrain_option_enabled(host_flags, host_option_device_info)) + LOG(LOG_ERROR, "Additionally, passcode must never be set since restore on iOS 16+"); + devinfo_free(&dev); + return -1; + } + } +} + +void device_event_cb_gui(const usbmuxd_event_t *event, void* userdata) { + if (event->device.conn_type != CONNECTION_TYPE_USB) return; + switch (event->event) { + case UE_DEVICE_ADD: + fprintf(stderr, "Normal mode device connected\n"); + connected_normal_mode_gui(&event->device); + break; + case UE_DEVICE_REMOVE: + fprintf(stderr, "Normal mode device disconnected\n"); + device_status = DISCONNECTED; + devinfo_free(&dev); + if (supported_device || unsupported_device) { + supported_device = false; + unsupported_device = false; + waiting_for_device = true; + } + break; + } +} + +void irecv_device_event_cb_gui(const irecv_device_event_t *event, void* userdata) { + switch(event->type) { + case IRECV_DEVICE_ADD: + if (event->mode == IRECV_K_RECOVERY_MODE_1 || event->mode == IRECV_K_RECOVERY_MODE_2 || event->mode == IRECV_K_RECOVERY_MODE_3 || event->mode == IRECV_K_RECOVERY_MODE_4) { + fprintf(stderr, "Recovery mode device %llu connected\n", event->device_info->ecid); + recvinfo_t info; + recvinfo_cmd(&info, event->device_info->ecid); + printf("Mode: recovery\n"); + printf("ProductType: %s\n", info.product_type); + printf("DisplayName: %s\n", info.display_name); + device_status = RECOVERY; + + if (waiting_for_device) { + device_status = RECOVERY; + exitrecv_cmd(event->device_info->ecid); + send_alert("Device in Recovery", "Exiting recovery, device must start from normal mode."); + } + + } else if (event->mode == IRECV_K_DFU_MODE) { + device_status == DFU; + fprintf(stderr, "DFU mode device %llu connected\n", event->device_info->ecid); + } + break; + case IRECV_DEVICE_REMOVE: + fprintf(stderr, "Recovery mode device disconnected\n"); + device_status = DISCONNECTED; + if (enter_dfu) { + device_status = DISCONNECTED; + enter_dfu = false; + waiting_for_device = true; + } + break; + } +} + +void dfuhelper() { + subscribe_cmd(device_event_cb_gui, irecv_device_event_cb_gui); +} + +void guifree() { + devinfo_free(&dev); + unsubscribe_cmd(); +} diff --git a/src/gui_main.cpp b/src/gui_main.cpp new file mode 100644 index 0000000..1cc8f57 --- /dev/null +++ b/src/gui_main.cpp @@ -0,0 +1,350 @@ +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +extern "C" { +#include +} + +/* Bools for which view to show */ +bool waiting_for_device = true; +bool unsupported_device = false; +bool supported_device = false; +bool recovery_wait = false; +bool jailbreak = false; +bool enter_dfu = false; +bool dfu_helper = false; +bool settings = false; +bool execjb = false; + +uint64_t ms() { + using namespace std::chrono; + return duration_cast(system_clock::now().time_since_epoch()).count(); +} + +/* ----------------- [ Main Function ] ----------------- */ + +int main(int argc, char *argv[]) { + if (argc >= 2) { + // temp for testing + return palera1n(argc, argv); + } + + dfuhelper(); + + /* Vars for DFU Healper */ + int dfu_step1 = 3; + int dfu_step2 = 5; + int dfu_step3 = 10; + bool dfu_done = false; + bool set_ms = true; + auto desired = ms() + 1000; + + /* HelloImGui Stuff */ + HelloImGui::RunnerParams params; + params.fpsIdling.fpsIdle = 60.f; + params.appWindowParams.borderless = false; + params.appWindowParams.resizable = false; + params.appWindowParams.windowGeometry.size = {550, 300}; + params.appWindowParams.windowTitle = "palera1n"; + params.appWindowParams.restorePreviousGeometry = false; + params.imGuiWindowParams.defaultImGuiWindowType = HelloImGui::DefaultImGuiWindowType::NoDefaultWindow; + + /* Color & Size Stuff */ + bool open = true; + ImColor grad_color_left = ImColor(255, 177, 35); + ImColor grad_color_right = ImColor(4, 121, 168); + + int grad_color_left_r = 255; + float text_alpha = 0.0f; + bool reverse_gradient = false; + + + /* ImGui Loop */ + params.callbacks.ShowGui = [&]() { + { + /* Init colors, style, and fonts */ + auto &colors = ImGui::GetStyle().Colors; + auto &style = ImGui::GetStyle(); + ImGuiIO &io = ImGui::GetIO(); + init_colors(); + init_style(); + + /* Init window size and start ImGui */ + ImGui::SetNextWindowSize(ImVec2(560, 300)); + ImGui::SetNextWindowPos(ImVec2(-5, 0)); + ImGui::Begin("palera1n", &open, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar); + + /* Set our background gradient */ + ImGui::SetCursorPos(ImVec2(0, 0)); + ImGuiWindow* window = ImGui::GetCurrentWindow(); + if (!reverse_gradient) grad_color_left_r -= FLOAT_TO_INT(io.DeltaTime * 100.f) /2; + else grad_color_left_r += FLOAT_TO_INT(io.DeltaTime * 100.f) /2; + if (grad_color_left_r <= 140) reverse_gradient = true; + if (grad_color_left_r >= 255) reverse_gradient = false; + grad_color_left = ImColor(135, 63, grad_color_left_r) ; + grad_color_right = ImColor(4, 160, grad_color_left_r) ; + + auto dl(ImGui::GetWindowDrawList()); + dl->AddRectFilledMultiColor(ImVec2(0, 0), // pos - x y + ImVec2(560, 300), // size - width height + grad_color_left, // color top left + hex_imcolor(0x2390b4, 1.0f), // color + hex_imcolor(0x04c2a8, 1.0f), // color + grad_color_right); // color + + + if (!recovery_wait && !dfu_helper && !jailbreak) { + ImTextureID settings_icon = HelloImGui::ImTextureIdFromAsset("s60.png"); // pngs will be embedded soon + ImTextureID about_icon = HelloImGui::ImTextureIdFromAsset("i60.png"); // pngs will be embedded soon + image_btn_style_alt(); + ImGui::SetCursorPos(ImVec2(455, 245)); + ImGui::ImageButton(about_icon, ImVec2(33.0f, 33.0f)); + ImGui::SetCursorPos(ImVec2(500, 245)); + ImGui::ImageButton(settings_icon, ImVec2(33.0f, 33.0f)); + reset_design(); + } + + /* Waiting for device view */ + if (waiting_for_device) { + if (device_status == NORMAL) { + const char *name = dev.displayName; + char *arch = dev.CPUArchitecture; + char *type = dev.productType; + char *version = dev.productVersion; + if (strcmp("arm64", arch) != 0) { + waiting_for_device = false; + unsupported_device = true; + btn_x = 213.0f; + btn_y = 190.0f; + btn_w = 125.0f; + btn_h = 35.0f; + } else if (strstr(version, "15") != 0 || strstr(version, "16") != 0) { + waiting_for_device = false; + supported_device = true; + btn_x = 213.0f; + btn_y = 190.0f; + btn_w = 125.0f; + btn_h = 35.0f; + } + } + box_x = 55.0f; box_y = 75.0f; box_w = 450.0f; box_h = 150.0f; + + draw_box(pos(55, 75), size(450, 150), hex_color(0x000000, 0.25f), 20.0f); // box in center + rotate_image("spinner.png", pos(95, 150), size(40, 40), 0.0f, 4.0f); // loading anim in box + label("Waiting for connection...", pos(135,122), WHITE, SF_BoldLarge); // Large title + label("Connect your device in normal mode to get started!", pos(138, 157), WHITE, SF_Reg); // Sub title + + + /* Unsupported device view */ + } else if (unsupported_device) { + + anim_box("Jailbreak", ImVec2(450,150),ImVec2(300,200),ImVec2(54,75),ImVec2(129,50)); + draw_box(ImVec2(box_x, box_y),ImVec2(box_w, box_h), hex_color(0x000000, 0.25f), 20.0f); + + set_pos(167, 90); font(SF_Bold); + ImGui::Text("%s", dev.displayName); + ImGui::PopFont(); + + set_pos(167, 120); font(SF_RegMed); + ImGui::Text("%s running iOS %s (%s)", dev.productType, dev.productVersion, dev.CPUArchitecture); + + colors[ImGuiCol_Text] = hex_color(0xEB5160, 1.0f); + set_pos(167, 147); ImGui::Text(ICON_FA_BAN); + colors[ImGuiCol_Text] = hex_color(0xFFFFFF, 1.0f); + + ImGui::SameLine(); ImGui::Text("Unsupported device connected"); + ImGui::PopFont(); + + set_pos(213, 190); font(SF_RoundBold); btn_text_on; + bool hovered = is_hovered("Exit", 125, 35); + bool pressed = is_pressed("Exit", 125, 35); + ImVec2 btn_size = ImVec2(120, 30); + + if (hovered) { + anim_btn("Exit", ImVec2(125,35),ImVec2(127,37),ImVec2(213,190),ImVec2(212,189)); + btn_size = ImVec2(btn_w, btn_h); + ImGui::SetCursorPos(ImVec2(btn_x,btn_y)); + } else { + anim_btn("Exit", ImVec2(127,37),ImVec2(125,35),ImVec2(212,189),ImVec2(213,190)); + btn_size = ImVec2(btn_w, btn_h); + ImGui::SetCursorPos(ImVec2(btn_x,btn_y)); + } + + ImGui::Button("Exit", btn_size); + if (pressed) { + exit(0); + } + + + /* Supported device view */ + } else if (supported_device) { + anim_box("Jailbreak", ImVec2(450,150),ImVec2(300,200),ImVec2(54,75),ImVec2(129,50)); + draw_box(ImVec2(box_x, box_y),ImVec2(box_w, box_h), hex_color(0x000000, 0.25f), 20.0f); + + set_pos(167, 90); font(SF_Bold); + ImGui::Text("%s", dev.displayName); + ImGui::PopFont(); + + set_pos(167, 120); font(SF_RegMed); + ImGui::Text("%s running iOS %s (%s)", dev.productType, dev.productVersion, dev.CPUArchitecture); + + colors[ImGuiCol_Text] = hex_color(0x3CFF55, 1.0f); + set_pos(167, 147); ImGui::Text(ICON_FA_CHECK_CIRCLE); + colors[ImGuiCol_Text] = hex_color(0xFFFFFF, 1.0f); + + ImGui::SameLine(); ImGui::Text("Connected and ready."); + ImGui::PopFont(); + + set_pos(213, 190); font(SF_RoundBold); btn_text_on; + bool hovered = is_hovered("Jailbreak", 125, 35); + bool pressed = is_pressed("Jailbreak", 125, 35); + ImVec2 btn_size = ImVec2(120, 30); + + if (hovered) { + anim_btn("Jailbreak", ImVec2(125,35),ImVec2(127,37),ImVec2(213,190),ImVec2(212,189)); + btn_size = ImVec2(btn_w, btn_h); + ImGui::SetCursorPos(ImVec2(btn_x,btn_y)); + } else { + anim_btn("Jailbreak", ImVec2(127,37),ImVec2(125,35),ImVec2(212,189),ImVec2(213,190)); + btn_size = ImVec2(btn_w, btn_h); + ImGui::SetCursorPos(ImVec2(btn_x,btn_y)); + } + + ImGui::Button("Jailbreak", btn_size); + if (pressed) { + enter_recovery_cmd(0); + box_x = 140.0f; box_y = 55.0f; box_w = 320.0f; box_h = 240.0f; + supported_device = false; + recovery_wait = true; + btn_text_off; + ImGui::PopFont(); + } + + + /* Waiting for recovery view */ + } else if (recovery_wait) { + + draw_box(ImVec2(125, 105),ImVec2(300, 90), hex_color(0x000000, 0.25f), 20.0f); + //ImageRotated(loader, ImVec2(160, 150), ImVec2(40.0f, 40.0f), angle); + + set_pos(210, 138); font(SF_Bold); + ImGui::Text("Entering recovery..."); + ImGui::PopFont(); + + if (device_status == RECOVERY) { + recovery_wait = false; + enter_dfu = true; + } + + /* Ready for DFU view */ + } else if (enter_dfu) { + + draw_box(ImVec2(65, 105),ImVec2(450, 90), hex_color(0x000000, 0.25f), 20.0f); + + set_pos(110, 128); font(SF_Bold); + ImGui::Text("Time to enter DFU mode!"); + ImGui::PopFont(); + + set_pos(110, 153); font(SF_Reg); + ImGui::Text("Locate the power and volume down button before you proceed."); + + set_pos(108, 210); font(SF_Sm_Bold); btn_text_on; + if (ImGui::Button("Start", ImVec2(125, 35))) { + enter_dfu = false; + dfu_helper = true; + btn_text_off; + ImGui::PopFont(); + } + + /* DFU helper view */ + } else if (dfu_helper) { + draw_box(ImVec2(75, 65),ImVec2(450, 220), hex_color(0x000000, 0.5f), 20.0f); + + if (dfu_step1 > 0) dfu_text_light; + else dfu_text_dark; + set_pos(110, 110); font(SF_Reg); + ImGui::Text("1. Get Ready! %d", dfu_step1); + + if (dfu_step2 > 0 && dfu_step1 == 0) dfu_text_light; + else dfu_text_dark; + set_pos(110, 160); ImGui::Text("2. Hold volume down + side button %d", dfu_step2); + + if (dfu_step3 > 0 && dfu_step2 == 0) dfu_text_light; + else dfu_text_dark;; + set_pos(110, 210);ImGui::Text("3. Release side button, but keep holding volume down %d", dfu_step3); + ImGui::PopFont(); + + if (!dfu_done) { + if (set_ms) { + desired = ms() + 1000; + set_ms = false; + } + if (ms() >= desired) { + set_ms = true; + if (dfu_step1 > 0) dfu_step1 -= 1; + else if (dfu_step2 > 0) dfu_step2 -= 1; + else if (dfu_step3 > 0) dfu_step3 -= 1; + else dfu_done = true; + } + } + + if (dfu_step2 == 2) exitrecv_cmd(dev.ecid); + if (dfu_done) { + if (device_status == DFU) { + guifree(); + dfu_helper = false; + jailbreak = true; + } else { + send_alert("Failed to enter DFU", "Device failed to enter DFU mode, please try again."); + dfu_step1 = 3; dfu_step2 = 5; dfu_step3 = 10; + dfu_done = false; + dfu_helper = false; + waiting_for_device = true; + } + } + + /* Main Jailbreak view */ + } else if (jailbreak) { + pthread_t jb; + + draw_box(ImVec2(25, 70),ImVec2(500, 200), hex_color(0x000000, 0.25f), 20.0f); + + set_pos(20, 15); font(SF_Bold); + ImGui::Text("Installing jailbreak..."); + ImGui::PopFont(); + + set_pos(20, 40); font(SF_Reg); + ImGui::Text("This will take a moment to jailbreak, hang tight!"); + + set_pos(50, 100); font(Hack); + if (!execjb) { + execjb = true; + palera1n(1, NULL); + } + + // redirect logs here... + ImGui::Text("[*] Running..."); + set_pos(50, 125); ImGui::Text("[*] Some epic log stuff will go here :3"); + set_pos(50, 150); ImGui::Text("[*] lorem ipsum :frcoal:"); + ImGui::PopFont(); + + } else { + } + if (settings) { + draw_box(ImVec2(50.0f, 65.0f),ImVec2(230.0f, 230.0f), hex_color(0x000000, 0.5f), 20.0f); + draw_box(ImVec2(320.0f, 65.0f),ImVec2(230.0f, 230.0f), hex_color(0x000000, 0.5f), 20.0f); + } + ImGui::End(); + } + }; + HelloImGui::Run(params); + return 0; +}