forked from preemptive/PPiOS-Rename
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CDLCRunPath.m
83 lines (61 loc) · 1.94 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
72
73
74
75
76
77
78
79
80
81
82
83
// -*- 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-2012 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] retain];
//NSLog(@"path: %@", path);
}
return self;
}
- (void)dealloc;
{
[path release];
[super dealloc];
}
#pragma mark -
- (uint32_t)cmd;
{
return rpathCommand.cmd;
}
- (uint32_t)cmdsize;
{
return rpathCommand.cmdsize;
}
- (NSString *)path;
{
return path;
}
- (NSString *)resolvedRunPath;
{
NSString *loaderPathPrefix = @"@loader_path";
NSString *executablePathPrefix = @"@executable_path";
if ([path hasPrefix:loaderPathPrefix]) {
NSString *loaderPath = [self.machOFile.filename stringByDeletingLastPathComponent];
NSString *str = [[path stringByReplacingOccurrencesOfString:loaderPathPrefix withString:loaderPath] stringByStandardizingPath];
return str;
}
if ([path hasPrefix:executablePathPrefix]) {
NSString *str = @"";
NSString *executablePath = self.machOFile.searchPathState.executablePath;
if (executablePath)
str = [[path stringByReplacingOccurrencesOfString:executablePathPrefix withString:executablePath] stringByStandardizingPath];
return str;
}
return path;
}
@end