diff --git a/.gitignore b/.gitignore index e8998f8..d4b4923 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ contrib/ checkra1n* payload.c src/palera1n +src/palera1n.exe !xxd-embedded.h src/binpack.dmg src/ramdisk.dmg diff --git a/Makefile b/Makefile index 534a8dd..c2f53ea 100644 --- a/Makefile +++ b/Makefile @@ -7,11 +7,19 @@ CC ?= cc CFLAGS += -I$(DEP)/include -I$(SRC)/include -I$(SRC) -D_XOPEN_SOURCE=500 CFLAGS += -Wall -Wextra -Wno-unused-parameter -DPALERAIN_VERSION=\"2.0.0\" CFLAGS += -Wno-unused-variable -I$(SRC)/src -std=c99 -pedantic-errors -D_C99_SOURCE -D_POSIX_C_SOURCE=200112L -LIBS += $(DEP)/lib/libimobiledevice-1.0.a $(DEP)/lib/libirecovery-1.0.a $(DEP)/lib/libusbmuxd-2.0.a -LIBS += $(DEP)/lib/libimobiledevice-glue-1.0.a $(DEP)/lib/libplist-2.0.a -pthread -lm ifeq ($(TARGET_OS),) TARGET_OS = $(shell uname -s) endif +ifeq ($(findstring MINGW64,$(TARGET_OS)),MINGW64) +TARGET_OS = Windows +CFLAGS += -DWIN +LIBS = -limobiledevice-1.0 -lirecovery-1.0 -lusbmuxd-2.0 -limobiledevice-glue-1.0 -lplist-2.0 -lssl -lcrypto -lusb-1.0 -lreadline -pthread -lm +LIBS += -lws2_32 -liphlpapi -lsetupapi -lwinusb +else +LIBS += $(DEP)/lib/libimobiledevice-1.0.a $(DEP)/lib/libirecovery-1.0.a $(DEP)/lib/libusbmuxd-2.0.a +LIBS += $(DEP)/lib/libimobiledevice-glue-1.0.a $(DEP)/lib/libplist-2.0.a -pthread -lm +LIBS += $(DEP)/lib/libmbedtls.a $(DEP)/lib/libmbedcrypto.a $(DEP)/lib/libmbedx509.a $(DEP)/lib/libreadline.a +endif ifeq ($(TARGET_OS),Darwin) CFLAGS += -Wno-nullability-extension ifeq (,$(findstring version-min=, $(CFLAGS))) @@ -21,9 +29,11 @@ LDFLAGS += -Wl,-dead_strip LIBS += -framework CoreFoundation -framework IOKit else CFLAGS += -fdata-sections -ffunction-sections -LDFLAGS += -static -no-pie -Wl,--gc-sections +LDFLAGS += -no-pie -Wl,--gc-sections +ifneq ($(TARGET_OS),Windows) +LDFLAGS += -static +endif endif -LIBS += $(DEP)/lib/libmbedtls.a $(DEP)/lib/libmbedcrypto.a $(DEP)/lib/libmbedx509.a $(DEP)/lib/libreadline.a ifeq ($(TUI),1) LIBS += $(DEP)/lib/libnewt.a $(DEP)/lib/libpopt.a $(DEP)/lib/libslang.a @@ -46,7 +56,7 @@ else CFLAGS += -Os -g BUILD_STYLE = RELEASE endif -LIBS += -lc +#LIBS += -lc ifneq ($(BAKERAIN_DEVELOPE_R),) CFLAGS += -DBAKERAIN_DEVELOPE_R="\"$(BAKERAIN_DEVELOPE_R)\"" diff --git a/include/ANSI-color-codes.h b/include/ANSI-color-codes.h index 09bab04..aa5e2f7 100644 --- a/include/ANSI-color-codes.h +++ b/include/ANSI-color-codes.h @@ -78,7 +78,6 @@ #define BHWHT "\033[1;97m" //Reset -#define reset "\033[0m" #define CRESET "\033[0m" #define COLOR_RESET "\033[0m" diff --git a/include/palerain.h b/include/palerain.h index 3aaae4a..23a0c98 100644 --- a/include/palerain.h +++ b/include/palerain.h @@ -14,6 +14,7 @@ #include #include #include +#include #define LOG(loglevel, ...) p1_log(loglevel, __FILE__, __LINE__, __func__, __VA_ARGS__) #define CLEAR() printf("\33[2K\r"); diff --git a/src/Makefile b/src/Makefile index 9d8d3ba..22daaff 100644 --- a/src/Makefile +++ b/src/Makefile @@ -63,8 +63,12 @@ endif ifeq ($(USE_LIBUSB),1) OBJECTS += usb_libusb.o CFLAGS += -DHAVE_LIBUSB -DUSE_LIBUSB=1 +ifeq ($(TARGET_OS),Windows) +LIBS += -lusb-1.0 +else LIBS += $(DEP)/lib/libusb-1.0.a endif +endif ifeq ($(ROOTFUL),1) CFLAGS += -DROOTFUL=1 diff --git a/src/devhelper.c b/src/devhelper.c index e05075f..5190b82 100644 --- a/src/devhelper.c +++ b/src/devhelper.c @@ -7,9 +7,9 @@ #include #include #include -#ifdef WIN32 -#include +#ifdef WIN #include +#include #else #include #include diff --git a/src/dfuhelper.c b/src/dfuhelper.c index 268c278..17bd8f2 100644 --- a/src/dfuhelper.c +++ b/src/dfuhelper.c @@ -8,11 +8,16 @@ #include #include +#ifdef WIN +#include +#include +#else #include #include #include #include #include +#endif #include #include #include diff --git a/src/lock_vars.c b/src/lock_vars.c index a5483b9..aa9cd1f 100644 --- a/src/lock_vars.c +++ b/src/lock_vars.c @@ -9,17 +9,22 @@ #include #include +#ifdef WIN +#include +#include +#else #include #include #include #include +#include +#include #include +#endif #include #include #include #include -#include -#include #include #include diff --git a/src/lockdown_helper.c b/src/lockdown_helper.c index b7b941c..1f0b838 100644 --- a/src/lockdown_helper.c +++ b/src/lockdown_helper.c @@ -1,7 +1,12 @@ #ifndef HAVE_LIBIMOBILEDEVICE #include "lockdown_helper.h" #include +#ifdef WIN +#include +#include +#else #include +#endif #include #include #include diff --git a/src/main.c b/src/main.c index 05d6bf3..1fee1c7 100644 --- a/src/main.c +++ b/src/main.c @@ -10,16 +10,21 @@ #include #include +#ifdef WIN +#include +#include +#else #include #include #include #include +#include +#include #include +#endif #include #include #include -#include -#include #include #include @@ -145,15 +150,21 @@ int palera1n(int argc, char *argv[]) { normal_exit: cleanup: if (override_kpf.magic == OVERRIDE_MAGIC) { + #ifndef WIN munmap(override_kpf.ptr, (size_t)override_kpf.len); + #endif close(override_kpf.fd); } if (override_ramdisk.magic == OVERRIDE_MAGIC) { + #ifndef WIN munmap(override_ramdisk.ptr, (size_t)override_ramdisk.len); + #endif close(override_ramdisk.fd); } if (override_overlay.magic == OVERRIDE_MAGIC) { + #ifndef WIN munmap(override_overlay.ptr, (size_t)override_overlay.len); + #endif close(override_overlay.fd); } pthread_mutex_destroy(&log_mutex); diff --git a/src/optparse.c b/src/optparse.c index 906ea41..523b391 100644 --- a/src/optparse.c +++ b/src/optparse.c @@ -12,7 +12,9 @@ #include #include #include +#ifndef WIN #include +#endif #include uint64_t* palerain_flags_p = &palerain_flags; @@ -327,19 +329,27 @@ int optparse(int argc, char* argv[]) { usage(1, argv[0]); } } + #ifndef WIN if (verbose >= 2) setenv("LIBUSB_DEBUG", "1", 1); + #endif if (verbose >= 3) { libusbmuxd_set_debug_level(verbose - 2); irecv_set_debug_level(1); + #ifndef WIN setenv("LIBUSB_DEBUG", "2", 1); + #endif } if (verbose >= 4) { idevice_set_debug_level(1); + #ifndef WIN setenv("LIBUSB_DEBUG", "3", 1); + #endif } + #ifndef WIN if (verbose >= 5) setenv("LIBUSB_DEBUG", "4", 1); + #endif return 0; } diff --git a/src/override_file.c b/src/override_file.c index fc8ddd9..45e751b 100644 --- a/src/override_file.c +++ b/src/override_file.c @@ -11,7 +11,12 @@ #include #include #include +#ifndef WIN #include +#else +#include +#include +#endif #include @@ -31,11 +36,19 @@ int override_file(override_file_t *finfo, niarelap_file_t** orig, unsigned int * return errno; } LOG(LOG_VERBOSE5, "override_file: fstat fd %d succeeded!", fd); + #ifdef WIN + void *addr = VirtualAlloc(NULL, st.st_size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); + if (addr == NULL) { + LOG(LOG_ERROR, "Failed to map file %s: %d (%s)", filename, errno, strerror(errno)); + return errno; + } + #else void *addr = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); if (addr == MAP_FAILED) { LOG(LOG_ERROR, "Failed to map file %s: %d (%s)", filename, errno, strerror(errno)); return errno; } + #endif LOG(LOG_VERBOSE5, "override_file: Override file mapped successfully"); finfo->magic = OVERRIDE_MAGIC; finfo->fd = fd; diff --git a/src/pongo_helper.c b/src/pongo_helper.c index fd4d5c1..b1370d5 100644 --- a/src/pongo_helper.c +++ b/src/pongo_helper.c @@ -7,8 +7,10 @@ #include // exit, strtoull #include // strlen, strerror, memcpy, memmove #include // close +#ifndef WIN #include // mmap, munmap #include // fstst +#endif #include #include diff --git a/src/usb_libusb.c b/src/usb_libusb.c index 3685379..ae55210 100644 --- a/src/usb_libusb.c +++ b/src/usb_libusb.c @@ -34,8 +34,10 @@ #include // exit, strtoull #include // strlen, strerror, memcpy, memmove #include // close +#ifndef WIN #include // mmap, munmap #include // fstst +#endif #include #define ERR(...) LOG(LOG_ERROR, __VA_ARGS__)