Skip to content

Commit

Permalink
Merge pull request #6 from BinaryAnalysisPlatform/fix-tid-search
Browse files Browse the repository at this point in the history
Fix tid search
  • Loading branch information
ivg authored Sep 15, 2017
2 parents 688cf83 + 0917550 commit 9ade019
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup (
name = 'bap',
version = '1.0.0',
version = '1.1.0',
description = 'Python bindings to Binary Analysis Platform (BAP)',
author = 'BAP Team',
url = 'https://github.com/BinaryAnalysisPlatform/bap-python',
Expand Down
22 changes: 12 additions & 10 deletions src/bap/adt.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,8 @@ def find(self,key, d=None) :
If a key is an instance of Tid class, then a term with
corresponding tid is returned.
If a key is a number, or an instance of `bil.Int' class, then
a term with a matching address is returned.
If a key is a number, or an instance of `bil.Int' class or is
an integer, then a term with a matching address is returned.
Example
-------
Expand All @@ -475,24 +475,26 @@ def find(self,key, d=None) :
>>> main = proj.program.subs.find('main')
>>> main = proj.program.subs.find(main.id)
>>> main = proj.program.subs.find(main.id.name)
"""
def by_id(t,key) : return t.id == key
def by_name(t,key) :
if key.startswith(('@','%')):
return t.id.name == key
def by_id(t, k) : return t.id.number == k
def by_name(t,k) :
if k.startswith(('@','%')):
return t.id.name == k
else:
return hasattr(t,'name') and t.name == key
def by_addr(t,key) :
return hasattr(t, 'name') and t.name == k
def by_addr(t,k) :
value = t.attrs.get('address', None)
if value is not None:
return parse_addr(value) == key

test = by_addr
if isinstance(key,str):
test = by_name
elif isinstance(key,Tid):
elif hasattr(key,'constr') and key.constr == 'Tid':
key = key.number
test = by_id
elif isinstance(key,Int):
elif hasattr(key,'constr') and key.constr == 'Int':
key = key.value
test = by_addr

Expand Down

0 comments on commit 9ade019

Please sign in to comment.