From 443bacdc8d2f6f9abc4b352ea0e29c57de4ed72b Mon Sep 17 00:00:00 2001 From: CLARATION Date: Sat, 27 Jun 2026 00:05:02 -0700 Subject: [PATCH] refactor(build): de-dup definitions & manifest changes --- CMakeLists.txt | 16 ++++++++-------- resources/palera1n.exe.manifest | 30 ++++++++++++++++++++---------- src/event.cpp | 4 ++-- src/m8/checkm8.c | 12 ++++++------ src/m8/payload.c | 6 +++--- src/m8/run.c | 2 +- src/main.cpp | 4 ++-- src/usb/pongo_helper.c | 30 +++++++++++++++--------------- src/utils.h | 8 ++++---- 9 files changed, 61 insertions(+), 51 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5eab5d6..a6d300a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,7 +102,7 @@ if(APPLE AND WITH_GUI) MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/resources/Info.plist MACOSX_BUNDLE_ICON_FILE palera1n.icns ) -elseif(MINGW OR MSYS AND WITH_GUI) +elseif(MINGW AND WITH_GUI) set(APP_MANIFEST_RC ${CMAKE_SOURCE_DIR}/resources/app.rc) add_executable(palera1n WIN32 ${SOURCES} ${APP_MANIFEST_RC}) else() @@ -164,7 +164,7 @@ if(WITH_STATIC) mbedtls_LIBS=-lmbedtls\ -lmbedx509\ -lmbedcrypto ) - if(MINGW OR MSYS) + if(MINGW) set(IMD_AUTOTOOLS_ARGS --disable-static --enable-shared @@ -179,7 +179,7 @@ if(WITH_STATIC) ) endif() - if(NOT MINGW AND NOT MSYS) + if(NOT MINGW) # ========================= # mbedTLS # ========================= @@ -200,7 +200,7 @@ if(WITH_STATIC) ) endif() - if(LINUX OR MINGW OR MSYS) + if(LINUX OR MINGW) # ========================= # libusb # ========================= @@ -318,11 +318,11 @@ if(WITH_STATIC) limd_glue_ep ) - if(NOT MINGW AND NOT MSYS) + if(NOT MINGW) list(APPEND LIBIMOBILEDEVICE_DEPS mbedtls_ep) endif() - if(LINUX OR MINGW OR MSYS) + if(LINUX OR MINGW) list(APPEND LIBIMOBILEDEVICE_DEPS libusb_ep) endif() @@ -404,7 +404,7 @@ if(WITH_STATIC) libirecovery_ep ) - if(NOT MINGW AND NOT MSYS) + if(NOT MINGW) add_dependencies(palera1n mbedtls_ep) endif() @@ -428,7 +428,7 @@ if(WITH_STATIC) ) endif() - if(MINGW OR MSYS) + if(MINGW) target_link_libraries(palera1n PRIVATE imobiledevice-1.0 irecovery-1.0 diff --git a/resources/palera1n.exe.manifest b/resources/palera1n.exe.manifest index 5bbe480..b0642a1 100644 --- a/resources/palera1n.exe.manifest +++ b/resources/palera1n.exe.manifest @@ -1,13 +1,13 @@ - - - + + + - - + + + + + + + + + \ No newline at end of file diff --git a/src/event.cpp b/src/event.cpp index 85a5f41..02c314e 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -157,7 +157,7 @@ void recovery_device_event_cb( if (client) { - VERBOSE("Opened client after %d attempts", attempts); + LOG_VERBOSE("Opened client after %d attempts", attempts); irecv_device_t device = nullptr; if (irecv_devices_get_device_by_client(client, &device) == IRECV_E_SUCCESS && device) @@ -170,7 +170,7 @@ void recovery_device_event_cb( } else { - ERROR("Failed to open irecv client after retries"); + LOG_ERROR("Failed to open irecv client after retries"); } state.isSupported = SequenceIsSupported(state.productType); diff --git a/src/m8/checkm8.c b/src/m8/checkm8.c index 0e27b99..310699f 100644 --- a/src/m8/checkm8.c +++ b/src/m8/checkm8.c @@ -165,28 +165,28 @@ bool checkm8_stage_patch(const usb_handle_t *handle, struct DeviceConfiguration create_pongo_payload_for_device(deviceConfig->cpid, &payload, &data_sz); if (payload == NULL || data_sz == 0) { - ERROR("unsupported cpid 0x%X", (unsigned)deviceConfig->cpid); + LOG_ERROR("unsupported cpid 0x%X", (unsigned)deviceConfig->cpid); return false; } - VERBOSE("setting up stage 2 for CPID 0x%X", (unsigned)deviceConfig->cpid); + LOG_VERBOSE("setting up stage 2 for CPID 0x%X", (unsigned)deviceConfig->cpid); data = calloc(1, data_sz); if (!data) { - ERROR("failed to allocate payload buffer"); + LOG_ERROR("failed to allocate payload buffer"); return false; } memcpy(data, payload, data_sz); if(checkm8_usb_request_stall(handle) && checkm8_usb_request_leak(handle)) { - VERBOSE("successfully leaked data"); + LOG_VERBOSE("successfully leaked data"); } else { - ERROR("failed to leak data"); + LOG_ERROR("failed to leak data"); return false; } for(i = 0; i < 2; i++) { - VERBOSE("i = %zu", i); + LOG_VERBOSE("i = %zu", i); send_usb_control_request_no_data(handle, 2, 3, 0, 0x80, 0, NULL); } if(p != NULL && send_usb_control_request(handle, 0x00, 0, 0, 0x00, p, 0x30, &transfer_ret) && transfer_ret.ret == USB_TRANSFER_STALL) { diff --git a/src/m8/payload.c b/src/m8/payload.c index 9a38b81..475d2fb 100644 --- a/src/m8/payload.c +++ b/src/m8/payload.c @@ -56,7 +56,7 @@ bool checkm8_find_device_configuration_for_cpid( config->config_hole = 0; break; default: - ERROR("CPID 0x%x is not supported!", cpid); + LOG_ERROR("CPID 0x%x is not supported!", cpid); foundMatchingConfiguration = false; break; } @@ -226,7 +226,7 @@ bool checkm8_find_payload_configuration_for_cpid( config->usb_serial_number_string_descriptor = 0x18008062A; break; default: - ERROR("CPID 0x%x is not supported!", cpid); + LOG_ERROR("CPID 0x%x is not supported!", cpid); foundMatchingConfiguration = false; } return foundMatchingConfiguration; @@ -237,7 +237,7 @@ void create_pongo_payload_for_device( uint8_t **payload, size_t *payloadSize) { - VERBOSE("Preparing YoloDFU payload for CPID 0x%x.", cpid); + LOG_VERBOSE("Preparing YoloDFU payload for CPID 0x%x.", cpid); *payload = NULL; *payloadSize = 0; diff --git a/src/m8/run.c b/src/m8/run.c index 0c13bcc..3d7ee99 100644 --- a/src/m8/run.c +++ b/src/m8/run.c @@ -140,7 +140,7 @@ static void *pongo_thread(void *arg) if (!seen) { seen = true; - SUCCESS("Pongo device detected!"); + LOG_SUCCESS("Pongo device detected!"); char paleinfo[64]; snprintf(paleinfo, sizeof(paleinfo), "palera1n_flags 0x%" PRIx64, palerain_flags); diff --git a/src/main.cpp b/src/main.cpp index 9b8ecf0..7a96182 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -139,7 +139,7 @@ void parse_arguments(int argc, char* argv[]) { palerain_flags |= palerain_option_verbose_boot; break; case '?': - ERROR("Unknown option"); + LOG_ERROR("Unknown option"); print_usage(argv[0]); exit(1); default: break; @@ -148,7 +148,7 @@ void parse_arguments(int argc, char* argv[]) { if (!(palerain_flags & palerain_option_gui)) { if (!(palerain_flags & palerain_option_rootful) && !(palerain_flags & palerain_option_rootless)) { - ERROR("You must specify either -l, --rootless or -f, --rootful.\n"); + LOG_ERROR("You must specify either -l, --rootless or -f, --rootful.\n"); print_usage(argv[0]); exit(1); } diff --git a/src/usb/pongo_helper.c b/src/usb/pongo_helper.c index 93479ef..4a55972 100644 --- a/src/usb/pongo_helper.c +++ b/src/usb/pongo_helper.c @@ -21,15 +21,15 @@ void compress_pongo(void *out, size_t *out_len) { void checkm8_boot_pongo(usb_handle_t *handle) { transfer_ret_t transfer_ret; - VERBOSE("Booting pongoOS"); - VERBOSE("Compressing pongoOS"); - VERBOSE("Appending shellcode to the top of pongoOS (512 bytes)"); + LOG_VERBOSE("Booting pongoOS"); + LOG_VERBOSE("Compressing pongoOS"); + LOG_VERBOSE("Appending shellcode to the top of pongoOS (512 bytes)"); void *shellcode = malloc(512); memcpy(shellcode, payloads_lz4dec_bin, payloads_lz4dec_bin_len); size_t out_len = payloads_Pongo_bin_len; void *out = malloc(out_len); compress_pongo(out, &out_len); - VERBOSE("Compressed pongoOS from %u to %zu bytes", payloads_Pongo_bin_len, out_len); + LOG_VERBOSE("Compressed pongoOS from %u to %zu bytes", payloads_Pongo_bin_len, out_len); void *tmp = malloc(out_len + 512); memcpy(tmp, shellcode, 512); memcpy(tmp + 512, out, out_len); @@ -37,12 +37,12 @@ void checkm8_boot_pongo(usb_handle_t *handle) { out = tmp; out_len += 512; free(shellcode); - VERBOSE("Setting the compressed size into the shellcode"); + LOG_VERBOSE("Setting the compressed size into the shellcode"); uint32_t* size = (uint32_t*)(out + 0x1fc); *size = out_len - 512; - VERBOSE("Reconnecting to device"); + LOG_VERBOSE("Reconnecting to device"); init_usb_handle(handle, 0x5AC, 0x1227); - VERBOSE("Waiting for device to be ready"); + LOG_VERBOSE("Waiting for device to be ready"); wait_usb_handle(handle); { size_t len = 0; @@ -54,16 +54,16 @@ void checkm8_boot_pongo(usb_handle_t *handle) { send_usb_control_request(handle, 0x21, DFU_DNLOAD, 0, 0, (unsigned char*)&out[len], size, &transfer_ret); if(transfer_ret.sz != size || transfer_ret.ret != USB_TRANSFER_OK) { - VERBOSE("retrying at len = %zu", len); + LOG_VERBOSE("retrying at len = %zu", len); sleep_ms(100); goto retry; } len += size; - VERBOSE("len = %zu", len); + LOG_VERBOSE("len = %zu", len); } } send_usb_control_request_no_data(handle, 0x21, 4, 0, 0, 0, NULL); - VERBOSE("pongoOS sent, should be booting"); + LOG_VERBOSE("pongoOS sent, should be booting"); } int issue_pongo_command(const usb_handle_t *handle, const char *command) { @@ -81,11 +81,11 @@ int issue_pongo_command(const usb_handle_t *handle, const char *command) { size_t len = strlen(command); if (len > 510) { - ERROR("Pongo command too long: %s", command); + LOG_ERROR("Pongo command too long: %s", command); return -1; } - VERBOSE("Executing PongoOS command: '%s'", command); + LOG_VERBOSE("Executing PongoOS command: '%s'", command); snprintf(command_buf, sizeof(command_buf), "%s\n", command); len = strlen(command_buf); @@ -115,7 +115,7 @@ int issue_pongo_command(const usb_handle_t *handle, const char *command) { return 0; } - ERROR("Pongo USB error: %d", tx_status.ret); + LOG_ERROR("Pongo USB error: %d", tx_status.ret); return -1; } @@ -124,11 +124,11 @@ int issue_pongo_command(const usb_handle_t *handle, const char *command) { bool upload_buffer_to_pongo(usb_handle_t *handle, const void *data, size_t length) { if (data == NULL || length == 0) { - ERROR("Invalid data buffer or length."); + LOG_ERROR("Invalid data buffer or length."); return false; } - VERBOSE("Uploading %zu bytes to PongoOS...", length); + LOG_VERBOSE("Uploading %zu bytes to PongoOS...", length); bool ret = false; transfer_ret_t tx_status = {0}; diff --git a/src/utils.h b/src/utils.h index 5d9ab0f..7845260 100644 --- a/src/utils.h +++ b/src/utils.h @@ -26,10 +26,10 @@ typedef enum { } log_level_t; #define LOG(fmt, ...) log_write(LOG_INFO, fmt, ##__VA_ARGS__) -#define SUCCESS(fmt, ...) log_write(LOG_SUCCESS, fmt, ##__VA_ARGS__) -#define WARN(fmt, ...) log_write(LOG_WARN, fmt, ##__VA_ARGS__) -#define ERROR(fmt, ...) log_write(LOG_ERROR, fmt, ##__VA_ARGS__) -#define VERBOSE(fmt, ...) log_write(LOG_VERBOSE, fmt, ##__VA_ARGS__) +#define LOG_SUCCESS(fmt, ...) log_write(LOG_SUCCESS, fmt, ##__VA_ARGS__) +#define LOG_WARN(fmt, ...) log_write(LOG_WARN, fmt, ##__VA_ARGS__) +#define LOG_ERROR(fmt, ...) log_write(LOG_ERROR, fmt, ##__VA_ARGS__) +#define LOG_VERBOSE(fmt, ...) log_write(LOG_VERBOSE, fmt, ##__VA_ARGS__) #ifdef __cplusplus extern "C" {