mirror of
https://github.com/vivisect/vivisect
synced 2026-06-08 18:04:23 +00:00
80de840881
A lot of cleanup things in prep for a python 3 transition. Getting rid of the old exception syntax, converting prints over to logging, cutting random scraps of code to be proper unit tests, cut away some older bits of code, etc. This still works in python2. It's just a lot of tidying up. There are no major functionality changes.
37 lines
940 B
Python
37 lines
940 B
Python
|
|
class VSConstResolver:
|
|
def __init__(self):
|
|
self.rev_lookup = {}
|
|
self.const_lookup = {}
|
|
|
|
def clearAll(self):
|
|
self.rev_lookup = {}
|
|
self.const_lookup = {}
|
|
|
|
def addModule(self, mod):
|
|
for name in dir(mod):
|
|
val = getattr(mod, name)
|
|
if type(val) not in (int, long):
|
|
continue
|
|
|
|
# First lets add the "reverse" lookup
|
|
revs = self.rev_lookup.get(val)
|
|
if revs is None:
|
|
revs = []
|
|
self.rev_lookup[val] = revs
|
|
revs.append(name)
|
|
|
|
# Now the forward....
|
|
self.const_lookup[name] = val
|
|
|
|
def constLookup(self, name):
|
|
return self.const_lookup.get(name)
|
|
|
|
def revLookup(self, const):
|
|
'''
|
|
Lookup the possible names of a constant based on
|
|
modules added with constAddModule()
|
|
'''
|
|
return self.rev_lookup.get(const)
|
|
|