Embedding data, particularly text-based data back into an mdbackup file isn't just a matter of setting the value in the dictionary for the @"Data" key. Instead, you need to serialize your output. The code that follows demonstrates a simple way to serialize property lists into an mdbackup-compatible format.
Unfortunately, you cannot simply use this approach to replace the data in a backup file to trick the iPhone into updating a new version. Once you mess with your mdbackup file (notice how the code here produces a second file rather than altering the original), you'll need to synchronize the updated file with the manifest that's used to ensure that untampered files are restored.
// Read in the file to embed
NSMutableString *embedFile = [NSMutableString stringWithCString:argv[1] encoding:1];
if (![[NSFileManager defaultManager] fileExistsAtPath:embedFile])
{
fprintf(stderr, "File %s does not exist\n", argv[1]);
exit(-1);
}
NSData *pdata = [NSData dataWithContentsOfFile:embedFile];
// Read in the mdbackup file
NSMutableString *mfile = [NSMutableString stringWithCString:argv[2] encoding:1];
if (![[NSFileManager defaultManager] fileExistsAtPath:mfile])
{
fprintf(stderr, "File %s does not exist\n", argv[2]);
exit(-1);
}
NSMutableDictionary *plist = [NSMutableDictionary dictionaryWithContentsOfFile:mfile];
// Add the embedded file
[plist setObject:pdata forKey:@"Data"];
// Serialize the output
NSString *errorString;
// NSPropertyListXMLFormat_v1_0
NSData *outData = [NSPropertyListSerialization dataFromPropertyList:plist format:NSPropertyListBinaryFormat_v1_0 errorDescription:&errorString];
[outData writeToFile:[@"out-" stringByAppendingString:mfile] atomically:NO];
Trying to restore old Notes from a previous backup into the current backup. Should not be horribly difficult, except I need to update the Manifest.plist file. This is the closest I have found to a suggestion on how to go about it and yet it seems that it just stops mid-sentence.
I attempted to do this by treating it as a typical manifest for reading and writing, but apparently did it wrong or it isn't quite so typical.
So, how?
"you'll need to synchronize the updated file with the manifest that's used to ensure that untampered files are restored." seems like an incomplete thought . . .
Thanks!
Nevermind, I found the followup post here:
http://blogs.oreilly.com/iphone/2008/07/iphone-backups-part-5-even-mor.html