@@ -13,88 +13,56 @@ One of the best ways to learn a complicated API is to simply find the right exam
1313
1414## Loading Files & Databases
1515
16- ### Loading a file headlessly
16+ !!! note "Headless Usage"
17+ Headless file loading requires Binary Ninja Commercial or Enterprise. This feature is not available in the Personal edition.
1718
18- The ` load ` function is the recommended way to open a file for analysis in a headless script:
19+ ### Basic file loading
1920
2021``` python
2122from binaryninja import load
2223
23- # Basic usage - automatically runs analysis
24+ # Using context manager (recommended)
25+ with load(' /bin/ls' ) as bv:
26+ if bv is not None :
27+ print (f " { bv.arch.name} : { hex (bv.entry_point)} " )
28+
29+ # Without context manager - must close manually
2430bv = load(' /bin/ls' )
2531if bv is not None :
26- # Do something with the binary view
2732 print (f " Loaded { bv.file.filename} " )
28- print (f " Architecture: { bv.arch.name} " )
29- print (f " Entry point: { hex (bv.entry_point)} " )
30-
31- # Important: Close the file when done to prevent memory leaks
32- bv.file.close()
33+ bv.file.close() # Important: prevents memory leaks
3334```
3435
35- ### Loading a file with options
36-
37- You can customize the loading behavior by passing options:
36+ ### Loading with options
3837
3938``` python
4039from binaryninja import load
4140
42- # Load with custom options
4341bv = load(' /bin/ls' , options = {
4442 ' loader.imageBase' : 0x fffffff0000 ,
4543 ' loader.macho.processFunctionStarts' : False ,
46- ' analysis.mode' : ' basic' ,
47- ' analysis.linearSweep.autorun' : False
44+ ' analysis.mode' : ' basic'
4845})
49-
50- if bv is not None :
51- # Process the binary view
52- print (f " Loaded at base address: { hex (bv.start)} " )
53- bv.file.close()
5446```
5547
56- ### Loading a database file
57-
58- Binary Ninja database files (.bndb) can be loaded the same way as regular binaries:
48+ ### Loading a database
5949
6050``` python
6151from binaryninja import load
6252
63- # Load a saved database
53+ # .bndb files use the same API
6454bv = load(' /path/to/analysis.bndb' )
65- if bv is not None :
66- # All previous analysis is preserved
67- print (f " Loaded database with { len (bv.functions)} functions " )
68- bv.file.close()
6955```
7056
71- ### Using the context manager pattern
72-
73- The recommended way to work with Binary Ninja files is using a context manager, which automatically handles cleanup:
74-
75- ``` python
76- from binaryninja import load
77-
78- # Context manager automatically closes the file
79- with load(' /bin/ls' ) as bv:
80- if bv is not None :
81- for func in bv.functions:
82- print (f " { hex (func.start)} : { func.name} " )
83- # File is automatically closed here
84- ```
85-
86- ### Controlling analysis behavior
87-
88- By default, ` load() ` runs analysis automatically. You can disable this for faster loading:
57+ ### Controlling analysis
8958
9059``` python
9160from binaryninja import load
9261
9362# Load without running analysis
9463bv = load(' /bin/ls' , update_analysis = False )
9564if bv is not None :
96- # Manually control when analysis runs
97- bv.update_analysis_and_wait()
65+ bv.update_analysis_and_wait() # Run analysis manually
9866 bv.file.close()
9967```
10068
0 commit comments