-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdwarf_types.py
173 lines (113 loc) · 3.76 KB
/
dwarf_types.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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
__all__ = ["BaseType", "VolatileType", "ConstType", "TypeDef", "PointerType"]
__all__ += ["ArrayType", "EnumsType", "Structure", "Member", "Subroutine"]
class BaseType:
def __init__(self, name, byte_size, enconding):
self.name = name
self.byte_size = byte_size
self.enconding = enconding
def __repr__(self):
return "<BaseType @ %s %s %s>" % (
self.name, self.byte_size, self.enconding)
def __str__(self):
return self.name
class ConstType:
def __init__(self, type_ref):
self.type_ref = type_ref
@property
def byte_size(self):
return self.type_ref.byte_size
def __repr__(self):
return "<ConstType @ %s>" % self.__str__()
def __str__(self):
return "%s const" % self.type_ref
class VolatileType:
def __init__(self, type_ref):
self.type_ref = type_ref
@property
def byte_size(self):
return self.type_ref.byte_size
def __repr__(self):
return "<VolatileType @ %s>" % self.__str__()
def __str__(self):
return "%s volatile" % self.type_ref
class TypeDef:
def __init__(self, name, type_ref, decl_file, decl_line):
"""
:param type_ref A type reference offset, -1 stands void?
"""
self.name = name
self.type_ref = type_ref
self.decl_file = decl_file
self.decl_line = decl_line
@property
def byte_size(self):
return self.type_ref.byte_size
def __repr__(self):
return "<TypeDef @ %s>" % self.__str__()
def __str__(self):
return "%s" % self.name
class PointerType:
def __init__(self, type_ref, byte_size):
self.type_ref = type_ref
self.byte_size = byte_size
def __repr__(self):
return "<Pointer @ %s>" % self.__str__()
def __str__(self):
return "%s*" % self.type_ref
class ArrayType:
def __init__(self, type_ref, size):
self.type_ref = type_ref
self.size = size
@property
def byte_size(self):
return self.type_ref.byte_size * self.size
def __repr__(self):
return "<ArrayType @ %s>" % self.__str__()
def __str__(self):
return "%s[%s]" % (self.type_ref, self.size)
class EnumsType:
def __init__(self, name, byte_size, type_ref,
decl_file, decl_line):
self.name = name
self.byte_size = byte_size
self.type_ref = type_ref
self.decl_file = decl_file
self.decl_line = decl_line
self.enumerators = {}
def add_enumerator(self, name, value):
self.enumerators[name] = value
def __repr__(self):
return "<Enums @ %s>" % self.name
def __str__(self):
return "Enums %s" % self.name
class Structure:
def __init__(self, name, byte_size, decl_file, decl_line):
self.name = name
self.byte_size = byte_size
self.decl_file = decl_file
self.decl_line = decl_line
self.members = {}
def add_members(self, offset, member):
self.members[offset] = member
def __repr__(self):
return "<Structure @ %s %s>" % (self.name, self.byte_size)
def __str__(self):
return "struct %s" % self.name
class Member:
def __init__(self, name, type_ref, decl_file, decl_line):
self.name = name
self.type_ref = type_ref
self.decl_file = decl_file
self.decl_line = decl_line
def __repr__(self):
return "<Member @ name: %s type: %s>" % (
self.name, self.type_ref)
def __str__(self):
return "%s" % self.name
class Subroutine:
def __init__(self, prototyped):
self.prototyped = prototyped
def __repr__(self):
return "<Subroutine @ %s>" % self.prototyped
def __str__(self):
return self.__repr__()