feat: add Windows building support, needs cleanup.

This commit is contained in:
Mineek committed 2023-07-17 17:53:41 +02:00
1 parent 0df72933a8
commit 5c41f37b39
14 files changed
+80 -12

No files matched your search

+1
View File
@@ -8,6 +8,7 @@ contrib/
checkra1n*
payload.c
src/palera1n
src/palera1n.exe
!xxd-embedded.h
src/binpack.dmg
src/ramdisk.dmg
+15 -5
View File
@@ -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)\""
-1
View File
@@ -78,7 +78,6 @@
#define BHWHT "\033[1;97m"
//Reset
#define reset "\033[0m"
#define CRESET "\033[0m"
#define COLOR_RESET "\033[0m"
+1
View File
@@ -14,6 +14,7 @@
#include <usbmuxd.h>
#include <libirecovery.h>
#include <libimobiledevice/libimobiledevice.h>
#include <pthread.h>
#define LOG(loglevel, ...) p1_log(loglevel, __FILE__, __LINE__, __func__, __VA_ARGS__)
#define CLEAR() printf("\33[2K\r");
+4
View File
@@ -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
+2 -2
View File
@@ -7,9 +7,9 @@
#include <stddef.h>
#include <unistd.h>
#include <ctype.h>
#ifdef WIN32
#include <windows.h>
#ifdef WIN
#include <winsock2.h>
#include <windows.h>
#else
#include <sys/select.h>
#include <sys/socket.h>
+5
View File
@@ -8,11 +8,16 @@
#include <unistd.h>
#include <ctype.h>
#ifdef WIN
#include <winsock2.h>
#include <windows.h>
#else
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/ioctl.h>
#include <signal.h>
#endif
#include <pthread.h>
#include <errno.h>
#include <inttypes.h>
+7 -2
View File
@@ -9,17 +9,22 @@
#include <ctype.h>
#include <assert.h>
#ifdef WIN
#include <winsock2.h>
#include <windows.h>
#else
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/ioctl.h>
#include <spawn.h>
#include <sys/mman.h>
#include <signal.h>
#endif
#include <pthread.h>
#include <inttypes.h>
#include <getopt.h>
#include <errno.h>
#include <spawn.h>
#include <sys/mman.h>
#include <time.h>
#include <libimobiledevice/libimobiledevice.h>
+5
View File
@@ -1,7 +1,12 @@
#ifndef HAVE_LIBIMOBILEDEVICE
#include "lockdown_helper.h"
#include <usbmuxd.h>
#ifdef WIN
#include <winsock2.h>
#include <windows.h>
#else
#include <arpa/inet.h>
#endif
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
+13 -2
View File
@@ -10,16 +10,21 @@
#include <limits.h>
#include <assert.h>
#ifdef WIN
#include <winsock2.h>
#include <windows.h>
#else
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/ioctl.h>
#include <spawn.h>
#include <sys/mman.h>
#include <signal.h>
#endif
#include <pthread.h>
#include <inttypes.h>
#include <errno.h>
#include <spawn.h>
#include <sys/mman.h>
#include <time.h>
#include <libimobiledevice/libimobiledevice.h>
@@ -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);
+10
View File
@@ -12,7 +12,9 @@
#include <limits.h>
#include <errno.h>
#include <palerain.h>
#ifndef WIN
#include <sys/mman.h>
#endif
#include <inttypes.h>
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;
}
+13
View File
@@ -11,7 +11,12 @@
#include <ctype.h>
#include <assert.h>
#include <getopt.h>
#ifndef WIN
#include <sys/mman.h>
#else
#include <winsock2.h>
#include <windows.h>
#endif
#include <errno.h>
@@ -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;
+2
View File
@@ -7,8 +7,10 @@
#include <stdlib.h> // exit, strtoull
#include <string.h> // strlen, strerror, memcpy, memmove
#include <unistd.h> // close
#ifndef WIN
#include <sys/mman.h> // mmap, munmap
#include <sys/stat.h> // fstst
#endif
#include <palerain.h>
#include <ANSI-color-codes.h>
+2
View File
@@ -34,8 +34,10 @@
#include <stdlib.h> // exit, strtoull
#include <string.h> // strlen, strerror, memcpy, memmove
#include <unistd.h> // close
#ifndef WIN
#include <sys/mman.h> // mmap, munmap
#include <sys/stat.h> // fstst
#endif
#include <palerain.h>
#define ERR(...) LOG(LOG_ERROR, __VA_ARGS__)