Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse the contents of a foreign file created with NSKeyedArchiver

I need to be able to compare two versions of a plist file created with NSKeyedArchiver. In particular, it's the "elements" file created in Xcode for a .xcdatamodeld file.

Since I have not created this file myself I can not recreate its object model. Instead, I need to understand which classes and keyed properties the archive contains.

Ideally, I want to create a tree containing strings representing the names of classes along with their property names and values. I assume that all this information is stored in the archive, so it should be possible to generically parse this archive, right?

I've read about NSKeyedUnarchiver and its delegate. I've only gotten as as as this:

Unarchive the file data:

NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
unarchiver.delegate = self;
id graph = [unarchiver decodeObjectForKey:@"root"];

Here's the delegate method that gets called when an unknown class is requested. I return a proxy class here in which I hope to collect its values:

- (Class)unarchiver:(NSKeyedUnarchiver *)unarchiver cannotDecodeObjectOfClassName:(NSString *)name originalClasses:(NSArray *)classNames
{
    NSLog(@"wants: %@", name);
    return [ObjProxy class];
}

The proxy class implements

- (id)initWithCoder:(NSCoder *)aDecoder

in which I do not know how to proceed, not knowing the actual properties of the classes. NSCoder doesn't seem to provide any function to learn of the available keys. Is there a trick to get to them, maybe by overriding some of the lower level objc methods?

So far, with this little code shown above, when parsing the "elements" file, I only get the request for one class, "XDPMModel", and then it's done.

Any ideas how to get this working, i.e. traverse the tree deeper?

like image 772
Thomas Tempelmann Avatar asked Feb 23 '23 07:02

Thomas Tempelmann


1 Answers

You can use PlistExplorer, it's a Cocoa Tool to inspect files written by NSKeyedArchiver.

like image 193
0xced Avatar answered May 16 '23 06:05

0xced