<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPhone1,1_2.1_5F136.bundle/018-4108-7-nowipe.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPhone1,1_2.1_5F136.bundle/018-4108-7.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPhone1,1_2.1_5F136.bundle/018-4118-1.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPhone1,1_2.1_5F136.bundle/DeviceTree.m68ap.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPhone1,1_2.1_5F136.bundle/Info.plist</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPhone1,1_2.1_5F136.bundle/LLB.m68ap.RELEASE.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPhone1,1_2.1_5F136.bundle/Services.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPhone1,1_2.1_5F136.bundle/WTF.m68ap.RELEASE.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPhone1,1_2.1_5F136.bundle/WTF.s5l8900xall.RELEASE.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPhone1,1_2.1_5F136.bundle/bbupdater.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPhone1,1_2.1_5F136.bundle/fstab.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPhone1,1_2.1_5F136.bundle/iBEC.m68ap.RELEASE.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPhone1,1_2.1_5F136.bundle/iBSS.m68ap.RELEASE.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPhone1,1_2.1_5F136.bundle/iBoot.m68ap.RELEASE.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPhone1,1_2.1_5F136.bundle/kernelcache.release.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPhone1,1_2.1_5F136.bundle/lockdownd.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPhone1,2_2.1_5F136.bundle/018-4118-1.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPhone1,2_2.1_5F136.bundle/018-4122-1-nowipe.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPhone1,2_2.1_5F136.bundle/018-4122-1.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPhone1,2_2.1_5F136.bundle/DeviceTree.n82ap.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPhone1,2_2.1_5F136.bundle/Info.plist</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPhone1,2_2.1_5F136.bundle/LLB.n82ap.RELEASE.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPhone1,2_2.1_5F136.bundle/Services.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPhone1,2_2.1_5F136.bundle/WTF.n82ap.RELEASE.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPhone1,2_2.1_5F136.bundle/WTF.s5l8900xall.RELEASE.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPhone1,2_2.1_5F136.bundle/fstab.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPhone1,2_2.1_5F136.bundle/iBEC.n82ap.RELEASE.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPhone1,2_2.1_5F136.bundle/iBSS.n82ap.RELEASE.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPhone1,2_2.1_5F136.bundle/iBoot.n82ap.RELEASE.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPhone1,2_2.1_5F136.bundle/kernelcache.release.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPhone1,2_2.1_5F136.bundle/lockdownd.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPod1,1_2.1_5F137.bundle/018-4146-1.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPod1,1_2.1_5F137.bundle/018-4149-1-nowipe.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPod1,1_2.1_5F137.bundle/018-4149-1.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPod1,1_2.1_5F137.bundle/DeviceTree.n45ap.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPod1,1_2.1_5F137.bundle/Info.plist</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPod1,1_2.1_5F137.bundle/LLB.n45ap.RELEASE.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPod1,1_2.1_5F137.bundle/Services.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPod1,1_2.1_5F137.bundle/WTF.n45ap.RELEASE.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPod1,1_2.1_5F137.bundle/WTF.s5l8900xall.RELEASE.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPod1,1_2.1_5F137.bundle/fstab.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPod1,1_2.1_5F137.bundle/iBEC.n45ap.RELEASE.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPod1,1_2.1_5F137.bundle/iBSS.n45ap.RELEASE.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPod1,1_2.1_5F137.bundle/iBoot.n45ap.RELEASE.patch</filename>
    </added>
    <added>
      <filename>ipsw-patch/FirmwareBundles/iPod1,1_2.1_5F137.bundle/kernelcache.release.patch</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -41,7 +41,7 @@ SET(CPACK_RESOURCE_FILE_README &quot;${PROJECT_SOURCE_DIR}/README.markdown&quot;)
 SET(CPACK_RESOURCE_FILE_LICENSE &quot;${PROJECT_SOURCE_DIR}/LICENSE&quot;)
 SET(CPACK_PACKAGE_VERSION_MAJOR &quot;0&quot;)
 SET(CPACK_PACKAGE_VERSION_MINOR &quot;5&quot;)
-SET(CPACK_PACKAGE_VERSION_PATCH &quot;2&quot;)
+SET(CPACK_PACKAGE_VERSION_PATCH &quot;3&quot;)
 SET(CPACK_PACKAGE_EXECUTABLES &quot;xpwn&quot; &quot;XPwn Pwner&quot;)
 SET(CPACK_PACKAGE_EXECUTABLES &quot;ipsw&quot; &quot;IPSW Tool&quot;)
 SET(CPACK_PACKAGE_EXECUTABLES &quot;hdutil&quot; &quot;Apple disk image utility&quot;)</diff>
      <filename>CMakeLists.txt</filename>
    </modified>
    <modified>
      <diff>@@ -1,21 +1,23 @@
 INCLUDE(${PROJECT_SOURCE_DIR}/FindUSB.cmake)
 
-IF(NOT USB_FOUND)
-	message(STATUS &quot;libusb is required for dfu-util!&quot;)
-ELSE(NOT USB_FOUND)
-	include_directories(${USB_INCLUDE_DIR})
-	link_directories(${USB_LIBRARIES})
+IF(NOT APPLE OR NOT BUILD_STATIC)
+	IF(NOT USB_FOUND)
+		message(STATUS &quot;libusb is required for dfu-util!&quot;)
+		ELSE(NOT USB_FOUND)
+		include_directories(${USB_INCLUDE_DIR})
+		link_directories(${USB_LIBRARIES})
 
-	add_executable(dfu-util dfu.c sam7dfu.c main.c)
+		add_executable(dfu-util dfu.c sam7dfu.c main.c)
 
-	link_directories(${PROJECT_BINARY_DIR}/common ${PROJECT_BINARY_DIR}/hfs ${PROJECT_BINARY_DIR}/ipsw-patch)
+		link_directories(${PROJECT_BINARY_DIR}/common ${PROJECT_BINARY_DIR}/hfs ${PROJECT_BINARY_DIR}/ipsw-patch)
 
-	IF(APPLE)
-		SET_TARGET_PROPERTIES(dfu-util PROPERTIES LINK_FLAGS &quot;-framework CoreFoundation -framework IOKit&quot;)
-	ENDIF(APPLE)
+		IF(APPLE)
+			SET_TARGET_PROPERTIES(dfu-util PROPERTIES LINK_FLAGS &quot;-framework CoreFoundation -framework IOKit&quot;)
+		ENDIF(APPLE)
 
-	target_link_libraries(dfu-util xpwn)
-	target_link_libraries(dfu-util ${USB_LIBRARIES})
+		target_link_libraries(dfu-util xpwn)
+		target_link_libraries(dfu-util ${USB_LIBRARIES})
 
-	install(TARGETS dfu-util DESTINATION .)
-ENDIF(NOT USB_FOUND)
+		install(TARGETS dfu-util DESTINATION .)
+	ENDIF(NOT USB_FOUND)
+ENDIF(NOT APPLE OR NOT BUILD_STATIC)</diff>
      <filename>dfu-util/CMakeLists.txt</filename>
    </modified>
    <modified>
      <diff>@@ -6,486 +6,494 @@ int writeExtents(RawFile* rawFile);
 
 int isBlockUsed(Volume* volume, uint32_t block)
 {
-  unsigned char byte;
-  
-  READ(volume-&gt;allocationFile, block / 8, 1, &amp;byte);
-  return (byte &amp; (1 &lt;&lt; (7 - (block % 8)))) != 0;
+	unsigned char byte;
+
+	READ(volume-&gt;allocationFile, block / 8, 1, &amp;byte);
+	return (byte &amp; (1 &lt;&lt; (7 - (block % 8)))) != 0;
 }
 
 int setBlockUsed(Volume* volume, uint32_t block, int used) {
-  unsigned char byte;
-  
-  READ(volume-&gt;allocationFile, block / 8, 1, &amp;byte);
-  if(used) {
-    byte |= (1 &lt;&lt; (7 - (block % 8)));
-  } else {
-    byte &amp;= ~(1 &lt;&lt; (7 - (block % 8)));
-  }
-  ASSERT(WRITE(volume-&gt;allocationFile, block / 8, 1, &amp;byte), &quot;WRITE&quot;);
-  
-  return TRUE;
+	unsigned char byte;
+
+	READ(volume-&gt;allocationFile, block / 8, 1, &amp;byte);
+	if(used) {
+		byte |= (1 &lt;&lt; (7 - (block % 8)));
+	} else {
+		byte &amp;= ~(1 &lt;&lt; (7 - (block % 8)));
+	}
+	ASSERT(WRITE(volume-&gt;allocationFile, block / 8, 1, &amp;byte), &quot;WRITE&quot;);
+
+	return TRUE;
 }
 
 int allocate(RawFile* rawFile, off_t size) {
-  unsigned char* zeros;
-  Volume* volume;
-  HFSPlusForkData* forkData;
-  uint32_t blocksNeeded;
-  uint32_t blocksToAllocate;
-  Extent* extent;
-  Extent* lastExtent;
-  
-  uint32_t curBlock;
-  
-  volume = rawFile-&gt;volume;
-  forkData = rawFile-&gt;forkData;
-  extent = rawFile-&gt;extents;
- 
-  blocksNeeded = ((uint64_t)size / (uint64_t)volume-&gt;volumeHeader-&gt;blockSize) + (((size % volume-&gt;volumeHeader-&gt;blockSize) == 0) ? 0 : 1);
-  
-  if(blocksNeeded &gt; forkData-&gt;totalBlocks) {
-    zeros = (unsigned char*) malloc(volume-&gt;volumeHeader-&gt;blockSize);
-    memset(zeros, 0, volume-&gt;volumeHeader-&gt;blockSize);
-  
-    blocksToAllocate = blocksNeeded - forkData-&gt;totalBlocks;
-    
-    if(blocksToAllocate &gt; volume-&gt;volumeHeader-&gt;freeBlocks) {
-      return FALSE;
-    }
-    
-    lastExtent = NULL;
-    while(extent != NULL) {
-      lastExtent = extent;
-      extent = extent-&gt;next;
-    }
-    
-    if(lastExtent == NULL) {
-      rawFile-&gt;extents = (Extent*) malloc(sizeof(Extent));
-      lastExtent = rawFile-&gt;extents;
-      lastExtent-&gt;blockCount = 0;
-      lastExtent-&gt;next = NULL;
-      curBlock = volume-&gt;volumeHeader-&gt;nextAllocation;
-    } else {
-      curBlock = lastExtent-&gt;startBlock + lastExtent-&gt;blockCount;
-    }
-    
-    while(blocksToAllocate &gt; 0) {
-      if(isBlockUsed(volume, curBlock)) {
-        if(lastExtent-&gt;blockCount &gt; 0) {
-          lastExtent-&gt;next = (Extent*) malloc(sizeof(Extent));
-          lastExtent = lastExtent-&gt;next;
-          lastExtent-&gt;blockCount = 0;
-          lastExtent-&gt;next = NULL;
-        }
-        curBlock = volume-&gt;volumeHeader-&gt;nextAllocation;
-        volume-&gt;volumeHeader-&gt;nextAllocation++;
-        if(volume-&gt;volumeHeader-&gt;nextAllocation &gt;= volume-&gt;volumeHeader-&gt;totalBlocks) {
-          volume-&gt;volumeHeader-&gt;nextAllocation = 0;
-        }
-      } else {
-        if(lastExtent-&gt;blockCount == 0) {
-          lastExtent-&gt;startBlock = curBlock;
-        }
-
-        /* zero out allocated block */
-        ASSERT(WRITE(volume-&gt;image, curBlock * volume-&gt;volumeHeader-&gt;blockSize, volume-&gt;volumeHeader-&gt;blockSize, zeros), &quot;WRITE&quot;);
-
-        setBlockUsed(volume, curBlock, TRUE);
-        volume-&gt;volumeHeader-&gt;freeBlocks--;
-        blocksToAllocate--;
-        curBlock++;
-        lastExtent-&gt;blockCount++;
-        
-        if(curBlock &gt;= volume-&gt;volumeHeader-&gt;totalBlocks) {
-          curBlock = volume-&gt;volumeHeader-&gt;nextAllocation;
-        }
-      }
-    }
-    
-    free(zeros);
-  } else if(blocksNeeded &lt; forkData-&gt;totalBlocks) {
-    blocksToAllocate = blocksNeeded;
-  
-    lastExtent = NULL;
-    
-    while(blocksToAllocate &gt; 0) {
-      if(blocksToAllocate &gt; extent-&gt;blockCount) {
-        blocksToAllocate -= extent-&gt;blockCount;
-        lastExtent = extent;
-        extent = extent-&gt;next;
-      } else {
-        break;
-      }
-    }
-    
-    
-    if(blocksToAllocate == 0 &amp;&amp; lastExtent != NULL) {
-      lastExtent-&gt;next = NULL;
-    } else {
-      rawFile-&gt;extents = NULL;
-    }
-    
-    do {
-      for(curBlock = (extent-&gt;startBlock + blocksToAllocate); curBlock &lt; (extent-&gt;startBlock + extent-&gt;blockCount); curBlock++) {
-        setBlockUsed(volume, curBlock, FALSE);
-        volume-&gt;volumeHeader-&gt;freeBlocks++;
-      }
-      blocksToAllocate = 0;
-      lastExtent = extent;
-      extent = extent-&gt;next;
-      free(lastExtent);
-      
-    } while(extent != NULL);
-  }
-
-  writeExtents(rawFile);
-  
-  forkData-&gt;logicalSize = size;
-  forkData-&gt;totalBlocks = blocksNeeded;
-
-  updateVolume(rawFile-&gt;volume);
-  
-  if(rawFile-&gt;catalogRecord != NULL) {
-    updateCatalog(rawFile-&gt;volume, rawFile-&gt;catalogRecord);
-  }
-  
-  return TRUE;
+	unsigned char* zeros;
+	Volume* volume;
+	HFSPlusForkData* forkData;
+	uint32_t blocksNeeded;
+	uint32_t blocksToAllocate;
+	Extent* extent;
+	Extent* lastExtent;
+
+	uint32_t curBlock;
+
+	volume = rawFile-&gt;volume;
+	forkData = rawFile-&gt;forkData;
+	extent = rawFile-&gt;extents;
+
+	blocksNeeded = ((uint64_t)size / (uint64_t)volume-&gt;volumeHeader-&gt;blockSize) + (((size % volume-&gt;volumeHeader-&gt;blockSize) == 0) ? 0 : 1);
+
+	if(blocksNeeded &gt; forkData-&gt;totalBlocks) {
+		zeros = (unsigned char*) malloc(volume-&gt;volumeHeader-&gt;blockSize);
+		memset(zeros, 0, volume-&gt;volumeHeader-&gt;blockSize);
+
+		blocksToAllocate = blocksNeeded - forkData-&gt;totalBlocks;
+
+		if(blocksToAllocate &gt; volume-&gt;volumeHeader-&gt;freeBlocks) {
+			return FALSE;
+		}
+
+		lastExtent = NULL;
+		while(extent != NULL) {
+			lastExtent = extent;
+			extent = extent-&gt;next;
+		}
+
+		if(lastExtent == NULL) {
+			rawFile-&gt;extents = (Extent*) malloc(sizeof(Extent));
+			lastExtent = rawFile-&gt;extents;
+			lastExtent-&gt;blockCount = 0;
+			lastExtent-&gt;next = NULL;
+			curBlock = volume-&gt;volumeHeader-&gt;nextAllocation;
+		} else {
+			curBlock = lastExtent-&gt;startBlock + lastExtent-&gt;blockCount;
+		}
+
+		while(blocksToAllocate &gt; 0) {
+			if(isBlockUsed(volume, curBlock)) {
+				if(lastExtent-&gt;blockCount &gt; 0) {
+					lastExtent-&gt;next = (Extent*) malloc(sizeof(Extent));
+					lastExtent = lastExtent-&gt;next;
+					lastExtent-&gt;blockCount = 0;
+					lastExtent-&gt;next = NULL;
+				}
+				curBlock = volume-&gt;volumeHeader-&gt;nextAllocation;
+				volume-&gt;volumeHeader-&gt;nextAllocation++;
+				if(volume-&gt;volumeHeader-&gt;nextAllocation &gt;= volume-&gt;volumeHeader-&gt;totalBlocks) {
+					volume-&gt;volumeHeader-&gt;nextAllocation = 0;
+				}
+			} else {
+				if(lastExtent-&gt;blockCount == 0) {
+					lastExtent-&gt;startBlock = curBlock;
+				}
+
+				/* zero out allocated block */
+				ASSERT(WRITE(volume-&gt;image, curBlock * volume-&gt;volumeHeader-&gt;blockSize, volume-&gt;volumeHeader-&gt;blockSize, zeros), &quot;WRITE&quot;);
+
+				setBlockUsed(volume, curBlock, TRUE);
+				volume-&gt;volumeHeader-&gt;freeBlocks--;
+				blocksToAllocate--;
+				curBlock++;
+				lastExtent-&gt;blockCount++;
+
+				if(curBlock &gt;= volume-&gt;volumeHeader-&gt;totalBlocks) {
+					curBlock = volume-&gt;volumeHeader-&gt;nextAllocation;
+				}
+			}
+		}
+
+		free(zeros);
+	} else if(blocksNeeded &lt; forkData-&gt;totalBlocks) {
+		blocksToAllocate = blocksNeeded;
+
+		lastExtent = NULL;
+
+		while(blocksToAllocate &gt; 0) {
+			if(blocksToAllocate &gt; extent-&gt;blockCount) {
+				blocksToAllocate -= extent-&gt;blockCount;
+				lastExtent = extent;
+				extent = extent-&gt;next;
+			} else {
+				break;
+			}
+		}
+
+
+		if(blocksToAllocate == 0 &amp;&amp; lastExtent != NULL) {
+			// snip the extent list here, since we don't need the rest
+			lastExtent-&gt;next = NULL;
+		} else if(blocksNeeded == 0) {
+			rawFile-&gt;extents = NULL;
+		}
+
+		do {
+			for(curBlock = (extent-&gt;startBlock + blocksToAllocate); curBlock &lt; (extent-&gt;startBlock + extent-&gt;blockCount); curBlock++) {
+				setBlockUsed(volume, curBlock, FALSE);
+				volume-&gt;volumeHeader-&gt;freeBlocks++;
+			}
+			lastExtent = extent;
+			extent = extent-&gt;next;
+
+			if(blocksToAllocate == 0)
+			{ 
+				free(lastExtent);
+			} else {
+				lastExtent-&gt;next = NULL;
+				lastExtent-&gt;blockCount = blocksToAllocate;
+			}
+
+			blocksToAllocate = 0;
+		} while(extent != NULL);
+	}
+
+	writeExtents(rawFile);
+
+	forkData-&gt;logicalSize = size;
+	forkData-&gt;totalBlocks = blocksNeeded;
+
+	updateVolume(rawFile-&gt;volume);
+
+	if(rawFile-&gt;catalogRecord != NULL) {
+		updateCatalog(rawFile-&gt;volume, rawFile-&gt;catalogRecord);
+	}
+
+	return TRUE;
 }
 
 static int rawFileRead(io_func* io,off_t location, size_t size, void *buffer) {
-  RawFile* rawFile;
-  Volume* volume;
-  Extent* extent;
-  
-  size_t blockSize;
-  off_t fileLoc;
-  off_t locationInBlock;
-  size_t possible;
-  
-  rawFile = (RawFile*) io-&gt;data;
-  volume = rawFile-&gt;volume;
-  blockSize = volume-&gt;volumeHeader-&gt;blockSize;
-  
-  extent = rawFile-&gt;extents;
-  fileLoc = 0;
-  
-  locationInBlock = location;
-  while(TRUE) {
-    fileLoc += extent-&gt;blockCount * blockSize;
-    if(fileLoc &lt;= location) {
-      locationInBlock -= extent-&gt;blockCount * blockSize;
-      extent = extent-&gt;next;
-      if(extent == NULL)
-        break;
-    } else {
-      break;
-    }
-  }
-  
-  while(size &gt; 0) {
-    if(extent == NULL)
-      return FALSE;
-      
-    possible = extent-&gt;blockCount * blockSize - locationInBlock;
-        
-    if(size &gt; possible) {
-      ASSERT(READ(volume-&gt;image, extent-&gt;startBlock * blockSize + locationInBlock, possible, buffer), &quot;READ&quot;);
-      size -= possible;
-      buffer = (void*)(((size_t)buffer) + possible);
-      extent = extent-&gt;next;
-    } else {
-      ASSERT(READ(volume-&gt;image, extent-&gt;startBlock * blockSize + locationInBlock, size, buffer), &quot;READ&quot;);
-      break;
-    }
-    
-    locationInBlock = 0;
-  }
-   
-  return TRUE;
+	RawFile* rawFile;
+	Volume* volume;
+	Extent* extent;
+
+	size_t blockSize;
+	off_t fileLoc;
+	off_t locationInBlock;
+	size_t possible;
+
+	rawFile = (RawFile*) io-&gt;data;
+	volume = rawFile-&gt;volume;
+	blockSize = volume-&gt;volumeHeader-&gt;blockSize;
+
+	extent = rawFile-&gt;extents;
+	fileLoc = 0;
+
+	locationInBlock = location;
+	while(TRUE) {
+		fileLoc += extent-&gt;blockCount * blockSize;
+		if(fileLoc &lt;= location) {
+			locationInBlock -= extent-&gt;blockCount * blockSize;
+			extent = extent-&gt;next;
+			if(extent == NULL)
+				break;
+		} else {
+			break;
+		}
+	}
+
+	while(size &gt; 0) {
+		if(extent == NULL)
+			return FALSE;
+
+		possible = extent-&gt;blockCount * blockSize - locationInBlock;
+
+		if(size &gt; possible) {
+			ASSERT(READ(volume-&gt;image, extent-&gt;startBlock * blockSize + locationInBlock, possible, buffer), &quot;READ&quot;);
+			size -= possible;
+			buffer = (void*)(((size_t)buffer) + possible);
+			extent = extent-&gt;next;
+		} else {
+			ASSERT(READ(volume-&gt;image, extent-&gt;startBlock * blockSize + locationInBlock, size, buffer), &quot;READ&quot;);
+			break;
+		}
+
+		locationInBlock = 0;
+	}
+
+	return TRUE;
 }
 
 static int rawFileWrite(io_func* io,off_t location, size_t size, void *buffer) {
-  RawFile* rawFile;
-  Volume* volume;
-  Extent* extent;
-  
-  size_t blockSize;
-  off_t fileLoc;
-  off_t locationInBlock;
-  size_t possible;
-  
-  rawFile = (RawFile*) io-&gt;data;
-  volume = rawFile-&gt;volume;
-  blockSize = volume-&gt;volumeHeader-&gt;blockSize;
-  
-  if(rawFile-&gt;forkData-&gt;logicalSize &lt; (location + size)) {
-    ASSERT(allocate(rawFile, location + size), &quot;allocate&quot;);
-  }
-  
-  extent = rawFile-&gt;extents;
-  fileLoc = 0;
-  
-  locationInBlock = location;
-  while(TRUE) {
-    fileLoc += extent-&gt;blockCount * blockSize;
-    if(fileLoc &lt;= location) {
-      locationInBlock -= extent-&gt;blockCount * blockSize;
-      extent = extent-&gt;next;
-      if(extent == NULL)
-        break;
-    } else {
-      break;
-    }
-  }
-  
-  while(size &gt; 0) {
-    if(extent == NULL)
-      return FALSE;
-      
-    possible = extent-&gt;blockCount * blockSize - locationInBlock;
-        
-    if(size &gt; possible) {
-      ASSERT(WRITE(volume-&gt;image, extent-&gt;startBlock * blockSize + locationInBlock, possible, buffer), &quot;WRITE&quot;);
-      size -= possible;
-      buffer = (void*)(((size_t)buffer) + possible);
-      extent = extent-&gt;next;
-    } else {
-      ASSERT(WRITE(volume-&gt;image, extent-&gt;startBlock * blockSize + locationInBlock, size, buffer), &quot;WRITE&quot;);
-      break;
-    }
-    
-    locationInBlock = 0;
-  }
-   
-  return TRUE;
+	RawFile* rawFile;
+	Volume* volume;
+	Extent* extent;
+
+	size_t blockSize;
+	off_t fileLoc;
+	off_t locationInBlock;
+	size_t possible;
+
+	rawFile = (RawFile*) io-&gt;data;
+	volume = rawFile-&gt;volume;
+	blockSize = volume-&gt;volumeHeader-&gt;blockSize;
+
+	if(rawFile-&gt;forkData-&gt;logicalSize &lt; (location + size)) {
+		ASSERT(allocate(rawFile, location + size), &quot;allocate&quot;);
+	}
+
+	extent = rawFile-&gt;extents;
+	fileLoc = 0;
+
+	locationInBlock = location;
+	while(TRUE) {
+		fileLoc += extent-&gt;blockCount * blockSize;
+		if(fileLoc &lt;= location) {
+			locationInBlock -= extent-&gt;blockCount * blockSize;
+			extent = extent-&gt;next;
+			if(extent == NULL)
+				break;
+		} else {
+			break;
+		}
+	}
+
+	while(size &gt; 0) {
+		if(extent == NULL)
+			return FALSE;
+
+		possible = extent-&gt;blockCount * blockSize - locationInBlock;
+
+		if(size &gt; possible) {
+			ASSERT(WRITE(volume-&gt;image, extent-&gt;startBlock * blockSize + locationInBlock, possible, buffer), &quot;WRITE&quot;);
+			size -= possible;
+			buffer = (void*)(((size_t)buffer) + possible);
+			extent = extent-&gt;next;
+		} else {
+			ASSERT(WRITE(volume-&gt;image, extent-&gt;startBlock * blockSize + locationInBlock, size, buffer), &quot;WRITE&quot;);
+			break;
+		}
+
+		locationInBlock = 0;
+	}
+
+	return TRUE;
 }
 
 static void closeRawFile(io_func* io) {
-  RawFile* rawFile;
-  Extent* extent;
-  Extent* toRemove;
-  
-  rawFile = (RawFile*) io-&gt;data;
-  extent = rawFile-&gt;extents;
-  
-  while(extent != NULL) {
-    toRemove = extent;
-    extent = extent-&gt;next;
-    free(toRemove);
-  }
-  
-  free(rawFile);
-  free(io);
+	RawFile* rawFile;
+	Extent* extent;
+	Extent* toRemove;
+
+	rawFile = (RawFile*) io-&gt;data;
+	extent = rawFile-&gt;extents;
+
+	while(extent != NULL) {
+		toRemove = extent;
+		extent = extent-&gt;next;
+		free(toRemove);
+	}
+
+	free(rawFile);
+	free(io);
 }
 
 int removeExtents(RawFile* rawFile) {
-  uint32_t blocksLeft;
-  HFSPlusForkData* forkData;
-  uint32_t currentBlock;
-  
-  uint32_t startBlock;
-  uint32_t blockCount;
-    
-  HFSPlusExtentDescriptor* descriptor;
-  int currentExtent;
-  HFSPlusExtentKey extentKey;
-  int exact;
-  
-  extentKey.keyLength = sizeof(HFSPlusExtentKey) - sizeof(extentKey.keyLength);
-  extentKey.forkType = 0;
-  extentKey.fileID = rawFile-&gt;id;
-  
-  forkData = rawFile-&gt;forkData;
-  blocksLeft = forkData-&gt;totalBlocks;
-  currentExtent = 0;
-  currentBlock = 0;
-  descriptor = (HFSPlusExtentDescriptor*) forkData-&gt;extents;
-  
-  while(blocksLeft &gt; 0) {       
-    if(currentExtent == 8) {
-      if(rawFile-&gt;volume-&gt;extentsTree == NULL) {
-        hfs_panic(&quot;no extents overflow file loaded yet!&quot;);
-        return FALSE;
-      }
-      
-      if(descriptor != ((HFSPlusExtentDescriptor*) forkData-&gt;extents)) {
-        free(descriptor);
-      }
-      
-      extentKey.startBlock = currentBlock;
-      descriptor = (HFSPlusExtentDescriptor*) search(rawFile-&gt;volume-&gt;extentsTree, (BTKey*)(&amp;extentKey), &amp;exact, NULL, NULL);
-      if(descriptor == NULL || exact == FALSE) {
-        hfs_panic(&quot;inconsistent extents information!&quot;);
-        return FALSE;
-      } else {
-        removeFromBTree(rawFile-&gt;volume-&gt;extentsTree, (BTKey*)(&amp;extentKey));
-        currentExtent = 0;
-        continue;
-      }
-    }
-
-    startBlock = descriptor[currentExtent].startBlock;
-    blockCount = descriptor[currentExtent].blockCount;
-    
-    currentBlock += blockCount;
-    blocksLeft -= blockCount;
-    currentExtent++;
-  }
-  
-  if(descriptor != ((HFSPlusExtentDescriptor*) forkData-&gt;extents)) {
-    free(descriptor);
-  }
-  
-  return TRUE;
+	uint32_t blocksLeft;
+	HFSPlusForkData* forkData;
+	uint32_t currentBlock;
+
+	uint32_t startBlock;
+	uint32_t blockCount;
+
+	HFSPlusExtentDescriptor* descriptor;
+	int currentExtent;
+	HFSPlusExtentKey extentKey;
+	int exact;
+
+	extentKey.keyLength = sizeof(HFSPlusExtentKey) - sizeof(extentKey.keyLength);
+	extentKey.forkType = 0;
+	extentKey.fileID = rawFile-&gt;id;
+
+	forkData = rawFile-&gt;forkData;
+	blocksLeft = forkData-&gt;totalBlocks;
+	currentExtent = 0;
+	currentBlock = 0;
+	descriptor = (HFSPlusExtentDescriptor*) forkData-&gt;extents;
+
+	while(blocksLeft &gt; 0) {       
+		if(currentExtent == 8) {
+			if(rawFile-&gt;volume-&gt;extentsTree == NULL) {
+				hfs_panic(&quot;no extents overflow file loaded yet!&quot;);
+				return FALSE;
+			}
+
+			if(descriptor != ((HFSPlusExtentDescriptor*) forkData-&gt;extents)) {
+				free(descriptor);
+			}
+
+			extentKey.startBlock = currentBlock;
+			descriptor = (HFSPlusExtentDescriptor*) search(rawFile-&gt;volume-&gt;extentsTree, (BTKey*)(&amp;extentKey), &amp;exact, NULL, NULL);
+			if(descriptor == NULL || exact == FALSE) {
+				hfs_panic(&quot;inconsistent extents information!&quot;);
+				return FALSE;
+			} else {
+				removeFromBTree(rawFile-&gt;volume-&gt;extentsTree, (BTKey*)(&amp;extentKey));
+				currentExtent = 0;
+				continue;
+			}
+		}
+
+		startBlock = descriptor[currentExtent].startBlock;
+		blockCount = descriptor[currentExtent].blockCount;
+
+		currentBlock += blockCount;
+		blocksLeft -= blockCount;
+		currentExtent++;
+	}
+
+	if(descriptor != ((HFSPlusExtentDescriptor*) forkData-&gt;extents)) {
+		free(descriptor);
+	}
+
+	return TRUE;
 }
 
 int writeExtents(RawFile* rawFile) {
-  Extent* extent;
-  int currentExtent;
-  HFSPlusExtentKey extentKey;
-  HFSPlusExtentDescriptor descriptor[8];
-  HFSPlusForkData* forkData;
-  
-  removeExtents(rawFile);
-  
-  forkData = rawFile-&gt;forkData;
-  currentExtent = 0;
-  extent = rawFile-&gt;extents;
-  
-  memset(forkData-&gt;extents, 0, sizeof(HFSPlusExtentRecord));
-  while(extent != NULL &amp;&amp; currentExtent &lt; 8) {
-    ((HFSPlusExtentDescriptor*)forkData-&gt;extents)[currentExtent].startBlock = extent-&gt;startBlock;
-    ((HFSPlusExtentDescriptor*)forkData-&gt;extents)[currentExtent].blockCount = extent-&gt;blockCount;
-    extent = extent-&gt;next;
-    currentExtent++;
-  }
-  
-  if(extent != NULL) {
-    extentKey.keyLength = sizeof(HFSPlusExtentKey) - sizeof(extentKey.keyLength);
-    extentKey.forkType = 0;
-    extentKey.fileID = rawFile-&gt;id;
-    
-    currentExtent = 0;
-    
-    while(extent != NULL) {
-      if(currentExtent == 0) {
-        memset(descriptor, 0, sizeof(HFSPlusExtentRecord));
-      }
-      
-      if(currentExtent == 8) {
-        extentKey.startBlock = descriptor[0].startBlock;
-        addToBTree(rawFile-&gt;volume-&gt;extentsTree, (BTKey*)(&amp;extentKey), sizeof(HFSPlusExtentRecord), (unsigned char *)(&amp;(descriptor[0])));
-        currentExtent = 0;
-      }
-      
-      descriptor[currentExtent].startBlock = extent-&gt;startBlock;
-      descriptor[currentExtent].blockCount = extent-&gt;blockCount;
-      
-      currentExtent++;
-      extent = extent-&gt;next;
-    }
-       
-    extentKey.startBlock = descriptor[0].startBlock;
-    addToBTree(rawFile-&gt;volume-&gt;extentsTree, (BTKey*)(&amp;extentKey), sizeof(HFSPlusExtentRecord), (unsigned char *)(&amp;(descriptor[0])));
-  }
-  
-  return TRUE;
+	Extent* extent;
+	int currentExtent;
+	HFSPlusExtentKey extentKey;
+	HFSPlusExtentDescriptor descriptor[8];
+	HFSPlusForkData* forkData;
+
+	removeExtents(rawFile);
+
+	forkData = rawFile-&gt;forkData;
+	currentExtent = 0;
+	extent = rawFile-&gt;extents;
+
+	memset(forkData-&gt;extents, 0, sizeof(HFSPlusExtentRecord));
+	while(extent != NULL &amp;&amp; currentExtent &lt; 8) {
+		((HFSPlusExtentDescriptor*)forkData-&gt;extents)[currentExtent].startBlock = extent-&gt;startBlock;
+		((HFSPlusExtentDescriptor*)forkData-&gt;extents)[currentExtent].blockCount = extent-&gt;blockCount;
+		extent = extent-&gt;next;
+		currentExtent++;
+	}
+
+	if(extent != NULL) {
+		extentKey.keyLength = sizeof(HFSPlusExtentKey) - sizeof(extentKey.keyLength);
+		extentKey.forkType = 0;
+		extentKey.fileID = rawFile-&gt;id;
+
+		currentExtent = 0;
+
+		while(extent != NULL) {
+			if(currentExtent == 0) {
+				memset(descriptor, 0, sizeof(HFSPlusExtentRecord));
+			}
+
+			if(currentExtent == 8) {
+				extentKey.startBlock = descriptor[0].startBlock;
+				addToBTree(rawFile-&gt;volume-&gt;extentsTree, (BTKey*)(&amp;extentKey), sizeof(HFSPlusExtentRecord), (unsigned char *)(&amp;(descriptor[0])));
+				currentExtent = 0;
+			}
+
+			descriptor[currentExtent].startBlock = extent-&gt;startBlock;
+			descriptor[currentExtent].blockCount = extent-&gt;blockCount;
+
+			currentExtent++;
+			extent = extent-&gt;next;
+		}
+
+		extentKey.startBlock = descriptor[0].startBlock;
+		addToBTree(rawFile-&gt;volume-&gt;extentsTree, (BTKey*)(&amp;extentKey), sizeof(HFSPlusExtentRecord), (unsigned char *)(&amp;(descriptor[0])));
+	}
+
+	return TRUE;
 }
 
 int readExtents(RawFile* rawFile) {
-  uint32_t blocksLeft;
-  HFSPlusForkData* forkData;
-  uint32_t currentBlock;
-  
-  Extent* extent;
-  Extent* lastExtent;
-  
-  HFSPlusExtentDescriptor* descriptor;
-  int currentExtent;
-  HFSPlusExtentKey extentKey;
-  int exact;
-  
-  extentKey.keyLength = sizeof(HFSPlusExtentKey) - sizeof(extentKey.keyLength);
-  extentKey.forkType = 0;
-  extentKey.fileID = rawFile-&gt;id;
-  
-  forkData = rawFile-&gt;forkData;
-  blocksLeft = forkData-&gt;totalBlocks;
-  currentExtent = 0;
-  currentBlock = 0;
-  descriptor = (HFSPlusExtentDescriptor*) forkData-&gt;extents;
-  
-  lastExtent = NULL;
-  
-  while(blocksLeft &gt; 0) {
-    extent = (Extent*) malloc(sizeof(Extent));
-       
-    if(currentExtent == 8) {
-      if(rawFile-&gt;volume-&gt;extentsTree == NULL) {
-        hfs_panic(&quot;no extents overflow file loaded yet!&quot;);
-        return FALSE;
-      }
-      
-      if(descriptor != ((HFSPlusExtentDescriptor*) forkData-&gt;extents)) {
-        free(descriptor);
-      }
-      
-      extentKey.startBlock = currentBlock;
-      descriptor = (HFSPlusExtentDescriptor*) search(rawFile-&gt;volume-&gt;extentsTree, (BTKey*)(&amp;extentKey), &amp;exact, NULL, NULL);
-      if(descriptor == NULL || exact == FALSE) {
-        hfs_panic(&quot;inconsistent extents information!&quot;);
-        return FALSE;
-      } else {
-        currentExtent = 0;
-        continue;
-      }
-    }
-    
-    extent-&gt;startBlock = descriptor[currentExtent].startBlock;
-    extent-&gt;blockCount = descriptor[currentExtent].blockCount;
-    extent-&gt;next = NULL;
-    
-    currentBlock += extent-&gt;blockCount;
-    blocksLeft -= extent-&gt;blockCount;
-    currentExtent++;
-    
-    if(lastExtent == NULL) {
-      rawFile-&gt;extents = extent;
-    } else {
-      lastExtent-&gt;next = extent;
-    }
-    
-    lastExtent = extent;
-  }
-  
-  if(descriptor != ((HFSPlusExtentDescriptor*) forkData-&gt;extents)) {
-    free(descriptor);
-  }
-  
-  return TRUE;
+	uint32_t blocksLeft;
+	HFSPlusForkData* forkData;
+	uint32_t currentBlock;
+
+	Extent* extent;
+	Extent* lastExtent;
+
+	HFSPlusExtentDescriptor* descriptor;
+	int currentExtent;
+	HFSPlusExtentKey extentKey;
+	int exact;
+
+	extentKey.keyLength = sizeof(HFSPlusExtentKey) - sizeof(extentKey.keyLength);
+	extentKey.forkType = 0;
+	extentKey.fileID = rawFile-&gt;id;
+
+	forkData = rawFile-&gt;forkData;
+	blocksLeft = forkData-&gt;totalBlocks;
+	currentExtent = 0;
+	currentBlock = 0;
+	descriptor = (HFSPlusExtentDescriptor*) forkData-&gt;extents;
+
+	lastExtent = NULL;
+
+	while(blocksLeft &gt; 0) {
+		extent = (Extent*) malloc(sizeof(Extent));
+
+		if(currentExtent == 8) {
+			if(rawFile-&gt;volume-&gt;extentsTree == NULL) {
+				hfs_panic(&quot;no extents overflow file loaded yet!&quot;);
+				return FALSE;
+			}
+
+			if(descriptor != ((HFSPlusExtentDescriptor*) forkData-&gt;extents)) {
+				free(descriptor);
+			}
+
+			extentKey.startBlock = currentBlock;
+			descriptor = (HFSPlusExtentDescriptor*) search(rawFile-&gt;volume-&gt;extentsTree, (BTKey*)(&amp;extentKey), &amp;exact, NULL, NULL);
+			if(descriptor == NULL || exact == FALSE) {
+				hfs_panic(&quot;inconsistent extents information!&quot;);
+				return FALSE;
+			} else {
+				currentExtent = 0;
+				continue;
+			}
+		}
+
+		extent-&gt;startBlock = descriptor[currentExtent].startBlock;
+		extent-&gt;blockCount = descriptor[currentExtent].blockCount;
+		extent-&gt;next = NULL;
+
+		currentBlock += extent-&gt;blockCount;
+		blocksLeft -= extent-&gt;blockCount;
+		currentExtent++;
+
+		if(lastExtent == NULL) {
+			rawFile-&gt;extents = extent;
+		} else {
+			lastExtent-&gt;next = extent;
+		}
+
+		lastExtent = extent;
+	}
+
+	if(descriptor != ((HFSPlusExtentDescriptor*) forkData-&gt;extents)) {
+		free(descriptor);
+	}
+
+	return TRUE;
 }
 
 io_func* openRawFile(HFSCatalogNodeID id, HFSPlusForkData* forkData, HFSPlusCatalogRecord* catalogRecord, Volume* volume) {
-  io_func* io;
-  RawFile* rawFile;
-  
-  io = (io_func*) malloc(sizeof(io_func));
-  rawFile = (RawFile*) malloc(sizeof(RawFile));
-  
-  rawFile-&gt;id = id;
-  rawFile-&gt;volume = volume;
-  rawFile-&gt;forkData = forkData;
-  rawFile-&gt;catalogRecord = catalogRecord;
-  rawFile-&gt;extents = NULL;
-  
-  io-&gt;data = rawFile;
-  io-&gt;read = &amp;rawFileRead;
-  io-&gt;write = &amp;rawFileWrite;
-  io-&gt;close = &amp;closeRawFile;
-  
-  if(!readExtents(rawFile)) {
-    return NULL;
-  }
-
-  return io;
+	io_func* io;
+	RawFile* rawFile;
+
+	io = (io_func*) malloc(sizeof(io_func));
+	rawFile = (RawFile*) malloc(sizeof(RawFile));
+
+	rawFile-&gt;id = id;
+	rawFile-&gt;volume = volume;
+	rawFile-&gt;forkData = forkData;
+	rawFile-&gt;catalogRecord = catalogRecord;
+	rawFile-&gt;extents = NULL;
+
+	io-&gt;data = rawFile;
+	io-&gt;read = &amp;rawFileRead;
+	io-&gt;write = &amp;rawFileWrite;
+	io-&gt;close = &amp;closeRawFile;
+
+	if(!readExtents(rawFile)) {
+		return NULL;
+	}
+
+	return io;
 }</diff>
      <filename>hfs/rawfile.c</filename>
    </modified>
    <modified>
      <diff>@@ -12,6 +12,9 @@
 #define ftello ftello64
 #define off_t off64_t
 #define mkdir(x, y) mkdir(x)
+#define PATH_SEPARATOR &quot;\\&quot;
+#else
+#define PATH_SEPARATOR &quot;/&quot;
 #endif
 
 #define TRUE 1</diff>
      <filename>includes/common.h</filename>
    </modified>
    <modified>
      <diff>@@ -161,6 +161,7 @@ struct HFSPlusCatalogKey {
 } __attribute__((__packed__));
 typedef struct HFSPlusCatalogKey HFSPlusCatalogKey;
 
+#ifndef __MACTYPES__
 struct Point {
   int16_t              v;
   int16_t              h;
@@ -180,6 +181,8 @@ typedef struct Rect   Rect;
 typedef uint32_t        FourCharCode;
 typedef FourCharCode  OSType;
 
+#endif
+
 /* Finder flags (finderFlags, fdFlags and frFlags) */
 enum {
   kIsOnDesk       = 0x0001,     /* Files and folders (System 6) */</diff>
      <filename>includes/hfs/hfsplus.h</filename>
    </modified>
    <modified>
      <diff>@@ -5,6 +5,8 @@
 #include &lt;xpwn/outputstate.h&gt;
 #include &lt;hfs/hfsplus.h&gt;
 
+typedef int (*PatchFunction)(AbstractFile* file);
+
 #ifdef __cplusplus
 extern &quot;C&quot; {
 #endif
@@ -15,6 +17,10 @@ extern &quot;C&quot; {
 	void doPatchInPlace(Volume* volume, const char* filePath, const char* patchPath);
 	void fixupBootNeuterArgs(Volume* volume, char unlockBaseband, char selfDestruct, char use39, char use46);
 	void createRestoreOptions(Volume* volume, int SystemPartitionSize, int UpdateBaseband);
+
+	int patchSigCheck(AbstractFile* file);
+	int patchKernel(AbstractFile* file);
+	int patchDeviceTree(AbstractFile* file);
 #ifdef __cplusplus
 }
 #endif</diff>
      <filename>includes/xpwn/pwnutil.h</filename>
    </modified>
    <modified>
      <diff>@@ -27,7 +27,11 @@ IF(NOT PNG_FOUND)
 ENDIF(NOT PNG_FOUND)
 
 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})
@@ -38,20 +42,42 @@ 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)
+ENDIF(HAVE_HW_CRYPTO)
+
 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)
 
-target_link_libraries(xpwn dmg hfs common minizip ${CRYPTO_LIBRARIES} ${BZIP2_LIBRARIES} ${PNG_LIBRARIES} ${ZLIB_LIBRARIES} m)
-
-ADD_CUSTOM_TARGET(libXPwn.a
-	COMMAND ${CMAKE_C_COMPILER}
-		-L${PROJECT_BINARY_DIR}/ipsw-patch -L${PROJECT_BINARY_DIR}/dmg -L${PROJECT_BINARY_DIR}/hfs
-		-L${PROJECT_BINARY_DIR}/hfs -L${PROJECT_BINARY_DIR}/minizip -L${PROJECT_BINARY_DIR}/common
-		-Xlinker --whole-archive -lxpwn -ldmg -lhfs -lcommon -lminizip
-		${CRYPTO_LIBRARIES} ${BZIP2_LIBRARIES} ${PNG_LIBRARIES}
-		-Xlinker --unresolved-symbols=ignore-all -Xlinker -r -nostdlib -o libXPwn.o
-	COMMAND ${CMAKE_AR} cr libXPwn.a libXPwn.o
-	COMMAND ${CMAKE_RANLIB} libXPwn.a
-	DEPENDS xpwn dmg hfs common minizip)
+IF(HAVE_HW_CRYPTO)
+	target_link_libraries(xpwn IOKit)
+ENDIF(HAVE_HW_CRYPTO)
+
+target_link_libraries(xpwn dmg hfs common minizip ${CRYPTO_LIBRARIES} ${BZIP2_LIBRARIES} ${PNG_LIBRARIES} m)
+
+IF(NOT APPLE)
+	target_link_libraries(xpwn ${ZLIB_LIBRARIES})
+ENDIF(NOT APPLE)
+
+IF(APPLE)
+	ADD_CUSTOM_TARGET(libXPwn.a
+		COMMAND powerpc-apple-darwin8-libtool -static -o libXPwn.a
+			${PROJECT_BINARY_DIR}/ipsw-patch/libxpwn.a ${PROJECT_BINARY_DIR}/minizip/libminizip.a
+			${PROJECT_BINARY_DIR}/common/libcommon.a ${PROJECT_BINARY_DIR}/hfs/libhfs.a 
+			${PROJECT_BINARY_DIR}/dmg/libdmg.a ${PNG_LIBRARIES} ${BZIP2_LIBRARIES}
+			${CRYPTO_LIBRARIES}
+		DEPENDS xpwn dmg hfs common minizip)
+ELSE(APPLE)
+	ADD_CUSTOM_TARGET(libXPwn.a
+		COMMAND ${CMAKE_C_COMPILER}
+			-L${PROJECT_BINARY_DIR}/ipsw-patch -L${PROJECT_BINARY_DIR}/dmg -L${PROJECT_BINARY_DIR}/hfs
+			-L${PROJECT_BINARY_DIR}/hfs -L${PROJECT_BINARY_DIR}/minizip -L${PROJECT_BINARY_DIR}/common
+			-Xlinker --whole-archive -lxpwn -ldmg -lhfs -lcommon -lminizip
+			${CRYPTO_LIBRARIES} ${BZIP2_LIBRARIES} ${PNG_LIBRARIES}
+			-Xlinker --unresolved-symbols=ignore-all -Xlinker -r -nostdlib -o libXPwn.o
+		COMMAND ${CMAKE_AR} cr libXPwn.a libXPwn.o
+		COMMAND ${CMAKE_RANLIB} libXPwn.a
+		DEPENDS xpwn dmg hfs common minizip)
+ENDIF(APPLE)
 
 IF(WIN32)
 	TARGET_LINK_LIBRARIES(xpwn gdi32)</diff>
      <filename>ipsw-patch/CMakeLists.txt</filename>
    </modified>
    <modified>
      <diff>@@ -3,6 +3,76 @@
 #include &quot;common.h&quot;
 #include &lt;xpwn/img3.h&gt;
 
+#ifdef HAVE_HW_CRYPTO
+#include &lt;stdint.h&gt;
+#include &lt;IOKit/IOKitLib.h&gt;
+
+typedef struct 
+{
+	void*		inbuf;
+	void*		outbuf;
+	uint32_t	size;
+	uint8_t		iv[16];
+	uint32_t	mode;
+	uint32_t	bits;
+	uint8_t		keybuf[32];
+	uint32_t	mask;
+} IOAESStruct;
+
+#define kIOAESAcceleratorInfo 0
+#define kIOAESAcceleratorTask 1
+#define kIOAESAcceleratorTest 2
+
+#define kIOAESAcceleratorEncrypt 0
+#define kIOAESAcceleratorDecrypt 1
+
+#define kIOAESAcceleratorGIDMask 0x3E8
+#define kIOAESAcceleratorUIDMask 0x7D0
+#define kIOAESAcceleratorCustomMask 0
+
+typedef enum {
+	UID,
+	GID,
+	Custom
+} IOAESKeyType;
+
+IOReturn doAES(io_connect_t conn, void* inbuf, void *outbuf, uint32_t size, IOAESKeyType keyType, void* key, void* iv, int mode) {
+	IOAESStruct in;
+
+	in.mode = mode;
+	in.bits = 128;
+	in.inbuf = inbuf;
+	in.outbuf = outbuf;
+	in.size = size;
+
+	switch(keyType) {
+		case UID:
+			in.mask = kIOAESAcceleratorUIDMask;
+			break;
+		case GID:
+			in.mask = kIOAESAcceleratorGIDMask;
+			break;
+		case Custom:
+			in.mask = kIOAESAcceleratorCustomMask;
+			break;
+	}
+	memset(in.keybuf, 0, sizeof(in.keybuf));
+
+	if(key)
+		memcpy(in.keybuf, key, in.bits / 8);
+
+	if(iv)
+		memcpy(in.iv, iv, 16);
+	else
+		memset(in.iv, 0, 16);
+
+	IOByteCount inSize = sizeof(in);
+
+	return IOConnectCallStructMethod(conn, kIOAESAcceleratorTask, &amp;in, inSize, &amp;in, &amp;inSize);
+}
+
+#endif
+
 void writeImg3Element(AbstractFile* file, Img3Element* element);
 
 void writeImg3Root(AbstractFile* file, Img3Element* element);
@@ -314,11 +384,33 @@ AbstractFile* createAbstractFileFromImg3(AbstractFile* file) {
 		keySeedLen = 16 + (((AppleImg3KBAGHeader*)info-&gt;kbag-&gt;data)-&gt;key_bits)/8;
 		keySeed = (uint8_t*) malloc(keySeedLen);
 		memcpy(keySeed, (uint8_t*)((AppleImg3KBAGHeader*)info-&gt;kbag-&gt;data) + sizeof(AppleImg3KBAGHeader), keySeedLen);
+#ifdef HAVE_HW_CRYPTO
+		CFMutableDictionaryRef dict = IOServiceMatching(&quot;IOAESAccelerator&quot;);
+		io_service_t dev = IOServiceGetMatchingService(kIOMasterPortDefault, dict);
+		io_connect_t conn = 0;
+		IOServiceOpen(dev, mach_task_self(), 0, &amp;conn);
+		doAES(conn, keySeed, keySeed, keySeedLen, GID, NULL, NULL, kIOAESAcceleratorDecrypt);
+		IOServiceClose(conn);
+		IOObjectRelease(dev);
+
+		unsigned int key[keySeedLen - 16];
+		unsigned int iv[16];
+
+		int i;
+		for(i = 0; i &lt; 16; i++)
+			iv[i] = keySeed[i];
+
+		for(i = 0; i &lt; (keySeedLen - 16); i++)
+			key[i] = keySeed[i + 16];
+
+		setKeyImg3(abstractFile2, key, iv);
+#else
 		int i = 0;
 		for(i = 0; i &lt; keySeedLen; i++) {
 			printf(&quot;%02x&quot;, keySeed[i]);
 		}
 		printf(&quot;\n&quot;);
+#endif
 		free(keySeed);
 	}
 </diff>
      <filename>ipsw-patch/img3.c</filename>
    </modified>
    <modified>
      <diff>@@ -33,6 +33,10 @@ void libxpwn_loglevel(int logLevel) {
 }
 
 void Log(int level, const char* file, unsigned int line, const char* function, const char* format, ...) {
+	static FILE* logFile = NULL;
+	if(logFile == NULL)
+		logFile = fopen(&quot;log.txt&quot;, &quot;w&quot;);
+
 	char mainBuffer[1024];
 	char buffer[1024];
 
@@ -54,5 +58,8 @@ void Log(int level, const char* file, unsigned int line, const char* function, c
 			snprintf(mainBuffer, sizeof(mainBuffer), &quot;%s:%s:%d: %s&quot;, file, function, line, buffer);
 	}
 	logCallback(mainBuffer);
+	strcat(mainBuffer, &quot;\n&quot;);
+	fwrite(mainBuffer, 1, strlen(mainBuffer), logFile);
+	fflush(logFile);
 }
 </diff>
      <filename>ipsw-patch/libxpwn.c</filename>
    </modified>
    <modified>
      <diff>@@ -14,6 +14,8 @@
 
 #define DEFAULT_BUFFER_SIZE (1 * 1024 * 1024)
 
+uint64_t MaxLoadZipSize = UINT64_MAX;
+
 void addToOutputQueue(OutputState** state, const char* fileName, void* buffer, const size_t bufferSize, char* tmpFileName) {
 	OutputState* leftNeighbor;
 	OutputState* rightNeighbor;
@@ -282,10 +284,10 @@ char* createTempFile() {
 #ifdef WIN32
 	char tmpFilePath[512];
 	GetTempPath(512, tmpFilePath);
-	GetTempFileName(tmpFilePath, &quot;zip&quot;, 0, tmpFileBuffer);
+	GetTempFileName(tmpFilePath, &quot;pwn&quot;, 0, tmpFileBuffer);
 	CloseHandle(CreateFile(tmpFilePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_DELETE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY, NULL));
 #else
-	strcpy(tmpFileBuffer, &quot;/tmp/zipXXXXXX&quot;);
+	strcpy(tmpFileBuffer, &quot;/tmp/pwnXXXXXX&quot;);
 	close(mkstemp(tmpFileBuffer));
 	FILE* tFile = fopen(tmpFileBuffer, &quot;wb&quot;);
 	fclose(tFile);
@@ -323,7 +325,7 @@ void loadZipFile2(const char* ipsw, OutputState** output, const char* file, int
 		ASSERT(unzGetCurrentFileInfo(zip, &amp;pfile_info, NULL, 0, NULL, 0, NULL, 0) == UNZ_OK, &quot;cannot get current file info from ipsw&quot;);
 		fileName = (char*) malloc(pfile_info.size_filename + 1);
 		ASSERT(unzGetCurrentFileInfo(zip, NULL, fileName, pfile_info.size_filename + 1, NULL, 0, NULL, 0) == UNZ_OK, &quot;cannot get current file name from ipsw&quot;);
-		if((file == NULL &amp;&amp; fileName[strlen(fileName) - 1] != '/') || (file != NULL &amp;&amp; strcmp(fileName, file)) == 0) {
+		if(((file == NULL &amp;&amp; fileName[strlen(fileName) - 1] != '/') || (file != NULL &amp;&amp; strcmp(fileName, file)) == 0) &amp;&amp; pfile_info.uncompressed_size &lt;= MaxLoadZipSize) {
 			printf(&quot;loading: %s (%ld)\n&quot;, fileName, pfile_info.uncompressed_size); fflush(stdout);
 			ASSERT(unzOpenCurrentFile(zip) == UNZ_OK, &quot;cannot open compressed file in IPSW&quot;);
 			if(useMemory) {</diff>
      <filename>ipsw-patch/outputstate.c</filename>
    </modified>
    <modified>
      <diff>@@ -55,7 +55,7 @@ Dictionary* parseIPSW2(const char* inputIPSW, const char* bundleRoot, char** bun
 
 	fclose(inputIPSWFile);
 
-	XLOG(0, &quot;Matching IPSW... (%02x%02x%02x%02x...)\n&quot;, (int) hash[0], (int) hash[1], (int) hash[2], (int) hash[3]);
+	XLOG(0, &quot;Matching IPSW in %s... (%02x%02x%02x%02x...)\n&quot;, bundleRoot, (int) hash[0], (int) hash[1], (int) hash[2], (int) hash[3]);
 
 	dir = opendir(bundleRoot);
 	if(dir == NULL) {
@@ -67,10 +67,8 @@ Dictionary* parseIPSW2(const char* inputIPSW, const char* bundleRoot, char** bun
 			continue;
 		}
 
-		infoPath = (char*) malloc(sizeof(char) * (strlen(bundleRoot) + strlen(ent-&gt;d_name) + sizeof(&quot;/Info.plist&quot;)));
-		strcpy(infoPath, bundleRoot);
-		strcat(infoPath, ent-&gt;d_name);
-		strcat(infoPath, &quot;/Info.plist&quot;);
+		infoPath = (char*) malloc(sizeof(char) * (strlen(bundleRoot) + sizeof(PATH_SEPARATOR) + strlen(ent-&gt;d_name) + sizeof(PATH_SEPARATOR &quot;Info.plist&quot;)));
+		sprintf(infoPath, &quot;%s&quot; PATH_SEPARATOR &quot;%s&quot; PATH_SEPARATOR &quot;Info.plist&quot;, bundleRoot, ent-&gt;d_name);
 		XLOG(0, &quot;checking: %s\n&quot;, infoPath);
 
 		if((plistFile = createAbstractFileFromFile(fopen(infoPath, &quot;rb&quot;))) != NULL) {
@@ -95,9 +93,8 @@ Dictionary* parseIPSW2(const char* inputIPSW, const char* bundleRoot, char** bun
 				}
 
 				if(i == 20) {
-					*bundlePath = (char*) malloc(sizeof(char) * (strlen(bundleRoot) + strlen(ent-&gt;d_name) + 1));
-					strcpy(*bundlePath, bundleRoot);
-					strcat(*bundlePath, ent-&gt;d_name);
+					*bundlePath = (char*) malloc(sizeof(char) * (strlen(bundleRoot) + sizeof(PATH_SEPARATOR) + strlen(ent-&gt;d_name)));
+					sprintf(*bundlePath, &quot;%s&quot; PATH_SEPARATOR &quot;%s&quot;, bundleRoot, ent-&gt;d_name);
 
 					free(infoPath);
 					break;
@@ -325,3 +322,124 @@ void fixupBootNeuterArgs(Volume* volume, char unlockBaseband, char selfDestruct,
 	add_hfs(volume, plistFile, bootNeuterPlist);
 	free(plist);
 }
+
+int patchSigCheck(AbstractFile* file) {
+	const uint8_t patch[] = {0x01, 0xE0, 0x01, 0x20, 0x40, 0x42, 0x88, 0x23};
+	
+	size_t length = file-&gt;getLength(file);
+	uint8_t* buffer = (uint8_t*)malloc(length);
+	file-&gt;seek(file, 0);
+	file-&gt;read(file, buffer, length);
+	
+	int retval = FALSE;
+	int i;
+	for(i = 0; i &lt; length; i++) {
+		uint8_t* candidate = &amp;buffer[i];
+		if(memcmp(candidate, patch, sizeof(patch)) == 0) {
+			candidate[4] = 0;
+			candidate[5] = 0x20;
+			file-&gt;seek(file, i);
+			file-&gt;write(file, candidate, sizeof(patch));
+			retval = TRUE;
+			continue;
+		}
+	}
+	
+	free(buffer);
+	return retval;
+}
+
+int patchKernel(AbstractFile* file) {
+	const char patch[] = {0x00, 0x00, 0x00, 0x0A, 0x00, 0x40, 0xA0, 0xE3, 0x04, 0x00, 0xA0, 0xE1, 0x90, 0x80, 0xBD, 0xE8};
+
+	const char patch2[] = {0xFF, 0x50, 0xA0, 0xE3, 0x04, 0x00, 0xA0, 0xE1, 0x0A, 0x10, 0xA0, 0xE1};
+
+	const char patch3[] = {0x99, 0x91, 0x43, 0x2B, 0x91, 0xCD, 0xE7, 0x04, 0x24, 0x1D, 0xB0};
+	
+	size_t length = file-&gt;getLength(file);
+	uint8_t* buffer = (uint8_t*)malloc(length);
+	file-&gt;seek(file, 0);
+	file-&gt;read(file, buffer, length);
+	
+	int retval = 0;
+	int i;
+	for(i = 0; i &lt; length; i++) {
+		uint8_t* candidate = &amp;buffer[i];
+		if(memcmp(candidate, patch, sizeof(patch)) == 0) {
+			candidate[4] = 0x01;
+			file-&gt;seek(file, i);
+			file-&gt;write(file, candidate, sizeof(patch));
+			retval = TRUE;
+			continue;
+		}
+		if(memcmp(candidate, patch2, sizeof(patch2)) == 0) {
+			candidate[0] = 0x00;
+			file-&gt;seek(file, i);
+			file-&gt;write(file, candidate, sizeof(patch2));
+			retval = TRUE;
+			continue;
+		}
+		if(memcmp(candidate, patch3, sizeof(patch3)) == 0) {
+			candidate[0] = 0x2B;
+			candidate[1] = 0x99;
+			candidate[2] = 0x00;
+			candidate[3] = 0x00;
+			file-&gt;seek(file, i);
+			file-&gt;write(file, candidate, sizeof(patch3));
+			retval = TRUE;
+			continue;
+		}
+	}
+	
+	free(buffer);
+	return retval;
+}
+
+int patchDeviceTree(AbstractFile* file) {
+	const char patch[] = &quot;secure-root-prefix&quot;;
+	const char patch2[] = &quot;function-disable_keys&quot;;
+	
+	size_t length = file-&gt;getLength(file);
+	uint8_t* buffer = (uint8_t*)malloc(length);
+	file-&gt;seek(file, 0);
+	file-&gt;read(file, buffer, length);
+	
+	int retval = 0;
+	int i;
+	for(i = 0; i &lt; length; i++) {
+		uint8_t* candidate = &amp;buffer[i];
+		if(memcmp(candidate, patch, sizeof(patch) - 1) == 0) {
+			candidate[0] = 'x';
+			candidate[1] = 'x';
+			candidate[2] = 'x';
+			candidate[3] = 'x';
+			candidate[4] = 'x';
+			candidate[5] = 'x';
+			file-&gt;seek(file, i);
+			file-&gt;write(file, candidate, sizeof(patch) - 1);
+			retval++;
+			continue;
+		}
+		if(memcmp(candidate, patch2, sizeof(patch2) - 1) == 0) {
+			candidate[0] = 'x';
+			candidate[1] = 'x';
+			candidate[2] = 'x';
+			candidate[3] = 'x';
+			candidate[4] = 'x';
+			candidate[5] = 'x';
+			candidate[6] = 'x';
+			candidate[7] = 'x';
+			file-&gt;seek(file, i);
+			file-&gt;write(file, candidate, sizeof(patch) - 1);
+			retval++;
+			continue;
+		}
+	}
+	
+	free(buffer);
+	if(retval == 2)
+		return TRUE;
+	else
+		return FALSE;
+}
+</diff>
      <filename>ipsw-patch/pwnutil.c</filename>
    </modified>
    <modified>
      <diff>@@ -1,29 +1,31 @@
 INCLUDE(${PROJECT_SOURCE_DIR}/FindUSB.cmake)
 
-IF(NOT USB_FOUND)
-	message(STATUS &quot;libusb is required for xpwn!&quot;)
-ELSE(NOT USB_FOUND)
-	include_directories(include)
+IF(NOT APPLE OR NOT BUILD_STATIC)
+	IF(NOT USB_FOUND)
+		message(STATUS &quot;libusb is required for xpwn!&quot;)
+	ELSE(NOT USB_FOUND)
+		include_directories(include)
 
-	include_directories(${USB_INCLUDE_DIR})
-	link_directories(${USB_LIBRARIES})
+		include_directories(${USB_INCLUDE_DIR})
+		link_directories(${USB_LIBRARIES})
 
-	add_executable(xpwn-bin src/xpwn.cpp src/libibooter.cpp)
+		add_executable(xpwn-bin src/xpwn.cpp src/libibooter.cpp)
 
-	target_link_libraries(xpwn-bin ${USB_LIBRARIES})
+		target_link_libraries(xpwn-bin ${USB_LIBRARIES})
 
-	link_directories(${PROJECT_BINARY_DIR}/common ${PROJECT_BINARY_DIR}/hfs ${PROJECT_BINARY_DIR}/ipsw-patch)
+		link_directories(${PROJECT_BINARY_DIR}/common ${PROJECT_BINARY_DIR}/hfs ${PROJECT_BINARY_DIR}/ipsw-patch)
 
-	target_link_libraries(xpwn-bin xpwn)
+		target_link_libraries(xpwn-bin xpwn)
 
-	set_target_properties(xpwn-bin PROPERTIES OUTPUT_NAME &quot;xpwn&quot;)
+		set_target_properties(xpwn-bin PROPERTIES OUTPUT_NAME &quot;xpwn&quot;)
 
-	IF(APPLE)
-		SET_TARGET_PROPERTIES(xpwn-bin PROPERTIES LINK_FLAGS &quot;-framework CoreFoundation -framework IOKit&quot;)
-	ENDIF(APPLE)
+		IF(APPLE)
+			SET_TARGET_PROPERTIES(xpwn-bin PROPERTIES LINK_FLAGS &quot;-framework CoreFoundation -framework IOKit&quot;)
+		ENDIF(APPLE)
 
-	install(FILES ramdisk.dmg DESTINATION .)
-	install(TARGETS xpwn-bin DESTINATION .)
+		install(FILES ramdisk.dmg DESTINATION .)
+		install(TARGETS xpwn-bin DESTINATION .)
 
-ENDIF(NOT USB_FOUND)
+	ENDIF(NOT USB_FOUND)
+ENDIF(NOT APPLE OR NOT BUILD_STATIC)
 </diff>
      <filename>xpwn/CMakeLists.txt</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>a0b9ad4d246f6eb8f28234ef5359fa99a7e2eb9c</id>
    </parent>
  </parents>
  <author>
    <name>planetbeing</name>
    <email>planetbeing@gmail.com</email>
  </author>
  <url>http://github.com/planetbeing/xpwn/commit/345ea539bc305a072f2ba92a6dccca5fb7403cde</url>
  <id>345ea539bc305a072f2ba92a6dccca5fb7403cde</id>
  <committed-date>2008-09-19T15:01:06-07:00</committed-date>
  <authored-date>2008-09-19T15:01:06-07:00</authored-date>
  <message>Lots of miscellaneous fixes merged from private branch</message>
  <tree>59e39d7640af3b9397d06eb47f447aa555c4ea68</tree>
  <committer>
    <name>planetbeing</name>
    <email>planetbeing@gmail.com</email>
  </committer>
</commit>
