convert into static declarations where possible

This commit is contained in:
Nick Chan 2025-02-06 11:45:52 +08:00
parent ad08952999
commit b62347c73e
13 changed files with 70 additions and 73 deletions

View File

@ -204,12 +204,9 @@ boyermoore_horspool_memmem(const unsigned char* haystack, size_t hlen,
const unsigned char* needle, size_t nlen);
extern void* pongo_usb_callback(stuff_t* arg);
usb_ret_t USBControlTransfer(usb_device_handle_t handle, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint32_t wLength, void *data, uint32_t *wLenDone);
const char *usb_strerror(usb_ret_t err);
int wait_for_pongo(void);
int upload_pongo_file(usb_device_handle_t, unsigned char*, unsigned int);
int issue_pongo_command(usb_device_handle_t, char*);
int tui(void);
int optparse(int argc, char* argv[]);
@ -221,7 +218,6 @@ bool set_found_pongo(bool val);
uint64_t get_ecid_wait_for_dfu(void);
uint64_t set_ecid_wait_for_dfu(uint64_t ecid);
void write_stdout(char *buf, uint32_t len);
void io_start(stuff_t *stuff);
void io_stop(stuff_t *stuff);

View File

@ -102,12 +102,9 @@ void tui_draw_rectangle(int x1, int y1, int x2, int y2);
#define TUI_VERSION "Unknown Version"
#endif
extern int tui_state;
extern int tui_x_offset;
extern int tui_y_offset;
extern bool tui_can_start;
extern int tui_mouse_x;
extern int tui_mouse_y;
@ -167,8 +164,6 @@ struct tui_connected_device {
extern struct tui_connected_device *tui_connected_devices;
int tui_compare_versions(const char *firstVersion, const char *secondVersion);
void tui_jailbreak(void);
extern bool tui_is_jailbreaking;
extern int tui_jailbreak_stage;
@ -179,7 +174,6 @@ void tui_jailbreak_status_changed(void);
extern bool tui_is_restarting;
void tui_terminate(int sig);
extern bool tui_options_allow_untested;
extern bool tui_options_safe_mode;
extern bool tui_options_verbose_boot;
extern bool tui_options_force_revert;

View File

@ -40,7 +40,7 @@
int dfuhelper_thr_running = false;
void step(int time, int time2, char *text, bool (*cond)(uint64_t), uint64_t cond_arg) {
static void step(int time, int time2, char *text, bool (*cond)(uint64_t), uint64_t cond_arg) {
for (int i = time2; i < time; i++) {
printf(
(palerain_flags & palerain_option_no_colors)
@ -59,7 +59,7 @@ void step(int time, int time2, char *text, bool (*cond)(uint64_t), uint64_t cond
if (time2 == 0) puts("");
}
int connected_normal_mode(const usbmuxd_device_info_t *usbmuxd_device) {
static int connected_normal_mode(const usbmuxd_device_info_t *usbmuxd_device) {
devinfo_t dev;
int ret;
ret = devinfo_cmd(&dev, usbmuxd_device->udid);
@ -133,7 +133,7 @@ static bool conditional(uint64_t ecid) {
return get_ecid_wait_for_dfu() != ecid;
}
void* connected_recovery_mode(struct irecv_device_info* info) {
static void* connected_recovery_mode(struct irecv_device_info* info) {
int ret;
uint64_t ecid;
uint32_t cpid, bdid;
@ -223,7 +223,7 @@ void* connected_recovery_mode(struct irecv_device_info* info) {
return NULL;
}
void* connected_dfu_mode(struct irecv_device_info* info) {
static void* connected_dfu_mode(struct irecv_device_info* info) {
if (get_ecid_wait_for_dfu() == info->ecid) {
set_ecid_wait_for_dfu(0);
puts("");
@ -240,7 +240,7 @@ void* connected_dfu_mode(struct irecv_device_info* info) {
return NULL;
}
void device_event_cb(const usbmuxd_event_t *event, void* userdata) {
static void device_event_cb(const usbmuxd_event_t *event, void* userdata) {
if (event->device.conn_type != CONNECTION_TYPE_USB) return;
switch (event->event) {
case UE_DEVICE_ADD:
@ -265,7 +265,7 @@ void device_event_cb(const usbmuxd_event_t *event, void* userdata) {
}
}
void irecv_device_event_cb(const irecv_device_event_t *event, void* userdata) {
static void irecv_device_event_cb(const irecv_device_event_t *event, void* userdata) {
pthread_t recovery_thread, dfu_thread;
int ret;

View File

@ -57,7 +57,7 @@ void thr_cleanup(void* ptr) {
*(int*)ptr = 0;
}
int build_checks(void) {
static int build_checks(void) {
#ifndef NO_CHECKRAIN
#if defined(__APPLE__)
struct mach_header_64* c1_header = (struct mach_header_64*)&checkra1n[0];
@ -96,7 +96,7 @@ int saved_argc;
char** saved_argv;
char** saved_envp;
int palera1n(int argc, char *argv[], char *envp[]) {
static int palera1n(int argc, char *argv[], char *envp[]) {
saved_argc = argc;
saved_argv = argv;
saved_envp = envp;

View File

@ -14,7 +14,6 @@
#include <sys/mman.h>
#include <errno.h>
int override_file(override_file_t *finfo, niarelap_file_t** orig, unsigned int *orig_len, char *filename) {
int ret = 0;
int fd = open(filename, O_RDONLY);

View File

@ -21,6 +21,10 @@ int pongo_thr_running = 0;
#define ERR(...) LOG(LOG_VERBOSE, __VA_ARGS__)
static int issue_pongo_command(usb_device_handle_t, char*);
static int upload_pongo_file(usb_device_handle_t, unsigned char*, unsigned int);
static void write_stdout(char *buf, uint32_t len);
void* pongo_helper(void* ptr) {
pongo_thr_running = 1;
pthread_cleanup_push(thr_cleanup, &pongo_thr_running);
@ -32,7 +36,7 @@ void* pongo_helper(void* ptr) {
return NULL;
}
void *pongo_usb_callback(stuff_t *arg) {
static void *pongo_usb_callback(stuff_t *arg) {
if (get_found_pongo())
return NULL;
set_found_pongo(1);
@ -145,7 +149,7 @@ done:
return NULL;
}
int issue_pongo_command(usb_device_handle_t handle, char *command)
static int issue_pongo_command(usb_device_handle_t handle, char *command)
{
uint32_t outpos = 0;
uint32_t outlen = 0;
@ -207,7 +211,7 @@ bad:
return ret;
}
int upload_pongo_file(usb_device_handle_t handle, unsigned char *buf, unsigned int buf_len)
static int upload_pongo_file(usb_device_handle_t handle, unsigned char *buf, unsigned int buf_len)
{
int ret = 0;
ret = USBControlTransfer(handle, 0x21, 1, 0, 0, 4, &buf_len, NULL);
@ -263,7 +267,7 @@ void io_stop(stuff_t *stuff)
#endif
}
void write_stdout(char *buf, uint32_t len)
static void write_stdout(char *buf, uint32_t len)
{
while(len > 0) {
if (verbose >= 3) {

View File

@ -3,7 +3,7 @@
#include <palerain.h>
#include <tui.h>
irecv_device_t tui_get_recovery_device(uint64_t ecid) {
static irecv_device_t tui_get_recovery_device(uint64_t ecid) {
irecv_client_t client = NULL;
for (int i = 0; i <= 5; i++) {
irecv_error_t err = irecv_open_with_ecid(&client, ecid);
@ -28,7 +28,7 @@ irecv_device_t tui_get_recovery_device(uint64_t ecid) {
struct tui_connected_device *tui_connected_devices = NULL;
void* tui_connected_recovery_mode(struct irecv_device_info* info) {
static void* tui_connected_recovery_mode(struct irecv_device_info* info) {
//printf("Recovery mode device %" PRIu64 " connected\n", info->ecid);
tui_last_event = TUI_EVENT_CONNECTED_DEVICES_CHANGED;
sem_post(tui_event_semaphore);
@ -36,7 +36,7 @@ void* tui_connected_recovery_mode(struct irecv_device_info* info) {
return NULL;
}
void* tui_disconnected_recovery_mode(struct irecv_device_info* info) {
static void* tui_disconnected_recovery_mode(struct irecv_device_info* info) {
//printf("Recovery mode device %" PRIu64 " disconnected\n", info->ecid);
tui_last_event = TUI_EVENT_CONNECTED_DEVICES_CHANGED;
sem_post(tui_event_semaphore);
@ -44,7 +44,7 @@ void* tui_disconnected_recovery_mode(struct irecv_device_info* info) {
return NULL;
}
void* tui_connected_dfu_mode(struct irecv_device_info* info) {
static void* tui_connected_dfu_mode(struct irecv_device_info* info) {
//printf("DFU mode device %" PRIu64 " connected\n", info->ecid);
tui_last_event = TUI_EVENT_CONNECTED_DEVICES_CHANGED;
sem_post(tui_event_semaphore);
@ -52,7 +52,7 @@ void* tui_connected_dfu_mode(struct irecv_device_info* info) {
return NULL;
}
void* tui_disconnected_dfu_mode(struct irecv_device_info* info) {
static void* tui_disconnected_dfu_mode(struct irecv_device_info* info) {
//printf("DFU mode device %" PRIu64 " disconnected\n", info->ecid);
tui_last_event = TUI_EVENT_CONNECTED_DEVICES_CHANGED;
sem_post(tui_event_semaphore);
@ -60,7 +60,7 @@ void* tui_disconnected_dfu_mode(struct irecv_device_info* info) {
return NULL;
}
int tui_connected_normal_mode(const usbmuxd_device_info_t *usbmuxd_device) {
static int tui_connected_normal_mode(const usbmuxd_device_info_t *usbmuxd_device) {
struct tui_connected_device *tui_dev = malloc(sizeof(struct tui_connected_device));
strcpy(tui_dev->udid, usbmuxd_device->udid);
tui_dev->next = tui_connected_devices;
@ -105,7 +105,7 @@ int tui_connected_normal_mode(const usbmuxd_device_info_t *usbmuxd_device) {
return 0;
}
void tui_disconnected_normal_mode(const usbmuxd_device_info_t *usbmuxd_device) {
static void tui_disconnected_normal_mode(const usbmuxd_device_info_t *usbmuxd_device) {
struct tui_connected_device *cur = tui_connected_devices;
struct tui_connected_device *prev = NULL;
while (cur) {
@ -126,7 +126,7 @@ void tui_disconnected_normal_mode(const usbmuxd_device_info_t *usbmuxd_device) {
sem_post(tui_event_semaphore);
}
void tui_device_event_cb(const usbmuxd_event_t *event, void* userdata) {
static void tui_device_event_cb(const usbmuxd_event_t *event, void* userdata) {
if (event->device.conn_type != CONNECTION_TYPE_USB) return;
switch (event->event) {
case UE_DEVICE_ADD:
@ -140,7 +140,7 @@ void tui_device_event_cb(const usbmuxd_event_t *event, void* userdata) {
}
}
void tui_irecv_device_event_cb(const irecv_device_event_t *event, void* userdata) {
static void tui_irecv_device_event_cb(const irecv_device_event_t *event, void* userdata) {
pthread_t recovery_thread, dfu_thread;
int ret;

View File

@ -28,13 +28,14 @@ int proc_pidpath(int pid, void * buffer, uint32_t buffersize);
char random_sem_name[sizeof("palera1n.tui_event_semaphore") + 16 + 1];
#endif
int tui_state = 0;
static int tui_state = 0;
int tui_x_offset = 0;
int tui_y_offset = 0;
bool supports_bright_colors = true;
struct termios saved_termios;
static struct termios saved_termios;
int redraw_screen(void) {
SETCOLOR(FG_BRIGHT_WHITE, BG_BLACK);
@ -83,7 +84,7 @@ int redraw_screen(void) {
return 0;
}
int destroy_window(void) {
static int destroy_window(void) {
if (!tui_started) return 0;
tui_started = false;
tcsetattr(STDIN_FILENO, 0, &saved_termios);
@ -97,7 +98,7 @@ int destroy_window(void) {
return 0;
}
int init_window(void) {
static int init_window(void) {
setlocale(LC_ALL, NULL);
tui_started = true;
@ -151,7 +152,7 @@ void tui_terminate(int sig) {
}
}
void resize_handler(int sig) {
static void resize_handler(int sig) {
redraw_screen();
}

View File

@ -28,9 +28,9 @@
#include <palerain.h>
#include <tui.h>
int tui_enter_dfu_nav_selection = 1;
bool tui_device_is_entering_dfu = false;
int tui_enter_dfu_status = 0;
static int tui_enter_dfu_nav_selection = 1;
static bool tui_device_is_entering_dfu = false;
static int tui_enter_dfu_status = 0;
enum {
DEVICE_TYPE_IPHONE_SE,
@ -41,7 +41,7 @@ enum {
DEVICE_TYPE_IPOD_TOUCH
} device_type;
int tui_product_type_to_device_type(char *product_type) {
static int tui_product_type_to_device_type(char *product_type) {
if (strcmp(product_type, "iPhone8,1") == 0 || strcmp(product_type, "iPhone8,2") == 0) {
return DEVICE_TYPE_IPHONE_6S;
}
@ -68,11 +68,11 @@ int tui_product_type_to_device_type(char *product_type) {
return DEVICE_TYPE_IPHONE_SE;
}
int tui_enter_dfu_device_type = DEVICE_TYPE_IPHONE_SE;
static int tui_enter_dfu_device_type = DEVICE_TYPE_IPHONE_SE;
int tui_enter_dfu_loading_progress = 1;
static int tui_enter_dfu_loading_progress = 1;
void tui_screen_enter_dfu_nav(void) {
static void tui_screen_enter_dfu_nav(void) {
MOVETOT(80 - 22, 23);
printf("%s[ Cancel ]" COLOR(FG_WHITE, BG_BLACK) " %s[ %s ]" COLOR(FG_WHITE, BG_BLACK),
tui_device_is_entering_dfu || tui_enter_dfu_status == 1 ? (supports_bright_colors ? COLOR(FG_BRIGHT_BLACK, BG_BLACK) : COLOR(FG_BLUE, BG_BLACK)) : tui_enter_dfu_nav_selection == 0 ? "\033[30;107m" : (
@ -343,9 +343,9 @@ void tui_screen_enter_dfu_redraw(void) {
}
// TODO: IMPLEMENT REAL ENTER RECOVERY
int dfu_time = 0;
static int dfu_time = 0;
tui_screen_t tui_enter_dfu(void) {
static tui_screen_t tui_enter_dfu(void) {
if (tui_connected_devices && !tui_connected_devices->next) {
if (tui_connected_devices->mode == TUI_DEVICE_MODE_NORMAL) {
tui_enter_dfu_status = 0;
@ -391,7 +391,7 @@ tui_screen_t tui_enter_dfu(void) {
return JAILBREAK_SCREEN;
}
int tui_enter_dfu_nav_mouse_select = -1;
static int tui_enter_dfu_nav_mouse_select = -1;
tui_screen_t tui_screen_enter_dfu(void) {
if (tui_connected_devices && !tui_connected_devices->next) {

View File

@ -18,7 +18,7 @@ int tui_enter_recovery_nav_selection = 1;
bool tui_device_is_entering_recovery = false;
bool tui_enter_recovery_mode_failed = false;
void tui_screen_enter_recovery_nav(void) {
static void tui_screen_enter_recovery_nav(void) {
MOVETOT(80 - 22, 23);
printf("%s[ Back ]" COLOR(FG_WHITE, BG_BLACK) " %s[ Next ]" COLOR(FG_WHITE, BG_BLACK),
tui_device_is_entering_recovery ? (supports_bright_colors ? COLOR(FG_BRIGHT_BLACK, BG_BLACK) : COLOR(FG_BLUE, BG_BLACK)) : tui_enter_recovery_nav_selection == 0 ? "\033[30;107m" : (
@ -34,7 +34,7 @@ void tui_screen_enter_recovery_nav(void) {
);
}
char enter_recovery_loading[9][8] = {
static char enter_recovery_loading[9][8] = {
"........",
"|.......",
".|......",
@ -46,7 +46,7 @@ char enter_recovery_loading[9][8] = {
".......|"
};
char enter_recovery_loading_troll[9][8] = {
static char enter_recovery_loading_troll[9][8] = {
".......",
"t......",
".r.....",
@ -57,10 +57,10 @@ char enter_recovery_loading_troll[9][8] = {
"......d",
};
bool is_troll;
int tui_enter_recovery_loading_progress = 0;
static bool is_troll;
static int tui_enter_recovery_loading_progress = 0;
void tui_screen_enter_recovery_loading(void) {
static void tui_screen_enter_recovery_loading(void) {
SETCOLOR(FG_YELLOW, BG_BLACK);
PRINTATT(3, 8, "Entering recovery mode ");
printf("%.8s", is_troll ? enter_recovery_loading_troll[tui_enter_recovery_loading_progress] : enter_recovery_loading[tui_enter_recovery_loading_progress]);
@ -88,9 +88,9 @@ void tui_screen_enter_recovery_redraw(void) {
fflush(stdout);
}
int recovery_time = 0;
static int recovery_time = 0;
tui_screen_t tui_enter_recovery(void) {
static tui_screen_t tui_enter_recovery(void) {
enter_recovery_cmd(tui_connected_devices->udid);
is_troll = false;
if (rand() % 1000 == 0) {
@ -128,7 +128,7 @@ tui_screen_t tui_enter_recovery(void) {
}
}
int tui_enter_recovery_nav_mouse_select = -1;
static int tui_enter_recovery_nav_mouse_select = -1;
tui_screen_t tui_screen_enter_recovery(void) {
tui_device_is_entering_recovery = false;

View File

@ -15,7 +15,7 @@
bool tui_is_jailbreaking = false;
void tui_screen_jailbreak_nav(void) {
static void tui_screen_jailbreak_nav(void) {
if (tui_is_jailbreaking) {
if (supports_bright_colors) {
SETCOLOR(FG_BRIGHT_BLACK, BG_BLACK);
@ -29,7 +29,8 @@ void tui_screen_jailbreak_nav(void) {
SETCOLOR(FG_WHITE, BG_BLACK);
}
pthread_t tui_jailbreak_thread_id;
static pthread_t tui_jailbreak_thread_id;
int tui_jailbreak_stage = 0;
char *tui_jailbreak_status = NULL;
@ -38,7 +39,7 @@ void tui_jailbreak_status_changed(void) {
sem_post(tui_event_semaphore);
}
void *tui_jailbreak_thread(void *arg) {
static void *tui_jailbreak_thread(void *arg) {
tui_jailbreak_stage = 1;
tui_jailbreak_status = "About to execute checkra1n";
@ -121,7 +122,7 @@ void tui_screen_jailbreak_redraw(void) {
tui_screen_jailbreak_nav();
}
int tui_jailbreak_nav_mouse_select = -1;
static int tui_jailbreak_nav_mouse_select = -1;
tui_screen_t tui_screen_jailbreak(void) {
redraw_screen();

View File

@ -13,9 +13,11 @@
#include <palerain.h>
#include <tui.h>
bool showing_ecid = false;
static int tui_compare_versions(const char *firstVersion, const char *secondVersion);
char palera1n_logo[17][16] = {
static bool showing_ecid = false;
static char palera1n_logo[17][16] = {
" ++ ",
" #@@# ",
" +@@@@+ ",
@ -34,7 +36,7 @@ char palera1n_logo[17][16] = {
" :++: "
};
char random_quotes[][150] = {
static char random_quotes[][150] = {
"panic(cpu 1 caller 0xfffffff0232bd958): SEP Panic",
"Now with Apple TV support!",
"checkra1n will open source in 2020",
@ -49,10 +51,10 @@ char random_quotes[][150] = {
#define PALERA1N_URL "https://palera.in"
int tui_main_nav_selection = 1;
bool quick_mode_enabled = false;
bool tui_can_start = false;
int random_quote;
static int tui_main_nav_selection = 1;
static bool quick_mode_enabled = false;
static bool tui_can_start = false;
static int random_quote;
bool easter_egg = false;
@ -206,7 +208,7 @@ void tui_screen_main_redraw(void) {
fflush(stdout);
}
int tui_main_nav_mouse_select = -1;
static int tui_main_nav_mouse_select = -1;
tui_screen_t tui_screen_main(void) {
random_quote = ((unsigned int)((rand()+rand())/2)) % 8;
@ -329,7 +331,7 @@ tui_screen_t tui_screen_main(void) {
return MAIN_SCREEN;
}
int tui_version_extract_component(const char *version, int index) {
static int tui_version_extract_component(const char *version, int index) {
int component = 0;
int componentIndex = 0;
for (int i = 0; version[i] != '\0'; i++) {
@ -348,7 +350,7 @@ int tui_version_extract_component(const char *version, int index) {
return component;
}
int tui_compare_versions(const char *firstVersion, const char *secondVersion) {
static int tui_compare_versions(const char *firstVersion, const char *secondVersion) {
if (strcmp(firstVersion, secondVersion) == 0) {
return 0;
}

View File

@ -13,10 +13,10 @@
#include <palerain.h>
#include <tui.h>
int tui_options_nav_selection = 0;
int tui_options_nav_mouse_select = 0;
static int tui_options_nav_selection = 0;
static int tui_options_nav_mouse_select = 0;
bool tui_options_allow_untested = false;
static bool tui_options_allow_untested = false;
bool tui_options_safe_mode = false;
bool tui_options_verbose_boot = false;
bool tui_options_force_revert = false;