diff -Nurd -x'*~' posixninja-xpwn-7609d82.orig/dfu-util/CMakeLists.txt posixninja-xpwn-7609d82/dfu-util/CMakeLists.txt
--- posixninja-xpwn-7609d82.orig/dfu-util/CMakeLists.txt	2010-05-07 12:09:49.000000000 -0400
+++ posixninja-xpwn-7609d82/dfu-util/CMakeLists.txt	2018-02-04 11:46:28.000000000 -0500
@@ -5,7 +5,6 @@
 		message(STATUS "libusb is required for dfu-util!")
 		ELSE(NOT USB_FOUND)
 		include_directories(${USB_INCLUDE_DIR})
-		link_directories(${USB_LIBRARIES})
 
 		add_executable(dfu-util dfu.c sam7dfu.c main.c)
 
diff -Nurd -x'*~' posixninja-xpwn-7609d82.orig/dmg/CMakeLists.txt posixninja-xpwn-7609d82/dmg/CMakeLists.txt
--- posixninja-xpwn-7609d82.orig/dmg/CMakeLists.txt	2010-05-07 12:09:49.000000000 -0400
+++ posixninja-xpwn-7609d82/dmg/CMakeLists.txt	2018-02-04 11:47:22.000000000 -0500
@@ -12,7 +12,6 @@
 ENDIF(NOT ZLIB_FOUND)
 
 include_directories(${ZLIB_INCLUDE_DIR})
-link_directories(${ZLIB_LIBRARIES})
 
 link_directories(${PROJECT_BINARY_DIR}/common ${PROJECT_BINARY_DIR}/hfs)
 
diff -Nurd -x'*~' posixninja-xpwn-7609d82.orig/dmg/filevault.c posixninja-xpwn-7609d82/dmg/filevault.c
--- posixninja-xpwn-7609d82.orig/dmg/filevault.c	2010-05-07 12:09:49.000000000 -0400
+++ posixninja-xpwn-7609d82/dmg/filevault.c	2018-02-03 17:22:29.000000000 -0500
@@ -51,9 +51,9 @@
 	myChunk = info->curChunk;
 
 	FLIPENDIAN(myChunk);
-	HMAC_Init_ex(&(info->hmacCTX), NULL, 0, NULL, NULL);
-	HMAC_Update(&(info->hmacCTX), (unsigned char *) &myChunk, sizeof(uint32_t));
-	HMAC_Final(&(info->hmacCTX), msgDigest, &msgDigestLen);
+	HMAC_Init_ex(info->hmacCTX, NULL, 0, NULL, NULL);
+	HMAC_Update(info->hmacCTX, (unsigned char *) &myChunk, sizeof(uint32_t));
+	HMAC_Final(info->hmacCTX, msgDigest, &msgDigestLen);
 
 	AES_cbc_encrypt(info->chunk, buffer, info->blockSize, &(info->aesEncKey), msgDigest, AES_ENCRYPT);
 
@@ -85,9 +85,9 @@
 	info->curChunk = chunk;
 
 	FLIPENDIAN(chunk);
-	HMAC_Init_ex(&(info->hmacCTX), NULL, 0, NULL, NULL);
-	HMAC_Update(&(info->hmacCTX), (unsigned char *) &chunk, sizeof(uint32_t));
-	HMAC_Final(&(info->hmacCTX), msgDigest, &msgDigestLen);
+	HMAC_Init_ex(info->hmacCTX, NULL, 0, NULL, NULL);
+	HMAC_Update(info->hmacCTX, (unsigned char *) &chunk, sizeof(uint32_t));
+	HMAC_Final(info->hmacCTX, msgDigest, &msgDigestLen);
 
 	AES_cbc_encrypt(buffer, info->chunk, info->blockSize, &(info->aesKey), msgDigest, AES_DECRYPT);
 }
@@ -177,7 +177,12 @@
 		cacheChunk(info, 0);
 	}
 
-	HMAC_CTX_cleanup(&(info->hmacCTX));
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
+	HMAC_CTX_free(info->hmacCTX);
+#else
+	HMAC_CTX_cleanup(info->hmacCTX);
+	free(info->hmacCTX);
+#endif
 
 	if(info->headerDirty) {
 		if(info->version == 2) {
@@ -234,8 +239,19 @@
 		hmacKey[i] = curByte;
 	}
 
-	HMAC_CTX_init(&(info->hmacCTX));
-	HMAC_Init_ex(&(info->hmacCTX), hmacKey, sizeof(hmacKey), EVP_sha1(), NULL);
+
+#if OPENSSL_VERSION_NUMBER >= 0x10100000L
+	info->hmacCTX = HMAC_CTX_new();
+	HMAC_CTX_reset(info->hmacCTX);
+#else
+	info->hmacCTX = malloc(sizeof(*info->hmacCTX));
+	if (!info->hmacCTX) {
+		fprintf(stderr, "Out of memory: HMAC CTX!\n");
+		exit(1);
+	}
+	HMAC_CTX_init(info->hmacCTX);
+#endif
+	HMAC_Init_ex(info->hmacCTX, hmacKey, sizeof(hmacKey), EVP_sha1(), NULL);
 	AES_set_decrypt_key(aesKey, FILEVAULT_CIPHER_KEY_LENGTH * 8, &(info->aesKey));
 	AES_set_encrypt_key(aesKey, FILEVAULT_CIPHER_KEY_LENGTH * 8, &(info->aesEncKey));
 
diff -Nurd -x'*~' posixninja-xpwn-7609d82.orig/fwstitcher/CMakeLists.txt posixninja-xpwn-7609d82/fwstitcher/CMakeLists.txt
--- posixninja-xpwn-7609d82.orig/fwstitcher/CMakeLists.txt	2010-05-07 12:09:49.000000000 -0400
+++ posixninja-xpwn-7609d82/fwstitcher/CMakeLists.txt	2018-02-03 17:12:44.000000000 -0500
@@ -1,6 +1,6 @@
 link_directories(${PROJECT_BINARY_DIR}/common ${PROJECT_BINARY_DIR}/xpwn)
 
-include_directories(.)
+include_directories(. ${OPENSSL_INCLUDE_DIR})
 
 add_executable(fwstitcher fwstitcher.c base64.c)
 
diff -Nurd -x'*~' posixninja-xpwn-7609d82.orig/hfs/CMakeLists.txt posixninja-xpwn-7609d82/hfs/CMakeLists.txt
--- posixninja-xpwn-7609d82.orig/hfs/CMakeLists.txt	2010-05-07 12:09:49.000000000 -0400
+++ posixninja-xpwn-7609d82/hfs/CMakeLists.txt	2018-02-04 11:46:08.000000000 -0500
@@ -5,7 +5,6 @@
 ENDIF(NOT ZLIB_FOUND)
 
 include_directories(${ZLIB_INCLUDE_DIR})
-link_directories(${ZLIB_LIBRARIES})
 
 link_directories (${PROJECT_BINARY_DIR}/common)
 add_library(hfs btree.c catalog.c extents.c xattr.c fastunicodecompare.c flatfile.c hfslib.c rawfile.c utility.c volume.c hfscompress.c)
diff -Nurd -x'*~' posixninja-xpwn-7609d82.orig/includes/dmg/filevault.h posixninja-xpwn-7609d82/includes/dmg/filevault.h
--- posixninja-xpwn-7609d82.orig/includes/dmg/filevault.h	2010-05-07 12:09:49.000000000 -0400
+++ posixninja-xpwn-7609d82/includes/dmg/filevault.h	2018-02-03 17:22:29.000000000 -0500
@@ -79,7 +79,7 @@
 
 	AbstractFile*	file;
 
-	HMAC_CTX	hmacCTX;
+	HMAC_CTX	*hmacCTX;
 	AES_KEY		aesKey;
 	AES_KEY		aesEncKey;
 
diff -Nurd -x'*~' posixninja-xpwn-7609d82.orig/includes/xpwn/img3.h posixninja-xpwn-7609d82/includes/xpwn/img3.h
--- posixninja-xpwn-7609d82.orig/includes/xpwn/img3.h	2010-05-07 12:09:49.000000000 -0400
+++ posixninja-xpwn-7609d82/includes/xpwn/img3.h	2018-02-04 12:32:39.000000000 -0500
@@ -88,6 +88,7 @@
 	void replaceSignatureImg3(AbstractFile* file, AbstractFile* signature);
 	void exploit24kpwn(AbstractFile* file);
 	void exploitN8824kpwn(AbstractFile* file);
+	Img3Element* readImg3Element(AbstractFile* file);
 #ifdef __cplusplus
 }
 #endif
diff -Nurd -x'*~' posixninja-xpwn-7609d82.orig/ipsw-patch/CMakeLists.txt posixninja-xpwn-7609d82/ipsw-patch/CMakeLists.txt
--- posixninja-xpwn-7609d82.orig/ipsw-patch/CMakeLists.txt	2010-05-07 12:09:49.000000000 -0400
+++ posixninja-xpwn-7609d82/ipsw-patch/CMakeLists.txt	2018-02-04 11:47:57.000000000 -0500
@@ -1,3 +1,9 @@
+include_directories(${PROJECT_SOURCE_DIR}/minizip)
+link_directories(${PROJECT_BINARY_DIR}/minizip)
+
+link_directories(${PROJECT_BINARY_DIR}/common ${PROJECT_BINARY_DIR}/hfs ${PROJECT_BINARY_DIR}/dmg)
+
+INCLUDE(FindOpenSSL)
 INCLUDE(FindZLIB)
 INCLUDE(FindBZip2)
 INCLUDE(FindPNG)
@@ -28,19 +34,8 @@
 
 include_directories(${ZLIB_INCLUDE_DIR})
 
-IF(NOT APPLE)
-link_directories(${ZLIB_LIBRARIES})
-ENDIF(NOT APPLE)
-
 include_directories(${BZIP2_INCLUDE_DIR})
-link_directories(${BZIP2_LIBRARIES})
 include_directories(${PNG_INCLUDE_DIR})
-link_directories(${PNG_LIBRARIES})
-
-include_directories(${PROJECT_SOURCE_DIR}/minizip)
-link_directories(${PROJECT_BINARY_DIR}/minizip)
-
-link_directories(${PROJECT_BINARY_DIR}/common ${PROJECT_BINARY_DIR}/hfs ${PROJECT_BINARY_DIR}/dmg)
 
 IF(HAVE_HW_CRYPTO)
 	add_definitions(-DHAVE_HW_CRYPTO)
@@ -48,6 +43,15 @@
 
 add_library(xpwn 8900.c bspatch.c ibootim.c img2.c img3.c libxpwn.c lzss.c lzssfile.c nor_files.c outputstate.c plist.c pwnutil.c)
 
+IF(OPENSSL_FOUND)
+	add_definitions(-DHAVE_CRYPT)
+	include_directories(${OPENSSL_INCLUDE_DIR})
+	target_link_libraries(xpwn ${CRYPTO_LIBRARIES})
+	IF(WIN32)
+		TARGET_LINK_LIBRARIES(xpwn gdi32)
+	ENDIF(WIN32)
+ENDIF(OPENSSL_FOUND)
+
 IF(HAVE_HW_CRYPTO)
 	target_link_libraries(xpwn IOKit)
 ENDIF(HAVE_HW_CRYPTO)
diff -Nurd -x'*~' posixninja-xpwn-7609d82.orig/ipsw-patch/ibootim.c posixninja-xpwn-7609d82/ipsw-patch/ibootim.c
--- posixninja-xpwn-7609d82.orig/ipsw-patch/ibootim.c	2010-05-07 12:09:49.000000000 -0400
+++ posixninja-xpwn-7609d82/ipsw-patch/ibootim.c	2018-02-03 17:12:44.000000000 -0500
@@ -255,9 +255,11 @@
 	uint8_t *imageBuffer = malloc(imageFile->getLength(imageFile));
 	imageFile->read(imageFile, imageBuffer, imageFile->getLength(imageFile));
 
+	png_uint_32 height = png_get_image_height(png_ptr, info_ptr);
+
 	png_bytepp row_pointers = (png_bytepp) malloc(sizeof(png_bytep) * info->header.height);
 	int i;
-	for(i = 0; i < info_ptr->height; i++) {
+	for(i = 0; i < height; i++) {
 		row_pointers[i] = imageBuffer + (info->header.width * bytes_per_pixel * i);
 	}
 
@@ -274,7 +276,24 @@
 	AbstractFile* imageFile;
 	unsigned char header[8];
 	InfoIBootIM* info;
+	png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, pngError, pngWarn);
+	if (!png_ptr) {
+		return NULL;
+	}
+
+	png_infop info_ptr = png_create_info_struct(png_ptr);
+	if (!info_ptr)
+	{
+		png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
+		return NULL;
+	}
 	png_uint_32 i;
+	png_byte bit_depth = png_get_bit_depth(png_ptr, info_ptr);
+	png_byte color_type = png_get_color_type(png_ptr, info_ptr);
+	png_uint_32 height = png_get_image_height(png_ptr, info_ptr);
+	png_uint_32 width = png_get_image_width(png_ptr, info_ptr);
+	png_uint_32 rowbytes = png_get_rowbytes(png_ptr, info_ptr);
+
 	png_bytepp row_pointers;
 	
 	uint8_t* imageBuffer;
@@ -287,18 +306,6 @@
 	}
 	png->seek(png, 0);
 
-	png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, pngError, pngWarn);
-	if (!png_ptr) {
-		return NULL;
-	}
-
-	png_infop info_ptr = png_create_info_struct(png_ptr);
-	if (!info_ptr)
-	{
-		png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
-		return NULL;
-	}
-
 	png_infop end_info = png_create_info_struct(png_ptr);
 	if (!end_info)
 	{
@@ -318,15 +325,15 @@
 
 	png_read_info(png_ptr, info_ptr);
 	
-	if(info_ptr->bit_depth > 8) {
-		XLOG(0, "warning: bit depth per channel is greater than 8 (%d). Attempting to strip, but image quality will be degraded.\n", info_ptr->bit_depth);
+	if(bit_depth > 8) {
+		XLOG(0, "warning: bit depth per channel is greater than 8 (%d). Attempting to strip, but image quality will be degraded.\n", bit_depth);
 	}
 	
-	if(info_ptr->color_type == PNG_COLOR_TYPE_GRAY || info_ptr->color_type == PNG_COLOR_TYPE_RGB) {
+	if(color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_RGB) {
 		XLOG(0, "notice: attempting to add dummy transparency channel\n");
 	}
 	
-	if(info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
+	if(color_type == PNG_COLOR_TYPE_PALETTE) {
 		XLOG(0, "notice: attempting to expand palette into full rgb\n");
 	}
 	
@@ -339,24 +346,24 @@
 	png_read_update_info(png_ptr, info_ptr);
 	
 
-	if(info_ptr->width > 320 || info_ptr->height > 480) {
-		XLOG(0, "error: dimensions out of range, must be within 320x480, not %lux%lu\n", info_ptr->width, info_ptr->height);
+	if(width > 320 || height > 480) {
+		XLOG(0, "error: dimensions out of range, must be within 320x480, not %lux%lu\n", width, height);
 		png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
 		return NULL;
 	}
 
-	if(info_ptr->bit_depth != 8) {
-		XLOG(0, "error: bit depth per channel must be 8 not %d!\n", info_ptr->bit_depth);
+	if(bit_depth != 8) {
+		XLOG(0, "error: bit depth per channel must be 8 not %d!\n", bit_depth);
 		png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
 		return NULL;
 	}
 
-	if(info_ptr->color_type != PNG_COLOR_TYPE_GRAY_ALPHA && info_ptr->color_type != PNG_COLOR_TYPE_RGB_ALPHA) {
+	if(color_type != PNG_COLOR_TYPE_GRAY_ALPHA && color_type != PNG_COLOR_TYPE_RGB_ALPHA) {
 		XLOG(0, "error: incorrect color type, must be greyscale with alpha, or rgb with alpha\n");
-		if(info_ptr->color_type == PNG_COLOR_TYPE_GRAY || info_ptr->color_type == PNG_COLOR_TYPE_RGB) {
+		if(color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_RGB) {
 			XLOG(0, "It appears you're missing an alpha channel. Add transparency to your image\n");
 		}
-		if(info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
+		if(color_type == PNG_COLOR_TYPE_PALETTE) {
 			XLOG(0, "This PNG is saved with the palette color type rather than ARGB.\n");
 		}
 		png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
@@ -364,10 +371,10 @@
 		return NULL;
 	}
 
-	row_pointers = (png_bytepp) malloc(sizeof(png_bytep) * info_ptr->height);
-	imageBuffer = malloc(info_ptr->height * info_ptr->rowbytes);
-	for(i = 0; i < info_ptr->height; i++) {
-		row_pointers[i] = imageBuffer + (info_ptr->rowbytes * i);
+	row_pointers = (png_bytepp) malloc(sizeof(png_bytep) * height);
+	imageBuffer = malloc(height * rowbytes);
+	for(i = 0; i < height; i++) {
+		row_pointers[i] = imageBuffer + (rowbytes * i);
 	}
 
 	png_read_image(png_ptr, row_pointers);
@@ -383,15 +390,15 @@
 	}
 	info = (InfoIBootIM*) (imageFile->data);
 	
-	info->header.width = (uint16_t) info_ptr->width;
-	info->header.height = (uint16_t) info_ptr->height;
-	if(info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
+	info->header.width = (uint16_t) width;
+	info->header.height = (uint16_t) height;
+	if(color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
 		info->header.format = IBOOTIM_GREY;
 	} else {
 		info->header.format = IBOOTIM_ARGB;
 	}
 	
-	imageFile->write(imageFile, imageBuffer, info_ptr->height * info_ptr->rowbytes);
+	imageFile->write(imageFile, imageBuffer, height * rowbytes);
 	
 	imageFile->close(imageFile);
 
diff -Nurd -x'*~' posixninja-xpwn-7609d82.orig/ipsw-patch/main.c posixninja-xpwn-7609d82/ipsw-patch/main.c
--- posixninja-xpwn-7609d82.orig/ipsw-patch/main.c	2010-05-07 12:09:49.000000000 -0400
+++ posixninja-xpwn-7609d82/ipsw-patch/main.c	2018-02-04 12:19:11.000000000 -0500
@@ -13,6 +13,7 @@
 #include <dmg/dmglib.h>
 #include <xpwn/pwnutil.h>
 #include <stdio.h>
+#include <unistd.h>
 
 #ifdef WIN32
 #include <windows.h>
diff -Nurd -x'*~' posixninja-xpwn-7609d82.orig/ipsw-patch/xpwntool.c posixninja-xpwn-7609d82/ipsw-patch/xpwntool.c
--- posixninja-xpwn-7609d82.orig/ipsw-patch/xpwntool.c	2010-05-07 12:09:49.000000000 -0400
+++ posixninja-xpwn-7609d82/ipsw-patch/xpwntool.c	2018-02-04 12:22:35.000000000 -0500
@@ -2,6 +2,7 @@
 #include <string.h>
 #include "xpwn/libxpwn.h"
 #include "xpwn/nor_files.h"
+#include "xpwn/img3.h"
 
 #define BUFFERSIZE (1024*1024)
 
diff -Nurd -x'*~' posixninja-xpwn-7609d82.orig/minizip/CMakeLists.txt posixninja-xpwn-7609d82/minizip/CMakeLists.txt
--- posixninja-xpwn-7609d82.orig/minizip/CMakeLists.txt	2010-05-07 12:09:49.000000000 -0400
+++ posixninja-xpwn-7609d82/minizip/CMakeLists.txt	2018-02-04 11:47:04.000000000 -0500
@@ -5,7 +5,6 @@
 ENDIF(NOT ZLIB_FOUND)
 
 include_directories(${ZLIB_INCLUDE_DIR})
-link_directories(${ZLIB_LIBRARIES})
 
 add_library(minizip ioapi.c unzip.c zip.c)
 
diff -Nurd -x'*~' posixninja-xpwn-7609d82.orig/xpwn/CMakeLists.txt posixninja-xpwn-7609d82/xpwn/CMakeLists.txt
--- posixninja-xpwn-7609d82.orig/xpwn/CMakeLists.txt	2010-05-07 12:09:49.000000000 -0400
+++ posixninja-xpwn-7609d82/xpwn/CMakeLists.txt	2018-02-04 11:46:57.000000000 -0500
@@ -7,7 +7,6 @@
 		include_directories(include)
 
 		include_directories(${USB_INCLUDE_DIR})
-		link_directories(${USB_LIBRARIES})
 
 		add_executable(xpwn-bin src/xpwn.cpp src/libibooter.cpp)
 
