NEEDED??? epan/dissectors/packet-dcerpc.c dissect_ndr_c_and_or_v_array_core dissect_n...
[wireshark-sm.git] / wiretap / ruby_marshal.c
blob377c688f1001efbfd9502b489fa971516490467c
1 /* ruby_marshal.c
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
8 */
10 #include "config.h"
11 #include "ruby_marshal.h"
13 #include <string.h>
15 #include "wtap-int.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)
25 return false;
26 if (filebuf[1] != RUBY_MARSHAL_MINOR)
27 return false;
28 switch (filebuf[2]) {
29 case '0':
30 case 'T':
31 case 'F':
32 case 'i':
33 case ':':
34 case '"':
35 case 'I':
36 case '[':
37 case '{':
38 case 'f':
39 case 'c':
40 case 'm':
41 case 'S':
42 case '/':
43 case 'o':
44 case 'C':
45 case 'e':
46 case ';':
47 case '@':
48 return true;
49 default:
50 return false;
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 */
57 uint8_t filebuf[3];
58 int bytes_read;
60 bytes_read = file_read(filebuf, sizeof(filebuf), wth->fh);
61 if (bytes_read < 0) {
62 /* Read error. */
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),
95 NULL, NULL, NULL
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
113 * Local variables:
114 * c-basic-offset: 4
115 * tab-width: 8
116 * indent-tabs-mode: nil
117 * End:
119 * vi: set shiftwidth=4 tabstop=8 expandtab:
120 * :indentSize=4:tabSize=8:noTabs=true: