-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathpyfuncs.py
More file actions
135 lines (119 loc) · 4.77 KB
/
pyfuncs.py
File metadata and controls
135 lines (119 loc) · 4.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#----------------------------------------------------------------
# ---------------------------------------------------------------
# Library of useful functions for the MDbg Iron Python Extension
# ---------------------------------------------------------------
#----------------------------------------------------------------
# import regular expressions module
import re
#----------------------------------------------------
# Execute an Mdbg command.
# Parameter cmd must be a string
#----------------------------------------------------
def ExeShellCmd(cmd):
CommandBase.ExecuteCommand(cmd);
#----------------------------------------------------
# Reload all previously loaded and since modified
# python scripts.
#----------------------------------------------------
def RefreshScripts():
ExeShellCmd("pyr all");
#----------------------------------------------------
# Get the current MDbgEngine
#----------------------------------------------------
def GetDebugger():
return CommandBase.Debugger;
#----------------------------------------------------
# Get the current MDbgProcess object
#----------------------------------------------------
def CurProcess():
return GetDebugger().Processes.Active
#----------------------------------------------------
# Get the current MDbgThread object
#----------------------------------------------------
def CurThread():
return CurProcess().Threads.Active
#----------------------------------------------------
# Get the current frame.
#----------------------------------------------------
def CurFrame():
return CurThread().CurrentFrame
#----------------------------------------------------
# Get locals for the current frame.
# Returns an array of MdbgValue[]
#----------------------------------------------------
def CurLocals():
return CurFrame().Function.GetActiveLocalVars(CurFrame())
#----------------------------------------------------
# Get locals for the current frame.
# Returns an dictionary of MdbgValue[] referenced by
# variable name
#----------------------------------------------------
def CurLocalsByName():
locals = CurLocals()
localsByName = {}
for m in CurLocals():
localsByName[m.Name] = m
return localsByName
#----------------------------------------------------
# Print program variable.
# Parameter v must be a MDbgValue object OR
# a variable name string
# Calls MDbgValue.GetStringValue() with depth 0
#----------------------------------------------------
def PrintVariable(v):
if str(type(v))!="<type 'MDbgValue'>":
v = CurProcess().ResolveVariable(str(v), CurFrame());
print v.Name + " = " + v.GetStringValue(0, False) + " (" + v.TypeName + ")";
#----------------------------------------------------
# Print program variable.
# Parameter v must be a MDbgValue object OR
# a variable name string
# Parameter depth must be an integer
# Calls MDbgValue.GetStringValue() with specified depth
#----------------------------------------------------
def PrintVariable2(v, depth):
if str(type(v))!="<type 'MDbgValue'>":
v = CurProcess().ResolveVariable(str(v), CurFrame());
print v.Name + " = " + v.GetStringValue(depth, False) + " (" + v.TypeName + ")";
#----------------------------------------------------
# Print locals for the current frame.
#----------------------------------------------------
def PrintLocals():
for v in CurLocals():
PrintVariable(v);
#----------------------------------------------------
# Print the callstack
#----------------------------------------------------
def PrintStack():
i = 0
for x in CurThread().Frames:
print "%d) %s" % (i, x)
i = i + 1
print '------------'
#----------------------------------------------------
# Checks if current callstack contains given function
# Parameter function must be a string
# Returns 1 if callstack contains given function,
# 0 otherwise
#----------------------------------------------------
def StackContainsFunction(function):
searchStr = "\." + function + " \("
regexp = re.compile(searchStr, re.IGNORECASE)
for f in CurThread().Frames:
m = regexp.search(f.ToString())
if m:
return 1
return 0
#----------------------------------------------------
# Checks if the current frame is the given function.
# Parameter function must be a string
# Returns 1 if current frame is given function,
# 0 otherwise
#----------------------------------------------------
def InsideFunction(function):
searchStr = "\." + function + " \("
regexp = re.compile(searchStr, re.IGNORECASE)
m = regexp.search(CurFrame().ToString())
if m:
return 1
return 0