Skip to content

Commit 0917550

Browse files
committed
fixes the sequence search operation
the operation was overloaded by the type of the key, however once the sequence class has been moved from the BIR module to the ADT module everything went wrong, since the type names were no longer available. The new implementation relies on the `constr` attribute to determine the constructor name. fixes [BinaryAnalysisPlatform/bap#699].
1 parent aadd388 commit 0917550

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/bap/adt.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,8 @@ def find(self,key, d=None) :
462462
If a key is an instance of Tid class, then a term with
463463
corresponding tid is returned.
464464
465-
If a key is a number, or an instance of `bil.Int' class, then
466-
a term with a matching address is returned.
465+
If a key is a number, or an instance of `bil.Int' class or is
466+
an integer, then a term with a matching address is returned.
467467
468468
Example
469469
-------
@@ -475,25 +475,26 @@ def find(self,key, d=None) :
475475
>>> main = proj.program.subs.find('main')
476476
>>> main = proj.program.subs.find(main.id)
477477
>>> main = proj.program.subs.find(main.id.name)
478+
478479
"""
479-
def by_id(t,key) : return t.id == key
480-
def by_name(t,key) :
481-
if key.startswith(('@','%')):
482-
return t.id.name == key
480+
def by_id(t, k) : return t.id.number == k
481+
def by_name(t,k) :
482+
if k.startswith(('@','%')):
483+
return t.id.name == k
483484
else:
484-
return hasattr(t,'name') and t.name == key
485-
def by_addr(t,key) :
485+
return hasattr(t, 'name') and t.name == k
486+
def by_addr(t,k) :
486487
value = t.attrs.get('address', None)
487488
if value is not None:
488489
return parse_addr(value) == key
489490

490491
test = by_addr
491492
if isinstance(key,str):
492493
test = by_name
493-
elif hasattr(key,id):
494-
key = key.id
494+
elif hasattr(key,'constr') and key.constr == 'Tid':
495+
key = key.number
495496
test = by_id
496-
elif isinstance(key,Int):
497+
elif hasattr(key,'constr') and key.constr == 'Int':
497498
key = key.value
498499
test = by_addr
499500

0 commit comments

Comments
 (0)