From 43510986f0c5634abf5be63a03a1e37d626380f8 Mon Sep 17 00:00:00 2001 From: CLARATION Date: Mon, 29 Jun 2026 22:31:51 -0700 Subject: [PATCH] fix(m8): exit properly this time --- src/m8/run.c | 9 ++++++++- src/main.cpp | 4 +--- src/wx/ExploitPanel.cpp | 39 ++++++++++++++++++++++++++------------- src/wx/RecoveryPanel.cpp | 9 ++++----- src/wx/SettingsPanel.cpp | 38 ++++++++++++++++++-------------------- 5 files changed, 57 insertions(+), 42 deletions(-) diff --git a/src/m8/run.c b/src/m8/run.c index 0f374af..f78e410 100644 --- a/src/m8/run.c +++ b/src/m8/run.c @@ -187,8 +187,15 @@ bool exploit(shared_t *state) pthread_create(&t1, NULL, exploit_thread, state); pthread_create(&t2, NULL, pongo_thread, state); + while (!atomic_load(&state->stop)) { + sleep_ms(10); + } + + pthread_cancel(t1); + pthread_cancel(t2); + pthread_join(t1, NULL); pthread_join(t2, NULL); - return atomic_load(&state->result) == 1 && atomic_load(&state->stop); + return atomic_load(&state->result) == 1; } diff --git a/src/main.cpp b/src/main.cpp index fcd5151..4994c27 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -294,7 +294,7 @@ int main(int argc, char* argv[], char* envp[]) { return 0; } else if (palerain_flags & palerain_option_tui) { LOG_WARN("TUI is not implemented yet"); - exit(1); + return 1; } else { shared_t state{}; return exploit(&state); @@ -303,6 +303,4 @@ int main(int argc, char* argv[], char* envp[]) { shared_t state{}; return exploit(&state); #endif - - return 0; } diff --git a/src/wx/ExploitPanel.cpp b/src/wx/ExploitPanel.cpp index 5749574..1e5880d 100644 --- a/src/wx/ExploitPanel.cpp +++ b/src/wx/ExploitPanel.cpp @@ -49,31 +49,33 @@ ExploitPanel::ExploitPanel(MainFrame* frame, wxWindow* parent) { auto* root = new wxBoxSizer(wxVERTICAL); - auto* text = new wxStaticText(this, wxID_ANY, - "Installing jailbreak, this will take a moment. If the device asks for a passcode\nplease enter it. Do not disconnect the device until finished."); + auto* descriptionText = new wxStaticText(this, wxID_ANY, + "Installing jailbreak, this will take a moment. If the device asks for a passcode\n" + "please enter it. Do not disconnect the device until finished." + ); + + m_statusText = new wxStaticText(this, wxID_ANY, stage_to_string(STAGE_RESET)); - m_statusText = new wxStaticText(this, wxID_ANY, "Idle."); m_progressBar = new wxGauge(this, wxID_ANY, 100); m_progressBar->SetValue(0); m_backButton = new wxButton(this, wxID_ANY, "Back"); m_backButton->Disable(); - m_backButton->Bind(wxEVT_BUTTON, [this, frame](wxCommandEvent&) { - m_statusText->SetLabel("Idle."); + m_statusText->SetLabel(stage_to_string(STAGE_RESET)); m_progressBar->SetValue(0); m_backButton->Disable(); frame->ShowMain(); }); - root->Add(text, 0, wxALL, 10); + root->Add(descriptionText, 0, wxALL, 10); root->Add(m_statusText, 0, wxALL, 10); root->Add(m_progressBar, 0, wxALL | wxEXPAND, 20); root->AddStretchSpacer(); auto* bottomRow = new wxBoxSizer(wxHORIZONTAL); bottomRow->AddStretchSpacer(); - bottomRow->Add(m_backButton, 0, wxRIGHT | wxLEFT | wxBOTTOM, 12); + bottomRow->Add(m_backButton, 0, wxRIGHT | wxBOTTOM, 12); root->Add(bottomRow, 0, wxEXPAND); @@ -95,33 +97,44 @@ void ExploitPanel::StartExploit() std::thread([this]() { const auto deviceState = GetDeviceState(); - if (!deviceState.connected || deviceState.mode != DeviceMode::DFU) + if (!deviceState.connected || deviceState.mode != DeviceMode::DFU) { + wxTheApp->CallAfter([this]() { m_backButton->Enable(); }); return; + } auto state = std::make_shared(); atomic_init(&state->stage, STAGE_RESET); atomic_init(&state->stop, false); atomic_init(&state->result, 0); - std::thread worker([state]() + auto isFinished = std::make_shared>(false); + + std::thread worker([state, isFinished]() { exploit(state.get()); + isFinished->store(true); }); - while (true) + for (;;) { int stage = atomic_load(&state->stage); int progress = stage_to_progress(stage); + bool finished = isFinished->load(); - wxTheApp->CallAfter([this, stage, progress]() + wxTheApp->CallAfter([this, stage, progress, finished]() { m_statusText->SetLabel(stage_to_string(stage)); m_progressBar->SetValue(progress); - if (stage == STAGE_DONE) m_backButton->Enable(); + + if (finished || stage == STAGE_DONE) { + m_backButton->Enable(); + } }); - if (stage == STAGE_DONE) + if (stage == STAGE_DONE || finished) { + atomic_store(&state->stop, true); break; + } std::this_thread::sleep_for(std::chrono::milliseconds(100)); } diff --git a/src/wx/RecoveryPanel.cpp b/src/wx/RecoveryPanel.cpp index e000ee7..72866ee 100644 --- a/src/wx/RecoveryPanel.cpp +++ b/src/wx/RecoveryPanel.cpp @@ -26,21 +26,20 @@ RecoveryPanel::RecoveryPanel(MainFrame* frame, wxWindow* parent) root->Add(new wxStaticText(this, wxID_ANY, "The device needs to be put into DFU mode to apply the jailbreak. This is a\n" - "manual process and we will guide you through it.\n\n" + "manual process and we will guide you through it.\n" "In order to prevent filesystem corruption through hard reset, the device will\n" - "be put into recovery mode first. Click next when you are ready."), 0, wxALL, 10); + "be put into recovery mode first. Click next when you are ready." + ), 0, wxALL, 10); m_statusText = new wxStaticText(this, wxID_ANY, ""); root->Add(m_statusText, 0, wxALL, 10); m_backButton = new wxButton(this, wxID_ANY, "Back"); m_nextButton = new wxButton(this, wxID_ANY, "Next"); - m_backButton->Bind(wxEVT_BUTTON, [frame](wxCommandEvent&) { frame->ShowMain(); }); - m_nextButton->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { m_statusText->SetLabel("Entering recovery mode..."); @@ -61,7 +60,7 @@ RecoveryPanel::RecoveryPanel(MainFrame* frame, wxWindow* parent) auto* bottomRow = new wxBoxSizer(wxHORIZONTAL); bottomRow->AddStretchSpacer(); - bottomRow->Add(m_backButton, 0, wxRIGHT | wxLEFT | wxBOTTOM, 12); + bottomRow->Add(m_backButton, 0, wxRIGHT | wxBOTTOM, 12); bottomRow->Add(m_nextButton, 0, wxRIGHT | wxLEFT | wxBOTTOM, 12); root->AddStretchSpacer(); diff --git a/src/wx/SettingsPanel.cpp b/src/wx/SettingsPanel.cpp index fb03227..096ff11 100644 --- a/src/wx/SettingsPanel.cpp +++ b/src/wx/SettingsPanel.cpp @@ -17,19 +17,20 @@ SettingsPanel::SettingsPanel(MainFrame* frame, wxWindow* parent) root->Add(new wxStaticText(this, wxID_ANY, "You may set the following options. If you don't know what they mean you'll\n" - "probably have no reason to set them."), 0, wxALL, 10); + "probably have no reason to set them." + ), 0, wxALL, 10); - auto* option_safemode = new wxCheckBox(this, wxID_ANY, "Safe Mode"); - auto* option_verbose = new wxCheckBox(this, wxID_ANY, "Verbose Boot"); - auto* option_revert = new wxCheckBox(this, wxID_ANY, "Restore System"); - auto* option_dark_blockchain = new wxCheckBox(this, wxID_ANY, "Dark Blockchain"); + auto* optionSafemode = new wxCheckBox(this, wxID_ANY, "Safe Mode"); + auto* optionVerbose = new wxCheckBox(this, wxID_ANY, "Verbose Boot"); + auto* optionRevert = new wxCheckBox(this, wxID_ANY, "Restore System"); + auto* optionDarkBlockchain = new wxCheckBox(this, wxID_ANY, "Dark Blockchain"); - option_safemode->SetValue(palerain_flags & palerain_option_safemode); - option_verbose->SetValue(palerain_flags & palerain_option_verbose_boot); - option_revert->SetValue(palerain_flags & palerain_option_force_revert); - option_dark_blockchain->SetValue(palerain_flags & palerain_option_flower_chain); + optionSafemode->SetValue(palerain_flags & palerain_option_safemode); + optionVerbose->SetValue(palerain_flags & palerain_option_verbose_boot); + optionRevert->SetValue(palerain_flags & palerain_option_force_revert); + optionDarkBlockchain->SetValue(palerain_flags & palerain_option_flower_chain); - option_safemode->Bind(wxEVT_CHECKBOX, [&](wxCommandEvent& e) + optionSafemode->Bind(wxEVT_CHECKBOX, [&](wxCommandEvent& e) { if (e.IsChecked()) palerain_flags |= palerain_option_safemode; @@ -37,7 +38,7 @@ SettingsPanel::SettingsPanel(MainFrame* frame, wxWindow* parent) palerain_flags &= ~palerain_option_safemode; }); - option_verbose->Bind(wxEVT_CHECKBOX, [&](wxCommandEvent& e) + optionVerbose->Bind(wxEVT_CHECKBOX, [&](wxCommandEvent& e) { if (e.IsChecked()) palerain_flags |= palerain_option_verbose_boot; @@ -45,7 +46,7 @@ SettingsPanel::SettingsPanel(MainFrame* frame, wxWindow* parent) palerain_flags &= ~palerain_option_verbose_boot; }); - option_revert->Bind(wxEVT_CHECKBOX, [&](wxCommandEvent& e) + optionRevert->Bind(wxEVT_CHECKBOX, [&](wxCommandEvent& e) { if (e.IsChecked()) palerain_flags |= palerain_option_force_revert; @@ -53,7 +54,7 @@ SettingsPanel::SettingsPanel(MainFrame* frame, wxWindow* parent) palerain_flags &= ~palerain_option_force_revert; }); - option_dark_blockchain->Bind(wxEVT_CHECKBOX, [&](wxCommandEvent& e) + optionDarkBlockchain->Bind(wxEVT_CHECKBOX, [&](wxCommandEvent& e) { if (e.IsChecked()) palerain_flags |= palerain_option_flower_chain; @@ -61,13 +62,11 @@ SettingsPanel::SettingsPanel(MainFrame* frame, wxWindow* parent) palerain_flags &= ~palerain_option_flower_chain; }); - root->Add(option_safemode, 0, wxLEFT | wxRIGHT, 10); - root->Add(option_verbose, 0, wxLEFT | wxRIGHT | wxTOP, 10); - + root->Add(optionSafemode, 0, wxLEFT | wxRIGHT, 10); + root->Add(optionVerbose, 0, wxLEFT | wxRIGHT | wxTOP, 10); root->Add(new wxStaticText(this, wxID_ANY, "Boot Arguments:"), 0, wxALL, 10); auto* bootArgs = new wxTextCtrl(this, wxID_ANY, "", wxDefaultPosition, wxDefaultSize); - bootArgs->SetValue(wxString(boot_args, wxConvUTF8)); bootArgs->Bind(wxEVT_TEXT, [&](wxCommandEvent& e) { @@ -80,9 +79,8 @@ SettingsPanel::SettingsPanel(MainFrame* frame, wxWindow* parent) }); root->Add(bootArgs, 0, wxLEFT | wxRIGHT | wxEXPAND, 30); - - root->Add(option_revert, 0, wxLEFT | wxRIGHT | wxTOP, 10); - root->Add(option_dark_blockchain, 0, wxLEFT | wxRIGHT | wxTOP, 10); + root->Add(optionRevert, 0, wxLEFT | wxRIGHT | wxTOP, 10); + root->Add(optionDarkBlockchain, 0, wxLEFT | wxRIGHT | wxTOP, 10); root->AddStretchSpacer();