Permalink
Browse files

merge with ih8sn0w

  • Loading branch information...
Joshua Hill
Joshua Hill committed Feb 28, 2010
2 parents 28f7132 + 5109634 commit c68a13c04d9be24c6f8911786b202cb0af4f4a96
Showing with 213 additions and 198 deletions.
  1. +30 −48 dmg/io.c
  2. +20 −1 hfs/hfs.c
  3. +3 −0 ipsw-patch/img3.c
  4. +2 −2 ipsw-patch/itunespwn.c
  5. +148 −147 ipsw-patch/lzssfile.c
  6. +10 −0 ipsw-patch/xpwntool.c
View
@@ -7,6 +7,7 @@
#include <inttypes.h>
#define SECTORS_AT_A_TIME 0x200
+#define IGNORE_THRESHOLD SECTORS_AT_A_TIME * 2
// Okay, this value sucks. You shouldn't touch it because it affects how many ignore sections get added to the blkx list
// If the blkx list gets too fragmented with ignore sections, then the copy list in certain versions of the iPhone's
@@ -19,6 +20,8 @@
// There's always a large-ish one at the end, and a tiny 2 sector one at the end too, to take care of the space after
// the backup volume header. No frakking clue how they go about determining how to do that.
+// I've done some tweaks, to make algorithm to act more closer to Apple // Vortex
+
BLKXTable* insertBLKX(AbstractFile* out, AbstractFile* in, uint32_t firstSectorNumber, uint32_t numSectors, uint32_t blocksDescriptor,
uint32_t checksumType, ChecksumFunc uncompressedChk, void* uncompressedChkToken, ChecksumFunc compressedChk,
void* compressedChkToken, Volume* volume, int addComment) {
@@ -27,15 +30,14 @@ BLKXTable* insertBLKX(AbstractFile* out, AbstractFile* in, uint32_t firstSectorN
uint32_t roomForRuns;
uint32_t curRun;
uint64_t curSector;
+ uint64_t curOff;
unsigned char* inBuffer;
unsigned char* outBuffer;
size_t bufferSize;
size_t have;
int ret;
- int IGNORE_THRESHOLD = 100000;
-
z_stream strm;
blkx = (BLKXTable*) malloc(sizeof(BLKXTable) + (2 * sizeof(BLKXRun)));
@@ -102,6 +104,8 @@ BLKXTable* insertBLKX(AbstractFile* out, AbstractFile* in, uint32_t firstSectorN
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
+ curOff = startOff + (blkx->sectorCount - numSectors) * SECTOR_SIZE;
+
int amountRead;
{
size_t sectorsToSkip = 0;
@@ -111,7 +115,7 @@ BLKXTable* insertBLKX(AbstractFile* out, AbstractFile* in, uint32_t firstSectorN
{
blkx->runs[curRun].sectorCount = ((numSectors - processed) > SECTORS_AT_A_TIME) ? SECTORS_AT_A_TIME : (numSectors - processed);
- //printf("Currently at %" PRId64 "\n", curOff);
+ //printf("Currently at %" PRId64 "\n", curOff);
in->seek(in, startOff + (blkx->sectorCount - numSectors + processed) * SECTOR_SIZE);
ASSERT((amountRead = in->read(in, inBuffer, blkx->runs[curRun].sectorCount * SECTOR_SIZE)) == (blkx->runs[curRun].sectorCount * SECTOR_SIZE), "mRead");
@@ -138,62 +142,40 @@ BLKXTable* insertBLKX(AbstractFile* out, AbstractFile* in, uint32_t firstSectorN
if(counter < counter_max)
{
- if(sectorsToSkip > IGNORE_THRESHOLD)
+ if(sectorsToSkip < IGNORE_THRESHOLD)
{
- //printf("Seeking back to %" PRId64 "\n", curOff + (skipInBuffer * SECTOR_SIZE));
- //in->seek(in, curOff + (skipInBuffer * SECTOR_SIZE));
- } else {
- //printf("Breaking out: %d / %d\n", (size_t) counter, (size_t) counter_max);
- }
+ blkx->runs[curRun].sectorCount = (numSectors > SECTORS_AT_A_TIME) ? SECTORS_AT_A_TIME : numSectors;
+ in->seek(in, curOff);
+ ASSERT((amountRead = in->read(in, inBuffer, blkx->runs[curRun].sectorCount * SECTOR_SIZE)) == (blkx->runs[curRun].sectorCount * SECTOR_SIZE), "mRead");
+ };
break;
}
}
- if(sectorsToSkip > IGNORE_THRESHOLD)
+ if(sectorsToSkip >= IGNORE_THRESHOLD)
{
- int remainder = sectorsToSkip & 0xf;
-
- if(sectorsToSkip != remainder)
- {
- blkx->runs[curRun].type = BLOCK_IGNORE;
- blkx->runs[curRun].reserved = 0;
- blkx->runs[curRun].sectorStart = curSector;
- blkx->runs[curRun].sectorCount = sectorsToSkip - remainder;
- blkx->runs[curRun].compOffset = out->tell(out) - blkx->dataStart;
- blkx->runs[curRun].compLength = 0;
-
- printf("run %d: skipping sectors=%" PRId64 ", left=%d\n", curRun, (int64_t) sectorsToSkip, numSectors);
-
- curSector += blkx->runs[curRun].sectorCount;
- numSectors -= blkx->runs[curRun].sectorCount;
-
- curRun++;
- }
-
- if(remainder > 0)
- {
- blkx->runs[curRun].type = BLOCK_IGNORE;
- blkx->runs[curRun].reserved = 0;
- blkx->runs[curRun].sectorStart = curSector;
- blkx->runs[curRun].sectorCount = remainder;
- blkx->runs[curRun].compOffset = out->tell(out) - blkx->dataStart;
- blkx->runs[curRun].compLength = 0;
-
- printf("run %d: skipping sectors=%" PRId64 ", left=%d\n", curRun, (int64_t) sectorsToSkip, numSectors);
-
- curSector += blkx->runs[curRun].sectorCount;
- numSectors -= blkx->runs[curRun].sectorCount;
-
- curRun++;
+ blkx->runs[curRun].type = BLOCK_IGNORE;
+ blkx->runs[curRun].reserved = 0;
+ blkx->runs[curRun].sectorStart = curSector;
+ blkx->runs[curRun].sectorCount = sectorsToSkip;
+ blkx->runs[curRun].compOffset = out->tell(out) - blkx->dataStart;
+ blkx->runs[curRun].compLength = 0;
+
+ printf("run %d: skipping sectors=%" PRId64 ", left=%d\n", curRun, (int64_t) sectorsToSkip, numSectors);
+
+ curSector += blkx->runs[curRun].sectorCount;
+ numSectors -= blkx->runs[curRun].sectorCount;
+ curRun++;
+ if(curRun >= roomForRuns) {
+ roomForRuns <<= 1;
+ blkx = (BLKXTable*) realloc(blkx, sizeof(BLKXTable) + (roomForRuns * sizeof(BLKXRun)));
}
- IGNORE_THRESHOLD = 0;
-
continue;
}
}
- printf("run %d: sectors=%" PRId64 ", left=%d\n", curRun, blkx->runs[curRun].sectorCount, numSectors);
+ printf("run %d: sectors=%" PRId64 ", left=%d\n", curRun, blkx->runs[curRun].sectorCount, numSectors);
ASSERT(deflateInit(&strm, 1) == Z_OK, "deflateInit");
@@ -216,7 +198,7 @@ BLKXTable* insertBLKX(AbstractFile* out, AbstractFile* in, uint32_t firstSectorN
have = bufferSize - strm.avail_out;
if((have / SECTOR_SIZE) >= (blkx->runs[curRun].sectorCount - 15)) {
- blkx->runs[curRun].type = BLOCK_RAW;
+ blkx->runs[curRun].type = BLOCK_RAW;
ASSERT(out->write(out, inBuffer, blkx->runs[curRun].sectorCount * SECTOR_SIZE) == (blkx->runs[curRun].sectorCount * SECTOR_SIZE), "fwrite");
blkx->runs[curRun].compLength += blkx->runs[curRun].sectorCount * SECTOR_SIZE;
View
@@ -222,6 +222,23 @@ void cmd_grow(Volume* volume, int argc, const char *argv[]) {
printf("grew volume: %" PRId64 "\n", newSize);
}
+void cmd_untar(Volume* volume, int argc, const char *argv[]) {
+ AbstractFile *inFile;
+
+ if(argc < 2) {
+ printf("Not enough arguments");
+ return;
+ }
+
+ inFile = createAbstractFileFromFile(fopen(argv[1], "rb"));
+
+ if(inFile == NULL) {
+ printf("file to untar not found");
+ }
+
+ hfs_untar(volume, inFile);
+}
+
void cmd_getattr(Volume* volume, int argc, const char *argv[]) {
HFSPlusCatalogRecord* record;
@@ -271,7 +288,7 @@ int main(int argc, const char *argv[]) {
TestByteOrder();
if(argc < 3) {
- printf("usage: %s <image-file> <ls|cat|mv|symlink|mkdir|add|rm|chmod|extract|extractall|rmall|addall|grow|getattr|debug> <arguments>\n", argv[0]);
+ printf("usage: %s <image-file> <ls|cat|mv|mkdir|add|rm|chmod|extract|extractall|rmall|addall|debug|symlink|getattr|grow|untar> <arguments>\n", argv[0]);
return 0;
}
@@ -315,6 +332,8 @@ int main(int argc, const char *argv[]) {
cmd_addall(volume, argc - 2, argv + 2);
} else if(strcmp(argv[2], "grow") == 0) {
cmd_grow(volume, argc - 2, argv + 2);
+ } else if(strcmp(argv[2], "untar") == 0) {
+ cmd_untar(volume, argc - 2, argv + 2);
} else if(strcmp(argv[2], "getattr") == 0) {
cmd_getattr(volume, argc - 2, argv + 2);
} else if(strcmp(argv[2], "debug") == 0) {
View
@@ -537,9 +537,12 @@ AbstractFile* createAbstractFileFromImg3(AbstractFile* file) {
info->cert = NULL;
info->kbag = NULL;
info->type = NULL;
+<<<<<<< HEAD:ipsw-patch/img3.c
info->shsh = NULL;
info->ecid = NULL;
info->encrypted = FALSE;
+=======
+>>>>>>> 510963469f82480453a13bbb73c0a95da0f0b378:ipsw-patch/img3.c
current = (Img3Element*) info->root->data;
while(current != NULL) {
View
@@ -9,7 +9,7 @@
#define SHGFP_TYPE_CURRENT 0
-const char restorePlist[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n <key>DeviceClass</key>\n <string>iPhone</string>\n <key>DeviceMap</key>\n <array/>\n <key>FirmwareDirectory</key>\n <string>Firmware</string>\n <key>ProductBuildVersion</key>\n <string>5A348</string>\n <key>ProductType</key>\n <string>iPhone1,1</string>\n <key>ProductVersion</key>\n <string>2.0</string>\n <key>SupportedProductTypeIDs</key>\n <dict>\n <key>DFU</key>\n <array>\n <integer>304218112</integer>\n </array>\n <key>Recovery</key>\n <array/>\n </dict>\n</dict>\n</plist>\n";
+const char restorePlist[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict>\n <key>DeviceClass</key>\n <string>iPhone</string>\n <key>DeviceMap</key>\n <array/>\n <key>FirmwareDirectory</key>\n <string>Firmware</string>\n <key>KernelCachesByPlatform</key>\n <dict/>\n <key>ProductBuildVersion</key>\n <string>7A341</string>\n <key>ProductType</key>\n <string>iPhone1,1</string>\n <key>ProductVersion</key>\n <string>3.0</string>\n <key>RamDisksByPlatform</key>\n <dict/>\n <key>SupportedProductTypeIDs</key>\n <dict>\n <key>DFU</key>\n <array>\n <integer>304218112</integer>\n </array>\n <key>Recovery</key>\n <array/>\n </dict>\n</dict>\n</plist>\n";
int main(int argc, char* argv[]) {
@@ -27,7 +27,7 @@ int main(int argc, char* argv[]) {
mkdir(path, 0755);
}
- strcat(path, "\\x12220000_4_Recovery.ipsw");
+ strcat(path, "\\x12220000_5_Recovery.ipsw");
void* buffer;
buffer = malloc(sizeof(restorePlist) - 1);
Oops, something went wrong.

0 comments on commit c68a13c

Please sign in to comment.