void closeImg3(AbstractFile* file) { Img3Info* info = (Img3Info*) file->data; if(info->dirty) { if(info->encrypted) { uint32_t sz = info->data->header->dataSize; if (info->decryptLast) { sz = info->data->header->size; } uint8_t ivec[16]; memcpy(ivec, info->iv, 16); AES_cbc_encrypt(info->data->data, info->data->data, (sz / 16) * 16, &(info->encryptKey), ivec, AES_ENCRYPT); } info->file->seek(info->file, 0); info->root->header->dataSize = 0; /* hack to make certain writeImg3Element doesn't preallocate */ info->root->header->size = 0; writeImg3Element(info->file, info->root, info); } info->root->free(info->root); info->file->close(info->file); free(info); free(file); }
void writeImg3Root(AbstractFile * file, Img3Element * element, Img3Info * info) { AppleImg3RootHeader *header; Img3Element *current; off_t curPos; curPos = file->tell(file); curPos -= sizeof(AppleImg3Header); file->seek(file, curPos + sizeof(AppleImg3RootHeader)); header = (AppleImg3RootHeader *) element->header; current = (Img3Element *) element->data; while (current != NULL) { if (current->header->magic == IMG3_SHSH_MAGIC) { header->extra.shshOffset = (uint32_t) (file->tell(file) - sizeof(AppleImg3RootHeader)); } if (current->header->magic != IMG3_KBAG_MAGIC || info->encrypted) { writeImg3Element(file, current, info); } current = current->next; } header->base.dataSize = file->tell(file) - (curPos + sizeof(AppleImg3RootHeader)); header->base.size = sizeof(AppleImg3RootHeader) + header->base.dataSize; file->seek(file, curPos); flipAppleImg3Header(&(header->base)); flipAppleImg3RootExtra(&(header->extra)); file->write(file, header, sizeof(AppleImg3RootHeader)); flipAppleImg3RootExtra(&(header->extra)); flipAppleImg3Header(&(header->base)); file->seek(file, header->base.size); }
void closeImg3(AbstractFile * file) { uint8_t ivec[16]; Img3Info *info = (Img3Info *) file->data; if (info->dirty) { if (info->encrypted) { uint32_t sz = info->data->header->dataSize; if (info->decryptLast) { sz = info->data->header->size; } memcpy(ivec, info->iv, 16); AES_cbc_encrypt(info->data->data, info->data->data, (sz / 16) * 16, &(info->encryptKey), ivec, AES_ENCRYPT); } if (info->exploit24k) { info->replaceDWord = *((uint32_t *) info->data->data); FLIPENDIANLE(info->replaceDWord); *((uint32_t *) info->data->data) = 0x22023001; flipEndianLE(info->data->data, 4); } if (info->exploitN8824k) { info->replaceDWord = *((uint32_t *) info->data->data); FLIPENDIANLE(info->replaceDWord); *((uint32_t *) info->data->data) = 0x84023001; flipEndianLE(info->data->data, 4); } info->file->seek(info->file, 0); info->root->header->dataSize = 0; /* hack to make certain writeImg3Element doesn't preallocate */ info->root->header->size = 0; writeImg3Element(info->file, info->root, info); } info->root->free(info->root); info->file->close(info->file); free(info); free(file); }