3131
3232
3333class LinearDisassemblyLine :
34- def __init__ (self , line_type , func , block , contents ):
34+ def __init__ (self , line_type : LinearDisassemblyLineType , func : Optional [ _function . Function ] , block : Optional [ basicblock . BasicBlock ] , contents : _function . DisassemblyTextLine ):
3535 self .type = line_type
3636 self .function = func
3737 self .block = block
@@ -82,7 +82,7 @@ def _to_core_struct(self) -> core.BNLinearDisassemblyLine:
8282
8383
8484class LinearViewObjectIdentifier :
85- def __init__ (self , name , start = None , end = None ):
85+ def __init__ (self , name : str , start : Optional [ int ] = None , end : Optional [ int ] = None ):
8686 self ._name = name
8787 self ._start = start
8888 self ._end = end
@@ -166,7 +166,7 @@ def _from_api_object(obj):
166166
167167
168168class LinearViewObject :
169- def __init__ (self , handle , parent = None ):
169+ def __init__ (self , handle , parent : Optional [ 'LinearViewObject' ] = None ):
170170 self .handle = handle
171171 self ._parent = parent
172172
@@ -187,21 +187,21 @@ def __str__(self):
187187 return result
188188
189189 @property
190- def first_child (self ):
190+ def first_child (self ) -> Optional [ 'LinearViewObject' ] :
191191 result = core .BNGetFirstLinearViewObjectChild (self .handle )
192192 if not result :
193193 return None
194194 return LinearViewObject (result , self )
195195
196196 @property
197- def last_child (self ):
197+ def last_child (self ) -> Optional [ 'LinearViewObject' ] :
198198 result = core .BNGetLastLinearViewObjectChild (self .handle )
199199 if not result :
200200 return None
201201 return LinearViewObject (result , self )
202202
203203 @property
204- def previous (self ):
204+ def previous (self ) -> Optional [ 'LinearViewObject' ] :
205205 if self ._parent is None :
206206 return None
207207 result = core .BNGetPreviousLinearViewObjectChild (self ._parent .handle , self .handle )
@@ -210,7 +210,7 @@ def previous(self):
210210 return LinearViewObject (result , self ._parent )
211211
212212 @property
213- def next (self ):
213+ def next (self ) -> Optional [ 'LinearViewObject' ] :
214214 if self ._parent is None :
215215 return None
216216 result = core .BNGetNextLinearViewObjectChild (self ._parent .handle , self .handle )
@@ -219,26 +219,26 @@ def next(self):
219219 return LinearViewObject (result , self ._parent )
220220
221221 @property
222- def start (self ):
222+ def start (self ) -> int :
223223 return core .BNGetLinearViewObjectStart (self .handle )
224224
225225 @property
226- def end (self ):
226+ def end (self ) -> int :
227227 return core .BNGetLinearViewObjectEnd (self .handle )
228228
229229 @property
230- def parent (self ):
230+ def parent (self ) -> Optional [ 'LinearViewObject' ] :
231231 return self ._parent
232232
233233 @property
234- def identifier (self ):
234+ def identifier (self ) -> LinearViewObjectIdentifier :
235235 ident = core .BNGetLinearViewObjectIdentifier (self .handle )
236236 result = LinearViewObjectIdentifier ._from_api_object (ident )
237237 core .BNFreeLinearViewObjectIdentifier (ident )
238238 return result
239239
240240 @property
241- def cursor (self ):
241+ def cursor (self ) -> 'LinearViewCursor' :
242242 root = self
243243 while root .parent is not None :
244244 root = root .parent
@@ -254,20 +254,20 @@ def ordering_index(self):
254254 def ordering_index_total (self ):
255255 return core .BNGetLinearViewObjectOrderingIndexTotal (self .handle )
256256
257- def child_for_address (self , addr ):
257+ def child_for_address (self , addr ) -> Optional [ 'LinearViewObject' ] :
258258 result = core .BNGetLinearViewObjectChildForAddress (self .handle , addr )
259259 if not result :
260260 return None
261261 return LinearViewObject (result , self )
262262
263- def child_for_identifier (self , ident ):
263+ def child_for_identifier (self , ident ) -> Optional [ 'LinearViewObject' ] :
264264 ident_obj = ident ._to_core_struct ()
265265 result = core .BNGetLinearViewObjectChildForIdentifier (self .handle , ident_obj )
266266 if not result :
267267 return None
268268 return LinearViewObject (result , self )
269269
270- def child_for_ordering_index (self , idx ):
270+ def child_for_ordering_index (self , idx ) -> Optional [ 'LinearViewObject' ] :
271271 result = core .BNGetLinearViewObjectChildForOrderingIndex (self .handle , idx )
272272 if not result :
273273 return None
@@ -501,11 +501,13 @@ def single_function_language_representation(
501501
502502
503503class LinearViewCursor :
504- def __init__ (self , root_object , handle = None ):
504+ def __init__ (self , root_object : Optional [ LinearViewObject ] , handle = None ):
505505 if handle is not None :
506506 self .handle = handle
507- else :
507+ elif root_object is not None :
508508 self .handle = core .BNCreateLinearViewCursor (root_object .handle )
509+ else :
510+ raise TypeError ("At least one of root_object or handle must not be None" )
509511
510512 def __del__ (self ):
511513 if core is not None :
@@ -565,7 +567,7 @@ def valid(self):
565567 return not (self .before_begin or self .after_end )
566568
567569 @property
568- def current_object (self ):
570+ def current_object (self ) -> Optional [ 'LinearViewObject' ] :
569571 count = ctypes .c_ulonglong (0 )
570572 path = core .BNGetLinearViewCursorPathObjects (self .handle , count )
571573 assert path is not None , "core.BNGetLinearViewCursorPathObjects returned None"
@@ -576,7 +578,7 @@ def current_object(self):
576578 return result
577579
578580 @property
579- def path (self ):
581+ def path (self ) -> List [ LinearViewObjectIdentifier ] :
580582 count = ctypes .c_ulonglong (0 )
581583 path = core .BNGetLinearViewCursorPath (self .handle , count )
582584 assert path is not None , "core.BNGetLinearViewCursorPath returned None"
@@ -587,7 +589,7 @@ def path(self):
587589 return result
588590
589591 @property
590- def path_objects (self ):
592+ def path_objects (self ) -> List [ LinearViewObject ] :
591593 count = ctypes .c_ulonglong (0 )
592594 path = core .BNGetLinearViewCursorPathObjects (self .handle , count )
593595 assert path is not None , "core.BNGetLinearViewCursorPathObjects returned None"
@@ -632,10 +634,10 @@ def seek_to_path(self, path, addr=None):
632634 def seek_to_ordering_index (self , idx ):
633635 core .BNSeekLinearViewCursorToOrderingIndex (self .handle , idx )
634636
635- def previous (self ):
637+ def previous (self ) -> bool :
636638 return core .BNLinearViewCursorPrevious (self .handle )
637639
638- def next (self ):
640+ def next (self ) -> bool :
639641 return core .BNLinearViewCursorNext (self .handle )
640642
641643 @staticmethod
@@ -650,16 +652,16 @@ def _make_lines(lines, count: int, object) -> List['LinearDisassemblyLine']:
650652 core .BNFreeLinearDisassemblyLines (lines , count )
651653
652654 @property
653- def lines (self ):
655+ def lines (self ) -> List [ 'LinearDisassemblyLine' ] :
654656 current = self .current_object
655657 count = ctypes .c_ulonglong (0 )
656658 return LinearViewCursor ._make_lines (core .BNGetLinearViewCursorLines (self .handle , count ), count .value , current )
657659
658- def duplicate (self ):
660+ def duplicate (self ) -> 'LinearViewCursor' :
659661 return LinearViewCursor (None , handle = core .BNDuplicateLinearViewCursor (self .handle ))
660662
661663 @staticmethod
662- def compare (a , b ):
664+ def compare (a : 'LinearViewCursor' , b : 'LinearViewCursor' ):
663665 return core .BNCompareLinearViewCursors (a .handle , b .handle )
664666
665667 @property
0 commit comments