Skip to content

Commit d5f567b

Browse files
committed
feat: LoadFileAsync
1 parent a024d5c commit d5f567b

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

Handle/BNBinaryView.cs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using System.IO;
44
using System.Linq;
55
using System.Runtime.InteropServices;
6+
using System.Threading;
7+
using System.Threading.Tasks;
68
using Microsoft.Win32.SafeHandles;
79

810
namespace BinaryNinja
@@ -182,6 +184,63 @@ public ulong Length
182184
);
183185
}
184186

187+
public static Task<BinaryView?> LoadFileAsync(
188+
string filename ,
189+
bool updateAnalysis = false ,
190+
string options = "",
191+
CancellationToken? cancellationToken = null
192+
)
193+
{
194+
return Task.Run(() =>
195+
{
196+
bool cancelled = false;
197+
198+
ProgressDelegate progress = (param2 , param3) =>
199+
{
200+
if (null != cancellationToken)
201+
{
202+
if (cancellationToken.GetValueOrDefault().IsCancellationRequested)
203+
{
204+
cancelled = true;
205+
206+
return false;
207+
}
208+
}
209+
210+
return true;
211+
};
212+
213+
if (cancelled)
214+
{
215+
return null;
216+
}
217+
218+
BinaryView? view = BinaryView.TakeHandle(
219+
NativeMethods.BNLoadFilename(
220+
filename ,
221+
updateAnalysis ,
222+
options ,
223+
Marshal.GetFunctionPointerForDelegate<NativeDelegates.BNProgressFunction>(
224+
UnsafeUtils.WrapProgressDelegate(progress)) ,
225+
IntPtr.Zero
226+
)
227+
);
228+
229+
if (null == view)
230+
{
231+
return null;
232+
}
233+
234+
if (cancelled && ( null != cancellationToken) )
235+
{
236+
cancellationToken.GetValueOrDefault().ThrowIfCancellationRequested();
237+
}
238+
239+
return view;
240+
}
241+
);
242+
}
243+
185244
public static BinaryView? OpenExisting(string filename , ProgressDelegate? progress = null)
186245
{
187246
FileMetadata file = new FileMetadata(filename);

0 commit comments

Comments
 (0)