Permalink
Browse files

forgot the actual files

  • Loading branch information...
1 parent 2377488 commit 42a7096f0f7afedd68817ca7208cffa6abeb2edb Karsten Kusche committed Jan 18, 2010
View
@@ -0,0 +1,19 @@
+//
+// CrackedUnarchiver.h
+// PlistExplorer
+//
+// Created by Karsten Kusche on 13.01.10.
+// Copyright 2010 Briksoftware.com. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+@class PlistExplorer;
+
+@interface CrackedUnarchiver : NSKeyedUnarchiver {
+ PlistExplorer* cracker;
+}
+
+- (PlistExplorer *) cracker;
+- (void) setCracker: (PlistExplorer *) newValue;
+@end
View
@@ -0,0 +1,24 @@
+//
+// CrackedUnarchiver.m
+// PlistExplorer
+//
+// Created by Karsten Kusche on 13.01.10.
+// Copyright 2010 Briksoftware.com. All rights reserved.
+//
+
+#import "CrackedUnarchiver.h"
+
+
+@implementation CrackedUnarchiver
+
+
+- (PlistExplorer *) cracker {
+ return cracker;
+}
+
+- (void) setCracker: (PlistExplorer *) newValue {
+ [cracker autorelease];
+ cracker = [newValue retain];
+}
+
+@end
View
@@ -0,0 +1,16 @@
+//
+// Morphic.h
+// PlistExplorer
+//
+// Created by Karsten Kusche on 13.01.10.
+// Copyright 2010 Briksoftware.com. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface Morphic : NSObject {
+ NSMutableDictionary* data;
+}
+
+@end
View
@@ -0,0 +1,55 @@
+//
+// Morphic.m
+// PlistExplorer
+//
+// Created by Karsten Kusche on 13.01.10.
+// Copyright 2010 Briksoftware.com. All rights reserved.
+//
+
+#import "Morphic.h"
+#import "PlistExplorer.h"
+#import "CrackedUnarchiver.h"
+
+@implementation Morphic
+
+- (id) init
+{
+ self = [super init];
+ if (self != nil) {
+ data = [NSMutableDictionary dictionary];
+ }
+ return self;
+}
+
+- (id)initWithCoder:(NSKeyedUnarchiver*)unarchiver
+{
+ self = [self init];
+ NSArray* keys = [[(CrackedUnarchiver*)unarchiver cracker] keysOfUnarchiver:unarchiver];
+
+ for (NSString* key in keys)
+ {
+ id obj = [unarchiver decodeObjectForKey:key];
+ if (obj == nil)
+ {
+ // nil wouldn't be shown, so use a string @"nil"
+ obj = @"nil";
+ }
+ [data setObject: obj forKey:key];
+ }
+ return self;
+}
+
+- (void)logYourselfLevel:(NSInteger)level
+{
+ // the information about the object
+ printf("%s\n",[[NSString stringWithFormat:@"%@%@",[self gapForLevel:level],[self className]] UTF8String]);
+
+ // the information about the object's properties
+ for (NSString* key in [data allKeys])
+ {
+ id object = [data objectForKey:key];
+ [key logYourselfLevel: level+1];
+ [object logYourselfLevel: level+3];
+ }
+}
+@end
View
@@ -0,0 +1,27 @@
+//
+// PlistExplorer.h
+// PlistExplorer
+//
+// Created by Karsten Kusche on 13.01.10.
+// Copyright 2010 Briksoftware.com. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface PlistExplorer : NSObject {
+ NSString* file;
+ NSData* data;
+}
+
+- (NSDictionary*)crackFile:(NSString*)aFile;
+- (NSArray*)keysOfUnarchiver:(NSKeyedUnarchiver*)unarchiver;
+
+@end
+
+
+@interface NSObject (PlistExplorer)
+- (void)logYourself;
+- (void)logYourselfLevel:(NSInteger)level;
+- (NSString*)gapForLevel:(NSInteger) level;
+@end
View
@@ -0,0 +1,174 @@
+//
+// PlistExplorer.m
+// PlistExplorer
+//
+// Created by Karsten Kusche on 13.01.10.
+// Copyright 2010 Briksoftware.com. All rights reserved.
+//
+
+#import "PlistExplorer.h"
+#import "Morphic.h"
+#import "CrackedUnarchiver.h"
+#import "objc/objc-class.h"
+
+@interface NSKeyedUnarchiver (PlistExplorer)
+
+- (id)_blobForCurrentObject; // returns the current blob object
+- (void)setClass:(Class)arg1 forClassName:(NSString*)name;
+- (void)reset;
+
+@end
+
+@implementation NSObject (PlistExplorer)
+
+- (void)logYourself
+{
+ [self logYourselfLevel:1];
+}
+
+- (NSString*)logString
+{
+ return [self description];
+}
+
+- (void)logYourselfLevel:(NSInteger)level
+{
+ printf("%s\n",[[NSString stringWithFormat:@"%@%@",[self gapForLevel:level],[self logString]] UTF8String]);
+}
+
+- (NSString*)gapForLevel:(NSInteger)level
+{
+ NSMutableString* gap = [NSMutableString stringWithCapacity:level*2];
+ int i;
+ for (i = 0; i< level; i++)
+ {
+ [gap appendString:@" "];
+ }
+ return gap;
+}
+
+@end
+
+@implementation NSArray (PlistExplorer)
+
+- (void)logYourselfLevel:(NSInteger)level
+{
+ for (id obj in self)
+ {
+ [obj logYourselfLevel: level + 1];
+ }
+}
+
+@end
+
+@implementation NSDictionary (PlistExplorer)
+
+- (void)logYourselfLevel:(NSInteger)level
+{
+ for (NSString* key in [self allKeys])
+ {
+ id obj = [self objectForKey:key];
+ [key logYourselfLevel: level + 1];
+ [obj logYourselfLevel: level + 3];
+ }
+}
+
+@end
+
+
+@implementation NSData (PlistExplorer)
+
+- (NSString*)logString
+{
+ // description of NSData is a bit too long, just write something usefull
+ return [NSString stringWithFormat: @"NSData with: %i Bytes",[self length]];
+}
+
+@end
+
+@implementation PlistExplorer
+
+- (NSKeyedUnarchiver *) newUnarchiver
+{
+ CrackedUnarchiver* unarchiver = [[CrackedUnarchiver alloc] initForReadingWithData:data];
+ [unarchiver setCracker:self];
+ return unarchiver;
+}
+
+- (NSString*)getClassNameFromException:(NSException*)exception
+{
+ // parse the exception's reason for the name of the class that it wanted to unarchive
+
+ NSString* reason = [exception reason];
+ NSScanner* scanner = [NSScanner scannerWithString:reason];
+ NSString* prefix;
+ [scanner scanString:@"*** -[CrackedUnarchiver decodeObjectForKey:]: cannot decode object of class (" intoString:&prefix];
+ NSString* name;
+ [scanner scanUpToString:@")" intoString:&name];
+ return name;
+}
+
+- (NSArray*)keysOfUnarchiver:(NSKeyedUnarchiver*)unarchiver
+{
+ NSDictionary* blob = [unarchiver _blobForCurrentObject];
+ // blob has the keys of all objects + a @"$class" key
+ return [blob allKeys];
+}
+
+
+- (void) addMorphicNamed: (NSString *) className
+{
+ Class newClass = objc_allocateClassPair([Morphic class], [className UTF8String],0);
+ objc_registerClassPair(newClass);
+}
+
+- (id)crackUnarchiver:(NSKeyedUnarchiver*)unarchiver
+{
+ // return the unarchived object
+
+ NSArray* keys = [self keysOfUnarchiver: unarchiver];
+ for (NSString* key in keys)
+ {
+ // there should be only one key in keys. At least only the first object is returned.
+ BOOL error = YES;
+ while (error)
+ {
+ // try until it is cracked
+ @try
+ {
+ error = NO;
+ return [unarchiver decodeObjectForKey:key];
+
+ }
+ @catch (NSException* exception)
+ {
+ if ([[exception name] isEqual:NSInvalidUnarchiveOperationException])
+ {
+ // too bad the exception doesn't have the class's name in its info dictionary.
+ // actually this could probably be swizzled into appkit..
+ NSString* className = [self getClassNameFromException: exception];
+ [self addMorphicNamed: className];
+ unarchiver = [self newUnarchiver];
+ }
+ else
+ {
+ NSLog(@"unhandled exception: %@",exception);
+ exit(1);
+ }
+ error = YES;
+ }
+ }
+ }
+ // NSLog(@"dict: %@",dict);
+ return nil;
+}
+
+- (NSDictionary*)crackFile:(NSString*)aFile
+{
+ file = aFile;
+ data = [NSData dataWithContentsOfFile:file];
+ NSKeyedUnarchiver* unarchiver = [self newUnarchiver];
+
+ return [self crackUnarchiver: unarchiver];
+}
+@end
Oops, something went wrong.

0 comments on commit 42a7096

Please sign in to comment.