forked from preemptive/PPiOS-Rename
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CDLCRunPath.m
71 lines (52 loc) · 1.87 KB
/
CDLCRunPath.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// -*- mode: ObjC -*-
// This file is part of class-dump, a utility for examining the Objective-C segment of Mach-O files.
// Copyright (C) 1997-1998, 2000-2001, 2004-2015 Steve Nygard.
#import "CDLCRunPath.h"
#import "CDMachOFile.h"
#import "CDSearchPathState.h"
@implementation CDLCRunPath
{
struct rpath_command _rpathCommand;
NSString *_path;
}
- (id)initWithDataCursor:(CDMachOFileDataCursor *)cursor;
{
if ((self = [super initWithDataCursor:cursor])) {
_rpathCommand.cmd = [cursor readInt32];
_rpathCommand.cmdsize = [cursor readInt32];
_rpathCommand.path.offset = [cursor readInt32];
NSUInteger length = _rpathCommand.cmdsize - sizeof(_rpathCommand);
//NSLog(@"expected length: %u", length);
_path = [cursor readStringOfLength:length encoding:NSASCIIStringEncoding];
//NSLog(@"path: %@", _path);
}
return self;
}
#pragma mark -
- (uint32_t)cmd;
{
return _rpathCommand.cmd;
}
- (uint32_t)cmdsize;
{
return _rpathCommand.cmdsize;
}
- (NSString *)resolvedRunPath;
{
NSString *loaderPathPrefix = @"@loader_path";
NSString *executablePathPrefix = @"@executable_path";
if ([self.path hasPrefix:loaderPathPrefix]) {
NSString *loaderPath = [self.machOFile.filename stringByDeletingLastPathComponent];
NSString *str = [[self.path stringByReplacingOccurrencesOfString:loaderPathPrefix withString:loaderPath] stringByStandardizingPath];
return str;
}
if ([self.path hasPrefix:executablePathPrefix]) {
NSString *str = @"";
NSString *executablePath = self.machOFile.searchPathState.executablePath;
if (executablePath)
str = [[self.path stringByReplacingOccurrencesOfString:executablePathPrefix withString:executablePath] stringByStandardizingPath];
return str;
}
return self.path;
}
@end