@@ -479,6 +479,31 @@ def _to_core_struct(self) -> core.BNValueLocationComponent:
479479 struct .returnedPointer = self .returned_pointer .to_BNVariable ()
480480 return struct
481481
482+ def to_string (self , arch : Optional ['architecture.Architecture' ]):
483+ if arch is None :
484+ if isinstance (self .var , variable .ArchitectureVariable ):
485+ arch = self .var .arch
486+ elif isinstance (self .var , variable .Variable ):
487+ arch = self .var .function .arch
488+ if arch is None :
489+ if self .indirect :
490+ indirect = " indirect"
491+ else :
492+ indirect = ""
493+ if self .returned_pointer is None :
494+ ret_ptr = ""
495+ else :
496+ ret_ptr = f" returned ptr { repr (self .returned_pointer )} "
497+ return f"{ repr (self .var )} offset { hex (self .offset )} size { repr (self .size )} { indirect } { ret_ptr } "
498+ struct = self ._to_core_struct ()
499+ return core .BNValueLocationComponentToString (struct , arch .handle )
500+
501+ def __str__ (self ):
502+ return self .to_string (None )
503+
504+ def __repr__ (self ):
505+ return f"<component { self .to_string (None )} >"
506+
482507
483508@dataclass
484509class ValueLocation :
@@ -503,6 +528,46 @@ def _to_core_struct(self) -> core.BNValueLocation:
503528 def with_confidence (self , confidence : int ) -> 'ValueLocationWithConfidence' :
504529 return ValueLocationWithConfidence (self , confidence )
505530
531+ def variable_for_parameter (self , idx : int ) -> Optional ['variable.CoreVariable' ]:
532+ struct = self ._to_core_struct ()
533+ var = core .BNVariable ()
534+ if core .BNGetValueLocationVariableForParameter (struct , var , idx ):
535+ return variable .CoreVariable .from_BNVariable (var )
536+ return None
537+
538+ @staticmethod
539+ def parse (string : str , arch : 'architecture.Architecture' ) -> 'ValueLocation' :
540+ struct = core .BNValueLocation ()
541+ error = ctypes .c_char_p ()
542+ if not core .BNParseValueLocation (string , arch .handle , struct , error ):
543+ assert error .value is not None , "core.BNParseValueLocation returned 'error' set to None"
544+ error_str = error .value .decode ("utf-8" )
545+ core .free_string (error )
546+ raise SyntaxError (error_str )
547+ result = ValueLocation ._from_core_struct (struct , arch )
548+ core .BNFreeValueLocation (struct )
549+ return result
550+
551+ def to_string (self , arch : Optional ['architecture.Architecture' ]):
552+ if arch is None :
553+ for component in self .components :
554+ if isinstance (component .var , variable .ArchitectureVariable ):
555+ arch = component .var .arch
556+ break
557+ if isinstance (component .var , variable .Variable ):
558+ arch = component .var .function .arch
559+ break
560+ if arch is None :
561+ return repr (self .components )
562+ struct = self ._to_core_struct ()
563+ return core .BNValueLocationToString (struct , arch .handle )
564+
565+ def __str__ (self ):
566+ return self .to_string (None )
567+
568+ def __repr__ (self ):
569+ return f"<value location { self .to_string (None )} >"
570+
506571
507572@dataclass
508573class ValueLocationWithConfidence :
@@ -519,6 +584,9 @@ def from_optional_location(location: OptionalLocation) -> Optional['ValueLocatio
519584 return ValueLocation ([ValueLocationComponent (location )]).with_confidence (core .max_confidence )
520585 return None
521586
587+ def __repr__ (self ):
588+ return f"<value location { self .location .to_string (None )} confidence { self .confidence } >"
589+
522590
523591@dataclass
524592class ReturnValue :
@@ -570,7 +638,7 @@ def __init__(self, type: SomeType, name: str = "", location: OptionalLocation =
570638
571639 def __repr__ (self ):
572640 ic = self .type .immutable_copy ()
573- if self .location is not None :
641+ if ( self .location is not None ) and ( str ( self . location ) != self . name ) :
574642 return f"{ ic .get_string_before_name ()} { self .name } { ic .get_string_after_name ()} @ { self .location } "
575643 return f"{ ic .get_string_before_name ()} { self .name } { ic .get_string_after_name ()} "
576644
0 commit comments