feat(gui): add progress

chore: use proper logging
This commit is contained in:
CLARATION committed 2026-06-26 20:56:46 -07:00
1 parent de37667158
commit cdd94742ee
12 files changed
+235 -99

No files matched your search

+83 -26
View File
@@ -2,41 +2,72 @@
#include "ExploitPanel.hpp"
#include <thread>
#include <wx/wx.h>
#include <thread>
#include <atomic>
#include "AppFrame.hpp"
#include "DevicePanel.hpp"
#include "../state.hpp"
#include "../utils.h"
#include "../m8/run.h"
static const char* stage_to_string(int stage)
{
switch (stage) {
case STAGE_PREPARE: return "Checking if device is ready";
case STAGE_RESET: return "Checking if device is ready";
case STAGE_SETUP: return "Setting up the exploit (this is the heap spray)";
case STAGE_SPRAY: return "Setting up the exploit (this is the heap spray)";
case STAGE_PATCH: return "Right before trigger (this is the real bug setup)";
case STAGE_PONGO: return "Booting...";
case STAGE_JAILBREAK: return "Booting...";
case STAGE_DONE: return "Done.";
default: return "Working...";
}
}
static int stage_to_progress(int stage)
{
switch (stage) {
case STAGE_PREPARE: return 5;
case STAGE_RESET: return 15;
case STAGE_SETUP: return 30;
case STAGE_SPRAY: return 50;
case STAGE_PATCH: return 70;
case STAGE_PONGO: return 90;
case STAGE_JAILBREAK: return 95;
case STAGE_DONE: return 100;
default: return 0;
}
}
ExploitPanel::ExploitPanel(MainFrame* frame, wxWindow* parent)
: DevicePanel(frame, 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.");
m_statusText = new wxStaticText(this, wxID_ANY, "");
root->Add(text, 0, wxALL, 10);
root->Add(m_statusText, 0, wxALL, 10);
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, [frame](wxCommandEvent&)
{
m_backButton->Bind(wxEVT_BUTTON, [this, frame](wxCommandEvent&) {
m_statusText->SetLabel("Idle.");
m_progressBar->SetValue(0);
m_backButton->Disable();
frame->ShowMain();
});
auto* bottomRow = new wxBoxSizer(wxHORIZONTAL);
bottomRow->AddStretchSpacer();
bottomRow->Add(m_backButton, 0, wxALL, 10);
root->Add(text, 0, wxALL, 10);
root->Add(m_statusText, 0, wxALL, 10);
root->Add(m_progressBar, 0, wxALL | wxEXPAND, 20);
root->AddStretchSpacer();
root->Add(bottomRow, 0, wxEXPAND);
root->Add(m_backButton, 0, wxALL | wxALIGN_RIGHT, 10);
SetSizer(root);
}
@@ -45,27 +76,53 @@ void ExploitPanel::SetDeviceState(const DeviceState& state)
{
DevicePanel::SetDeviceState(state);
if (!(this->IsShown()))
if (!IsShown())
return;
if (state.mode == DeviceMode::Normal)
{
m_statusText->SetLabel("Done.");
m_backButton->Enable();
}
}
void ExploitPanel::StartExploit()
{
m_statusText->SetLabel("Exploiting device...");
m_statusText->SetLabel("Starting...");
m_backButton->Disable();
std::thread([this]()
{
const auto state = GetDeviceState();
if (!state.connected || state.mode != DeviceMode::DFU)
const auto deviceState = GetDeviceState();
if (!deviceState.connected || deviceState.mode != DeviceMode::DFU)
return;
exploit();
shared_t state{};
atomic_init(&state.result, 0);
atomic_init(&state.stop, false);
atomic_init(&state.exploit_done, false);
atomic_init(&state.pongo_done, false);
atomic_init(&state.stage, STAGE_PREPARE);
std::thread worker([&]() {
exploit(&state);
});
worker.detach();
while (true)
{
int stage = atomic_load(&state.stage);
int progress = stage_to_progress(stage);
wxTheApp->CallAfter([this, stage, progress]() {
m_statusText->SetLabel(stage_to_string(stage));
m_progressBar->SetValue(progress);
});
if (stage == STAGE_DONE) {
wxTheApp->CallAfter([this]() {
m_backButton->Enable();
});
break;
}
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}).detach();
}