Skip to content

Commit

Permalink
Simplify reading of section name and segment name
Browse files Browse the repository at this point in the history
  • Loading branch information
0xced committed Mar 12, 2014
1 parent 5082090 commit dbc8e49
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions Source/CDSection.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ - (id)initWithDataCursor:(CDMachOFileDataCursor *)cursor segment:(CDLCSegment *)
if ((self = [super init])) {
_segment = segment;

[cursor readBytesOfLength:16 intoBuffer:_section.sectname];
[cursor readBytesOfLength:16 intoBuffer:_section.segname];
_sectionName = [cursor readStringOfLength:16 encoding:NSASCIIStringEncoding];
memcpy(_section.sectname, [_sectionName UTF8String], sizeof(_section.sectname));
_segmentName = [cursor readStringOfLength:16 encoding:NSASCIIStringEncoding];
memcpy(_section.segname, [_segmentName UTF8String], sizeof(_section.segname));
_section.addr = [cursor readPtr];
_section.size = [cursor readPtr];
_section.offset = [cursor readInt32];
Expand All @@ -36,17 +38,6 @@ - (id)initWithDataCursor:(CDMachOFileDataCursor *)cursor segment:(CDLCSegment *)
if (cursor.machOFile.uses64BitABI) {
_section.reserved3 = [cursor readInt32];
}

// These aren't guaranteed to be null terminated. Witness __cstring_object in __OBJC segment
char buf[17];

memcpy(buf, _section.segname, 16);
buf[16] = 0;
_segmentName = [[NSString alloc] initWithBytes:buf length:strlen(buf) encoding:NSASCIIStringEncoding];

memcpy(buf, _section.sectname, 16);
buf[16] = 0;
_sectionName = [[NSString alloc] initWithBytes:buf length:strlen(buf) encoding:NSASCIIStringEncoding];
}

return self;
Expand Down

0 comments on commit dbc8e49

Please sign in to comment.