2023-01-16 16:17:41 +08:00
|
|
|
#ifndef COMMON_H
|
|
|
|
|
#define COMMON_H
|
|
|
|
|
|
|
|
|
|
#include "lockdown_helper.h"
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
#include <usbmuxd.h>
|
|
|
|
|
#include <libirecovery.h>
|
2023-01-17 13:46:42 +08:00
|
|
|
#include <libusb-1.0/libusb.h>
|
2023-01-16 16:17:41 +08:00
|
|
|
|
|
|
|
|
#define LOG(loglevel, ...) p1_log(loglevel, __FILE__, __LINE__, __func__, __VA_ARGS__)
|
|
|
|
|
#define CLEAR() printf("\33[2K\r");
|
2023-01-18 16:02:43 +08:00
|
|
|
#define palerain_option_version 129
|
2023-01-16 16:17:41 +08:00
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
|
LOG_FATAL = 0,
|
|
|
|
|
LOG_ERROR = 1,
|
|
|
|
|
LOG_WARNING = 2,
|
|
|
|
|
LOG_INFO = 3,
|
2023-01-18 00:44:47 +08:00
|
|
|
LOG_VERBOSE = 4,
|
2023-01-18 17:58:20 +08:00
|
|
|
LOG_VERBOSE2 = 5,
|
|
|
|
|
LOG_VERBOSE3 = 6,
|
|
|
|
|
LOG_VERBOSE4 = 7,
|
2023-01-22 23:20:46 +08:00
|
|
|
LOG_VERBOSE5 = 8,
|
2023-01-16 16:17:41 +08:00
|
|
|
} log_level_t;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
uint64_t ecid;
|
|
|
|
|
char* productType;
|
|
|
|
|
char* productVersion;
|
|
|
|
|
char* buildVersion;
|
|
|
|
|
char* CPUArchitecture;
|
|
|
|
|
const char* displayName;
|
|
|
|
|
} devinfo_t;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
int mode;
|
|
|
|
|
unsigned int cpid;
|
|
|
|
|
char product_type[0x20];
|
|
|
|
|
char display_name[0x20];
|
|
|
|
|
char iboot_ver[0x20];
|
|
|
|
|
} recvinfo_t;
|
|
|
|
|
|
2023-01-18 17:58:20 +08:00
|
|
|
typedef struct {
|
|
|
|
|
uint32_t magic; /* 0xd803b376*/
|
|
|
|
|
unsigned char* ptr; /* pointer to the override file in memory */
|
|
|
|
|
unsigned int len; /* length of override file */
|
|
|
|
|
unsigned char* orig_ptr; /* pointer to the overriden file */
|
|
|
|
|
unsigned int orig_len; /* length of the overriden file */
|
|
|
|
|
int fd; /* file descriptor of the override file */
|
|
|
|
|
} override_file_t;
|
|
|
|
|
|
2023-01-16 16:17:41 +08:00
|
|
|
// set this value to 0 gracefully exit
|
|
|
|
|
extern int spin;
|
2023-01-18 16:02:43 +08:00
|
|
|
extern unsigned int verbose;
|
2023-01-17 21:40:32 +08:00
|
|
|
extern int demote;
|
2023-01-22 19:18:35 +08:00
|
|
|
extern char* pongo_path;
|
2023-01-17 13:46:42 +08:00
|
|
|
|
|
|
|
|
extern bool dfuhelper_only;
|
|
|
|
|
extern bool pongo_exit;
|
2023-01-16 16:17:41 +08:00
|
|
|
|
|
|
|
|
void* dfuhelper(void* ptr);
|
|
|
|
|
int p1_log(log_level_t loglevel, const char *fname, int lineno, const char *fxname, char* __restrict format, ...);
|
|
|
|
|
/* devhelper helpers */
|
|
|
|
|
void devinfo_free(devinfo_t *dev);
|
|
|
|
|
bool cpid_is_arm64(unsigned int cpid);
|
|
|
|
|
/* devhelper commands */
|
|
|
|
|
int subscribe_cmd(usbmuxd_event_cb_t device_event_cb, irecv_device_event_cb_t irecv_event_cb);
|
|
|
|
|
int unsubscribe_cmd();
|
|
|
|
|
int devinfo_cmd(devinfo_t *dev, const char *udid);
|
|
|
|
|
int enter_recovery_cmd(const char* udid);
|
|
|
|
|
int reboot_cmd(const char* udid);
|
|
|
|
|
int passstat_cmd(char* status, const char* udid);
|
|
|
|
|
int recvinfo_cmd(recvinfo_t* info, const uint64_t ecid);
|
|
|
|
|
int autoboot_cmd(const uint64_t ecid);
|
|
|
|
|
int exitrecv_cmd(const uint64_t ecid);
|
|
|
|
|
|
2023-01-16 17:33:12 +08:00
|
|
|
void exec_checkra1n();
|
2023-01-17 13:46:42 +08:00
|
|
|
|
|
|
|
|
typedef int usb_ret_t;
|
|
|
|
|
typedef libusb_device_handle *usb_device_handle_t;
|
|
|
|
|
|
|
|
|
|
#define USB_RET_SUCCESS LIBUSB_SUCCESS
|
|
|
|
|
#define USB_RET_NOT_RESPONDING LIBUSB_ERROR_OTHER
|
2023-01-18 01:49:16 +08:00
|
|
|
#define USB_RET_IO LIBUSB_ERROR_IO
|
2023-01-17 13:46:42 +08:00
|
|
|
|
|
|
|
|
extern void* pongo_usb_callback(void* 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);
|
2023-01-22 21:02:19 +08:00
|
|
|
usb_ret_t USBBulkUpload(usb_device_handle_t handle, void *data, int len);
|
2023-01-17 13:46:42 +08:00
|
|
|
const char *usb_strerror(usb_ret_t err);
|
|
|
|
|
int wait_for_pongo();
|
2023-01-18 00:44:47 +08:00
|
|
|
int issue_pongo_command();
|
|
|
|
|
int upload_pongo_file();
|
2023-01-16 18:06:23 +08:00
|
|
|
#endif
|