-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBNProjectFile.cs
More file actions
249 lines (207 loc) · 6.61 KB
/
Copy pathBNProjectFile.cs
File metadata and controls
249 lines (207 loc) · 6.61 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
namespace BinaryNinja
{
public sealed class ProjectFile : AbstractSafeHandle<ProjectFile>
{
internal ProjectFile(IntPtr handle , bool owner)
: base(handle , owner)
{
}
internal static ProjectFile? NewFromHandle(IntPtr handle)
{
if (handle == IntPtr.Zero)
{
return null;
}
return new ProjectFile(
NativeMethods.BNNewProjectFileReference(handle) ,
true
);
}
internal static ProjectFile MustNewFromHandle(IntPtr handle)
{
if (handle == IntPtr.Zero)
{
throw new ArgumentNullException(nameof(handle));
}
return new ProjectFile(
NativeMethods.BNNewProjectFileReference(handle) ,
true
);
}
internal static ProjectFile? TakeHandle(IntPtr handle)
{
if (handle == IntPtr.Zero)
{
return null;
}
return new ProjectFile(handle, true);
}
internal static ProjectFile MustTakeHandle(IntPtr handle)
{
if (handle == IntPtr.Zero)
{
throw new ArgumentNullException(nameof(handle));
}
return new ProjectFile(handle, true);
}
internal static ProjectFile? BorrowHandle(IntPtr handle)
{
if (handle == IntPtr.Zero)
{
return null;
}
return new ProjectFile(handle, false);
}
internal static ProjectFile MustBorrowHandle(IntPtr handle)
{
if (handle == IntPtr.Zero)
{
throw new ArgumentNullException(nameof(handle));
}
return new ProjectFile(handle, false);
}
protected override bool ReleaseHandle()
{
if ( !this.IsInvalid )
{
NativeMethods.BNFreeProjectFile(this.handle);
this.SetHandleAsInvalid();
}
return true;
}
// --- Identity --------------------------------------------------------
/// <summary>The file's unique identifier.</summary>
public string Id
{
get { return UnsafeUtils.TakeAnsiString(NativeMethods.BNProjectFileGetId(this.handle)); }
}
/// <summary>The file's display name within the project.</summary>
public string Name
{
get { return UnsafeUtils.TakeAnsiString(NativeMethods.BNProjectFileGetName(this.handle)); }
}
/// <summary>Sets the file's display name.</summary>
public bool SetName(string name)
{
if (null == name)
{
throw new ArgumentNullException(nameof(name));
}
return NativeMethods.BNProjectFileSetName(this.handle, name);
}
/// <summary>The file's description.</summary>
public string Description
{
get { return UnsafeUtils.TakeAnsiString(NativeMethods.BNProjectFileGetDescription(this.handle)); }
}
/// <summary>Sets the file's description.</summary>
public bool SetDescription(string description)
{
if (null == description)
{
throw new ArgumentNullException(nameof(description));
}
return NativeMethods.BNProjectFileSetDescription(this.handle, description);
}
/// <summary>The absolute path of the file's backing content on disk.</summary>
public string PathOnDisk
{
get { return UnsafeUtils.TakeAnsiString(NativeMethods.BNProjectFileGetPathOnDisk(this.handle)); }
}
/// <summary>Gets the file's path within its project.</summary>
public string PathInProject
{
get { return UnsafeUtils.TakeUtf8String(NativeMethods.BNProjectFileGetPathInProject(this.handle)); }
}
/// <summary>Gets whether the file's backing contents exist on disk.</summary>
public bool ExistsOnDisk
{
get { return NativeMethods.BNProjectFileExistsOnDisk(this.handle); }
}
/// <summary>Gets the file's creation timestamp.</summary>
public long CreationTimestamp
{
get { return NativeMethods.BNProjectFileGetCreationTimestamp(this.handle); }
}
// --- Navigation ------------------------------------------------------
/// <summary>The project that owns this file. Mirrors Python ProjectFile.project.</summary>
public Project? Project
{
get { return Project.TakeHandle(NativeMethods.BNProjectFileGetProject(this.handle)); }
}
/// <summary>The folder containing this file, or null when it lives at the project root.</summary>
public ProjectFolder? Folder
{
get { return ProjectFolder.TakeHandle(NativeMethods.BNProjectFileGetFolder(this.handle)); }
}
/// <summary>Moves the file to another folder, or to the project root.</summary>
public bool SetFolder(ProjectFolder? folder)
{
return NativeMethods.BNProjectFileSetFolder(
this.handle,
null == folder ? IntPtr.Zero : folder.DangerousGetHandle()
);
}
/// <summary>Exports the file's contents to a destination path.</summary>
public bool Export(string destination)
{
if (null == destination)
{
throw new ArgumentNullException(nameof(destination));
}
return NativeMethods.BNProjectFileExport(this.handle, destination);
}
/// <summary>Adds another project file as a dependency.</summary>
public bool AddDependency(ProjectFile file)
{
if (null == file)
{
throw new ArgumentNullException(nameof(file));
}
return NativeMethods.BNProjectFileAddDependency(
this.handle,
file.DangerousGetHandle()
);
}
/// <summary>Removes a project file dependency.</summary>
public bool RemoveDependency(ProjectFile file)
{
if (null == file)
{
throw new ArgumentNullException(nameof(file));
}
return NativeMethods.BNProjectFileRemoveDependency(
this.handle,
file.DangerousGetHandle()
);
}
/// <summary>The project files this file depends on. Mirrors Python ProjectFile.dependencies.</summary>
public unsafe ProjectFile[] GetDependencies()
{
ulong count = 0;
IntPtr arrayPointer = NativeMethods.BNProjectFileGetDependencies(this.handle, (IntPtr)(&count));
return UnsafeUtils.TakeHandleArrayEx<ProjectFile>(
arrayPointer,
count,
ProjectFile.MustNewFromHandle,
NativeMethods.BNFreeProjectFileList
);
}
/// <summary>The project files that depend on this file. Mirrors Python ProjectFile.required_by.</summary>
public unsafe ProjectFile[] GetRequiredBy()
{
ulong count = 0;
IntPtr arrayPointer = NativeMethods.BNProjectFileGetRequiredBy(this.handle, (IntPtr)(&count));
return UnsafeUtils.TakeHandleArrayEx<ProjectFile>(
arrayPointer,
count,
ProjectFile.MustNewFromHandle,
NativeMethods.BNFreeProjectFileList
);
}
}
}