Files
palera1n/src/wx/ExploitPanel.cpp
T
C 18023c4037 feat: add tui (#758)
This commit also contains an entire redesign of the GUI interface, which now contains a sidebar for all panels. Hopefully checkra1n approves :)
2026-07-06 04:05:57 -07:00

135 lines
3.9 KiB
C++

#ifdef WITH_GUI
#include "ExploitPanel.hpp"
#include <wx/wx.h>
#include <wx/mstream.h>
#include <wx/image.h>
#include <wx/bitmap.h>
#include <wx/statline.h>
#include <thread>
#ifdef __cplusplus
#include <atomic>
using std::atomic_int;
using std::atomic_bool;
#else
#include <stdatomic.h>
#endif
#include <memory>
#include "AppFrame.hpp"
#include "../m8/run.h"
#include "../utils.h"
#include "../gen/images/logo.h"
ExploitPanel::ExploitPanel(MainFrame* frame, wxWindow* parent)
: DevicePanel(frame, parent)
{
auto* root = new wxBoxSizer(wxHORIZONTAL);
auto* left = new wxBoxSizer(wxVERTICAL);
wxMemoryInputStream stream(images_logo_png, images_logo_png_len);
wxImage img(stream, wxBITMAP_TYPE_PNG);
wxBitmap bmp(img);
auto* logo = new wxStaticBitmap(this, wxID_ANY, bmp);
auto* logoText = new wxStaticText(this, wxID_ANY, "Jailbreak");
auto* right = new wxBoxSizer(wxVERTICAL);
m_statusText = new wxStaticText(this, wxID_ANY, stage_to_string(STAGE_RESET));
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(stage_to_string(STAGE_RESET));
m_progressBar->SetValue(0);
m_backButton->Disable();
frame->ShowMain();
});
left->Add(new wxStaticText(this, wxID_ANY, "Installing jailbreak, this will take a moment. If the device asks for a passcode please enter it. Do not disconnect the device until finished.",
wxDefaultPosition,
wxDefaultSize,
wxST_WRAP
), 0, wxALL, 10);
left->Add(m_statusText, 0, wxALL, 10);
left->Add(m_progressBar, 0, wxALL | wxEXPAND, 20);
right->Add(logo, 0, wxALIGN_CENTER_HORIZONTAL | wxTOP | wxLEFT | wxRIGHT, 10);
right->Add(logoText, 0, wxALIGN_CENTER_HORIZONTAL | wxTOP, 5);
right->AddStretchSpacer();
right->Add(m_backButton, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 10);
root->Add(left, 1, wxEXPAND);
root->Add(new wxStaticLine(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_VERTICAL), 0, wxEXPAND | wxTOP | wxBOTTOM, 10);
root->Add(right, 0, wxEXPAND);
SetSizer(root);
}
void ExploitPanel::SetDeviceState(const DeviceState& state)
{
DevicePanel::SetDeviceState(state);
if (!IsShown())
return;
}
void ExploitPanel::StartExploit()
{
m_backButton->Disable();
std::thread([this]()
{
const auto deviceState = GetDeviceState();
if (!deviceState.connected || deviceState.mode != DeviceMode::DFU) {
wxTheApp->CallAfter([this]() { m_backButton->Enable(); });
return;
}
auto state = std::make_shared<shared_t>();
atomic_init(&state->stage, STAGE_RESET);
atomic_init(&state->stop, false);
atomic_init(&state->result, 0);
auto isFinished = std::make_shared<std::atomic<bool>>(false);
std::thread worker([state, isFinished]()
{
exploit(state.get());
isFinished->store(true);
});
for (;;)
{
int stage = atomic_load(&state->stage);
int progress = stage_to_progress(stage);
bool finished = isFinished->load();
wxTheApp->CallAfter([this, stage, progress, finished]()
{
m_statusText->SetLabel(stage_to_string(stage));
m_progressBar->SetValue(progress);
if (finished || stage == STAGE_DONE) {
m_backButton->Enable();
}
});
if (stage == STAGE_DONE || finished) {
atomic_store(&state->stop, true);
break;
}
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
if (worker.joinable())
worker.join();
}).detach();
}
#endif // WITH_GUI