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 | |
be5a4e67 PP |
23 | class CTFStringEncoding: |
24 | """ | |
25 | CTF string encodings. | |
26 | """ | |
27 | ||
28 | #: None | |
29 | NONE = 0 | |
30 | ||
31 | #: UTF-8 | |
32 | UTF8 = 1 | |
33 | ||
34 | #: ASCII | |
35 | ASCII = 2 | |
36 | ||
37 | #: Unknown | |
38 | UNKNOWN = 3 | |
39 | ||
40 | ||
41 | # Based on the enum in ctf-writer/writer.h | |
42 | class ByteOrder: | |
43 | """ | |
44 | Byte orders. | |
45 | """ | |
46 | ||
47 | #: Native byte order | |
48 | BYTE_ORDER_NATIVE = 0 | |
49 | ||
50 | #: Little-endian | |
51 | BYTE_ORDER_LITTLE_ENDIAN = 1 | |
52 | ||
53 | #: Big-endian | |
54 | BYTE_ORDER_BIG_ENDIAN = 2 | |
55 | ||
56 | #: Network byte order (big-endian) | |
57 | BYTE_ORDER_NETWORK = 3 | |
58 | ||
59 | #: Unknown byte order | |
60 | BYTE_ORDER_UNKNOWN = 4 # Python-specific entry | |
61 | ||
62 | ||
63 | # enum equivalent, accessible constants | |
64 | # These are taken directly from ctf/events.h | |
65 | # All changes to enums must also be made here | |
66 | class CTFTypeId: | |
67 | """ | |
68 | CTF numeric type identifiers. | |
69 | """ | |
70 | ||
71 | #: Unknown type | |
72 | UNKNOWN = 0 | |
73 | ||
74 | #: Integer | |
75 | INTEGER = 1 | |
76 | ||
77 | #: Floating point number | |
78 | FLOAT = 2 | |
79 | ||
80 | #: Enumeration | |
81 | ENUM = 3 | |
82 | ||
83 | #: String | |
84 | STRING = 4 | |
85 | ||
86 | #: Structure | |
87 | STRUCT = 5 | |
88 | ||
89 | #: Untagged variant | |
90 | UNTAGGED_VARIANT = 6 | |
91 | ||
92 | #: Variant | |
93 | VARIANT = 7 | |
94 | ||
95 | #: Array | |
96 | ARRAY = 8 | |
97 | ||
98 | #: Sequence | |
99 | SEQUENCE = 9 | |
100 | ||
101 | NR_CTF_TYPES = 10 | |
102 | ||
103 | def type_name(id): | |
104 | """ | |
105 | Returns the name of the CTF numeric type identifier *id*. | |
106 | """ | |
107 | ||
108 | name = "UNKNOWN_TYPE" | |
109 | constants = [ | |
110 | attr for attr in dir(CTFTypeId) if not callable( | |
111 | getattr( | |
112 | CTFTypeId, | |
113 | attr)) and not attr.startswith("__")] | |
114 | ||
115 | for attr in constants: | |
116 | if getattr(CTFTypeId, attr) == id: | |
117 | name = attr | |
118 | break | |
119 | ||
120 | return name | |
121 | ||
122 | ||
123 | class CTFScope: | |
124 | """ | |
125 | CTF scopes. | |
126 | """ | |
127 | ||
128 | #: Packet header | |
129 | TRACE_PACKET_HEADER = 0 | |
130 | ||
131 | #: Packet context | |
132 | STREAM_PACKET_CONTEXT = 1 | |
133 | ||
134 | #: Event header | |
135 | STREAM_EVENT_HEADER = 2 | |
136 | ||
137 | #: Stream event context | |
138 | STREAM_EVENT_CONTEXT = 3 | |
139 | ||
140 | #: Event context | |
141 | EVENT_CONTEXT = 4 | |
142 | ||
143 | #: Event fields | |
144 | EVENT_FIELDS = 5 | |
145 | ||
146 | def scope_name(scope): | |
147 | """ | |
148 | Returns the name of the CTF scope *scope*. | |
149 | """ | |
150 | ||
151 | name = "UNKNOWN_SCOPE" | |
152 | constants = [ | |
153 | attr for attr in dir(CTFScope) if not callable( | |
154 | getattr( | |
155 | CTFScope, | |
156 | attr)) and not attr.startswith("__")] | |
157 | ||
158 | for attr in constants: | |
159 | if getattr(CTFScope, attr) == scope: | |
160 | name = attr | |
161 | break | |
162 | ||
163 | return name |