forked from G33KatWork/EFIPWN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TreePrinter.py
86 lines (72 loc) · 2.29 KB
/
TreePrinter.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
import ast
#import EFI
class EfiTreePrintVisitor(ast.NodeVisitor):
def __init__(self):
self.indentation = 0
def generic_visit(self, node):
logger.error("Unrecognized node: %s " % (type(node).__name__))
raise Exception("Unrecognized node: %s " % (type(node).__name__))
#ast.NodeVisitor.generic_visit(self, node)
def visit_EfiFirmwareImage(self, node):
for v in node.firmwareVolumes:
self.visit(v)
def visit_EfiFirmwareVolume(self, node):
print indent(str(node), self.indentation)
self.indentation += 10
for f in node.files:
self.visit(f)
self.indentation -= 10
def visit_EfiFile(self, node):
print indent(str(node), self.indentation)
self.indentation += 10
for s in node.subsections:
self.visit(s)
self.indentation -= 10
def visit_EfiGenericSection(self, node):
print indent(str(node), self.indentation)
self.indentation += 10
# for n in node.subsubsections:
# self.visit(n)
self.indentation -= 10
def visit_EfiVersionSection(self, node):
print indent(str(node), self.indentation)
self.indentation += 10
# for n in node.subsubsections:
# self.visit(n)
self.indentation -= 10
def visit_EfiGuidDefinedSection(self, node):
print indent(str(node), self.indentation)
self.indentation += 10
for n in node.Subsections:
self.visit(n)
self.indentation -= 10
def visit_EfiUserInterfaceSection(self, node):
print indent(str(node), self.indentation)
self.indentation += 10
# for n in node.subsubsections:
# self.visit(n)
self.indentation -= 10
def visit_EfiFreeformSubtypeGuidSection(self, node):
print indent(str(node), self.indentation)
self.indentation += 10
for n in node.Subsections:
self.visit(n)
self.indentation -= 10
def visit_EfiCompressedSection(self, node):
print indent(str(node), self.indentation)
self.indentation += 10
for n in node.Subsections:
self.visit(n)
self.indentation -= 10
def visit_EfiFirmwareVolumeSection(self, node):
print indent(str(node), self.indentation)
self.indentation += 10
for s in node.SubFirmware.firmwareVolumes:
self.visit(s)
self.indentation -= 10
def indent(s, i):
a = s.split("\n")
res = ""
for b in a:
res += " "*i + b + "\n"
return res