Skip to content

Commit

Permalink
Merge pull request nygard#27 from 0xced/feature/NSUUID
Browse files Browse the repository at this point in the history
Use NSUUID instead of CFUUIDRef
  • Loading branch information
nygard committed Dec 8, 2013
2 parents 5369b24 + e006f98 commit f7c4e0a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 38 deletions.
4 changes: 3 additions & 1 deletion Source/CDClassDumpVisitor.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ - (void)visitObjectiveCProcessor:(CDObjectiveCProcessor *)processor;
[self.resultString appendString:@"#pragma mark -\n\n"];
[self.resultString appendString:@"//\n"];
[self.resultString appendFormat:@"// File: %@\n", machOFile.filename];
[self.resultString appendFormat:@"// UUID: %@\n", machOFile.uuidString];
if (machOFile.UUID) {
[self.resultString appendFormat:@"// UUID: %@\n", [machOFile.UUID UUIDString]];
}
[self.resultString appendString:@"//\n"];
[self.resultString appendFormat:@"// Arch: %@\n", CDNameForCPUType(machOFile.cputype, machOFile.cpusubtype)];

Expand Down
2 changes: 1 addition & 1 deletion Source/CDLCUUID.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

@interface CDLCUUID : CDLoadCommand

@property (nonatomic, readonly) NSString *uuidString;
@property (nonatomic, readonly) NSUUID *UUID;

@end
41 changes: 9 additions & 32 deletions Source/CDLCUUID.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,29 @@

#import "CDLCUUID.h"

#import <CoreFoundation/CoreFoundation.h>
#import "CDMachOFile.h"

@implementation CDLCUUID
{
struct uuid_command _uuidCommand;

CFUUIDRef _uuid;
NSUUID *_UUID;
}

- (id)initWithDataCursor:(CDMachOFileDataCursor *)cursor;
{
if ((self = [super initWithDataCursor:cursor])) {
_uuidCommand.cmd = [cursor readInt32];
_uuidCommand.cmdsize = [cursor readInt32];
for (NSUInteger index = 0; index < 16; index++) {
for (NSUInteger index = 0; index < sizeof(_uuidCommand.uuid); index++) {
_uuidCommand.uuid[index] = [cursor readByte];
}
// Lovely API
_uuid = CFUUIDCreateWithBytes(kCFAllocatorDefault,
_uuidCommand.uuid[0],
_uuidCommand.uuid[1],
_uuidCommand.uuid[2],
_uuidCommand.uuid[3],
_uuidCommand.uuid[4],
_uuidCommand.uuid[5],
_uuidCommand.uuid[6],
_uuidCommand.uuid[7],
_uuidCommand.uuid[8],
_uuidCommand.uuid[9],
_uuidCommand.uuid[10],
_uuidCommand.uuid[11],
_uuidCommand.uuid[12],
_uuidCommand.uuid[13],
_uuidCommand.uuid[14],
_uuidCommand.uuid[15]);
_UUID = [[NSUUID alloc] initWithUUIDBytes:_uuidCommand.uuid];
}

return self;
}

- (void)dealloc;
{
CFRelease(_uuid);
}

#pragma mark -

- (uint32_t)cmd;
Expand All @@ -63,18 +40,18 @@ - (uint32_t)cmdsize;
return _uuidCommand.cmdsize;
}

- (NSString *)uuidString;
{
return (__bridge_transfer NSString *)(CFUUIDCreateString(kCFAllocatorDefault, _uuid));
}

- (void)appendToString:(NSMutableString *)resultString verbose:(BOOL)isVerbose;
{
[super appendToString:resultString verbose:isVerbose];

[resultString appendString:@" uuid "];
[resultString appendString:[self uuidString]];
[resultString appendString:[self.UUID UUIDString]];
[resultString appendString:@"\n"];
}

- (NSString *)extraDescription;
{
return [self.UUID UUIDString];
}

@end
2 changes: 1 addition & 1 deletion Source/CDMachOFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ typedef enum : NSUInteger {
- (NSString *)loadCommandString:(BOOL)isVerbose;
- (NSString *)headerString:(BOOL)isVerbose;

@property (nonatomic, readonly) NSString *uuidString;
@property (nonatomic, readonly) NSUUID *UUID;
@property (nonatomic, readonly) NSString *archName;

- (Class)processorClass;
Expand Down
6 changes: 3 additions & 3 deletions Source/CDMachOFile.m
Original file line number Diff line number Diff line change
Expand Up @@ -458,13 +458,13 @@ - (NSString *)headerString:(BOOL)isVerbose;
return resultString;
}

- (NSString *)uuidString;
- (NSUUID *)UUID;
{
for (CDLoadCommand *loadCommand in _loadCommands)
if ([loadCommand isKindOfClass:[CDLCUUID class]])
return [(CDLCUUID *)loadCommand uuidString];
return [(CDLCUUID *)loadCommand UUID];

return @"N/A";
return nil;
}

// Must not return nil.
Expand Down

0 comments on commit f7c4e0a

Please sign in to comment.