-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfindAttributeVolatility.py
92 lines (70 loc) · 1.5 KB
/
findAttributeVolatility.py
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
#!/usr/bin/env python
import sys
import re
from cStringIO import StringIO
stdout = sys.stdout
found = False
first = True
entered = []
paths = []
def findRec(obj, path, name):
global found
global first
global paths
global entered
oldstdout = sys.stdout
sys.stdout = stringIO = StringIO()
try:
dt(obj)
except:
sys.stdout = oldstdout
print "Exception!!!"
return
string = stringIO.getvalue()
if "ERROR" in string:
return
lines = string.split('\n')
if "task_struct" in lines[0] and not first:
return
first = False
for i in range(1, len(lines)-1):
line = lines[i]
line = line.replace(":", " ")
newLine = re.sub(' +', ' ', line)
fields = newLine.split(' ')
#sys.stdout = stdout
#print fields
#print path
#sys.stdout = stringIO
if name in fields[1]:
#sys.stdout = stdout
found = True
#print "Name Found: " + path + "." + fields[1]
paths.append(path + "." + fields[1] + " : " + getattr(obj, fields[1]).__str__())
#sys.stdout = stringIO
if fields[1] in entered:
continue
entered.append(fields[1])
attr = getattr(obj, fields[1])
if "task_struct" in str(type(attr)):
continue
findRec(attr, path + "." + fields[1], name)
sys.stdout = oldstdout
return
def printAll():
if not found:
print "Not Found!"
else:
for el in paths:
print el
def search(obj, path, name):
global found
found = False
global first
first = True
global entered
entered = []
global paths
paths = []
findRec(obj, path, name)
printAll()