Commit | Line | Data |
---|---|---|
c72a561f | 1 | # The MIT License (MIT) |
be5a4e67 | 2 | # |
c72a561f | 3 | # Copyright (c) 2013-2017 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
be5a4e67 PP |
4 | # |
5 | # Permission is hereby granted, free of charge, to any person obtaining a copy | |
6 | # of this software and associated documentation files (the "Software"), to deal | |
7 | # in the Software without restriction, including without limitation the rights | |
8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
9 | # copies of the Software, and to permit persons to whom the Software is | |
10 | # furnished to do so, subject to the following conditions: | |
11 | # | |
12 | # The above copyright notice and this permission notice shall be included in | |
13 | # all copies or substantial portions of the Software. | |
14 | # | |
15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
c72a561f JG |
20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
21 | # THE SOFTWARE. | |
5b489212 | 22 | |
0b03f63e | 23 | |
be5a4e67 PP |
24 | class CTFStringEncoding: |
25 | """ | |
26 | CTF string encodings. | |
27 | """ | |
28 | ||
29 | #: None | |
30 | NONE = 0 | |
31 | ||
32 | #: UTF-8 | |
33 | UTF8 = 1 | |
34 | ||
35 | #: ASCII | |
36 | ASCII = 2 | |
37 | ||
38 | #: Unknown | |
39 | UNKNOWN = 3 | |
40 | ||
41 | ||
42 | # Based on the enum in ctf-writer/writer.h | |
43 | class ByteOrder: | |
44 | """ | |
45 | Byte orders. | |
46 | """ | |
47 | ||
48 | #: Native byte order | |
49 | BYTE_ORDER_NATIVE = 0 | |
50 | ||
51 | #: Little-endian | |
52 | BYTE_ORDER_LITTLE_ENDIAN = 1 | |
53 | ||
54 | #: Big-endian | |
55 | BYTE_ORDER_BIG_ENDIAN = 2 | |
56 | ||
57 | #: Network byte order (big-endian) | |
58 | BYTE_ORDER_NETWORK = 3 | |
59 | ||
60 | #: Unknown byte order | |
61 | BYTE_ORDER_UNKNOWN = 4 # Python-specific entry | |
62 | ||
63 | ||
64 | # enum equivalent, accessible constants | |
65 | # These are taken directly from ctf/events.h | |
66 | # All changes to enums must also be made here | |
67 | class CTFTypeId: | |
68 | """ | |
69 | CTF numeric type identifiers. | |
70 | """ | |
71 | ||
72 | #: Unknown type | |
73 | UNKNOWN = 0 | |
74 | ||
75 | #: Integer | |
76 | INTEGER = 1 | |
77 | ||
78 | #: Floating point number | |
79 | FLOAT = 2 | |
80 | ||
81 | #: Enumeration | |
82 | ENUM = 3 | |
83 | ||
84 | #: String | |
85 | STRING = 4 | |
86 | ||
87 | #: Structure | |
88 | STRUCT = 5 | |
89 | ||
90 | #: Untagged variant | |
91 | UNTAGGED_VARIANT = 6 | |
92 | ||
93 | #: Variant | |
94 | VARIANT = 7 | |
95 | ||
96 | #: Array | |
97 | ARRAY = 8 | |
98 | ||
99 | #: Sequence | |
100 | SEQUENCE = 9 | |
101 | ||
102 | NR_CTF_TYPES = 10 | |
103 | ||
104 | def type_name(id): | |
105 | """ | |
106 | Returns the name of the CTF numeric type identifier *id*. | |
107 | """ | |
108 | ||
109 | name = "UNKNOWN_TYPE" | |
110 | constants = [ | |
111 | attr for attr in dir(CTFTypeId) if not callable( | |
112 | getattr( | |
113 | CTFTypeId, | |
114 | attr)) and not attr.startswith("__")] | |
115 | ||
116 | for attr in constants: | |
117 | if getattr(CTFTypeId, attr) == id: | |
118 | name = attr | |
119 | break | |
120 | ||
121 | return name | |
122 | ||
123 | ||
124 | class CTFScope: | |
125 | """ | |
126 | CTF scopes. | |
127 | """ | |
128 | ||
129 | #: Packet header | |
130 | TRACE_PACKET_HEADER = 0 | |
131 | ||
132 | #: Packet context | |
133 | STREAM_PACKET_CONTEXT = 1 | |
134 | ||
135 | #: Event header | |
136 | STREAM_EVENT_HEADER = 2 | |
137 | ||
138 | #: Stream event context | |
139 | STREAM_EVENT_CONTEXT = 3 | |
140 | ||
141 | #: Event context | |
142 | EVENT_CONTEXT = 4 | |
143 | ||
144 | #: Event fields | |
145 | EVENT_FIELDS = 5 | |
146 | ||
147 | def scope_name(scope): | |
148 | """ | |
149 | Returns the name of the CTF scope *scope*. | |
150 | """ | |
151 | ||
152 | name = "UNKNOWN_SCOPE" | |
153 | constants = [ | |
154 | attr for attr in dir(CTFScope) if not callable( | |
155 | getattr( | |
156 | CTFScope, | |
157 | attr)) and not attr.startswith("__")] | |
158 | ||
159 | for attr in constants: | |
160 | if getattr(CTFScope, attr) == scope: | |
161 | name = attr | |
162 | break | |
163 | ||
164 | return name |