forked from SublimeCodeIntel/SublimeCodeIntel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlanginfo_binary.py
More file actions
362 lines (270 loc) · 9.53 KB
/
langinfo_binary.py
File metadata and controls
362 lines (270 loc) · 9.53 KB
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.1 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
# License for the specific language governing rights and limitations
# under the License.
#
# The Original Code is Komodo code.
#
# The Initial Developer of the Original Code is ActiveState Software Inc.
# Portions created by ActiveState Software Inc are Copyright (C) 2000-2007
# ActiveState Software Inc. All Rights Reserved.
#
# Contributor(s):
# ActiveState Software Inc
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
"""LangInfo definitions for some binary file types."""
from langinfo import LangInfo
class ELFLangInfo(LangInfo):
"""ELF-format binary (e.g. a standard executable on Linux)"""
name = "ELF"
# From '/usr/share/file/magic':
# 0 string \177ELF ELF
magic_numbers = [(0, 'string', '\177ELF')]
class ArchiveLibLangInfo(LangInfo):
"""Archive library (ar)"""
name = "ar"
exts = [".a"]
magic_numbers = [(0, 'string', '!<arch>')]
class MachOUniversalLangInfo(LangInfo):
name = "Mach-O universal"
# See '/usr/share/file/magic' for the full details on collision
# between compiled Java class data and Mach-O universal binaries and
# the hack to distinguish them.
# 0 belong 0xcafebabe
# TODO: check with a 64-bit Mach-O universal
magic_numbers = [(0, '>L', int('0xcafebabe', 16))]
class MachOLangInfo(LangInfo):
name = "Mach-O"
# From '/usr/share/file/magic':
# 0 lelong&0xfffffffe 0xfeedface Mach-O
# 0 belong&0xfffffffe 0xfeedface Mach-O
# Note: We are not current handling the '&0xfffffffe'.
#
# TODO: check with a 64-bit Mach-O
magic_numbers = [(0, '<L', int('0xfeedface', 16)),
(0, '>L', int('0xfeedface', 16))]
class WindowsExeLangInfo(LangInfo):
name = "Windows executable"
exts = [".exe", ".dll"]
# From '/usr/share/file/magic':
# 0 string MZ MS-DOS executable (EXE)
magic_numbers = [(0, "string", "MZ")]
class CompiledJavaClassLangInfo(LangInfo):
name = "compiled Java class"
exts = [".class"]
# See MachOUniversalLangInfo above. There is a collision in the
# magic number of Mach-O universal binaries and Java .class files.
# For now we rely on the '.class' extension to properly identify
# before magic number checking is done.
magic_numbers = None
class ZipLangInfo(LangInfo):
name = "Zip archive"
exts = [".zip"]
magic_numbers = [(0, "string", "PK\003\004")]
class GZipLangInfo(LangInfo):
name = "gzip archive"
exts = [".gz", ".tgz"]
magic_numbers = [(0, "string", "\037\213")]
class BZip2LangInfo(LangInfo):
name = "bzip2 compressed data"
exts = [".bz2"]
magic_numbers = [(0, "string", "BZh")]
class MSILangInfo(LangInfo):
"""Microsoft Installer Package"""
name = "MSI"
exts = [".msi"]
class JarLangInfo(ZipLangInfo):
name = "Jar archive"
exts = [".jar"]
class IcoLangInfo(LangInfo):
name = "Windows icon"
exts = [".ico"]
class IcnsLangInfo(LangInfo):
name = "Mac icon"
exts = [".icns"]
class XPMLangInfo(LangInfo):
name = "XPM"
exts = [".xpm"]
magic_numbers = [(0, "string", "/* XPM */")]
class PSDLangInfo(LangInfo):
name = "Adobe Photoshop Document"
exts = [".psd"]
magic_numbers = [(0, "string", "8BPS")]
class PNGLangInfo(LangInfo):
name = "PNG"
exts = [".png"]
magic_numbers = [(0, "string", "\x89PNG")]
class GIFLangInfo(LangInfo):
name = "GIF"
exts = [".gif"]
magic_numbers = [(0, "string", "GIF8")]
class JPEGLangInfo(LangInfo):
name = "JPEG"
exts = [".jpg", ".jpeg"]
# From '/usr/share/file/magic':
# 0 beshort 0xffd8 JPEG image data
magic_numbers = [(0, ">H", int("0xffd8", 16))]
class BMPLangInfo(LangInfo):
name = "Bitmap image"
exts = [".bmp"]
magic_numbers = [(0, "string", "BM")]
class TIFFLangInfo(LangInfo):
"""TIFF image format"""
name = "TIFF"
exts = [".tiff", ".tif"]
magic_numbers = [
(0, "string", "MM\x00\x2a"), # TIFF image data, big-endian
(0, "string", "II\x2a\x00"), # TIFF image data, little-endian
]
class DSStoreLangInfo(LangInfo):
"""Mac OS X filesystem directory metadata files."""
name = "DSStore"
filename_patterns = [".DS_Store"]
class BOMLangInfo(LangInfo):
"""Mac OS X/BSD 'Bill of Materials' file."""
name = "BOM"
exts = [".bom"]
magic_numbers = [(0, "string", "BOMStore")]
class PDFLangInfo(LangInfo):
name = "PDF"
exts = [".pdf"]
class RIFFLangInfo(LangInfo):
"""Resource Interchange File Format -- a generic meta-format for
storing data in tagged chunks.
http://en.wikipedia.org/wiki/RIFF_(File_format)
"""
name = "RIFF"
magic_numbers = [
(0, "string", "RIFX"), # RIFF (big-endian) data
(0, "string", "RIFF"), # RIFF (little-endian) data
]
class WAVLangInfo(LangInfo):
"""Waveform (WAVE) Audio format"""
name = "WAV"
conforms_to_bases = ["RIFF"]
exts = [".wav"]
class AVILangInfo(LangInfo):
"""Audio Video Interleave"""
name = "AVI"
conforms_to_bases = ["RIFF"]
exts = [".avi"]
class MacHelpIndexLangInfo(LangInfo):
"""Mac OS X Help Index"""
name = "Mac Help Index"
exts = [".helpindex"]
class AppleBinaryPListLangInfo(LangInfo):
name = "Apple Binary Property List"
magic_numbers = [(0, "string", "bplist00")]
class MacOSXDiskImageLangInfo(LangInfo):
name = "Mac OS X Disk Image"
exts = [".dmg"]
class OggLangInfo(LangInfo):
name = "Ogg data"
exts = [".ogg"]
magic_numbers = [(0, "string", "OggS")]
class FlashVideoLangInfo(LangInfo):
"""Macromedia Flash FLV Video File Format
http://www.digitalpreservation.gov/formats/fdd/fdd000131.shtml
"""
name = "Flash Video"
exts = [".flv"]
magic_numbers = [(0, "string", "FLV")]
class FlashSWFLangInfo(LangInfo):
"""Macromedia Flash SWF File Format
http://www.digitalpreservation.gov/formats/fdd/fdd000248.shtml
"""
name = "Flash SWF"
exts = [".swf"]
magic_numbers = [
(0, "string", "FWS"), # uncompressed
(0, "string", "CWS"), # compressed
]
class MP3LangInfo(LangInfo):
"""MPEG 1.0 Layer 3 audio encoding"""
name = "MP3"
exts = [".mp3"]
magic_numbers = [
(0, "string", "ID3"), # MP3 file with ID3 version 2.
]
class MPEGLangInfo(LangInfo):
"""MPEG video"""
name = "MPEG"
exts = [".mpg", ".mpeg"]
magic_numbers = [
(0, '>L', int('0x000001b3', 16)), # belong; MPEG video stream data
(0, '>L', int('0x000001ba', 16)), # belong; MPEG system stream data
]
class AACLangInfo(LangInfo):
"""MPEG-4 Advanced Audio Coding file"""
name = "AAC"
exts = [".m4a"]
magic_numbers = [
(16, "string", "M4A"),
]
class QuickTimeMovieLangInfo(LangInfo):
"""Apple QuickTime movie"""
name = "QuickTime Movie"
exts = [".mov"]
# Note: Excluding these checks as an optimization and to avoid possible
# false positives.
# magic_numbers = [
# (4, "string", "moov"),
# (4, "string", "mdat"),
# (4, "string", "ftyp"),
# (4, "string", "free"),
# (4, "string", "junk"),
# (4, "string", "pnot"),
# (4, "string", "skip"),
# (4, "string", "wide"),
# (4, "string", "pict"),
#]
class WindowsThumbnailCacheLangInfo(LangInfo):
"""Microsoft Windows directory thumbnail cache."""
name = "Windows thumbnail cache"
filename_patterns = ["Thumbs.db"]
class GettextMOLangInfo(LangInfo):
"""GNU Gettext message catalog
http://www.gnu.org/software/gettext/manual/gettext.html#MO-Files
"""
name = "GNU message catalog"
exts = [".mo"]
magic_numbers = [
(0, "string", "\336\22\4\225"), # GNU message catalog (little endian)
(0, "string", "\225\4\22\336"), # GNU message catalog (big endian),
]
class MSOfficeDocumentLangInfo(LangInfo):
name = "MS Office Document"
magic_numbers = [
(0, "string", "\376\067\0\043"),
(0, "string", "\320\317\021\340\241\261\032\341"),
(0, "string", "\333\245-\0\0\0"),
]
class ExcelDocumentLangInfo(MSOfficeDocumentLangInfo):
name = "MS Excel Document"
exts = [".xls"]
class MSWordDocumentLangInfo(MSOfficeDocumentLangInfo):
name = "MS Word Document"
# TODO: consider extended 'specialization' facility to look at ext as well.
# Can cause false positives for, e.g., a text document that uses '.doc'.
# exts = [".doc"]