Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kfatehi committed Dec 10, 2016
1 parent e1af87b commit e530b22
Show file tree
Hide file tree
Showing 11 changed files with 193 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
xcuserdata
6 changes: 6 additions & 0 deletions LICENSE
@@ -0,0 +1,6 @@
ISC License (ISC)
Copyright (c) 2016, Keyvan Fatehi

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
7 changes: 7 additions & 0 deletions README.md
@@ -0,0 +1,7 @@
# ichat2json

Reads an .ichat binary plist file and writes newline-separated JSON to STDOUT

## Special Thanks

* https://github.com/jmah/iChat-Image-Indexer
18 changes: 18 additions & 0 deletions ichat2json.xcodeproj/project.pbxproj
Expand Up @@ -8,6 +8,9 @@

/* Begin PBXBuildFile section */
7AE34B8A1DFBA30600969CBE /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AE34B891DFBA30500969CBE /* main.m */; };
7AE34B951DFBAB4800969CBE /* InstantMessage.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AE34B941DFBAB4800969CBE /* InstantMessage.m */; };
7AE34B981DFBAD1C00969CBE /* StubCoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AE34B971DFBAD1C00969CBE /* StubCoder.m */; };
7AE34B9B1DFBB54F00969CBE /* Sender.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AE34B9A1DFBB54F00969CBE /* Sender.m */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand All @@ -25,6 +28,12 @@
/* Begin PBXFileReference section */
7AE34B861DFBA30500969CBE /* ichat2json */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = ichat2json; sourceTree = BUILT_PRODUCTS_DIR; };
7AE34B891DFBA30500969CBE /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
7AE34B931DFBAB4800969CBE /* InstantMessage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InstantMessage.h; sourceTree = "<group>"; };
7AE34B941DFBAB4800969CBE /* InstantMessage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = InstantMessage.m; sourceTree = "<group>"; };
7AE34B961DFBAD1C00969CBE /* StubCoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StubCoder.h; sourceTree = "<group>"; };
7AE34B971DFBAD1C00969CBE /* StubCoder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StubCoder.m; sourceTree = "<group>"; };
7AE34B991DFBB54F00969CBE /* Sender.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Sender.h; sourceTree = "<group>"; };
7AE34B9A1DFBB54F00969CBE /* Sender.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Sender.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -57,7 +66,13 @@
7AE34B881DFBA30500969CBE /* ichat2json */ = {
isa = PBXGroup;
children = (
7AE34B991DFBB54F00969CBE /* Sender.h */,
7AE34B9A1DFBB54F00969CBE /* Sender.m */,
7AE34B961DFBAD1C00969CBE /* StubCoder.h */,
7AE34B971DFBAD1C00969CBE /* StubCoder.m */,
7AE34B891DFBA30500969CBE /* main.m */,
7AE34B931DFBAB4800969CBE /* InstantMessage.h */,
7AE34B941DFBAB4800969CBE /* InstantMessage.m */,
);
path = ichat2json;
sourceTree = "<group>";
Expand Down Expand Up @@ -118,7 +133,10 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
7AE34B9B1DFBB54F00969CBE /* Sender.m in Sources */,
7AE34B8A1DFBA30600969CBE /* main.m in Sources */,
7AE34B951DFBAB4800969CBE /* InstantMessage.m in Sources */,
7AE34B981DFBAD1C00969CBE /* StubCoder.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
18 changes: 18 additions & 0 deletions ichat2json/InstantMessage.h
@@ -0,0 +1,18 @@
//
// InstantMessage.h
// ichat2json
//
// Created by Keyvan Fatehi on 12/9/16.
// Copyright © 2016 Keyvan Fatehi. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Sender.h"

@interface InstantMessage : NSObject <NSCoding /* Decoding only */>

@property (readonly, copy) NSDate *date;
@property (readonly, copy) NSAttributedString *message;
@property (readonly, copy) Sender *sender;
- (NSString *) toJSONString;
@end
43 changes: 43 additions & 0 deletions ichat2json/InstantMessage.m
@@ -0,0 +1,43 @@
//
// InstantMessage.m
// ichat2json
//
// Created by Keyvan Fatehi on 12/9/16.
// Copyright © 2016 Keyvan Fatehi. All rights reserved.

#import "InstantMessage.h"

@implementation InstantMessage
- (id)initWithCoder:(NSCoder *)decoder;
{
if (!(self = [super init]))
return nil;
_sender = [decoder decodeObjectForKey:@"Sender"];
_date = [decoder decodeObjectForKey:@"Time"];
_message = [decoder decodeObjectForKey:@"MessageText"];

return self;
}

- (void)encodeWithCoder:(NSCoder *)encoder;
{ NSAssert1(NO, @"%@ does not allow encoding.", [self class]); }

- (NSString *) toJSONString;
{
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS"];
NSString *dateStr = [dateFormat stringFromDate:_date];
NSString *msg = [_message string];
NSString *senderName = [_sender accountName];
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:senderName, @"sender", msg, @"message", dateStr, @"date", nil];
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
NSString *jsonString;
if (! jsonData) {
NSLog(@"Got an error: %@", error);
} else {
jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}
return jsonString;
}
@end
15 changes: 15 additions & 0 deletions ichat2json/Sender.h
@@ -0,0 +1,15 @@
//
// Sender.h
// ichat2json
//
// Created by Keyvan Fatehi on 12/9/16.
// Copyright © 2016 Keyvan Fatehi. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface Sender : NSObject <NSCoding /* Decoding only */>

@property (readonly, copy) NSString *accountName;

@end
26 changes: 26 additions & 0 deletions ichat2json/Sender.m
@@ -0,0 +1,26 @@
//
// Sender.m
// ichat2json
//
// Created by Keyvan Fatehi on 12/9/16.
// Copyright © 2016 Keyvan Fatehi. All rights reserved.
//

#import "Sender.h"

@implementation Sender

@synthesize accountName = _accountName;

- (id)initWithCoder:(NSCoder *)decoder;
{
if (!(self = [super init]))
return nil;
_accountName = [decoder decodeObjectForKey:@"ID"];
return self;
}

- (void)encodeWithCoder:(NSCoder *)encoder;
{ NSAssert1(NO, @"%@ does not allow encoding.", [self class]); }

@end
13 changes: 13 additions & 0 deletions ichat2json/StubCoder.h
@@ -0,0 +1,13 @@
//
// StubCoder.h
// ichat2json
//
// Created by Keyvan Fatehi on 12/9/16.
// Copyright © 2016 Keyvan Fatehi. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface StubCoder : NSObject

@end
22 changes: 22 additions & 0 deletions ichat2json/StubCoder.m
@@ -0,0 +1,22 @@
//
// StubCoder.m
// ichat2json
//
// Created by Keyvan Fatehi on 12/9/16.
// Copyright © 2016 Keyvan Fatehi. All rights reserved.
//

#import "StubCoder.h"

@implementation StubCoder
- (id)initWithCoder:(NSCoder *)decoder;
{
if (!(self = [super init]))
return nil;

return self;
}

- (void)encodeWithCoder:(NSCoder *)encoder;
{ NSAssert1(NO, @"%@ does not allow encoding.", [self class]); }
@end
26 changes: 24 additions & 2 deletions ichat2json/main.m
Expand Up @@ -7,11 +7,33 @@
//

#import <Foundation/Foundation.h>
#import "InstantMessage.h"
#import "Sender.h"
#import "StubCoder.h"

int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here...
NSLog(@"Hello, World!");
if(argc < 2)
{
fprintf(stderr, "Usage: %s path/to/ichat\n", argv[0]);
exit(-1);
}

NSURL *f = [NSURL fileURLWithPath:[NSString stringWithUTF8String:argv[1]]];
[NSKeyedUnarchiver setClass:[InstantMessage class] forClassName:@"InstantMessage"];
[NSKeyedUnarchiver setClass:[StubCoder class] forClassName:@"NSFont"];
[NSKeyedUnarchiver setClass:[StubCoder class] forClassName:@"NSMutableParagraphStyle"];
[NSKeyedUnarchiver setClass:[Sender class] forClassName:@"Presentity"];
for (id object in [NSKeyedUnarchiver unarchiveObjectWithFile: [f path]]) {
if ([object isKindOfClass:[NSMutableArray class]]) {
for (id sub in object) {
if ([sub isKindOfClass:[InstantMessage class]]) {
InstantMessage *im = (InstantMessage *) sub;
fprintf(stdout, "%s\n", [[im toJSONString] UTF8String]);
}
}
}
}
}
return 0;
}

0 comments on commit e530b22

Please sign in to comment.