File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33using System . IO ;
44using System . Linq ;
55using System . Runtime . InteropServices ;
6+ using System . Threading ;
7+ using System . Threading . Tasks ;
68using Microsoft . Win32 . SafeHandles ;
79
810namespace 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 ) ;
You can’t perform that action at this time.
0 commit comments