diff options
author | Jakub Adam <jakub.adam@collabora.com> | 2020-01-13 18:46:50 +0100 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2020-01-14 20:04:01 +0000 |
commit | ce8e6e1c95863964ee868f04056ea8dfd15f1ca8 (patch) | |
tree | cc2d592b3bb28481bd4e01791834e2b8dfccf84c /wiretap | |
parent | 5b861d84f8c45886d67f3fdc9978ca97697fc1c3 (diff) |
wiretap: Add MP4 reader
Allows opening MP4 (ISO/IEC 14496-12) media files in Wireshark and
viewing their structure.
Change-Id: Ie20b8b89dc69bb52d6faa890e547d90317adecf6
Reviewed-on: https://code.wireshark.org/review/35804
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'wiretap')
-rw-r--r-- | wiretap/CMakeLists.txt | 1 | ||||
-rw-r--r-- | wiretap/file_access.c | 8 | ||||
-rw-r--r-- | wiretap/mp4.c | 60 | ||||
-rw-r--r-- | wiretap/mp4.h | 16 | ||||
-rw-r--r-- | wiretap/wtap.h | 2 |
5 files changed, 87 insertions, 0 deletions
diff --git a/wiretap/CMakeLists.txt b/wiretap/CMakeLists.txt index 720aab05ab..b32219c7c7 100644 --- a/wiretap/CMakeLists.txt +++ b/wiretap/CMakeLists.txt @@ -53,6 +53,7 @@ set(WIRETAP_NONGENERATED_FILES logcat.c logcat_text.c merge.c + mp4.c mpeg.c mplog.c mime_file.c diff --git a/wiretap/file_access.c b/wiretap/file_access.c index ee8da291bf..edb83a15b5 100644 --- a/wiretap/file_access.c +++ b/wiretap/file_access.c @@ -51,6 +51,7 @@ #include "k12.h" #include "ber.h" #include "catapult_dct2000.h" +#include "mp4.h" #include "mp2t.h" #include "mpeg.h" #include "netscreen.h" @@ -152,6 +153,7 @@ static const struct file_extension_info file_type_extensions_base[] = { { "Transport-Neutral Encapsulation Format", FALSE, "tnef" }, { "JPEG/JFIF files", FALSE, "jpg;jpeg;jfif" }, { "JavaScript Object Notation file", FALSE, "json" }, + { "MP4 file", FALSE, "mp4" }, }; #define N_FILE_TYPE_EXTENSIONS (sizeof file_type_extensions_base / sizeof file_type_extensions_base[0]) @@ -430,6 +432,7 @@ static const struct open_info open_info_base[] = { { "Ruby Marshal Object", OPEN_INFO_HEURISTIC, ruby_marshal_open, "", NULL, NULL }, { "Systemd Journal", OPEN_INFO_HEURISTIC, systemd_journal_open, "log;jnl;journal", NULL, NULL }, { "3gpp phone log", OPEN_INFO_MAGIC, log3gpp_open, "log", NULL, NULL }, + { "MP4 media file", OPEN_INFO_MAGIC, mp4_open, "mp4", NULL, NULL }, }; @@ -1665,6 +1668,11 @@ static const struct file_type_subtype_info dump_open_table_base[] = { /* WTAP_FILE_TYPE_SUBTYPE_LOG_3GPP */ { "3GPP Log", "3gpp_log", "*.log", NULL, TRUE, FALSE, 0, + NULL, NULL, NULL }, + + /* WTAP_FILE_TYPE_SUBTYPE_MP4 */ + { "MP4 media", "mp4", "mp4", NULL, + FALSE, FALSE, 0, NULL, NULL, NULL } }; diff --git a/wiretap/mp4.c b/wiretap/mp4.c new file mode 100644 index 0000000000..4e1fc86c9a --- /dev/null +++ b/wiretap/mp4.c @@ -0,0 +1,60 @@ +/* mp4.c + * + * MP4 (ISO/IEC 14496-12) file format decoder for the Wiretap library. + * + * Wiretap Library + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "mp4.h" + +#include "file_wrappers.h" +#include "wtap-int.h" + +static const guint8 mp4_magic[] = { 'f', 't', 'y', 'p' }; + +wtap_open_return_val +mp4_open(wtap *wth, int *err, gchar **err_info) +{ + char magic_buf[8]; + int bytes_read; + + bytes_read = file_read(magic_buf, sizeof (magic_buf), wth->fh); + + if (bytes_read < 0) { + *err = file_error(wth->fh, err_info); + return WTAP_OPEN_ERROR; + } + if (bytes_read == 0) + return WTAP_OPEN_NOT_MINE; + + if (bytes_read == sizeof (magic_buf) && + memcmp(magic_buf + 4, mp4_magic, sizeof (mp4_magic))) + return WTAP_OPEN_NOT_MINE; + + if (file_seek(wth->fh, 0, SEEK_SET, err) == -1) + return WTAP_OPEN_ERROR; + + wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_MP4; + wth->file_encap = WTAP_ENCAP_MP4; + wth->file_tsprec = WTAP_TSPREC_SEC; + wth->subtype_read = wtap_full_file_read; + wth->subtype_seek_read = wtap_full_file_seek_read; + wth->snapshot_length = 0; + + return WTAP_OPEN_MINE; +} + +/* + * Editor modelines - https://www.wireshark.org/tools/modelines.html + * + * Local variables: + * c-basic-offset: 8 + * tab-width: 8 + * indent-tabs-mode: t + * End: + * + * vi: set shiftwidth=8 tabstop=8 noexpandtab: + * :indentSize=8:tabSize=8:noTabs=false: + */ diff --git a/wiretap/mp4.h b/wiretap/mp4.h new file mode 100644 index 0000000000..c47ca865bf --- /dev/null +++ b/wiretap/mp4.h @@ -0,0 +1,16 @@ +/* mp4.h + * + * MP4 (ISO/IEC 14496-12) file format decoder for the Wiretap library. + * + * Wiretap Library + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef __W_MP4_H__ +#define __W_MP4_H__ + +#include "wtap.h" + +wtap_open_return_val mp4_open(wtap *wth, int *err, gchar **err_info); + +#endif diff --git a/wiretap/wtap.h b/wiretap/wtap.h index 0e022ec689..ee47294879 100644 --- a/wiretap/wtap.h +++ b/wiretap/wtap.h @@ -289,6 +289,7 @@ extern "C" { #define WTAP_ENCAP_IEEE802_15_4_TAP 206 #define WTAP_ENCAP_LOG_3GPP 207 #define WTAP_ENCAP_USB_2_0 208 +#define WTAP_ENCAP_MP4 209 /* After adding new item here, please also add new item to encap_table_base array */ @@ -385,6 +386,7 @@ extern "C" { #define WTAP_FILE_TYPE_SUBTYPE_RUBY_MARSHAL 83 #define WTAP_FILE_TYPE_SUBTYPE_SYSTEMD_JOURNAL 84 #define WTAP_FILE_TYPE_SUBTYPE_LOG_3GPP 85 +#define WTAP_FILE_TYPE_SUBTYPE_MP4 86 #define WTAP_NUM_FILE_TYPES_SUBTYPES wtap_get_num_file_types_subtypes() |