refactor: migrate to C++11

This commit is contained in:
CLARATION committed 2026-07-22 00:59:14 -07:00
1 parent ef3644b684
commit cc45e0a40c
7 files changed
+35 -28

No files matched your search

+1 -1
View File
@@ -4,7 +4,7 @@ project(palera1n VERSION 3.0)
include(FetchContent) include(FetchContent)
include(ExternalProject) include(ExternalProject)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True) set(CMAKE_CXX_STANDARD_REQUIRED True)
if(NOT IOS) if(NOT IOS)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.11") set(CMAKE_OSX_DEPLOYMENT_TARGET "10.11")
+19 -15
View File
@@ -113,14 +113,15 @@ void retain_handle(const hotplug_handle_t& h) {
#endif #endif
} }
template<auto FreeFn> template<typename T, void (*FreeFn)(T*)>
struct Releaser { struct Releaser {
template<typename T> void operator()(T* ptr) const {
void operator()(T* ptr) const { if (ptr) FreeFn(ptr); } if (ptr) FreeFn(ptr);
}
}; };
template<typename T, auto FreeFn> template<typename T, void (*FreeFn)(T*)>
using unique_c_ptr = std::unique_ptr<T, Releaser<FreeFn>>; using unique_c_ptr = std::unique_ptr<T, Releaser<T, FreeFn>>;
std::mutex g_mutex; std::mutex g_mutex;
std::vector<DeviceStateCallback> g_callbacks; std::vector<DeviceStateCallback> g_callbacks;
@@ -168,7 +169,7 @@ void publish_state() {
std::vector<DeviceStateCallback> callbacks; std::vector<DeviceStateCallback> callbacks;
DeviceState state; DeviceState state;
{ {
std::lock_guard lock(g_mutex); std::lock_guard<std::mutex> lock(g_mutex);
callbacks = g_callbacks; callbacks = g_callbacks;
state = build_public_state_locked(); state = build_public_state_locked();
} }
@@ -255,7 +256,7 @@ static void handle_other_add(hotplug_handle_t handle, DeviceMode mode, bool supp
if (ecid == 0) return; if (ecid == 0) return;
{ {
std::lock_guard lock(g_mutex); std::lock_guard<std::mutex> lock(g_mutex);
ManagedDevice& m = g_devices[ecid]; ManagedDevice& m = g_devices[ecid];
release_handle(m.handle); release_handle(m.handle);
@@ -279,9 +280,9 @@ static void handle_other_add(hotplug_handle_t handle, DeviceMode mode, bool supp
static void remove_device(platform_service_t service, DeviceMode mode, uint32_t target_device_id = 0, const std::string& target_udid = "") { static void remove_device(platform_service_t service, DeviceMode mode, uint32_t target_device_id = 0, const std::string& target_udid = "") {
bool changed = false; bool changed = false;
{ {
std::lock_guard lock(g_mutex); std::lock_guard<std::mutex> lock(g_mutex);
auto it = std::find_if(g_devices.begin(), g_devices.end(), [&](const auto& pair) { auto it = std::find_if(g_devices.begin(), g_devices.end(), [&](const std::pair<const uint64_t, ManagedDevice>& pair) {
if (service != IO_OBJECT_NULL) { if (service != IO_OBJECT_NULL) {
#if !defined(__APPLE__) && defined(WITH_CIDERRAIN) #if !defined(__APPLE__) && defined(WITH_CIDERRAIN)
return pair.second.handle.handle == service; return pair.second.handle.handle == service;
@@ -302,7 +303,8 @@ static void remove_device(platform_service_t service, DeviceMode mode, uint32_t
}); });
if (it != g_devices.end()) { if (it != g_devices.end()) {
auto& [ecid, m] = *it; auto& ecid = it->first;
auto& m = it->second;
if (mode == DeviceMode::Normal) { if (mode == DeviceMode::Normal) {
m.normalPresent = false; m.normalPresent = false;
@@ -377,7 +379,7 @@ void usbmuxd_listener_worker() {
known_normal_devices[id] = dev.get_udid().unwrap(); known_normal_devices[id] = dev.get_udid().unwrap();
{ {
std::lock_guard lock(g_mutex); std::lock_guard<std::mutex> lock(g_mutex);
ManagedDevice& m = g_devices[discovered.ecid]; ManagedDevice& m = g_devices[discovered.ecid];
release_handle(m.handle); release_handle(m.handle);
@@ -388,7 +390,9 @@ void usbmuxd_listener_worker() {
m.dfuPresent = false; m.dfuPresent = false;
m.device_id = id; m.device_id = id;
m.usbmuxd_device = std::make_unique<IdeviceFFI::UsbmuxdDevice>(std::move(dev)); m.usbmuxd_device = std::unique_ptr<IdeviceFFI::UsbmuxdDevice>(
new IdeviceFFI::UsbmuxdDevice(std::move(dev))
);
} }
publish_state(); publish_state();
} }
@@ -429,7 +433,7 @@ void register_device_state_callback(DeviceStateCallback cb) {
if (!cb) return; if (!cb) return;
DeviceState snapshot; DeviceState snapshot;
{ {
std::lock_guard lock(g_mutex); std::lock_guard<std::mutex> lock(g_mutex);
g_callbacks.push_back(cb); g_callbacks.push_back(cb);
snapshot = build_public_state_locked(); snapshot = build_public_state_locked();
} }
@@ -448,7 +452,7 @@ bool enter_recovery() {
std::string udid_str = ""; std::string udid_str = "";
{ {
std::lock_guard lock(g_mutex); std::lock_guard<std::mutex> lock(g_mutex);
if (g_activeEcid == 0) return false; if (g_activeEcid == 0) return false;
auto it = g_devices.find(g_activeEcid); auto it = g_devices.find(g_activeEcid);
@@ -479,7 +483,7 @@ void exit_recovery() {
hotplug_handle_t handle; hotplug_handle_t handle;
std::memset(&handle, 0, sizeof(handle)); std::memset(&handle, 0, sizeof(handle));
{ {
std::lock_guard lock(g_mutex); std::lock_guard<std::mutex> lock(g_mutex);
if (g_activeEcid == 0) return; if (g_activeEcid == 0) return;
auto it = g_devices.find(g_activeEcid); auto it = g_devices.find(g_activeEcid);
+1 -1
View File
@@ -325,7 +325,7 @@ static void hotplug_polling_worker() {
active_paths.insert(path); active_paths.insert(path);
if (gConnectedDevices.find(path) == gConnectedDevices.end()) { if (gConnectedDevices.find(path) == gConnectedDevices.end()) {
auto ctx = std::make_unique<PersistentDeviceContext>(); auto ctx = std::unique_ptr<PersistentDeviceContext>(new PersistentDeviceContext());
ctx->device = dev; ctx->device = dev;
if (liteusb_open_handle(&ctx->device, &ctx->session) == LITEUSB_ERR_SUCCESS) { if (liteusb_open_handle(&ctx->device, &ctx->session) == LITEUSB_ERR_SUCCESS) {
+6 -6
View File
@@ -144,11 +144,11 @@ TuiFrame::~TuiFrame() {
void TuiFrame::InitPanels() { void TuiFrame::InitPanels() {
m_panels.resize(PANEL_COUNT); m_panels.resize(PANEL_COUNT);
m_panels[PANEL_MAIN] = std::make_unique<TuiMainPanel>(this); m_panels[PANEL_MAIN] = std::unique_ptr<TuiMainPanel>(new TuiMainPanel(this));
m_panels[PANEL_OPTIONS] = std::make_unique<TuiSettingsPanel>(this); m_panels[PANEL_OPTIONS] = std::unique_ptr<TuiSettingsPanel>(new TuiSettingsPanel(this));
m_panels[PANEL_START_1] = std::make_unique<TuiRecoveryPanel>(this); m_panels[PANEL_START_1] = std::unique_ptr<TuiRecoveryPanel>(new TuiRecoveryPanel(this));
m_panels[PANEL_START_2] = std::make_unique<TuiDfuPanel>(this); m_panels[PANEL_START_2] = std::unique_ptr<TuiDfuPanel>(new TuiDfuPanel(this));
m_panels[PANEL_FINAL] = std::make_unique<TuiExploitPanel>(this); m_panels[PANEL_FINAL] = std::unique_ptr<TuiExploitPanel>(new TuiExploitPanel(this));
} }
void TuiFrame::InitDeviceEventListeners() { void TuiFrame::InitDeviceEventListeners() {
@@ -213,7 +213,7 @@ void TuiFrame::DrawUi() {
std::vector<std::string> labels; std::vector<std::string> labels;
labels.reserve(static_cast<size_t>(btn_cnt)); labels.reserve(static_cast<size_t>(btn_cnt));
const int button_width = std::clamp(SIDEBAR_BUTTON_WIDTH, 8, content_width); const int button_width = std::min(std::max(SIDEBAR_BUTTON_WIDTH, 8), content_width);
for (int i = 0; i < btn_cnt; ++i) { for (int i = 0; i < btn_cnt; ++i) {
labels.push_back(format_sidebar_button_label(panel_buttons[i], button_width)); labels.push_back(format_sidebar_button_label(panel_buttons[i], button_width));
+4 -1
View File
@@ -185,7 +185,10 @@ void TuiDfuPanel::draw_sequence_buttons(int button_x, int button_y, int button_w
const int mapped_x = button_x + scale_coord(btn.x, kDfuPanelCoordinateWidth, button_width); const int mapped_x = button_x + scale_coord(btn.x, kDfuPanelCoordinateWidth, button_width);
const int mapped_y = button_y + scale_coord(btn.y, kDfuButtonCoordinateMaxY, button_height); const int mapped_y = button_y + scale_coord(btn.y, kDfuButtonCoordinateMaxY, button_height);
const int label_x = std::clamp(mapped_x, button_x, button_x + std::max(0, button_width - 1)); const int label_x = std::min(
std::max(mapped_x, button_x),
button_x + std::max(0, button_width - 1)
);
const bool is_active = active_buttons.find(btn.id) != active_buttons.end(); const bool is_active = active_buttons.find(btn.id) != active_buttons.end();
if (is_active) { if (is_active) {
+3 -3
View File
@@ -74,13 +74,13 @@ void TuiExploitPanel::draw(int sy, int sx, int selected) {
mvprintw(sy + 8, content_x, "%.*s", kExploitContentWidth, status_text.empty() ? stage_to_string(STAGE_RESET) : status_text.c_str()); mvprintw(sy + 8, content_x, "%.*s", kExploitContentWidth, status_text.empty() ? stage_to_string(STAGE_RESET) : status_text.c_str());
const int bar_width = 50; const int bar_width = 50;
const int filled = (std::clamp(progress, 0, 100) * bar_width) / 100; const int filled = (std::min(std::max(progress, 0), 100) * bar_width) / 100;
std::string bar(static_cast<size_t>(bar_width), '-'); std::string bar(static_cast<size_t>(bar_width), '-');
for (int i = 0; i < filled; ++i) { for (int i = 0; i < filled; ++i) {
bar[static_cast<size_t>(i)] = '#'; bar[static_cast<size_t>(i)] = '#';
} }
mvprintw(sy + 10, sx + 2, "[%s] %3d%%", bar.c_str(), std::clamp(progress, 0, 100)); mvprintw(sy + 10, sx + 2, "[%s] %3d%%", bar.c_str(), std::min(std::max(progress, 0), 100));
} }
void TuiExploitPanel::handle_enter(int selected, int sy, int sx) { void TuiExploitPanel::handle_enter(int selected, int sy, int sx) {
@@ -105,7 +105,7 @@ bool TuiExploitPanel::is_button_enabled(int btn_idx) const {
void TuiExploitPanel::set_status(const std::string& status, int progress) { void TuiExploitPanel::set_status(const std::string& status, int progress) {
std::lock_guard<std::mutex> lock(m_status_mutex); std::lock_guard<std::mutex> lock(m_status_mutex);
m_status_text = status; m_status_text = status;
m_progress = std::clamp(progress, 0, 100); m_progress = std::min(std::max(progress, 0), 100);
} }
void TuiExploitPanel::exploit() void TuiExploitPanel::exploit()
+1 -1
View File
@@ -57,7 +57,7 @@ private:
std::mutex m_status_mutex; std::mutex m_status_mutex;
std::string m_status_text; std::string m_status_text;
int m_progress = 0; int m_progress = 0;
std::atomic<bool> m_is_exploiting = false; std::atomic<bool> m_is_exploiting{false};
}; };
#endif // TUI_EXPLOIT_PANEL_HPP #endif // TUI_EXPLOIT_PANEL_HPP