aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/ber.c
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2021-02-20 00:13:37 -0800
committerGuy Harris <gharris@sonic.net>2021-02-20 01:36:26 -0800
commit1f595c435c1476a24e2b443a768185ac2503087a (patch)
treed608bd80e5b357c5b11270089629dec883aabc5f /wiretap/ber.c
parentc80c16759ba23e29c70ec8fbe62e0a9870685a66 (diff)
BER: get rid of WTAP_FILE_TYPE_SUBTYPE_BER.
Save a copy of the pathname used to open a file in the wtap structure. This allows the BER file reader to put a pointer to it in the pseudo-header; it also would allow file readers to attempt to read "associated" files that have the same name as the file, but with a different extension. Instead of having cf_open() special-case BER files, and calling a routine in the BER dissector to specify the file name to the dissector, have separate dissectors for "dissect packet payload as BER" and "dissect a file as BER", and have the latter get the pathname of the file from the pseudo-header and determine the ASN.1 syntax from that. (Side-effect - this means that you can now dissect a BER file, and have the syntax be determined by the file extension, in TShark as well; the above cf_open() special-casing was *not* done in TShark, so it didn't work before. Now the application code doesn't need to do any of that, so it works in TShark as well as Wireshark.)
Diffstat (limited to 'wiretap/ber.c')
-rw-r--r--wiretap/ber.c51
1 files changed, 48 insertions, 3 deletions
diff --git a/wiretap/ber.c b/wiretap/ber.c
index c6bdd9c600..789f93993c 100644
--- a/wiretap/ber.c
+++ b/wiretap/ber.c
@@ -22,6 +22,34 @@
#define BER_UNI_TAG_SEQ 16 /* SEQUENCE, SEQUENCE OF */
#define BER_UNI_TAG_SET 17 /* SET, SET OF */
+static int ber_file_type_subtype = -1;
+
+void register_ber(void);
+
+static gboolean ber_full_file_read(wtap *wth, wtap_rec *rec, Buffer *buf,
+ int *err, gchar **err_info,
+ gint64 *data_offset)
+{
+ if (!wtap_full_file_read(wth, rec, buf, err, err_info, data_offset))
+ return FALSE;
+
+ /* Pass the file name. */
+ rec->rec_header.packet_header.pseudo_header.ber.pathname = wth->pathname;
+ return TRUE;
+}
+
+static gboolean ber_full_file_seek_read(wtap *wth, gint64 seek_off,
+ wtap_rec *rec, Buffer *buf,
+ int *err, gchar **err_info)
+{
+ if (!wtap_full_file_seek_read(wth, seek_off, rec, buf, err, err_info))
+ return FALSE;
+
+ /* Pass the file name. */
+ rec->rec_header.packet_header.pseudo_header.ber.pathname = wth->pathname;
+ return TRUE;
+}
+
wtap_open_return_val ber_open(wtap *wth, int *err, gchar **err_info)
{
#define BER_BYTES_TO_CHECK 8
@@ -90,17 +118,34 @@ wtap_open_return_val ber_open(wtap *wth, int *err, gchar **err_info)
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
return WTAP_OPEN_ERROR;
- wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_BER;
+ wth->file_type_subtype = ber_file_type_subtype;
wth->file_encap = WTAP_ENCAP_BER;
wth->snapshot_length = 0;
- wth->subtype_read = wtap_full_file_read;
- wth->subtype_seek_read = wtap_full_file_seek_read;
+ wth->subtype_read = ber_full_file_read;
+ wth->subtype_seek_read = ber_full_file_seek_read;
wth->file_tsprec = WTAP_TSPREC_SEC;
return WTAP_OPEN_MINE;
}
+static const struct file_type_subtype_info ber_info = {
+ "ASN.1 Basic Encoding Rules", "ber", NULL, NULL,
+ FALSE, FALSE, 0,
+ NULL, NULL, NULL
+};
+
+void register_ber(void)
+{
+ ber_file_type_subtype = wtap_register_file_type_subtypes(&ber_info);
+
+ /*
+ * Register name for backwards compatibility with the
+ * wtap_filetypes table in Lua.
+ */
+ wtap_register_backwards_compatibility_lua_name("BER", ber_file_type_subtype);
+}
+
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*