Files
vivisect-vivisect/vstruct/constants/__init__.py
T
James Gross 80de840881 Even More Syntax Cleanup (#293)
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.
2020-09-08 13:00:06 -04:00

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)