Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-doc
Path: blob/main/website/static/security/patches/EN-15:06/file-10.1.patch
18096 views
1
Index: contrib/file/ChangeLog
2
===================================================================
3
--- contrib/file/ChangeLog (revision 284174)
4
+++ contrib/file/ChangeLog (working copy)
5
@@ -1,3 +1,97 @@
6
+2015-01-02 15:15 Christos Zoulas <[email protected]>
7
+
8
+ * release 5.22
9
+
10
+2015-01-01 12:01 Christos Zoulas <[email protected]>
11
+
12
+ * add indirect relative for TIFF/Exif
13
+
14
+2014-12-16 18:10 Christos Zoulas <[email protected]>
15
+
16
+ * restructure elf note printing to avoid repeated messages
17
+ * add note limit, suggested by Alexander Cherepanov
18
+
19
+2014-12-16 16:53 Christos Zoulas <[email protected]>
20
+
21
+ * Bail out on partial pread()'s (Alexander Cherepanov)
22
+ * Fix incorrect bounds check in file_printable (Alexander Cherepanov)
23
+
24
+2014-12-11 20:01 Christos Zoulas <[email protected]>
25
+
26
+ * PR/405: ignore SIGPIPE from uncompress programs
27
+ * change printable -> file_printable and use it in
28
+ more places for safety
29
+ * in ELF, instead of "(uses dynamic libraries)" when PT_INTERP
30
+ is present print the interpreter name.
31
+
32
+2014-12-10 20:01 Christos Zoulas <[email protected]>
33
+
34
+ * release 5.21
35
+
36
+2014-11-27 18:40 Christos Zoulas <[email protected]>
37
+
38
+ * Allow setting more parameters from the command line.
39
+ * Split name/use and indirect magic recursion limits.
40
+
41
+2014-11-27 11:12 Christos Zoulas <[email protected]>
42
+
43
+ * Adjust ELF parameters and the default recursion
44
+ level.
45
+ * Allow setting the recursion level dynamically.
46
+
47
+2014-11-24 8:55 Christos Zoulas <[email protected]>
48
+
49
+ * The following fixes resulted from Thomas Jarosch's fuzzing
50
+ tests that revealed severe performance issues on pathological
51
+ input:
52
+ - limit number of elf program and sections processing
53
+ - abort elf note processing quickly
54
+ - reduce the number of recursion levels from 20 to 10
55
+ - preserve error messages in indirect magic handling
56
+
57
+ This is tracked as CVE-2014-8116 and CVE-2014-8117
58
+
59
+2014-11-12 10:30 Christos Zoulas <[email protected]>
60
+
61
+ * fix bogus free in the user buffer case.
62
+
63
+2014-11-11 12:35 Christos Zoulas <[email protected]>
64
+
65
+ * fix out of bounds read for pascal strings
66
+ * fix memory leak (not freeing the head of each mlist)
67
+
68
+2014-11-07 10:25 Christos Zoulas <[email protected]>
69
+
70
+ * When printing strings from a file, convert them to printable
71
+ on a byte by byte basis, so that we don't get issues with
72
+ locale's trying to interpret random byte streams as UTF-8 and
73
+ having printf error out with EILSEQ.
74
+
75
+2014-10-17 11:48 Christos Zoulas <[email protected]>
76
+
77
+ * fix bounds in note reading (Francisco Alonso / Red Hat)
78
+
79
+2014-10-11 15:02 Christos Zoulas <[email protected]>
80
+
81
+ * fix autoconf glue for setlocale and locale_t; some OS's
82
+ have locale_t in xlocale.h
83
+
84
+2014-10-10 15:01 Christos Zoulas <[email protected]>
85
+
86
+ * release 5.20
87
+
88
+2014-08-17 10:01 Christos Zoulas <[email protected]>
89
+
90
+ * recognize encrypted CDF documents
91
+
92
+2014-08-04 9:18 Christos Zoulas <[email protected]>
93
+
94
+ * add magic_load_buffers from Brooks Davis
95
+
96
+2014-07-24 16:40 Christos Zoulas <[email protected]>
97
+
98
+ * add thumbs.db support
99
+
100
2014-06-12 12:28 Christos Zoulas <[email protected]>
101
102
* release 5.19
103
Index: contrib/file/README
104
===================================================================
105
--- contrib/file/README (revision 284174)
106
+++ contrib/file/README (working copy)
107
@@ -1,6 +1,6 @@
108
## README for file(1) Command ##
109
110
- @(#) $File: README,v 1.48 2014/03/07 13:55:30 christos Exp $
111
+ @(#) $File: README,v 1.49 2015/01/02 20:23:04 christos Exp $
112
113
Mailing List: [email protected]
114
Mailing List archives: http://mx.gw.com/pipermail/file/
115
@@ -25,8 +25,8 @@ A public read-only git repository of the same sour
116
117
https://github.com/file/file
118
119
-The major changes for 5.x are CDF file parsing, indirect magic, and
120
-overhaul in mime and ascii encoding handling.
121
+The major changes for 5.x are CDF file parsing, indirect magic, name/use
122
+(recursion) and overhaul in mime and ascii encoding handling.
123
124
The major feature of 4.x is the refactoring of the code into a library,
125
and the re-write of the file command in terms of that library. The library
126
@@ -67,33 +67,41 @@ in magic(5) format please, to the maintainer, Chri
127
COPYING - read this first.
128
README - read this second (you are currently reading this file).
129
INSTALL - read on how to install
130
-
131
src/apprentice.c - parses /etc/magic to learn magic
132
+src/asctime_r.c - replacement for OS's that don't have it.
133
src/apptype.c - used for OS/2 specific application type magic
134
src/asprintf.c - replacement for OS's that don't have it.
135
src/ascmagic.c - third & last set of tests, based on hardwired assumptions.
136
-src/asctime_r.c - for systems that don't have it.
137
-src/asprintf.c - for systems that don't have it.
138
-src/cdf.c - parser for Microsoft Compound Document Files
139
+src/asctime_r.c - replacement for OS's that don't have it.
140
+src/asprintf.c - replacement for OS's that don't have it.
141
+src/cdf.[ch] - parser for Microsoft Compound Document Files
142
src/cdf_time.c - time converter for CDF.
143
src/compress.c - handles decompressing files to look inside.
144
-src/ctime_r.c - for systems that don't have it.
145
+src/ctime_r.c - replacement for OS's that don't have it.
146
+src/elfclass.h - common code for elf 32/64.
147
src/encoding.c - handles unicode encodings
148
src/file.c - the main program
149
src/file.h - header file
150
+src/file_opts.h - list of options
151
+src/fmtcheck.c - replacement for OS's that don't have it.
152
src/fsmagic.c - first set of tests the program runs, based on filesystem info
153
src/funcs.c - utilility functions
154
-src/getopt_long.c - for systems that don't have it.
155
-src/getline.c - for systems that don't have it.
156
+src/getline.c - replacement for OS's that don't have it.
157
+src/getopt_long.c - replacement for OS's that don't have it.
158
src/is_tar.c, tar.h - knows about tarchives (courtesy John Gilmore).
159
src/names.h - header file for ascmagic.c
160
+src/magic.h.in - source file for magic.h
161
src/magic.c - the libmagic api
162
+src/pread.c - replacement for OS's that don't have it.
163
src/print.c - print results, errors, warnings.
164
src/readcdf.c - CDF wrapper.
165
src/readelf.[ch] - Stand-alone elf parsing code.
166
src/softmagic.c - 2nd set of tests, based on /etc/magic
167
-src/strlcat.c - for systems that don't have it.
168
-src/strlcpy.c - for systems that don't have it.
169
+src/mygetopt.h - replacement for OS's that don't have it.
170
+src/strcasestr.c - replacement for OS's that don't have it.
171
+src/strlcat.c - replacement for OS's that don't have it.
172
+src/strlcpy.c - replacement for OS's that don't have it.
173
+src/tar.h - tar file definitions
174
src/vasprintf.c - for systems that don't have it.
175
doc/file.man - man page for the command
176
doc/magic.man - man page for the magic file, courtesy Guy Harris.
177
Index: contrib/file/TODO
178
===================================================================
179
--- contrib/file/TODO (revision 284174)
180
+++ contrib/file/TODO (working copy)
181
@@ -15,3 +15,5 @@ small amount of C is needed (because fast executio
182
required for soft magic, not the more detailed information given by
183
hard-wired routines). In this regard, note that hplip, which is
184
BSD-licensed, has a magic reimplementation in Python.
185
+
186
+Read the kerberos magic entry for more ideas.
187
Index: contrib/file/config.h.in
188
===================================================================
189
--- contrib/file/config.h.in (revision 284174)
190
+++ contrib/file/config.h.in (working copy)
191
@@ -44,6 +44,9 @@
192
/* Define to 1 if you have the `fork' function. */
193
#undef HAVE_FORK
194
195
+/* Define to 1 if you have the `freelocale' function. */
196
+#undef HAVE_FREELOCALE
197
+
198
/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */
199
#undef HAVE_FSEEKO
200
201
@@ -95,9 +98,15 @@
202
/* Define to 1 if you have a working `mmap' system call. */
203
#undef HAVE_MMAP
204
205
+/* Define to 1 if you have the `newlocale' function. */
206
+#undef HAVE_NEWLOCALE
207
+
208
/* Define to 1 if you have the `pread' function. */
209
#undef HAVE_PREAD
210
211
+/* Define to 1 if you have the `setlocale' function. */
212
+#undef HAVE_SETLOCALE
213
+
214
/* Define to 1 if you have the <stddef.h> header file. */
215
#undef HAVE_STDDEF_H
216
217
@@ -182,6 +191,9 @@
218
/* Define to 1 if you have the <unistd.h> header file. */
219
#undef HAVE_UNISTD_H
220
221
+/* Define to 1 if you have the `uselocale' function. */
222
+#undef HAVE_USELOCALE
223
+
224
/* Define to 1 if you have the `utime' function. */
225
#undef HAVE_UTIME
226
227
@@ -219,6 +231,9 @@
228
/* Define to 1 if `vfork' works. */
229
#undef HAVE_WORKING_VFORK
230
231
+/* Define to 1 if you have the <xlocale.h> header file. */
232
+#undef HAVE_XLOCALE_H
233
+
234
/* Define to 1 if you have the <zlib.h> header file. */
235
#undef HAVE_ZLIB_H
236
237
Index: contrib/file/configure
238
===================================================================
239
--- contrib/file/configure (revision 284174)
240
+++ contrib/file/configure (working copy)
241
@@ -1,6 +1,6 @@
242
#! /bin/sh
243
# Guess values for system-dependent variables and create Makefiles.
244
-# Generated by GNU Autoconf 2.69 for file 5.19.
245
+# Generated by GNU Autoconf 2.69 for file 5.22.
246
#
247
# Report bugs to <[email protected]>.
248
#
249
@@ -590,8 +590,8 @@ MAKEFLAGS=
250
# Identity of this package.
251
PACKAGE_NAME='file'
252
PACKAGE_TARNAME='file'
253
-PACKAGE_VERSION='5.19'
254
-PACKAGE_STRING='file 5.19'
255
+PACKAGE_VERSION='5.22'
256
+PACKAGE_STRING='file 5.22'
257
PACKAGE_BUGREPORT='[email protected]'
258
PACKAGE_URL=''
259
260
@@ -1327,7 +1327,7 @@ if test "$ac_init_help" = "long"; then
261
# Omit some internal or obsolete options to make the list less imposing.
262
# This message is too long to be a string in the A/UX 3.1 sh.
263
cat <<_ACEOF
264
-\`configure' configures file 5.19 to adapt to many kinds of systems.
265
+\`configure' configures file 5.22 to adapt to many kinds of systems.
266
267
Usage: $0 [OPTION]... [VAR=VALUE]...
268
269
@@ -1397,7 +1397,7 @@ fi
270
271
if test -n "$ac_init_help"; then
272
case $ac_init_help in
273
- short | recursive ) echo "Configuration of file 5.19:";;
274
+ short | recursive ) echo "Configuration of file 5.22:";;
275
esac
276
cat <<\_ACEOF
277
278
@@ -1507,7 +1507,7 @@ fi
279
test -n "$ac_init_help" && exit $ac_status
280
if $ac_init_version; then
281
cat <<\_ACEOF
282
-file configure 5.19
283
+file configure 5.22
284
generated by GNU Autoconf 2.69
285
286
Copyright (C) 2012 Free Software Foundation, Inc.
287
@@ -2163,7 +2163,7 @@ cat >config.log <<_ACEOF
288
This file contains any messages produced by compilers while
289
running configure, to aid debugging if configure makes a mistake.
290
291
-It was created by file $as_me 5.19, which was
292
+It was created by file $as_me 5.22, which was
293
generated by GNU Autoconf 2.69. Invocation command line was
294
295
$ $0 $@
296
@@ -3029,7 +3029,7 @@ fi
297
298
# Define the identity of the package.
299
PACKAGE='file'
300
- VERSION='5.19'
301
+ VERSION='5.22'
302
303
304
cat >>confdefs.h <<_ACEOF
305
@@ -12785,7 +12785,7 @@ fi
306
307
done
308
309
-for ac_header in getopt.h err.h
310
+for ac_header in getopt.h err.h xlocale.h
311
do :
312
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
313
ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
314
@@ -14191,7 +14191,7 @@ fi
315
fi
316
317
318
-for ac_func in strerror strndup strtoul mkstemp mkostemp utimes utime wcwidth strtof
319
+for ac_func in strerror strndup strtoul mkstemp mkostemp utimes utime wcwidth strtof newlocale uselocale freelocale setlocale
320
do :
321
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
322
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
323
@@ -14998,7 +14998,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
324
# report actual input values of CONFIG_FILES etc. instead of their
325
# values after options handling.
326
ac_log="
327
-This file was extended by file $as_me 5.19, which was
328
+This file was extended by file $as_me 5.22, which was
329
generated by GNU Autoconf 2.69. Invocation command line was
330
331
CONFIG_FILES = $CONFIG_FILES
332
@@ -15064,7 +15064,7 @@ _ACEOF
333
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
334
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
335
ac_cs_version="\\
336
-file config.status 5.19
337
+file config.status 5.22
338
configured by $0, generated by GNU Autoconf 2.69,
339
with options \\"\$ac_cs_config\\"
340
341
Index: contrib/file/configure.ac
342
===================================================================
343
--- contrib/file/configure.ac (revision 284174)
344
+++ contrib/file/configure.ac (working copy)
345
@@ -1,5 +1,5 @@
346
dnl Process this file with autoconf to produce a configure script.
347
-AC_INIT([file],[5.19],[[email protected]])
348
+AC_INIT([file],[5.22],[[email protected]])
349
AM_INIT_AUTOMAKE([subdir-objects foreign])
350
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
351
352
@@ -82,7 +82,7 @@ AC_HEADER_MAJOR
353
AC_HEADER_SYS_WAIT
354
AC_CHECK_HEADERS(stdint.h fcntl.h locale.h stdint.h inttypes.h unistd.h)
355
AC_CHECK_HEADERS(stddef.h utime.h wchar.h wctype.h limits.h)
356
-AC_CHECK_HEADERS(getopt.h err.h)
357
+AC_CHECK_HEADERS(getopt.h err.h xlocale.h)
358
AC_CHECK_HEADERS(sys/mman.h sys/stat.h sys/types.h sys/utime.h sys/time.h)
359
AC_CHECK_HEADERS(zlib.h)
360
361
@@ -138,7 +138,7 @@ else
362
fi])
363
364
dnl Checks for functions
365
-AC_CHECK_FUNCS(strerror strndup strtoul mkstemp mkostemp utimes utime wcwidth strtof)
366
+AC_CHECK_FUNCS(strerror strndup strtoul mkstemp mkostemp utimes utime wcwidth strtof newlocale uselocale freelocale setlocale)
367
368
dnl Provide implementation of some required functions if necessary
369
AC_REPLACE_FUNCS(getopt_long asprintf vasprintf strlcpy strlcat getline ctime_r asctime_r pread strcasestr fmtcheck)
370
Index: contrib/file/doc/file.man
371
===================================================================
372
--- contrib/file/doc/file.man (revision 284174)
373
+++ contrib/file/doc/file.man (working copy)
374
@@ -1,5 +1,5 @@
375
-.\" $File: file.man,v 1.106 2014/03/07 23:11:51 christos Exp $
376
-.Dd January 30, 2014
377
+.\" $File: file.man,v 1.111 2014/12/16 23:18:40 christos Exp $
378
+.Dd December 16, 2014
379
.Dt FILE __CSECTION__
380
.Os
381
.Sh NAME
382
@@ -16,6 +16,7 @@
383
.Op Fl F Ar separator
384
.Op Fl f Ar namefile
385
.Op Fl m Ar magicfiles
386
+.Op Fl P Ar name=value
387
.Ar
388
.Ek
389
.Nm
390
@@ -303,6 +304,16 @@ or
391
attempt to preserve the access time of files analyzed, to pretend that
392
.Nm
393
never read them.
394
+.It Fl P , Fl Fl parameter Ar name=value
395
+Set various parameter limits.
396
+.Bl -column "elf_phnum" "Default" "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -offset indent
397
+.It Sy "Name" Ta Sy "Default" Ta Sy "Explanation"
398
+.It Li indir Ta 15 Ta recursion limit for indirect magic
399
+.It Li name Ta 30 Ta use count limit for name/use magic
400
+.It Li elf_notes Ta 256 Ta max ELF notes processed
401
+.It Li elf_phnum Ta 128 Ta max ELF program sections processed
402
+.It Li elf_shnum Ta 32768 Ta max ELF sections processed
403
+.El
404
.It Fl r , Fl Fl raw
405
Don't translate unprintable characters to \eooo.
406
Normally
407
@@ -385,6 +396,7 @@ options.
408
.Xr hexdump 1 ,
409
.Xr od 1 ,
410
.Xr strings 1 ,
411
+.Xr fstyp 8
412
.Sh STANDARDS CONFORMANCE
413
This program is believed to exceed the System V Interface Definition
414
of FILE(CMD), as near as one can determine from the vague language
415
Index: contrib/file/doc/libmagic.man
416
===================================================================
417
--- contrib/file/doc/libmagic.man (revision 284174)
418
+++ contrib/file/doc/libmagic.man (working copy)
419
@@ -1,4 +1,4 @@
420
-.\" $File: libmagic.man,v 1.28 2014/03/02 14:47:16 christos Exp $
421
+.\" $File: libmagic.man,v 1.34 2014/12/16 23:18:40 christos Exp $
422
.\"
423
.\" Copyright (c) Christos Zoulas 2003.
424
.\" All Rights Reserved.
425
@@ -25,7 +25,7 @@
426
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
427
.\" SUCH DAMAGE.
428
.\"
429
-.Dd January 6, 2012
430
+.Dd December 16, 2014
431
.Dt LIBMAGIC 3
432
.Os
433
.Sh NAME
434
@@ -40,6 +40,9 @@
435
.Nm magic_compile ,
436
.Nm magic_list ,
437
.Nm magic_load ,
438
+.Nm magic_load_buffers ,
439
+.Nm magic_setparam ,
440
+.Nm magic_getparam ,
441
.Nm magic_version
442
.Nd Magic number recognition library
443
.Sh LIBRARY
444
@@ -71,6 +74,12 @@
445
.Ft int
446
.Fn magic_load "magic_t cookie" "const char *filename"
447
.Ft int
448
+.Fn magic_load_buffers "magic_t cookie" "void **buffers" "size_t *sizes" "size_t nbuffers"
449
+.Ft int
450
+.Fn magic_getparam "magic_t cookie" "int param" "void *value"
451
+.Ft int
452
+.Fn magic_setparam "magic_t cookie" "int param" "const void *value"
453
+.Ft int
454
.Fn magic_version "void"
455
.Sh DESCRIPTION
456
These functions
457
@@ -253,6 +262,60 @@ adds
458
to the database filename as appropriate.
459
.Pp
460
The
461
+.Fn magic_load_buffers
462
+function takes an array of size
463
+.Fa nbuffers
464
+of
465
+.Fa buffers
466
+with a respective size for each in the array of
467
+.Fa sizes
468
+loaded with the contents of the magic databases from the filesystem.
469
+This function can be used in environment where the magic library does
470
+not have direct access to the filesystem, but can access the magic
471
+database via shared memory or other IPC means.
472
+.Pp
473
+The
474
+.Fn magic_getparam
475
+and
476
+.Fn magic_setparam
477
+allow getting and setting various limits related to the the magic
478
+library.
479
+.Bl -column "MAGIC_PARAM_ELF_PHNUM_MAX" "size_t" "Default" -offset indent
480
+.It Sy "Parameter" Ta Sy "Type" Ta Sy "Default"
481
+.It Li MAGIC_PARAM_INDIR_MAX Ta size_t Ta 15
482
+.It Li MAGIC_PARAM_NAME_MAX Ta size_t Ta 30
483
+.It Li MAGIC_PARAM_ELF_NOTES_MAX Ta size_t Ta 256
484
+.It Li MAGIC_PARAM_ELF_PHNUM_MAX Ta size_t Ta 128
485
+.It Li MAGIC_PARAM_ELF_SHNUM_MAX Ta size_t Ta 32768
486
+.El
487
+.Pp
488
+The
489
+.Dv MAGIC_PARAM_INDIR_RECURSION
490
+parameter controls how many levels of recursion will be followed for
491
+indirect magic entries.
492
+.Pp
493
+The
494
+.Dv MAGIC_PARAM_NAME_RECURSION
495
+parameter controls how many levels of recursion will be followed for
496
+for name/use calls.
497
+.Pp
498
+The
499
+.Dv MAGIC_PARAM_NAME_MAX
500
+parameter controls the maximum number of calls for name/use.
501
+.Pp
502
+The
503
+.Dv MAGIC_PARAM_NOTES_MAX
504
+parameter controls how many ELF notes will be processed.
505
+.Pp
506
+The
507
+.Dv MAGIC_PARAM_PHNUM_MAX
508
+parameter controls how many ELF program sections will be processed.
509
+.Pp
510
+The
511
+.Dv MAGIC_PARAM_SHNUM_MAX
512
+parameter controls how many ELF sections will be processed.
513
+.Pp
514
+The
515
.Fn magic_version
516
command returns the version number of this library which is compiled into
517
the shared library using the constant
518
Index: contrib/file/doc/magic.man
519
===================================================================
520
--- contrib/file/doc/magic.man (revision 284174)
521
+++ contrib/file/doc/magic.man (working copy)
522
@@ -1,5 +1,5 @@
523
-.\" $File: magic.man,v 1.84 2014/06/03 19:01:34 christos Exp $
524
-.Dd June 3, 2014
525
+.\" $File: magic.man,v 1.85 2015/01/01 17:07:34 christos Exp $
526
+.Dd January 1, 2015
527
.Dt MAGIC __FSECTION__
528
.Os
529
.\" install as magic.4 on USG, magic.5 on V7, Berkeley and Linux systems.
530
@@ -200,6 +200,11 @@ interpreted as a UNIX-style date, but interpreted
531
than UTC.
532
.It Dv indirect
533
Starting at the given offset, consult the magic database again.
534
+The offset of th
535
+.Dv indirect
536
+magic is by default absolute in the file, but one can specify
537
+.Dv /r
538
+to indicate that the offset is relative from the beginning of the entry.
539
.It Dv name
540
Define a
541
.Dq named
542
Index: contrib/file/magic/Magdir/android
543
===================================================================
544
--- contrib/file/magic/Magdir/android (revision 284174)
545
+++ contrib/file/magic/Magdir/android (working copy)
546
@@ -1,6 +1,6 @@
547
548
#------------------------------------------------------------
549
-# $File: android,v 1.4 2014/06/03 19:01:34 christos Exp $
550
+# $File: android,v 1.7 2014/11/10 05:08:23 christos Exp $
551
# Various android related magic entries
552
#------------------------------------------------------------
553
554
@@ -15,20 +15,11 @@
555
>0 regex dey\n[0-9]{2}\0 Dalvik dex file (optimized for host)
556
>4 string >000 version %s
557
558
-# http://android.stackexchange.com/questions/23357/\
559
-# is-there-a-way-to-look-inside-and-modify-an-adb-backup-created-file/\
560
-# 23608#23608
561
-0 string ANDROID\040BACKUP\n Android Backup
562
->15 string 1\n \b, version 1
563
->17 string 0\n \b, uncompressed
564
->17 string 1\n \b, compressed
565
->19 string none\n \b, unencrypted
566
->19 string AES-256\n \b, encrypted AES-256
567
-
568
# Android bootimg format
569
# From https://android.googlesource.com/\
570
# platform/system/core/+/master/mkbootimg/bootimg.h
571
0 string ANDROID! Android bootimg
572
+>1024 string LOKI\01 \b, LOKI'd
573
>8 lelong >0 \b, kernel
574
>>12 lelong >0 \b (0x%x)
575
>16 lelong >0 \b, ramdisk
576
@@ -38,41 +29,7 @@
577
>36 lelong >0 \b, page size: %d
578
>38 string >0 \b, name: %s
579
>64 string >0 \b, cmdline (%s)
580
-# Dalvik .dex format. http://retrodev.com/android/dexformat.html
581
-# From <[email protected]> "Mike Fleming"
582
-# Fixed to avoid regexec 17 errors on some dex files
583
-# From <[email protected]> "Tim Strazzere"
584
-0 string dex\n
585
->0 regex dex\n[0-9]{2}\0 Dalvik dex file
586
->4 string >000 version %s
587
-0 string dey\n
588
->0 regex dey\n[0-9]{2}\0 Dalvik dex file (optimized for host)
589
->4 string >000 version %s
590
591
-# http://android.stackexchange.com/questions/23357/\
592
-# is-there-a-way-to-look-inside-and-modify-an-adb-backup-created-file/\
593
-# 23608#23608
594
-0 string ANDROID\040BACKUP\n Android Backup
595
->15 string 1\n \b, version 1
596
->17 string 0\n \b, uncompressed
597
->17 string 1\n \b, compressed
598
->19 string none\n \b, unencrypted
599
->19 string AES-256\n \b, encrypted AES-256
600
-
601
-# Android bootimg format
602
-# From https://android.googlesource.com/\
603
-# platform/system/core/+/master/mkbootimg/bootimg.h
604
-0 string ANDROID! Android bootimg
605
->8 lelong >0 \b, kernel
606
->>12 lelong >0 \b (0x%x)
607
->16 lelong >0 \b, ramdisk
608
->>20 lelong >0 \b (0x%x)
609
->24 lelong >0 \b, second stage
610
->>28 lelong >0 \b (0x%x)
611
->36 lelong >0 \b, page size: %d
612
->38 string >0 \b, name: %s
613
->64 string >0 \b, cmdline (%s)
614
-
615
# Android Backup archive
616
# From: Ariel Shkedi
617
# File extension: .ab
618
@@ -98,3 +55,85 @@
619
#>>>>>&1 regex/1l .* \b, PBKDF2 rounds: %s
620
#>>>>>>&1 regex/1l .* \b, IV: %s
621
#>>>>>>>&1 regex/1l .* \b, Key: %s
622
+
623
+# *.pit files by Joerg Jenderek
624
+# http://forum.xda-developers.com/showthread.php?p=9122369
625
+# http://forum.xda-developers.com/showthread.php?t=816449
626
+# Partition Information Table for Samsung's smartphone with Android
627
+# used by flash software Odin
628
+0 ulelong 0x12349876
629
+# 1st pit entry marker
630
+>0x01C ulequad&0xFFFFFFFCFFFFFFFC =0x0000000000000000
631
+# minimal 13 and maximal 18 PIT entries found
632
+>>4 ulelong <128 Partition Information Table for Samsung smartphone
633
+>>>4 ulelong x \b, %d entries
634
+# 1. pit entry
635
+>>>4 ulelong >0 \b; #1
636
+>>>0x01C use PIT-entry
637
+>>>4 ulelong >1 \b; #2
638
+>>>0x0A0 use PIT-entry
639
+>>>4 ulelong >2 \b; #3
640
+>>>0x124 use PIT-entry
641
+>>>4 ulelong >3 \b; #4
642
+>>>0x1A8 use PIT-entry
643
+>>>4 ulelong >4 \b; #5
644
+>>>0x22C use PIT-entry
645
+>>>4 ulelong >5 \b; #6
646
+>>>0x2B0 use PIT-entry
647
+>>>4 ulelong >6 \b; #7
648
+>>>0x334 use PIT-entry
649
+>>>4 ulelong >7 \b; #8
650
+>>>0x3B8 use PIT-entry
651
+>>>4 ulelong >8 \b; #9
652
+>>>0x43C use PIT-entry
653
+>>>4 ulelong >9 \b; #10
654
+>>>0x4C0 use PIT-entry
655
+>>>4 ulelong >10 \b; #11
656
+>>>0x544 use PIT-entry
657
+>>>4 ulelong >11 \b; #12
658
+>>>0x5C8 use PIT-entry
659
+>>>4 ulelong >12 \b; #13
660
+>>>>0x64C use PIT-entry
661
+# 14. pit entry
662
+>>>4 ulelong >13 \b; #14
663
+>>>>0x6D0 use PIT-entry
664
+>>>4 ulelong >14 \b; #15
665
+>>>0x754 use PIT-entry
666
+>>>4 ulelong >15 \b; #16
667
+>>>0x7D8 use PIT-entry
668
+>>>4 ulelong >16 \b; #17
669
+>>>0x85C use PIT-entry
670
+# 18. pit entry
671
+>>>4 ulelong >17 \b; #18
672
+>>>0x8E0 use PIT-entry
673
+
674
+0 name PIT-entry
675
+# garbage value implies end of pit entries
676
+>0x00 ulequad&0xFFFFFFFCFFFFFFFC =0x0000000000000000
677
+# skip empty partition name
678
+>>0x24 ubyte !0
679
+# partition name
680
+>>>0x24 string >\0 %-.32s
681
+# flags
682
+>>>0x0C ulelong&0x00000002 2 \b+RW
683
+# partition ID:
684
+# 0~IPL,MOVINAND,GANG;1~PIT,GPT;2~HIDDEN;3~SBL,HIDDEN;4~SBL2,HIDDEN;5~BOOT;6~KENREl,RECOVER,misc;7~RECOVER
685
+# ;11~MODEM;20~efs;21~PARAM;22~FACTORY,SYSTEM;23~DBDATAFS,USERDATA;24~CACHE;80~BOOTLOADER;81~TZSW
686
+>>>0x08 ulelong x (0x%x)
687
+# filename
688
+>>>0x44 string >\0 "%-.64s"
689
+#>>>0x18 ulelong >0
690
+# blocksize in 512 byte units ?
691
+#>>>>0x18 ulelong x \b, %db
692
+# partition size in blocks ?
693
+#>>>>0x22 ulelong x \b*%d
694
+
695
+# Android bootimg format
696
+# From https://android.googlesource.com/\
697
+# platform/system/core/+/master/libsparse/sparse_format.h
698
+0 lelong 0xed26ff3a Android sparse image
699
+>4 leshort x \b, version: %d
700
+>6 leshort x \b.%d
701
+>16 lelong x \b, Total of %d
702
+>12 lelong x \b %d-byte output blocks in
703
+>20 lelong x \b %d input chunks.
704
Index: contrib/file/magic/Magdir/animation
705
===================================================================
706
--- contrib/file/magic/Magdir/animation (revision 284174)
707
+++ contrib/file/magic/Magdir/animation (working copy)
708
@@ -1,6 +1,6 @@
709
710
#------------------------------------------------------------------------------
711
-# $File: animation,v 1.53 2014/04/30 21:41:02 christos Exp $
712
+# $File: animation,v 1.56 2014/10/23 23:12:51 christos Exp $
713
# animation: file(1) magic for animation/movie formats
714
#
715
# animation formats
716
@@ -32,43 +32,155 @@
717
!:mime application/x-quicktime-player
718
4 string/W jP JPEG 2000 image
719
!:mime image/jp2
720
+# http://www.ftyps.com/ with local additions
721
4 string ftyp ISO Media
722
->8 string isom \b, MPEG v4 system, version 1
723
-!:mime video/mp4
724
->8 string iso2 \b, MPEG v4 system, part 12 revision
725
->8 string mp41 \b, MPEG v4 system, version 1
726
-!:mime video/mp4
727
->8 string mp42 \b, MPEG v4 system, version 2
728
-!:mime video/mp4
729
->8 string mp7t \b, MPEG v4 system, MPEG v7 XML
730
->8 string mp7b \b, MPEG v4 system, MPEG v7 binary XML
731
->8 string/W jp2 \b, JPEG 2000
732
-!:mime image/jp2
733
+>8 string 3g2 \b, MPEG v4 system, 3GPP2
734
+!:mime video/3gpp2
735
+>>11 byte 4 \b v4 (H.263/AMR GSM 6.10)
736
+>>11 byte 5 \b v5 (H.263/AMR GSM 6.10)
737
+>>11 byte 6 \b v6 (ITU H.264/AMR GSM 6.10)
738
+>>11 byte a \b C.S0050-0 V1.0
739
+>>11 byte b \b C.S0050-0-A V1.0.0
740
+>>11 byte c \b C.S0050-0-B V1.0
741
>8 string 3ge \b, MPEG v4 system, 3GPP
742
!:mime video/3gpp
743
+>>11 byte 6 \b, Release 6 MBMS Extended Presentations
744
+>>11 byte 7 \b, Release 7 MBMS Extended Presentations
745
>8 string 3gg \b, MPEG v4 system, 3GPP
746
+>11 byte 6 \b, Release 6 General Profile
747
!:mime video/3gpp
748
>8 string 3gp \b, MPEG v4 system, 3GPP
749
+>11 byte 1 \b, Release %d (non existent)
750
+>11 byte 2 \b, Release %d (non existent)
751
+>11 byte 3 \b, Release %d (non existent)
752
+>11 byte 4 \b, Release %d
753
+>11 byte 5 \b, Release %d
754
+>11 byte 6 \b, Release %d
755
+>11 byte 7 \b, Release %d Streaming Servers
756
!:mime video/3gpp
757
>8 string 3gs \b, MPEG v4 system, 3GPP
758
+>11 byte 7 \b, Release %d Streaming Servers
759
!:mime video/3gpp
760
->8 string 3g2 \b, MPEG v4 system, 3GPP2
761
+>8 string avc1 \b, MPEG v4 system, 3GPP JVT AVC [ISO 14496-12:2005]
762
+!:mime video/mp4
763
+>8 string/W qt \b, Apple QuickTime movie
764
+!:mime video/quicktime
765
+>8 string CAEP \b, Canon Digital Camera
766
+>8 string caqv \b, Casio Digital Camera
767
+>8 string CDes \b, Convergent Design
768
+>8 string da0a \b, DMB MAF w/ MPEG Layer II aud, MOT slides, DLS, JPG/PNG/MNG
769
+>8 string da0b \b, DMB MAF, ext DA0A, with 3GPP timed text, DID, TVA, REL, IPMP
770
+>8 string da1a \b, DMB MAF audio with ER-BSAC audio, JPG/PNG/MNG images
771
+>8 string da1b \b, DMB MAF, ext da1a, with 3GPP timed text, DID, TVA, REL, IPMP
772
+>8 string da2a \b, DMB MAF aud w/ HE-AAC v2 aud, MOT slides, DLS, JPG/PNG/MNG
773
+>8 string da2b \b, DMB MAF, ext da2a, with 3GPP timed text, DID, TVA, REL, IPMP
774
+>8 string da3a \b, DMB MAF aud with HE-AAC aud, JPG/PNG/MNG images
775
+>8 string da3b \b, DMB MAF, ext da3a w/ BIFS, 3GPP, DID, TVA, REL, IPMP
776
+>8 string dmb1 \b, DMB MAF supporting all the components defined in the spec
777
+>8 string dmpf \b, Digital Media Project
778
+>8 string drc1 \b, Dirac (wavelet compression), encap in ISO base media (MP4)
779
+>8 string dv1a \b, DMB MAF vid w/ AVC vid, ER-BSAC aud, BIFS, JPG/PNG/MNG, TS
780
+>8 string dv1b \b, DMB MAF, ext dv1a, with 3GPP timed text, DID, TVA, REL, IPMP
781
+>8 string dv2a \b, DMB MAF vid w/ AVC vid, HE-AAC v2 aud, BIFS, JPG/PNG/MNG, TS
782
+>8 string dv2b \b, DMB MAF, ext dv2a, with 3GPP timed text, DID, TVA, REL, IPMP
783
+>8 string dv3a \b, DMB MAF vid w/ AVC vid, HE-AAC aud, BIFS, JPG/PNG/MNG, TS
784
+>8 string dv3b \b, DMB MAF, ext dv3a, with 3GPP timed text, DID, TVA, REL, IPMP
785
+>8 string dvr1 \b, DVB (.DVB) over RTP
786
+!:mime video/vnd.dvb.file
787
+>8 string dvt1 \b, DVB (.DVB) over MPEG-2 Transport Stream
788
+!:mime video/vnd.dvb.file
789
+>8 string F4V \b, Video for Adobe Flash Player 9+ (.F4V)
790
+!:mime video/mp4
791
+>8 string F4P \b, Protected Video for Adobe Flash Player 9+ (.F4P)
792
+!:mime video/mp4
793
+>8 string F4A \b, Audio for Adobe Flash Player 9+ (.F4A)
794
+!:mime audio/mp4
795
+>8 string F4B \b, Audio Book for Adobe Flash Player 9+ (.F4B)
796
+!:mime audio/mp4
797
+>8 string isc2 \b, ISMACryp 2.0 Encrypted File
798
+# ?/enc-isoff-generic
799
+>8 string iso2 \b, MP4 Base Media v2 [ISO 14496-12:2005]
800
+!:mime video/mp4
801
+>8 string isom \b, MP4 Base Media v1 [IS0 14496-12:2003]
802
+!:mime video/mp4
803
+>8 string/W jp2 \b, JPEG 2000
804
+!:mime image/jp2
805
+>8 string JP2 \b, JPEG 2000 Image (.JP2) [ISO 15444-1 ?]
806
+!:mime image/jp2
807
+>8 string JP20 \b, Unknown, from GPAC samples (prob non-existent)
808
+>8 string jpm \b, JPEG 2000 Compound Image (.JPM) [ISO 15444-6]
809
+!:mime image/jpm
810
+>8 string jpx \b, JPEG 2000 w/ extensions (.JPX) [ISO 15444-2]
811
+!:mime image/jpx
812
+>8 string KDDI \b, 3GPP2 EZmovie for KDDI 3G cellphones
813
!:mime video/3gpp2
814
->>11 byte 4 \b v4 (H.263/AMR GSM 6.10)
815
->>11 byte 5 \b v5 (H.263/AMR GSM 6.10)
816
->>11 byte 6 \b v6 (ITU H.264/AMR GSM 6.10)
817
+>8 string M4A \b, Apple iTunes ALAC/AAC-LC (.M4A) Audio
818
+!:mime audio/x-m4a
819
+>8 string M4B \b, Apple iTunes ALAC/AAC-LC (.M4B) Audio Book
820
+!:mime audio/mp4
821
+>8 string M4P \b, Apple iTunes ALAC/AAC-LC (.M4P) AES Protected Audio
822
+!:mime video/mp4
823
+>8 string M4V \b, Apple iTunes Video (.M4V) Video
824
+!:mime video/x-m4v
825
+>8 string M4VH \b, Apple TV (.M4V)
826
+!:mime video/x-m4v
827
+>8 string M4VP \b, Apple iPhone (.M4V)
828
+!:mime video/x-m4v
829
+>8 string mj2s \b, Motion JPEG 2000 [ISO 15444-3] Simple Profile
830
+!:mime video/mj2
831
+>8 string mjp2 \b, Motion JPEG 2000 [ISO 15444-3] General Profile
832
+!:mime video/mj2
833
+>8 string mmp4 \b, MPEG-4/3GPP Mobile Profile (.MP4 / .3GP) (for NTT)
834
+!:mime video/mp4
835
+>8 string mobi \b, MPEG-4, MOBI format
836
+!:mime video/mp4
837
+>8 string mp21 \b, MPEG-21 [ISO/IEC 21000-9]
838
+>8 string mp41 \b, MP4 v1 [ISO 14496-1:ch13]
839
+!:mime video/mp4
840
+>8 string mp42 \b, MP4 v2 [ISO 14496-14]
841
+!:mime video/mp4
842
+>8 string mp71 \b, MP4 w/ MPEG-7 Metadata [per ISO 14496-12]
843
+>8 string mp7t \b, MPEG v4 system, MPEG v7 XML
844
+>8 string mp7b \b, MPEG v4 system, MPEG v7 binary XML
845
>8 string mmp4 \b, MPEG v4 system, 3GPP Mobile
846
!:mime video/mp4
847
->8 string avc1 \b, MPEG v4 system, 3GPP JVT AVC
848
-!:mime video/3gpp
849
->8 string/W M4A \b, MPEG v4 system, iTunes AAC-LC
850
+>8 string MPPI \b, Photo Player, MAF [ISO/IEC 23000-3]
851
+>8 string mqt \b, Sony / Mobile QuickTime (.MQV) US Pat 7,477,830
852
+!:mime video/quicktime
853
+>8 string MSNV \b, MPEG-4 (.MP4) for SonyPSP
854
!:mime audio/mp4
855
->8 string/W M4V \b, MPEG v4 system, iTunes AVC-LC
856
+>8 string NDAS \b, MP4 v2 [ISO 14496-14] Nero Digital AAC Audio
857
+!:mime audio/mp4
858
+>8 string NDSC \b, MPEG-4 (.MP4) Nero Cinema Profile
859
!:mime video/mp4
860
->8 string/W M4P \b, MPEG v4 system, iTunes AES encrypted
861
->8 string/W M4B \b, MPEG v4 system, iTunes bookmarked
862
->8 string/W qt \b, Apple QuickTime movie
863
+>8 string NDSH \b, MPEG-4 (.MP4) Nero HDTV Profile
864
+!:mime video/mp4
865
+>8 string NDSM \b, MPEG-4 (.MP4) Nero Mobile Profile
866
+!:mime video/mp4
867
+>8 string NDSP \b, MPEG-4 (.MP4) Nero Portable Profile
868
+!:mime video/mp4
869
+>8 string NDSS \b, MPEG-4 (.MP4) Nero Standard Profile
870
+!:mime video/mp4
871
+>8 string NDXC \b, H.264/MPEG-4 AVC (.MP4) Nero Cinema Profile
872
+!:mime video/mp4
873
+>8 string NDXH \b, H.264/MPEG-4 AVC (.MP4) Nero HDTV Profile
874
+!:mime video/mp4
875
+>8 string NDXM \b, H.264/MPEG-4 AVC (.MP4) Nero Mobile Profile
876
+!:mime video/mp4
877
+>8 string NDXP \b, H.264/MPEG-4 AVC (.MP4) Nero Portable Profile
878
+!:mime video/mp4
879
+>8 string NDXS \b, H.264/MPEG-4 AVC (.MP4) Nero Standard Profile
880
+!:mime video/mp4
881
+>8 string odcf \b, OMA DCF DRM Format 2.0 (OMA-TS-DRM-DCF-V2_0-20060303-A)
882
+>8 string opf2 \b, OMA PDCF DRM Format 2.1 (OMA-TS-DRM-DCF-V2_1-20070724-C)
883
+>8 string opx2 \b, OMA PDCF DRM + XBS ext (OMA-TS-DRM_XBS-V1_0-20070529-C)
884
+>8 string pana \b, Panasonic Digital Camera
885
+>8 string qt \b, Apple QuickTime (.MOV/QT)
886
!:mime video/quicktime
887
+>8 string ROSS \b, Ross Video
888
+>8 string sdv \b, SD Memory Card Video
889
+>8 string ssc1 \b, Samsung stereo, single stream (patent pending)
890
+>8 string ssc2 \b, Samsung stereo, dual stream (patent pending)
891
892
# MPEG sequences
893
# Scans for all common MPEG header start codes
894
Index: contrib/file/magic/Magdir/archive
895
===================================================================
896
--- contrib/file/magic/Magdir/archive (revision 284174)
897
+++ contrib/file/magic/Magdir/archive (working copy)
898
@@ -1,5 +1,5 @@
899
#------------------------------------------------------------------------------
900
-# $File: archive,v 1.87 2014/06/03 19:15:58 christos Exp $
901
+# $File: archive,v 1.88 2014/08/16 10:42:17 christos Exp $
902
# archive: file(1) magic for archive formats (see also "msdos" for self-
903
# extracting compressed archives)
904
#
905
@@ -954,34 +954,3 @@
906
>0xE08 search/7776 \x55\xAA
907
>>&-512 indirect x \b; contains
908
909
-# Symantec GHOST image by Joerg Jenderek at May 2014
910
-# http://us.norton.com/ghost/
911
-# http://www.garykessler.net/library/file_sigs.html
912
-0 ubelong&0xFFFFf7f0 0xFEEF0100 Norton GHost image
913
-# *.GHO
914
->2 ubyte&0x08 0x00 \b, first file
915
-# *.GHS or *.[0-9] with cns program option
916
->2 ubyte&0x08 0x08 \b, split file
917
-# part of split index interesting for *.ghs
918
->>4 ubyte x id=0x%x
919
-# compression tag minus one equals numeric compression command line switch z[1-9]
920
->3 ubyte 0 \b, no compression
921
->3 ubyte 2 \b, fast compression (Z1)
922
->3 ubyte 3 \b, medium compression (Z2)
923
->3 ubyte >3
924
->>3 ubyte <11 \b, compression (Z%d-1)
925
->2 ubyte&0x08 0x00
926
-# ~ 30 byte password field only for *.gho
927
->>12 ubequad !0 \b, password protected
928
->>44 ubyte !1
929
-# 1~Image All, sector-by-sector only for *.gho
930
->>>10 ubyte 1 \b, sector copy
931
-# 1~Image Boot track only for *.gho
932
->>>43 ubyte 1 \b, boot track
933
-# 1~Image Disc only for *.gho implies Image Boot track and sector copy
934
->>44 ubyte 1 \b, disc sector copy
935
-# optional image description only *.gho
936
->>0xff string >\0 "%-.254s"
937
-# look for DOS sector end sequence
938
->0xE08 search/7776 \x55\xAA
939
->>&-512 indirect x \b; contains
940
Index: contrib/file/magic/Magdir/blender
941
===================================================================
942
--- contrib/file/magic/Magdir/blender (revision 284174)
943
+++ contrib/file/magic/Magdir/blender (working copy)
944
@@ -1,6 +1,6 @@
945
946
#------------------------------------------------------------------------------
947
-# $File: blender,v 1.5 2009/09/19 16:28:08 christos Exp $
948
+# $File: blender,v 1.6 2014/08/30 08:34:17 christos Exp $
949
# blender: file(1) magic for Blender 3D related files
950
#
951
# Native format rule v1.2. For questions use the developers list
952
@@ -35,5 +35,5 @@
953
>>>0x44 string =GLOB \b.
954
>>>>0x60 beshort x \b%.4d
955
956
-# Scripts that run in the embeded Python interpreter
957
+# Scripts that run in the embedded Python interpreter
958
0 string #!BPY Blender3D BPython script
959
Index: contrib/file/magic/Magdir/cafebabe
960
===================================================================
961
--- contrib/file/magic/Magdir/cafebabe (revision 284174)
962
+++ contrib/file/magic/Magdir/cafebabe (working copy)
963
@@ -1,6 +1,6 @@
964
965
#------------------------------------------------------------------------------
966
-# $File: cafebabe,v 1.16 2014/04/30 21:41:02 christos Exp $
967
+# $File: cafebabe,v 1.17 2015/01/01 17:07:00 christos Exp $
968
# Cafe Babes unite!
969
#
970
# Since Java bytecode and Mach-O universal binaries have the same magic number,
971
@@ -45,7 +45,7 @@
972
973
0 name mach-o \b [
974
>0 use mach-o-cpu \b
975
->&(8.L) indirect \b:
976
+>(8.L) indirect \b:
977
>0 belong x \b]
978
979
0 belong 0xcafebabe
980
Index: contrib/file/magic/Magdir/commands
981
===================================================================
982
--- contrib/file/magic/Magdir/commands (revision 284174)
983
+++ contrib/file/magic/Magdir/commands (working copy)
984
@@ -1,6 +1,6 @@
985
986
#------------------------------------------------------------------------------
987
-# $File: commands,v 1.50 2014/05/30 16:48:44 christos Exp $
988
+# $File: commands,v 1.51 2014/09/27 00:12:55 christos Exp $
989
# commands: file(1) magic for various shells and interpreters
990
#
991
#0 string/w : shell archive or script for antique kernel text
992
@@ -56,7 +56,7 @@
993
!:mime text/x-awk
994
0 string/wt #!\ /usr/bin/awk awk script text executable
995
!:mime text/x-awk
996
-0 regex/4096 =^\\s{0,100}BEGIN\\s{0,100}[{] awk script text
997
+0 regex/4096 =^\\s{0,100}BEGIN\\s{0,100}[{] awk or perl script text
998
999
# AT&T Bell Labs' Plan 9 shell
1000
0 string/wt #!\ /bin/rc Plan 9 rc shell script text executable
1001
Index: contrib/file/magic/Magdir/compress
1002
===================================================================
1003
--- contrib/file/magic/Magdir/compress (revision 284174)
1004
+++ contrib/file/magic/Magdir/compress (working copy)
1005
@@ -1,5 +1,5 @@
1006
#------------------------------------------------------------------------------
1007
-# $File: compress,v 1.58 2014/05/07 19:36:59 christos Exp $
1008
+# $File: compress,v 1.62 2014/09/13 14:27:12 christos Exp $
1009
# compress: file(1) magic for pure-compression formats (no archives)
1010
#
1011
# compress, gzip, pack, compact, huf, squeeze, crunch, freeze, yabba, etc.
1012
@@ -251,3 +251,13 @@
1013
# http://code.google.com/p/snappy/source/browse/trunk/framing_format.txt
1014
0 string \377\006\0\0sNaPpY snappy framed data
1015
!:mime application/x-snappy-framed
1016
+
1017
+# qpress, http://www.quicklz.com/
1018
+0 string qpress10 qpress compressed data
1019
+!:mime application/x-qpress
1020
+
1021
+# Zlib https://www.ietf.org/rfc/rfc6713.txt
1022
+0 beshort%31 =0
1023
+>0 byte&0xf =8
1024
+>>0 byte&0x80 =0 zlib compressed data
1025
+!:mime application/zlib
1026
Index: contrib/file/magic/Magdir/database
1027
===================================================================
1028
--- contrib/file/magic/Magdir/database (revision 284174)
1029
+++ contrib/file/magic/Magdir/database (working copy)
1030
@@ -1,6 +1,6 @@
1031
1032
#------------------------------------------------------------------------------
1033
-# $File: database,v 1.41 2014/06/03 19:17:27 christos Exp $
1034
+# $File: database,v 1.43 2014/10/28 15:47:39 christos Exp $
1035
# database: file(1) magic for various databases
1036
#
1037
# extracted from header/code files by Graeme Wilford ([email protected])
1038
@@ -9,10 +9,18 @@
1039
# GDBM magic numbers
1040
# Will be maintained as part of the GDBM distribution in the future.
1041
# <[email protected]>
1042
-0 belong 0x13579ace GNU dbm 1.x or ndbm database, big endian
1043
+0 belong 0x13579acd GNU dbm 1.x or ndbm database, big endian, 32-bit
1044
!:mime application/x-gdbm
1045
-0 lelong 0x13579ace GNU dbm 1.x or ndbm database, little endian
1046
+0 belong 0x13579ace GNU dbm 1.x or ndbm database, big endian, old
1047
!:mime application/x-gdbm
1048
+0 belong 0x13579acf GNU dbm 1.x or ndbm database, big endian, 64-bit
1049
+!:mime application/x-gdbm
1050
+0 lelong 0x13579acd GNU dbm 1.x or ndbm database, little endian, 32-bit
1051
+!:mime application/x-gdbm
1052
+0 lelong 0x13579ace GNU dbm 1.x or ndbm database, little endian, old
1053
+!:mime application/x-gdbm
1054
+0 lelong 0x13579acf GNU dbm 1.x or ndbm database, little endian, 64-bit
1055
+!:mime application/x-gdbm
1056
0 string GDBM GNU dbm 2.x database
1057
!:mime application/x-gdbm
1058
#
1059
@@ -202,27 +210,27 @@
1060
# for multiple index files (*.MDX) Production flag,tag numbers(<=0x30),tag length(<=0x20), reserverd (NULL)
1061
>>>>>>>24 ubelong&0x0133f7ff >0
1062
# test for reserved NULL byte
1063
->>>>>>>>47 ubyte x
1064
+>>>>>>>>47 ubyte 0
1065
# test for valid TAG key format (0x10 or 0)
1066
>>>>>>>>>559 ubyte&0xeF 0
1067
# test MM <= 12
1068
->>>>>>>>>45 ubeshort <0x0C20
1069
->>>>>>>>>>45 ubyte >0
1070
->>>>>>>>>>>46 ubyte <32
1071
->>>>>>>>>>>>46 ubyte >0
1072
+>>>>>>>>>>45 ubeshort <0x0C20
1073
+>>>>>>>>>>>45 ubyte >0
1074
+>>>>>>>>>>>>46 ubyte <32
1075
+>>>>>>>>>>>>>46 ubyte >0
1076
#!:mime application/x-mdx
1077
->>>>>>>>>>>>>0 use xbase-type
1078
->>>>>>>>>>>>>0 ubyte x \b MDX
1079
->>>>>>>>>>>>>1 ubyte x \b, creation-date
1080
->>>>>>>>>>>>>1 use xbase-date
1081
->>>>>>>>>>>>>44 ubyte x \b, update-date
1082
->>>>>>>>>>>>>44 use xbase-date
1083
+>>>>>>>>>>>>>>0 use xbase-type
1084
+>>>>>>>>>>>>>>0 ubyte x \b MDX
1085
+>>>>>>>>>>>>>>1 ubyte x \b, creation-date
1086
+>>>>>>>>>>>>>>1 use xbase-date
1087
+>>>>>>>>>>>>>>44 ubyte x \b, update-date
1088
+>>>>>>>>>>>>>>44 use xbase-date
1089
# No.of tags in use (1,2,5,12)
1090
->>>>>>>>>>>>>28 uleshort x \b, %d
1091
+>>>>>>>>>>>>>>28 uleshort x \b, %d
1092
# No. of entries in tag (0x30)
1093
->>>>>>>>>>>>>25 ubyte x \b/%d tags
1094
+>>>>>>>>>>>>>>25 ubyte x \b/%d tags
1095
# Length of tag
1096
->>>>>>>>>>>>>26 ubyte x * %d
1097
+>>>>>>>>>>>>>>26 ubyte x * %d
1098
# 1st tag name_
1099
>>>>>>>>>>>>>548 string x \b, 1st tag "%.11s"
1100
# 2nd tag name
1101
@@ -337,60 +345,103 @@
1102
# dBASE III
1103
>>>>>>16 ubyte 3
1104
# dBASE III DBT
1105
->>>>>>>0 use xbase-memo-print
1106
-# dBASE IV DBT , FoxPro FPT or many PNG , ZIP , DBF garbage
1107
+>>>>>>>0 use dbase3-memo-print
1108
+# dBASE III DBT without version, dBASE IV DBT , FoxPro FPT , or many ZIP , DBF garbage
1109
>>>>>>16 ubyte 0
1110
-# dBASE IV DBT with DBF name or DBF garbage
1111
->>>>>>>8 ubelong >0x40000000
1112
-# skip DBF and catch dBASE IV DBT with DBF name and with non big index of next free block
1113
->>>>>>>>0 ulelong <0x01010002
1114
->>>>>>>>>0 use xbase-memo-print
1115
->>>>>>>8 ubelong 0
1116
+# unusual dBASE III DBT like angest.dbt, dBASE IV DBT with block size 0 , FoxPro FPT , or garbage PCX DBF
1117
+>>>>>>>20 uleshort 0
1118
+# FoxPro FPT , unusual dBASE III DBT like biblio.dbt or garbage
1119
+>>>>>>>>8 ulong =0
1120
+>>>>>>>>>6 ubeshort >0
1121
+# skip emacs.PIF
1122
+>>>>>>>>>>4 ushort 0
1123
+>>>>>>>>>>>0 use foxpro-memo-print
1124
+# dBASE III DBT , garbage
1125
+>>>>>>>>>6 ubeshort 0
1126
# skip MM*DD*.bin by test for for reserved NULL byte
1127
->>>>>>>>508 ubelong 0
1128
-# real memo files should contain text here
1129
->>>>>>>>>520 ubelong >0x20202019
1130
->>>>>>>>>>520 ubelong <0xFEFEFEFF
1131
->>>>>>>>>>>0 use xbase-memo-print
1132
-# garbage PCX , ZIP , JAR , XPI
1133
->>>>>>>8 default x
1134
+>>>>>>>>>>510 ubeshort 0
1135
+# skip TK-DOS11.img image by looking for memo text
1136
+>>>>>>>>>>>512 ubelong <0xfeffff03
1137
+# skip EFI executables by looking for memo text
1138
+>>>>>>>>>>>>512 ubelong >0x1F202020
1139
+>>>>>>>>>>>>>513 ubyte >0
1140
+# unusual dBASE III DBT like adressen.dbt
1141
+>>>>>>>>>>>>>>0 use dbase3-memo-print
1142
+# dBASE III DBT like angest.dbt, or garbage PCX DBF
1143
+>>>>>>>>8 ubelong !0
1144
+# skip PCX and some DBF by test for for reserved NULL bytes
1145
+>>>>>>>>>510 ubeshort 0
1146
+# skip some DBF by test of invalid version
1147
+>>>>>>>>>>0 ubyte >5
1148
+>>>>>>>>>>>0 ubyte <48
1149
+>>>>>>>>>>>>0 use dbase3-memo-print
1150
+# dBASE IV DBT with positive block size
1151
+>>>>>>>20 uleshort >0
1152
+>>>>>>>>0 use dbase4-memo-print
1153
1154
-# Print the information of dBase DBT or FoxPro FPT memo files
1155
-0 name xbase-memo-print
1156
->0 ubyte x
1157
-# test version
1158
-# memo file
1159
->>16 ubyte 3 dBase III DBT
1160
->>16 ubyte 0
1161
->>>512 ubelong <0x00000003 FoxPro FPT
1162
-# Size of blocks for FoxPro
1163
->>>>6 ubeshort x \b, blocks size %u
1164
-# Number of next available block for appending data for FoxPro
1165
->>>>0 ubelong =0 \b, next free block index %u
1166
->>>>0 ubelong !0 \b, next free block index %u
1167
->>>512 default x dBase IV DBT
1168
-# DBF file name without extension
1169
->>>>8 string >\0 \b of %-.8s.DBF
1170
-# size of blocks ; not reliable 0x2020204C
1171
-#>>>>4 ulelong =0 \b, blocks size %u
1172
->>>>4 ulelong !0 \b, blocks size %u
1173
-# Block length found 0 , 512
1174
-#>>>>20 uleshort =0 \b, block length %u
1175
->>>>20 uleshort !0 \b, block length %u
1176
+# Print the information of dBase III DBT memo file
1177
+0 name dbase3-memo-print
1178
+>0 ubyte x dBase III DBT
1179
+# instead 3 as version number 0 for unusual examples like biblio.dbt
1180
+>16 ubyte !3 \b, version number %u
1181
# Number of next available block for appending data
1182
->>>>0 ulelong =0 \b, next free block index %u
1183
->>>>0 ulelong !0 \b, next free block index %u
1184
->>512 ubelong x
1185
->>>512 ubelong =0xFFFF0800
1186
->>>>520 string >\0 \b, 1st used item "%s"
1187
-# FoxPro
1188
->>>512 ubelong <3
1189
-# FoxPro memo
1190
->>>>512 ubelong =1
1191
->>>>520 string >\0 \b, 1st used item "%s"
1192
->>>512 default x
1193
-# may be deleted memo field
1194
->>>>512 string >\0 \b, 1st item "%s"
1195
+#>0 lelong =0 \b, next free block index %u
1196
+>0 lelong !0 \b, next free block index %u
1197
+# no positiv block length
1198
+#>20 uleshort =0 \b, block length %u
1199
+>20 uleshort !0 \b, block length %u
1200
+# dBase III memo field terminated by \032\032
1201
+>512 string >\0 \b, 1st item "%s"
1202
+# Print the information of dBase IV DBT memo file
1203
+0 name dbase4-memo-print
1204
+>0 lelong x dBase IV DBT
1205
+# 8 character shorted main name of coresponding dBASE IV DBF file
1206
+>8 ubelong >0x20000000
1207
+# skip unusual like for angest.dbt
1208
+>>20 uleshort >0
1209
+>>>8 string >\0 \b of %-.8s.DBF
1210
+# value 0 implies 512 as size
1211
+#>4 ulelong =0 \b, blocks size %u
1212
+# size of blocks not reliable like 0x2020204C in angest.dbt
1213
+>4 ulelong !0
1214
+>>4 ulelong&0x0000003f 0 \b, blocks size %u
1215
+# dBase IV DBT with positive block length (found 512 , 1024)
1216
+>20 uleshort >0 \b, block length %u
1217
+# next available block
1218
+#>0 lelong =0 \b, next free block index %u
1219
+>0 lelong !0 \b, next free block index %u
1220
+>20 uleshort >0
1221
+>>(20.s) ubelong x
1222
+>>>&-4 use dbase4-memofield-print
1223
+# unusual dBase IV DBT without block length (implies 512 as length)
1224
+>20 uleshort =0
1225
+>>512 ubelong x
1226
+>>>&-4 use dbase4-memofield-print
1227
+# Print the information of dBase IV memo field
1228
+0 name dbase4-memofield-print
1229
+# free dBase IV memo field
1230
+>0 ubelong !0xFFFF0800
1231
+>>0 lelong x \b, next free block %u
1232
+>>4 lelong x \b, next used block %u
1233
+# used dBase IV memo field
1234
+>0 ubelong =0xFFFF0800
1235
+# length of memo field
1236
+>>4 lelong x \b, field length %d
1237
+>>>8 string >\0 \b, 1st used item "%s"
1238
+# Print the information of FoxPro FPT memo file
1239
+0 name foxpro-memo-print
1240
+>0 belong x FoxPro FPT
1241
+# Size of blocks for FoxPro ( 64,256 )
1242
+>6 ubeshort x \b, blocks size %u
1243
+# next available block
1244
+#>0 belong =0 \b, next free block index %u
1245
+>0 belong !0 \b, next free block index %u
1246
+# field type ( 0~picture, 1~memo, 2~object )
1247
+>512 ubelong <3 \b, field type %u
1248
+# length of memo field
1249
+>512 ubelong 1
1250
+>>516 belong >0 \b, field length %d
1251
+>>>520 string >\0 \b, 1st item "%s"
1252
1253
# TODO:
1254
# DBASE index file *.NDX
1255
Index: contrib/file/magic/Magdir/elf
1256
===================================================================
1257
--- contrib/file/magic/Magdir/elf (revision 284174)
1258
+++ contrib/file/magic/Magdir/elf (working copy)
1259
@@ -1,6 +1,6 @@
1260
1261
#------------------------------------------------------------------------------
1262
-# $File: elf,v 1.67 2014/06/12 13:52:48 christos Exp $
1263
+# $File: elf,v 1.68 2014/09/19 19:05:57 christos Exp $
1264
# elf: file(1) magic for ELF executables
1265
#
1266
# We have to check the byte order flag to see what byte order all the
1267
@@ -257,6 +257,7 @@
1268
>18 leshort 216 Cognitive Smart Memory,
1269
>18 leshort 217 iCelero CoolEngine,
1270
>18 leshort 218 Nanoradio Optimized RISC,
1271
+>18 leshort 243 UCB RISC-V,
1272
>18 leshort 0x1057 AVR (unofficial),
1273
>18 leshort 0x1059 MSP430 (unofficial),
1274
>18 leshort 0x1223 Adapteva Epiphany (unofficial),
1275
Index: contrib/file/magic/Magdir/filesystems
1276
===================================================================
1277
--- contrib/file/magic/Magdir/filesystems (revision 284174)
1278
+++ contrib/file/magic/Magdir/filesystems (working copy)
1279
@@ -1,5 +1,5 @@
1280
#------------------------------------------------------------------------------
1281
-# $File: filesystems,v 1.95 2014/06/03 19:17:27 christos Exp $
1282
+# $File: filesystems,v 1.108 2015/01/01 17:43:47 christos Exp $
1283
# filesystems: file(1) magic for different filesystems
1284
#
1285
0 name partid
1286
@@ -254,19 +254,20 @@
1287
30 search/481 \x55\xAA
1288
# to display DOS/MBR boot sector (40) before old one (strength=50+21),Syslinux bootloader (71),SYSLINUX MBR (37+36),NetBSD mbr (110),AdvanceMAME mbr (111)
1289
# DOS BPB information (70) and after DOS floppy (120) like in previous file version
1290
-!:strength +72
1291
+!:strength +65
1292
# for sector sizes < 512 Bytes
1293
>11 uleshort <512
1294
>>(11.s-2) uleshort 0xAA55 DOS/MBR boot sector
1295
# for sector sizes with 512 or more Bytes
1296
>0x1FE leshort 0xAA55 DOS/MBR boot sector
1297
+
1298
# keep old DOS/MBR boot sector as dummy for mbr and bootloader displaying
1299
# only for sector sizes with 512 or more Bytes
1300
-0x1FE leshort 0xAA55
1301
+0x1FE leshort 0xAA55 DOS/MBR boot sector
1302
#
1303
# to display information (50) before DOS BPB (strength=70) and after DOS floppy (120) like in old file version
1304
-!:strength +21
1305
->2 string OSBS \b, OS/BS MBR
1306
+!:strength +65
1307
+>2 string OSBS OS/BS MBR
1308
# added by Joerg Jenderek at Feb 2013 according to http://thestarman.pcministry.com/asm/mbr/
1309
# and http://en.wikipedia.org/wiki/Master_Boot_Record
1310
# test for nearly all MS-DOS Master Boot Record initial program loader (IPL) is now done by
1311
@@ -538,6 +539,8 @@
1312
>>>514 string !HdrS
1313
# not BeOS
1314
>>>>422 string !Be\ Boot\ Loader
1315
+>>>>>32769 string CD001
1316
+>>>>>>0 use cdrom
1317
# jump over BPB instruction implies DOS bootsector or AdvanceMAME mbr
1318
>>>>>0 ubelong&0xFD000000 =0xE9000000
1319
# AdvanceMAME mbr
1320
@@ -1043,7 +1046,7 @@
1321
>>>>>>466 ubyte <0x10
1322
>>>>>>>466 ubyte 0x05 \b, extended partition table
1323
>>>>>>>466 ubyte 0x0F \b, extended partition table (LBA)
1324
->>>>>>>466 ubyte 0x0 \b, extended partition table (last)
1325
+>>>>>>>466 ubyte 0x0 \b, extended partition table (last)
1326
1327
# DOS x86 sector separated and moved from "DOS/MBR boot sector" by Joerg Jenderek at May 2011
1328
1329
@@ -1236,6 +1239,7 @@
1330
>>>>>181 search/166 Error\ \0
1331
# "a: disk" , "Fn: diskn" or "NetBSD MBR boot"
1332
>>>>>>&3 string x \b,"%s"
1333
+>>>446 use partition-table
1334
# Andrea Mazzoleni AdvanceCD mbr loader of http://advancemame.sourceforge.net/boot-readme.html
1335
# added by Joerg Jenderek at Nov 2012 for versions 1.3 - 1.4
1336
# assembler instructions: jmp short 0x58;nop;ASCII
1337
@@ -1353,18 +1357,19 @@
1338
# minimal short forward jump found 0x29 for bootloaders or 0x0
1339
# maximal short forward jump is 0x7f
1340
# OEM-ID is empty or contain readable bytes
1341
-0 ulelong&0x804000E9 0x000000E9
1342
+0 ulelong&0x804000E9 0x000000E9
1343
+!:strength +60
1344
# mtools-3.9.8/msdos.h
1345
# usual values are marked with comments to get only informations of strange FAT systems
1346
# valid sectorsize must be a power of 2 from 32 to 32768
1347
->11 uleshort&0xf001f 0
1348
+>11 uleshort&0x001f 0
1349
>>11 uleshort <32769
1350
>>>11 uleshort >31
1351
>>>>21 ubyte&0xf0 0xF0
1352
->>>>>0 ubyte 0xEB
1353
+>>>>>0 ubyte 0xEB DOS/MBR boot sector
1354
>>>>>>1 ubyte x \b, code offset 0x%x+2
1355
>>>>>0 ubyte 0xE9
1356
->>>>>>1 uleshort x \b, code offset 0x%x+2
1357
+>>>>>>1 uleshort x \b, code offset 0x%x+3
1358
>>>>>3 string >\0 \b, OEM-ID "%-.8s"
1359
#http://mirror.href.com/thestarman/asm/debug/debug2.htm#IHC
1360
>>>>>>8 string IHC \b cached by Windows 9M
1361
@@ -1373,10 +1378,11 @@
1362
>>>>>11 uleshort <512 \b, Bytes/sector %u
1363
>>>>>13 ubyte >1 \b, sectors/cluster %u
1364
#>>>>>13 ubyte =1 \b, sectors/cluster %u (usual on Floppies)
1365
->>>>>82 string FAT32
1366
+# for lazy FAT32 implementation like Transcend digital photo frame PF830
1367
+>>>>>82 string/c fat32
1368
>>>>>>14 uleshort !32 \b, reserved sectors %u
1369
#>>>>>>14 uleshort =32 \b, reserved sectors %u (usual Fat32)
1370
->>>>>82 string !FAT32
1371
+>>>>>82 string/c !fat32
1372
>>>>>>14 uleshort >1 \b, reserved sectors %u
1373
#>>>>>>14 uleshort =1 \b, reserved sectors %u (usual FAT12,FAT16)
1374
#>>>>>>14 uleshort 0 \b, reserved sectors %u (usual NTFS)
1375
@@ -1399,24 +1405,29 @@
1376
>>>>>26 ubyte =1 \b, heads %u
1377
# valid only for sector sizes with more then 32 Bytes
1378
>>>>>11 uleshort >32
1379
-# skip for Digital Research DOS (version 3.41) 1440 kB Bootdisk
1380
->>>>>>38 ubyte !0x70
1381
+# http://en.wikipedia.org/wiki/Design_of_the_FAT_file_system#Extended_BIOS_Parameter_Block
1382
+# skip for values 2,2Ah,70h,73h,DFh
1383
+# and continue for extended boot signature values 0,28h,29h,80h
1384
+>>>>>>38 ubyte&0x56 =0
1385
>>>>>>>28 ulelong >0 \b, hidden sectors %u
1386
#>>>>>>>28 ulelong =0 \b, hidden sectors %u (usual floppy)
1387
>>>>>>>32 ulelong >0 \b, sectors %u (volumes > 32 MB)
1388
#>>>>>>>32 ulelong =0 \b, sectors %u (volumes > 32 MB)
1389
# FAT<32 bit specific
1390
->>>>>>>82 string !FAT32
1391
+>>>>>>>82 string/c !fat32
1392
#>>>>>>>>36 ubyte 0x80 \b, physical drive 0x%x=0x80 (usual harddisk)
1393
#>>>>>>>>36 ubyte 0 \b, physical drive 0x%x=0 (usual floppy)
1394
>>>>>>>>36 ubyte !0x80
1395
>>>>>>>>>36 ubyte !0 \b, physical drive 0x%x
1396
+# VGA-copy CRC or
1397
+# in Windows NT bit 0 is a dirty flag to request chkdsk at boot time. bit 1 requests surface scan too
1398
>>>>>>>>37 ubyte >0 \b, reserved 0x%x
1399
#>>>>>>>>37 ubyte =0 \b, reserved 0x%x
1400
-# value is 0x80 for NTFS
1401
+# extended boot signatur value is 0x80 for NTFS, 0x28 or 0x29 for others
1402
>>>>>>>>38 ubyte !0x29 \b, dos < 4.0 BootSector (0x%x)
1403
+>>>>>>>>38 ubyte&0xFE =0x28
1404
+>>>>>>>>>39 ulelong x \b, serial number 0x%x
1405
>>>>>>>>38 ubyte =0x29
1406
->>>>>>>>>39 ulelong x \b, serial number 0x%x
1407
>>>>>>>>>43 string <NO\ NAME \b, label: "%11.11s"
1408
>>>>>>>>>43 string >NO\ NAME \b, label: "%11.11s"
1409
>>>>>>>>>43 string =NO\ NAME \b, unlabeled
1410
@@ -1426,11 +1437,35 @@
1411
# if it is small enough FAT is 12 bit, if it is too big enough FAT is 32 bit,
1412
# otherwise FAT is 16 bit.
1413
# http://homepage.ntlworld.com/jonathan.deboynepollard/FGA/determining-fat-widths.html
1414
->>>>>>54 string FAT \b, FAT
1415
->>>>>>>54 string FAT12 \b (12 bit)
1416
->>>>>>>54 string FAT16 \b (16 bit)
1417
+>>>>>82 string/c !fat32
1418
+>>>>>>54 string FAT12 \b, FAT (12 bit)
1419
+>>>>>>54 string FAT16 \b, FAT (16 bit)
1420
+>>>>>>54 default x
1421
+# determinate FAT bit size by media descriptor
1422
+# small floppies implies FAT12
1423
+>>>>>>>21 ubyte <0xF0 \b, FAT (12 bit by descriptor)
1424
+# with media descriptor F0h floppy or maybe superfloppy with FAT16
1425
+>>>>>>>21 ubyte =0xF0
1426
+# superfloppy (many sectors) implies FAT16
1427
+>>>>>>>>32 ulelong >0xFFFF \b, FAT (16 bit by descriptor+sectors)
1428
+# no superfloppy with media descriptor F0h implies FAT12
1429
+>>>>>>>>32 default x \b, FAT (12 bit by descriptor+sectors)
1430
+# with media descriptor F8h floppy or hard disc with FAT12 or FAT16
1431
+>>>>>>>21 ubyte =0xF8
1432
+# 360 KiB with media descriptor F8h, 9 sectors per track ,single sided floppy implies FAT12
1433
+>>>>>>>>19 ubequad 0xd002f80300090001 \b, FAT (12 bit by descriptor+geometry)
1434
+# hard disc with FAT12 or FAT16
1435
+>>>>>>>>19 default x \b, FAT (1Y bit by descriptor)
1436
+# with media descriptor FAh floppy, RAM disc with FAT12 or FAT16 or Tandy hard disc
1437
+>>>>>>>21 ubyte =0xFA
1438
+# 320 KiB with media descriptor FAh, 8 sectors per track ,single sided floppy implies FAT12
1439
+>>>>>>>>19 ubequad 0x8002fa0200080001 \b, FAT (12 bit by descriptor+geometry)
1440
+# RAM disc with FAT12 or FAT16 or Tandy hard disc
1441
+>>>>>>>>19 default x \b, FAT (1Y bit by descriptor)
1442
+# others are floppy
1443
+>>>>>>>21 default x \b, FAT (12 bit by descriptor)
1444
# FAT32 bit specific
1445
->>>>>82 string FAT32 \b, FAT (32 bit)
1446
+>>>>>82 string/c fat32 \b, FAT (32 bit)
1447
>>>>>>36 ulelong x \b, sectors/FAT %u
1448
# http://technet.microsoft.com/en-us/library/cc977221.aspx
1449
>>>>>>40 uleshort >0 \b, extension flags 0x%x
1450
@@ -1443,9 +1478,12 @@
1451
>>>>>>48 uleshort >1 \b, infoSector %u
1452
#>>>>>>48 uleshort =1 \b, infoSector %u (usual)
1453
>>>>>>48 uleshort <1 \b, infoSector %u
1454
->>>>>>50 uleshort >6 \b, Backup boot sector %u
1455
+# 0 or 0xFFFF instead of usual 6 means no backup sector
1456
+>>>>>>50 uleshort =0xFFFF \b, no Backup boot sector
1457
+>>>>>>50 uleshort =0 \b, no Backup boot sector
1458
#>>>>>>50 uleshort =6 \b, Backup boot sector %u (usual)
1459
->>>>>>50 uleshort <6 \b, Backup boot sector %u
1460
+>>>>>>50 default x
1461
+>>>>>>>50 uleshort x \b, Backup boot sector %u
1462
# corrected by Joerg Jenderek at Feb 2011 according to http://thestarman.pcministry.com/asm/mbr/MSWIN41.htm#FSINFO
1463
>>>>>>52 ulelong >0 \b, reserved1 0x%x
1464
>>>>>>56 ulelong >0 \b, reserved2 0x%x
1465
@@ -1880,12 +1918,11 @@
1466
# defect IO.SYS+MSDOS.SYS ?
1467
#>>>>>0x162 use 2xDOS-filename
1468
1469
-# CDROM Filesystems
1470
-# Modified for UDF by [email protected]
1471
-32769 string CD001 #
1472
+0 name cdrom
1473
+>38913 string !NSR0 ISO 9660 CD-ROM filesystem data
1474
!:mime application/x-iso9660-image
1475
->38913 string !NSR0 ISO 9660 CD-ROM filesystem data
1476
>38913 string NSR0 UDF filesystem data
1477
+!:mime application/x-iso9660-image
1478
>>38917 string 1 (version 1.0)
1479
>>38917 string 2 (version 1.5)
1480
>>38917 string 3 (version 2.0)
1481
@@ -1898,6 +1935,18 @@
1482
!:mime application/x-iso9660-image
1483
32777 string CDROM High Sierra CD-ROM filesystem data
1484
1485
+# CDROM Filesystems
1486
+# https://en.wikipedia.org/wiki/ISO_9660
1487
+# Modified for UDF by [email protected]
1488
+32769 string CD001
1489
+# mime line at that position does not work
1490
+# to display CD-ROM (70=81-11) after MBR (113=40+72+1), partition-table (71=50+21) and before Apple Driver Map (51)
1491
+!:strength -11
1492
+# to display CD-ROM (114=81+33) before MBR (113=40+72+1), partition-table (71=50+21) and Apple Driver Map (51)
1493
+# does not work
1494
+#!:strength +33
1495
+>0 use cdrom
1496
+
1497
# .cso files
1498
0 string CISO Compressed ISO CD image
1499
1500
@@ -2080,6 +2129,7 @@
1501
#----------------------------------------------------------
1502
#delta ISO Daniel Novotny ([email protected])
1503
0 string DISO Delta ISO data
1504
+!:strength +50
1505
>4 belong x version %d
1506
1507
# VMS backup savesets - [email protected]
1508
@@ -2131,7 +2181,6 @@
1509
# which is mapped to VBN 2 of [000000]INDEXF.SYS;1 - [email protected]
1510
#
1511
1008 string DECFILE11 Files-11 On-Disk Structure
1512
->525 byte x Level %d
1513
>525 byte x (ODS-%d);
1514
>1017 string A RSX-11, VAX/VMS or OpenVMS VAX file system;
1515
>1017 string B
1516
@@ -2266,14 +2315,31 @@
1517
1518
# UBIfs
1519
# Linux kernel sources: fs/ubifs/ubifs-media.h
1520
-0 belong 0x31181006
1521
->0x16 short 0 UBIfs image
1522
->0x08 lequad x \b, sequence number %llu
1523
->0x10 leshort x \b, length %u
1524
->0x04 lelong x \b, CRC 0x%08x
1525
+0 lelong 0x06101831
1526
+>0x16 leshort 0 UBIfs image
1527
+>0x08 lequad x \b, sequence number %llu
1528
+>0x10 leshort x \b, length %u
1529
+>0x04 lelong x \b, CRC 0x%08x
1530
1531
-0 belong 0x55424923
1532
->0x04 short <2
1533
->0x05 string \0\0\0
1534
->0x1c string \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
1535
->0x04 short x UBI image, version %u
1536
+0 lelong 0x23494255
1537
+>0x04 leshort <2
1538
+>0x05 string \0\0\0
1539
+>0x1c string \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
1540
+>0x04 leshort x UBI image, version %u
1541
+
1542
+# NEC PC-88 2D disk image
1543
+# From Fabio R. Schmidlin <[email protected]>
1544
+0x20 ulelong&0xFFFFFEFF 0x2A0
1545
+>0x10 string \0\0\0\0\0\0\0\0\0\0
1546
+>>0x280 string \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
1547
+>>>0x1A ubyte&0xEF 0
1548
+>>>>0x1B ubyte&0x8F 0
1549
+>>>>>0x1B ubyte&70 <0x40
1550
+>>>>>>0x1C ulelong >0x21
1551
+>>>>>>>0 regex [[:print:]]* NEC PC-88 disk image, name=%s
1552
+>>>>>>>>0x1B ubyte 0 \b, media=2D
1553
+>>>>>>>>0x1B ubyte 0x10 \b, media=2DD
1554
+>>>>>>>>0x1B ubyte 0x20 \b, media=2HD
1555
+>>>>>>>>0x1B ubyte 0x30 \b, media=1D
1556
+>>>>>>>>0x1B ubyte 0x40 \b, media=1DD
1557
+>>>>>>>>0x1A ubyte 0x10 \b, write-protected
1558
Index: contrib/file/magic/Magdir/images
1559
===================================================================
1560
--- contrib/file/magic/Magdir/images (revision 284174)
1561
+++ contrib/file/magic/Magdir/images (working copy)
1562
@@ -1,6 +1,6 @@
1563
1564
#------------------------------------------------------------------------------
1565
-# $File: images,v 1.91 2014/04/30 21:41:02 christos Exp $
1566
+# $File: images,v 1.102 2015/01/02 02:36:35 christos Exp $
1567
# images: file(1) magic for image formats (see also "iff", and "c-lang" for
1568
# XPM bitmaps)
1569
#
1570
@@ -115,9 +115,154 @@
1571
# never changed. The TIFF specification recommends testing for it.
1572
0 string MM\x00\x2a TIFF image data, big-endian
1573
!:mime image/tiff
1574
+>(4.L) use \^tiff_ifd
1575
0 string II\x2a\x00 TIFF image data, little-endian
1576
!:mime image/tiff
1577
+>(4.l) use tiff_ifd
1578
1579
+0 name tiff_ifd
1580
+>0 leshort x \b, direntries=%d
1581
+>2 use tiff_entry
1582
+
1583
+0 name tiff_entry
1584
+# NewSubFileType
1585
+>0 leshort 0xfe
1586
+>>12 use tiff_entry
1587
+>0 leshort 0x100
1588
+>>4 lelong 1
1589
+>>>12 use tiff_entry
1590
+>>>8 leshort x \b, width=%d
1591
+>0 leshort 0x101
1592
+>>4 lelong 1
1593
+>>>8 leshort x \b, height=%d
1594
+>>>12 use tiff_entry
1595
+>0 leshort 0x102
1596
+>>8 leshort x \b, bps=%d
1597
+>>12 use tiff_entry
1598
+>0 leshort 0x103
1599
+>>4 lelong 1 \b, compression=
1600
+>>>8 leshort 1 \bnone
1601
+>>>8 leshort 2 \bhuffman
1602
+>>>8 leshort 3 \bbi-level group 3
1603
+>>>8 leshort 4 \bbi-level group 4
1604
+>>>8 leshort 5 \bLZW
1605
+>>>8 leshort 6 \bJPEG (old)
1606
+>>>8 leshort 7 \bJPEG
1607
+>>>8 leshort 8 \bdeflate
1608
+>>>8 leshort 9 \bJBIG, ITU-T T.85
1609
+>>>8 leshort 0xa \bJBIG, ITU-T T.43
1610
+>>>8 leshort 0x7ffe \bNeXT RLE 2-bit
1611
+>>>8 leshort 0x8005 \bPackBits (Macintosh RLE)
1612
+>>>8 leshort 0x8029 \bThunderscan RLE
1613
+>>>8 leshort 0x807f \bRasterPadding (CT or MP)
1614
+>>>8 leshort 0x8080 \bRLE (Line Work)
1615
+>>>8 leshort 0x8081 \bRLE (High-Res Cont-Tone)
1616
+>>>8 leshort 0x8082 \bRLE (Binary Line Work)
1617
+>>>8 leshort 0x80b2 \bDeflate (PKZIP)
1618
+>>>8 leshort 0x80b3 \bKodak DCS
1619
+>>>8 leshort 0x8765 \bJBIG
1620
+>>>8 leshort 0x8798 \bJPEG2000
1621
+>>>8 leshort 0x8799 \bNikon NEF Compressed
1622
+>>>8 default x
1623
+>>>>8 leshort x \b(unknown 0x%x)
1624
+>>>12 use tiff_entry
1625
+>0 leshort 0x106 \b, PhotometricIntepretation=
1626
+>>8 leshort 0 \bWhiteIsZero
1627
+>>8 leshort 1 \bBlackIsZero
1628
+>>8 leshort 2 \bRGB
1629
+>>8 leshort 3 \bRGB Palette
1630
+>>8 leshort 4 \bTransparency Mask
1631
+>>8 leshort 5 \bCMYK
1632
+>>8 leshort 6 \bYCbCr
1633
+>>8 leshort 8 \bCIELab
1634
+>>>8 leshort x \b(unknown=0x%x)
1635
+>>12 use tiff_entry
1636
+# FillOrder
1637
+>0 leshort 0x10a
1638
+>>4 lelong 1
1639
+>>>12 use tiff_entry
1640
+# DocumentName
1641
+>0 leshort 0x10d
1642
+>>(8.l) string x \b, name=%s
1643
+>>>12 use tiff_entry
1644
+# ImageDescription
1645
+>0 leshort 0x10e
1646
+>>(8.l) string x \b, description=%s
1647
+>>>12 use tiff_entry
1648
+# Make
1649
+>0 leshort 0x10f
1650
+>>(8.l) string x \b, manufacturer=%s
1651
+>>>12 use tiff_entry
1652
+# Model
1653
+>0 leshort 0x110
1654
+>>(8.l) string x \b, model=%s
1655
+>>>12 use tiff_entry
1656
+# StripOffsets
1657
+>0 leshort 0x111
1658
+>>12 use tiff_entry
1659
+# Orientation
1660
+>0 leshort 0x112 \b, orientation=
1661
+>>8 leshort 1 \bupper-left
1662
+>>8 leshort 3 \blower-right
1663
+>>8 leshort 6 \bupper-right
1664
+>>8 leshort 8 \blower-left
1665
+>>8 leshort 9 \bundefined
1666
+>>8 default x
1667
+>>>8 leshort x \b[*%d*]
1668
+>>12 use tiff_entry
1669
+# XResolution
1670
+>0 leshort 0x11a
1671
+>>8 lelong x \b, xresolution=%d
1672
+>>12 use tiff_entry
1673
+# YResolution
1674
+>0 leshort 0x11b
1675
+>>8 lelong x \b, yresolution=%d
1676
+>>12 use tiff_entry
1677
+# ResolutionUnit
1678
+>0 leshort 0x128
1679
+>>8 leshort x \b, resolutionunit=%d
1680
+>>12 use tiff_entry
1681
+# Software
1682
+>0 leshort 0x131
1683
+>>(8.l) string x \b, software=%s
1684
+>>12 use tiff_entry
1685
+# Datetime
1686
+>0 leshort 0x132
1687
+>>(8.l) string x \b, datetime=%s
1688
+>>12 use tiff_entry
1689
+# HostComputer
1690
+>0 leshort 0x13c
1691
+>>(8.l) string x \b, hostcomputer=%s
1692
+>>12 use tiff_entry
1693
+# WhitePoint
1694
+>0 leshort 0x13e
1695
+>>12 use tiff_entry
1696
+# PrimaryChromaticities
1697
+>0 leshort 0x13f
1698
+>>12 use tiff_entry
1699
+# YCbCrCoefficients
1700
+>0 leshort 0x211
1701
+>>12 use tiff_entry
1702
+# YCbCrPositioning
1703
+>0 leshort 0x213
1704
+>>12 use tiff_entry
1705
+# ReferenceBlackWhite
1706
+>0 leshort 0x214
1707
+>>12 use tiff_entry
1708
+# Copyright
1709
+>0 leshort 0x8298
1710
+>>(8.l) string x \b, copyright=%s
1711
+>>12 use tiff_entry
1712
+# ExifOffset
1713
+>0 leshort 0x8769
1714
+>>12 use tiff_entry
1715
+# GPS IFD
1716
+>0 leshort 0x8825 \b, GPS-Data
1717
+>>12 use tiff_entry
1718
+
1719
+#>0 leshort x \b, unknown=0x%x
1720
+#>>12 use tiff_entry
1721
+
1722
0 string MM\x00\x2b Big TIFF image data, big-endian
1723
!:mime image/tiff
1724
0 string II\x2b\x00 Big TIFF image data, little-endian
1725
@@ -892,6 +1037,65 @@
1726
0 string \x46\x4d\x52\x00 ISO/IEC 19794-2 Format Minutiae Record (FMR)
1727
1728
# WEBP https://developers.google.com/speed/webp/docs/riff_container
1729
-0 string RIFF
1730
->8 string WEBP Web/P image data
1731
->>4 lelong x \b, %d bytes
1732
+#0 string RIFF
1733
+#>8 string WEBP Web/P image data
1734
+#>>4 lelong x \b, %d bytes
1735
+
1736
+# doc: http://www.shikino.co.jp/eng/products/images/FLOWER.jpg.zip
1737
+# example: http://www.shikino.co.jp/eng/products/images/FLOWER.wdp.zip
1738
+90 bequad 0x574D50484F544F00 JPEG-XR Image
1739
+>98 byte&0x08 =0x08 \b, hard tiling
1740
+>99 byte&0x80 =0x80 \b, tiling present
1741
+>99 byte&0x40 =0x40 \b, codestream present
1742
+>99 byte&0x38 x \b, spatial xform=
1743
+>99 byte&0x38 0x00 \bTL
1744
+>99 byte&0x38 0x08 \bBL
1745
+>99 byte&0x38 0x10 \bTR
1746
+>99 byte&0x38 0x18 \bBR
1747
+>99 byte&0x38 0x20 \bBT
1748
+>99 byte&0x38 0x28 \bRB
1749
+>99 byte&0x38 0x30 \bLT
1750
+>99 byte&0x38 0x38 \bLB
1751
+>100 byte&0x80 =0x80 \b, short header
1752
+>>102 beshort+1 x \b, %d
1753
+>>104 beshort+1 x \bx%d
1754
+>100 byte&0x80 =0x00 \b, long header
1755
+>>102 belong+1 x \b, %x
1756
+>>106 belong+1 x \bx%x
1757
+>101 beshort&0xf x \b, bitdepth=
1758
+>>101 beshort&0xf 0x0 \b1-WHITE=1
1759
+>>101 beshort&0xf 0x1 \b8
1760
+>>101 beshort&0xf 0x2 \b16
1761
+>>101 beshort&0xf 0x3 \b16-SIGNED
1762
+>>101 beshort&0xf 0x4 \b16-FLOAT
1763
+>>101 beshort&0xf 0x5 \b(reserved 5)
1764
+>>101 beshort&0xf 0x6 \b32-SIGNED
1765
+>>101 beshort&0xf 0x7 \b32-FLOAT
1766
+>>101 beshort&0xf 0x8 \b5
1767
+>>101 beshort&0xf 0x9 \b10
1768
+>>101 beshort&0xf 0xa \b5-6-5
1769
+>>101 beshort&0xf 0xb \b(reserved %d)
1770
+>>101 beshort&0xf 0xc \b(reserved %d)
1771
+>>101 beshort&0xf 0xd \b(reserved %d)
1772
+>>101 beshort&0xf 0xe \b(reserved %d)
1773
+>>101 beshort&0xf 0xf \b1-BLACK=1
1774
+>101 beshort&0xf0 x \b, colorfmt=
1775
+>>101 beshort&0xf0 0x00 \bYONLY
1776
+>>101 beshort&0xf0 0x10 \bYUV240
1777
+>>101 beshort&0xf0 0x20 \bYWV422
1778
+>>101 beshort&0xf0 0x30 \bYWV444
1779
+>>101 beshort&0xf0 0x40 \bCMYK
1780
+>>101 beshort&0xf0 0x50 \bCMYKDIRECT
1781
+>>101 beshort&0xf0 0x60 \bNCOMPONENT
1782
+>>101 beshort&0xf0 0x70 \bRGB
1783
+>>101 beshort&0xf0 0x80 \bRGBE
1784
+>>101 beshort&0xf0 >0x80 \b(reserved 0x%x)
1785
+
1786
+# From: Johan van der Knijff <[email protected]>
1787
+#
1788
+# BPG (Better Portable Graphics) format
1789
+# http://bellard.org/bpg/
1790
+# http://fileformats.archiveteam.org/wiki/BPG
1791
+#
1792
+0 string \x42\x50\x47\xFB BPG (Better Portable Graphics)
1793
+!:mime image/bpg
1794
Index: contrib/file/magic/Magdir/jpeg
1795
===================================================================
1796
--- contrib/file/magic/Magdir/jpeg (revision 284174)
1797
+++ contrib/file/magic/Magdir/jpeg (working copy)
1798
@@ -1,6 +1,6 @@
1799
1800
#------------------------------------------------------------------------------
1801
-# $File: jpeg,v 1.19 2013/02/04 15:50:03 christos Exp $
1802
+# $File: jpeg,v 1.25 2015/01/02 16:56:50 christos Exp $
1803
# JPEG images
1804
# SunOS 5.5.1 had
1805
#
1806
@@ -22,133 +22,74 @@
1807
>>11 byte x \b %d.
1808
>>12 byte x \b%02d
1809
# Next, the resolution or aspect ratio of the image:
1810
-#>>13 byte 0 \b, aspect ratio
1811
-#>>13 byte 1 \b, resolution (DPI)
1812
-#>>13 byte 2 \b, resolution (DPCM)
1813
-#>>4 beshort x \b, segment length %d
1814
+>>13 byte 0 \b, aspect ratio
1815
+>>13 byte 1 \b, resolution (DPI)
1816
+>>13 byte 2 \b, resolution (DPCM)
1817
+>>14 beshort x \b, density %dx
1818
+>>16 beshort x \b%d
1819
+>>4 beshort x \b, segment length %d
1820
# Next, show thumbnail info, if it exists:
1821
>>18 byte !0 \b, thumbnail %dx
1822
>>>19 byte x \b%d
1823
+>6 string Exif \b, Exif standard: [
1824
+>>12 indirect/r x
1825
+>>12 string x \b]
1826
1827
-# EXIF moved down here to avoid reporting a bogus version number,
1828
-# and EXIF version number printing added.
1829
-# - Patrik R=E5dman <[email protected]>
1830
->6 string Exif \b, EXIF standard
1831
-# Look for EXIF IFD offset in IFD 0, and then look for EXIF version tag in EXIF IFD.
1832
-# All possible combinations of entries have to be enumerated, since no looping
1833
-# is possible. And both endians are possible...
1834
-# The combinations included below are from real-world JPEGs.
1835
-# Little-endian
1836
->>12 string II
1837
-# IFD 0 Entry #5:
1838
->>>70 leshort 0x8769
1839
-# EXIF IFD Entry #1:
1840
->>>>(78.l+14) leshort 0x9000
1841
->>>>>(78.l+23) byte x %c
1842
->>>>>(78.l+24) byte x \b.%c
1843
->>>>>(78.l+25) byte !0x30 \b%c
1844
-# IFD 0 Entry #9:
1845
->>>118 leshort 0x8769
1846
-# EXIF IFD Entry #3:
1847
->>>>(126.l+38) leshort 0x9000
1848
->>>>>(126.l+47) byte x %c
1849
->>>>>(126.l+48) byte x \b.%c
1850
->>>>>(126.l+49) byte !0x30 \b%c
1851
-# IFD 0 Entry #10
1852
->>>130 leshort 0x8769
1853
-# EXIF IFD Entry #3:
1854
->>>>(138.l+38) leshort 0x9000
1855
->>>>>(138.l+47) byte x %c
1856
->>>>>(138.l+48) byte x \b.%c
1857
->>>>>(138.l+49) byte !0x30 \b%c
1858
-# EXIF IFD Entry #4:
1859
->>>>(138.l+50) leshort 0x9000
1860
->>>>>(138.l+59) byte x %c
1861
->>>>>(138.l+60) byte x \b.%c
1862
->>>>>(138.l+61) byte !0x30 \b%c
1863
-# EXIF IFD Entry #5:
1864
->>>>(138.l+62) leshort 0x9000
1865
->>>>>(138.l+71) byte x %c
1866
->>>>>(138.l+72) byte x \b.%c
1867
->>>>>(138.l+73) byte !0x30 \b%c
1868
-# IFD 0 Entry #11
1869
->>>142 leshort 0x8769
1870
-# EXIF IFD Entry #3:
1871
->>>>(150.l+38) leshort 0x9000
1872
->>>>>(150.l+47) byte x %c
1873
->>>>>(150.l+48) byte x \b.%c
1874
->>>>>(150.l+49) byte !0x30 \b%c
1875
-# EXIF IFD Entry #4:
1876
->>>>(150.l+50) leshort 0x9000
1877
->>>>>(150.l+59) byte x %c
1878
->>>>>(150.l+60) byte x \b.%c
1879
->>>>>(150.l+61) byte !0x30 \b%c
1880
-# EXIF IFD Entry #5:
1881
->>>>(150.l+62) leshort 0x9000
1882
->>>>>(150.l+71) byte x %c
1883
->>>>>(150.l+72) byte x \b.%c
1884
->>>>>(150.l+73) byte !0x30 \b%c
1885
-# Big-endian
1886
->>12 string MM
1887
-# IFD 0 Entry #9:
1888
->>>118 beshort 0x8769
1889
-# EXIF IFD Entry #1:
1890
->>>>(126.L+14) beshort 0x9000
1891
->>>>>(126.L+23) byte x %c
1892
->>>>>(126.L+24) byte x \b.%c
1893
->>>>>(126.L+25) byte !0x30 \b%c
1894
-# EXIF IFD Entry #3:
1895
->>>>(126.L+38) beshort 0x9000
1896
->>>>>(126.L+47) byte x %c
1897
->>>>>(126.L+48) byte x \b.%c
1898
->>>>>(126.L+49) byte !0x30 \b%c
1899
-# IFD 0 Entry #10
1900
->>>130 beshort 0x8769
1901
-# EXIF IFD Entry #3:
1902
->>>>(138.L+38) beshort 0x9000
1903
->>>>>(138.L+47) byte x %c
1904
->>>>>(138.L+48) byte x \b.%c
1905
->>>>>(138.L+49) byte !0x30 \b%c
1906
-# EXIF IFD Entry #5:
1907
->>>>(138.L+62) beshort 0x9000
1908
->>>>>(138.L+71) byte x %c
1909
->>>>>(138.L+72) byte x \b.%c
1910
->>>>>(138.L+73) byte !0x30 \b%c
1911
-# IFD 0 Entry #11
1912
->>>142 beshort 0x8769
1913
-# EXIF IFD Entry #4:
1914
->>>>(150.L+50) beshort 0x9000
1915
->>>>>(150.L+59) byte x %c
1916
->>>>>(150.L+60) byte x \b.%c
1917
->>>>>(150.L+61) byte !0x30 \b%c
1918
-# Here things get sticky. We can do ONE MORE marker segment with
1919
-# indirect addressing, and that's all. It would be great if we could
1920
-# do pointer arithemetic like in an assembler language. Christos?
1921
-# And if there was some sort of looping construct to do searches, plus a few
1922
-# named accumulators, it would be even more effective...
1923
-# At least we can show a comment if no other segments got inserted before:
1924
->(4.S+5) byte 0xFE \b, comment:
1925
->>(4.S+6) pstring/HJ x "%s"
1926
-# Or, we can show the encoding type (I've included only the three most common)
1927
-# and image dimensions if we are lucky and the SOFn (image segment) is here:
1928
->(4.S+5) byte 0xC0 \b, baseline
1929
->>(4.S+6) byte x \b, precision %d
1930
->>(4.S+7) beshort x \b, %dx
1931
->>(4.S+9) beshort x \b%d
1932
->(4.S+5) byte 0xC1 \b, extended sequential
1933
->>(4.S+6) byte x \b, precision %d
1934
->>(4.S+7) beshort x \b, %dx
1935
->>(4.S+9) beshort x \b%d
1936
->(4.S+5) byte 0xC2 \b, progressive
1937
->>(4.S+6) byte x \b, precision %d
1938
->>(4.S+7) beshort x \b, %dx
1939
->>(4.S+9) beshort x \b%d
1940
-# I've commented-out quantisation table reporting. I doubt anyone cares yet.
1941
-#>(4.S+5) byte 0xDB \b, quantisation table
1942
-#>>(4.S+6) beshort x \b length=%d
1943
-#>14 beshort x \b, %d x
1944
-#>16 beshort x \b %d
1945
+# Jump to the first segment
1946
+>(4.S+4) use jpeg_segment
1947
1948
+# This uses recursion...
1949
+0 name jpeg_segment
1950
+>0 beshort 0xFFFE
1951
+>>(2.S+2) use jpeg_segment
1952
+>>2 pstring/HJ x \b, comment: "%s"
1953
+
1954
+>0 beshort 0xFFC0
1955
+>>(2.S+2) use jpeg_segment
1956
+>>4 byte x \b, baseline, precision %d
1957
+>>7 beshort x \b, %dx
1958
+>>5 beshort x \b%d
1959
+>>9 byte x \b, frames %d
1960
+
1961
+>0 beshort 0xFFC1
1962
+>>(2.S+2) use jpeg_segment
1963
+>>4 byte x \b, extended sequential, precision %d
1964
+>>7 beshort x \b, %dx
1965
+>>5 beshort x \b%d
1966
+>>9 byte x \b, frames %d
1967
+
1968
+>0 beshort 0xFFC2
1969
+>>(2.S+2) use jpeg_segment
1970
+>>4 byte x \b, progressive, precision %d
1971
+>>7 beshort x \b, %dx
1972
+>>5 beshort x \b%d
1973
+>>9 byte x \b, frames %d
1974
+
1975
+# Define Huffman Tables
1976
+>0 beshort 0xFFC4
1977
+>>(2.S+2) use jpeg_segment
1978
+
1979
+>0 beshort 0xFFE1
1980
+#>>(2.S+2) use jpeg_segment
1981
+>>4 string Exif \b, Exif Standard: [
1982
+>>>10 indirect/r x
1983
+>>>10 string x \b]
1984
+
1985
+# Application specific markers
1986
+>0 beshort&0xFFE0 =0xFFE0
1987
+>>(2.S+2) use jpeg_segment
1988
+
1989
+# DB: Define Quantization tables
1990
+# DD: Define Restart interval [XXX: wrong here, it is 4 bytes]
1991
+# D8: Start of image
1992
+# D9: End of image
1993
+# Dn: Restart
1994
+>0 beshort&0xFFD0 =0xFFD0
1995
+>>(2.S+2) use jpeg_segment
1996
+
1997
+#>0 beshort x unknown 0x%x
1998
+#>>(2.S+2) use jpeg_segment
1999
+
2000
# HSI is Handmade Software's proprietary JPEG encoding scheme
2001
0 string hsi1 JPEG image data, HSI proprietary
2002
2003
Index: contrib/file/magic/Magdir/kerberos
2004
===================================================================
2005
--- contrib/file/magic/Magdir/kerberos (revision 0)
2006
+++ contrib/file/magic/Magdir/kerberos (working copy)
2007
@@ -0,0 +1,45 @@
2008
+
2009
+#------------------------------------------------------------------------------
2010
+# $File: kerberos,v 1.1 2014/12/10 18:45:43 christos Exp $
2011
+# kerberos: MIT kerberos file binary formats
2012
+#
2013
+
2014
+# This magic entry is for demonstration purposes and could be improved
2015
+# if the following features were implemented in file:
2016
+#
2017
+# Strings inside [[ .. ]] in the descriptions have special meanings and
2018
+# are not printed.
2019
+#
2020
+# - Provide some form of iteration in number of components
2021
+# [[${counter}=%d]] in the description
2022
+# then append
2023
+# [${counter}--] in the offset of the entries
2024
+# - Provide a way to round the next offset
2025
+# Add [R:4] after the offset?
2026
+# - Provide a way to have optional entries
2027
+# XXX: Syntax:
2028
+# - Provide a way to "save" entries to print them later.
2029
+# if the description is [[${name}=%s]], then nothing is
2030
+# printed and a subsequent entry in the same magic file
2031
+# can refer to ${name}
2032
+# - Provide a way to format strings as hex values
2033
+#
2034
+# http://www.gnu.org/software/shishi/manual/html_node/\
2035
+# The-Keytab-Binary-File-Format.html
2036
+#
2037
+
2038
+0 name keytab_entry
2039
+#>0 beshort x \b, size=%d
2040
+#>2 beshort x \b, components=%d
2041
+>4 pstring/H x \b, realm=%s
2042
+>>&0 pstring/H x \b, principal=%s/
2043
+>>>&0 pstring/H x \b%s
2044
+>>>>&0 belong x \b, type=%d
2045
+>>>>>&0 bedate x \b, date=%s
2046
+>>>>>>&0 byte x \b, kvno=%u
2047
+#>>>>>>>&0 pstring/H x
2048
+#>>>>>>>>&0 belong x
2049
+#>>>>>>>>>>&0 use keytab_entry
2050
+
2051
+0 belong 0x05020000 Kerberos Keytab file
2052
+>4 use keytab_entry
2053
Index: contrib/file/magic/Magdir/linux
2054
===================================================================
2055
--- contrib/file/magic/Magdir/linux (revision 284174)
2056
+++ contrib/file/magic/Magdir/linux (working copy)
2057
@@ -1,6 +1,6 @@
2058
2059
#------------------------------------------------------------------------------
2060
-# $File: linux,v 1.57 2014/05/20 20:10:17 christos Exp $
2061
+# $File: linux,v 1.59 2014/11/03 21:03:36 christos Exp $
2062
# linux: file(1) magic for Linux files
2063
#
2064
# Values for Linux/i386 binaries, from Daniel Quinlan <[email protected]>
2065
@@ -413,3 +413,22 @@
2066
>>>>20 belong >16
2067
>>>>>36 belong x \b, DT structure block size=%d
2068
2069
+# glibc locale archive as defined in glibc locale/locarchive.h
2070
+0 lelong 0xde020109 locale archive
2071
+>24 lelong x %d strings
2072
+
2073
+# Summary: Database file for mlocate
2074
+# Description: A database file as used by mlocate, a fast implementation
2075
+# of locate/updatedb. It uses merging to reuse the existing
2076
+# database and avoid rereading most of the filesystem. It's
2077
+# the default version of locate on Arch Linux (and others).
2078
+# File path: /var/lib/mlocate/mlocate.db by default (but configurable)
2079
+# Site: https://fedorahosted.org/mlocate/
2080
+# Format docs: http://linux.die.net/man/5/mlocate.db
2081
+# Type: mlocate database file
2082
+# URL: https://fedorahosted.org/mlocate/
2083
+# From: Wander Nauta <[email protected]>
2084
+0 string \0mlocate mlocate database
2085
+>12 byte x \b, version %d
2086
+>13 byte 1 \b, require visibility
2087
+>16 string x \b, root %s
2088
Index: contrib/file/magic/Magdir/macintosh
2089
===================================================================
2090
--- contrib/file/magic/Magdir/macintosh (revision 284174)
2091
+++ contrib/file/magic/Magdir/macintosh (working copy)
2092
@@ -1,6 +1,6 @@
2093
2094
#------------------------------------------------------------------------------
2095
-# $File: macintosh,v 1.23 2013/11/19 18:47:58 christos Exp $
2096
+# $File: macintosh,v 1.25 2014/09/03 13:34:16 christos Exp $
2097
# macintosh description
2098
#
2099
# BinHex is the Macintosh ASCII-encoded file format (see also "apple")
2100
@@ -165,7 +165,7 @@
2101
#>65 string ZSYS (Pre-System 7 system file)
2102
#>65 string acf3 (Aldus FreeHand)
2103
#>65 string cdev (control panel)
2104
-#>65 string dfil (Desk Acessory suitcase)
2105
+#>65 string dfil (Desk Accessory suitcase)
2106
#>65 string libr (library)
2107
#>65 string nX^d (WriteNow word processor)
2108
#>65 string nX^w (WriteNow dictionary)
2109
@@ -288,20 +288,38 @@
2110
>0x412 beshort x number of blocks: %d,
2111
>0x424 pstring x volume name: %s
2112
2113
+# *.hfs updated by Joerg Jenderek
2114
+# http://en.wikipedia.org/wiki/Hierarchical_File_System
2115
# "BD" gives many false positives
2116
-#0x400 beshort 0x4244 Macintosh HFS data
2117
-#>0 beshort 0x4C4B (bootable)
2118
-#>0x40a beshort &0x8000 (locked)
2119
-#>0x40a beshort ^0x0100 (mounted)
2120
-#>0x40a beshort &0x0200 (spared blocks)
2121
-#>0x40a beshort &0x0800 (unclean)
2122
-#>0x47C beshort 0x482B (Embedded HFS+ Volume)
2123
-#>0x402 beldate-0x7C25B080 x created: %s,
2124
-#>0x406 beldate-0x7C25B080 x last modified: %s,
2125
-#>0x440 beldate-0x7C25B080 >0 last backup: %s,
2126
-#>0x414 belong x block size: %d,
2127
-#>0x412 beshort x number of blocks: %d,
2128
-#>0x424 pstring x volume name: %s
2129
+0x400 beshort 0x4244
2130
+# ftp://ftp.mars.org/pub/hfs/hfsutils-3.2.6.tar.gz/hfsutils-3.2.6/libhfs/apple.h
2131
+# first block of volume bit map (always 3)
2132
+>0x40e ubeshort 0x0003
2133
+# maximal length of volume name is 27
2134
+>>0x424 ubyte <28 Macintosh HFS data
2135
+#!:mime application/octet-stream
2136
+# these mime and apple types are not sure
2137
+!:mime application/x-apple-diskimage
2138
+#!:apple hfsdINIT
2139
+#!:apple MACSdisk
2140
+>>>0 beshort 0x4C4B (bootable)
2141
+#>>>0 beshort 0x0000 (not bootable)
2142
+>>>0x40a beshort &0x8000 (locked)
2143
+>>>0x40a beshort ^0x0100 (mounted)
2144
+>>>0x40a beshort &0x0200 (spared blocks)
2145
+>>>0x40a beshort &0x0800 (unclean)
2146
+>>>0x47C beshort 0x482B (Embedded HFS+ Volume)
2147
+# http://www.epochconverter.com/
2148
+# 0x7C245F00 seconds ~ 2082758400 ~ 01 Jan 2036 00:00:00 ~ 66 years to 1970
2149
+# 0x7C25B080 seconds ~ 2082844800 ~ 02 Jan 2036 00:00:00
2150
+# construct not working
2151
+#>>>0x402 beldate-0x7C25B080 x created: %s,
2152
+#>>>0x406 beldate-0x7C25B080 x last modified: %s,
2153
+#>>>0x440 beldate-0x7C25B080 >0 last backup: %s,
2154
+# found block sizes 200h,1200h,2800h
2155
+>>>0x414 belong x block size: %d,
2156
+>>>0x412 beshort x number of blocks: %d,
2157
+>>>0x424 pstring x volume name: %s
2158
2159
0x400 beshort 0x482B Macintosh HFS Extended
2160
>&0 beshort x version %d data
2161
@@ -322,43 +340,9 @@
2162
>&42 belong x number of blocks: %d,
2163
>&46 belong x free blocks: %d
2164
2165
-# I don't think this is really necessary since it doesn't do much and
2166
-# anything with a valid driver descriptor will also have a valid
2167
-# partition map
2168
-#0 beshort 0x4552 Apple Device Driver data
2169
-#>&24 beshort =1 \b, MacOS
2170
-
2171
-# Is that the partition type a cstring or a pstring? Well, IM says "strings
2172
-# shorter than 32 bytes must be terminated with NULL" so I'll treat it as a
2173
-# cstring. Of course, partitions can contain more than four entries, but
2174
-# what're you gonna do?
2175
-# GRR: This magic is too weak, it is just "PM"
2176
-#0x200 beshort 0x504D Apple Partition data
2177
-#>0x2 beshort x (block size: %d):
2178
-#>0x230 string x first type: %s,
2179
-#>0x210 string x name: %s,
2180
-#>0x254 belong x number of blocks: %d,
2181
-#>0x400 beshort 0x504D
2182
-#>>0x430 string x second type: %s,
2183
-#>>0x410 string x name: %s,
2184
-#>>0x454 belong x number of blocks: %d,
2185
-#>>0x600 beshort 0x504D
2186
-#>>>0x630 string x third type: %s,
2187
-#>>>0x610 string x name: %s,
2188
-#>>>0x654 belong x number of blocks: %d,
2189
-#>>0x800 beshort 0x504D
2190
-#>>>0x830 string x fourth type: %s,
2191
-#>>>0x810 string x name: %s,
2192
-#>>>0x854 belong x number of blocks: %d,
2193
-#>>>0xa00 beshort 0x504D
2194
-#>>>>0xa30 string x fifth type: %s,
2195
-#>>>>0xa10 string x name: %s,
2196
-#>>>>0xa54 belong x number of blocks: %d
2197
-#>>>0xc00 beshort 0x504D
2198
-#>>>>0xc30 string x sixth type: %s,
2199
-#>>>>0xc10 string x name: %s,
2200
-#>>>>0xc54 belong x number of blocks: %d
2201
## AFAIK, only the signature is different
2202
+# same as Apple Partition Map
2203
+# GRR: This magic is too weak, it is just "TS"
2204
#0x200 beshort 0x5453 Apple Old Partition data
2205
#>0x2 beshort x block size: %d,
2206
#>0x230 string x first type: %s,
2207
Index: contrib/file/magic/Magdir/meteorological
2208
===================================================================
2209
--- contrib/file/magic/Magdir/meteorological (revision 0)
2210
+++ contrib/file/magic/Magdir/meteorological (working copy)
2211
@@ -0,0 +1,49 @@
2212
+
2213
+#------------------------------------------------------------------------------
2214
+# $File: meteorological,v 1.1 2014/08/04 06:26:16 christos Exp $
2215
+# rinex: file(1) magic for RINEX files
2216
+# http://igscb.jpl.nasa.gov/igscb/data/format/rinex210.txt
2217
+# ftp://cddis.gsfc.nasa.gov/pub/reports/formats/rinex300.pdf
2218
+# data for testing: ftp://cddis.gsfc.nasa.gov/pub/gps/data
2219
+60 string RINEX
2220
+>80 search/256 XXRINEXB RINEX Data, GEO SBAS Broadcast
2221
+>>&32 string x \b, date %15.15s
2222
+>>5 string x \b, version %6.6s
2223
+!:mime rinex/broadcast
2224
+>80 search/256 XXRINEXD RINEX Data, Observation (Hatanaka comp)
2225
+>>&32 string x \b, date %15.15s
2226
+>>5 string x \b, version %6.6s
2227
+!:mime rinex/observation
2228
+>80 search/256 XXRINEXC RINEX Data, Clock
2229
+>>&32 string x \b, date %15.15s
2230
+>>5 string x \b, version %6.6s
2231
+!:mime rinex/clock
2232
+>80 search/256 XXRINEXH RINEX Data, GEO SBAS Navigation
2233
+>>&32 string x \b, date %15.15s
2234
+>>5 string x \b, version %6.6s
2235
+!:mime rinex/navigation
2236
+>80 search/256 XXRINEXG RINEX Data, GLONASS Navigation
2237
+>>&32 string x \b, date %15.15s
2238
+>>5 string x \b, version %6.6s
2239
+!:mime rinex/navigation
2240
+>80 search/256 XXRINEXL RINEX Data, Galileo Navigation
2241
+>>&32 string x \b, date %15.15s
2242
+>>5 string x \b, version %6.6s
2243
+!:mime rinex/navigation
2244
+>80 search/256 XXRINEXM RINEX Data, Meteorological
2245
+>>&32 string x \b, date %15.15s
2246
+>>5 string x \b, version %6.6s
2247
+!:mime rinex/meteorological
2248
+>80 search/256 XXRINEXN RINEX Data, Navigation
2249
+>>&32 string x \b, date %15.15s
2250
+>>5 string x \b, version %6.6s
2251
+!:mime rinex/navigation
2252
+>80 search/256 XXRINEXO RINEX Data, Observation
2253
+>>&32 string x \b, date %15.15s
2254
+>>5 string x \b, version %6.6s
2255
+!:mime rinex/observation
2256
+
2257
+# https://en.wikipedia.org/wiki/GRIB
2258
+0 string GRIB
2259
+>7 byte =1 Gridded binary (GRIB) version 1
2260
+>7 byte =2 Gridded binary (GRIB) version 2
2261
Index: contrib/file/magic/Magdir/msooxml
2262
===================================================================
2263
--- contrib/file/magic/Magdir/msooxml (revision 284174)
2264
+++ contrib/file/magic/Magdir/msooxml (working copy)
2265
@@ -1,6 +1,6 @@
2266
2267
#------------------------------------------------------------------------------
2268
-# $File: msooxml,v 1.4 2014/01/06 18:16:24 rrt Exp $
2269
+# $File: msooxml,v 1.5 2014/08/05 07:38:45 christos Exp $
2270
# msooxml: file(1) magic for Microsoft Office XML
2271
# From: Ralf Brown <[email protected]>
2272
2273
@@ -16,7 +16,7 @@
2274
0 string PK\003\004
2275
!:strength +10
2276
# make sure the first file is correct
2277
->0x1E regex \[Content_Types\]\.xml|_rels/\.rels
2278
+>0x1E regex \\[Content_Types\\]\\.xml|_rels/\\.rels
2279
# skip to the second local file header
2280
# since some documents include a 520-byte extra field following the file
2281
# header, we need to scan for the next header
2282
Index: contrib/file/magic/Magdir/netbsd
2283
===================================================================
2284
--- contrib/file/magic/Magdir/netbsd (revision 284174)
2285
+++ contrib/file/magic/Magdir/netbsd (working copy)
2286
@@ -1,6 +1,6 @@
2287
2288
#------------------------------------------------------------------------------
2289
-# $File: netbsd,v 1.21 2014/03/29 15:40:34 christos Exp $
2290
+# $File: netbsd,v 1.22 2014/12/08 20:53:52 christos Exp $
2291
# netbsd: file(1) magic for NetBSD objects
2292
#
2293
# All new-style magic numbers are in network byte order.
2294
@@ -247,7 +247,7 @@
2295
# Kernel core dump format
2296
0 belong&0x0000ffff 0x00008fca NetBSD kernel core file
2297
>0 belong&0x03ff0000 0x00000000 \b, Unknown
2298
->0 belong&0x03ff0000 0x00001000 \b, sun 68010/68020
2299
+>0 belong&0x03ff0000 0x00010000 \b, sun 68010/68020
2300
>0 belong&0x03ff0000 0x00020000 \b, sun 68020
2301
>0 belong&0x03ff0000 0x00640000 \b, 386 PC
2302
>0 belong&0x03ff0000 0x00860000 \b, i386 BSD
2303
@@ -262,20 +262,24 @@
2304
>0 belong&0x03ff0000 0x008f0000 \b, arm6 BSD
2305
>0 belong&0x03ff0000 0x00900000 \b, m68k BSD (2K pages)
2306
>0 belong&0x03ff0000 0x00910000 \b, sh3 BSD
2307
->0 belong&0x03ff0000 0x00920000 \b, ppc BSD (Big Endian)
2308
->0 belong&0x03ff0000 0x00930000 \b, vax BSD (4K pages)
2309
->0 belong&0x03ff0000 0x00940000 \b, mips1 BSD
2310
->0 belong&0x03ff0000 0x00950000 \b, mips2 BSD
2311
->0 belong&0x03ff0000 0x00960000 \b, parisc BSD
2312
->0 belong&0x03ff0000 0x00970000 \b, sh5/64 BSD
2313
->0 belong&0x03ff0000 0x00980000 \b, SPARC/64 BSD
2314
->0 belong&0x03ff0000 0x00990000 \b, amd64 BSD
2315
->0 belong&0x03ff0000 0x009a0000 \b, hp200 (68010) BSD
2316
->0 belong&0x03ff0000 0x009b0000 \b, hp300 (68020+68881) BSD
2317
->0 belong&0x03ff0000 0x009b0000 \b, hp300 (68020+68881) BSD
2318
->0 belong&0x03ff0000 0x00c80000 \b, hp200
2319
->0 belong&0x03ff0000 0x020b0000 \b, hp300 (68020+68881) HP-UX
2320
->0 belong&0x03ff0000 0x020c0000 \b, hp300 (68020+68881) HP-UX
2321
+>0 belong&0x03ff0000 0x00950000 \b, ppc BSD (Big Endian)
2322
+>0 belong&0x03ff0000 0x00960000 \b, vax BSD (4K pages)
2323
+>0 belong&0x03ff0000 0x00970000 \b, mips1 BSD
2324
+>0 belong&0x03ff0000 0x00980000 \b, mips2 BSD
2325
+>0 belong&0x03ff0000 0x00990000 \b, m88k BSD
2326
+>0 belong&0x03ff0000 0x00920000 \b, parisc BSD
2327
+>0 belong&0x03ff0000 0x009b0000 \b, sh5/64 BSD
2328
+>0 belong&0x03ff0000 0x009c0000 \b, SPARC/64 BSD
2329
+>0 belong&0x03ff0000 0x009d0000 \b, amd64 BSD
2330
+>0 belong&0x03ff0000 0x009e0000 \b, sh5/32 BSD
2331
+>0 belong&0x03ff0000 0x009f0000 \b, ia64 BSD
2332
+>0 belong&0x03ff0000 0x00b70000 \b, aarch64 BSD
2333
+>0 belong&0x03ff0000 0x00b80000 \b, or1k BSD
2334
+>0 belong&0x03ff0000 0x00b90000 \b, Risk-V BSD
2335
+>0 belong&0x03ff0000 0x00c80000 \b, hp200 BSD
2336
+>0 belong&0x03ff0000 0x012c0000 \b, hp300 BSD
2337
+>0 belong&0x03ff0000 0x020b0000 \b, hp800 HP-UX
2338
+>0 belong&0x03ff0000 0x020c0000 \b, hp200/hp300 HP-UX
2339
>0 belong&0xfc000000 0x04000000 \b, CPU
2340
>0 belong&0xfc000000 0x08000000 \b, DATA
2341
>0 belong&0xfc000000 0x10000000 \b, STACK
2342
Index: contrib/file/magic/Magdir/pascal
2343
===================================================================
2344
--- contrib/file/magic/Magdir/pascal (revision 284174)
2345
+++ contrib/file/magic/Magdir/pascal (working copy)
2346
@@ -1,10 +1,10 @@
2347
#------------------------------------------------------------------------------
2348
-# $File: pascal,v 1.1 2011/12/08 12:12:46 rrt Exp $
2349
+# $File: pascal,v 1.2 2014/07/14 14:21:33 rrt Exp $
2350
# pascal: file(1) magic for Pascal source
2351
#
2352
0 search/8192 (input, Pascal source text
2353
!:mime text/x-pascal
2354
-0 regex \^program Pascal source text
2355
-!:mime text/x-pascal
2356
-0 regex \^record Pascal source text
2357
-!:mime text/x-pascal
2358
+#0 regex \^program Pascal source text
2359
+#!:mime text/x-pascal
2360
+#0 regex \^record Pascal source text
2361
+#!:mime text/x-pascal
2362
Index: contrib/file/magic/Magdir/pgp
2363
===================================================================
2364
--- contrib/file/magic/Magdir/pgp (revision 284174)
2365
+++ contrib/file/magic/Magdir/pgp (working copy)
2366
@@ -1,6 +1,6 @@
2367
2368
#------------------------------------------------------------------------------
2369
-# $File: pgp,v 1.9 2009/09/19 16:28:11 christos Exp $
2370
+# $File: pgp,v 1.11 2014/11/11 21:32:38 christos Exp $
2371
# pgp: file(1) magic for Pretty Good Privacy
2372
# see http://lists.gnupg.org/pipermail/gnupg-devel/1999-September/016052.html
2373
#
2374
@@ -21,7 +21,449 @@
2375
2376
2 string ---BEGIN\ PGP\ PUBLIC\ KEY\ BLOCK- PGP public key block
2377
!:mime application/pgp-keys
2378
+>10 search/100 \n\n
2379
+>>&0 use pgp
2380
0 string -----BEGIN\040PGP\40MESSAGE- PGP message
2381
!:mime application/pgp
2382
+>10 search/100 \n\n
2383
+>>&0 use pgp
2384
0 string -----BEGIN\040PGP\40SIGNATURE- PGP signature
2385
!:mime application/pgp-signature
2386
+>10 search/100 \n\n
2387
+>>&0 use pgp
2388
+
2389
+# Decode the type of the packet based on it's base64 encoding.
2390
+# Idea from Mark Martinec
2391
+# The specification is in RFC 4880, section 4.2 and 4.3:
2392
+# http://tools.ietf.org/html/rfc4880#section-4.2
2393
+
2394
+0 name pgp
2395
+>0 byte 0x67 Reserved (old)
2396
+>0 byte 0x68 Public-Key Encrypted Session Key (old)
2397
+>0 byte 0x69 Signature (old)
2398
+>0 byte 0x6a Symmetric-Key Encrypted Session Key (old)
2399
+>0 byte 0x6b One-Pass Signature (old)
2400
+>0 byte 0x6c Secret-Key (old)
2401
+>0 byte 0x6d Public-Key (old)
2402
+>0 byte 0x6e Secret-Subkey (old)
2403
+>0 byte 0x6f Compressed Data (old)
2404
+>0 byte 0x70 Symmetrically Encrypted Data (old)
2405
+>0 byte 0x71 Marker (old)
2406
+>0 byte 0x72 Literal Data (old)
2407
+>0 byte 0x73 Trust (old)
2408
+>0 byte 0x74 User ID (old)
2409
+>0 byte 0x75 Public-Subkey (old)
2410
+>0 byte 0x76 Unused (old)
2411
+>0 byte 0x77
2412
+>>1 byte&0xc0 0x00 Reserved
2413
+>>1 byte&0xc0 0x40 Public-Key Encrypted Session Key
2414
+>>1 byte&0xc0 0x80 Signature
2415
+>>1 byte&0xc0 0xc0 Symmetric-Key Encrypted Session Key
2416
+>0 byte 0x78
2417
+>>1 byte&0xc0 0x00 One-Pass Signature
2418
+>>1 byte&0xc0 0x40 Secret-Key
2419
+>>1 byte&0xc0 0x80 Public-Key
2420
+>>1 byte&0xc0 0xc0 Secret-Subkey
2421
+>0 byte 0x79
2422
+>>1 byte&0xc0 0x00 Compressed Data
2423
+>>1 byte&0xc0 0x40 Symmetrically Encrypted Data
2424
+>>1 byte&0xc0 0x80 Marker
2425
+>>1 byte&0xc0 0xc0 Literal Data
2426
+>0 byte 0x7a
2427
+>>1 byte&0xc0 0x00 Trust
2428
+>>1 byte&0xc0 0x40 User ID
2429
+>>1 byte&0xc0 0x80 Public-Subkey
2430
+>>1 byte&0xc0 0xc0 Unused [z%x]
2431
+>0 byte 0x30
2432
+>>1 byte&0xc0 0x00 Unused [0%x]
2433
+>>1 byte&0xc0 0x40 User Attribute
2434
+>>1 byte&0xc0 0x80 Sym. Encrypted and Integrity Protected Data
2435
+>>1 byte&0xc0 0xc0 Modification Detection Code
2436
+
2437
+# magic signatures to detect PGP crypto material (from stef)
2438
+# detects and extracts metadata from:
2439
+# - symmetric encrypted packet header
2440
+# - RSA (e=65537) secret (sub-)keys
2441
+
2442
+# 1024b RSA encrypted data
2443
+
2444
+0 string \x84\x8c\x03 PGP RSA encrypted session key -
2445
+>3 lelong x keyid: %X
2446
+>7 lelong x %X
2447
+>11 byte 0x01 RSA (Encrypt or Sign) 1024b
2448
+>11 byte 0x02 RSA Encrypt-Only 1024b
2449
+>12 string \x04\x00
2450
+>12 string \x03\xff
2451
+>12 string \x03\xfe
2452
+>12 string \x03\xfd
2453
+>12 string \x03\xfc
2454
+>12 string \x03\xfb
2455
+>12 string \x03\xfa
2456
+>12 string \x03\xf9
2457
+>142 byte 0xd2 .
2458
+
2459
+# 2048b RSA encrypted data
2460
+
2461
+0 string \x85\x01\x0c\x03 PGP RSA encrypted session key -
2462
+>4 lelong x keyid: %X
2463
+>8 lelong x %X
2464
+>12 byte 0x01 RSA (Encrypt or Sign) 2048b
2465
+>12 byte 0x02 RSA Encrypt-Only 2048b
2466
+>13 string \x08\x00
2467
+>13 string \x07\xff
2468
+>13 string \x07\xfe
2469
+>13 string \x07\xfd
2470
+>13 string \x07\xfc
2471
+>13 string \x07\xfb
2472
+>13 string \x07\xfa
2473
+>13 string \x07\xf9
2474
+>271 byte 0xd2 .
2475
+
2476
+# 3072b RSA encrypted data
2477
+
2478
+0 string \x85\x01\x8c\x03 PGP RSA encrypted session key -
2479
+>4 lelong x keyid: %X
2480
+>8 lelong x %X
2481
+>12 byte 0x01 RSA (Encrypt or Sign) 3072b
2482
+>12 byte 0x02 RSA Encrypt-Only 3072b
2483
+>13 string \x0c\x00
2484
+>13 string \x0b\xff
2485
+>13 string \x0b\xfe
2486
+>13 string \x0b\xfd
2487
+>13 string \x0b\xfc
2488
+>13 string \x0b\xfb
2489
+>13 string \x0b\xfa
2490
+>13 string \x0b\xf9
2491
+>399 byte 0xd2 .
2492
+
2493
+# 3072b RSA encrypted data
2494
+
2495
+0 string \x85\x02\x0c\x03 PGP RSA encrypted session key -
2496
+>4 lelong x keyid: %X
2497
+>8 lelong x %X
2498
+>12 byte 0x01 RSA (Encrypt or Sign) 4096b
2499
+>12 byte 0x02 RSA Encrypt-Only 4096b
2500
+>13 string \x10\x00
2501
+>13 string \x0f\xff
2502
+>13 string \x0f\xfe
2503
+>13 string \x0f\xfd
2504
+>13 string \x0f\xfc
2505
+>13 string \x0f\xfb
2506
+>13 string \x0f\xfa
2507
+>13 string \x0f\xf9
2508
+>527 byte 0xd2 .
2509
+
2510
+# 4096b RSA encrypted data
2511
+
2512
+0 string \x85\x04\x0c\x03 PGP RSA encrypted session key -
2513
+>4 lelong x keyid: %X
2514
+>8 lelong x %X
2515
+>12 byte 0x01 RSA (Encrypt or Sign) 8129b
2516
+>12 byte 0x02 RSA Encrypt-Only 8129b
2517
+>13 string \x20\x00
2518
+>13 string \x1f\xff
2519
+>13 string \x1f\xfe
2520
+>13 string \x1f\xfd
2521
+>13 string \x1f\xfc
2522
+>13 string \x1f\xfb
2523
+>13 string \x1f\xfa
2524
+>13 string \x1f\xf9
2525
+>1039 byte 0xd2 .
2526
+
2527
+# crypto algo mapper
2528
+
2529
+0 name crypto
2530
+>0 byte 0x00 Plaintext or unencrypted data
2531
+>0 byte 0x01 IDEA
2532
+>0 byte 0x02 TripleDES
2533
+>0 byte 0x03 CAST5 (128 bit key)
2534
+>0 byte 0x04 Blowfish (128 bit key, 16 rounds)
2535
+>0 byte 0x07 AES with 128-bit key
2536
+>0 byte 0x08 AES with 192-bit key
2537
+>0 byte 0x09 AES with 256-bit key
2538
+>0 byte 0x0a Twofish with 256-bit key
2539
+
2540
+# hash algo mapper
2541
+
2542
+0 name hash
2543
+>0 byte 0x01 MD5
2544
+>0 byte 0x02 SHA-1
2545
+>0 byte 0x03 RIPE-MD/160
2546
+>0 byte 0x08 SHA256
2547
+>0 byte 0x09 SHA384
2548
+>0 byte 0x0a SHA512
2549
+>0 byte 0x0b SHA224
2550
+
2551
+# pgp symmetric encrypted data
2552
+
2553
+0 byte 0x8c PGP symmetric key encrypted data -
2554
+>1 byte 0x0d
2555
+>1 byte 0x0c
2556
+>2 byte 0x04
2557
+>3 use crypto
2558
+>4 byte 0x01 salted -
2559
+>>5 use hash
2560
+>>14 byte 0xd2 .
2561
+>>14 byte 0xc9 .
2562
+>4 byte 0x03 salted & iterated -
2563
+>>5 use hash
2564
+>>15 byte 0xd2 .
2565
+>>15 byte 0xc9 .
2566
+
2567
+# encrypted keymaterial needs s2k & can be checksummed/hashed
2568
+
2569
+0 name chkcrypto
2570
+>0 use crypto
2571
+>1 byte 0x00 Simple S2K
2572
+>1 byte 0x01 Salted S2K
2573
+>1 byte 0x03 Salted&Iterated S2K
2574
+>2 use hash
2575
+
2576
+# all PGP keys start with this prolog
2577
+# containing version, creation date, and purpose
2578
+
2579
+0 name keyprolog
2580
+>0 byte 0x04
2581
+>1 beldate x created on %s -
2582
+>5 byte 0x01 RSA (Encrypt or Sign)
2583
+>5 byte 0x02 RSA Encrypt-Only
2584
+
2585
+# end of secret keys known signature
2586
+# contains e=65537 and the prolog to
2587
+# the encrypted parameters
2588
+
2589
+0 name keyend
2590
+>0 string \x00\x11\x01\x00\x01 e=65537
2591
+>5 use crypto
2592
+>5 byte 0xff checksummed
2593
+>>6 use chkcrypto
2594
+>5 byte 0xfe hashed
2595
+>>6 use chkcrypto
2596
+
2597
+# PGP secret keys contain also the public parts
2598
+# these vary by bitsize of the key
2599
+
2600
+0 name x1024
2601
+>0 use keyprolog
2602
+>6 string \x03\xfe
2603
+>6 string \x03\xff
2604
+>6 string \x04\x00
2605
+>136 use keyend
2606
+
2607
+0 name x2048
2608
+>0 use keyprolog
2609
+>6 string \x80\x00
2610
+>6 string \x07\xfe
2611
+>6 string \x07\xff
2612
+>264 use keyend
2613
+
2614
+0 name x3072
2615
+>0 use keyprolog
2616
+>6 string \x0b\xfe
2617
+>6 string \x0b\xff
2618
+>6 string \x0c\x00
2619
+>392 use keyend
2620
+
2621
+0 name x4096
2622
+>0 use keyprolog
2623
+>6 string \x10\x00
2624
+>6 string \x0f\xfe
2625
+>6 string \x0f\xff
2626
+>520 use keyend
2627
+
2628
+# \x00|\x1f[\xfe\xff]).{1024})'
2629
+0 name x8192
2630
+>0 use keyprolog
2631
+>6 string \x20\x00
2632
+>6 string \x1f\xfe
2633
+>6 string \x1f\xff
2634
+>1032 use keyend
2635
+
2636
+# depending on the size of the pkt
2637
+# we branch into the proper key size
2638
+# signatures defined as x{keysize}
2639
+
2640
+>0 name pgpkey
2641
+>0 string \x01\xd8 1024b
2642
+>>2 use x1024
2643
+>0 string \x01\xeb 1024b
2644
+>>2 use x1024
2645
+>0 string \x01\xfb 1024b
2646
+>>2 use x1024
2647
+>0 string \x01\xfd 1024b
2648
+>>2 use x1024
2649
+>0 string \x01\xf3 1024b
2650
+>>2 use x1024
2651
+>0 string \x01\xee 1024b
2652
+>>2 use x1024
2653
+>0 string \x01\xfe 1024b
2654
+>>2 use x1024
2655
+>0 string \x01\xf4 1024b
2656
+>>2 use x1024
2657
+>0 string \x02\x0d 1024b
2658
+>>2 use x1024
2659
+>0 string \x02\x03 1024b
2660
+>>2 use x1024
2661
+>0 string \x02\x05 1024b
2662
+>>2 use x1024
2663
+>0 string \x02\x15 1024b
2664
+>>2 use x1024
2665
+>0 string \x02\x00 1024b
2666
+>>2 use x1024
2667
+>0 string \x02\x10 1024b
2668
+>>2 use x1024
2669
+>0 string \x02\x04 1024b
2670
+>>2 use x1024
2671
+>0 string \x02\x06 1024b
2672
+>>2 use x1024
2673
+>0 string \x02\x16 1024b
2674
+>>2 use x1024
2675
+>0 string \x03\x98 2048b
2676
+>>2 use x2048
2677
+>0 string \x03\xab 2048b
2678
+>>2 use x2048
2679
+>0 string \x03\xbb 2048b
2680
+>>2 use x2048
2681
+>0 string \x03\xbd 2048b
2682
+>>2 use x2048
2683
+>0 string \x03\xcd 2048b
2684
+>>2 use x2048
2685
+>0 string \x03\xb3 2048b
2686
+>>2 use x2048
2687
+>0 string \x03\xc3 2048b
2688
+>>2 use x2048
2689
+>0 string \x03\xc5 2048b
2690
+>>2 use x2048
2691
+>0 string \x03\xd5 2048b
2692
+>>2 use x2048
2693
+>0 string \x03\xae 2048b
2694
+>>2 use x2048
2695
+>0 string \x03\xbe 2048b
2696
+>>2 use x2048
2697
+>0 string \x03\xc0 2048b
2698
+>>2 use x2048
2699
+>0 string \x03\xd0 2048b
2700
+>>2 use x2048
2701
+>0 string \x03\xb4 2048b
2702
+>>2 use x2048
2703
+>0 string \x03\xc4 2048b
2704
+>>2 use x2048
2705
+>0 string \x03\xc6 2048b
2706
+>>2 use x2048
2707
+>0 string \x03\xd6 2048b
2708
+>>2 use x2048
2709
+>0 string \x05X 3072b
2710
+>>2 use x3072
2711
+>0 string \x05k 3072b
2712
+>>2 use x3072
2713
+>0 string \x05{ 3072b
2714
+>>2 use x3072
2715
+>0 string \x05} 3072b
2716
+>>2 use x3072
2717
+>0 string \x05\x8d 3072b
2718
+>>2 use x3072
2719
+>0 string \x05s 3072b
2720
+>>2 use x3072
2721
+>0 string \x05\x83 3072b
2722
+>>2 use x3072
2723
+>0 string \x05\x85 3072b
2724
+>>2 use x3072
2725
+>0 string \x05\x95 3072b
2726
+>>2 use x3072
2727
+>0 string \x05n 3072b
2728
+>>2 use x3072
2729
+>0 string \x05\x7e 3072b
2730
+>>2 use x3072
2731
+>0 string \x05\x80 3072b
2732
+>>2 use x3072
2733
+>0 string \x05\x90 3072b
2734
+>>2 use x3072
2735
+>0 string \x05t 3072b
2736
+>>2 use x3072
2737
+>0 string \x05\x84 3072b
2738
+>>2 use x3072
2739
+>0 string \x05\x86 3072b
2740
+>>2 use x3072
2741
+>0 string \x05\x96 3072b
2742
+>>2 use x3072
2743
+>0 string \x07[ 4096b
2744
+>>2 use x4096
2745
+>0 string \x07\x18 4096b
2746
+>>2 use x4096
2747
+>0 string \x07+ 4096b
2748
+>>2 use x4096
2749
+>0 string \x07; 4096b
2750
+>>2 use x4096
2751
+>0 string \x07= 4096b
2752
+>>2 use x4096
2753
+>0 string \x07M 4096b
2754
+>>2 use x4096
2755
+>0 string \x073 4096b
2756
+>>2 use x4096
2757
+>0 string \x07C 4096b
2758
+>>2 use x4096
2759
+>0 string \x07E 4096b
2760
+>>2 use x4096
2761
+>0 string \x07U 4096b
2762
+>>2 use x4096
2763
+>0 string \x07. 4096b
2764
+>>2 use x4096
2765
+>0 string \x07> 4096b
2766
+>>2 use x4096
2767
+>0 string \x07@ 4096b
2768
+>>2 use x4096
2769
+>0 string \x07P 4096b
2770
+>>2 use x4096
2771
+>0 string \x074 4096b
2772
+>>2 use x4096
2773
+>0 string \x07D 4096b
2774
+>>2 use x4096
2775
+>0 string \x07F 4096b
2776
+>>2 use x4096
2777
+>0 string \x07V 4096b
2778
+>>2 use x4096
2779
+>0 string \x0e[ 8192b
2780
+>>2 use x8192
2781
+>0 string \x0e\x18 8192b
2782
+>>2 use x8192
2783
+>0 string \x0e+ 8192b
2784
+>>2 use x8192
2785
+>0 string \x0e; 8192b
2786
+>>2 use x8192
2787
+>0 string \x0e= 8192b
2788
+>>2 use x8192
2789
+>0 string \x0eM 8192b
2790
+>>2 use x8192
2791
+>0 string \x0e3 8192b
2792
+>>2 use x8192
2793
+>0 string \x0eC 8192b
2794
+>>2 use x8192
2795
+>0 string \x0eE 8192b
2796
+>>2 use x8192
2797
+>0 string \x0eU 8192b
2798
+>>2 use x8192
2799
+>0 string \x0e. 8192b
2800
+>>2 use x8192
2801
+>0 string \x0e> 8192b
2802
+>>2 use x8192
2803
+>0 string \x0e@ 8192b
2804
+>>2 use x8192
2805
+>0 string \x0eP 8192b
2806
+>>2 use x8192
2807
+>0 string \x0e4 8192b
2808
+>>2 use x8192
2809
+>0 string \x0eD 8192b
2810
+>>2 use x8192
2811
+>0 string \x0eF 8192b
2812
+>>2 use x8192
2813
+>0 string \x0eV 8192b
2814
+>>2 use x8192
2815
+
2816
+# PGP RSA (e=65537) secret (sub-)key header
2817
+
2818
+0 byte 0x95 PGP Secret Key -
2819
+>1 use pgpkey
2820
+0 byte 0x97 PGP Secret Sub-key -
2821
+>1 use pgpkey
2822
+0 byte 0x9d PGP Secret Sub-key -
2823
+>1 use pgpkey
2824
Index: contrib/file/magic/Magdir/python
2825
===================================================================
2826
--- contrib/file/magic/Magdir/python (revision 284174)
2827
+++ contrib/file/magic/Magdir/python (working copy)
2828
@@ -1,6 +1,6 @@
2829
2830
#------------------------------------------------------------------------------
2831
-# $File: python,v 1.25 2014/05/06 16:08:32 christos Exp $
2832
+# $File: python,v 1.26 2014/08/04 05:58:40 christos Exp $
2833
# python: file(1) magic for python
2834
#
2835
# Outlook puts """ too for urgent messages
2836
@@ -23,6 +23,7 @@
2837
0 belong 0x4f0c0d0a python 3.1 byte-compiled
2838
0 belong 0x6c0c0d0a python 3.2 byte-compiled
2839
0 belong 0x9e0c0d0a python 3.3 byte-compiled
2840
+0 belong 0xee0c0d0a python 3.4 byte-compiled
2841
2842
0 search/1/w #!\ /usr/bin/python Python script text executable
2843
!:mime text/x-python
2844
Index: contrib/file/magic/Magdir/qt
2845
===================================================================
2846
--- contrib/file/magic/Magdir/qt (revision 0)
2847
+++ contrib/file/magic/Magdir/qt (working copy)
2848
@@ -0,0 +1,19 @@
2849
+
2850
+#------------------------------------------------------------------------------
2851
+# $File: qt,v 1.2 2014/12/16 19:49:29 christos Exp $
2852
+# qt: file(1) magic for Qt
2853
+
2854
+# http://doc.qt.io/qt-5/resources.html
2855
+0 string \<!DOCTYPE\040RCC\> Qt Resource Collection file
2856
+
2857
+# https://qt.gitorious.org/qt/qtbase/source/\
2858
+# 5367fa356233da4c0f28172a8f817791525f5457:\
2859
+# src/tools/rcc/rcc.cpp#L840
2860
+0 string qres\0\0 Qt Binary Resource file
2861
+0 search/1024 The\040Resource\040Compiler\040for\040Qt Qt C-code resource file
2862
+
2863
+# https://qt.gitorious.org/qt/qtbase/source/\
2864
+# 5367fa356233da4c0f28172a8f817791525f5457:\
2865
+# src/corelib/kernel/qtranslator.cpp#L62
2866
+0 string \x3c\xb8\x64\x18\xca\xef\x9c\x95
2867
+>8 string \xcd\x21\x1c\xbf\x60\xa1\xbd\xdd Qt Translation file
2868
Index: contrib/file/magic/Magdir/riff
2869
===================================================================
2870
--- contrib/file/magic/Magdir/riff (revision 284174)
2871
+++ contrib/file/magic/Magdir/riff (working copy)
2872
@@ -1,6 +1,6 @@
2873
2874
#------------------------------------------------------------------------------
2875
-# $File: riff,v 1.27 2014/04/30 21:41:02 christos Exp $
2876
+# $File: riff,v 1.30 2014/09/23 17:02:12 christos Exp $
2877
# riff: file(1) magic for RIFF format
2878
# See
2879
#
2880
@@ -45,6 +45,26 @@
2881
>>&(4.l+4) use riff-walk
2882
>0 string fact
2883
>>&(4.l+4) use riff-walk
2884
+>0 string VP8
2885
+>>11 byte 0x9d
2886
+>>>12 byte 0x01
2887
+>>>>13 byte 0x2a \b, VP8 encoding
2888
+>>>>>14 leshort&0x3fff x \b, %d
2889
+>>>>>16 leshort&0x3fff x \bx%d, Scaling:
2890
+>>>>>14 leshort&0xc000 0x0000 \b [none]
2891
+>>>>>14 leshort&0xc000 0x1000 \b [5/4]
2892
+>>>>>14 leshort&0xc000 0x2000 \b [5/3]
2893
+>>>>>14 leshort&0xc000 0x3000 \b [2]
2894
+>>>>>14 leshort&0xc000 0x0000 \bx[none]
2895
+>>>>>14 leshort&0xc000 0x1000 \bx[5/4]
2896
+>>>>>14 leshort&0xc000 0x2000 \bx[5/3]
2897
+>>>>>14 leshort&0xc000 0x3000 \bx[2]
2898
+>>>>>15 byte&0x80 =0x00 \b, YUV color
2899
+>>>>>15 byte&0x80 =0x80 \b, bad color specification
2900
+>>>>>15 byte&0x40 =0x40 \b, no clamping required
2901
+>>>>>15 byte&0x40 =0x00 \b, decoders should clamp
2902
+#>0 string x we got %s
2903
+#>>&(4.l+4) use riff-walk
2904
2905
# AVI section extended by Patrik Radman <[email protected]>
2906
#
2907
@@ -209,6 +229,8 @@
2908
>8 string 4XMV \b, 4X Movie file
2909
# AMV-type AVI file: http://wiki.multimedia.cx/index.php?title=AMV
2910
>8 string AMV\040 \b, AMV
2911
+>8 string WEBP \b, Web/P image
2912
+>>12 use riff-walk
2913
2914
#
2915
# XXX - some of the below may only appear in little-endian form.
2916
@@ -284,4 +306,3 @@
2917
>>&6 leshort =2 \b, stereo
2918
>>&6 leshort >2 \b, %d channels
2919
>>&8 lelong >0 %d Hz
2920
-
2921
Index: contrib/file/magic/Magdir/rinex
2922
===================================================================
2923
--- contrib/file/magic/Magdir/rinex (revision 284174)
2924
+++ contrib/file/magic/Magdir/rinex (working copy)
2925
@@ -1,44 +0,0 @@
2926
-
2927
-#------------------------------------------------------------------------------
2928
-# $File: rinex,v 1.4 2011/05/03 01:44:17 christos Exp $
2929
-# rinex: file(1) magic for RINEX files
2930
-# http://igscb.jpl.nasa.gov/igscb/data/format/rinex210.txt
2931
-# ftp://cddis.gsfc.nasa.gov/pub/reports/formats/rinex300.pdf
2932
-# data for testing: ftp://cddis.gsfc.nasa.gov/pub/gps/data
2933
-60 string RINEX
2934
->80 search/256 XXRINEXB RINEX Data, GEO SBAS Broadcast
2935
->>&32 string x \b, date %15.15s
2936
->>5 string x \b, version %6.6s
2937
-!:mime rinex/broadcast
2938
->80 search/256 XXRINEXD RINEX Data, Observation (Hatanaka comp)
2939
->>&32 string x \b, date %15.15s
2940
->>5 string x \b, version %6.6s
2941
-!:mime rinex/observation
2942
->80 search/256 XXRINEXC RINEX Data, Clock
2943
->>&32 string x \b, date %15.15s
2944
->>5 string x \b, version %6.6s
2945
-!:mime rinex/clock
2946
->80 search/256 XXRINEXH RINEX Data, GEO SBAS Navigation
2947
->>&32 string x \b, date %15.15s
2948
->>5 string x \b, version %6.6s
2949
-!:mime rinex/navigation
2950
->80 search/256 XXRINEXG RINEX Data, GLONASS Navigation
2951
->>&32 string x \b, date %15.15s
2952
->>5 string x \b, version %6.6s
2953
-!:mime rinex/navigation
2954
->80 search/256 XXRINEXL RINEX Data, Galileo Navigation
2955
->>&32 string x \b, date %15.15s
2956
->>5 string x \b, version %6.6s
2957
-!:mime rinex/navigation
2958
->80 search/256 XXRINEXM RINEX Data, Meteorological
2959
->>&32 string x \b, date %15.15s
2960
->>5 string x \b, version %6.6s
2961
-!:mime rinex/meteorological
2962
->80 search/256 XXRINEXN RINEX Data, Navigation
2963
->>&32 string x \b, date %15.15s
2964
->>5 string x \b, version %6.6s
2965
-!:mime rinex/navigation
2966
->80 search/256 XXRINEXO RINEX Data, Observation
2967
->>&32 string x \b, date %15.15s
2968
->>5 string x \b, version %6.6s
2969
-!:mime rinex/observation
2970
Index: contrib/file/magic/Magdir/sequent
2971
===================================================================
2972
--- contrib/file/magic/Magdir/sequent (revision 284174)
2973
+++ contrib/file/magic/Magdir/sequent (working copy)
2974
@@ -1,6 +1,6 @@
2975
2976
#------------------------------------------------------------------------------
2977
-# $File: sequent,v 1.11 2014/06/02 19:27:54 christos Exp $
2978
+# $File: sequent,v 1.12 2014/08/16 16:07:12 christos Exp $
2979
# sequent: file(1) magic for Sequent machines
2980
#
2981
# Sequent information updated by Don Dwiggins <atsun!dwiggins>.
2982
@@ -30,9 +30,6 @@
2983
0 leshort 0x32eb SYMMETRY i386 executable (invalid @ 0)
2984
>16 lelong >0 not stripped
2985
>124 lelong >0 version %d
2986
-0 leshort 0x42eb SYMMETRY i386 standalone executable
2987
->16 lelong >0 not stripped
2988
->124 lelong >0 version %d
2989
# http://en.wikipedia.org/wiki/Sequent_Computer_Systems
2990
# below test line conflicts with MS-DOS 2.11 floppies and Acronis loader
2991
#0 leshort 0x42eb SYMMETRY i386 standalone executable
2992
Index: contrib/file/magic/Magdir/sereal
2993
===================================================================
2994
--- contrib/file/magic/Magdir/sereal (revision 284174)
2995
+++ contrib/file/magic/Magdir/sereal (working copy)
2996
@@ -1,5 +1,6 @@
2997
+
2998
#------------------------------------------------------------------------------
2999
-# $File: sereal,v 1.1 2014/05/14 23:04:59 christos Exp $
3000
+# $File: sereal,v 1.2 2014/11/11 20:10:49 christos Exp $
3001
# sereal: file(1) magic the Sereal binary serialization format
3002
#
3003
# From: Ævar Arnfjörð Bjarmason <[email protected]>
3004
@@ -15,10 +16,10 @@
3005
#
3006
# See https://github.com/Sereal/Sereal/commit/35372ae01d in the
3007
# Sereal.git repository for test Sereal data.
3008
-0 string \=srl Sereal data
3009
+0 string \=srl Sereal data
3010
!:mime application/sereal
3011
->4 byte&0x0F x (version %d,
3012
->4 byte&0xF0 0x00 uncompressed)
3013
->4 byte&0xF0 0x10 compressed with non-incremental Snappy)
3014
->4 byte&0xF0 0x20 compressed with incremental Snappy)
3015
->4 byte&0xF0 >0x20 unknown subformat, flag: %d>>4)
3016
+>4 byte&0x0F x (version %d,
3017
+>4 byte&0xF0 0x00 uncompressed)
3018
+>4 byte&0xF0 0x10 compressed with non-incremental Snappy)
3019
+>4 byte&0xF0 0x20 compressed with incremental Snappy)
3020
+>4 byte&0xF0 >0x20 unknown subformat, flag: %d>>4)
3021
Index: contrib/file/magic/Magdir/ssh
3022
===================================================================
3023
--- contrib/file/magic/Magdir/ssh (revision 284174)
3024
+++ contrib/file/magic/Magdir/ssh (working copy)
3025
@@ -3,6 +3,7 @@
3026
3027
0 string SSH\ PRIVATE\ KEY OpenSSH RSA1 private key,
3028
>28 string >\0 version %s
3029
+0 string -----BEGIN\ OPENSSH\ PRIVATE\ KEY----- OpenSSH private key
3030
3031
0 string ssh-dss\ OpenSSH DSA public key
3032
0 string ssh-rsa\ OpenSSH RSA public key
3033
@@ -9,3 +10,4 @@
3034
0 string ecdsa-sha2-nistp256 OpenSSH ECDSA public key
3035
0 string ecdsa-sha2-nistp384 OpenSSH ECDSA public key
3036
0 string ecdsa-sha2-nistp521 OpenSSH ECDSA public key
3037
+0 string ssh-ed25519 OpenSSH ED25519 public key
3038
Index: contrib/file/magic/Magdir/vms
3039
===================================================================
3040
--- contrib/file/magic/Magdir/vms (revision 284174)
3041
+++ contrib/file/magic/Magdir/vms (working copy)
3042
@@ -1,6 +1,6 @@
3043
3044
#------------------------------------------------------------------------------
3045
-# $File: vms,v 1.7 2013/03/09 22:36:00 christos Exp $
3046
+# $File: vms,v 1.9 2014/08/17 13:47:59 christos Exp $
3047
# vms: file(1) magic for VMS executables (experimental)
3048
#
3049
# VMS .exe formats, both VAX and AXP (Greg Roelofs, [email protected])
3050
Index: contrib/file/magic/Magdir/vorbis
3051
===================================================================
3052
--- contrib/file/magic/Magdir/vorbis (revision 284174)
3053
+++ contrib/file/magic/Magdir/vorbis (working copy)
3054
@@ -1,6 +1,6 @@
3055
3056
#------------------------------------------------------------------------------
3057
-# $File: vorbis,v 1.18 2014/04/30 21:41:02 christos Exp $
3058
+# $File: vorbis,v 1.20 2014/09/23 16:35:08 christos Exp $
3059
# vorbis: file(1) magic for Ogg/Vorbis files
3060
#
3061
# From Felix von Leitner <[email protected]>
3062
@@ -23,7 +23,6 @@
3063
# --- Ogg Framing ---
3064
#0 search/1000 OggS Ogg data
3065
0 string OggS Ogg data
3066
-!:mime application/ogg
3067
>4 byte !0 UNKNOWN REVISION %u
3068
##>4 byte 0 revision 0
3069
>4 byte 0
3070
@@ -31,9 +30,12 @@
3071
# non-Vorbis content: FLAC (Free Lossless Audio Codec, http://flac.sourceforge.net)
3072
>>28 string \x7fFLAC \b, FLAC audio
3073
# non-Vorbis content: Theora
3074
+!:mime audio/ogg
3075
>>28 string \x80theora \b, Theora video
3076
+!:mime video/ogg
3077
# non-Vorbis content: Kate
3078
->>28 string \x80kate\0\0\0\0 \b, Kate
3079
+>>28 string \x80kate\0\0\0\0 \b, Kate (Karaoke and Text)
3080
+!:mime application/ogg
3081
>>>37 ubyte x v%u
3082
>>>38 ubyte x \b.%u,
3083
>>>40 byte 0 utf8 encoding,
3084
@@ -44,12 +46,15 @@
3085
>>>76 string \0 no category set
3086
# non-Vorbis content: Skeleton
3087
>>28 string fishead\0 \b, Skeleton
3088
+!:mime video/ogg
3089
>>>36 short x v%u
3090
>>>40 short x \b.%u
3091
# non-Vorbis content: Speex
3092
>>28 string Speex\ \ \ \b, Speex audio
3093
+!:mime audio/ogg
3094
# non-Vorbis content: OGM
3095
>>28 string \x01video\0\0\0 \b, OGM video
3096
+!:mime video/ogg
3097
>>>37 string/c div3 (DivX 3)
3098
>>>37 string/c divx (DivX 4)
3099
>>>37 string/c dx50 (DivX 5)
3100
@@ -56,6 +61,7 @@
3101
>>>37 string/c xvid (XviD)
3102
# --- First vorbis packet - general header ---
3103
>>28 string \x01vorbis \b, Vorbis audio,
3104
+!:mime audio/ogg
3105
>>>35 lelong !0 UNKNOWN VERSION %u,
3106
##>>>35 lelong 0 version 0,
3107
>>>35 lelong 0
3108
Index: contrib/file/magic/Magdir/windows
3109
===================================================================
3110
--- contrib/file/magic/Magdir/windows (revision 284174)
3111
+++ contrib/file/magic/Magdir/windows (working copy)
3112
@@ -1,6 +1,6 @@
3113
3114
#------------------------------------------------------------------------------
3115
-# $File: windows,v 1.8 2014/04/30 21:41:02 christos Exp $
3116
+# $File: windows,v 1.10 2014/09/24 19:52:46 christos Exp $
3117
# windows: file(1) magic for Microsoft Windows
3118
#
3119
# This file is mainly reserved for files where programs
3120
@@ -159,8 +159,9 @@
3121
>&0 string Version\ 5.00\r\n\r\n Windows Registry text (Win2K or above)
3122
3123
# Windows *.INF *.INI files updated by Joerg Jenderek at Apr 2013
3124
-# emtpy ,comment , section , unicode line
3125
-0 regex/s \\`(\r\n|;|[[]|\xFF\xFE)
3126
+# empty ,comment , section
3127
+# PR/383: remove unicode BOM because it is not portable across regex impls
3128
+0 regex/s \\`(\\r\\n|;|[[])
3129
# left bracket in section line
3130
>&0 search/8192 [
3131
# http://en.wikipedia.org/wiki/Autorun.inf
3132
Index: contrib/file/magic/Makefile.am
3133
===================================================================
3134
--- contrib/file/magic/Makefile.am (revision 284174)
3135
+++ contrib/file/magic/Makefile.am (working copy)
3136
@@ -1,5 +1,5 @@
3137
#
3138
-# $File: Makefile.am,v 1.98 2014/06/03 18:22:34 christos Exp $
3139
+# $File: Makefile.am,v 1.101 2014/12/12 16:48:39 christos Exp $
3140
#
3141
MAGIC_FRAGMENT_BASE = Magdir
3142
MAGIC_DIR = $(top_srcdir)/magic
3143
@@ -117,6 +117,7 @@ $(MAGIC_FRAGMENT_DIR)/jpeg \
3144
$(MAGIC_FRAGMENT_DIR)/karma \
3145
$(MAGIC_FRAGMENT_DIR)/kde \
3146
$(MAGIC_FRAGMENT_DIR)/keepass \
3147
+$(MAGIC_FRAGMENT_DIR)/kerberos \
3148
$(MAGIC_FRAGMENT_DIR)/kml \
3149
$(MAGIC_FRAGMENT_DIR)/lecter \
3150
$(MAGIC_FRAGMENT_DIR)/lex \
3151
@@ -142,6 +143,7 @@ $(MAGIC_FRAGMENT_DIR)/matroska \
3152
$(MAGIC_FRAGMENT_DIR)/mcrypt \
3153
$(MAGIC_FRAGMENT_DIR)/mercurial \
3154
$(MAGIC_FRAGMENT_DIR)/metastore \
3155
+$(MAGIC_FRAGMENT_DIR)/meteorological \
3156
$(MAGIC_FRAGMENT_DIR)/mime \
3157
$(MAGIC_FRAGMENT_DIR)/mips \
3158
$(MAGIC_FRAGMENT_DIR)/mirage \
3159
@@ -196,9 +198,9 @@ $(MAGIC_FRAGMENT_DIR)/pulsar \
3160
$(MAGIC_FRAGMENT_DIR)/pwsafe \
3161
$(MAGIC_FRAGMENT_DIR)/pyramid \
3162
$(MAGIC_FRAGMENT_DIR)/python \
3163
+$(MAGIC_FRAGMENT_DIR)/qt \
3164
$(MAGIC_FRAGMENT_DIR)/revision \
3165
$(MAGIC_FRAGMENT_DIR)/riff \
3166
-$(MAGIC_FRAGMENT_DIR)/rinex \
3167
$(MAGIC_FRAGMENT_DIR)/rpm \
3168
$(MAGIC_FRAGMENT_DIR)/rtf \
3169
$(MAGIC_FRAGMENT_DIR)/ruby \
3170
Index: contrib/file/magic/Makefile.in
3171
===================================================================
3172
--- contrib/file/magic/Makefile.in (revision 284174)
3173
+++ contrib/file/magic/Makefile.in (working copy)
3174
@@ -262,7 +262,7 @@ top_builddir = @top_builddir@
3175
top_srcdir = @top_srcdir@
3176
3177
#
3178
-# $File: Makefile.am,v 1.98 2014/06/03 18:22:34 christos Exp $
3179
+# $File: Makefile.am,v 1.101 2014/12/12 16:48:39 christos Exp $
3180
#
3181
MAGIC_FRAGMENT_BASE = Magdir
3182
MAGIC_DIR = $(top_srcdir)/magic
3183
@@ -378,6 +378,7 @@ $(MAGIC_FRAGMENT_DIR)/jpeg \
3184
$(MAGIC_FRAGMENT_DIR)/karma \
3185
$(MAGIC_FRAGMENT_DIR)/kde \
3186
$(MAGIC_FRAGMENT_DIR)/keepass \
3187
+$(MAGIC_FRAGMENT_DIR)/kerberos \
3188
$(MAGIC_FRAGMENT_DIR)/kml \
3189
$(MAGIC_FRAGMENT_DIR)/lecter \
3190
$(MAGIC_FRAGMENT_DIR)/lex \
3191
@@ -403,6 +404,7 @@ $(MAGIC_FRAGMENT_DIR)/matroska \
3192
$(MAGIC_FRAGMENT_DIR)/mcrypt \
3193
$(MAGIC_FRAGMENT_DIR)/mercurial \
3194
$(MAGIC_FRAGMENT_DIR)/metastore \
3195
+$(MAGIC_FRAGMENT_DIR)/meteorological \
3196
$(MAGIC_FRAGMENT_DIR)/mime \
3197
$(MAGIC_FRAGMENT_DIR)/mips \
3198
$(MAGIC_FRAGMENT_DIR)/mirage \
3199
@@ -457,9 +459,9 @@ $(MAGIC_FRAGMENT_DIR)/pulsar \
3200
$(MAGIC_FRAGMENT_DIR)/pwsafe \
3201
$(MAGIC_FRAGMENT_DIR)/pyramid \
3202
$(MAGIC_FRAGMENT_DIR)/python \
3203
+$(MAGIC_FRAGMENT_DIR)/qt \
3204
$(MAGIC_FRAGMENT_DIR)/revision \
3205
$(MAGIC_FRAGMENT_DIR)/riff \
3206
-$(MAGIC_FRAGMENT_DIR)/rinex \
3207
$(MAGIC_FRAGMENT_DIR)/rpm \
3208
$(MAGIC_FRAGMENT_DIR)/rtf \
3209
$(MAGIC_FRAGMENT_DIR)/ruby \
3210
Index: contrib/file/src/Makefile.in
3211
===================================================================
3212
--- contrib/file/src/Makefile.in (revision 284174)
3213
+++ contrib/file/src/Makefile.in (working copy)
3214
@@ -81,9 +81,9 @@ build_triplet = @build@
3215
host_triplet = @host@
3216
bin_PROGRAMS = file$(EXEEXT)
3217
subdir = src
3218
-DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am pread.c \
3219
- ctime_r.c getline.c vasprintf.c asprintf.c asctime_r.c \
3220
- fmtcheck.c strlcpy.c getopt_long.c strcasestr.c strlcat.c \
3221
+DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am ctime_r.c \
3222
+ vasprintf.c asctime_r.c asprintf.c strcasestr.c pread.c \
3223
+ getline.c strlcpy.c strlcat.c fmtcheck.c getopt_long.c \
3224
$(top_srcdir)/depcomp $(include_HEADERS)
3225
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
3226
am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \
3227
Index: contrib/file/src/apprentice.c
3228
===================================================================
3229
--- contrib/file/src/apprentice.c (revision 284174)
3230
+++ contrib/file/src/apprentice.c (working copy)
3231
@@ -32,7 +32,7 @@
3232
#include "file.h"
3233
3234
#ifndef lint
3235
-FILE_RCSID("@(#)$File: apprentice.c,v 1.211 2014/06/03 19:01:34 christos Exp $")
3236
+FILE_RCSID("@(#)$File: apprentice.c,v 1.229 2015/01/01 17:07:34 christos Exp $")
3237
#endif /* lint */
3238
3239
#include "magic.h"
3240
@@ -86,6 +86,10 @@
3241
#define ALLOC_CHUNK (size_t)10
3242
#define ALLOC_INCR (size_t)200
3243
3244
+#define MAP_TYPE_MMAP 0
3245
+#define MAP_TYPE_MALLOC 1
3246
+#define MAP_TYPE_USER 2
3247
+
3248
struct magic_entry {
3249
struct magic *mp;
3250
uint32_t cont_count;
3251
@@ -101,6 +105,7 @@ struct magic_entry_set {
3252
struct magic_map {
3253
void *p;
3254
size_t len;
3255
+ int type;
3256
struct magic *magic[MAGIC_SETS];
3257
uint32_t nmagic[MAGIC_SETS];
3258
};
3259
@@ -131,7 +136,10 @@ private uint16_t swap2(uint16_t);
3260
private uint32_t swap4(uint32_t);
3261
private uint64_t swap8(uint64_t);
3262
private char *mkdbname(struct magic_set *, const char *, int);
3263
+private struct magic_map *apprentice_buf(struct magic_set *, struct magic *,
3264
+ size_t);
3265
private struct magic_map *apprentice_map(struct magic_set *, const char *);
3266
+private int check_buffer(struct magic_set *, struct magic_map *, const char *);
3267
private void apprentice_unmap(struct magic_map *);
3268
private int apprentice_compile(struct magic_set *, struct magic_map *,
3269
const char *);
3270
@@ -396,10 +404,11 @@ add_mlist(struct mlist *mlp, struct magic_map *map
3271
{
3272
struct mlist *ml;
3273
3274
+ mlp->map = idx == 0 ? map : NULL;
3275
if ((ml = CAST(struct mlist *, malloc(sizeof(*ml)))) == NULL)
3276
return -1;
3277
3278
- ml->map = idx == 0 ? map : NULL;
3279
+ ml->map = NULL;
3280
ml->magic = map->magic[idx];
3281
ml->nmagic = map->nmagic[idx];
3282
3283
@@ -416,13 +425,11 @@ add_mlist(struct mlist *mlp, struct magic_map *map
3284
private int
3285
apprentice_1(struct magic_set *ms, const char *fn, int action)
3286
{
3287
+ struct magic_map *map;
3288
#ifndef COMPILE_ONLY
3289
struct mlist *ml;
3290
-#endif /* COMPILE_ONLY */
3291
- struct magic_map *map;
3292
-#ifndef COMPILE_ONLY
3293
size_t i;
3294
-#endif /* COMPILE_ONLY */
3295
+#endif
3296
3297
if (magicsize != FILE_MAGICSIZE) {
3298
file_error(ms, 0, "magic element size %lu != %lu",
3299
@@ -451,22 +458,29 @@ apprentice_1(struct magic_set *ms, const char *fn,
3300
for (i = 0; i < MAGIC_SETS; i++) {
3301
if (add_mlist(ms->mlist[i], map, i) == -1) {
3302
file_oomem(ms, sizeof(*ml));
3303
- apprentice_unmap(map);
3304
- return -1;
3305
+ goto fail;
3306
}
3307
}
3308
3309
if (action == FILE_LIST) {
3310
for (i = 0; i < MAGIC_SETS; i++) {
3311
- printf("Set %zu:\nBinary patterns:\n", i);
3312
+ printf("Set %" SIZE_T_FORMAT "u:\nBinary patterns:\n",
3313
+ i);
3314
apprentice_list(ms->mlist[i], BINTEST);
3315
printf("Text patterns:\n");
3316
apprentice_list(ms->mlist[i], TEXTTEST);
3317
}
3318
}
3319
+ return 0;
3320
+fail:
3321
+ for (i = 0; i < MAGIC_SETS; i++) {
3322
+ mlist_free(ms->mlist[i]);
3323
+ ms->mlist[i] = NULL;
3324
+ }
3325
+ return -1;
3326
+#else
3327
+ return 0;
3328
#endif /* COMPILE_ONLY */
3329
-
3330
- return 0;
3331
}
3332
3333
protected void
3334
@@ -510,6 +524,11 @@ file_ms_alloc(int flags)
3335
ms->mlist[i] = NULL;
3336
ms->file = "unknown";
3337
ms->line = 0;
3338
+ ms->indir_max = FILE_INDIR_MAX;
3339
+ ms->name_max = FILE_NAME_MAX;
3340
+ ms->elf_shnum_max = FILE_ELF_SHNUM_MAX;
3341
+ ms->elf_phnum_max = FILE_ELF_PHNUM_MAX;
3342
+ ms->elf_notes_max = FILE_ELF_NOTES_MAX;
3343
return ms;
3344
free:
3345
free(ms);
3346
@@ -521,17 +540,21 @@ apprentice_unmap(struct magic_map *map)
3347
{
3348
if (map == NULL)
3349
return;
3350
- if (map->p != NULL) {
3351
+
3352
+ switch (map->type) {
3353
#ifdef QUICK
3354
- if (map->len)
3355
+ case MAP_TYPE_MMAP:
3356
+ if (map->p)
3357
(void)munmap(map->p, map->len);
3358
- else
3359
+ break;
3360
#endif
3361
+ case MAP_TYPE_MALLOC:
3362
free(map->p);
3363
- } else {
3364
- uint32_t j;
3365
- for (j = 0; j < MAGIC_SETS; j++)
3366
- free(map->magic[j]);
3367
+ break;
3368
+ case MAP_TYPE_USER:
3369
+ break;
3370
+ default:
3371
+ abort();
3372
}
3373
free(map);
3374
}
3375
@@ -550,21 +573,70 @@ mlist_alloc(void)
3376
private void
3377
mlist_free(struct mlist *mlist)
3378
{
3379
- struct mlist *ml;
3380
+ struct mlist *ml, *next;
3381
3382
if (mlist == NULL)
3383
return;
3384
3385
- for (ml = mlist->next; ml != mlist;) {
3386
- struct mlist *next = ml->next;
3387
+ ml = mlist->next;
3388
+ for (ml = mlist->next; (next = ml->next) != NULL; ml = next) {
3389
if (ml->map)
3390
apprentice_unmap(ml->map);
3391
free(ml);
3392
- ml = next;
3393
+ if (ml == mlist)
3394
+ break;
3395
}
3396
- free(ml);
3397
}
3398
3399
+#ifndef COMPILE_ONLY
3400
+/* void **bufs: an array of compiled magic files */
3401
+protected int
3402
+buffer_apprentice(struct magic_set *ms, struct magic **bufs,
3403
+ size_t *sizes, size_t nbufs)
3404
+{
3405
+ size_t i, j;
3406
+ struct mlist *ml;
3407
+ struct magic_map *map;
3408
+
3409
+ if (nbufs == 0)
3410
+ return -1;
3411
+
3412
+ if (ms->mlist[0] != NULL)
3413
+ file_reset(ms);
3414
+
3415
+ init_file_tables();
3416
+
3417
+ for (i = 0; i < MAGIC_SETS; i++) {
3418
+ mlist_free(ms->mlist[i]);
3419
+ if ((ms->mlist[i] = mlist_alloc()) == NULL) {
3420
+ file_oomem(ms, sizeof(*ms->mlist[i]));
3421
+ goto fail;
3422
+ }
3423
+ }
3424
+
3425
+ for (i = 0; i < nbufs; i++) {
3426
+ map = apprentice_buf(ms, bufs[i], sizes[i]);
3427
+ if (map == NULL)
3428
+ goto fail;
3429
+
3430
+ for (j = 0; j < MAGIC_SETS; j++) {
3431
+ if (add_mlist(ms->mlist[j], map, j) == -1) {
3432
+ file_oomem(ms, sizeof(*ml));
3433
+ goto fail;
3434
+ }
3435
+ }
3436
+ }
3437
+
3438
+ return 0;
3439
+fail:
3440
+ for (i = 0; i < MAGIC_SETS; i++) {
3441
+ mlist_free(ms->mlist[i]);
3442
+ ms->mlist[i] = NULL;
3443
+ }
3444
+ return -1;
3445
+}
3446
+#endif
3447
+
3448
/* const char *fn: list of magic files and directories */
3449
protected int
3450
file_apprentice(struct magic_set *ms, const char *fn, int action)
3451
@@ -590,11 +662,9 @@ file_apprentice(struct magic_set *ms, const char *
3452
mlist_free(ms->mlist[i]);
3453
if ((ms->mlist[i] = mlist_alloc()) == NULL) {
3454
file_oomem(ms, sizeof(*ms->mlist[i]));
3455
- if (i != 0) {
3456
- --i;
3457
- do
3458
- mlist_free(ms->mlist[i]);
3459
- while (i != 0);
3460
+ while (i-- > 0) {
3461
+ mlist_free(ms->mlist[i]);
3462
+ ms->mlist[i] = NULL;
3463
}
3464
free(mfn);
3465
return -1;
3466
@@ -1317,7 +1387,7 @@ file_signextend(struct magic_set *ms, struct magic
3467
* the sign extension must have happened.
3468
*/
3469
case FILE_BYTE:
3470
- v = (char) v;
3471
+ v = (signed char) v;
3472
break;
3473
case FILE_SHORT:
3474
case FILE_BESHORT:
3475
@@ -1535,6 +1605,145 @@ check_cond(struct magic_set *ms, int cond, uint32_
3476
}
3477
#endif /* ENABLE_CONDITIONALS */
3478
3479
+private int
3480
+parse_indirect_modifier(struct magic_set *ms, struct magic *m, const char **lp)
3481
+{
3482
+ const char *l = *lp;
3483
+
3484
+ while (!isspace((unsigned char)*++l))
3485
+ switch (*l) {
3486
+ case CHAR_INDIRECT_RELATIVE:
3487
+ m->str_flags |= INDIRECT_RELATIVE;
3488
+ break;
3489
+ default:
3490
+ if (ms->flags & MAGIC_CHECK)
3491
+ file_magwarn(ms, "indirect modifier `%c' "
3492
+ "invalid", *l);
3493
+ *lp = l;
3494
+ return -1;
3495
+ }
3496
+ *lp = l;
3497
+ return 0;
3498
+}
3499
+
3500
+private void
3501
+parse_op_modifier(struct magic_set *ms, struct magic *m, const char **lp,
3502
+ int op)
3503
+{
3504
+ const char *l = *lp;
3505
+ char *t;
3506
+ uint64_t val;
3507
+
3508
+ ++l;
3509
+ m->mask_op |= op;
3510
+ val = (uint64_t)strtoull(l, &t, 0);
3511
+ l = t;
3512
+ m->num_mask = file_signextend(ms, m, val);
3513
+ eatsize(&l);
3514
+ *lp = l;
3515
+}
3516
+
3517
+private int
3518
+parse_string_modifier(struct magic_set *ms, struct magic *m, const char **lp)
3519
+{
3520
+ const char *l = *lp;
3521
+ char *t;
3522
+ int have_range = 0;
3523
+
3524
+ while (!isspace((unsigned char)*++l)) {
3525
+ switch (*l) {
3526
+ case '0': case '1': case '2':
3527
+ case '3': case '4': case '5':
3528
+ case '6': case '7': case '8':
3529
+ case '9':
3530
+ if (have_range && (ms->flags & MAGIC_CHECK))
3531
+ file_magwarn(ms, "multiple ranges");
3532
+ have_range = 1;
3533
+ m->str_range = CAST(uint32_t, strtoul(l, &t, 0));
3534
+ if (m->str_range == 0)
3535
+ file_magwarn(ms, "zero range");
3536
+ l = t - 1;
3537
+ break;
3538
+ case CHAR_COMPACT_WHITESPACE:
3539
+ m->str_flags |= STRING_COMPACT_WHITESPACE;
3540
+ break;
3541
+ case CHAR_COMPACT_OPTIONAL_WHITESPACE:
3542
+ m->str_flags |= STRING_COMPACT_OPTIONAL_WHITESPACE;
3543
+ break;
3544
+ case CHAR_IGNORE_LOWERCASE:
3545
+ m->str_flags |= STRING_IGNORE_LOWERCASE;
3546
+ break;
3547
+ case CHAR_IGNORE_UPPERCASE:
3548
+ m->str_flags |= STRING_IGNORE_UPPERCASE;
3549
+ break;
3550
+ case CHAR_REGEX_OFFSET_START:
3551
+ m->str_flags |= REGEX_OFFSET_START;
3552
+ break;
3553
+ case CHAR_BINTEST:
3554
+ m->str_flags |= STRING_BINTEST;
3555
+ break;
3556
+ case CHAR_TEXTTEST:
3557
+ m->str_flags |= STRING_TEXTTEST;
3558
+ break;
3559
+ case CHAR_TRIM:
3560
+ m->str_flags |= STRING_TRIM;
3561
+ break;
3562
+ case CHAR_PSTRING_1_LE:
3563
+#define SET_LENGTH(a) m->str_flags = (m->str_flags & ~PSTRING_LEN) | (a)
3564
+ if (m->type != FILE_PSTRING)
3565
+ goto bad;
3566
+ SET_LENGTH(PSTRING_1_LE);
3567
+ break;
3568
+ case CHAR_PSTRING_2_BE:
3569
+ if (m->type != FILE_PSTRING)
3570
+ goto bad;
3571
+ SET_LENGTH(PSTRING_2_BE);
3572
+ break;
3573
+ case CHAR_PSTRING_2_LE:
3574
+ if (m->type != FILE_PSTRING)
3575
+ goto bad;
3576
+ SET_LENGTH(PSTRING_2_LE);
3577
+ break;
3578
+ case CHAR_PSTRING_4_BE:
3579
+ if (m->type != FILE_PSTRING)
3580
+ goto bad;
3581
+ SET_LENGTH(PSTRING_4_BE);
3582
+ break;
3583
+ case CHAR_PSTRING_4_LE:
3584
+ switch (m->type) {
3585
+ case FILE_PSTRING:
3586
+ case FILE_REGEX:
3587
+ break;
3588
+ default:
3589
+ goto bad;
3590
+ }
3591
+ SET_LENGTH(PSTRING_4_LE);
3592
+ break;
3593
+ case CHAR_PSTRING_LENGTH_INCLUDES_ITSELF:
3594
+ if (m->type != FILE_PSTRING)
3595
+ goto bad;
3596
+ m->str_flags |= PSTRING_LENGTH_INCLUDES_ITSELF;
3597
+ break;
3598
+ default:
3599
+ bad:
3600
+ if (ms->flags & MAGIC_CHECK)
3601
+ file_magwarn(ms, "string modifier `%c' "
3602
+ "invalid", *l);
3603
+ goto out;
3604
+ }
3605
+ /* allow multiple '/' for readability */
3606
+ if (l[1] == '/' && !isspace((unsigned char)l[2]))
3607
+ l++;
3608
+ }
3609
+ if (string_modifier_check(ms, m) == -1)
3610
+ goto out;
3611
+ *lp = l;
3612
+ return 0;
3613
+out:
3614
+ *lp = l;
3615
+ return -1;
3616
+}
3617
+
3618
/*
3619
* parse one line from magic file, put into magic[index++] if valid
3620
*/
3621
@@ -1804,118 +2013,27 @@ parse(struct magic_set *ms, struct magic_entry *me
3622
m->str_range = 0;
3623
m->str_flags = m->type == FILE_PSTRING ? PSTRING_1_LE : 0;
3624
if ((op = get_op(*l)) != -1) {
3625
- if (!IS_STRING(m->type)) {
3626
- uint64_t val;
3627
- ++l;
3628
- m->mask_op |= op;
3629
- val = (uint64_t)strtoull(l, &t, 0);
3630
- l = t;
3631
- m->num_mask = file_signextend(ms, m, val);
3632
- eatsize(&l);
3633
- }
3634
- else if (op == FILE_OPDIVIDE) {
3635
- int have_range = 0;
3636
- while (!isspace((unsigned char)*++l)) {
3637
- switch (*l) {
3638
- case '0': case '1': case '2':
3639
- case '3': case '4': case '5':
3640
- case '6': case '7': case '8':
3641
- case '9':
3642
- if (have_range &&
3643
- (ms->flags & MAGIC_CHECK))
3644
- file_magwarn(ms,
3645
- "multiple ranges");
3646
- have_range = 1;
3647
- m->str_range = CAST(uint32_t,
3648
- strtoul(l, &t, 0));
3649
- if (m->str_range == 0)
3650
- file_magwarn(ms,
3651
- "zero range");
3652
- l = t - 1;
3653
- break;
3654
- case CHAR_COMPACT_WHITESPACE:
3655
- m->str_flags |=
3656
- STRING_COMPACT_WHITESPACE;
3657
- break;
3658
- case CHAR_COMPACT_OPTIONAL_WHITESPACE:
3659
- m->str_flags |=
3660
- STRING_COMPACT_OPTIONAL_WHITESPACE;
3661
- break;
3662
- case CHAR_IGNORE_LOWERCASE:
3663
- m->str_flags |= STRING_IGNORE_LOWERCASE;
3664
- break;
3665
- case CHAR_IGNORE_UPPERCASE:
3666
- m->str_flags |= STRING_IGNORE_UPPERCASE;
3667
- break;
3668
- case CHAR_REGEX_OFFSET_START:
3669
- m->str_flags |= REGEX_OFFSET_START;
3670
- break;
3671
- case CHAR_BINTEST:
3672
- m->str_flags |= STRING_BINTEST;
3673
- break;
3674
- case CHAR_TEXTTEST:
3675
- m->str_flags |= STRING_TEXTTEST;
3676
- break;
3677
- case CHAR_TRIM:
3678
- m->str_flags |= STRING_TRIM;
3679
- break;
3680
- case CHAR_PSTRING_1_LE:
3681
- if (m->type != FILE_PSTRING)
3682
- goto bad;
3683
- m->str_flags = (m->str_flags & ~PSTRING_LEN) | PSTRING_1_LE;
3684
- break;
3685
- case CHAR_PSTRING_2_BE:
3686
- if (m->type != FILE_PSTRING)
3687
- goto bad;
3688
- m->str_flags = (m->str_flags & ~PSTRING_LEN) | PSTRING_2_BE;
3689
- break;
3690
- case CHAR_PSTRING_2_LE:
3691
- if (m->type != FILE_PSTRING)
3692
- goto bad;
3693
- m->str_flags = (m->str_flags & ~PSTRING_LEN) | PSTRING_2_LE;
3694
- break;
3695
- case CHAR_PSTRING_4_BE:
3696
- if (m->type != FILE_PSTRING)
3697
- goto bad;
3698
- m->str_flags = (m->str_flags & ~PSTRING_LEN) | PSTRING_4_BE;
3699
- break;
3700
- case CHAR_PSTRING_4_LE:
3701
- switch (m->type) {
3702
- case FILE_PSTRING:
3703
- case FILE_REGEX:
3704
- break;
3705
- default:
3706
- goto bad;
3707
- }
3708
- m->str_flags = (m->str_flags & ~PSTRING_LEN) | PSTRING_4_LE;
3709
- break;
3710
- case CHAR_PSTRING_LENGTH_INCLUDES_ITSELF:
3711
- if (m->type != FILE_PSTRING)
3712
- goto bad;
3713
- m->str_flags |= PSTRING_LENGTH_INCLUDES_ITSELF;
3714
- break;
3715
- default:
3716
- bad:
3717
- if (ms->flags & MAGIC_CHECK)
3718
- file_magwarn(ms,
3719
- "string extension `%c' "
3720
- "invalid", *l);
3721
- return -1;
3722
- }
3723
- /* allow multiple '/' for readability */
3724
- if (l[1] == '/' &&
3725
- !isspace((unsigned char)l[2]))
3726
- l++;
3727
+ if (IS_STRING(m->type)) {
3728
+ int r;
3729
+
3730
+ if (op != FILE_OPDIVIDE) {
3731
+ if (ms->flags & MAGIC_CHECK)
3732
+ file_magwarn(ms,
3733
+ "invalid string/indirect op: "
3734
+ "`%c'", *t);
3735
+ return -1;
3736
}
3737
- if (string_modifier_check(ms, m) == -1)
3738
+
3739
+ if (m->type == FILE_INDIRECT)
3740
+ r = parse_indirect_modifier(ms, m, &l);
3741
+ else
3742
+ r = parse_string_modifier(ms, m, &l);
3743
+ if (r == -1)
3744
return -1;
3745
- }
3746
- else {
3747
- if (ms->flags & MAGIC_CHECK)
3748
- file_magwarn(ms, "invalid string op: %c", *t);
3749
- return -1;
3750
- }
3751
+ } else
3752
+ parse_op_modifier(ms, m, &l, op);
3753
}
3754
+
3755
/*
3756
* We used to set mask to all 1's here, instead let's just not do
3757
* anything if mask = 0 (unless you have a better idea)
3758
@@ -2069,8 +2187,14 @@ out:
3759
}
3760
3761
private int
3762
+goodchar(unsigned char x, const char *extra)
3763
+{
3764
+ return (isascii(x) && isalnum(x)) || strchr(extra, x);
3765
+}
3766
+
3767
+private int
3768
parse_extra(struct magic_set *ms, struct magic_entry *me, const char *line,
3769
- off_t off, size_t len, const char *name, int nt)
3770
+ off_t off, size_t len, const char *name, const char *extra, int nt)
3771
{
3772
size_t i;
3773
const char *l = line;
3774
@@ -2091,9 +2215,7 @@ parse_extra(struct magic_set *ms, struct magic_ent
3775
}
3776
3777
EATAB;
3778
- for (i = 0; *l && ((isascii((unsigned char)*l) &&
3779
- isalnum((unsigned char)*l)) || strchr("-+/.", *l)) &&
3780
- i < len; buf[i++] = *l++)
3781
+ for (i = 0; *l && i < len && goodchar(*l, extra); buf[i++] = *l++)
3782
continue;
3783
3784
if (i == len && *l) {
3785
@@ -2103,6 +2225,9 @@ parse_extra(struct magic_set *ms, struct magic_ent
3786
file_magwarn(ms, "%s type `%s' truncated %"
3787
SIZE_T_FORMAT "u", name, line, i);
3788
} else {
3789
+ if (!isspace((unsigned char)*l) && !goodchar(*l, extra))
3790
+ file_magwarn(ms, "%s type `%s' has bad char '%c'",
3791
+ name, line, *l);
3792
if (nt)
3793
buf[i] = '\0';
3794
}
3795
@@ -2109,8 +2234,9 @@ parse_extra(struct magic_set *ms, struct magic_ent
3796
3797
if (i > 0)
3798
return 0;
3799
- else
3800
- return -1;
3801
+
3802
+ file_magerror(ms, "Bad magic entry '%s'", line);
3803
+ return -1;
3804
}
3805
3806
/*
3807
@@ -2123,7 +2249,7 @@ parse_apple(struct magic_set *ms, struct magic_ent
3808
struct magic *m = &me->mp[0];
3809
3810
return parse_extra(ms, me, line, offsetof(struct magic, apple),
3811
- sizeof(m->apple), "APPLE", 0);
3812
+ sizeof(m->apple), "APPLE", "!+-./", 0);
3813
}
3814
3815
/*
3816
@@ -2136,7 +2262,7 @@ parse_mime(struct magic_set *ms, struct magic_entr
3817
struct magic *m = &me->mp[0];
3818
3819
return parse_extra(ms, me, line, offsetof(struct magic, mimetype),
3820
- sizeof(m->mimetype), "MIME", 1);
3821
+ sizeof(m->mimetype), "MIME", "+-/.", 1);
3822
}
3823
3824
private int
3825
@@ -2697,6 +2823,28 @@ eatsize(const char **p)
3826
}
3827
3828
/*
3829
+ * handle a buffer containing a compiled file.
3830
+ */
3831
+private struct magic_map *
3832
+apprentice_buf(struct magic_set *ms, struct magic *buf, size_t len)
3833
+{
3834
+ struct magic_map *map;
3835
+
3836
+ if ((map = CAST(struct magic_map *, calloc(1, sizeof(*map)))) == NULL) {
3837
+ file_oomem(ms, sizeof(*map));
3838
+ return NULL;
3839
+ }
3840
+ map->len = len;
3841
+ map->p = buf;
3842
+ map->type = MAP_TYPE_USER;
3843
+ if (check_buffer(ms, map, "buffer") != 0) {
3844
+ apprentice_unmap(map);
3845
+ return NULL;
3846
+ }
3847
+ return map;
3848
+}
3849
+
3850
+/*
3851
* handle a compiled file.
3852
*/
3853
3854
@@ -2705,12 +2853,8 @@ apprentice_map(struct magic_set *ms, const char *f
3855
{
3856
int fd;
3857
struct stat st;
3858
- uint32_t *ptr;
3859
- uint32_t version, entries, nentries;
3860
- int needsbyteswap;
3861
char *dbname = NULL;
3862
struct magic_map *map;
3863
- size_t i;
3864
3865
fd = -1;
3866
if ((map = CAST(struct magic_map *, calloc(1, sizeof(*map)))) == NULL) {
3867
@@ -2742,6 +2886,7 @@ apprentice_map(struct magic_set *ms, const char *f
3868
file_error(ms, errno, "cannot map `%s'", dbname);
3869
goto error;
3870
}
3871
+ map->type = MAP_TYPE_MMAP;
3872
#else
3873
if ((map->p = CAST(void *, malloc(map->len))) == NULL) {
3874
file_oomem(ms, map->len);
3875
@@ -2751,16 +2896,39 @@ apprentice_map(struct magic_set *ms, const char *f
3876
file_badread(ms);
3877
goto error;
3878
}
3879
- map->len = 0;
3880
+ map->type = MAP_TYPE_MALLOC;
3881
#define RET 1
3882
#endif
3883
(void)close(fd);
3884
fd = -1;
3885
+
3886
+ if (check_buffer(ms, map, dbname) != 0)
3887
+ goto error;
3888
+
3889
+ free(dbname);
3890
+ return map;
3891
+
3892
+error:
3893
+ if (fd != -1)
3894
+ (void)close(fd);
3895
+ apprentice_unmap(map);
3896
+ free(dbname);
3897
+ return NULL;
3898
+}
3899
+
3900
+private int
3901
+check_buffer(struct magic_set *ms, struct magic_map *map, const char *dbname)
3902
+{
3903
+ uint32_t *ptr;
3904
+ uint32_t entries, nentries;
3905
+ uint32_t version;
3906
+ int i, needsbyteswap;
3907
+
3908
ptr = CAST(uint32_t *, map->p);
3909
if (*ptr != MAGICNO) {
3910
if (swap4(*ptr) != MAGICNO) {
3911
file_error(ms, 0, "bad magic in `%s'", dbname);
3912
- goto error;
3913
+ return -1;
3914
}
3915
needsbyteswap = 1;
3916
} else
3917
@@ -2773,15 +2941,14 @@ apprentice_map(struct magic_set *ms, const char *f
3918
file_error(ms, 0, "File %s supports only version %d magic "
3919
"files. `%s' is version %d", VERSION,
3920
VERSIONNO, dbname, version);
3921
- goto error;
3922
+ return -1;
3923
}
3924
- entries = (uint32_t)(st.st_size / sizeof(struct magic));
3925
- if ((off_t)(entries * sizeof(struct magic)) != st.st_size) {
3926
- file_error(ms, 0, "Size of `%s' %" INT64_T_FORMAT "u is not "
3927
+ entries = (uint32_t)(map->len / sizeof(struct magic));
3928
+ if ((entries * sizeof(struct magic)) != map->len) {
3929
+ file_error(ms, 0, "Size of `%s' %" SIZE_T_FORMAT "u is not "
3930
"a multiple of %" SIZE_T_FORMAT "u",
3931
- dbname, (unsigned long long)st.st_size,
3932
- sizeof(struct magic));
3933
- goto error;
3934
+ dbname, map->len, sizeof(struct magic));
3935
+ return -1;
3936
}
3937
map->magic[0] = CAST(struct magic *, map->p) + 1;
3938
nentries = 0;
3939
@@ -2797,20 +2964,12 @@ apprentice_map(struct magic_set *ms, const char *f
3940
if (entries != nentries + 1) {
3941
file_error(ms, 0, "Inconsistent entries in `%s' %u != %u",
3942
dbname, entries, nentries + 1);
3943
- goto error;
3944
+ return -1;
3945
}
3946
if (needsbyteswap)
3947
for (i = 0; i < MAGIC_SETS; i++)
3948
byteswap(map->magic[i], map->nmagic[i]);
3949
- free(dbname);
3950
- return map;
3951
-
3952
-error:
3953
- if (fd != -1)
3954
- (void)close(fd);
3955
- apprentice_unmap(map);
3956
- free(dbname);
3957
- return NULL;
3958
+ return 0;
3959
}
3960
3961
/*
3962
Index: contrib/file/src/ascmagic.c
3963
===================================================================
3964
--- contrib/file/src/ascmagic.c (revision 284174)
3965
+++ contrib/file/src/ascmagic.c (working copy)
3966
@@ -35,7 +35,7 @@
3967
#include "file.h"
3968
3969
#ifndef lint
3970
-FILE_RCSID("@(#)$File: ascmagic.c,v 1.88 2014/02/12 23:20:53 christos Exp $")
3971
+FILE_RCSID("@(#)$File: ascmagic.c,v 1.91 2014/11/28 02:46:39 christos Exp $")
3972
#endif /* lint */
3973
3974
#include "magic.h"
3975
@@ -147,7 +147,8 @@ file_ascmagic_with_encoding(struct magic_set *ms,
3976
== NULL)
3977
goto done;
3978
if ((rv = file_softmagic(ms, utf8_buf,
3979
- (size_t)(utf8_end - utf8_buf), 0, TEXTTEST, text)) == 0)
3980
+ (size_t)(utf8_end - utf8_buf), 0, NULL,
3981
+ TEXTTEST, text)) == 0)
3982
rv = -1;
3983
}
3984
3985
Index: contrib/file/src/cdf.c
3986
===================================================================
3987
--- contrib/file/src/cdf.c (revision 284174)
3988
+++ contrib/file/src/cdf.c (working copy)
3989
@@ -35,7 +35,7 @@
3990
#include "file.h"
3991
3992
#ifndef lint
3993
-FILE_RCSID("@(#)$File: cdf.c,v 1.63 2014/06/09 13:04:37 christos Exp $")
3994
+FILE_RCSID("@(#)$File: cdf.c,v 1.69 2014/12/04 15:56:46 christos Exp $")
3995
#endif
3996
3997
#include <assert.h>
3998
@@ -73,6 +73,8 @@ static union {
3999
#define CDF_TOLE8(x) ((uint64_t)(NEED_SWAP ? _cdf_tole8(x) : (uint64_t)(x)))
4000
#define CDF_TOLE4(x) ((uint32_t)(NEED_SWAP ? _cdf_tole4(x) : (uint32_t)(x)))
4001
#define CDF_TOLE2(x) ((uint16_t)(NEED_SWAP ? _cdf_tole2(x) : (uint16_t)(x)))
4002
+#define CDF_TOLE(x) (sizeof(x) == 2 ? CDF_TOLE2(x) : (sizeof(x) == 4 ? \
4003
+ CDF_TOLE4(x) : CDF_TOLE8(x)))
4004
#define CDF_GETUINT32(x, y) cdf_getuint32(x, y)
4005
4006
4007
@@ -461,6 +463,12 @@ cdf_count_chain(const cdf_sat_t *sat, cdf_secid_t
4008
/ sizeof(maxsector));
4009
4010
DPRINTF(("Chain:"));
4011
+ if (sid == CDF_SECID_END_OF_CHAIN) {
4012
+ /* 0-length chain. */
4013
+ DPRINTF((" empty\n"));
4014
+ return 0;
4015
+ }
4016
+
4017
for (j = i = 0; sid >= 0; i++, j++) {
4018
DPRINTF((" %d", sid));
4019
if (j >= CDF_LOOP_LIMIT) {
4020
@@ -817,13 +825,18 @@ cdf_read_property_info(const cdf_stream_t *sst, co
4021
goto out;
4022
for (i = 0; i < sh.sh_properties; i++) {
4023
size_t tail = (i << 1) + 1;
4024
+ size_t ofs;
4025
if (cdf_check_stream_offset(sst, h, p, tail * sizeof(uint32_t),
4026
__LINE__) == -1)
4027
goto out;
4028
- size_t ofs = CDF_GETUINT32(p, tail);
4029
+ ofs = CDF_GETUINT32(p, tail);
4030
q = (const uint8_t *)(const void *)
4031
((const char *)(const void *)p + ofs
4032
- 2 * sizeof(uint32_t));
4033
+ if (q < p) {
4034
+ DPRINTF(("Wrapped around %p < %p\n", q, p));
4035
+ goto out;
4036
+ }
4037
if (q > e) {
4038
DPRINTF(("Ran of the end %p > %p\n", q, e));
4039
goto out;
4040
@@ -985,8 +998,56 @@ cdf_unpack_summary_info(const cdf_stream_t *sst, c
4041
}
4042
4043
4044
+#define extract_catalog_field(f, l) \
4045
+ memcpy(&ce[i].f, b + (l), sizeof(ce[i].f)); \
4046
+ ce[i].f = CDF_TOLE(ce[i].f)
4047
4048
int
4049
+cdf_unpack_catalog(const cdf_header_t *h, const cdf_stream_t *sst,
4050
+ cdf_catalog_t **cat)
4051
+{
4052
+ size_t ss = sst->sst_dirlen < h->h_min_size_standard_stream ?
4053
+ CDF_SHORT_SEC_SIZE(h) : CDF_SEC_SIZE(h);
4054
+ const char *b = CAST(const char *, sst->sst_tab);
4055
+ const char *eb = b + ss * sst->sst_len;
4056
+ size_t nr, i, k;
4057
+ cdf_catalog_entry_t *ce;
4058
+ uint16_t reclen;
4059
+ const uint16_t *np;
4060
+
4061
+ for (nr = 0; b < eb; nr++) {
4062
+ memcpy(&reclen, b, sizeof(reclen));
4063
+ reclen = CDF_TOLE2(reclen);
4064
+ if (reclen == 0)
4065
+ break;
4066
+ b += reclen;
4067
+ }
4068
+ *cat = CAST(cdf_catalog_t *,
4069
+ malloc(sizeof(cdf_catalog_t) + nr * sizeof(*ce)));
4070
+ (*cat)->cat_num = nr;
4071
+ ce = (*cat)->cat_e;
4072
+ b = CAST(const char *, sst->sst_tab);
4073
+ for (i = 0; i < nr; i++) {
4074
+ extract_catalog_field(ce_namlen, 0);
4075
+ extract_catalog_field(ce_num, 2);
4076
+ extract_catalog_field(ce_timestamp, 6);
4077
+ reclen = ce[i].ce_namlen;
4078
+ ce[i].ce_namlen =
4079
+ sizeof(ce[i].ce_name) / sizeof(ce[i].ce_name[0]) - 1;
4080
+ if (ce[i].ce_namlen > reclen - 14)
4081
+ ce[i].ce_namlen = reclen - 14;
4082
+ np = CAST(const uint16_t *, (b + 16));
4083
+ for (k = 0; k < ce[i].ce_namlen; k++) {
4084
+ ce[i].ce_name[k] = np[k];
4085
+ CDF_TOLE2(ce[i].ce_name[k]);
4086
+ }
4087
+ ce[i].ce_name[ce[i].ce_namlen] = 0;
4088
+ b += reclen;
4089
+ }
4090
+ return 0;
4091
+}
4092
+
4093
+int
4094
cdf_print_classid(char *buf, size_t buflen, const cdf_classid_t *id)
4095
{
4096
return snprintf(buf, buflen, "%.8x-%.4x-%.4x-%.2x%.2x-"
4097
@@ -1068,6 +1129,15 @@ cdf_print_elapsed_time(char *buf, size_t bufsiz, c
4098
return len;
4099
}
4100
4101
+char *
4102
+cdf_u16tos8(char *buf, size_t len, const uint16_t *p)
4103
+{
4104
+ size_t i;
4105
+ for (i = 0; i < len && p[i]; i++)
4106
+ buf[i] = (char)p[i];
4107
+ buf[i] = '\0';
4108
+ return buf;
4109
+}
4110
4111
#ifdef CDF_DEBUG
4112
void
4113
@@ -1093,7 +1163,7 @@ cdf_dump_header(const cdf_header_t *h)
4114
for (i = 0; i < __arraycount(h->h_master_sat); i++) {
4115
if (h->h_master_sat[i] == CDF_SECID_FREE)
4116
break;
4117
- (void)fprintf(stderr, "%35.35s[%.3zu] = %d\n",
4118
+ (void)fprintf(stderr, "%35.35s[%.3" SIZE_T_FORMAT "u] = %d\n",
4119
"master_sat", i, h->h_master_sat[i]);
4120
}
4121
}
4122
@@ -1288,7 +1358,7 @@ cdf_dump_summary_info(const cdf_header_t *h, const
4123
return;
4124
(void)fprintf(stderr, "Endian: %x\n", ssi.si_byte_order);
4125
(void)fprintf(stderr, "Os Version %d.%d\n", ssi.si_os_version & 0xff,
4126
- ssi.si_os_version >> 8);
4127
+ ssi.si_os_version >> 8);
4128
(void)fprintf(stderr, "Os %d\n", ssi.si_os);
4129
cdf_print_classid(buf, sizeof(buf), &ssi.si_class);
4130
(void)fprintf(stderr, "Class %s\n", buf);
4131
@@ -1297,6 +1367,27 @@ cdf_dump_summary_info(const cdf_header_t *h, const
4132
free(info);
4133
}
4134
4135
+
4136
+void
4137
+cdf_dump_catalog(const cdf_header_t *h, const cdf_stream_t *sst)
4138
+{
4139
+ cdf_catalog_t *cat;
4140
+ cdf_unpack_catalog(h, sst, &cat);
4141
+ const cdf_catalog_entry_t *ce = cat->cat_e;
4142
+ struct timespec ts;
4143
+ char tbuf[64], sbuf[256];
4144
+ size_t i;
4145
+
4146
+ printf("Catalog:\n");
4147
+ for (i = 0; i < cat->cat_num; i++) {
4148
+ cdf_timestamp_to_timespec(&ts, ce[i].ce_timestamp);
4149
+ printf("\t%d %s %s", ce[i].ce_num,
4150
+ cdf_u16tos8(sbuf, ce[i].ce_namlen, ce[i].ce_name),
4151
+ cdf_ctime(&ts.tv_sec, tbuf));
4152
+ }
4153
+ free(cat);
4154
+}
4155
+
4156
#endif
4157
4158
#ifdef TEST
4159
@@ -1309,6 +1400,7 @@ main(int argc, char *argv[])
4160
cdf_stream_t sst, scn;
4161
cdf_dir_t dir;
4162
cdf_info_t info;
4163
+ const cdf_directory_t *root;
4164
4165
if (argc < 2) {
4166
(void)fprintf(stderr, "Usage: %s <filename>\n", getprogname());
4167
@@ -1342,7 +1434,8 @@ main(int argc, char *argv[])
4168
if (cdf_read_dir(&info, &h, &sat, &dir) == -1)
4169
err(1, "Cannot read dir");
4170
4171
- if (cdf_read_short_stream(&info, &h, &sat, &dir, &sst) == -1)
4172
+ if (cdf_read_short_stream(&info, &h, &sat, &dir, &sst, &root)
4173
+ == -1)
4174
err(1, "Cannot read short stream");
4175
#ifdef CDF_DEBUG
4176
cdf_dump_stream(&h, &sst);
4177
@@ -1355,10 +1448,18 @@ main(int argc, char *argv[])
4178
4179
if (cdf_read_summary_info(&info, &h, &sat, &ssat, &sst, &dir,
4180
&scn) == -1)
4181
- err(1, "Cannot read summary info");
4182
+ warn("Cannot read summary info");
4183
#ifdef CDF_DEBUG
4184
- cdf_dump_summary_info(&h, &scn);
4185
+ else
4186
+ cdf_dump_summary_info(&h, &scn);
4187
#endif
4188
+ if (cdf_read_catalog(&info, &h, &sat, &ssat, &sst, &dir,
4189
+ &scn) == -1)
4190
+ warn("Cannot read catalog");
4191
+#ifdef CDF_DEBUG
4192
+ else
4193
+ cdf_dump_catalog(&h, &scn);
4194
+#endif
4195
4196
(void)close(info.i_fd);
4197
}
4198
Index: contrib/file/src/cdf.h
4199
===================================================================
4200
--- contrib/file/src/cdf.h (revision 284174)
4201
+++ contrib/file/src/cdf.h (working copy)
4202
@@ -267,6 +267,19 @@ typedef struct {
4203
size_t i_len;
4204
} cdf_info_t;
4205
4206
+
4207
+typedef struct {
4208
+ uint16_t ce_namlen;
4209
+ uint32_t ce_num;
4210
+ uint64_t ce_timestamp;
4211
+ uint16_t ce_name[256];
4212
+} cdf_catalog_entry_t;
4213
+
4214
+typedef struct {
4215
+ size_t cat_num;
4216
+ cdf_catalog_entry_t cat_e[0];
4217
+} cdf_catalog_t;
4218
+
4219
struct timespec;
4220
int cdf_timestamp_to_timespec(struct timespec *, cdf_timestamp_t);
4221
int cdf_timespec_to_timestamp(cdf_timestamp_t *, const struct timespec *);
4222
@@ -301,11 +314,19 @@ int cdf_read_property_info(const cdf_stream_t *, c
4223
int cdf_read_user_stream(const cdf_info_t *, const cdf_header_t *,
4224
const cdf_sat_t *, const cdf_sat_t *, const cdf_stream_t *,
4225
const cdf_dir_t *, const char *, cdf_stream_t *);
4226
+#define cdf_read_catalog(info, header, sat, ssat, stream, dir, scn) \
4227
+ cdf_read_user_stream(info, header, sat, ssat, stream, dir, "Catalog", \
4228
+ scn)
4229
+#define cdf_read_encrypted_package(info, header, sat, ssat, stream, dir, scn) \
4230
+ cdf_read_user_stream(info, header, sat, ssat, stream, dir, \
4231
+ "EncryptedPackage", scn)
4232
int cdf_read_summary_info(const cdf_info_t *, const cdf_header_t *,
4233
const cdf_sat_t *, const cdf_sat_t *, const cdf_stream_t *,
4234
const cdf_dir_t *, cdf_stream_t *);
4235
int cdf_unpack_summary_info(const cdf_stream_t *, const cdf_header_t *,
4236
cdf_summary_info_header_t *, cdf_property_info_t **, size_t *);
4237
+int cdf_unpack_catalog(const cdf_header_t *, const cdf_stream_t *,
4238
+ cdf_catalog_t **);
4239
int cdf_print_classid(char *, size_t, const cdf_classid_t *);
4240
int cdf_print_property_name(char *, size_t, uint32_t);
4241
int cdf_print_elapsed_time(char *, size_t, cdf_timestamp_t);
4242
@@ -313,6 +334,7 @@ uint16_t cdf_tole2(uint16_t);
4243
uint32_t cdf_tole4(uint32_t);
4244
uint64_t cdf_tole8(uint64_t);
4245
char *cdf_ctime(const time_t *, char *);
4246
+char *cdf_u16tos8(char *, size_t, const uint16_t *);
4247
4248
#ifdef CDF_DEBUG
4249
void cdf_dump_header(const cdf_header_t *);
4250
@@ -323,6 +345,7 @@ void cdf_dump_dir(const cdf_info_t *, const cdf_he
4251
const cdf_sat_t *, const cdf_stream_t *, const cdf_dir_t *);
4252
void cdf_dump_property_info(const cdf_property_info_t *, size_t);
4253
void cdf_dump_summary_info(const cdf_header_t *, const cdf_stream_t *);
4254
+void cdf_dump_catalog(const cdf_header_t *, const cdf_stream_t *);
4255
#endif
4256
4257
4258
Index: contrib/file/src/compress.c
4259
===================================================================
4260
--- contrib/file/src/compress.c (revision 284174)
4261
+++ contrib/file/src/compress.c (working copy)
4262
@@ -35,7 +35,7 @@
4263
#include "file.h"
4264
4265
#ifndef lint
4266
-FILE_RCSID("@(#)$File: compress.c,v 1.73 2014/01/05 15:55:21 christos Exp $")
4267
+FILE_RCSID("@(#)$File: compress.c,v 1.77 2014/12/12 16:33:01 christos Exp $")
4268
#endif
4269
4270
#include "magic.h"
4271
@@ -45,7 +45,8 @@
4272
#endif
4273
#include <string.h>
4274
#include <errno.h>
4275
-#ifndef __MINGW32__
4276
+#include <signal.h>
4277
+#if !defined(__MINGW32__) && !defined(WIN32)
4278
#include <sys/ioctl.h>
4279
#endif
4280
#ifdef HAVE_SYS_WAIT_H
4281
@@ -103,10 +104,12 @@ file_zmagic(struct magic_set *ms, int fd, const ch
4282
size_t i, nsz;
4283
int rv = 0;
4284
int mime = ms->flags & MAGIC_MIME;
4285
+ sig_t osigpipe;
4286
4287
if ((ms->flags & MAGIC_COMPRESS) == 0)
4288
return 0;
4289
4290
+ osigpipe = signal(SIGPIPE, SIG_IGN);
4291
for (i = 0; i < ncompr; i++) {
4292
if (nbytes < compr[i].maglen)
4293
continue;
4294
@@ -133,6 +136,7 @@ file_zmagic(struct magic_set *ms, int fd, const ch
4295
}
4296
}
4297
error:
4298
+ (void)signal(SIGPIPE, osigpipe);
4299
free(newbuf);
4300
ms->flags |= MAGIC_COMPRESS;
4301
return rv;
4302
@@ -377,6 +381,7 @@ uncompressbuf(struct magic_set *ms, int fd, size_t
4303
const unsigned char *old, unsigned char **newch, size_t n)
4304
{
4305
int fdin[2], fdout[2];
4306
+ int status;
4307
ssize_t r;
4308
pid_t pid;
4309
4310
@@ -459,7 +464,17 @@ uncompressbuf(struct magic_set *ms, int fd, size_t
4311
/*NOTREACHED*/
4312
4313
default: /* parent */
4314
- break;
4315
+ if (wait(&status) == -1) {
4316
+#ifdef DEBUG
4317
+ (void)fprintf(stderr,
4318
+ "Wait failed (%s)\n",
4319
+ strerror(errno));
4320
+#endif
4321
+ exit(1);
4322
+ }
4323
+ exit(WIFEXITED(status) ?
4324
+ WEXITSTATUS(status) : 1);
4325
+ /*NOTREACHED*/
4326
}
4327
(void) close(fdin[1]);
4328
fdin[1] = -1;
4329
@@ -470,7 +485,7 @@ uncompressbuf(struct magic_set *ms, int fd, size_t
4330
(void)fprintf(stderr, "Malloc failed (%s)\n",
4331
strerror(errno));
4332
#endif
4333
- n = 0;
4334
+ n = NODATA;
4335
goto err;
4336
}
4337
if ((r = sread(fdout[0], *newch, HOWMANY, 0)) <= 0) {
4338
@@ -479,7 +494,7 @@ uncompressbuf(struct magic_set *ms, int fd, size_t
4339
strerror(errno));
4340
#endif
4341
free(*newch);
4342
- n = 0;
4343
+ n = NODATA;
4344
*newch = NULL;
4345
goto err;
4346
} else {
4347
@@ -491,12 +506,24 @@ err:
4348
if (fdin[1] != -1)
4349
(void) close(fdin[1]);
4350
(void) close(fdout[0]);
4351
-#ifdef WNOHANG
4352
- while (waitpid(pid, NULL, WNOHANG) != -1)
4353
- continue;
4354
-#else
4355
- (void)wait(NULL);
4356
+ if (wait(&status) == -1) {
4357
+#ifdef DEBUG
4358
+ (void)fprintf(stderr, "Wait failed (%s)\n",
4359
+ strerror(errno));
4360
#endif
4361
+ n = NODATA;
4362
+ } else if (!WIFEXITED(status)) {
4363
+#ifdef DEBUG
4364
+ (void)fprintf(stderr, "Child not exited (0x%x)\n",
4365
+ status);
4366
+#endif
4367
+ } else if (WEXITSTATUS(status) != 0) {
4368
+#ifdef DEBUG
4369
+ (void)fprintf(stderr, "Child exited (0x%d)\n",
4370
+ WEXITSTATUS(status));
4371
+#endif
4372
+ }
4373
+
4374
(void) close(fdin[0]);
4375
4376
return n;
4377
Index: contrib/file/src/elfclass.h
4378
===================================================================
4379
--- contrib/file/src/elfclass.h (revision 284174)
4380
+++ contrib/file/src/elfclass.h (working copy)
4381
@@ -32,17 +32,18 @@
4382
swap = (u.c[sizeof(int32_t) - 1] + 1) != elfhdr.e_ident[EI_DATA];
4383
4384
type = elf_getu16(swap, elfhdr.e_type);
4385
+ notecount = ms->elf_notes_max;
4386
switch (type) {
4387
#ifdef ELFCORE
4388
case ET_CORE:
4389
phnum = elf_getu16(swap, elfhdr.e_phnum);
4390
- if (phnum > MAX_PHNUM)
4391
- return toomany(ms, "program", phnum);
4392
+ if (phnum > ms->elf_phnum_max)
4393
+ return toomany(ms, "program headers", phnum);
4394
flags |= FLAGS_IS_CORE;
4395
if (dophn_core(ms, clazz, swap, fd,
4396
(off_t)elf_getu(swap, elfhdr.e_phoff), phnum,
4397
(size_t)elf_getu16(swap, elfhdr.e_phentsize),
4398
- fsize, &flags) == -1)
4399
+ fsize, &flags, &notecount) == -1)
4400
return -1;
4401
break;
4402
#endif
4403
@@ -49,26 +50,27 @@
4404
case ET_EXEC:
4405
case ET_DYN:
4406
phnum = elf_getu16(swap, elfhdr.e_phnum);
4407
- if (phnum > MAX_PHNUM)
4408
+ if (phnum > ms->elf_phnum_max)
4409
return toomany(ms, "program", phnum);
4410
shnum = elf_getu16(swap, elfhdr.e_shnum);
4411
- if (shnum > MAX_SHNUM)
4412
+ if (shnum > ms->elf_shnum_max)
4413
return toomany(ms, "section", shnum);
4414
if (dophn_exec(ms, clazz, swap, fd,
4415
(off_t)elf_getu(swap, elfhdr.e_phoff), phnum,
4416
(size_t)elf_getu16(swap, elfhdr.e_phentsize),
4417
- fsize, &flags, shnum) == -1)
4418
+ fsize, shnum, &flags, &notecount) == -1)
4419
return -1;
4420
/*FALLTHROUGH*/
4421
case ET_REL:
4422
shnum = elf_getu16(swap, elfhdr.e_shnum);
4423
- if (shnum > MAX_SHNUM)
4424
- return toomany(ms, "section", shnum);
4425
+ if (shnum > ms->elf_shnum_max)
4426
+ return toomany(ms, "section headers", shnum);
4427
if (doshn(ms, clazz, swap, fd,
4428
(off_t)elf_getu(swap, elfhdr.e_shoff), shnum,
4429
(size_t)elf_getu16(swap, elfhdr.e_shentsize),
4430
- fsize, &flags, elf_getu16(swap, elfhdr.e_machine),
4431
- (int)elf_getu16(swap, elfhdr.e_shstrndx)) == -1)
4432
+ fsize, elf_getu16(swap, elfhdr.e_machine),
4433
+ (int)elf_getu16(swap, elfhdr.e_shstrndx),
4434
+ &flags, &notecount) == -1)
4435
return -1;
4436
break;
4437
4438
@@ -75,4 +77,6 @@
4439
default:
4440
break;
4441
}
4442
+ if (notecount == 0)
4443
+ return toomany(ms, "notes", ms->elf_notes_max);
4444
return 1;
4445
Index: contrib/file/src/encoding.c
4446
===================================================================
4447
--- contrib/file/src/encoding.c (revision 284174)
4448
+++ contrib/file/src/encoding.c (working copy)
4449
@@ -35,7 +35,7 @@
4450
#include "file.h"
4451
4452
#ifndef lint
4453
-FILE_RCSID("@(#)$File: encoding.c,v 1.9 2013/11/19 20:45:50 christos Exp $")
4454
+FILE_RCSID("@(#)$File: encoding.c,v 1.10 2014/09/11 12:08:52 christos Exp $")
4455
#endif /* lint */
4456
4457
#include "magic.h"
4458
@@ -97,7 +97,6 @@ file_encoding(struct magic_set *ms, const unsigned
4459
*code_mime = "utf-8";
4460
} else if (file_looks_utf8(buf, nbytes, *ubuf, ulen) > 1) {
4461
DPRINTF(("utf8 %" SIZE_T_FORMAT "u\n", *ulen));
4462
- *code = "UTF-8 Unicode (with BOM)";
4463
*code = "UTF-8 Unicode";
4464
*code_mime = "utf-8";
4465
} else if ((ucs_type = looks_ucs16(buf, nbytes, *ubuf, ulen)) != 0) {
4466
Index: contrib/file/src/file.c
4467
===================================================================
4468
--- contrib/file/src/file.c (revision 284174)
4469
+++ contrib/file/src/file.c (working copy)
4470
@@ -32,7 +32,7 @@
4471
#include "file.h"
4472
4473
#ifndef lint
4474
-FILE_RCSID("@(#)$File: file.c,v 1.153 2014/02/11 15:41:04 christos Exp $")
4475
+FILE_RCSID("@(#)$File: file.c,v 1.160 2014/12/16 23:18:40 christos Exp $")
4476
#endif /* lint */
4477
4478
#include "magic.h"
4479
@@ -54,9 +54,6 @@
4480
#ifdef HAVE_UNISTD_H
4481
#include <unistd.h> /* for read() */
4482
#endif
4483
-#ifdef HAVE_LOCALE_H
4484
-#include <locale.h>
4485
-#endif
4486
#ifdef HAVE_WCHAR_H
4487
#include <wchar.h>
4488
#endif
4489
@@ -101,7 +98,7 @@ private const struct option long_options[] = {
4490
#undef OPT_LONGONLY
4491
{0, 0, NULL, 0}
4492
};
4493
-#define OPTSTRING "bcCde:Ef:F:hiklLm:nNprsvz0"
4494
+#define OPTSTRING "bcCde:Ef:F:hiklLm:nNpP:rsvz0"
4495
4496
private const struct {
4497
const char *name;
4498
@@ -119,6 +116,18 @@ private const struct {
4499
{ "tokens", MAGIC_NO_CHECK_TOKENS }, /* OBSOLETE: ignored for backwards compatibility */
4500
};
4501
4502
+private struct {
4503
+ const char *name;
4504
+ int tag;
4505
+ size_t value;
4506
+} pm[] = {
4507
+ { "indir", MAGIC_PARAM_INDIR_MAX, 0 },
4508
+ { "name", MAGIC_PARAM_NAME_MAX, 0 },
4509
+ { "elf_phnum", MAGIC_PARAM_ELF_PHNUM_MAX, 0 },
4510
+ { "elf_shnum", MAGIC_PARAM_ELF_SHNUM_MAX, 0 },
4511
+ { "elf_notes", MAGIC_PARAM_ELF_NOTES_MAX, 0 },
4512
+};
4513
+
4514
private char *progname; /* used throughout */
4515
4516
private void usage(void);
4517
@@ -128,6 +137,8 @@ private void help(void);
4518
private int unwrap(struct magic_set *, const char *);
4519
private int process(struct magic_set *ms, const char *, int);
4520
private struct magic_set *load(const char *, int);
4521
+private void setparam(const char *);
4522
+private void applyparam(magic_t);
4523
4524
4525
/*
4526
@@ -145,7 +156,9 @@ main(int argc, char *argv[])
4527
const char *magicfile = NULL; /* where the magic is */
4528
4529
/* makes islower etc work for other langs */
4530
+#ifdef HAVE_SETLOCALE
4531
(void)setlocale(LC_CTYPE, "");
4532
+#endif
4533
4534
#ifdef __EMX__
4535
/* sh-like wildcard expansion! Shouldn't hurt at least ... */
4536
@@ -243,9 +256,13 @@ main(int argc, char *argv[])
4537
flags |= MAGIC_PRESERVE_ATIME;
4538
break;
4539
#endif
4540
+ case 'P':
4541
+ setparam(optarg);
4542
+ break;
4543
case 'r':
4544
flags |= MAGIC_RAW;
4545
break;
4546
+ break;
4547
case 's':
4548
flags |= MAGIC_DEVICES;
4549
break;
4550
@@ -298,6 +315,8 @@ main(int argc, char *argv[])
4551
strerror(errno));
4552
return 1;
4553
}
4554
+
4555
+
4556
switch(action) {
4557
case FILE_CHECK:
4558
c = magic_check(magic, magicfile);
4559
@@ -321,7 +340,7 @@ main(int argc, char *argv[])
4560
if (magic == NULL)
4561
if ((magic = load(magicfile, flags)) == NULL)
4562
return 1;
4563
- break;
4564
+ applyparam(magic);
4565
}
4566
4567
if (optind == argc) {
4568
@@ -351,7 +370,42 @@ main(int argc, char *argv[])
4569
return e;
4570
}
4571
4572
+private void
4573
+applyparam(magic_t magic)
4574
+{
4575
+ size_t i;
4576
4577
+ for (i = 0; i < __arraycount(pm); i++) {
4578
+ if (pm[i].value == 0)
4579
+ continue;
4580
+ if (magic_setparam(magic, pm[i].tag, &pm[i].value) == -1) {
4581
+ (void)fprintf(stderr, "%s: Can't set %s %s\n", progname,
4582
+ pm[i].name, strerror(errno));
4583
+ exit(1);
4584
+ }
4585
+ }
4586
+}
4587
+
4588
+private void
4589
+setparam(const char *p)
4590
+{
4591
+ size_t i;
4592
+ char *s;
4593
+
4594
+ if ((s = strchr(p, '=')) == NULL)
4595
+ goto badparm;
4596
+
4597
+ for (i = 0; i < __arraycount(pm); i++) {
4598
+ if (strncmp(p, pm[i].name, s - p) != 0)
4599
+ continue;
4600
+ pm[i].value = atoi(s + 1);
4601
+ return;
4602
+ }
4603
+badparm:
4604
+ (void)fprintf(stderr, "%s: Unknown param %s\n", progname, p);
4605
+ exit(1);
4606
+}
4607
+
4608
private struct magic_set *
4609
/*ARGSUSED*/
4610
load(const char *magicfile, int flags)
4611
Index: contrib/file/src/file.h
4612
===================================================================
4613
--- contrib/file/src/file.h (revision 284174)
4614
+++ contrib/file/src/file.h (working copy)
4615
@@ -27,7 +27,7 @@
4616
*/
4617
/*
4618
* file.h - definitions for file(1) program
4619
- * @(#)$File: file.h,v 1.152 2014/06/03 19:01:34 christos Exp $
4620
+ * @(#)$File: file.h,v 1.164 2015/01/01 17:07:34 christos Exp $
4621
*/
4622
4623
#ifndef __file_h__
4624
@@ -64,7 +64,9 @@
4625
#include <regex.h>
4626
#include <time.h>
4627
#include <sys/types.h>
4628
+#ifndef WIN32
4629
#include <sys/param.h>
4630
+#endif
4631
/* Do this here and now, because struct stat gets re-defined on solaris */
4632
#include <sys/stat.h>
4633
#include <stdarg.h>
4634
@@ -232,6 +234,7 @@ struct magic {
4635
(t) == FILE_LESTRING16 || \
4636
(t) == FILE_REGEX || \
4637
(t) == FILE_SEARCH || \
4638
+ (t) == FILE_INDIRECT || \
4639
(t) == FILE_NAME || \
4640
(t) == FILE_USE)
4641
4642
@@ -344,6 +347,8 @@ struct magic {
4643
#define STRING_IGNORE_CASE (STRING_IGNORE_LOWERCASE|STRING_IGNORE_UPPERCASE)
4644
#define STRING_DEFAULT_RANGE 100
4645
4646
+#define INDIRECT_RELATIVE BIT(0)
4647
+#define CHAR_INDIRECT_RELATIVE 'r'
4648
4649
/* list of magic entries */
4650
struct mlist {
4651
@@ -401,6 +406,16 @@ struct magic_set {
4652
/* FIXME: Make the string dynamically allocated so that e.g.
4653
strings matched in files can be longer than MAXstring */
4654
union VALUETYPE ms_value; /* either number or string */
4655
+ uint16_t indir_max;
4656
+ uint16_t name_max;
4657
+ uint16_t elf_shnum_max;
4658
+ uint16_t elf_phnum_max;
4659
+ uint16_t elf_notes_max;
4660
+#define FILE_INDIR_MAX 15
4661
+#define FILE_NAME_MAX 30
4662
+#define FILE_ELF_SHNUM_MAX 32768
4663
+#define FILE_ELF_PHNUM_MAX 128
4664
+#define FILE_ELF_NOTES_MAX 256
4665
};
4666
4667
/* Type for Unicode characters */
4668
@@ -440,8 +455,10 @@ protected int file_encoding(struct magic_set *, co
4669
unichar **, size_t *, const char **, const char **, const char **);
4670
protected int file_is_tar(struct magic_set *, const unsigned char *, size_t);
4671
protected int file_softmagic(struct magic_set *, const unsigned char *, size_t,
4672
- size_t, int, int);
4673
+ uint16_t, uint16_t *, int, int);
4674
protected int file_apprentice(struct magic_set *, const char *, int);
4675
+protected int buffer_apprentice(struct magic_set *, struct magic **,
4676
+ size_t *, size_t);
4677
protected int file_magicfind(struct magic_set *, const char *, struct mlist *);
4678
protected uint64_t file_signextend(struct magic_set *, struct magic *,
4679
uint64_t);
4680
@@ -464,14 +481,26 @@ protected int file_looks_utf8(const unsigned char
4681
size_t *);
4682
protected size_t file_pstring_length_size(const struct magic *);
4683
protected size_t file_pstring_get_length(const struct magic *, const char *);
4684
+protected char * file_printable(char *, size_t, const char *);
4685
#ifdef __EMX__
4686
protected int file_os2_apptype(struct magic_set *, const char *, const void *,
4687
size_t);
4688
#endif /* __EMX__ */
4689
4690
+#if defined(HAVE_LOCALE_H)
4691
+#include <locale.h>
4692
+#endif
4693
+#if defined(HAVE_XLOCALE_H)
4694
+#include <xlocale.h>
4695
+#endif
4696
+
4697
typedef struct {
4698
const char *pat;
4699
- char *old_lc_ctype;
4700
+#if defined(HAVE_NEWLOCALE) && defined(HAVE_USELOCALE) && defined(HAVE_FREELOCALE)
4701
+#define USE_C_LOCALE
4702
+ locale_t old_lc_ctype;
4703
+ locale_t c_lc_ctype;
4704
+#endif
4705
int rc;
4706
regex_t rx;
4707
} file_regex_t;
4708
Index: contrib/file/src/file_opts.h
4709
===================================================================
4710
--- contrib/file/src/file_opts.h (revision 284174)
4711
+++ contrib/file/src/file_opts.h (working copy)
4712
@@ -43,6 +43,12 @@ OPT('0', "print0", 0, " terminate fi
4713
#if defined(HAVE_UTIME) || defined(HAVE_UTIMES)
4714
OPT('p', "preserve-date", 0, " preserve access times on files\n")
4715
#endif
4716
+OPT('P', "parameter", 0, " set file engine parameter limits\n"
4717
+ " indir 15 recursion limit for indirection\n"
4718
+ " name 30 use limit for name/use magic\n"
4719
+ " elf_notes 256 max ELF notes processed\n"
4720
+ " elf_phnum 128 max ELF prog sections processed\n"
4721
+ " elf_shnum 32768 max ELF sections processed\n")
4722
OPT('r', "raw", 0, " don't translate unprintable chars to \\ooo\n")
4723
OPT('s', "special-files", 0, " treat special (block/char devices) files as\n"
4724
" ordinary ones\n")
4725
Index: contrib/file/src/fsmagic.c
4726
===================================================================
4727
--- contrib/file/src/fsmagic.c (revision 284174)
4728
+++ contrib/file/src/fsmagic.c (working copy)
4729
@@ -32,7 +32,7 @@
4730
#include "file.h"
4731
4732
#ifndef lint
4733
-FILE_RCSID("@(#)$File: fsmagic.c,v 1.73 2014/05/14 23:15:42 christos Exp $")
4734
+FILE_RCSID("@(#)$File: fsmagic.c,v 1.75 2014/12/04 15:56:46 christos Exp $")
4735
#endif /* lint */
4736
4737
#include "magic.h"
4738
@@ -75,10 +75,10 @@ bad_link(struct magic_set *ms, int err, char *buf)
4739
else if (!mime) {
4740
if (ms->flags & MAGIC_ERROR) {
4741
file_error(ms, err,
4742
- "broken symbolic link to `%s'", buf);
4743
+ "broken symbolic link to %s", buf);
4744
return -1;
4745
}
4746
- if (file_printf(ms, "broken symbolic link to `%s'", buf) == -1)
4747
+ if (file_printf(ms, "broken symbolic link to %s", buf) == -1)
4748
return -1;
4749
}
4750
return 1;
4751
@@ -129,7 +129,7 @@ file_fsmagic(struct magic_set *ms, const char *fn,
4752
4753
#ifdef WIN32
4754
{
4755
- HANDLE hFile = CreateFile(fn, 0, FILE_SHARE_DELETE |
4756
+ HANDLE hFile = CreateFile((LPCSTR)fn, 0, FILE_SHARE_DELETE |
4757
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0,
4758
NULL);
4759
if (hFile != INVALID_HANDLE_VALUE) {
4760
@@ -352,7 +352,7 @@ file_fsmagic(struct magic_set *ms, const char *fn,
4761
if (mime) {
4762
if (handle_mime(ms, mime, "symlink") == -1)
4763
return -1;
4764
- } else if (file_printf(ms, "%ssymbolic link to `%s'",
4765
+ } else if (file_printf(ms, "%ssymbolic link to %s",
4766
COMMA, buf) == -1)
4767
return -1;
4768
}
4769
Index: contrib/file/src/funcs.c
4770
===================================================================
4771
--- contrib/file/src/funcs.c (revision 284174)
4772
+++ contrib/file/src/funcs.c (working copy)
4773
@@ -27,7 +27,7 @@
4774
#include "file.h"
4775
4776
#ifndef lint
4777
-FILE_RCSID("@(#)$File: funcs.c,v 1.72 2014/05/14 23:15:42 christos Exp $")
4778
+FILE_RCSID("@(#)$File: funcs.c,v 1.79 2014/12/16 20:52:49 christos Exp $")
4779
#endif /* lint */
4780
4781
#include "magic.h"
4782
@@ -45,9 +45,6 @@
4783
#if defined(HAVE_LIMITS_H)
4784
#include <limits.h>
4785
#endif
4786
-#if defined(HAVE_LOCALE_H)
4787
-#include <locale.h>
4788
-#endif
4789
4790
#ifndef SIZE_MAX
4791
#define SIZE_MAX ((size_t)~0)
4792
@@ -230,7 +227,7 @@ file_buffer(struct magic_set *ms, int fd, const ch
4793
4794
/* try soft magic tests */
4795
if ((ms->flags & MAGIC_NO_CHECK_SOFT) == 0)
4796
- if ((m = file_softmagic(ms, ubuf, nb, 0, BINTEST,
4797
+ if ((m = file_softmagic(ms, ubuf, nb, 0, NULL, BINTEST,
4798
looks_text)) != 0) {
4799
if ((ms->flags & MAGIC_DEBUG) != 0)
4800
(void)fprintf(stderr, "softmagic %d\n", m);
4801
@@ -455,13 +452,14 @@ out:
4802
protected int
4803
file_regcomp(file_regex_t *rx, const char *pat, int flags)
4804
{
4805
- rx->old_lc_ctype = setlocale(LC_CTYPE, NULL);
4806
+#ifdef USE_C_LOCALE
4807
+ rx->c_lc_ctype = newlocale(LC_CTYPE_MASK, "C", 0);
4808
+ assert(rx->c_lc_ctype != NULL);
4809
+ rx->old_lc_ctype = uselocale(rx->c_lc_ctype);
4810
assert(rx->old_lc_ctype != NULL);
4811
- rx->old_lc_ctype = strdup(rx->old_lc_ctype);
4812
- assert(rx->old_lc_ctype != NULL);
4813
+#endif
4814
rx->pat = pat;
4815
4816
- (void)setlocale(LC_CTYPE, "C");
4817
return rx->rc = regcomp(&rx->rx, pat, flags);
4818
}
4819
4820
@@ -478,8 +476,10 @@ file_regfree(file_regex_t *rx)
4821
{
4822
if (rx->rc == 0)
4823
regfree(&rx->rx);
4824
- (void)setlocale(LC_CTYPE, rx->old_lc_ctype);
4825
- free(rx->old_lc_ctype);
4826
+#ifdef USE_C_LOCALE
4827
+ (void)uselocale(rx->old_lc_ctype);
4828
+ freelocale(rx->c_lc_ctype);
4829
+#endif
4830
}
4831
4832
protected void
4833
@@ -531,3 +531,28 @@ file_pop_buffer(struct magic_set *ms, file_pushbuf
4834
free(pb);
4835
return rbuf;
4836
}
4837
+
4838
+/*
4839
+ * convert string to ascii printable format.
4840
+ */
4841
+protected char *
4842
+file_printable(char *buf, size_t bufsiz, const char *str)
4843
+{
4844
+ char *ptr, *eptr;
4845
+ const unsigned char *s = (const unsigned char *)str;
4846
+
4847
+ for (ptr = buf, eptr = ptr + bufsiz - 1; ptr < eptr && *s; s++) {
4848
+ if (isprint(*s)) {
4849
+ *ptr++ = *s;
4850
+ continue;
4851
+ }
4852
+ if (ptr >= eptr - 3)
4853
+ break;
4854
+ *ptr++ = '\\';
4855
+ *ptr++ = ((*s >> 6) & 7) + '0';
4856
+ *ptr++ = ((*s >> 3) & 7) + '0';
4857
+ *ptr++ = ((*s >> 0) & 7) + '0';
4858
+ }
4859
+ *ptr = '\0';
4860
+ return buf;
4861
+}
4862
Index: contrib/file/src/getline.c
4863
===================================================================
4864
--- contrib/file/src/getline.c (revision 284174)
4865
+++ contrib/file/src/getline.c (working copy)
4866
@@ -1,4 +1,4 @@
4867
-/* $NetBSD: fgetln.c,v 1.9 2008/04/29 06:53:03 martin Exp $ */
4868
+/* $NetBSD: getline.c,v 1.2 2014/09/16 17:23:50 christos Exp $ */
4869
4870
/*-
4871
* Copyright (c) 2011 The NetBSD Foundation, Inc.
4872
@@ -52,10 +52,14 @@ getdelim(char **buf, size_t *bufsiz, int delimiter
4873
for (ptr = *buf, eptr = *buf + *bufsiz;;) {
4874
int c = fgetc(fp);
4875
if (c == -1) {
4876
- if (feof(fp))
4877
- return ptr == *buf ? -1 : ptr - *buf;
4878
- else
4879
- return -1;
4880
+ if (feof(fp)) {
4881
+ ssize_t diff = (ssize_t)(ptr - *buf);
4882
+ if (diff != 0) {
4883
+ *ptr = '\0';
4884
+ return diff;
4885
+ }
4886
+ }
4887
+ return -1;
4888
}
4889
*ptr++ = c;
4890
if (c == delimiter) {
4891
@@ -76,7 +80,7 @@ getdelim(char **buf, size_t *bufsiz, int delimiter
4892
}
4893
}
4894
4895
-ssize_t
4896
+public ssize_t
4897
getline(char **buf, size_t *bufsiz, FILE *fp)
4898
{
4899
return getdelim(buf, bufsiz, '\n', fp);
4900
@@ -93,7 +97,7 @@ main(int argc, char *argv[])
4901
size_t n = 0;
4902
4903
while ((len = getline(&p, &n, stdin)) != -1)
4904
- (void)printf("%zd %s", len, p);
4905
+ (void)printf("%" SIZE_T_FORMAT "d %s", len, p);
4906
free(p);
4907
return 0;
4908
}
4909
Index: contrib/file/src/magic.c
4910
===================================================================
4911
--- contrib/file/src/magic.c (revision 284174)
4912
+++ contrib/file/src/magic.c (working copy)
4913
@@ -33,7 +33,7 @@
4914
#include "file.h"
4915
4916
#ifndef lint
4917
-FILE_RCSID("@(#)$File: magic.c,v 1.84 2014/05/14 23:15:42 christos Exp $")
4918
+FILE_RCSID("@(#)$File: magic.c,v 1.91 2014/12/16 23:18:40 christos Exp $")
4919
#endif /* lint */
4920
4921
#include "magic.h"
4922
@@ -128,6 +128,7 @@ out:
4923
#else
4924
char *hmagicp;
4925
char *tmppath = NULL;
4926
+ LPTSTR dllpath;
4927
hmagicpath = NULL;
4928
4929
#define APPENDPATH() \
4930
@@ -173,7 +174,7 @@ out:
4931
}
4932
4933
/* Third, try to get magic file relative to dll location */
4934
- LPTSTR dllpath = malloc(sizeof(*dllpath) * (MAX_PATH + 1));
4935
+ dllpath = malloc(sizeof(*dllpath) * (MAX_PATH + 1));
4936
dllpath[MAX_PATH] = 0; /* just in case long path gets truncated and not null terminated */
4937
if (GetModuleFileNameA(NULL, dllpath, MAX_PATH)){
4938
PathRemoveFileSpecA(dllpath);
4939
@@ -257,7 +258,21 @@ magic_load(struct magic_set *ms, const char *magic
4940
return file_apprentice(ms, magicfile, FILE_LOAD);
4941
}
4942
4943
+#ifndef COMPILE_ONLY
4944
+/*
4945
+ * Install a set of compiled magic buffers.
4946
+ */
4947
public int
4948
+magic_load_buffers(struct magic_set *ms, void **bufs, size_t *sizes,
4949
+ size_t nbufs)
4950
+{
4951
+ if (ms == NULL)
4952
+ return -1;
4953
+ return buffer_apprentice(ms, (struct magic **)bufs, sizes, nbufs);
4954
+}
4955
+#endif
4956
+
4957
+public int
4958
magic_compile(struct magic_set *ms, const char *magicfile)
4959
{
4960
if (ms == NULL)
4961
@@ -522,3 +537,53 @@ magic_version(void)
4962
{
4963
return MAGIC_VERSION;
4964
}
4965
+
4966
+public int
4967
+magic_setparam(struct magic_set *ms, int param, const void *val)
4968
+{
4969
+ switch (param) {
4970
+ case MAGIC_PARAM_INDIR_MAX:
4971
+ ms->indir_max = *(const size_t *)val;
4972
+ return 0;
4973
+ case MAGIC_PARAM_NAME_MAX:
4974
+ ms->name_max = *(const size_t *)val;
4975
+ return 0;
4976
+ case MAGIC_PARAM_ELF_PHNUM_MAX:
4977
+ ms->elf_phnum_max = *(const size_t *)val;
4978
+ return 0;
4979
+ case MAGIC_PARAM_ELF_SHNUM_MAX:
4980
+ ms->elf_shnum_max = *(const size_t *)val;
4981
+ return 0;
4982
+ case MAGIC_PARAM_ELF_NOTES_MAX:
4983
+ ms->elf_notes_max = *(const size_t *)val;
4984
+ return 0;
4985
+ default:
4986
+ errno = EINVAL;
4987
+ return -1;
4988
+ }
4989
+}
4990
+
4991
+public int
4992
+magic_getparam(struct magic_set *ms, int param, void *val)
4993
+{
4994
+ switch (param) {
4995
+ case MAGIC_PARAM_INDIR_MAX:
4996
+ *(size_t *)val = ms->indir_max;
4997
+ return 0;
4998
+ case MAGIC_PARAM_NAME_MAX:
4999
+ *(size_t *)val = ms->name_max;
5000
+ return 0;
5001
+ case MAGIC_PARAM_ELF_PHNUM_MAX:
5002
+ *(size_t *)val = ms->elf_phnum_max;
5003
+ return 0;
5004
+ case MAGIC_PARAM_ELF_SHNUM_MAX:
5005
+ *(size_t *)val = ms->elf_shnum_max;
5006
+ return 0;
5007
+ case MAGIC_PARAM_ELF_NOTES_MAX:
5008
+ *(size_t *)val = ms->elf_notes_max;
5009
+ return 0;
5010
+ default:
5011
+ errno = EINVAL;
5012
+ return -1;
5013
+ }
5014
+}
5015
Index: contrib/file/src/magic.h
5016
===================================================================
5017
--- contrib/file/src/magic.h (revision 284174)
5018
+++ contrib/file/src/magic.h (working copy)
5019
@@ -75,7 +75,7 @@
5020
#define MAGIC_NO_CHECK_FORTRAN 0x000000 /* Don't check ascii/fortran */
5021
#define MAGIC_NO_CHECK_TROFF 0x000000 /* Don't check ascii/troff */
5022
5023
-#define MAGIC_VERSION 518 /* This implementation */
5024
+#define MAGIC_VERSION 521 /* This implementation */
5025
5026
5027
#ifdef __cplusplus
5028
@@ -96,11 +96,22 @@ int magic_setflags(magic_t, int);
5029
5030
int magic_version(void);
5031
int magic_load(magic_t, const char *);
5032
+int magic_load_buffers(magic_t, void **, size_t *, size_t);
5033
+
5034
int magic_compile(magic_t, const char *);
5035
int magic_check(magic_t, const char *);
5036
int magic_list(magic_t, const char *);
5037
int magic_errno(magic_t);
5038
5039
+#define MAGIC_PARAM_INDIR_MAX 0
5040
+#define MAGIC_PARAM_NAME_MAX 1
5041
+#define MAGIC_PARAM_ELF_PHNUM_MAX 2
5042
+#define MAGIC_PARAM_ELF_SHNUM_MAX 3
5043
+#define MAGIC_PARAM_ELF_NOTES_MAX 4
5044
+
5045
+int magic_setparam(magic_t, int, const void *);
5046
+int magic_getparam(magic_t, int, void *);
5047
+
5048
#ifdef __cplusplus
5049
};
5050
#endif
5051
Index: contrib/file/src/magic.h.in
5052
===================================================================
5053
--- contrib/file/src/magic.h.in (revision 284174)
5054
+++ contrib/file/src/magic.h.in (working copy)
5055
@@ -96,11 +96,22 @@ int magic_setflags(magic_t, int);
5056
5057
int magic_version(void);
5058
int magic_load(magic_t, const char *);
5059
+int magic_load_buffers(magic_t, void **, size_t *, size_t);
5060
+
5061
int magic_compile(magic_t, const char *);
5062
int magic_check(magic_t, const char *);
5063
int magic_list(magic_t, const char *);
5064
int magic_errno(magic_t);
5065
5066
+#define MAGIC_PARAM_INDIR_MAX 0
5067
+#define MAGIC_PARAM_NAME_MAX 1
5068
+#define MAGIC_PARAM_ELF_PHNUM_MAX 2
5069
+#define MAGIC_PARAM_ELF_SHNUM_MAX 3
5070
+#define MAGIC_PARAM_ELF_NOTES_MAX 4
5071
+
5072
+int magic_setparam(magic_t, int, const void *);
5073
+int magic_getparam(magic_t, int, void *);
5074
+
5075
#ifdef __cplusplus
5076
};
5077
#endif
5078
Index: contrib/file/src/pread.c
5079
===================================================================
5080
--- contrib/file/src/pread.c (revision 284174)
5081
+++ contrib/file/src/pread.c (working copy)
5082
@@ -1,6 +1,6 @@
5083
#include "file.h"
5084
#ifndef lint
5085
-FILE_RCSID("@(#)$File: pread.c,v 1.2 2013/04/02 16:23:07 christos Exp $")
5086
+FILE_RCSID("@(#)$File: pread.c,v 1.3 2014/09/15 19:11:25 christos Exp $")
5087
#endif /* lint */
5088
#include <fcntl.h>
5089
#include <unistd.h>
5090
@@ -7,8 +7,17 @@
5091
5092
ssize_t
5093
pread(int fd, void *buf, size_t len, off_t off) {
5094
- if (lseek(fd, off, SEEK_SET) == (off_t)-1)
5095
+ off_t old;
5096
+ ssize_t rv;
5097
+
5098
+ if ((old = lseek(fd, off, SEEK_SET)) == -1)
5099
return -1;
5100
5101
- return read(fd, buf, len);
5102
+ if ((rv = read(fd, buf, len)) == -1)
5103
+ return -1;
5104
+
5105
+ if (lseek(fd, old, SEEK_SET) == -1)
5106
+ return -1;
5107
+
5108
+ return rv;
5109
}
5110
Index: contrib/file/src/readcdf.c
5111
===================================================================
5112
--- contrib/file/src/readcdf.c (revision 284174)
5113
+++ contrib/file/src/readcdf.c (working copy)
5114
@@ -26,7 +26,7 @@
5115
#include "file.h"
5116
5117
#ifndef lint
5118
-FILE_RCSID("@(#)$File: readcdf.c,v 1.44 2014/05/14 23:22:48 christos Exp $")
5119
+FILE_RCSID("@(#)$File: readcdf.c,v 1.49 2014/12/04 15:56:46 christos Exp $")
5120
#endif
5121
5122
#include <assert.h>
5123
@@ -35,9 +35,6 @@
5124
#include <string.h>
5125
#include <time.h>
5126
#include <ctype.h>
5127
-#if defined(HAVE_LOCALE_H)
5128
-#include <locale.h>
5129
-#endif
5130
5131
#include "cdf.h"
5132
#include "magic.h"
5133
@@ -75,7 +72,7 @@ static const struct cv {
5134
const char *mime;
5135
} clsid2mime[] = {
5136
{
5137
- { 0x00000000000c1084LLU, 0x46000000000000c0LLU },
5138
+ { 0x00000000000c1084ULL, 0x46000000000000c0ULL },
5139
"x-msi",
5140
},
5141
{ { 0, 0 },
5142
@@ -83,7 +80,7 @@ static const struct cv {
5143
},
5144
}, clsid2desc[] = {
5145
{
5146
- { 0x00000000000c1084LLU, 0x46000000000000c0LLU },
5147
+ { 0x00000000000c1084ULL, 0x46000000000000c0ULL },
5148
"MSI Installer",
5149
},
5150
{ { 0, 0 },
5151
@@ -107,20 +104,23 @@ cdf_app_to_mime(const char *vbuf, const struct nv
5152
{
5153
size_t i;
5154
const char *rv = NULL;
5155
- char *old_lc_ctype;
5156
+#ifdef USE_C_LOCALE
5157
+ locale_t old_lc_ctype, c_lc_ctype;
5158
5159
- old_lc_ctype = setlocale(LC_CTYPE, NULL);
5160
+ c_lc_ctype = newlocale(LC_CTYPE_MASK, "C", 0);
5161
+ assert(c_lc_ctype != NULL);
5162
+ old_lc_ctype = uselocale(c_lc_ctype);
5163
assert(old_lc_ctype != NULL);
5164
- old_lc_ctype = strdup(old_lc_ctype);
5165
- assert(old_lc_ctype != NULL);
5166
- (void)setlocale(LC_CTYPE, "C");
5167
+#endif
5168
for (i = 0; nv[i].pattern != NULL; i++)
5169
if (strcasestr(vbuf, nv[i].pattern) != NULL) {
5170
rv = nv[i].mime;
5171
break;
5172
}
5173
- (void)setlocale(LC_CTYPE, old_lc_ctype);
5174
- free(old_lc_ctype);
5175
+#ifdef USE_C_LOCALE
5176
+ (void)uselocale(old_lc_ctype);
5177
+ freelocale(c_lc_ctype);
5178
+#endif
5179
return rv;
5180
}
5181
5182
@@ -241,6 +241,37 @@ cdf_file_property_info(struct magic_set *ms, const
5183
}
5184
5185
private int
5186
+cdf_file_catalog(struct magic_set *ms, const cdf_header_t *h,
5187
+ const cdf_stream_t *sst)
5188
+{
5189
+ cdf_catalog_t *cat;
5190
+ size_t i;
5191
+ char buf[256];
5192
+ cdf_catalog_entry_t *ce;
5193
+
5194
+ if (NOTMIME(ms)) {
5195
+ if (file_printf(ms, "Microsoft Thumbs.db [") == -1)
5196
+ return -1;
5197
+ if (cdf_unpack_catalog(h, sst, &cat) == -1)
5198
+ return -1;
5199
+ ce = cat->cat_e;
5200
+ /* skip first entry since it has a , or paren */
5201
+ for (i = 1; i < cat->cat_num; i++)
5202
+ if (file_printf(ms, "%s%s",
5203
+ cdf_u16tos8(buf, ce[i].ce_namlen, ce[i].ce_name),
5204
+ i == cat->cat_num - 1 ? "]" : ", ") == -1) {
5205
+ free(cat);
5206
+ return -1;
5207
+ }
5208
+ free(cat);
5209
+ } else {
5210
+ if (file_printf(ms, "application/CDFV2") == -1)
5211
+ return -1;
5212
+ }
5213
+ return 1;
5214
+}
5215
+
5216
+private int
5217
cdf_file_summary_info(struct magic_set *ms, const cdf_header_t *h,
5218
const cdf_stream_t *sst, const cdf_directory_t *root_storage)
5219
{
5220
@@ -285,11 +316,12 @@ cdf_file_summary_info(struct magic_set *ms, const
5221
if (root_storage) {
5222
str = cdf_clsid_to_mime(root_storage->d_storage_uuid,
5223
clsid2desc);
5224
- if (str)
5225
+ if (str) {
5226
if (file_printf(ms, ", %s", str) == -1)
5227
return -2;
5228
}
5229
}
5230
+ }
5231
5232
m = cdf_file_property_info(ms, info, count, root_storage);
5233
free(info);
5234
@@ -302,11 +334,11 @@ private char *
5235
format_clsid(char *buf, size_t len, const uint64_t uuid[2]) {
5236
snprintf(buf, len, "%.8" PRIx64 "-%.4" PRIx64 "-%.4" PRIx64 "-%.4"
5237
PRIx64 "-%.12" PRIx64,
5238
- (uuid[0] >> 32) & (uint64_t)0x000000000ffffffffLLU,
5239
- (uuid[0] >> 16) & (uint64_t)0x0000000000000ffffLLU,
5240
- (uuid[0] >> 0) & (uint64_t)0x0000000000000ffffLLU,
5241
- (uuid[1] >> 48) & (uint64_t)0x0000000000000ffffLLU,
5242
- (uuid[1] >> 0) & (uint64_t)0x0000fffffffffffffLLU);
5243
+ (uuid[0] >> 32) & (uint64_t)0x000000000ffffffffULL,
5244
+ (uuid[0] >> 16) & (uint64_t)0x0000000000000ffffULL,
5245
+ (uuid[0] >> 0) & (uint64_t)0x0000000000000ffffULL,
5246
+ (uuid[1] >> 48) & (uint64_t)0x0000000000000ffffULL,
5247
+ (uuid[1] >> 0) & (uint64_t)0x0000fffffffffffffULL);
5248
return buf;
5249
}
5250
#endif
5251
@@ -323,6 +355,7 @@ file_trycdf(struct magic_set *ms, int fd, const un
5252
int i;
5253
const char *expn = "";
5254
const char *corrupt = "corrupt: ";
5255
+ const cdf_directory_t *root_storage;
5256
5257
info.i_fd = fd;
5258
info.i_buf = buf;
5259
@@ -356,7 +389,6 @@ file_trycdf(struct magic_set *ms, int fd, const un
5260
goto out2;
5261
}
5262
5263
- const cdf_directory_t *root_storage;
5264
if ((i = cdf_read_short_stream(&info, &h, &sat, &dir, &sst,
5265
&root_storage)) == -1) {
5266
expn = "Cannot read short stream";
5267
@@ -404,8 +436,24 @@ file_trycdf(struct magic_set *ms, int fd, const un
5268
if ((i = cdf_read_summary_info(&info, &h, &sat, &ssat, &sst, &dir,
5269
&scn)) == -1) {
5270
if (errno == ESRCH) {
5271
- corrupt = expn;
5272
- expn = "No summary info";
5273
+ if ((i = cdf_read_catalog(&info, &h, &sat, &ssat, &sst,
5274
+ &dir, &scn)) == -1) {
5275
+ corrupt = expn;
5276
+ if ((i = cdf_read_encrypted_package(&info, &h,
5277
+ &sat, &ssat, &sst, &dir, &scn)) == -1)
5278
+ expn = "No summary info";
5279
+ else {
5280
+ expn = "Encrypted";
5281
+ i = -1;
5282
+ }
5283
+ goto out4;
5284
+ }
5285
+#ifdef CDF_DEBUG
5286
+ cdf_dump_catalog(&h, &scn);
5287
+#endif
5288
+ if ((i = cdf_file_catalog(ms, &h, &scn))
5289
+ < 0)
5290
+ expn = "Can't expand catalog";
5291
} else {
5292
expn = "Cannot read summary info";
5293
}
5294
@@ -464,7 +512,8 @@ out0:
5295
if (file_printf(ms, ", %s%s", corrupt, expn) == -1)
5296
return -1;
5297
} else {
5298
- if (file_printf(ms, "application/CDFV2-corrupt") == -1)
5299
+ if (file_printf(ms, "application/CDFV2-%s",
5300
+ *corrupt ? "corrupt" : "encrypted") == -1)
5301
return -1;
5302
}
5303
i = 1;
5304
Index: contrib/file/src/readelf.c
5305
===================================================================
5306
--- contrib/file/src/readelf.c (revision 284174)
5307
+++ contrib/file/src/readelf.c (working copy)
5308
@@ -27,7 +27,7 @@
5309
#include "file.h"
5310
5311
#ifndef lint
5312
-FILE_RCSID("@(#)$File: readelf.c,v 1.103 2014/05/02 02:25:10 christos Exp $")
5313
+FILE_RCSID("@(#)$File: readelf.c,v 1.117 2014/12/16 23:29:42 christos Exp $")
5314
#endif
5315
5316
#ifdef BUILTIN_ELF
5317
@@ -43,14 +43,14 @@
5318
5319
#ifdef ELFCORE
5320
private int dophn_core(struct magic_set *, int, int, int, off_t, int, size_t,
5321
- off_t, int *);
5322
+ off_t, int *, uint16_t *);
5323
#endif
5324
private int dophn_exec(struct magic_set *, int, int, int, off_t, int, size_t,
5325
- off_t, int *, int);
5326
+ off_t, int, int *, uint16_t *);
5327
private int doshn(struct magic_set *, int, int, int, off_t, int, size_t,
5328
- off_t, int *, int, int);
5329
+ off_t, int, int, int *, uint16_t *);
5330
private size_t donote(struct magic_set *, void *, size_t, size_t, int,
5331
- int, size_t, int *);
5332
+ int, size_t, int *, uint16_t *);
5333
5334
#define ELF_ALIGN(a) ((((a) + align - 1) / align) * align)
5335
5336
@@ -60,13 +60,14 @@ private uint16_t getu16(int, uint16_t);
5337
private uint32_t getu32(int, uint32_t);
5338
private uint64_t getu64(int, uint64_t);
5339
5340
-#define MAX_PHNUM 256
5341
-#define MAX_SHNUM 1024
5342
+#define MAX_PHNUM 128
5343
+#define MAX_SHNUM 32768
5344
+#define SIZE_UNKNOWN ((off_t)-1)
5345
5346
private int
5347
toomany(struct magic_set *ms, const char *name, uint16_t num)
5348
{
5349
- if (file_printf(ms, ", too many %s header sections (%u)", name, num
5350
+ if (file_printf(ms, ", too many %s (%u)", name, num
5351
) == -1)
5352
return -1;
5353
return 0;
5354
@@ -292,15 +293,19 @@ private const char os_style_names[][8] = {
5355
"NetBSD",
5356
};
5357
5358
-#define FLAGS_DID_CORE 0x01
5359
-#define FLAGS_DID_NOTE 0x02
5360
-#define FLAGS_DID_BUILD_ID 0x04
5361
-#define FLAGS_DID_CORE_STYLE 0x08
5362
-#define FLAGS_IS_CORE 0x10
5363
+#define FLAGS_DID_CORE 0x001
5364
+#define FLAGS_DID_OS_NOTE 0x002
5365
+#define FLAGS_DID_BUILD_ID 0x004
5366
+#define FLAGS_DID_CORE_STYLE 0x008
5367
+#define FLAGS_DID_NETBSD_PAX 0x010
5368
+#define FLAGS_DID_NETBSD_MARCH 0x020
5369
+#define FLAGS_DID_NETBSD_CMODEL 0x040
5370
+#define FLAGS_DID_NETBSD_UNKNOWN 0x080
5371
+#define FLAGS_IS_CORE 0x100
5372
5373
private int
5374
dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
5375
- int num, size_t size, off_t fsize, int *flags)
5376
+ int num, size_t size, off_t fsize, int *flags, uint16_t *notecount)
5377
{
5378
Elf32_Phdr ph32;
5379
Elf64_Phdr ph64;
5380
@@ -318,13 +323,13 @@ dophn_core(struct magic_set *ms, int clazz, int sw
5381
* Loop through all the program headers.
5382
*/
5383
for ( ; num; num--) {
5384
- if (pread(fd, xph_addr, xph_sizeof, off) == -1) {
5385
+ if (pread(fd, xph_addr, xph_sizeof, off) < (ssize_t)xph_sizeof) {
5386
file_badread(ms);
5387
return -1;
5388
}
5389
off += size;
5390
5391
- if (xph_offset > fsize) {
5392
+ if (fsize != SIZE_UNKNOWN && xph_offset > fsize) {
5393
/* Perhaps warn here */
5394
continue;
5395
}
5396
@@ -346,7 +351,7 @@ dophn_core(struct magic_set *ms, int clazz, int sw
5397
if (offset >= (size_t)bufsize)
5398
break;
5399
offset = donote(ms, nbuf, offset, (size_t)bufsize,
5400
- clazz, swap, 4, flags);
5401
+ clazz, swap, 4, flags, notecount);
5402
if (offset == 0)
5403
break;
5404
5405
@@ -476,132 +481,127 @@ do_note_freebsd_version(struct magic_set *ms, int
5406
}
5407
}
5408
5409
-private size_t
5410
-donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
5411
- int clazz, int swap, size_t align, int *flags)
5412
+private int
5413
+do_bid_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
5414
+ int swap __attribute__((__unused__)), uint32_t namesz, uint32_t descsz,
5415
+ size_t noff, size_t doff, int *flags)
5416
{
5417
- Elf32_Nhdr nh32;
5418
- Elf64_Nhdr nh64;
5419
- size_t noff, doff;
5420
-#ifdef ELFCORE
5421
- int os_style = -1;
5422
-#endif
5423
- uint32_t namesz, descsz;
5424
- unsigned char *nbuf = CAST(unsigned char *, vbuf);
5425
-
5426
- if (xnh_sizeof + offset > size) {
5427
- /*
5428
- * We're out of note headers.
5429
- */
5430
- return xnh_sizeof + offset;
5431
+ if (namesz == 4 && strcmp((char *)&nbuf[noff], "GNU") == 0 &&
5432
+ type == NT_GNU_BUILD_ID && (descsz == 16 || descsz == 20)) {
5433
+ uint8_t desc[20];
5434
+ uint32_t i;
5435
+ *flags |= FLAGS_DID_BUILD_ID;
5436
+ if (file_printf(ms, ", BuildID[%s]=", descsz == 16 ? "md5/uuid" :
5437
+ "sha1") == -1)
5438
+ return 1;
5439
+ (void)memcpy(desc, &nbuf[doff], descsz);
5440
+ for (i = 0; i < descsz; i++)
5441
+ if (file_printf(ms, "%02x", desc[i]) == -1)
5442
+ return 1;
5443
+ return 1;
5444
}
5445
+ return 0;
5446
+}
5447
5448
- (void)memcpy(xnh_addr, &nbuf[offset], xnh_sizeof);
5449
- offset += xnh_sizeof;
5450
-
5451
- namesz = xnh_namesz;
5452
- descsz = xnh_descsz;
5453
- if ((namesz == 0) && (descsz == 0)) {
5454
- /*
5455
- * We're out of note headers.
5456
- */
5457
- return (offset >= size) ? offset : size;
5458
- }
5459
-
5460
- if (namesz & 0x80000000) {
5461
- (void)file_printf(ms, ", bad note name size 0x%lx",
5462
- (unsigned long)namesz);
5463
- return 0;
5464
- }
5465
-
5466
- if (descsz & 0x80000000) {
5467
- (void)file_printf(ms, ", bad note description size 0x%lx",
5468
- (unsigned long)descsz);
5469
- return 0;
5470
- }
5471
-
5472
-
5473
- noff = offset;
5474
- doff = ELF_ALIGN(offset + namesz);
5475
-
5476
- if (offset + namesz > size) {
5477
- /*
5478
- * We're past the end of the buffer.
5479
- */
5480
- return doff;
5481
- }
5482
-
5483
- offset = ELF_ALIGN(doff + descsz);
5484
- if (doff + descsz > size) {
5485
- /*
5486
- * We're past the end of the buffer.
5487
- */
5488
- return (offset >= size) ? offset : size;
5489
- }
5490
-
5491
- if ((*flags & (FLAGS_DID_NOTE|FLAGS_DID_BUILD_ID)) ==
5492
- (FLAGS_DID_NOTE|FLAGS_DID_BUILD_ID))
5493
- goto core;
5494
-
5495
+private int
5496
+do_os_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
5497
+ int swap, uint32_t namesz, uint32_t descsz,
5498
+ size_t noff, size_t doff, int *flags)
5499
+{
5500
if (namesz == 5 && strcmp((char *)&nbuf[noff], "SuSE") == 0 &&
5501
- xnh_type == NT_GNU_VERSION && descsz == 2) {
5502
+ type == NT_GNU_VERSION && descsz == 2) {
5503
+ *flags |= FLAGS_DID_OS_NOTE;
5504
file_printf(ms, ", for SuSE %d.%d", nbuf[doff], nbuf[doff + 1]);
5505
+ return 1;
5506
}
5507
+
5508
if (namesz == 4 && strcmp((char *)&nbuf[noff], "GNU") == 0 &&
5509
- xnh_type == NT_GNU_VERSION && descsz == 16) {
5510
+ type == NT_GNU_VERSION && descsz == 16) {
5511
uint32_t desc[4];
5512
(void)memcpy(desc, &nbuf[doff], sizeof(desc));
5513
5514
+ *flags |= FLAGS_DID_OS_NOTE;
5515
if (file_printf(ms, ", for GNU/") == -1)
5516
- return size;
5517
+ return 1;
5518
switch (elf_getu32(swap, desc[0])) {
5519
case GNU_OS_LINUX:
5520
if (file_printf(ms, "Linux") == -1)
5521
- return size;
5522
+ return 1;
5523
break;
5524
case GNU_OS_HURD:
5525
if (file_printf(ms, "Hurd") == -1)
5526
- return size;
5527
+ return 1;
5528
break;
5529
case GNU_OS_SOLARIS:
5530
if (file_printf(ms, "Solaris") == -1)
5531
- return size;
5532
+ return 1;
5533
break;
5534
case GNU_OS_KFREEBSD:
5535
if (file_printf(ms, "kFreeBSD") == -1)
5536
- return size;
5537
+ return 1;
5538
break;
5539
case GNU_OS_KNETBSD:
5540
if (file_printf(ms, "kNetBSD") == -1)
5541
- return size;
5542
+ return 1;
5543
break;
5544
default:
5545
if (file_printf(ms, "<unknown>") == -1)
5546
- return size;
5547
+ return 1;
5548
}
5549
if (file_printf(ms, " %d.%d.%d", elf_getu32(swap, desc[1]),
5550
elf_getu32(swap, desc[2]), elf_getu32(swap, desc[3])) == -1)
5551
- return size;
5552
- *flags |= FLAGS_DID_NOTE;
5553
- return size;
5554
+ return 1;
5555
+ return 1;
5556
}
5557
5558
- if (namesz == 4 && strcmp((char *)&nbuf[noff], "GNU") == 0 &&
5559
- xnh_type == NT_GNU_BUILD_ID && (descsz == 16 || descsz == 20)) {
5560
- uint8_t desc[20];
5561
- uint32_t i;
5562
- if (file_printf(ms, ", BuildID[%s]=", descsz == 16 ? "md5/uuid" :
5563
- "sha1") == -1)
5564
- return size;
5565
- (void)memcpy(desc, &nbuf[doff], descsz);
5566
- for (i = 0; i < descsz; i++)
5567
- if (file_printf(ms, "%02x", desc[i]) == -1)
5568
- return size;
5569
- *flags |= FLAGS_DID_BUILD_ID;
5570
+ if (namesz == 7 && strcmp((char *)&nbuf[noff], "NetBSD") == 0) {
5571
+ if (type == NT_NETBSD_VERSION && descsz == 4) {
5572
+ *flags |= FLAGS_DID_OS_NOTE;
5573
+ do_note_netbsd_version(ms, swap, &nbuf[doff]);
5574
+ return 1;
5575
+ }
5576
}
5577
5578
+ if (namesz == 8 && strcmp((char *)&nbuf[noff], "FreeBSD") == 0) {
5579
+ if (type == NT_FREEBSD_VERSION && descsz == 4) {
5580
+ *flags |= FLAGS_DID_OS_NOTE;
5581
+ do_note_freebsd_version(ms, swap, &nbuf[doff]);
5582
+ return 1;
5583
+ }
5584
+ }
5585
+
5586
+ if (namesz == 8 && strcmp((char *)&nbuf[noff], "OpenBSD") == 0 &&
5587
+ type == NT_OPENBSD_VERSION && descsz == 4) {
5588
+ *flags |= FLAGS_DID_OS_NOTE;
5589
+ if (file_printf(ms, ", for OpenBSD") == -1)
5590
+ return 1;
5591
+ /* Content of note is always 0 */
5592
+ return 1;
5593
+ }
5594
+
5595
+ if (namesz == 10 && strcmp((char *)&nbuf[noff], "DragonFly") == 0 &&
5596
+ type == NT_DRAGONFLY_VERSION && descsz == 4) {
5597
+ uint32_t desc;
5598
+ *flags |= FLAGS_DID_OS_NOTE;
5599
+ if (file_printf(ms, ", for DragonFly") == -1)
5600
+ return 1;
5601
+ (void)memcpy(&desc, &nbuf[doff], sizeof(desc));
5602
+ desc = elf_getu32(swap, desc);
5603
+ if (file_printf(ms, " %d.%d.%d", desc / 100000,
5604
+ desc / 10000 % 10, desc % 10000) == -1)
5605
+ return 1;
5606
+ return 1;
5607
+ }
5608
+ return 0;
5609
+}
5610
+
5611
+private int
5612
+do_pax_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
5613
+ int swap, uint32_t namesz, uint32_t descsz,
5614
+ size_t noff, size_t doff, int *flags)
5615
+{
5616
if (namesz == 4 && strcmp((char *)&nbuf[noff], "PaX") == 0 &&
5617
- xnh_type == NT_NETBSD_PAX && descsz == 4) {
5618
+ type == NT_NETBSD_PAX && descsz == 4) {
5619
static const char *pax[] = {
5620
"+mprotect",
5621
"-mprotect",
5622
@@ -614,11 +614,12 @@ do_note_freebsd_version(struct magic_set *ms, int
5623
size_t i;
5624
int did = 0;
5625
5626
+ *flags |= FLAGS_DID_NETBSD_PAX;
5627
(void)memcpy(&desc, &nbuf[doff], sizeof(desc));
5628
desc = elf_getu32(swap, desc);
5629
5630
if (desc && file_printf(ms, ", PaX: ") == -1)
5631
- return size;
5632
+ return 1;
5633
5634
for (i = 0; i < __arraycount(pax); i++) {
5635
if (((1 << i) & desc) == 0)
5636
@@ -625,69 +626,20 @@ do_note_freebsd_version(struct magic_set *ms, int
5637
continue;
5638
if (file_printf(ms, "%s%s", did++ ? "," : "",
5639
pax[i]) == -1)
5640
- return size;
5641
+ return 1;
5642
}
5643
+ return 1;
5644
}
5645
+ return 0;
5646
+}
5647
5648
- if (namesz == 7 && strcmp((char *)&nbuf[noff], "NetBSD") == 0) {
5649
- switch (xnh_type) {
5650
- case NT_NETBSD_VERSION:
5651
- if (descsz == 4) {
5652
- do_note_netbsd_version(ms, swap, &nbuf[doff]);
5653
- *flags |= FLAGS_DID_NOTE;
5654
- return size;
5655
- }
5656
- break;
5657
- case NT_NETBSD_MARCH:
5658
- if (file_printf(ms, ", compiled for: %.*s", (int)descsz,
5659
- (const char *)&nbuf[doff]) == -1)
5660
- return size;
5661
- break;
5662
- case NT_NETBSD_CMODEL:
5663
- if (file_printf(ms, ", compiler model: %.*s",
5664
- (int)descsz, (const char *)&nbuf[doff]) == -1)
5665
- return size;
5666
- break;
5667
- default:
5668
- if (file_printf(ms, ", note=%u", xnh_type) == -1)
5669
- return size;
5670
- break;
5671
- }
5672
- return size;
5673
- }
5674
-
5675
- if (namesz == 8 && strcmp((char *)&nbuf[noff], "FreeBSD") == 0) {
5676
- if (xnh_type == NT_FREEBSD_VERSION && descsz == 4) {
5677
- do_note_freebsd_version(ms, swap, &nbuf[doff]);
5678
- *flags |= FLAGS_DID_NOTE;
5679
- return size;
5680
- }
5681
- }
5682
-
5683
- if (namesz == 8 && strcmp((char *)&nbuf[noff], "OpenBSD") == 0 &&
5684
- xnh_type == NT_OPENBSD_VERSION && descsz == 4) {
5685
- if (file_printf(ms, ", for OpenBSD") == -1)
5686
- return size;
5687
- /* Content of note is always 0 */
5688
- *flags |= FLAGS_DID_NOTE;
5689
- return size;
5690
- }
5691
-
5692
- if (namesz == 10 && strcmp((char *)&nbuf[noff], "DragonFly") == 0 &&
5693
- xnh_type == NT_DRAGONFLY_VERSION && descsz == 4) {
5694
- uint32_t desc;
5695
- if (file_printf(ms, ", for DragonFly") == -1)
5696
- return size;
5697
- (void)memcpy(&desc, &nbuf[doff], sizeof(desc));
5698
- desc = elf_getu32(swap, desc);
5699
- if (file_printf(ms, " %d.%d.%d", desc / 100000,
5700
- desc / 10000 % 10, desc % 10000) == -1)
5701
- return size;
5702
- *flags |= FLAGS_DID_NOTE;
5703
- return size;
5704
- }
5705
-
5706
-core:
5707
+private int
5708
+do_core_note(struct magic_set *ms, unsigned char *nbuf, uint32_t type,
5709
+ int swap, uint32_t namesz, uint32_t descsz,
5710
+ size_t noff, size_t doff, int *flags, size_t size, int clazz)
5711
+{
5712
+#ifdef ELFCORE
5713
+ int os_style = -1;
5714
/*
5715
* Sigh. The 2.0.36 kernel in Debian 2.1, at
5716
* least, doesn't correctly implement name
5717
@@ -716,20 +668,17 @@ do_note_freebsd_version(struct magic_set *ms, int
5718
os_style = OS_STYLE_NETBSD;
5719
}
5720
5721
-#ifdef ELFCORE
5722
- if ((*flags & FLAGS_DID_CORE) != 0)
5723
- return size;
5724
-
5725
if (os_style != -1 && (*flags & FLAGS_DID_CORE_STYLE) == 0) {
5726
if (file_printf(ms, ", %s-style", os_style_names[os_style])
5727
== -1)
5728
- return size;
5729
+ return 1;
5730
*flags |= FLAGS_DID_CORE_STYLE;
5731
}
5732
5733
switch (os_style) {
5734
case OS_STYLE_NETBSD:
5735
- if (xnh_type == NT_NETBSD_CORE_PROCINFO) {
5736
+ if (type == NT_NETBSD_CORE_PROCINFO) {
5737
+ char sbuf[512];
5738
uint32_t signo;
5739
/*
5740
* Extract the program name. It is at
5741
@@ -737,8 +686,9 @@ do_note_freebsd_version(struct magic_set *ms, int
5742
* including the terminating NUL.
5743
*/
5744
if (file_printf(ms, ", from '%.31s'",
5745
- &nbuf[doff + 0x7c]) == -1)
5746
- return size;
5747
+ file_printable(sbuf, sizeof(sbuf),
5748
+ (const char *)&nbuf[doff + 0x7c])) == -1)
5749
+ return 1;
5750
5751
/*
5752
* Extract the signal number. It is at
5753
@@ -748,14 +698,14 @@ do_note_freebsd_version(struct magic_set *ms, int
5754
sizeof(signo));
5755
if (file_printf(ms, " (signal %u)",
5756
elf_getu32(swap, signo)) == -1)
5757
- return size;
5758
+ return 1;
5759
*flags |= FLAGS_DID_CORE;
5760
- return size;
5761
+ return 1;
5762
}
5763
break;
5764
5765
default:
5766
- if (xnh_type == NT_PRPSINFO && *flags & FLAGS_IS_CORE) {
5767
+ if (type == NT_PRPSINFO && *flags & FLAGS_IS_CORE) {
5768
size_t i, j;
5769
unsigned char c;
5770
/*
5771
@@ -823,7 +773,7 @@ do_note_freebsd_version(struct magic_set *ms, int
5772
* Try next offsets, in case this match is
5773
* in the middle of a string.
5774
*/
5775
- for (k = i + 1 ; k < NOFFSETS ; k++) {
5776
+ for (k = i + 1 ; k < NOFFSETS; k++) {
5777
size_t no;
5778
int adjust = 1;
5779
if (prpsoffsets(k) >= prpsoffsets(i))
5780
@@ -848,9 +798,9 @@ do_note_freebsd_version(struct magic_set *ms, int
5781
cp--;
5782
if (file_printf(ms, ", from '%.*s'",
5783
(int)(cp - cname), cname) == -1)
5784
- return size;
5785
+ return 1;
5786
*flags |= FLAGS_DID_CORE;
5787
- return size;
5788
+ return 1;
5789
5790
tryanother:
5791
;
5792
@@ -859,6 +809,129 @@ do_note_freebsd_version(struct magic_set *ms, int
5793
break;
5794
}
5795
#endif
5796
+ return 0;
5797
+}
5798
+
5799
+private size_t
5800
+donote(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
5801
+ int clazz, int swap, size_t align, int *flags, uint16_t *notecount)
5802
+{
5803
+ Elf32_Nhdr nh32;
5804
+ Elf64_Nhdr nh64;
5805
+ size_t noff, doff;
5806
+ uint32_t namesz, descsz;
5807
+ unsigned char *nbuf = CAST(unsigned char *, vbuf);
5808
+
5809
+ if (*notecount == 0)
5810
+ return 0;
5811
+ --*notecount;
5812
+
5813
+ if (xnh_sizeof + offset > size) {
5814
+ /*
5815
+ * We're out of note headers.
5816
+ */
5817
+ return xnh_sizeof + offset;
5818
+ }
5819
+
5820
+ (void)memcpy(xnh_addr, &nbuf[offset], xnh_sizeof);
5821
+ offset += xnh_sizeof;
5822
+
5823
+ namesz = xnh_namesz;
5824
+ descsz = xnh_descsz;
5825
+ if ((namesz == 0) && (descsz == 0)) {
5826
+ /*
5827
+ * We're out of note headers.
5828
+ */
5829
+ return (offset >= size) ? offset : size;
5830
+ }
5831
+
5832
+ if (namesz & 0x80000000) {
5833
+ (void)file_printf(ms, ", bad note name size 0x%lx",
5834
+ (unsigned long)namesz);
5835
+ return 0;
5836
+ }
5837
+
5838
+ if (descsz & 0x80000000) {
5839
+ (void)file_printf(ms, ", bad note description size 0x%lx",
5840
+ (unsigned long)descsz);
5841
+ return 0;
5842
+ }
5843
+
5844
+ noff = offset;
5845
+ doff = ELF_ALIGN(offset + namesz);
5846
+
5847
+ if (offset + namesz > size) {
5848
+ /*
5849
+ * We're past the end of the buffer.
5850
+ */
5851
+ return doff;
5852
+ }
5853
+
5854
+ offset = ELF_ALIGN(doff + descsz);
5855
+ if (doff + descsz > size) {
5856
+ /*
5857
+ * We're past the end of the buffer.
5858
+ */
5859
+ return (offset >= size) ? offset : size;
5860
+ }
5861
+
5862
+ if ((*flags & FLAGS_DID_OS_NOTE) == 0) {
5863
+ if (do_os_note(ms, nbuf, xnh_type, swap,
5864
+ namesz, descsz, noff, doff, flags))
5865
+ return size;
5866
+ }
5867
+
5868
+ if ((*flags & FLAGS_DID_BUILD_ID) == 0) {
5869
+ if (do_bid_note(ms, nbuf, xnh_type, swap,
5870
+ namesz, descsz, noff, doff, flags))
5871
+ return size;
5872
+ }
5873
+
5874
+ if ((*flags & FLAGS_DID_NETBSD_PAX) == 0) {
5875
+ if (do_pax_note(ms, nbuf, xnh_type, swap,
5876
+ namesz, descsz, noff, doff, flags))
5877
+ return size;
5878
+ }
5879
+
5880
+ if ((*flags & FLAGS_DID_CORE) == 0) {
5881
+ if (do_core_note(ms, nbuf, xnh_type, swap,
5882
+ namesz, descsz, noff, doff, flags, size, clazz))
5883
+ return size;
5884
+ }
5885
+
5886
+ if (namesz == 7 && strcmp((char *)&nbuf[noff], "NetBSD") == 0) {
5887
+ if (descsz > 100)
5888
+ descsz = 100;
5889
+ switch (xnh_type) {
5890
+ case NT_NETBSD_VERSION:
5891
+ return size;
5892
+ case NT_NETBSD_MARCH:
5893
+ if (*flags & FLAGS_DID_NETBSD_MARCH)
5894
+ return size;
5895
+ *flags |= FLAGS_DID_NETBSD_MARCH;
5896
+ if (file_printf(ms, ", compiled for: %.*s",
5897
+ (int)descsz, (const char *)&nbuf[doff]) == -1)
5898
+ return size;
5899
+ break;
5900
+ case NT_NETBSD_CMODEL:
5901
+ if (*flags & FLAGS_DID_NETBSD_CMODEL)
5902
+ return size;
5903
+ *flags |= FLAGS_DID_NETBSD_CMODEL;
5904
+ if (file_printf(ms, ", compiler model: %.*s",
5905
+ (int)descsz, (const char *)&nbuf[doff]) == -1)
5906
+ return size;
5907
+ break;
5908
+ default:
5909
+ if (*flags & FLAGS_DID_NETBSD_UNKNOWN)
5910
+ return size;
5911
+ *flags |= FLAGS_DID_NETBSD_UNKNOWN;
5912
+ if (file_printf(ms, ", note=%u", xnh_type) == -1)
5913
+ return size;
5914
+ break;
5915
+ }
5916
+ return size;
5917
+ }
5918
+
5919
return offset;
5920
}
5921
5922
@@ -914,7 +987,8 @@ static const cap_desc_t cap_desc_386[] = {
5923
5924
private int
5925
doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
5926
- size_t size, off_t fsize, int *flags, int mach, int strtab)
5927
+ size_t size, off_t fsize, int mach, int strtab, int *flags,
5928
+ uint16_t *notecount)
5929
{
5930
Elf32_Shdr sh32;
5931
Elf64_Shdr sh64;
5932
@@ -925,6 +999,7 @@ doshn(struct magic_set *ms, int clazz, int swap, i
5933
uint64_t cap_hw1 = 0; /* SunOS 5.x hardware capabilites */
5934
uint64_t cap_sf1 = 0; /* SunOS 5.x software capabilites */
5935
char name[50];
5936
+ ssize_t namesize;
5937
5938
if (size != xsh_sizeof) {
5939
if (file_printf(ms, ", corrupted section header size") == -1)
5940
@@ -933,7 +1008,7 @@ doshn(struct magic_set *ms, int clazz, int swap, i
5941
}
5942
5943
/* Read offset of name section to be able to read section names later */
5944
- if (pread(fd, xsh_addr, xsh_sizeof, off + size * strtab) == -1) {
5945
+ if (pread(fd, xsh_addr, xsh_sizeof, off + size * strtab) < (ssize_t)xsh_sizeof) {
5946
file_badread(ms);
5947
return -1;
5948
}
5949
@@ -941,15 +1016,15 @@ doshn(struct magic_set *ms, int clazz, int swap, i
5950
5951
for ( ; num; num--) {
5952
/* Read the name of this section. */
5953
- if (pread(fd, name, sizeof(name), name_off + xsh_name) == -1) {
5954
+ if ((namesize = pread(fd, name, sizeof(name) - 1, name_off + xsh_name)) == -1) {
5955
file_badread(ms);
5956
return -1;
5957
}
5958
- name[sizeof(name) - 1] = '\0';
5959
+ name[namesize] = '\0';
5960
if (strcmp(name, ".debug_info") == 0)
5961
stripped = 0;
5962
5963
- if (pread(fd, xsh_addr, xsh_sizeof, off) == -1) {
5964
+ if (pread(fd, xsh_addr, xsh_sizeof, off) < (ssize_t)xsh_sizeof) {
5965
file_badread(ms);
5966
return -1;
5967
}
5968
@@ -964,7 +1039,7 @@ doshn(struct magic_set *ms, int clazz, int swap, i
5969
stripped = 0;
5970
break;
5971
default:
5972
- if (xsh_offset > fsize) {
5973
+ if (fsize != SIZE_UNKNOWN && xsh_offset > fsize) {
5974
/* Perhaps warn here */
5975
continue;
5976
}
5977
@@ -979,7 +1054,7 @@ doshn(struct magic_set *ms, int clazz, int swap, i
5978
" for note");
5979
return -1;
5980
}
5981
- if (pread(fd, nbuf, xsh_size, xsh_offset) == -1) {
5982
+ if (pread(fd, nbuf, xsh_size, xsh_offset) < (ssize_t)xsh_size) {
5983
file_badread(ms);
5984
free(nbuf);
5985
return -1;
5986
@@ -990,7 +1065,7 @@ doshn(struct magic_set *ms, int clazz, int swap, i
5987
if (noff >= (off_t)xsh_size)
5988
break;
5989
noff = donote(ms, nbuf, (size_t)noff,
5990
- xsh_size, clazz, swap, 4, flags);
5991
+ xsh_size, clazz, swap, 4, flags, notecount);
5992
if (noff == 0)
5993
break;
5994
}
5995
@@ -1157,13 +1232,15 @@ doshn(struct magic_set *ms, int clazz, int swap, i
5996
*/
5997
private int
5998
dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
5999
- int num, size_t size, off_t fsize, int *flags, int sh_num)
6000
+ int num, size_t size, off_t fsize, int sh_num, int *flags,
6001
+ uint16_t *notecount)
6002
{
6003
Elf32_Phdr ph32;
6004
Elf64_Phdr ph64;
6005
const char *linking_style = "statically";
6006
- const char *shared_libraries = "";
6007
+ const char *interp = "";
6008
unsigned char nbuf[BUFSIZ];
6009
+ char ibuf[BUFSIZ];
6010
ssize_t bufsize;
6011
size_t offset, align, len;
6012
6013
@@ -1174,12 +1251,14 @@ dophn_exec(struct magic_set *ms, int clazz, int sw
6014
}
6015
6016
for ( ; num; num--) {
6017
- if (pread(fd, xph_addr, xph_sizeof, off) == -1) {
6018
+ if (pread(fd, xph_addr, xph_sizeof, off) < (ssize_t)xph_sizeof) {
6019
file_badread(ms);
6020
return -1;
6021
}
6022
6023
off += size;
6024
+ bufsize = 0;
6025
+ align = 4;
6026
6027
/* Things we can determine before we seek */
6028
switch (xph_type) {
6029
@@ -1186,11 +1265,29 @@ dophn_exec(struct magic_set *ms, int clazz, int sw
6030
case PT_DYNAMIC:
6031
linking_style = "dynamically";
6032
break;
6033
+ case PT_NOTE:
6034
+ if (sh_num) /* Did this through section headers */
6035
+ continue;
6036
+ if (((align = xph_align) & 0x80000000UL) != 0 ||
6037
+ align < 4) {
6038
+ if (file_printf(ms,
6039
+ ", invalid note alignment 0x%lx",
6040
+ (unsigned long)align) == -1)
6041
+ return -1;
6042
+ align = 4;
6043
+ }
6044
+ /*FALLTHROUGH*/
6045
case PT_INTERP:
6046
- shared_libraries = " (uses shared libs)";
6047
+ len = xph_filesz < sizeof(nbuf) ? xph_filesz
6048
+ : sizeof(nbuf);
6049
+ bufsize = pread(fd, nbuf, len, xph_offset);
6050
+ if (bufsize == -1) {
6051
+ file_badread(ms);
6052
+ return -1;
6053
+ }
6054
break;
6055
default:
6056
- if (xph_offset > fsize) {
6057
+ if (fsize != SIZE_UNKNOWN && xph_offset > fsize) {
6058
/* Maybe warn here? */
6059
continue;
6060
}
6061
@@ -1199,27 +1296,18 @@ dophn_exec(struct magic_set *ms, int clazz, int sw
6062
6063
/* Things we can determine when we seek */
6064
switch (xph_type) {
6065
+ case PT_INTERP:
6066
+ if (bufsize && nbuf[0]) {
6067
+ nbuf[bufsize - 1] = '\0';
6068
+ interp = (const char *)nbuf;
6069
+ } else
6070
+ interp = "*empty*";
6071
+ break;
6072
case PT_NOTE:
6073
- if ((align = xph_align) & 0x80000000UL) {
6074
- if (file_printf(ms,
6075
- ", invalid note alignment 0x%lx",
6076
- (unsigned long)align) == -1)
6077
- return -1;
6078
- align = 4;
6079
- }
6080
- if (sh_num)
6081
- break;
6082
/*
6083
* This is a PT_NOTE section; loop through all the notes
6084
* in the section.
6085
*/
6086
- len = xph_filesz < sizeof(nbuf) ? xph_filesz
6087
- : sizeof(nbuf);
6088
- bufsize = pread(fd, nbuf, len, xph_offset);
6089
- if (bufsize == -1) {
6090
- file_badread(ms);
6091
- return -1;
6092
- }
6093
offset = 0;
6094
for (;;) {
6095
if (offset >= (size_t)bufsize)
6096
@@ -1226,7 +1314,7 @@ dophn_exec(struct magic_set *ms, int clazz, int sw
6097
break;
6098
offset = donote(ms, nbuf, offset,
6099
(size_t)bufsize, clazz, swap, align,
6100
- flags);
6101
+ flags, notecount);
6102
if (offset == 0)
6103
break;
6104
}
6105
@@ -1235,9 +1323,13 @@ dophn_exec(struct magic_set *ms, int clazz, int sw
6106
break;
6107
}
6108
}
6109
- if (file_printf(ms, ", %s linked%s", linking_style, shared_libraries)
6110
+ if (file_printf(ms, ", %s linked", linking_style)
6111
== -1)
6112
- return -1;
6113
+ return -1;
6114
+ if (interp[0])
6115
+ if (file_printf(ms, ", interpreter %s",
6116
+ file_printable(ibuf, sizeof(ibuf), interp)) == -1)
6117
+ return -1;
6118
return 0;
6119
}
6120
6121
@@ -1257,7 +1349,7 @@ file_tryelf(struct magic_set *ms, int fd, const un
6122
int flags = 0;
6123
Elf32_Ehdr elf32hdr;
6124
Elf64_Ehdr elf64hdr;
6125
- uint16_t type, phnum, shnum;
6126
+ uint16_t type, phnum, shnum, notecount;
6127
6128
if (ms->flags & (MAGIC_MIME|MAGIC_APPLE))
6129
return 0;
6130
@@ -1283,7 +1375,10 @@ file_tryelf(struct magic_set *ms, int fd, const un
6131
file_badread(ms);
6132
return -1;
6133
}
6134
- fsize = st.st_size;
6135
+ if (S_ISREG(st.st_mode) || st.st_size != 0)
6136
+ fsize = st.st_size;
6137
+ else
6138
+ fsize = SIZE_UNKNOWN;
6139
6140
clazz = buf[EI_CLASS];
6141
6142
Index: contrib/file/src/softmagic.c
6143
===================================================================
6144
--- contrib/file/src/softmagic.c (revision 284174)
6145
+++ contrib/file/src/softmagic.c (working copy)
6146
@@ -32,7 +32,7 @@
6147
#include "file.h"
6148
6149
#ifndef lint
6150
-FILE_RCSID("@(#)$File: softmagic.c,v 1.191 2014/06/04 17:36:34 christos Exp $")
6151
+FILE_RCSID("@(#)$File: softmagic.c,v 1.206 2015/01/01 17:07:34 christos Exp $")
6152
#endif /* lint */
6153
6154
#include "magic.h"
6155
@@ -41,17 +41,13 @@
6156
#include <ctype.h>
6157
#include <stdlib.h>
6158
#include <time.h>
6159
-#if defined(HAVE_LOCALE_H)
6160
-#include <locale.h>
6161
-#endif
6162
6163
-
6164
private int match(struct magic_set *, struct magic *, uint32_t,
6165
- const unsigned char *, size_t, size_t, int, int, int, int, int *, int *,
6166
- int *);
6167
+ const unsigned char *, size_t, size_t, int, int, int, uint16_t,
6168
+ uint16_t *, int *, int *, int *);
6169
private int mget(struct magic_set *, const unsigned char *,
6170
- struct magic *, size_t, size_t, unsigned int, int, int, int, int, int *,
6171
- int *, int *);
6172
+ struct magic *, size_t, size_t, unsigned int, int, int, int, uint16_t,
6173
+ uint16_t *, int *, int *, int *);
6174
private int magiccheck(struct magic_set *, struct magic *);
6175
private int32_t mprint(struct magic_set *, struct magic *);
6176
private int32_t moffset(struct magic_set *, struct magic *);
6177
@@ -68,8 +64,6 @@ private void cvt_64(union VALUETYPE *, const struc
6178
6179
#define OFFSET_OOB(n, o, i) ((n) < (o) || (i) > ((n) - (o)))
6180
6181
-#define MAX_RECURSION_LEVEL 10
6182
-
6183
/*
6184
* softmagic - lookup one file in parsed, in-memory copy of database
6185
* Passed the name and FILE * of one file to be typed.
6186
@@ -77,14 +71,21 @@ private void cvt_64(union VALUETYPE *, const struc
6187
/*ARGSUSED1*/ /* nbytes passed for regularity, maybe need later */
6188
protected int
6189
file_softmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes,
6190
- size_t level, int mode, int text)
6191
+ uint16_t indir_level, uint16_t *name_count, int mode, int text)
6192
{
6193
struct mlist *ml;
6194
int rv, printed_something = 0, need_separator = 0;
6195
+ uint16_t nc;
6196
+
6197
+ if (name_count == NULL) {
6198
+ nc = 0;
6199
+ name_count = &nc;
6200
+ }
6201
+
6202
for (ml = ms->mlist[0]->next; ml != ms->mlist[0]; ml = ml->next)
6203
if ((rv = match(ms, ml->magic, ml->nmagic, buf, nbytes, 0, mode,
6204
- text, 0, level, &printed_something, &need_separator,
6205
- NULL)) != 0)
6206
+ text, 0, indir_level, name_count,
6207
+ &printed_something, &need_separator, NULL)) != 0)
6208
return rv;
6209
6210
return 0;
6211
@@ -101,8 +102,8 @@ file_fmtcheck(struct magic_set *ms, const struct m
6212
const char *ptr = fmtcheck(m->desc, def);
6213
if (ptr == def)
6214
file_magerror(ms,
6215
- "%s, %zu: format `%s' does not match with `%s'",
6216
- file, line, m->desc, def);
6217
+ "%s, %" SIZE_T_FORMAT "u: format `%s' does not match"
6218
+ " with `%s'", file, line, m->desc, def);
6219
return ptr;
6220
}
6221
#else
6222
@@ -139,8 +140,8 @@ file_fmtcheck(struct magic_set *ms, const struct m
6223
private int
6224
match(struct magic_set *ms, struct magic *magic, uint32_t nmagic,
6225
const unsigned char *s, size_t nbytes, size_t offset, int mode, int text,
6226
- int flip, int recursion_level, int *printed_something, int *need_separator,
6227
- int *returnval)
6228
+ int flip, uint16_t indir_level, uint16_t *name_count,
6229
+ int *printed_something, int *need_separator, int *returnval)
6230
{
6231
uint32_t magindex = 0;
6232
unsigned int cont_level = 0;
6233
@@ -177,8 +178,8 @@ match(struct magic_set *ms, struct magic *magic, u
6234
6235
/* if main entry matches, print it... */
6236
switch (mget(ms, s, m, nbytes, offset, cont_level, mode, text,
6237
- flip, recursion_level + 1, printed_something,
6238
- need_separator, returnval)) {
6239
+ flip, indir_level, name_count,
6240
+ printed_something, need_separator, returnval)) {
6241
case -1:
6242
return -1;
6243
case 0:
6244
@@ -238,9 +239,9 @@ match(struct magic_set *ms, struct magic *magic, u
6245
if (file_check_mem(ms, ++cont_level) == -1)
6246
return -1;
6247
6248
- while (++magindex < nmagic &&
6249
- magic[magindex].cont_level != 0) {
6250
- m = &magic[magindex];
6251
+ while (magindex + 1 < nmagic &&
6252
+ magic[magindex + 1].cont_level != 0) {
6253
+ m = &magic[++magindex];
6254
ms->line = m->lineno; /* for messages */
6255
6256
if (cont_level < m->cont_level)
6257
@@ -266,8 +267,8 @@ match(struct magic_set *ms, struct magic *magic, u
6258
}
6259
#endif
6260
switch (mget(ms, s, m, nbytes, offset, cont_level, mode,
6261
- text, flip, recursion_level + 1, printed_something,
6262
- need_separator, returnval)) {
6263
+ text, flip, indir_level, name_count,
6264
+ printed_something, need_separator, returnval)) {
6265
case -1:
6266
return -1;
6267
case 0:
6268
@@ -410,7 +411,7 @@ mprint(struct magic_set *ms, struct magic *m)
6269
float vf;
6270
double vd;
6271
int64_t t = 0;
6272
- char buf[128], tbuf[26];
6273
+ char buf[128], tbuf[26], sbuf[512];
6274
union VALUETYPE *p = &ms->ms_value;
6275
6276
switch (m->type) {
6277
@@ -504,7 +505,9 @@ mprint(struct magic_set *ms, struct magic *m)
6278
case FILE_BESTRING16:
6279
case FILE_LESTRING16:
6280
if (m->reln == '=' || m->reln == '!') {
6281
- if (file_printf(ms, F(ms, m, "%s"), m->value.s) == -1)
6282
+ if (file_printf(ms, F(ms, m, "%s"),
6283
+ file_printable(sbuf, sizeof(sbuf), m->value.s))
6284
+ == -1)
6285
return -1;
6286
t = ms->offset + m->vallen;
6287
}
6288
@@ -530,7 +533,8 @@ mprint(struct magic_set *ms, struct magic *m)
6289
*++last = '\0';
6290
}
6291
6292
- if (file_printf(ms, F(ms, m, "%s"), str) == -1)
6293
+ if (file_printf(ms, F(ms, m, "%s"),
6294
+ file_printable(sbuf, sizeof(sbuf), str)) == -1)
6295
return -1;
6296
6297
if (m->type == FILE_PSTRING)
6298
@@ -634,7 +638,8 @@ mprint(struct magic_set *ms, struct magic *m)
6299
file_oomem(ms, ms->search.rm_len);
6300
return -1;
6301
}
6302
- rval = file_printf(ms, F(ms, m, "%s"), cp);
6303
+ rval = file_printf(ms, F(ms, m, "%s"),
6304
+ file_printable(sbuf, sizeof(sbuf), cp));
6305
free(cp);
6306
6307
if (rval == -1)
6308
@@ -648,7 +653,8 @@ mprint(struct magic_set *ms, struct magic *m)
6309
}
6310
6311
case FILE_SEARCH:
6312
- if (file_printf(ms, F(ms, m, "%s"), m->value.s) == -1)
6313
+ if (file_printf(ms, F(ms, m, "%s"),
6314
+ file_printable(sbuf, sizeof(sbuf), m->value.s)) == -1)
6315
return -1;
6316
if ((m->str_flags & REGEX_OFFSET_START))
6317
t = ms->search.offset;
6318
@@ -946,14 +952,17 @@ mconvert(struct magic_set *ms, struct magic *m, in
6319
size_t sz = file_pstring_length_size(m);
6320
char *ptr1 = p->s, *ptr2 = ptr1 + sz;
6321
size_t len = file_pstring_get_length(m, ptr1);
6322
- if (len >= sizeof(p->s)) {
6323
+ sz = sizeof(p->s) - sz; /* maximum length of string */
6324
+ if (len >= sz) {
6325
/*
6326
* The size of the pascal string length (sz)
6327
* is 1, 2, or 4. We need at least 1 byte for NUL
6328
* termination, but we've already truncated the
6329
* string by p->s, so we need to deduct sz.
6330
+ * Because we can use one of the bytes of the length
6331
+ * after we shifted as NUL termination.
6332
*/
6333
- len = sizeof(p->s) - sz;
6334
+ len = sz;
6335
}
6336
while (len--)
6337
*ptr1++ = *ptr2++;
6338
@@ -1063,7 +1072,7 @@ mconvert(struct magic_set *ms, struct magic *m, in
6339
private void
6340
mdebug(uint32_t offset, const char *str, size_t len)
6341
{
6342
- (void) fprintf(stderr, "mget/%zu @%d: ", len, offset);
6343
+ (void) fprintf(stderr, "mget/%" SIZE_T_FORMAT "u @%d: ", len, offset);
6344
file_showstr(stderr, str, len);
6345
(void) fputc('\n', stderr);
6346
(void) fputc('\n', stderr);
6347
@@ -1193,8 +1202,8 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, in
6348
private int
6349
mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
6350
size_t nbytes, size_t o, unsigned int cont_level, int mode, int text,
6351
- int flip, int recursion_level, int *printed_something,
6352
- int *need_separator, int *returnval)
6353
+ int flip, uint16_t indir_level, uint16_t *name_count,
6354
+ int *printed_something, int *need_separator, int *returnval)
6355
{
6356
uint32_t offset = ms->offset;
6357
uint32_t lhs;
6358
@@ -1204,18 +1213,28 @@ mget(struct magic_set *ms, const unsigned char *s,
6359
union VALUETYPE *p = &ms->ms_value;
6360
struct mlist ml;
6361
6362
- if (recursion_level >= MAX_RECURSION_LEVEL) {
6363
- file_error(ms, 0, "recursion nesting exceeded");
6364
+ if (indir_level >= ms->indir_max) {
6365
+ file_error(ms, 0, "indirect recursion nesting (%hu) exceeded",
6366
+ indir_level);
6367
return -1;
6368
}
6369
6370
+ if (*name_count >= ms->name_max) {
6371
+ file_error(ms, 0, "name use count (%hu) exceeded",
6372
+ *name_count);
6373
+ return -1;
6374
+ }
6375
+
6376
if (mcopy(ms, p, m->type, m->flag & INDIR, s, (uint32_t)(offset + o),
6377
(uint32_t)nbytes, m) == -1)
6378
return -1;
6379
6380
if ((ms->flags & MAGIC_DEBUG) != 0) {
6381
- fprintf(stderr, "mget(type=%d, flag=%x, offset=%u, o=%zu, "
6382
- "nbytes=%zu)\n", m->type, m->flag, offset, o, nbytes);
6383
+ fprintf(stderr, "mget(type=%d, flag=%x, offset=%u, o=%"
6384
+ SIZE_T_FORMAT "u, " "nbytes=%" SIZE_T_FORMAT
6385
+ "u, il=%hu, nc=%hu)\n",
6386
+ m->type, m->flag, offset, o, nbytes,
6387
+ indir_level, *name_count);
6388
mdebug(offset, (char *)(void *)p, sizeof(union VALUETYPE));
6389
#ifndef COMPILE_ONLY
6390
file_mdump(m);
6391
@@ -1646,6 +1665,8 @@ mget(struct magic_set *ms, const unsigned char *s,
6392
break;
6393
6394
case FILE_INDIRECT:
6395
+ if (m->str_flags & INDIRECT_RELATIVE)
6396
+ offset += o;
6397
if (offset == 0)
6398
return 0;
6399
6400
@@ -1656,7 +1677,7 @@ mget(struct magic_set *ms, const unsigned char *s,
6401
return -1;
6402
6403
rv = file_softmagic(ms, s + offset, nbytes - offset,
6404
- recursion_level, BINTEST, text);
6405
+ indir_level + 1, name_count, BINTEST, text);
6406
6407
if ((ms->flags & MAGIC_DEBUG) != 0)
6408
fprintf(stderr, "indirect @offs=%u[%d]\n", offset, rv);
6409
@@ -1691,13 +1712,13 @@ mget(struct magic_set *ms, const unsigned char *s,
6410
file_error(ms, 0, "cannot find entry `%s'", rbuf);
6411
return -1;
6412
}
6413
-
6414
+ (*name_count)++;
6415
oneed_separator = *need_separator;
6416
if (m->flag & NOSPACE)
6417
*need_separator = 0;
6418
rv = match(ms, ml.magic, ml.nmagic, s, nbytes, offset + o,
6419
- mode, text, flip, recursion_level, printed_something,
6420
- need_separator, returnval);
6421
+ mode, text, flip, indir_level, name_count,
6422
+ printed_something, need_separator, returnval);
6423
if (rv != 1)
6424
*need_separator = oneed_separator;
6425
return rv;
6426
@@ -1952,6 +1973,7 @@ magiccheck(struct magic_set *ms, struct magic *m)
6427
case FILE_REGEX: {
6428
int rc;
6429
file_regex_t rx;
6430
+ const char *search;
6431
6432
if (ms->search.s == NULL)
6433
return 0;
6434
@@ -1968,19 +1990,31 @@ magiccheck(struct magic_set *ms, struct magic *m)
6435
size_t slen = ms->search.s_len;
6436
#ifndef REG_STARTEND
6437
#define REG_STARTEND 0
6438
- char c;
6439
- if (slen != 0)
6440
- slen--;
6441
- c = ms->search.s[slen];
6442
- ((char *)(intptr_t)ms->search.s)[slen] = '\0';
6443
+ char *copy;
6444
+ if (slen != 0) {
6445
+ copy = malloc(slen);
6446
+ if (copy == NULL) {
6447
+ file_error(ms, errno,
6448
+ "can't allocate %" SIZE_T_FORMAT "u bytes",
6449
+ slen);
6450
+ return -1;
6451
+ }
6452
+ memcpy(copy, ms->search.s, slen);
6453
+ copy[--slen] = '\0';
6454
+ search = copy;
6455
+ } else {
6456
+ search = ms->search.s;
6457
+ copy = NULL;
6458
+ }
6459
#else
6460
+ search = ms->search.s;
6461
pmatch[0].rm_so = 0;
6462
pmatch[0].rm_eo = slen;
6463
#endif
6464
- rc = file_regexec(&rx, (const char *)ms->search.s,
6465
+ rc = file_regexec(&rx, (const char *)search,
6466
1, pmatch, REG_STARTEND);
6467
#if REG_STARTEND == 0
6468
- ((char *)(intptr_t)ms->search.s)[l] = c;
6469
+ free(copy);
6470
#endif
6471
switch (rc) {
6472
case 0:
6473
Index: contrib/file/src/vasprintf.c
6474
===================================================================
6475
--- contrib/file/src/vasprintf.c (revision 284174)
6476
+++ contrib/file/src/vasprintf.c (working copy)
6477
@@ -108,7 +108,7 @@ you use strange formats.
6478
#include "file.h"
6479
6480
#ifndef lint
6481
-FILE_RCSID("@(#)$File: vasprintf.c,v 1.12 2014/05/14 23:09:21 christos Exp $")
6482
+FILE_RCSID("@(#)$File: vasprintf.c,v 1.13 2014/12/04 15:56:46 christos Exp $")
6483
#endif /* lint */
6484
6485
#include <assert.h>
6486
@@ -633,11 +633,15 @@ int vasprintf(char **ptr, const char *format_strin
6487
#ifdef va_copy
6488
va_copy (s.vargs, vargs);
6489
#else
6490
-#ifdef __va_copy
6491
+# ifdef __va_copy
6492
__va_copy (s.vargs, vargs);
6493
-#else
6494
+# else
6495
+# ifdef WIN32
6496
+ s.vargs = vargs;
6497
+# else
6498
memcpy (&s.vargs, &vargs, sizeof (s.va_args));
6499
-#endif /* __va_copy */
6500
+# endif /* WIN32 */
6501
+# endif /* __va_copy */
6502
#endif /* va_copy */
6503
s.maxlen = (size_t)INT_MAX;
6504
6505
Index: lib/libmagic/config.h
6506
===================================================================
6507
--- lib/libmagic/config.h (revision 284174)
6508
+++ lib/libmagic/config.h (working copy)
6509
@@ -1,5 +1,13 @@
6510
/* $FreeBSD$ */
6511
6512
+/* Get __FreeBSD_version. */
6513
+#include <osreldate.h>
6514
+
6515
+/* Only specific versions of FreeBSD support xlocale */
6516
+#if __FreeBSD_version >= 1000002 || (__FreeBSD_version < 1000000 && __FreeBSD_version >= 900506)
6517
+#define FREEBSD_XLOCALE_SUPPORT 1
6518
+#endif
6519
+
6520
/* config.h. Generated from config.h.in by configure. */
6521
/* config.h.in. Generated from configure.ac by autoheader. */
6522
6523
@@ -47,6 +55,11 @@
6524
/* Define to 1 if you have the `fork' function. */
6525
#define HAVE_FORK 1
6526
6527
+/* Define to 1 if you have the `freelocale' function. */
6528
+#ifdef FREEBSD_XLOCALE_SUPPORT
6529
+#define HAVE_FREELOCALE 1
6530
+#endif
6531
+
6532
/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */
6533
#define HAVE_FSEEKO 1
6534
6535
@@ -98,9 +111,17 @@
6536
/* Define to 1 if you have a working `mmap' system call. */
6537
#define HAVE_MMAP 1
6538
6539
+/* Define to 1 if you have the `newlocale' function. */
6540
+#ifdef FREEBSD_XLOCALE_SUPPORT
6541
+#define HAVE_NEWLOCALE 1
6542
+#endif
6543
+
6544
/* Define to 1 if you have the `pread' function. */
6545
#define HAVE_PREAD 1
6546
6547
+/* Define to 1 if you have the `setlocale' function. */
6548
+#define HAVE_SETLOCALE 1
6549
+
6550
/* Define to 1 if you have the <stddef.h> header file. */
6551
#define HAVE_STDDEF_H 1
6552
6553
@@ -185,6 +206,11 @@
6554
/* Define to 1 if you have the <unistd.h> header file. */
6555
#define HAVE_UNISTD_H 1
6556
6557
+/* Define to 1 if you have the `uselocale' function. */
6558
+#ifdef FREEBSD_XLOCALE_SUPPORT
6559
+#define HAVE_USELOCALE 1
6560
+#endif
6561
+
6562
/* Define to 1 if you have the `utime' function. */
6563
#define HAVE_UTIME 1
6564
6565
@@ -222,6 +248,11 @@
6566
/* Define to 1 if `vfork' works. */
6567
#define HAVE_WORKING_VFORK 1
6568
6569
+/* Define to 1 if you have the <xlocale.h> header file. */
6570
+#ifdef FREEBSD_XLOCALE_SUPPORT
6571
+#define HAVE_XLOCALE_H 1
6572
+#endif
6573
+
6574
/* Define to 1 if you have the <zlib.h> header file. */
6575
#define HAVE_ZLIB_H 1
6576
6577
@@ -247,7 +278,7 @@
6578
#define PACKAGE_NAME "file"
6579
6580
/* Define to the full name and version of this package. */
6581
-#define PACKAGE_STRING "file 5.19"
6582
+#define PACKAGE_STRING "file 5.22"
6583
6584
/* Define to the one symbol short name of this package. */
6585
#define PACKAGE_TARNAME "file"
6586
@@ -256,7 +287,7 @@
6587
#define PACKAGE_URL ""
6588
6589
/* Define to the version of this package. */
6590
-#define PACKAGE_VERSION "5.19"
6591
+#define PACKAGE_VERSION "5.22"
6592
6593
/* Define to 1 if you have the ANSI C header files. */
6594
#define STDC_HEADERS 1
6595
@@ -287,7 +318,7 @@
6596
6597
6598
/* Version number of package */
6599
-#define VERSION "5.19"
6600
+#define VERSION "5.22"
6601
6602
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
6603
significant byte first (like Motorola and SPARC, unlike Intel). */
6604
6605