diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 20:34:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 20:34:10 +0000 |
commit | e4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc (patch) | |
tree | 68cb5ef9081156392f1dd62a00c6ccc1451b93df /epan/dissectors/asn1/mpeg-audio | |
parent | Initial commit. (diff) | |
download | wireshark-e4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc.tar.xz wireshark-e4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc.zip |
Adding upstream version 4.2.2.upstream/4.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'epan/dissectors/asn1/mpeg-audio')
-rw-r--r-- | epan/dissectors/asn1/mpeg-audio/CMakeLists.txt | 34 | ||||
-rw-r--r-- | epan/dissectors/asn1/mpeg-audio/mpeg-audio.asn | 75 | ||||
-rw-r--r-- | epan/dissectors/asn1/mpeg-audio/mpeg-audio.cnf | 11 | ||||
-rw-r--r-- | epan/dissectors/asn1/mpeg-audio/packet-mpeg-audio-template.c | 226 |
4 files changed, 346 insertions, 0 deletions
diff --git a/epan/dissectors/asn1/mpeg-audio/CMakeLists.txt b/epan/dissectors/asn1/mpeg-audio/CMakeLists.txt new file mode 100644 index 00000000..da68fc2e --- /dev/null +++ b/epan/dissectors/asn1/mpeg-audio/CMakeLists.txt @@ -0,0 +1,34 @@ +# CMakeLists.txt +# +# Wireshark - Network traffic analyzer +# By Gerald Combs <gerald@wireshark.org> +# Copyright 1998 Gerald Combs +# +# SPDX-License-Identifier: GPL-2.0-or-later +# + +set( PROTOCOL_NAME mpeg-audio ) + +set( PROTO_OPT ) + +set( EXT_ASN_FILE_LIST +) + +set( ASN_FILE_LIST + ${PROTOCOL_NAME}.asn +) + +set( EXTRA_DIST + ${ASN_FILE_LIST} + packet-${PROTOCOL_NAME}-template.c + ${PROTOCOL_NAME}.cnf +) + +set( SRC_FILES + ${EXTRA_DIST} + ${EXT_ASN_FILE_LIST} +) + +set( A2W_FLAGS ) + +ASN2WRS() diff --git a/epan/dissectors/asn1/mpeg-audio/mpeg-audio.asn b/epan/dissectors/asn1/mpeg-audio/mpeg-audio.asn new file mode 100644 index 00000000..0934d08b --- /dev/null +++ b/epan/dissectors/asn1/mpeg-audio/mpeg-audio.asn @@ -0,0 +1,75 @@ +-- ASN description of MPEG Audio +-- Written by Shaun Jackman <sjackman@gmail.com> +-- Copyright 2007 Shaun Jackman +-- +-- This program is free software; you can redistribute it and/or +-- modify it under the terms of the GNU General Public License. + +MPEG DEFINITIONS ::= BEGIN + +Audio ::= SEQUENCE { + sync BIT STRING (SIZE (11)), + version ENUMERATED + { mpeg-2-5(0), reserved(1), mpeg-2(2), mpeg-1(3) }, + layer ENUMERATED + { reserved(0), layer-3(1), layer-2(2), layer-1(3) }, + protection ENUMERATED { crc(0), none(1) }, + bitrate INTEGER (0..15), + frequency INTEGER (0..3), + padding BOOLEAN, + private BOOLEAN, + channel-mode ENUMERATED + { stereo(0), joint-stereo(1), dual-channel(2), single-channel(3) }, + mode-extension INTEGER (0..3), + copyright BOOLEAN, + original BOOLEAN, + emphasis ENUMERATED + { none(0), em-50-15-ms(1), reserved(2), ccit-j-17(3) } +} + +ID3v1 ::= SEQUENCE { + tag OCTET STRING (SIZE (3)), + title OCTET STRING (SIZE (30)), + artist OCTET STRING (SIZE (30)), + album OCTET STRING (SIZE (30)), + year OCTET STRING (SIZE (4)), + comment OCTET STRING (SIZE (28)), + must-be-zero INTEGER (0..255), + track INTEGER (0..255), + genre INTEGER { + blues(0), classic-rock(1), country(2), dance(3), disco(4), + funk(5), grunge(6), hip-hop(7), jazz(8), metal(9), + new-age(10), oldies(11), other(12), pop(13), r-and-b(14), + rap(15), reggae(16), rock(17), techno(18), industrial(19), + alternative(20), ska(21), death-metal(22), pranks(23), + soundtrack(24), euro-techno(25), ambient(26), trip-hop(27), + vocal(28), jazz-and-funk(29), fusion(30), trance(31), + classical(32), instrumental(33), acid(34), house(35), + game(36), sound-clip(37), gospel(38), noise(39), + alternative-rock(40), bass(41), soul(42), punk(43), space(44), + meditative(45), instrumental-pop(46), instrumental-rock(47), + ethnic(48), gothic(49), darkwave(50), techno-industrial(51), + electronic(52), pop-folk(53), eurodance(54), dream(55), + southern-rock(56), comedy(57), cult(58), gangsta(59), + top-40(60), christian-rap(61), pop-funk(62), jungle(63), + native-american(64), cabaret(65), new-wave(66), + psychedelic(67), rave(68), showtunes(69), trailer(70), + lo-fi(71), tribal(72), acid-punk(73), acid-jazz(74), + polka(75), retro(76), musical(77), rock-and-roll(78), + hard-rock(79), folk(80), folk-rock(81), national-folk(82), + swing(83), fast-fusion(84), bebob(85), latin(86), revival(87), + celtic(88), bluegrass(89), avantgarde(90), gothic-rock(91), + progressive-rock(92), psychedelic-rock(93), + symphonic-rock(94), slow-rock(95), big-band(96), chorus(97), + easy-listening(98), acoustic(99), humour(100), speech(101), + chanson(102), opera(103), chamber-music(104), sonata(105), + symphony(106), booty-bass(107), primus(108), porn-groove(109), + satire(110), slow-jam(111), club(112), tango(113), samba(114), + folklore(115), ballad(116), power-ballad(117), + rhythmic-soul(118), freestyle(119), duet(120), punk-rock(121), + drum-solo(122), a-cappella(123), euro-house(124), + dance-hall(125) + } (0..255) +} + +END diff --git a/epan/dissectors/asn1/mpeg-audio/mpeg-audio.cnf b/epan/dissectors/asn1/mpeg-audio/mpeg-audio.cnf new file mode 100644 index 00000000..f445a2fa --- /dev/null +++ b/epan/dissectors/asn1/mpeg-audio/mpeg-audio.cnf @@ -0,0 +1,11 @@ +# mpeg-audio.cnf +# mpeg-audio conformation file + +#.TYPE_ATTR +ID3v1/tag TYPE=FT_STRING +ID3v1/title TYPE=FT_STRING +ID3v1/artist TYPE=FT_STRING +ID3v1/album TYPE=FT_STRING +ID3v1/year TYPE=FT_STRING +ID3v1/comment TYPE=FT_STRING +#.END diff --git a/epan/dissectors/asn1/mpeg-audio/packet-mpeg-audio-template.c b/epan/dissectors/asn1/mpeg-audio/packet-mpeg-audio-template.c new file mode 100644 index 00000000..29e42ae2 --- /dev/null +++ b/epan/dissectors/asn1/mpeg-audio/packet-mpeg-audio-template.c @@ -0,0 +1,226 @@ +/* MPEG audio packet decoder. + * Written by Shaun Jackman <sjackman@gmail.com>. + * Copyright 2007 Shaun Jackman + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "config.h" + +#include <epan/packet.h> +#include <epan/asn1.h> + +#include <wsutil/mpeg-audio.h> + +#include "packet-per.h" + +#include "packet-mpeg-audio-hf.c" +#include "packet-mpeg-audio-ett.c" +#include "packet-mpeg-audio-fn.c" + +void proto_register_mpeg_audio(void); +void proto_reg_handoff_mpeg_audio(void); + +dissector_handle_t mpeg_audio_handle; + +static int proto_mpeg_audio = -1; +static dissector_handle_t id3v2_handle; + +static int hf_mpeg_audio_header = -1; +static int hf_mpeg_audio_data = -1; +static int hf_mpeg_audio_padbytes = -1; +static int hf_id3v1 = -1; + +static int ett_mpeg_audio = -1; + +static gboolean +test_mpeg_audio(tvbuff_t *tvb, int offset) +{ + guint32 hdr; + struct mpa mpa; + + if (!tvb_bytes_exist(tvb, offset, 4)) + return FALSE; + if (tvb_strneql(tvb, offset, "TAG", 3) == 0) + return TRUE; + if (tvb_strneql(tvb, offset, "ID3", 3) == 0) + return TRUE; + + hdr = tvb_get_guint32(tvb, offset, ENC_BIG_ENDIAN); + MPA_UNMARSHAL(&mpa, hdr); + return MPA_VALID(&mpa); +} + +static int +mpeg_resync(tvbuff_t *tvb, int offset) +{ + guint32 hdr; + struct mpa mpa; + + /* This only looks to resync on another frame; it doesn't + * look for an ID3 tag. + */ + offset = tvb_find_guint8(tvb, offset, -1, '\xff'); + while (offset != -1 && tvb_bytes_exist(tvb, offset, 4)) { + hdr = tvb_get_guint32(tvb, offset, ENC_BIG_ENDIAN); + MPA_UNMARSHAL(&mpa, hdr); + if (MPA_VALID(&mpa)) { + return offset; + } + offset = tvb_find_guint8(tvb, offset + 1, -1, '\xff'); + } + return tvb_reported_length(tvb); +} + +static int +dissect_mpeg_audio_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) +{ + guint32 h; + struct mpa mpa; + int data_size = 0; + asn1_ctx_t asn1_ctx; + int offset = 0; + static const char *version_names[] = { "1", "2", "2.5" }; + + if (!tvb_bytes_exist(tvb, 0, 4)) + return 0; + + h = tvb_get_ntohl(tvb, 0); + MPA_UNMARSHAL(&mpa, h); + if (!MPA_SYNC_VALID(&mpa) || !MPA_VERSION_VALID(&mpa) || !MPA_LAYER_VALID(&mpa)) { + return 0; + } + + col_add_fstr(pinfo->cinfo, COL_PROTOCOL, + "MPEG-%s", version_names[mpa_version(&mpa)]); + col_add_fstr(pinfo->cinfo, COL_INFO, + "Audio Layer %d", mpa_layer(&mpa) + 1); + if (MPA_BITRATE_VALID(&mpa) && MPA_FREQUENCY_VALID(&mpa)) { + data_size = (int)(MPA_DATA_BYTES(&mpa) - sizeof mpa); + col_append_fstr(pinfo->cinfo, COL_INFO, + ", %d kb/s, %g kHz", + mpa_bitrate(&mpa) / 1000, + mpa_frequency(&mpa) / (float)1000); + } + + asn1_ctx_init(&asn1_ctx, ASN1_ENC_PER, TRUE, pinfo); + offset = dissect_mpeg_audio_Audio(tvb, offset, &asn1_ctx, + tree, hf_mpeg_audio_header); + if (data_size > 0) { + unsigned int padding; + + proto_tree_add_item(tree, hf_mpeg_audio_data, tvb, + offset / 8, data_size, ENC_NA); + offset += data_size * 8; + padding = mpa_padding(&mpa); + if (padding > 0) { + proto_tree_add_item(tree, hf_mpeg_audio_padbytes, tvb, + offset / 8, padding, ENC_NA); + offset += padding * 8; + } + } + return offset / 8; +} + +static int +dissect_id3v1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) +{ + asn1_ctx_t asn1_ctx; + + col_set_str(pinfo->cinfo, COL_PROTOCOL, "ID3v1"); + col_clear(pinfo->cinfo, COL_INFO); + asn1_ctx_init(&asn1_ctx, ASN1_ENC_PER, TRUE, pinfo); + return dissect_mpeg_audio_ID3v1(tvb, 0, &asn1_ctx, + tree, hf_id3v1); +} + +static int +dissect_mpeg_audio(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_) +{ + proto_item *ti; + proto_tree *mpeg_audio_tree; + + int magic, offset = 0; + guint32 frame_len; + tvbuff_t *next_tvb; + + ti = proto_tree_add_item(tree, proto_mpeg_audio, tvb, offset, -1, ENC_NA); + mpeg_audio_tree = proto_item_add_subtree(ti, ett_mpeg_audio); + while (tvb_reported_length_remaining(tvb, offset) >= 4) { + next_tvb = tvb_new_subset_remaining(tvb, offset); + magic = tvb_get_ntoh24(next_tvb, 0); + switch (magic) { + case 0x544147: /* TAG */ + offset += dissect_id3v1(next_tvb, pinfo, mpeg_audio_tree); + break; + case 0x494433: /* ID3 */ + offset += call_dissector(id3v2_handle, tvb, pinfo, mpeg_audio_tree); + break; + default: + frame_len = dissect_mpeg_audio_frame(next_tvb, pinfo, mpeg_audio_tree); + if (frame_len == 0) { + frame_len = mpeg_resync(next_tvb, 0); + } + offset += frame_len; + } + } + return tvb_reported_length(tvb); +} + +static gboolean +dissect_mpeg_audio_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) +{ + if (!test_mpeg_audio(tvb, 0)) { + return FALSE; + } + dissect_mpeg_audio(tvb, pinfo, tree, data); + return TRUE; +} + +void +proto_register_mpeg_audio(void) +{ + static hf_register_info hf[] = { +#include "packet-mpeg-audio-hfarr.c" + { &hf_mpeg_audio_header, + { "Frame Header", "mpeg-audio.header", + FT_NONE, BASE_NONE, NULL, 0, NULL, HFILL }}, + { &hf_mpeg_audio_data, + { "Data", "mpeg-audio.data", + FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }}, + { &hf_mpeg_audio_padbytes, + { "Padding", "mpeg-audio.padbytes", + FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }}, + + { &hf_id3v1, + { "ID3v1", "mpeg-audio.id3v1", + FT_NONE, BASE_NONE, NULL, 0, NULL, HFILL }}, + }; + + static gint *ett[] = { + &ett_mpeg_audio, +#include "packet-mpeg-audio-ettarr.c" + }; + + proto_mpeg_audio = proto_register_protocol("Moving Picture Experts Group Audio", "MPEG Audio", "mpeg-audio"); + proto_register_field_array(proto_mpeg_audio, hf, array_length(hf)); + proto_register_subtree_array(ett, array_length(ett)); + + mpeg_audio_handle = register_dissector("mpeg-audio", dissect_mpeg_audio, proto_mpeg_audio); +} + +void +proto_reg_handoff_mpeg_audio(void) +{ + dissector_add_string("media_type", "audio/mpeg", mpeg_audio_handle); + /* "audio/mp3" used by Chrome before 2020 */ + /* https://chromium.googlesource.com/chromium/src/+/842f46a95f49e24534ad35c7a71e5c425d426550 */ + dissector_add_string("media_type", "audio/mp3", mpeg_audio_handle); + + heur_dissector_add("mpeg", dissect_mpeg_audio_heur, "MPEG Audio", "mpeg_audio", proto_mpeg_audio, HEURISTIC_ENABLE); + + id3v2_handle = find_dissector("id3v2"); +} |