Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / file-tiff.c
blob36b3112a36adae1450e21f4d071493ab6f00292f
1 /* file-tiff.c
3 * Routines for image/tiff dissection
4 * Copyright 2021, Daniel Dulaney.
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * The TIFF 6 specification can be found at:
11 * https://www.adobe.io/content/dam/udp/en/open/standards/tiff/TIFF6.pdf
13 * SPDX-License-Identifier: GPL-2.0-or-later
16 #include "config.h"
17 #include <epan/packet.h>
18 #include <epan/expert.h>
19 #include <wsutil/array.h>
21 void proto_reg_handoff_tiff(void);
22 void proto_register_tiff(void);
24 static int proto_tiff;
26 // Header fields
27 static int hf_tiff_header_endianness;
28 static int hf_tiff_header_magic;
29 static int hf_tiff_header_lead_ifd;
31 // IFD fields
32 static int hf_tiff_ifd_count;
33 static int hf_tiff_ifd_next;
35 // Entry fields
36 static int hf_tiff_entry_tag;
37 static int hf_tiff_entry_type;
38 static int hf_tiff_entry_count;
39 static int hf_tiff_entry_offset;
40 static int hf_tiff_entry_unknown;
42 // Expert fields
43 static expert_field ei_tiff_unknown_tag;
44 static expert_field ei_tiff_bad_entry;
45 static expert_field ei_tiff_zero_denom;
48 static int ett_tiff;
49 static int ett_ifd;
50 static int ett_t6;
52 #define TIFF_TAG_NEW_SUBFILE_TYPE 254
53 // Fields TBD
55 #define TIFF_TAG_SUBFILE_TYPE 255
56 // Fields TBD
58 #define TIFF_TAG_IMAGE_WIDTH 256
59 static int hf_tiff_image_width;
61 #define TIFF_TAG_IMAGE_LENGTH 257
62 static int hf_tiff_image_length;
64 #define TIFF_TAG_BITS_PER_SAMPLE 258
65 static int hf_tiff_bits_per_sample;
67 #define TIFF_TAG_COMPRESSION 259
68 static int hf_tiff_compression;
70 #define TIFF_TAG_PHOTOMETRIC_INTERPRETATION 262
71 static int hf_tiff_photometric_interp;
73 #define TIFF_TAG_THRESHHOLDING 263
74 static int hf_tiff_threshholding;
76 #define TIFF_TAG_CELL_WIDTH 264
77 static int hf_tiff_cell_width;
79 #define TIFF_TAG_CELL_LENGTH 265
80 static int hf_tiff_cell_length;
82 #define TIFF_TAG_FILL_ORDER 266
83 static int hf_tiff_fill_order;
85 #define TIFF_TAG_DOCUMENT_NAME 269
86 static int hf_tiff_document_name;
88 #define TIFF_TAG_IMAGE_DESCRIPTION 270
89 static int hf_tiff_image_description;
91 #define TIFF_TAG_MAKE 271
92 static int hf_tiff_make;
94 #define TIFF_TAG_MODEL 272
95 static int hf_tiff_model;
97 #define TIFF_TAG_STRIP_OFFSETS 273
98 static int hf_tiff_strip_offset;
100 #define TIFF_TAG_ORIENTATION 274
101 static int hf_tiff_orientation;
103 #define TIFF_TAG_SAMPLES_PER_PIXEL 277
104 static int hf_tiff_samples_per_pixel;
106 #define TIFF_TAG_ROWS_PER_STRIP 278
107 static int hf_tiff_rows_per_strip;
109 #define TIFF_TAG_STRIP_BYTE_COUNTS 279
110 static int hf_tiff_strip_byte_count;
112 #define TIFF_TAG_MIN_SAMPLE_VALUE 280
113 // Fields TBD
115 #define TIFF_TAG_MAX_SAMPLE_VALUE 281
116 // Fields TBD
118 #define TIFF_TAG_X_RESOLUTION 282
119 static int hf_tiff_x_res_numer;
120 static int hf_tiff_x_res_denom;
121 static int hf_tiff_x_res_approx;
123 #define TIFF_TAG_Y_RESOLUTION 283
124 static int hf_tiff_y_res_numer;
125 static int hf_tiff_y_res_denom;
126 static int hf_tiff_y_res_approx;
128 #define TIFF_TAG_PLANAR_CONFIGURATION 284
129 static int hf_tiff_planar_configuration;
131 #define TIFF_TAG_PAGE_NAME 285
132 static int hf_tiff_page_name;
134 #define TIFF_TAG_X_POSITION 286
135 // Fields TBD
137 #define TIFF_TAG_Y_POSITION 287
138 // Fields TBD
140 #define TIFF_TAG_FREE_OFFSETS 288
141 // Fields TBD
143 #define TIFF_TAG_FREE_BYTE_COUNTS 289
144 // Fields TBD
146 #define TIFF_TAG_GRAY_RESPONSE_UNIT 290
147 static int hf_tiff_gray_response_unit;
149 #define TIFF_TAG_GRAY_RESPONSE_CURVE 291
150 // Fields TBD
152 #define TIFF_TAG_T4_OPTIONS 292
153 // Fields TBD
155 #define TIFF_TAG_T6_OPTIONS 293
156 static int hf_tiff_t6_options;
157 static int hf_tiff_t6_unused;
158 static int hf_tiff_t6_allow_uncompresed;
160 #define TIFF_TAG_RESOLUTION_UNIT 296
161 static int hf_tiff_resolution_unit;
163 #define TIFF_TAG_PAGE_NUMBER 297
164 // Fields TBD
166 #define TIFF_TAG_TRANSFER_FUNCTION 301
167 // Fields TBD
169 #define TIFF_TAG_SOFTWARE 305
170 static int hf_tiff_software;
172 #define TIFF_TAG_DATE_TIME 306
173 static int hf_tiff_date_time;
175 #define TIFF_TAG_ARTIST 315
176 static int hf_tiff_artist;
178 #define TIFF_TAG_HOST_COMPUTER 316
179 static int hf_tiff_host_computer;
181 #define TIFF_TAG_PREDICTOR 317
182 static int hf_tiff_predictor;
184 #define TIFF_TAG_WHITE_POINT 318
185 // Fields TBD
187 #define TIFF_TAG_PRIMARY_CHROMATICITIES 319
188 // Fields TBD
190 #define TIFF_TAG_COLOR_MAP 320
191 // Fields TBD
193 #define TIFF_TAG_HALFTONE_HINTS 321
194 // Fields TBD
196 #define TIFF_TAG_TILE_WIDTH 322
197 static int hf_tiff_tile_width;
199 #define TIFF_TAG_TILE_LENGTH 323
200 static int hf_tiff_tile_length;
202 #define TIFF_TAG_TILE_OFFSETS 324
203 // Fields TBD
205 #define TIFF_TAG_TILE_BYTE_COUNTS 325
206 // Fields TBD
208 #define TIFF_TAG_INK_SET 332
209 static int hf_tiff_ink_set;
211 #define TIFF_TAG_INK_NAMES 333
212 // Fields TBD
214 #define TIFF_TAG_NUMBER_OF_INKS 334
215 static int hf_tiff_number_of_inks;
217 #define TIFF_TAG_DOT_RANGE 336
218 // Fields TBD
220 #define TIFF_TAG_TARGET_PRINTER 337
221 static int hf_tiff_target_printer;
223 #define TIFF_TAG_EXTRA_SAMPLES 338
224 // Fields TBD
226 #define TIFF_TAG_SAMPLE_FORMAT 339
227 // Fields TBD
229 #define TIFF_TAG_S_MIN_SAMPLE_VALUE 340
230 // Fields TBD
232 #define TIFF_TAG_S_MAX_SAMPLE_VALUE 341
233 // Fields TBD
235 #define TIFF_TAG_TRANSFER_RANGE 342
236 // Fields TBD
238 #define TIFF_TAG_JPEG_PROC 512
239 // Fields TBD
241 #define TIFF_TAG_JPEG_INTERCHANGE_FORMAT 513
242 // Fields TBD
244 #define TIFF_TAG_JPEG_INTERCHANGE_FORMAT_LENGTH 514
245 // Fields TBD
247 #define TIFF_TAG_JPEG_RESTART_INTERVAL 515
248 // Fields TBD
250 #define TIFF_TAG_JPEG_LOSSLESS_PREDICTORS 517
251 // Fields TBD
253 #define TIFF_TAG_JPEG_POINT_TRANSFORMS 518
254 // Fields TBD
256 #define TIFF_TAG_JPEG_Q_TABLES 519
257 // Fields TBD
259 #define TIFF_TAG_JPEG_DC_TABLES 520
260 // Fields TBD
262 #define TIFF_TAG_JPEG_AC_TABLES 521
263 // Fields TBD
265 #define TIFF_TAG_YCBCR_COEFFICIENTS 529
266 // Fields TBD
268 #define TIFF_TAG_YCBCR_SUBSAMPLING 530
269 // Fields TBD
271 #define TIFF_TAG_YCBCR_POSITIONING 531
272 // Fields TBD
274 #define TIFF_TAG_REFERENCE_BLACK_WHITE 532
275 // Fields TBD
277 #define TIFF_TAG_COPYRIGHT 0x8298
278 static int hf_tiff_copyright;
280 static const value_string tiff_endianness_names[] = {
281 { 0x4949, "Little-Endian" },
282 { 0x4D4D, "Big-Endian" },
283 { 0, NULL },
286 static const value_string tiff_tag_names[] = {
287 { TIFF_TAG_NEW_SUBFILE_TYPE, "New Subfile Type" },
288 { TIFF_TAG_SUBFILE_TYPE, "Subfile Type" },
289 { TIFF_TAG_IMAGE_WIDTH, "Image Width" },
290 { TIFF_TAG_IMAGE_LENGTH, "Image Length" },
291 { TIFF_TAG_BITS_PER_SAMPLE, "Bits Per Sample" },
292 { TIFF_TAG_COMPRESSION, "Compression" },
293 { TIFF_TAG_PHOTOMETRIC_INTERPRETATION, "Photometric Interpretation" },
294 { TIFF_TAG_THRESHHOLDING, "Threshholding" },
295 { TIFF_TAG_CELL_WIDTH, "Cell Width" },
296 { TIFF_TAG_CELL_LENGTH, "Cell Length" },
297 { TIFF_TAG_FILL_ORDER, "Fill Order" },
298 { TIFF_TAG_DOCUMENT_NAME, "Document Name" },
299 { TIFF_TAG_IMAGE_DESCRIPTION, "Image Description" },
300 { TIFF_TAG_MAKE, "Make" },
301 { TIFF_TAG_MODEL, "Model" },
302 { TIFF_TAG_STRIP_OFFSETS, "Strip Offsets" },
303 { TIFF_TAG_ORIENTATION, "Orientation" },
304 { TIFF_TAG_SAMPLES_PER_PIXEL, "Samples Per Pixel" },
305 { TIFF_TAG_ROWS_PER_STRIP, "Rows Per Strip" },
306 { TIFF_TAG_STRIP_BYTE_COUNTS, "Strip Byte Counts" },
307 { TIFF_TAG_MIN_SAMPLE_VALUE, "Min Sample Value" },
308 { TIFF_TAG_MAX_SAMPLE_VALUE, "Max Sample Value" },
309 { TIFF_TAG_X_RESOLUTION, "X Resolution" },
310 { TIFF_TAG_Y_RESOLUTION, "Y Resolution" },
311 { TIFF_TAG_PLANAR_CONFIGURATION, "Planar Configuration" },
312 { TIFF_TAG_PAGE_NAME, "Page Name" },
313 { TIFF_TAG_X_POSITION, "X Position" },
314 { TIFF_TAG_Y_POSITION, "Y Position" },
315 { TIFF_TAG_FREE_OFFSETS, "Free Offsets" },
316 { TIFF_TAG_FREE_BYTE_COUNTS, "Free Byte Counts" },
317 { TIFF_TAG_GRAY_RESPONSE_UNIT, "Gray Response Unit" },
318 { TIFF_TAG_GRAY_RESPONSE_CURVE, "Gray Response Curve" },
319 { TIFF_TAG_T4_OPTIONS, "T4 Options" },
320 { TIFF_TAG_T6_OPTIONS, "T6 Options" },
321 { TIFF_TAG_RESOLUTION_UNIT, "Resolution Unit" },
322 { TIFF_TAG_PAGE_NUMBER, "Page Number" },
323 { TIFF_TAG_TRANSFER_FUNCTION, "Transfer Function" },
324 { TIFF_TAG_SOFTWARE, "Software" },
325 { TIFF_TAG_DATE_TIME, "Date Time" },
326 { TIFF_TAG_ARTIST, "Artist" },
327 { TIFF_TAG_HOST_COMPUTER, "Host Computer" },
328 { TIFF_TAG_PREDICTOR, "Predictor" },
329 { TIFF_TAG_WHITE_POINT, "White Point" },
330 { TIFF_TAG_PRIMARY_CHROMATICITIES, "Primary Chromaticities" },
331 { TIFF_TAG_COLOR_MAP, "Color Map" },
332 { TIFF_TAG_HALFTONE_HINTS, "Halftone Hints" },
333 { TIFF_TAG_TILE_WIDTH, "Tile Width" },
334 { TIFF_TAG_TILE_LENGTH, "Tile Length" },
335 { TIFF_TAG_TILE_OFFSETS, "Tile Offsets" },
336 { TIFF_TAG_TILE_BYTE_COUNTS, "Tile Byte Counts" },
337 { TIFF_TAG_INK_SET, "Ink Set" },
338 { TIFF_TAG_INK_NAMES, "Ink Names" },
339 { TIFF_TAG_NUMBER_OF_INKS, "Number Of Inks" },
340 { TIFF_TAG_DOT_RANGE, "Dot Range" },
341 { TIFF_TAG_TARGET_PRINTER, "Target Printer" },
342 { TIFF_TAG_EXTRA_SAMPLES, "Extra Samples" },
343 { TIFF_TAG_SAMPLE_FORMAT, "Sample Format" },
344 { TIFF_TAG_S_MIN_SAMPLE_VALUE, "S Min Sample Value" },
345 { TIFF_TAG_S_MAX_SAMPLE_VALUE, "S Max Sample Value" },
346 { TIFF_TAG_TRANSFER_RANGE, "Transfer Range" },
347 { TIFF_TAG_JPEG_PROC, "JPEG Proc" },
348 { TIFF_TAG_JPEG_INTERCHANGE_FORMAT, "JPEG Interchange Format" },
349 { TIFF_TAG_JPEG_INTERCHANGE_FORMAT_LENGTH, "JPEG Interchange Format Length" },
350 { TIFF_TAG_JPEG_RESTART_INTERVAL, "JPEG Restart Interval" },
351 { TIFF_TAG_JPEG_LOSSLESS_PREDICTORS, "JPEG Lossless Predictors" },
352 { TIFF_TAG_JPEG_POINT_TRANSFORMS, "JPEG Point Transforms" },
353 { TIFF_TAG_JPEG_Q_TABLES, "JPEG Q Tables" },
354 { TIFF_TAG_JPEG_DC_TABLES, "JPEG DC Tables" },
355 { TIFF_TAG_JPEG_AC_TABLES, "JPEG AC Tables" },
356 { TIFF_TAG_YCBCR_COEFFICIENTS, "YCbCr Coefficients" },
357 { TIFF_TAG_YCBCR_SUBSAMPLING, "YCbCr Subsampling" },
358 { TIFF_TAG_YCBCR_POSITIONING, "YCbCr Positioning" },
359 { TIFF_TAG_REFERENCE_BLACK_WHITE, "Reference Black White" },
360 { TIFF_TAG_COPYRIGHT, "Copyright" },
361 { 0, NULL },
364 #define TIFF_TYPE_BYTE 1
365 #define TIFF_TYPE_ASCII 2
366 #define TIFF_TYPE_SHORT 3
367 #define TIFF_TYPE_LONG 4
368 #define TIFF_TYPE_RATIONAL 5
369 #define TIFF_TYPE_SBYTE 6
370 #define TIFF_TYPE_UNDEFINED 7
371 #define TIFF_TYPE_SSHORT 8
372 #define TIFF_TYPE_SLONG 9
373 #define TIFF_TYPE_SRATIONAL 10
374 #define TIFF_TYPE_FLOAT 11
375 #define TIFF_TYPE_DOUBLE 12
377 static const value_string tiff_type_names[] = {
378 { TIFF_TYPE_BYTE, "Byte" },
379 { TIFF_TYPE_ASCII, "ASCII" },
380 { TIFF_TYPE_SHORT, "Unsigned Short" },
381 { TIFF_TYPE_LONG, "Unsigned Long" },
382 { TIFF_TYPE_RATIONAL, "Rational" },
383 { TIFF_TYPE_SBYTE, "Signed Byte" },
384 { TIFF_TYPE_UNDEFINED, "Undefined" },
385 { TIFF_TYPE_SSHORT, "Signed Short" },
386 { TIFF_TYPE_SLONG, "Signed Long" },
387 { TIFF_TYPE_SRATIONAL, "Signed Rational" },
388 { TIFF_TYPE_FLOAT, "Float" },
389 { TIFF_TYPE_DOUBLE, "Double" },
390 { 0, NULL },
393 static const value_string tiff_compression_names[] = {
394 { 1, "Uncompressed" },
395 { 2, "CITT 1D" },
396 { 3, "Group 3 Fax" },
397 { 4, "Group 4 Fax" },
398 { 5, "LZW" },
399 { 6, "JPEG" },
400 { 32773, "PackBits" },
401 { 0, NULL },
404 static const value_string tiff_photometric_interp_names[] = {
405 { 0, "White is Zero" },
406 { 1, "Black is Zero" },
407 { 2, "RGB" },
408 { 3, "RGB Palette" },
409 { 4, "Transparency Mask" },
410 { 5, "CMYK" },
411 { 6, "YCbCr" },
412 /* N.B. no value for 7 (see Appendix A) */
413 { 8, "CIELab" },
414 { 0, NULL },
417 static const value_string tiff_threshholding_names[] = {
418 { 0, "None" },
419 { 1, "Ordered" },
420 { 2, "Randomized" },
421 { 0, NULL },
424 static const value_string tiff_fill_order_names[] = {
425 { 1, "High-order first" },
426 { 2, "Low-order first" },
427 { 0, NULL },
430 static const value_string tiff_orientation_names[] = {
431 { 1, "Origin at Top-Left, Horizontal Rows" },
432 { 2, "Origin at Top-Right, Horizontal Rows" },
433 { 3, "Origin at Bottom-Right, Horizontal Rows" },
434 { 4, "Origin at Bottom-Left, Horizontal Rows" },
435 { 5, "Origin at Top-Left, Vertical Rows" },
436 { 6, "Origin at Top-Right, Vertical Rows" },
437 { 7, "Origin at Bottom-Right, Vertical Rows" },
438 { 8, "Origin at Bottom-Left, Vertical Rows" },
439 { 0, NULL },
442 static const value_string tiff_planar_configuration_names[] = {
443 { 1, "Chunky" },
444 { 2, "Planar" },
445 { 0, NULL },
448 static const value_string tiff_gray_response_unit_names[] = {
449 { 1, "Tenths" },
450 { 2, "Hundredths" },
451 { 3, "Thousandths" },
452 { 4, "Ten-thousandths" },
453 { 5, "Hundred-thousandths" },
454 { 0, NULL },
457 static const value_string tiff_allow_uncompressed_names[] = {
458 { 0, "Not Allowed" },
459 { 1, "Allowed" },
460 { 0, NULL },
463 static const value_string tiff_resolution_unit_names[] = {
464 { 1, "None" },
465 { 2, "Inch" },
466 { 3, "Centimeter" },
467 { 0, NULL },
470 static const value_string tiff_predictor_names[] = {
471 { 1, "No Predictor" },
472 { 2, "Horizontal Differencing" },
473 { 0, NULL },
476 static const value_string tiff_ink_set_names[] = {
477 { 1, "CMYK" },
478 { 2, "Not CMYK" },
479 { 0, NULL },
482 // Return the length of the given data type.
484 // If the type isn't known, return -1.
485 static int
486 tiff_type_len(const uint16_t type) {
487 switch (type) {
488 case TIFF_TYPE_BYTE: return 1;
489 case TIFF_TYPE_ASCII: return 1;
490 case TIFF_TYPE_SHORT: return 2;
491 case TIFF_TYPE_LONG: return 4;
492 case TIFF_TYPE_RATIONAL: return 8;
493 case TIFF_TYPE_SBYTE: return 1;
494 case TIFF_TYPE_UNDEFINED: return 1;
495 case TIFF_TYPE_SSHORT: return 2;
496 case TIFF_TYPE_SLONG: return 4;
497 case TIFF_TYPE_SRATIONAL: return 8;
498 case TIFF_TYPE_FLOAT: return 4;
499 case TIFF_TYPE_DOUBLE: return 8;
501 default: return -1;
505 // Return the length of the given array of data.
507 // If the type isn't known, return -1.
508 static int
509 tiff_data_len(const uint16_t type, const uint32_t count) {
510 const int field = tiff_type_len(type);
511 if (field < 0) return -1;
512 else return field * count;
515 static void
516 dissect_tiff_tag_unknown(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, uint32_t offset, uint16_t type, uint32_t count, int encoding _U_)
518 const int len = tiff_data_len(type, count);
520 expert_add_info(pinfo, tree, &ei_tiff_unknown_tag);
522 uint32_t item_offset;
523 if (len <= 0) {
524 // If we can't determine the length, that's an issue
525 expert_add_info_format(pinfo, tree, &ei_tiff_bad_entry, "Could not determine length of entry");
526 return;
527 } else if (len <= 4) {
528 // If the length is <= 4, the item is located directly at the offset
529 item_offset = offset;
530 } else {
531 // If the length is >4, the offset is a pointer indicating where the item is located
532 proto_tree_add_item_ret_uint(tree, hf_tiff_entry_offset, tvb, offset, 4, encoding, &item_offset);
535 proto_tree_add_item(tree, hf_tiff_entry_unknown, tvb, item_offset, len, encoding);
538 static void
539 dissect_tiff_single_uint(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, uint32_t offset, uint16_t type, uint32_t count, int encoding, int hfindex) {
540 if (count != 1) {
541 expert_add_info_format(pinfo, tree, &ei_tiff_bad_entry, "Expected a single item; found %d items", count);
542 return;
545 if (type == TIFF_TYPE_BYTE) {
546 proto_tree_add_item(tree, hfindex, tvb, offset, 1, encoding);
547 } else if (type == TIFF_TYPE_SHORT) {
548 proto_tree_add_item(tree, hfindex, tvb, offset, 2, encoding);
549 } else if (type == TIFF_TYPE_LONG) {
550 proto_tree_add_item(tree, hfindex, tvb, offset, 4, encoding);
551 } else {
552 expert_add_info_format(pinfo, tree, &ei_tiff_bad_entry, "Expected an unsigned integer, found type %s", val_to_str_const(type, tiff_type_names, "Unknown"));
556 static void
557 dissect_tiff_array_uint(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, uint32_t offset, uint16_t type, uint32_t count, int encoding, int hfindex) {
558 if (!(type == TIFF_TYPE_BYTE || type == TIFF_TYPE_SHORT || type == TIFF_TYPE_LONG)) {
559 expert_add_info_format(pinfo, tree, &ei_tiff_bad_entry, "Expected an unsigned integer, found type %s", val_to_str_const(type, tiff_type_names, "Unknown"));
560 return;
563 if (count < 1) {
564 expert_add_info_format(pinfo, tree, &ei_tiff_bad_entry, "At least 1 item; found %d items", count);
565 return;
568 const int item_len = tiff_type_len(type);
569 const int len = tiff_data_len(type, count);
571 uint32_t item_offset;
572 if (len <= 0 || item_len <= 0) {
573 // If we can't determine the length, that's an issue
574 expert_add_info_format(pinfo, tree, &ei_tiff_bad_entry, "Could not determine length of entry");
575 return;
576 } else if (len <= 4) {
577 // If the length is <= 4, the item is located directly at the offset
578 item_offset = offset;
579 } else {
580 // If the length is >4, the offset is a pointer indicating where the item is located
581 proto_tree_add_item_ret_uint(tree, hf_tiff_entry_offset, tvb, offset, 4, encoding, &item_offset);
584 // Add each item
585 for (uint32_t i = 0; i < count; i++) {
586 proto_tree_add_item(tree, hfindex, tvb, item_offset + item_len * i, item_len, encoding);
590 static void
591 dissect_tiff_single_string(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, unsigned offset, uint16_t type, uint32_t count, int encoding, int hfindex) {
592 if (type != TIFF_TYPE_ASCII) {
593 expert_add_info_format(pinfo, tree, &ei_tiff_bad_entry, "Expected an ASCII string");
594 return;
597 uint32_t item_offset;
598 if (count == 0) {
599 expert_add_info_format(pinfo, tree, &ei_tiff_bad_entry, "Expected at least one byte for an ASCII string; got zero");
600 return;
601 } else if (count <= 4) {
602 // If there are 4 or fewer bytes, the string is embedded in the pointer
603 item_offset = offset;
604 } else {
605 // If the length is >4, the offset is a pointer indicating where the item is located
606 proto_tree_add_item_ret_uint(tree, hf_tiff_entry_offset, tvb, offset, 4, encoding, &item_offset);
609 proto_tree_add_item(tree, hfindex, tvb, item_offset, count, ENC_ASCII);
612 static void
613 dissect_tiff_single_urational(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, unsigned offset, uint16_t type, uint32_t count, int encoding, int hfnumer, int hfdenom, int hfapprox) {
614 if (count != 1) {
615 expert_add_info_format(pinfo, tree, &ei_tiff_bad_entry, "Expected a single item; found %d items", count);
616 return;
619 if (type != TIFF_TYPE_RATIONAL) {
620 expert_add_info_format(pinfo, tree, &ei_tiff_bad_entry, "Expected an unsigned rational");
621 return;
624 uint32_t item_offset;
625 proto_tree_add_item_ret_uint(tree, hf_tiff_entry_offset, tvb, offset, 4, encoding, &item_offset);
627 uint32_t numer = 0;
628 uint32_t denom = 0;
629 proto_tree_add_item_ret_uint(tree, hfnumer, tvb, item_offset, 4, encoding, &numer);
630 proto_item *denom_ti = proto_tree_add_item_ret_uint(tree, hfdenom, tvb, item_offset + 4, 4, encoding, &denom);
632 if (denom > 0) {
633 proto_item *approx_item = proto_tree_add_double(tree, hfapprox, tvb, item_offset, 8, (double)numer / (double)denom);
634 proto_item_set_generated(approx_item);
636 else {
637 expert_add_info_format(pinfo, denom_ti, &ei_tiff_zero_denom, "Denominator is zero");
641 static void
642 dissect_tiff_t6_options(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, unsigned offset, uint16_t type, uint32_t count, int encoding) {
643 if (count != 1) {
644 expert_add_info_format(pinfo, tree, &ei_tiff_bad_entry, "Expected a single item; found %d items", count);
645 return;
648 if (type != TIFF_TYPE_LONG) {
649 expert_add_info_format(pinfo, tree, &ei_tiff_bad_entry, "Expected an unsigned long");
650 return;
653 proto_item *t6_ti = proto_tree_add_item(tree, hf_tiff_t6_options, tvb, offset, 4, encoding);
654 proto_tree *t6_tree = proto_item_add_subtree(t6_ti, ett_t6);
655 proto_tree_add_item(t6_tree, hf_tiff_t6_unused, tvb, offset, 4, encoding);
656 proto_tree_add_item(t6_tree, hf_tiff_t6_allow_uncompresed, tvb, offset, 4, encoding);
659 static void
660 dissect_tiff_entry(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, uint32_t offset, int encoding) {
661 const uint16_t tag = tvb_get_uint16(tvb, offset, encoding);
663 proto_tree *entry_tree = proto_tree_add_subtree_format(tree, tvb, offset, 12, ett_ifd, NULL, "%s", val_to_str_const(tag, tiff_tag_names, "Unknown Entry"));
665 proto_tree_add_item(entry_tree, hf_tiff_entry_tag, tvb, offset, 2, encoding);
667 uint32_t type = 0;
668 uint32_t count = 0;
669 proto_tree_add_item_ret_uint(entry_tree, hf_tiff_entry_type, tvb, offset + 2, 2, encoding, &type);
670 proto_tree_add_item_ret_uint(entry_tree, hf_tiff_entry_count, tvb, offset + 4, 4, encoding, &count);
672 switch (tag) {
673 case TIFF_TAG_IMAGE_WIDTH:
674 dissect_tiff_single_uint(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_image_width);
675 break;
676 case TIFF_TAG_IMAGE_LENGTH:
677 dissect_tiff_single_uint(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_image_length);
678 break;
679 case TIFF_TAG_BITS_PER_SAMPLE:
680 dissect_tiff_array_uint(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_bits_per_sample);
681 break;
682 case TIFF_TAG_COMPRESSION:
683 dissect_tiff_single_uint(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_compression);
684 break;
685 case TIFF_TAG_PHOTOMETRIC_INTERPRETATION:
686 dissect_tiff_single_uint(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_photometric_interp);
687 break;
688 case TIFF_TAG_THRESHHOLDING:
689 dissect_tiff_single_uint(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_threshholding);
690 break;
691 case TIFF_TAG_CELL_WIDTH:
692 dissect_tiff_single_uint(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_cell_width);
693 break;
694 case TIFF_TAG_CELL_LENGTH:
695 dissect_tiff_single_uint(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_cell_length);
696 break;
697 case TIFF_TAG_FILL_ORDER:
698 dissect_tiff_single_uint(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_fill_order);
699 break;
700 case TIFF_TAG_DOCUMENT_NAME:
701 dissect_tiff_single_string(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_document_name);
702 break;
703 case TIFF_TAG_IMAGE_DESCRIPTION:
704 dissect_tiff_single_string(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_image_description);
705 break;
706 case TIFF_TAG_MAKE:
707 dissect_tiff_single_string(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_make);
708 break;
709 case TIFF_TAG_MODEL:
710 dissect_tiff_single_string(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_model);
711 break;
712 case TIFF_TAG_STRIP_OFFSETS:
713 dissect_tiff_array_uint(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_strip_offset);
714 break;
715 case TIFF_TAG_ORIENTATION:
716 dissect_tiff_single_uint(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_orientation);
717 break;
718 case TIFF_TAG_SAMPLES_PER_PIXEL:
719 dissect_tiff_single_uint(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_samples_per_pixel);
720 break;
721 case TIFF_TAG_ROWS_PER_STRIP:
722 dissect_tiff_single_uint(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_rows_per_strip);
723 break;
724 case TIFF_TAG_STRIP_BYTE_COUNTS:
725 dissect_tiff_array_uint(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_strip_byte_count);
726 break;
727 case TIFF_TAG_X_RESOLUTION:
728 dissect_tiff_single_urational(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_x_res_numer, hf_tiff_x_res_denom, hf_tiff_x_res_approx);
729 break;
730 case TIFF_TAG_Y_RESOLUTION:
731 dissect_tiff_single_urational(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_y_res_numer, hf_tiff_y_res_denom, hf_tiff_y_res_approx);
732 break;
733 case TIFF_TAG_PLANAR_CONFIGURATION:
734 dissect_tiff_single_uint(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_planar_configuration);
735 break;
736 case TIFF_TAG_PAGE_NAME:
737 dissect_tiff_single_string(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_page_name);
738 break;
739 case TIFF_TAG_GRAY_RESPONSE_UNIT:
740 dissect_tiff_single_uint(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_gray_response_unit);
741 break;
742 case TIFF_TAG_T6_OPTIONS:
743 dissect_tiff_t6_options(tvb, pinfo, entry_tree, offset + 8, type, count, encoding);
744 break;
745 case TIFF_TAG_RESOLUTION_UNIT:
746 dissect_tiff_single_uint(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_resolution_unit);
747 break;
748 case TIFF_TAG_SOFTWARE:
749 dissect_tiff_single_string(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_software);
750 break;
751 case TIFF_TAG_DATE_TIME:
752 dissect_tiff_single_string(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_date_time);
753 break;
754 case TIFF_TAG_ARTIST:
755 dissect_tiff_single_string(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_artist);
756 break;
757 case TIFF_TAG_HOST_COMPUTER:
758 dissect_tiff_single_string(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_host_computer);
759 break;
760 case TIFF_TAG_PREDICTOR:
761 dissect_tiff_single_uint(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_predictor);
762 break;
763 case TIFF_TAG_TILE_WIDTH:
764 dissect_tiff_single_uint(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_tile_width);
765 break;
766 case TIFF_TAG_TILE_LENGTH:
767 dissect_tiff_single_uint(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_tile_length);
768 break;
769 case TIFF_TAG_INK_SET:
770 dissect_tiff_single_uint(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_ink_set);
771 break;
772 case TIFF_TAG_NUMBER_OF_INKS:
773 dissect_tiff_single_uint(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_number_of_inks);
774 break;
775 case TIFF_TAG_TARGET_PRINTER:
776 dissect_tiff_single_string(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_target_printer);
777 break;
778 case TIFF_TAG_COPYRIGHT:
779 dissect_tiff_single_string(tvb, pinfo, entry_tree, offset + 8, type, count, encoding, hf_tiff_copyright);
780 break;
781 default:
782 dissect_tiff_tag_unknown(tvb, pinfo, entry_tree, offset + 8, type, count, encoding);
786 // Dissect an IFD with all of its fields, starting at the given offset
788 // Return the offset of the next IFD, or 0 if there isn't one
789 static uint32_t
790 dissect_tiff_ifd(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, uint32_t offset, int encoding) {
791 uint16_t ifd_count = tvb_get_uint16(tvb, offset, encoding);
792 int ifd_length = 2 + (ifd_count * 12) + 4;
794 proto_tree *ifd_tree = proto_tree_add_subtree(tree, tvb, offset, ifd_length, ett_ifd, NULL, "Image File Directory");
796 proto_tree_add_item(ifd_tree, hf_tiff_ifd_count, tvb, offset, 2, encoding);
797 offset += 2;
799 for (int i = 0; i < ifd_count; i++) {
800 dissect_tiff_entry(tvb, pinfo, ifd_tree, offset, encoding);
801 offset += 12;
804 proto_tree_add_item(ifd_tree, hf_tiff_ifd_next, tvb, offset, 4, encoding);
805 uint32_t ifd_next = tvb_get_uint32(tvb, offset, encoding);
807 return ifd_next;
810 static int
811 dissect_tiff(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_) {
812 int encoding;
814 // Reject if we don't have enough room for the heuristics
815 if (tvb_captured_length(tvb) < 4) {
816 return 0;
819 // Figure out if we're big-endian or little endian
820 uint16_t raw_encoding = tvb_get_ntohs(tvb, 0);
821 uint16_t magic;
822 uint32_t ifd_offset;
823 if (raw_encoding == 0x4949) {
824 encoding = ENC_LITTLE_ENDIAN;
825 } else if (raw_encoding == 0x4D4D) {
826 encoding = ENC_BIG_ENDIAN;
827 } else {
828 // If we don't recognize the endianness, abort with nothing decoded
829 return 0;
832 magic = tvb_get_uint16(tvb, 2, encoding);
834 // If the magic number isn't 42, abort with nothing decoded
835 if (magic != 42) {
836 return 0;
839 proto_item *ti = proto_tree_add_item(tree, proto_tiff, tvb, 0, -1, ENC_NA);
840 proto_tree *tiff_tree = proto_item_add_subtree(ti, ett_tiff);
842 // Dissect the rest of the header
843 proto_tree_add_item(tiff_tree, hf_tiff_header_endianness, tvb, 0, 2, encoding);
844 proto_tree_add_item(tiff_tree, hf_tiff_header_magic, tvb, 2, 2, encoding);
845 proto_tree_add_item_ret_uint(tiff_tree, hf_tiff_header_lead_ifd, tvb, 4, 4, encoding, &ifd_offset);
847 // Keep dissecting IFDs until the offset to the next one is zero
848 while (ifd_offset != 0) {
849 ifd_offset = dissect_tiff_ifd(tvb, pinfo, tiff_tree, ifd_offset, encoding);
852 return tvb_captured_length(tvb);
855 void
856 proto_register_tiff(void)
858 static hf_register_info hf[] = {
859 { &hf_tiff_header_endianness,
860 { "Endianness", "tiff.endianness",
861 FT_UINT16, BASE_HEX, VALS(tiff_endianness_names),
862 0x0, NULL, HFILL }
864 { &hf_tiff_header_magic,
865 { "Magic", "tiff.magic",
866 FT_UINT16, BASE_HEX, NULL,
867 0x0, NULL, HFILL }
869 { &hf_tiff_header_lead_ifd,
870 { "Lead IFD Offset", "tiff.lead_ifd",
871 FT_UINT32, BASE_HEX, NULL,
872 0x0, NULL, HFILL }
874 { &hf_tiff_ifd_count,
875 { "Number of Entries", "tiff.ifd_count",
876 FT_UINT16, BASE_DEC, NULL,
877 0x0, NULL, HFILL }
879 { &hf_tiff_ifd_next,
880 { "Next IFD Offset", "tiff.next_ifd",
881 FT_UINT32, BASE_HEX, NULL,
882 0x0, NULL, HFILL }
884 { &hf_tiff_entry_tag,
885 { "Tag", "tiff.tag",
886 FT_UINT16, BASE_DEC, VALS(tiff_tag_names),
887 0x0, NULL, HFILL }
889 { &hf_tiff_entry_type,
890 { "Type", "tiff.type",
891 FT_UINT16, BASE_DEC, VALS(tiff_type_names),
892 0x0, NULL, HFILL }
894 { &hf_tiff_entry_count,
895 { "Count", "tiff.count",
896 FT_UINT32, BASE_DEC, NULL,
897 0x0, NULL, HFILL }
899 { &hf_tiff_entry_offset,
900 { "Offset", "tiff.offset",
901 FT_UINT32, BASE_DEC, NULL,
902 0x0, NULL, HFILL }
904 { &hf_tiff_entry_unknown,
905 { "Unknown Data", "tiff.unknown",
906 FT_BYTES, BASE_NONE, NULL,
907 0x0, NULL, HFILL }
909 { &hf_tiff_image_width,
910 { "Image Width", "tiff.image_width",
911 FT_UINT32, BASE_DEC, NULL,
912 0x0, NULL, HFILL }
914 { &hf_tiff_image_length,
915 { "Image Length", "tiff.image_length",
916 FT_UINT32, BASE_DEC, NULL,
917 0x0, NULL, HFILL }
919 { &hf_tiff_bits_per_sample,
920 { "Bits per Sample", "tiff.bits_per_sample",
921 FT_UINT16, BASE_DEC, NULL,
922 0x0, NULL, HFILL }
924 { &hf_tiff_compression,
925 { "Compression", "tiff.compression",
926 FT_UINT16, BASE_DEC, VALS(tiff_compression_names),
927 0x0, NULL, HFILL }
929 { &hf_tiff_photometric_interp,
930 { "Photometric Interpretation", "tiff.photometric_interp",
931 FT_UINT16, BASE_DEC, VALS(tiff_photometric_interp_names),
932 0x0, NULL, HFILL }
934 { &hf_tiff_threshholding,
935 { "Threshholding", "tiff.threshholding",
936 FT_UINT16, BASE_DEC, VALS(tiff_threshholding_names),
937 0x0, NULL, HFILL }
939 { &hf_tiff_cell_width,
940 { "Cell Width", "tiff.cell_width",
941 FT_UINT16, BASE_DEC, NULL,
942 0x0, NULL, HFILL }
944 { &hf_tiff_cell_length,
945 { "Cell Length", "tiff.cell_length",
946 FT_UINT16, BASE_DEC, NULL,
947 0x0, NULL, HFILL }
949 { &hf_tiff_fill_order,
950 { "Fill Order", "tiff.fill_order",
951 FT_UINT16, BASE_DEC, VALS(tiff_fill_order_names),
952 0x0, NULL, HFILL }
954 { &hf_tiff_document_name,
955 { "Document Name", "tiff.document_name",
956 FT_STRINGZ, BASE_NONE, NULL,
957 0x0, NULL, HFILL }
959 { &hf_tiff_image_description,
960 { "Image Description", "tiff.image_description",
961 FT_STRINGZ, BASE_NONE, NULL,
962 0x0, NULL, HFILL }
964 { &hf_tiff_make,
965 { "Make", "tiff.make",
966 FT_STRINGZ, BASE_NONE, NULL,
967 0x0, NULL, HFILL }
969 { &hf_tiff_model,
970 { "Model", "tiff.model",
971 FT_STRINGZ, BASE_NONE, NULL,
972 0x0, NULL, HFILL }
974 { &hf_tiff_strip_offset,
975 { "Strip Offset", "tiff.strip_offset",
976 FT_UINT32, BASE_DEC, NULL,
977 0x0, NULL, HFILL }
979 { &hf_tiff_orientation,
980 { "Orientation", "tiff.orientation",
981 FT_UINT16, BASE_DEC, VALS(tiff_orientation_names),
982 0x0, NULL, HFILL }
984 { &hf_tiff_samples_per_pixel,
985 { "Samples per Pixel", "tiff.samples_per_pixel",
986 FT_UINT16, BASE_DEC, NULL,
987 0x0, NULL, HFILL }
989 { &hf_tiff_rows_per_strip,
990 { "Rows per Strip", "tiff.rows_per_strip",
991 FT_UINT16, BASE_DEC, NULL,
992 0x0, NULL, HFILL }
994 { &hf_tiff_strip_byte_count,
995 { "Strip Byte Count", "tiff.strip_byte_count",
996 FT_UINT32, BASE_DEC, NULL,
997 0x0, NULL, HFILL }
999 { &hf_tiff_x_res_numer,
1000 { "X Resolution Numerator", "tiff.x_res_numer",
1001 FT_UINT32, BASE_DEC, NULL,
1002 0x0, NULL, HFILL }
1004 { &hf_tiff_x_res_denom,
1005 { "X Resolution Denominator", "tiff.x_res_denom",
1006 FT_UINT32, BASE_DEC, NULL,
1007 0x0, NULL, HFILL }
1009 { &hf_tiff_x_res_approx,
1010 { "X Resolution Approximation", "tiff.x_res_approx",
1011 FT_DOUBLE, BASE_NONE, NULL,
1012 0x0, NULL, HFILL }
1014 { &hf_tiff_y_res_numer,
1015 { "Y Resolution Numerator", "tiff.y_res_numer",
1016 FT_UINT32, BASE_DEC, NULL,
1017 0x0, NULL, HFILL }
1019 { &hf_tiff_y_res_denom,
1020 { "Y Resolution Denominator", "tiff.y_res_denom",
1021 FT_UINT32, BASE_DEC, NULL,
1022 0x0, NULL, HFILL }
1024 { &hf_tiff_y_res_approx,
1025 { "Y Resolution Approximation", "tiff.y_res_approx",
1026 FT_DOUBLE, BASE_NONE, NULL,
1027 0x0, NULL, HFILL }
1029 { &hf_tiff_planar_configuration,
1030 { "Planar Configuration", "tiff.planar_configuration",
1031 FT_UINT16, BASE_DEC, VALS(tiff_planar_configuration_names),
1032 0x0, NULL, HFILL }
1034 { &hf_tiff_page_name,
1035 { "Page Name", "tiff.page_name",
1036 FT_STRINGZ, BASE_NONE, NULL,
1037 0x0, NULL, HFILL }
1039 { &hf_tiff_gray_response_unit,
1040 { "Gray Response Unit", "tiff.gray_response_unit",
1041 FT_UINT16, BASE_DEC, VALS(tiff_gray_response_unit_names),
1042 0x0, NULL, HFILL }
1044 { &hf_tiff_t6_options,
1045 { "T6 Options", "tiff.t6",
1046 FT_UINT32, BASE_HEX, NULL,
1047 0x0, NULL, HFILL }
1049 { &hf_tiff_t6_unused,
1050 { "Unused", "tiff.t6.unused",
1051 FT_UINT32, BASE_HEX, NULL,
1052 0xFFFFFFFD, NULL, HFILL }
1054 { &hf_tiff_t6_allow_uncompresed,
1055 { "Allow Uncompressed", "tiff.t6.allow_uncompressed",
1056 FT_UINT32, BASE_HEX, VALS(tiff_allow_uncompressed_names),
1057 0x00000002, NULL, HFILL }
1059 { &hf_tiff_resolution_unit,
1060 { "Resolution Unit", "tiff.resolution_unit",
1061 FT_UINT16, BASE_DEC, VALS(tiff_resolution_unit_names),
1062 0x0, NULL, HFILL }
1064 { &hf_tiff_software,
1065 { "Software", "tiff.software",
1066 FT_STRINGZ, BASE_NONE, NULL,
1067 0x0, NULL, HFILL }
1069 { &hf_tiff_date_time,
1070 { "Date/Time", "tiff.date_time",
1071 FT_STRINGZ, BASE_NONE, NULL,
1072 0x0, NULL, HFILL }
1074 { &hf_tiff_artist,
1075 { "Artist", "tiff.artist",
1076 FT_STRINGZ, BASE_NONE, NULL,
1077 0x0, NULL, HFILL }
1079 { &hf_tiff_host_computer,
1080 { "Host Computer", "tiff.host_computer",
1081 FT_STRINGZ, BASE_NONE, NULL,
1082 0x0, NULL, HFILL }
1084 { &hf_tiff_predictor,
1085 { "Predictor", "tiff.predictor",
1086 FT_UINT16, BASE_DEC, VALS(tiff_predictor_names),
1087 0x0, NULL, HFILL }
1089 { &hf_tiff_tile_width,
1090 { "Tile Width", "tiff.tile_width",
1091 FT_UINT32, BASE_DEC, NULL,
1092 0x0, NULL, HFILL }
1094 { &hf_tiff_tile_length,
1095 { "Tile Width", "tiff.tile_length",
1096 FT_UINT32, BASE_DEC, NULL,
1097 0x0, NULL, HFILL }
1099 { &hf_tiff_ink_set,
1100 { "Ink Set", "tiff.ink_set",
1101 FT_UINT16, BASE_DEC, VALS(tiff_ink_set_names),
1102 0x0, NULL, HFILL }
1104 { &hf_tiff_number_of_inks,
1105 { "Number of Inks", "tiff.number_of_inks",
1106 FT_UINT16, BASE_DEC, NULL,
1107 0x0, NULL, HFILL }
1109 { &hf_tiff_target_printer,
1110 { "Target Printer", "tiff.target_printer",
1111 FT_STRINGZ, BASE_NONE, NULL,
1112 0x0, NULL, HFILL }
1114 { &hf_tiff_copyright,
1115 { "Copyright", "tiff.copyright",
1116 FT_STRINGZ, BASE_NONE, NULL,
1117 0x0, NULL, HFILL }
1121 static int *ett[] = {
1122 &ett_tiff,
1123 &ett_ifd,
1124 &ett_t6,
1127 static ei_register_info ei[] = {
1128 { &ei_tiff_unknown_tag,
1129 { "tiff.unknown_tag", PI_UNDECODED, PI_NOTE,
1130 "Unknown tag", EXPFILL }
1132 { &ei_tiff_bad_entry,
1133 { "tiff.bad_entry", PI_PROTOCOL, PI_WARN,
1134 "Invalid entry contents", EXPFILL }
1136 { &ei_tiff_zero_denom,
1137 { "tiff.zero_denom", PI_PROTOCOL, PI_WARN,
1138 "Zero denominator", EXPFILL }
1143 proto_tiff = proto_register_protocol("Tagged Image File Format", "TIFF image", "tiff");
1145 register_dissector("tiff", dissect_tiff, proto_tiff);
1146 proto_register_field_array(proto_tiff, hf, array_length(hf));
1147 proto_register_subtree_array(ett, array_length(ett));
1149 expert_module_t *expert_tiff = expert_register_protocol(proto_tiff);
1150 expert_register_field_array(expert_tiff, ei, array_length(ei));
1153 static bool
1154 dissect_tiff_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
1156 return dissect_tiff(tvb, pinfo, tree, data) > 0;
1159 void
1160 proto_reg_handoff_tiff(void)
1162 dissector_handle_t tiff_handle = find_dissector("tiff");
1164 // Register the TIFF media type
1165 dissector_add_string("media_type", "image/tiff", tiff_handle);
1167 // Register the TIFF heuristic dissector
1168 heur_dissector_add("wtap_file", dissect_tiff_heur, "TIFF file", "tiff_wtap", proto_tiff, HEURISTIC_ENABLE);