3 * Routines for reading a binary file containing a ruby marshal object
5 * Copyright 2018, Dario Lombardo <lomato@gmail.com>
7 * SPDX-License-Identifier: GPL-2.0-or-later
11 #include "ruby_marshal.h"
16 #include "file_wrappers.h"
18 static int ruby_marshal_file_type_subtype
= -1;
20 void register_ruby_marshal(void);
22 static bool is_ruby_marshal(const uint8_t* filebuf
)
24 if (filebuf
[0] != RUBY_MARSHAL_MAJOR
)
26 if (filebuf
[1] != RUBY_MARSHAL_MINOR
)
54 wtap_open_return_val
ruby_marshal_open(wtap
*wth
, int *err
, char **err_info
)
56 /* The size of this buffer should match the expectations of is_ruby_marshal */
60 bytes_read
= file_read(filebuf
, sizeof(filebuf
), wth
->fh
);
63 *err
= file_error(wth
->fh
, err_info
);
64 return WTAP_OPEN_ERROR
;
67 if (bytes_read
!= sizeof(filebuf
) || !is_ruby_marshal(filebuf
)) {
68 return WTAP_OPEN_NOT_MINE
;
71 if (file_seek(wth
->fh
, 0, SEEK_SET
, err
) == -1) {
72 return WTAP_OPEN_ERROR
;
75 wth
->file_type_subtype
= ruby_marshal_file_type_subtype
;
76 wth
->file_encap
= WTAP_ENCAP_RUBY_MARSHAL
;
77 wth
->file_tsprec
= WTAP_TSPREC_SEC
;
78 wth
->subtype_read
= wtap_full_file_read
;
79 wth
->subtype_seek_read
= wtap_full_file_seek_read
;
80 wth
->snapshot_length
= 0;
82 return WTAP_OPEN_MINE
;
85 static const struct supported_block_type ruby_marshal_blocks_supported
[] = {
87 * We support packet blocks, with no comments or other options.
89 { WTAP_BLOCK_PACKET
, MULTIPLE_BLOCKS_SUPPORTED
, NO_OPTIONS_SUPPORTED
}
92 static const struct file_type_subtype_info ruby_marshal_info
= {
93 "Ruby marshal files", "ruby_marshal", NULL
, NULL
,
94 false, BLOCKS_SUPPORTED(ruby_marshal_blocks_supported
),
98 void register_ruby_marshal(void)
100 ruby_marshal_file_type_subtype
= wtap_register_file_type_subtype(&ruby_marshal_info
);
103 * Register name for backwards compatibility with the
104 * wtap_filetypes table in Lua.
106 wtap_register_backwards_compatibility_lua_name("RUBY_MARSHAL",
107 ruby_marshal_file_type_subtype
);
111 * Editor modelines - https://www.wireshark.org/tools/modelines.html
116 * indent-tabs-mode: nil
119 * vi: set shiftwidth=4 tabstop=8 expandtab:
120 * :indentSize=4:tabSize=8:noTabs=true: