1 """
2 Unified expression helpers.
3 """
4
6 return eval(pycode, {}, locals)
7
9 """
10 An object to act as the locals dictionary for the evaluation
11 of envi expressions. You may pass in an envi.resolver.SymbolResolver
12 object to automagically use symbols in your expressions.
13 """
15 dict.__init__(self)
16 self.symobj = symobj
17
19 if self.symobj != None:
20 ret = self.symobj.getSymByName(name)
21 if ret != None: return ret
22 return dict.__getitem__(self, name)
23
25
26 - def __init__(self, memobj, symobj=None):
37
38 - def sym(self, symstr):
39 '''
40 An easy to use utility for symbols which have un-pythonic names.
41
42 Example x = sym('kernel32.??2@$$FYAPAXI@Z')
43 '''
44 return long(evaluate(symstr, self))
45
47 """
48 The expression mapbase(address) returns the base address of the
49 memory mapped area containing "address"
50 """
51 map = self.memobj.getMemoryMap(address)
52 if not map:
53 raise Exception("ERROR - un-mapped address in mapbase()")
54 return map[0]
55
57 """
58 The expression maplen(address) returns the length of the
59 memory mapped area containing "address".
60 """
61 map = self.memobj.getMemoryMap(address)
62 if not map:
63 raise Exception("ERROR - un-mapped address in maplen()")
64 return map[1]
65
67 """
68 The expression ispoi(value) returns True if the specified value
69 is a valid pointer. Otherwise, False.
70 """
71 return self.memobj.isValidPointer(addr)
72
73 - def mem(self, addr, size):
74 """
75 Read and return memory.
76
77 Example: mem(ecx, 20)
78 """
79 return self.memobj.readMemory(addr, size)
80
81 - def poi(self, address):
82 """
83 When expression contains "poi(addr)" this will return
84 the address pointed to by addr.
85 """
86 return self.memobj.readMemoryFormat(address, "P")[0]
87