Commit Graph

38 Commits

Author SHA1 Message Date
João Valverde 0e50979b3f Replace g_assert() with ws_assert() 2021-06-19 01:23:31 +00:00
Guy Harris 272502790b Add FT_STRINGZTRUNC.
FT_STRINGZPAD is for null-*padded* strings, where the field is in an
area of specified length, and, if the string is shorter than that
length, all bytes past the end of the string are NULs.

FT_STRINGZTRUNC is for null-*truncated* strings, where the field is in
an area of specified length and, if the string is shorter than that
length, there's a null character (which might be more than one byte, for
UCS-2, UTF-16, or UTF-32), and anything after that is not guaranteed to
have any particular value.

Use IS_FT_STRING() in some places rather than enumerating all the string
types, so that those places get automatically changed if the set of
string types changes.
2020-09-12 14:16:12 -07:00
Stig Bjørlykke 09777ecc04 epan: Always clear all decode-as when loading entries
Always call decode_clear_all() when loading decode_as entries because
this function will create decode_build_reset_list based on entries that
has been changed from its original state.

Ping-Bug: 16635
Change-Id: Ib589d4bc863b680146063ad682398f6180125a38
Reviewed-on: https://code.wireshark.org/review/37582
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
2020-06-29 18:42:26 +00:00
Stig Bjørlykke 3dc5f5c2d6 epan: Keep decode_as_list when changing profile
The decode_as_list is built at startup and contains all protocols
registered for "decode as". Do not clear this list on profile change,
only on exit.

Bug: 16635
Change-Id: I832a042327603ae0f01b10ab620fccc03d4fd3a3
Reviewed-on: https://code.wireshark.org/review/37579
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
2020-06-29 18:40:27 +00:00
Martin Kaiser c6ebd5bf36 register_decode_as_next_proto: remove the "title" parameter
Remove the "title" parameter from the register_decode_as_next_proto()
function. This parameter is no longer required since decode_as_t does
not have a title any more.

Change-Id: I300c755bd465453aa91703b53ce9adc954e38c00
Reviewed-on: https://code.wireshark.org/review/33579
Reviewed-by: Martin Kaiser <wireshark@kaiser.cx>
Petri-Dish: Martin Kaiser <wireshark@kaiser.cx>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-06-13 05:38:22 +00:00
Martin Kaiser f155601d66 decode_as: remove the "title" member from decode_as_t
The title of a decode_as_t was used by the GTK UI. It's no
longer required for Qt.

Change-Id: Ibd9d4acbe9cad2c1af520340d04e550326a97ebe
Reviewed-on: https://code.wireshark.org/review/33557
Petri-Dish: Martin Kaiser <wireshark@kaiser.cx>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-06-11 18:50:32 +00:00
Guy Harris cced5fb949 Constification, to remove some compiler warnings.
Change-Id: I24f0bdc72109a6ef3d801dc28cb9b523ff4e5fe7
Reviewed-on: https://code.wireshark.org/review/32458
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-03-17 21:09:34 +00:00
Anders Broman a4251ec71d decode-as: Write the entries sorted to file.
If the list isn't sorted port ranges in preferences get may get "scrambled".
Try SIP udp.ports 5060, 5062-5064, 5066, 5078 save and open again the
order is now random. This patch should fix that.

Change-Id: Ic81f5d132d2c28ca982e8719786cdddbd237d37b
Reviewed-on: https://code.wireshark.org/review/32420
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-03-15 19:17:49 +00:00
Guy Harris d332507ef2 Fix the "pointer to function that generates a label" values.
build_label_func is a pointer type, pointing to a function that can be
used to generate a label for a "Decode As" entry.  There's no need to
have pointers to those pointers; have register_decode_as_next_proto()
take a build_label_func, not a build_label_func *, as its last argument,
assign that value rather than dereferencing it, get rid of unnecessary
casts, and fix the comment in epan/decode_as.h for that argument.

Change-Id: Idc3cf18204c543a2191b122c8129b362562c0ecd
Reviewed-on: https://code.wireshark.org/review/25773
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-02-13 18:06:11 +00:00
Dario Lombardo 55c68ee69c epan: use SPDX indentifiers.
Skipping dissectors dir for now.

Change-Id: I717b66bfbc7cc81b83f8c2cbc011fcad643796aa
Reviewed-on: https://code.wireshark.org/review/25694
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-02-08 19:29:45 +00:00
Guy Harris e6d47cb7b3 Don't cast away constness if it's not necessary.
Change-Id: Ic5ecf4628f03c63b68fadd9ffed49cfd5497d99c
Reviewed-on: https://code.wireshark.org/review/25361
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-01-18 06:00:59 +00:00
Michael Mann eef3c8434d Add ability for preferences to determine what they can change.
Add flags field to preference structure to help determine what
areas of Wireshark are affected by a preference changing.  The
intent is to be able to distinguish dissection from GUI or other
changes that are not dissection.

The default is to have all preferences affect dissection, but their
flags can be changed.  This patch doesn't change any flags from the
default.

Change-Id: Ied5ae961bc3f33f5b730b2892fff3fa0898380b8
Reviewed-on: https://code.wireshark.org/review/25171
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Michael Mann <mmann78@netscape.net>
2018-01-06 17:49:23 +00:00
AndersBroman 585a57ea1e [decode_as.c] Use g_list_prepend() insted of g_list_append, it's faster.
Change-Id: I56c4a7948da48d02c81c5cf30187a6eeb973db77
Reviewed-on: https://code.wireshark.org/review/24700
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2017-12-04 11:58:55 +00:00
Michael Mann 69250aa51e Add support for dissector tables of type FT_NONE.
This is for dissectors that have "payloads" that don't have
a unique identifier to determine a sub dissector.

For the command line parameter -d, specifying a selector is no longer
required for dissector tables of type FT_NONE.

Change-Id: I3370d9e0dc147deeca4f26b842fe35dc3bda876e
Reviewed-on: https://code.wireshark.org/review/22574
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-09-16 11:12:52 +00:00
Michael Mann 7d65b573f2 Have register_decode_as_next_proto create dissector table.
For protocols that have don't have a unique identifier for their
payload, have register_decode_as_next_proto be a one stop shop to
create Decode As functionality and a dissector table of type FT_NONE.

Change-Id: Ic1f2e9ed0aee0554a4eb8f232630b99c0604dfc0
Reviewed-on: https://code.wireshark.org/review/22575
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-09-16 11:12:29 +00:00
Michael Mann 9b3c8d4515 Expand register_decode_as_next_proto to include prompt string.
Many dissectors don't have an identifier to pass to a dissector table.
When using Decode As they all have a "value" function that returns 0
just so something is returned.

A first step to a cleaner refactor of the functionality is to allow
dissectors to provide a "prompt" function when registering Decode As
with register_decode_as_next_proto() so that the text exposed in
the GUI can vary, but the function that returns 0 (nothing) can be
consolidated under decode as registration functionality.  This casts
a wider net for register_decode_as_next_proto() use.

Change-Id: I2995b3c251dae70f5f529b672473d25c6288ed5c
Reviewed-on: https://code.wireshark.org/review/22562
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2017-07-11 08:41:49 +00:00
Martin Kaiser f7952b30c7 decode_as: replace DISSECTOR_ASSERT() with g_assert()
Don't use DISSECTOR_ASSERT() unless we're in wmem packet scope, see
commit 341b06ce0795ae957627c9174b57e75c7827f028

Change-Id: I509f9197155fe6ea6f46c23c93eb188220b9dd8d
Reviewed-on: https://code.wireshark.org/review/22379
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-06-24 22:04:49 +00:00
Martin Kaiser 1620c45e03 simplified Decode As entry if the next protocol requires manual selection
There's a number of protocols whose payload contains yet another
protocol but no criterion to figure out what this next protocol is.

Define a new global function register_decode_as_next_proto() to register
a Decode As entry for this scenario so the user can manually select the
next protocol.

A lot of the housekeeping that is normally required for Decode As is not
applicable to such a scenario. Provide simple data structures and
functions to cover this, make them internal to epan/decode_as.c and
allow them to be shared by multiple of the new simplified Decode As
entries.

(For now, the mechanism is based on an FT_UINT32 dissectore table where
all entries are linked to number 0. We should eventually come up with a
better mechanism.)

Change-Id: I3f81e331d7d04cfdfe9a58732d881652d77fabe2
Reviewed-on: https://code.wireshark.org/review/22376
Reviewed-by: Martin Kaiser <wireshark@kaiser.cx>
Petri-Dish: Martin Kaiser <wireshark@kaiser.cx>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-06-24 22:04:09 +00:00
Max Dmitrichenko 860bfd8ba4 decode as: Fix small memory leak
Change-Id: I3b924ff3e81a5b4ca17fcb9a087b7d7520225f34
Reviewed-on: https://code.wireshark.org/review/21231
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-04-19 22:27:35 +00:00
Stig Bjørlykke 618df2460a decode_as: Initialize decode_as_list after free
Initialize decode_as_list = NULL after free to avoid random crashes
in g_list functions after changing profile.

This bug was introduced in g5c7b0b96

Change-Id: Ibc752f245115c5a426989e20e0ab9d0f0faac43d
Reviewed-on: https://code.wireshark.org/review/19821
Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
2017-01-28 11:53:06 +00:00
Michael Mann 21a3b8cc71 Internalize struct preference
Move "struct preference" into prefs.c, essentially creating a "private"
structure to handle preferences. The 2 motivating factors were:
1. Better memory management so that clients/users of API don't have to worry
about it.
2. Hide the ugliness of the union stuff and make it transparent to the API.

A few bugs related to preference <-> Decode As integration were fixed
while in the neighborhood.

Change-Id: I509b9a236235d066b139c98222b701475e0ed365
Reviewed-on: https://code.wireshark.org/review/19578
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2017-01-22 10:43:57 +00:00
Dario Lombardo 5c7b0b9687 decode_as: clean memory on exit.
Change-Id: Ifbbfc1ff71c32c2e9b758b55d32bff9a1ccd1576
Reviewed-on: https://code.wireshark.org/review/19689
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-01-21 00:25:15 +00:00
Michael Mann 165c8b0422 Refactor range preference.
Refactored so that all handling of ranges in struct preference
can be internal to prefs.c

Change-Id: I68577909f9c07b23a16ab3443a523355d4645314
Reviewed-on: https://code.wireshark.org/review/19577
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-01-07 15:35:18 +00:00
Michael Mann 6a6d7ea34f Convert range API to always use wmem memory.
This is mostly to address memory leaks in range preferences (the biggest
user of range functionality) on shutdown.
Now range preferences must use epan scoped memory when referencing
internal preference structures to keep consistency.

Change-Id: Idc644f59b5b42fa1d46891542b53ff13ea754157
Reviewed-on: https://code.wireshark.org/review/19387
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-01-07 00:44:10 +00:00
Michael Mann 739bdfb45f Some Pref <-> Decode As bugfixes.
1. If a deprecated port preference is found, populate the new port preference with the value
2. Mark preferences as changed to trigger preference callback at startup.

Change-Id: Ic271841686617e847d2e0ed8800bbb0fa874df47
Reviewed-on: https://code.wireshark.org/review/18274
Reviewed-by: Michael Mann <mmann78@netscape.net>
2016-10-18 23:03:23 +00:00
Michael Mann 268841f3e0 Combine Decode As and port preferences for tcp.port dissector table.
This patch introduces new APIs to allow dissectors to have a preference for
a (TCP) port, but the underlying data is actually part of Decode As functionality.
For now the APIs are intentionally separate from the regular APIs that register a
dissector within a dissector table.  It may be possible to eventually combine the
two so that all dissectors that register with a dissector table have an opportunity
to "automatically" have a preference to adjust the "table value" through the
preferences dialog.

The tcp.port dissector table was used as the guinea pig.  This will eventually be
expanded to other dissector tables as well (most notably UDP ports).  Some
dissectors that "shared" a TCP/UDP port preference were also converted. It also
removed the need for some preference callback functions (mostly when the callback
function was the proto_reg_handoff function) so there is cleanup around that.

Dissectors that has a port preference whose default was 0 were switched to using
the dissector_add_for_decode_as_with_preference API rather than dissector_add_uint_with_preference

Also added comments for TCP ports used that aren't IANA registered.

Change-Id: I99604f95d426ad345f4b494598d94178b886eb67
Reviewed-on: https://code.wireshark.org/review/17724
Reviewed-by: Michael Mann <mmann78@netscape.net>
2016-10-08 02:44:53 +00:00
Guy Harris a4c8ebc18b Don't do any Decode As stuff for dissector tables not used with Decode As.
Have all dissector tables have a "supports Decode As" flag, which
defaults to FALSE, and which is set to TRUE if a register_decode_as()
refers to it.

When adding a dissector to a dissector table with a given key, only add
it for Decode As if the dissector table supports it.

For non-FT_STRING dissector tables, always check for multiple entries
for the same protocol with different dissectors, and report an error if
we found them.

This means there's no need for the creator of a dissector table to
specify whether duplicates of that sort should be allowed - we always do
the check when registering something for "Decode As" (in a non-FT_STRING
dissector table), and just don't bother registering anything for "Decode
As" if the dissector table doesn't support "Decode As", so there's no
check done for those dissector tables.

Change-Id: I4a1fdea3bddc2af27a65cfbca23edc99b26c0eed
Reviewed-on: https://code.wireshark.org/review/17402
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-08-31 00:08:01 +00:00
João Valverde 95dee44a77 const gpointer -> gconstpointer
'const gpointer' is the same as 'void *const'. Replace with gconstpointer
where straightforward (assuming that was the intent) and use gpointer everywhere
else for clarity (that does not change *API* constness contract; it just means
a variable is not declared immutable inside the called funtion).

Change-Id: Iad2ef13205bfb4ff0056b2bce056353b58942267
Reviewed-on: https://code.wireshark.org/review/13945
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2016-02-16 05:10:49 +00:00
Michael Mann 74541a9596 Don't allow multiple registrations of a protocol in dissector tables.
The target here is the Decode As dialog where protocols have multiple registrations into a dissector table and that shows up as multiple entries in the Decode As dialog list with the same name so users are unsure which "dissector" they are choosing.

The "default" behavior (done in this commit) is to not allow duplicates for a dissector table, whether its part of Decode As or not.  It's just ENFORCED for Decode As.

Bug: 3949
Change-Id: Ibe14fa61aaeca0881f9cc39b78799e314b5e8127
Reviewed-on: https://code.wireshark.org/review/11405
Petri-Dish: Michael Mann <mmann78@netscape.net>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2015-11-04 12:39:40 +00:00
Michal Labedzki 77d9a059fe Qt: Fix DecodeAs
Previously DecodeAs neither save its changes nor changes dissector tables.
Do that and redissect packets to refresh view.

Bug: 10553
Change-Id: Icd8453c9650f0265852f6b6b58bc483b35570a15
Reviewed-on: https://code.wireshark.org/review/7676
Petri-Dish: Michal Labedzki <michal.labedzki@tieto.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michal Labedzki <michal.labedzki@tieto.com>
2015-03-14 14:26:17 +00:00
Guy Harris 7c72f70f59 Remove a comment asking a question, as the answer is "no".
I.e., no, the epan/decode_as.c stuff belongs in libwireshark, not libui,
because dissectors need to be able to say "I support decode-as...".
Code to implement the UIs that allow decode-as entries to be specified
would belong in libui.

Change-Id: Ibf9da19e752481a3892d0f03d0a0537590ab1811
Reviewed-on: https://code.wireshark.org/review/3416
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2014-08-04 22:01:06 +00:00
Alexis La Goutte 296591399f Remove all $Id$ from top of file
(Using sed : sed -i '/^ \* \$Id\$/,+1 d')

Fix manually some typo (in export_object_dicom.c and crc16-plain.c)

Change-Id: I4c1ae68d1c4afeace8cb195b53c715cf9e1227a8
Reviewed-on: https://code.wireshark.org/review/497
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-03-04 14:27:33 +00:00
Gerald Combs 17a67c3b5c Get the "Decode As" dialog working, albeit with a few warts. It differs
from the GTK flavor in two major ways:

- The "Decode As" and "User Specified Decodes" dialog have been unified.
- You can modify the decode as behavior at any time, not just when you
  have a packet selected.

Revert part of 53498 so that we can move items marked

/*** THE FOLLOWING SHOULD NOT BE USED BY ANY DISSECTORS!!! ***/

from epan/decode_as.h to ui/decode_as_utils.h. 

Move "save" code from decode_as_dlg.c to decode_as_utils.c as well.

In packet-dcerpc.c don't register a table named "ethertype". We might
want to add checks for duplicate table names.

To do:
- Add support for ranges?
- Either add support for DCERPC or make DCERPC use a regular dissector
  table.
- Fix string selectors (i.e. BER).


svn path=/trunk/; revision=53910
2013-12-10 19:23:26 +00:00
Jakub Zawadzki 65db82872c When including <epan/prefs.h> don't force inclusion of <epan/uat.h>
svn path=/trunk/; revision=53769
2013-12-03 22:16:49 +00:00
Gerald Combs 27089d62a9 Clean up whitespace.
svn path=/trunk/; revision=53648
2013-11-29 15:46:50 +00:00
Gerald Combs 5acdfae070 Restore disabled "decode as" settings.
svn path=/trunk/; revision=53635
2013-11-29 03:14:24 +00:00
Gerald Combs 70709e1b35 Move common "decode as" preference code to epan.
We presumably want "decode as" behavior to be consistent across UIs so
call load_decode_as_entries() from read_prefs().

svn path=/trunk/; revision=53498
2013-11-22 00:20:23 +00:00
Michael Mann 76ab93ea94 Provide "Decode As" functionality through dissectors themselves instead of the GUI. Bug 9450 (https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=9450)
The basic idea behind this design is to have dissectors register with a "decode as list" with their name and dissector table.  When "Decode As" dialog is launched, any "registered" dissector found in the packet will cause a tab to be created in the dialog.

This patch includes just the dissector portion of the functionality (minus packet-dcerpc.[ch] because it has hooks to the current GUI)

svn path=/trunk/; revision=53445
2013-11-20 19:17:08 +00:00