From 5393894ed755320f07e193c2e4d55a2ed88bd736 Mon Sep 17 00:00:00 2001 From: Reinhold Kainhofer <reinhold@kainhofer.com> Date: Sun, 18 Dec 2011 01:18:44 +0100 Subject: [PATCH] wireshark magicolor dissector: basic functionality, no argument dissection to scanner commands --- .gitignore | 1 + wireshark-plugin-magicolor/AUTHORS | 2 + wireshark-plugin-magicolor/CMakeLists.txt | 84 +++++ wireshark-plugin-magicolor/COPYING | 340 ++++++++++++++++++ wireshark-plugin-magicolor/ChangeLog | 0 wireshark-plugin-magicolor/INSTALL | 9 + wireshark-plugin-magicolor/NEWS | 3 + wireshark-plugin-magicolor/README | 19 + .../cmake/FindGLIB2.cmake | 238 ++++++++++++ .../cmake/FindWireshark.cmake | 28 ++ .../cmake/UseMakeDissectorReg.cmake | 33 ++ wireshark-plugin-magicolor/moduleinfo.h | 17 + wireshark-plugin-magicolor/packet-bizhub.c | 0 wireshark-plugin-magicolor/packet-magicolor.c | 244 +++++++++++++ .../tools/make-dissector-reg | 186 ++++++++++ .../tools/make-dissector-reg.py | 305 ++++++++++++++++ 16 files changed, 1509 insertions(+) create mode 100644 .gitignore create mode 100644 wireshark-plugin-magicolor/AUTHORS create mode 100644 wireshark-plugin-magicolor/CMakeLists.txt create mode 100644 wireshark-plugin-magicolor/COPYING create mode 100644 wireshark-plugin-magicolor/ChangeLog create mode 100644 wireshark-plugin-magicolor/INSTALL create mode 100644 wireshark-plugin-magicolor/NEWS create mode 100644 wireshark-plugin-magicolor/README create mode 100644 wireshark-plugin-magicolor/cmake/FindGLIB2.cmake create mode 100644 wireshark-plugin-magicolor/cmake/FindWireshark.cmake create mode 100644 wireshark-plugin-magicolor/cmake/UseMakeDissectorReg.cmake create mode 100644 wireshark-plugin-magicolor/moduleinfo.h create mode 100644 wireshark-plugin-magicolor/packet-bizhub.c create mode 100644 wireshark-plugin-magicolor/packet-magicolor.c create mode 100755 wireshark-plugin-magicolor/tools/make-dissector-reg create mode 100755 wireshark-plugin-magicolor/tools/make-dissector-reg.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/wireshark-plugin-magicolor/AUTHORS b/wireshark-plugin-magicolor/AUTHORS new file mode 100644 index 0000000..403caff --- /dev/null +++ b/wireshark-plugin-magicolor/AUTHORS @@ -0,0 +1,2 @@ +Author: +Reinhold Kainhofer <reinhold@kainhofer.com> diff --git a/wireshark-plugin-magicolor/CMakeLists.txt b/wireshark-plugin-magicolor/CMakeLists.txt new file mode 100644 index 0000000..a1ba046 --- /dev/null +++ b/wireshark-plugin-magicolor/CMakeLists.txt @@ -0,0 +1,84 @@ +# CMakeLists.txt +# +# $Id: CMakeLists.txt 31995 2010-02-24 22:32:10Z jmayer $ +# +# Wireshark - Network traffic analyzer +# By Gerald Combs <gerald@wireshark.org> +# Copyright 1998 Gerald Combs +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# + +project(magicolor-wireshark-plugin C) + +cmake_minimum_required(VERSION 2.6) +set(CMAKE_BACKWARDS_COMPATIBILITY 2.6) +set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) +set(CMAKE_INSTALL_LIBDIR ~/.wireshark) + +INCLUDE(UseMakeDissectorReg) + +set(GLIB2_MIN_VERSION 2.4.0) + +find_package(GLIB2) +include_directories (${GLIB2_INCLUDE_DIRS}) + +find_package(Wireshark) +include_directories (${WIRESHARK_INCLUDE_DIRS}) + +set(LINK_MODE_LIB SHARED) +set(LINK_MODE_MODULE MODULE) + + +set(DISSECTOR_SRC + packet-magicolor.c +) + +set(PLUGIN_FILES + plugin.c + ${DISSECTOR_SRC} +) + +set(CLEAN_FILES + ${PLUGIN_FILES} +) + +if (WERROR) + set_source_files_properties( + ${CLEAN_FILES} + PROPERTIES + COMPILE_FLAGS -Werror + ) +endif() + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + +register_dissector_files(plugin.c + plugin + ${DISSECTOR_SRC} +) + +add_library(magicolor ${LINK_MODE_MODULE} + ${PLUGIN_FILES} +) +set_target_properties(magicolor PROPERTIES PREFIX "") +set_target_properties(magicolor PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}") + +target_link_libraries(magicolor wireshark) + +install(TARGETS magicolor + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/plugins NAMELINK_SKIP +) + diff --git a/wireshark-plugin-magicolor/COPYING b/wireshark-plugin-magicolor/COPYING new file mode 100644 index 0000000..d60c31a --- /dev/null +++ b/wireshark-plugin-magicolor/COPYING @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/wireshark-plugin-magicolor/ChangeLog b/wireshark-plugin-magicolor/ChangeLog new file mode 100644 index 0000000..e69de29 diff --git a/wireshark-plugin-magicolor/INSTALL b/wireshark-plugin-magicolor/INSTALL new file mode 100644 index 0000000..ff62ac2 --- /dev/null +++ b/wireshark-plugin-magicolor/INSTALL @@ -0,0 +1,9 @@ +This wireshark plugin is built with cmake (in a separate build/ directory): + mkdir build + cd build + cmake .. + make + make install + +This will build the .so plugin for wireshark and install it into the user's +~/.wireshark/plugins/ directory, where wireshark will load plugins from. diff --git a/wireshark-plugin-magicolor/NEWS b/wireshark-plugin-magicolor/NEWS new file mode 100644 index 0000000..da4bed1 --- /dev/null +++ b/wireshark-plugin-magicolor/NEWS @@ -0,0 +1,3 @@ +December 14, 2011 + Start + diff --git a/wireshark-plugin-magicolor/README b/wireshark-plugin-magicolor/README new file mode 100644 index 0000000..39d8b6c --- /dev/null +++ b/wireshark-plugin-magicolor/README @@ -0,0 +1,19 @@ +The HP 2101nw wireless G USB print server is a USB port forwareder over +a wireless TCP/IP network. + +-) Configuration (setting up the wirless network, only needed once) is done + via a USB connection to the PC, format is a simple config file USB bulk + data exchange. + +-) Network detection of the print server uses UDP port 34444 and the same + format as the USB configuration. + +-) Locking/reserving the print server to the PC uses TCP and UDP port 34447, + format of the packets is "SBSU[Cmd][args]". + +-) Commnication with the printer (USB over TCP) uses TCP port 34448, format is + 24 bytes header, then raw USB data. Response uses a 20-bytes header of + the format "RBRU[len]...", after which the raw USB data is sent. + + +The author is Reinhold Kainhofer <reinhold@kainhofer.com> diff --git a/wireshark-plugin-magicolor/cmake/FindGLIB2.cmake b/wireshark-plugin-magicolor/cmake/FindGLIB2.cmake new file mode 100644 index 0000000..ae7badd --- /dev/null +++ b/wireshark-plugin-magicolor/cmake/FindGLIB2.cmake @@ -0,0 +1,238 @@ +# +# $Id: FindGLIB2.cmake 34248 2010-09-25 15:38:12Z jmayer $ +# +# - Try to find GLib2 +# Once done this will define +# +# GLIB2_FOUND - system has GLib2 +# GLIB2_INCLUDE_DIRS - the GLib2 include directory +# GLIB2_LIBRARIES - Link these to use GLib2 +# +# HAVE_GLIB_GREGEX_H glib has gregex.h header and +# supports g_regex_match_simple +# +# Copyright (c) 2006 Andreas Schneider <mail@cynapses.org> +# Copyright (c) 2006 Philippe Bernery <philippe.bernery@gmail.com> +# Copyright (c) 2007 Daniel Gollub <gollub@b1-systems.de> +# Copyright (c) 2007 Alban Browaeys <prahal@yahoo.com> +# Copyright (c) 2008 Michael Bell <michael.bell@web.de> +# Copyright (c) 2008-2009 Bjoern Ricks <bjoern.ricks@googlemail.com> +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# + + +IF (GLIB2_LIBRARIES AND GLIB2_INCLUDE_DIRS ) + # in cache already + SET(GLIB2_FOUND TRUE) +ELSE (GLIB2_LIBRARIES AND GLIB2_INCLUDE_DIRS ) + + INCLUDE(FindPkgConfig) + + ## Glib + IF ( GLIB2_FIND_REQUIRED ) + SET( _pkgconfig_REQUIRED "REQUIRED" ) + ELSE ( GLIB2_FIND_REQUIRED ) + SET( _pkgconfig_REQUIRED "" ) + ENDIF ( GLIB2_FIND_REQUIRED ) + + IF ( GLIB2_MIN_VERSION ) + PKG_SEARCH_MODULE( GLIB2 ${_pkgconfig_REQUIRED} glib-2.0>=${GLIB2_MIN_VERSION} ) + ELSE ( GLIB2_MIN_VERSION ) + PKG_SEARCH_MODULE( GLIB2 ${_pkgconfig_REQUIRED} glib-2.0 ) + ENDIF ( GLIB2_MIN_VERSION ) + IF ( PKG_CONFIG_FOUND ) + IF ( GLIB2_FOUND ) + SET ( GLIB2_CORE_FOUND TRUE ) + ELSE ( GLIB2_FOUND ) + SET ( GLIB2_CORE_FOUND FALSE ) + ENDIF ( GLIB2_FOUND ) + ENDIF ( PKG_CONFIG_FOUND ) + + # Look for glib2 include dir and libraries w/o pkgconfig + IF ( NOT GLIB2_FOUND AND NOT PKG_CONFIG_FOUND ) + FIND_PATH( + _glibconfig_include_DIR + NAMES + glibconfig.h + PATHS + /opt/gnome/lib64 + /opt/gnome/lib + /opt/lib/ + /opt/local/lib + /sw/lib/ + /usr/lib64 + /usr/lib + /usr/local/include + ${CMAKE_LIBRARY_PATH} + PATH_SUFFIXES + glib-2.0/include + ) + + FIND_PATH( + _glib2_include_DIR + NAMES + glib.h + PATHS + /opt/gnome/include + /opt/local/include + /sw/include + /usr/include + /usr/local/include + PATH_SUFFIXES + glib-2.0 + ) + + #MESSAGE(STATUS "Glib headers: ${_glib2_include_DIR}") + + FIND_LIBRARY( + _glib2_link_DIR + NAMES + glib-2.0 + glib + PATHS + /opt/gnome/lib + /opt/local/lib + /sw/lib + /usr/lib + /usr/local/lib + ) + IF ( _glib2_include_DIR AND _glib2_link_DIR ) + SET ( _glib2_FOUND TRUE ) + ENDIF ( _glib2_include_DIR AND _glib2_link_DIR ) + + + IF ( _glib2_FOUND ) + SET ( GLIB2_INCLUDE_DIRS ${_glib2_include_DIR} ${_glibconfig_include_DIR} ) + SET ( GLIB2_LIBRARIES ${_glib2_link_DIR} ) + SET ( GLIB2_CORE_FOUND TRUE ) + ELSE ( _glib2_FOUND ) + SET ( GLIB2_CORE_FOUND FALSE ) + ENDIF ( _glib2_FOUND ) + + # Handle dependencies + # libintl + IF ( NOT LIBINTL_FOUND ) + FIND_PATH(LIBINTL_INCLUDE_DIR + NAMES + libintl.h + PATHS + /opt/gnome/include + /opt/local/include + /sw/include + /usr/include + /usr/local/include + ) + + FIND_LIBRARY(LIBINTL_LIBRARY + NAMES + intl + PATHS + /opt/gnome/lib + /opt/local/lib + /sw/lib + /usr/local/lib + /usr/lib + ) + + IF (LIBINTL_LIBRARY AND LIBINTL_INCLUDE_DIR) + SET (LIBINTL_FOUND TRUE) + ENDIF (LIBINTL_LIBRARY AND LIBINTL_INCLUDE_DIR) + ENDIF ( NOT LIBINTL_FOUND ) + + # libiconv + IF ( NOT LIBICONV_FOUND ) + FIND_PATH(LIBICONV_INCLUDE_DIR + NAMES + iconv.h + PATHS + /opt/gnome/include + /opt/local/include + /opt/local/include + /sw/include + /sw/include + /usr/local/include + /usr/include + PATH_SUFFIXES + glib-2.0 + ) + + FIND_LIBRARY(LIBICONV_LIBRARY + NAMES + iconv + PATHS + /opt/gnome/lib + /opt/local/lib + /sw/lib + /usr/lib + /usr/local/lib + ) + + IF (LIBICONV_LIBRARY AND LIBICONV_INCLUDE_DIR) + SET (LIBICONV_FOUND TRUE) + ENDIF (LIBICONV_LIBRARY AND LIBICONV_INCLUDE_DIR) + ENDIF ( NOT LIBICONV_FOUND ) + + IF (LIBINTL_FOUND) + SET (GLIB2_LIBRARIES ${GLIB2_LIBRARIES} ${LIBINTL_LIBRARY}) + SET (GLIB2_INCLUDE_DIRS ${GLIB2_INCLUDE_DIRS} ${LIBINTL_INCLUDE_DIR}) + ENDIF (LIBINTL_FOUND) + + IF (LIBICONV_FOUND) + SET (GLIB2_LIBRARIES ${GLIB2_LIBRARIES} ${LIBICONV_LIBRARY}) + SET (GLIB2_INCLUDE_DIRS ${GLIB2_INCLUDE_DIRS} ${LIBICONV_INCLUDE_DIR}) + ENDIF (LIBICONV_FOUND) + + ENDIF ( NOT GLIB2_FOUND AND NOT PKG_CONFIG_FOUND ) + ## + + IF (GLIB2_CORE_FOUND AND GLIB2_INCLUDE_DIRS AND GLIB2_LIBRARIES) + SET (GLIB2_FOUND TRUE) + ENDIF (GLIB2_CORE_FOUND AND GLIB2_INCLUDE_DIRS AND GLIB2_LIBRARIES) + + IF (GLIB2_FOUND) + IF (NOT GLIB2_FIND_QUIETLY) + MESSAGE (STATUS "Found GLib2: ${GLIB2_LIBRARIES} ${GLIB2_INCLUDE_DIRS}") + ENDIF (NOT GLIB2_FIND_QUIETLY) + ELSE (GLIB2_FOUND) + IF (GLIB2_FIND_REQUIRED) + MESSAGE (SEND_ERROR "Could not find GLib2") + ENDIF (GLIB2_FIND_REQUIRED) + ENDIF (GLIB2_FOUND) + + # show the GLIB2_INCLUDE_DIRS and GLIB2_LIBRARIES variables only in the advanced view + MARK_AS_ADVANCED(GLIB2_INCLUDE_DIRS GLIB2_LIBRARIES) + MARK_AS_ADVANCED(LIBICONV_INCLUDE_DIR LIBICONV_LIBRARY) + MARK_AS_ADVANCED(LIBINTL_INCLUDE_DIR LIBINTL_LIBRARY) + +ENDIF (GLIB2_LIBRARIES AND GLIB2_INCLUDE_DIRS) + +IF ( WIN32 ) + # include libiconv for win32 + IF ( NOT LIBICONV_FOUND ) + FIND_PATH(LIBICONV_INCLUDE_DIR iconv.h PATH_SUFFIXES glib-2.0) + + FIND_LIBRARY(LIBICONV_LIBRARY NAMES iconv) + + IF (LIBICONV_LIBRARY AND LIBICONV_INCLUDE_DIR) + SET (LIBICONV_FOUND TRUE) + ENDIF (LIBICONV_LIBRARY AND LIBICONV_INCLUDE_DIR) + ENDIF ( NOT LIBICONV_FOUND ) + IF (LIBICONV_FOUND) + SET (GLIB2_LIBRARIES ${GLIB2_LIBRARIES} ${LIBICONV_LIBRARY}) + SET (GLIB2_INCLUDE_DIRS ${GLIB2_INCLUDE_DIRS} ${LIBICONV_INCLUDE_DIR}) + ENDIF (LIBICONV_FOUND) +ENDIF ( WIN32 ) + +IF ( GLIB2_FOUND ) + # Check if system has a newer version of glib + # which supports g_regex_match_simple + INCLUDE( CheckIncludeFiles ) + SET( CMAKE_REQUIRED_INCLUDES ${GLIB2_INCLUDE_DIRS} ) + CHECK_INCLUDE_FILES ( glib/gregex.h HAVE_GLIB_GREGEX_H ) + CHECK_INCLUDE_FILES ( glib/gchecksum.h HAVE_GLIB_GCHECKSUM_H ) + # Reset CMAKE_REQUIRED_INCLUDES + SET( CMAKE_REQUIRED_INCLUDES "" ) +ENDIF( GLIB2_FOUND ) diff --git a/wireshark-plugin-magicolor/cmake/FindWireshark.cmake b/wireshark-plugin-magicolor/cmake/FindWireshark.cmake new file mode 100644 index 0000000..59497da --- /dev/null +++ b/wireshark-plugin-magicolor/cmake/FindWireshark.cmake @@ -0,0 +1,28 @@ +# +# Try to find the wireshark library and its includes +# +# This snippet sets the following variables: +# WIRESHARK_FOUND True if wireshark library got found +# WIRESHARK_INCLUDE_DIRS Location of the wireshark headers +# WIRESHARK_LIBRARIES List of libraries to use wireshark +# +# Copyright (c) 2011 Reinhold Kainhofer <reinhold@kainhofer.com> +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# + +# wireshark does not install its library with pkg-config information, +# so we need to manually find the libraries and headers + +FIND_PATH( WIRESHARK_INCLUDE_DIRS epan/column_info.h PATH_SUFFIXES wireshark ) +FIND_LIBRARY( WIRESHARK_LIBRARIES wireshark ) + +# Report results +IF ( WIRESHARK_LIBRARIES AND WIRESHARK_INCLUDE_DIRS ) + SET( WIRESHARK_FOUND 1 ) +ELSE ( WIRESHARK_LIBRARIES AND WIRESHARK_INCLUDE_DIRS ) + MESSAGE( SEND_ERROR "Could NOT find the wireshark library and headers" ) +ENDIF ( WIRESHARK_LIBRARIES AND WIRESHARK_INCLUDE_DIRS ) + diff --git a/wireshark-plugin-magicolor/cmake/UseMakeDissectorReg.cmake b/wireshark-plugin-magicolor/cmake/UseMakeDissectorReg.cmake new file mode 100644 index 0000000..e7e1a73 --- /dev/null +++ b/wireshark-plugin-magicolor/cmake/UseMakeDissectorReg.cmake @@ -0,0 +1,33 @@ +# +# $Id: UseMakeDissectorReg.cmake 33616 2010-07-22 12:18:36Z stig $ +# +MACRO(REGISTER_DISSECTOR_FILES _outputfile _registertype ) + # FIXME: Only the Python stuff has been implemented + # Make this into a MACRO, to avoid duplication with plugins/.../ + #register.c: $(plugin_src) $(ALL_DISSECTORS_SRC) $(top_srcdir)/tools/make-dissector-reg \ + # $(top_srcdir)/tools/make-dissector-reg.py + # @if test -n "$(PYTHON)"; then \ + # echo Making register.c with python ; \ + # $(PYTHON) $(top_srcdir)/tools/make-dissector-reg.py $(srcdir) \ + # dissectors $(ALL_DISSECTORS_SRC) ; \ + # else \ + # echo Making register.c with shell script ; \ + # $(top_srcdir)/tools/make-dissector-reg $(srcdir) \ + # dissectors $(plugin_src) $(ALL_DISSECTORS_SRC) ; \ + # fi + set( _sources ${ARGN} ) + ADD_CUSTOM_COMMAND( + OUTPUT + ${_outputfile} + COMMAND ${PYTHON_EXECUTABLE} + ${CMAKE_SOURCE_DIR}/tools/make-dissector-reg.py + ${CMAKE_CURRENT_SOURCE_DIR} + ${_registertype} + ${_sources} + DEPENDS + ${_sources} + ${CMAKE_SOURCE_DIR}/tools/make-dissector-reg + ${CMAKE_SOURCE_DIR}/tools/make-dissector-reg.py + ) +ENDMACRO(REGISTER_DISSECTOR_FILES) + diff --git a/wireshark-plugin-magicolor/moduleinfo.h b/wireshark-plugin-magicolor/moduleinfo.h new file mode 100644 index 0000000..12c7e51 --- /dev/null +++ b/wireshark-plugin-magicolor/moduleinfo.h @@ -0,0 +1,17 @@ +/* Included *after* config.h, in order to re-define these macros */ + +#ifdef PACKAGE +#undef PACKAGE +#endif + +/* Name of package */ +#define PACKAGE "magicolor" + + +#ifdef VERSION +#undef VERSION +#endif + +/* Version number of package */ +#define VERSION "0.0.1" + diff --git a/wireshark-plugin-magicolor/packet-bizhub.c b/wireshark-plugin-magicolor/packet-bizhub.c new file mode 100644 index 0000000..e69de29 diff --git a/wireshark-plugin-magicolor/packet-magicolor.c b/wireshark-plugin-magicolor/packet-magicolor.c new file mode 100644 index 0000000..f916521 --- /dev/null +++ b/wireshark-plugin-magicolor/packet-magicolor.c @@ -0,0 +1,244 @@ +/* packet-magicolor.c + * Routines for HP 2101nw wireless USB print server + * packet disassembly + * Copyright (c) 2011 Reinhold Kainhofer <reinhold@kainhofer.com> + * + * Base on packet-interlink.c: + * Routines for Interlink protocol packet disassembly + * By Uwe Girlich <uwe.girlich@philosys.de> + * Copyright 2010 Uwe Girlich + * + * $Id: packet-magicolor.c 35224 2010-12-20 05:35:29Z guy $ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <config.h> +#include <epan/packet.h> + +#define MAGICOLOR_PORT 4567 + +static int proto_magicolor = -1; +static gint ett_magicolor = -1; + +/* Variables for magicolor packets */ +static int hf_magicolor_cmdtype = -1; +static int hf_magicolor_netcommand = -1; +static int hf_magicolor_netstatus = -1; +static int hf_magicolor_netusbid = -1; + +static int hf_magicolor_command = -1; +static int hf_magicolor_arglen = -1; +static int hf_magicolor_arg = -1; +static int hf_magicolor_final = -1; + + +/* Displayed names of commands */ +static const value_string commandtypes[] = { + { 0x03, "Scanner command" }, + { 0x04, "Network communication wrapper command" }, + { 0x00, NULL } +}; + +static const value_string netwrapper_commands[] = { + { 0x00, "Welcome by scanner" }, + { 0x01, "Response by PC" }, + { 0x02, "ACK by Scanner (valid USB-ID)" }, + { 0x03, "BYE sent from PC to Scanner" }, + { 0x00, NULL } +}; + +static const value_string scanner_commands[] = { + { 0x08, "Start scan" }, + { 0x09, "Poll for error" }, + { 0x0a, "Stop scan / cleanup" }, + { 0x0b, "Query image parameters" }, + { 0x0c, "Scan settings" }, + { 0x0d, "Get status" }, + { 0x0e, "Read data" }, + { 0x0f, "Unknown (Get buttons?)" }, + { 0x12, "End of scan" }, + { 0x00, NULL } +}; + +static const value_string netwrapper_status[] = { + { 0x00, "OK" }, + { 0x01, "NOT OK" }, + { 0x00, NULL } +}; + +static int +dissect_magicolor (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) +{ + gint offset = 0; + guint8 cmdtype = tvb_get_guint8 (tvb, 0); + + /* TODO: Some sanity checking to determine whether the packet is really + * a magicolor communication packet */ + /* TODO: How do we detect answers by the device? They don't have any + * custom header or standardized format! */ +/* if (cmdtype != 0x03 && cmdtype != 0x04) + return 0;*/ + + + col_set_str (pinfo-> cinfo, COL_PROTOCOL, "KONICA MINOLTA magicolor scanner communication"); + col_clear (pinfo->cinfo, COL_INFO); + + if (tree) { + proto_item *ti = NULL; + proto_item *magicolor_tree = NULL; + guint8 command = tvb_get_guint8 (tvb, 1); + + ti = proto_tree_add_item (tree, proto_magicolor, tvb, 0, -1, ENC_NA); + magicolor_tree = proto_item_add_subtree (ti, ett_magicolor); + proto_tree_add_item (magicolor_tree, hf_magicolor_cmdtype, tvb, offset, 1, ENC_LITTLE_ENDIAN); + offset += 1; + if (cmdtype == 0x03) { + proto_tree_add_item (magicolor_tree, hf_magicolor_command, tvb, offset, 1, ENC_LITTLE_ENDIAN); + offset += 1; + } else if (cmdtype == 0x04) { + proto_tree_add_item (magicolor_tree, hf_magicolor_netcommand, tvb, offset, 1, ENC_LITTLE_ENDIAN); + offset += 1; + } else { + return offset; + } + + /* For 0x04 commands, use the explicit knowledge about cmd args! */ + if (cmdtype == 0x04) { + col_add_fstr (pinfo->cinfo, COL_INFO, "Netwrapper cmd (%s), status=%s", + match_strval (command, netwrapper_commands), + match_strval (tvb_get_guint8 (tvb, 2), netwrapper_status)); + /* First byte is always status */ + proto_tree_add_item (magicolor_tree, hf_magicolor_netstatus, tvb, offset, 1, ENC_LITTLE_ENDIAN); + offset += 1; + switch (command) { + case 0x01: + proto_tree_add_item (magicolor_tree, hf_magicolor_netusbid, tvb, offset, 2, ENC_LITTLE_ENDIAN); + offset += 2; + break; + case 0x00: /* All other commands don't have any additional parameters */ + case 0x02: + case 0x03: + break; + } + return offset; + } + + if (cmdtype == 0x03) { + guint32 arglen = tvb_get_letohl (tvb, 2); + col_add_fstr (pinfo->cinfo, COL_INFO, "Scanner cmd (%s), arglen=%d", + match_strval (command, scanner_commands), arglen); + proto_tree_add_item (magicolor_tree, hf_magicolor_arglen, tvb, offset, 4, ENC_LITTLE_ENDIAN); + offset += 4; + proto_tree_add_item (magicolor_tree, hf_magicolor_arg, tvb, offset, arglen, ENC_LITTLE_ENDIAN); + offset += arglen; + switch (command) { + case 0x08: + case 0x09: + case 0x0a: + case 0x0b: + case 0x0c: + case 0x0d: + case 0x0e: + case 0x0f: + case 0x12: + case 0x10: + break; + } + proto_tree_add_item (magicolor_tree, hf_magicolor_final, tvb, offset, 4, ENC_LITTLE_ENDIAN); + offset += 4; + + /* TODO: Loop until we encounter a 0x00000000 arglen value, don't hardcode just one argument! */ +/* return tvb_length(tvb); */ + return offset; + } + } + return 0; +} +void +proto_register_magicolor(void) +{ + static hf_register_info hf_magicolor[] = { + { &hf_magicolor_cmdtype, + { "Communication type", "magicolor.type", + FT_UINT8, BASE_HEX, + VALS(commandtypes), 0x0, + NULL, HFILL }, + }, + { &hf_magicolor_netcommand, + { "Netwrapper command", "magicolor.netwrapper", + FT_UINT8, BASE_HEX, + VALS (netwrapper_commands), 0x0, + NULL, HFILL }, + }, + { &hf_magicolor_netstatus, + { "Connect status", "magicolor.netwrapper.status", + FT_UINT8, BASE_HEX, + VALS (netwrapper_status), 0x0, + NULL, HFILL }, + }, + { &hf_magicolor_netusbid, + { "USB id", "magicolor.netwrapper.usb_id", + FT_UINT16, BASE_HEX, + NULL, 0x0, + NULL, HFILL }, + }, + + { &hf_magicolor_command, + { "Command", "magicolor.command", + FT_UINT8, BASE_HEX, + VALS (scanner_commands), 0x0, + NULL, HFILL }, + }, + { &hf_magicolor_arglen, + { "Argument length", "magicolor.arglen", + FT_UINT32, BASE_DEC, + NULL, 0x0, + NULL, HFILL }, + }, + { &hf_magicolor_arg, + { "Argument", "magicolor.arg", + FT_BYTES, BASE_NONE, + NULL, 0x0, + NULL, HFILL }, + }, + { &hf_magicolor_final, + { "Final delimiter", "magicolor.final", + FT_UINT32, BASE_HEX, + NULL, 0x0, + NULL, HFILL }, + }, + }; + static gint *ett_magicolor_arr[] = { /* protocol subtree array */ + &ett_magicolor + }; + proto_magicolor = proto_register_protocol( + "KONICA MINOLTA Magicolor scanner communication", "magicolor", "magicolor"); + proto_register_field_array (proto_magicolor, hf_magicolor, array_length (hf_magicolor)); + proto_register_subtree_array (ett_magicolor_arr, array_length (ett_magicolor_arr)); +} + +void +proto_reg_handoff_magicolor_magicolor(void) +{ + static dissector_handle_t magicolor_handle; + magicolor_handle = new_create_dissector_handle (dissect_magicolor, proto_magicolor); + dissector_add_uint ("tcp.port", MAGICOLOR_PORT, magicolor_handle); +} + diff --git a/wireshark-plugin-magicolor/tools/make-dissector-reg b/wireshark-plugin-magicolor/tools/make-dissector-reg new file mode 100755 index 0000000..d2efa7c --- /dev/null +++ b/wireshark-plugin-magicolor/tools/make-dissector-reg @@ -0,0 +1,186 @@ +#! /bin/sh + +# +# $Id: make-dissector-reg 21716 2007-05-07 17:55:42Z gal $ +# + +# +# The first argument is the directory in which the source files live. +# +srcdir="$1" +shift + +# +# The second argument is either "plugin" or "dissectors"; if it's +# "plugin", we build a plugin.c for a plugin, and if it's +# "dissectors", we build a register.c for libwireshark. +# +registertype="$1" +shift +if [ "$registertype" = plugin ] +then + outfile="plugin.c" +elif [ "$registertype" = dissectors ] +then + outfile="register.c" +else + echo "Unknown output type '$registertype'" 1>&2 + exit 1 +fi + +# +# All subsequent arguments are the files to scan. +# +rm -f ${outfile}-tmp +echo '/* Do not modify this file. */' >${outfile}-tmp +echo '/* It is created automatically by the Makefile. */'>>${outfile}-tmp +if [ "$registertype" = plugin ] +then + cat <<"EOF" >>${outfile}-tmp +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <gmodule.h> + +#include "moduleinfo.h" + +#ifndef ENABLE_STATIC +G_MODULE_EXPORT const gchar version[] = VERSION; + +/* Start the functions we need for the plugin stuff */ + +G_MODULE_EXPORT void +plugin_register (void) +{ +EOF +# +# Build code to call all the protocol registration routines. +# +for f in "$@" +do + if [ -f $f ] + then + srcfile=$f + else + srcfile=$srcdir/$f + fi + grep '^proto_register_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';' +done | sed -e 's/^.*://' -e 's/^\([a-z_0-9A-Z]*\).*/ {extern void \1 (void); \1 ();}/' >>${outfile}-tmp +for f in "$@" +do + if [ -f $f ] + then + srcfile=$f + else + srcfile=$srcdir/$f + fi + grep '^void proto_register_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';' +done | sed -e 's/^.*://' -e 's/^void \([a-z_0-9A-Z]*\).*/ {extern void \1 (void); \1 ();}/' >>${outfile}-tmp +else + cat <<"EOF" >>${outfile}-tmp +#include "register.h" +void +register_all_protocols(register_cb cb, gpointer client_data) +{ +EOF +# +# Build code to call all the protocol registration routines. +# +for f in "$@" +do + if [ -f $f ] + then + srcfile=$f + else + srcfile=$srcdir/$f + fi + grep '^proto_register_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';' +done | sed -e 's/^.*://' -e 's/^\([a-z_0-9A-Z]*\).*/ {extern void \1 (void); if(cb) (*cb)(RA_REGISTER, \"\1\", client_data); \1 ();}/' >>${outfile}-tmp +for f in "$@" +do + if [ -f $f ] + then + srcfile=$f + else + srcfile=$srcdir/$f + fi + grep '^void proto_register_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';' +done | sed -e 's/^.*://' -e 's/^void \([a-z_0-9A-Z]*\).*/ {extern void \1 (void); if(cb) (*cb)(RA_REGISTER, \"\1\", client_data); \1 ();}/' >>${outfile}-tmp + +fi +echo '}' >>${outfile}-tmp + + +# +# Build code to call all the protocol handoff registration routines. +# +if [ "$registertype" = plugin ] +then + cat <<"EOF" >>${outfile}-tmp +G_MODULE_EXPORT void +plugin_reg_handoff(void) +{ +EOF +for f in "$@" +do + if [ -f $f ] + then + srcfile=$f + else + srcfile=$srcdir/$f + fi + grep '^proto_reg_handoff_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';' +done | sed -e 's/^.*://' -e 's/^\([a-z_0-9A-Z]*\).*/ {extern void \1 (void); \1 ();}/' >>${outfile}-tmp +for f in "$@" +do + if [ -f $f ] + then + srcfile=$f + else + srcfile=$srcdir/$f + fi + grep '^void proto_reg_handoff_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';' +done | sed -e 's/^.*://' -e 's/^void \([a-z_0-9A-Z]*\).*/ {extern void \1 (void); \1 ();}/' >>${outfile}-tmp +else + cat <<"EOF" >>${outfile}-tmp +void +register_all_protocol_handoffs(register_cb cb, gpointer client_data) +{ +EOF +for f in "$@" +do + if [ -f $f ] + then + srcfile=$f + else + srcfile=$srcdir/$f + fi + grep '^proto_reg_handoff_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';' +done | sed -e 's/^.*://' -e 's/^\([a-z_0-9A-Z]*\).*/ {extern void \1 (void); if(cb) (*cb)(RA_HANDOFF, \"\1\", client_data); \1 ();}/' >>${outfile}-tmp +for f in "$@" +do + if [ -f $f ] + then + srcfile=$f + else + srcfile=$srcdir/$f + fi + grep '^void proto_reg_handoff_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';' +done | sed -e 's/^.*://' -e 's/^void \([a-z_0-9A-Z]*\).*/ {extern void \1 (void); if(cb) (*cb)(RA_HANDOFF, \"\1\", client_data); \1 ();}/' >>${outfile}-tmp +fi +echo '}' >>${outfile}-tmp +if [ "$registertype" = plugin ] +then + echo '#endif' >>${outfile}-tmp +else + cat <<"EOF" >>${outfile}-tmp +gulong register_count(void) +{ +EOF + proto_regs=`grep RA_REGISTER ${outfile}-tmp | wc -l` + handoff_regs=`grep RA_HANDOFF ${outfile}-tmp | wc -l` + echo " return $proto_regs + $handoff_regs;" >>${outfile}-tmp + echo '}' >>${outfile}-tmp +fi +mv ${outfile}-tmp ${outfile} diff --git a/wireshark-plugin-magicolor/tools/make-dissector-reg.py b/wireshark-plugin-magicolor/tools/make-dissector-reg.py new file mode 100755 index 0000000..4497290 --- /dev/null +++ b/wireshark-plugin-magicolor/tools/make-dissector-reg.py @@ -0,0 +1,305 @@ +#!/usr/bin/env python +# +# Looks for registration routines in the protocol dissectors, +# and assembles C code to call all the routines. +# +# This is a Python version of the make-reg-dotc shell script. +# Running the shell script on Win32 is very very slow because of +# all the process-launching that goes on --- multiple greps and +# seds for each input file. I wrote this python version so that +# less processes would have to be started. +# +# $Id: make-dissector-reg.py 30447 2009-10-09 20:47:18Z krj $ + +import os +import sys +import re +import pickle +from stat import * + +VERSION_KEY = '_VERSION' +CUR_VERSION = '$Id: make-dissector-reg.py 30447 2009-10-09 20:47:18Z krj $' + +# +# The first argument is the directory in which the source files live. +# +srcdir = sys.argv[1] + +# +# The second argument is either "plugin" or "dissectors"; if it's +# "plugin", we build a plugin.c for a plugin, and if it's +# "dissectors", we build a register.c for libwireshark. +# +registertype = sys.argv[2] +if registertype == "plugin" or registertype == "plugin_wtap": + tmp_filename = "plugin.c-tmp" + final_filename = "plugin.c" + cache_filename = None + preamble = """\ +/* + * Do not modify this file. + * + * It is created automatically by Makefile or Makefile.nmake. + */ +""" +elif registertype == "dissectors": + tmp_filename = "register.c-tmp" + final_filename = "register.c" + cache_filename = "register-cache.pkl" + preamble = """\ +/* + * Do not modify this file. + * + * It is created automatically by the "register.c" target in + * epan/dissectors/Makefile or Makefile.nmake using information in + * epan/dissectors/register-cache.pkl. + * + * You can force this file to be regenerated completely by deleting + * it along with epan/dissectors/register-cache.pkl. + */ +""" +else: + print "Unknown output type '%s'" % registertype + sys.exit(1) + + +# +# All subsequent arguments are the files to scan. +# +files = sys.argv[3:] + +# Create the proper list of filenames +filenames = [] +for file in files: + if os.path.isfile(file): + filenames.append(file) + else: + filenames.append(os.path.join(srcdir, file)) + +if len(filenames) < 1: + print "No files found" + sys.exit(1) + + +# Look through all files, applying the regex to each line. +# If the pattern matches, save the "symbol" section to the +# appropriate array. +regs = { + 'proto_reg': [], + 'handoff_reg': [], + 'wtap_register': [], + } + +# For those that don't know Python, r"" indicates a raw string, +# devoid of Python escapes. +proto_regex0 = r"^(?P<symbol>proto_register_[_A-Za-z0-9]+)\s*\([^;]+$" +proto_regex1 = r"void\s+(?P<symbol>proto_register_[_A-Za-z0-9]+)\s*\([^;]+$" + +handoff_regex0 = r"^(?P<symbol>proto_reg_handoff_[_A-Za-z0-9]+)\s*\([^;]+$" +handoff_regex1 = r"void\s+(?P<symbol>proto_reg_handoff_[_A-Za-z0-9]+)\s*\([^;]+$" + +wtap_reg_regex0 = r"^(?P<symbol>wtap_register_[_A-Za-z0-9]+)\s*\([^;]+$" +wtap_reg_regex1 = r"void\s+(?P<symbol>wtap_register_[_A-Za-z0-9]+)\s*\([^;]+$" + +# This table drives the pattern-matching and symbol-harvesting +patterns = [ + ( 'proto_reg', re.compile(proto_regex0) ), + ( 'proto_reg', re.compile(proto_regex1) ), + ( 'handoff_reg', re.compile(handoff_regex0) ), + ( 'handoff_reg', re.compile(handoff_regex1) ), + ( 'wtap_register', re.compile(wtap_reg_regex0) ), + ( 'wtap_register', re.compile(wtap_reg_regex1) ), + ] + +# Open our registration symbol cache +cache = None +if cache_filename: + try: + cache_file = open(cache_filename, 'rb') + cache = pickle.load(cache_file) + cache_file.close() + if not cache.has_key(VERSION_KEY) or cache[VERSION_KEY] != CUR_VERSION: + cache = {VERSION_KEY: CUR_VERSION} + except: + cache = {VERSION_KEY: CUR_VERSION} + +# Grep +for filename in filenames: + file = open(filename) + cur_mtime = os.fstat(file.fileno())[ST_MTIME] + if cache and cache.has_key(filename): + cdict = cache[filename] + if cur_mtime == cdict['mtime']: +# print "Pulling %s from cache" % (filename) + regs['proto_reg'].extend(cdict['proto_reg']) + regs['handoff_reg'].extend(cdict['handoff_reg']) + regs['wtap_register'].extend(cdict['wtap_register']) + file.close() + continue + # We don't have a cache entry + if cache is not None: + cache[filename] = { + 'mtime': cur_mtime, + 'proto_reg': [], + 'handoff_reg': [], + 'wtap_register': [], + } +# print "Searching %s" % (filename) + for line in file.readlines(): + for action in patterns: + regex = action[1] + match = regex.search(line) + if match: + symbol = match.group("symbol") + sym_type = action[0] + regs[sym_type].append(symbol) + if cache is not None: +# print "Caching %s for %s: %s" % (sym_type, filename, symbol) + cache[filename][sym_type].append(symbol) + file.close() + +if cache is not None and cache_filename is not None: + cache_file = open(cache_filename, 'wb') + pickle.dump(cache, cache_file) + cache_file.close() + +# Make sure we actually processed something +if len(regs['proto_reg']) < 1: + print "No protocol registrations found" + sys.exit(1) + +# Sort the lists to make them pretty +regs['proto_reg'].sort() +regs['handoff_reg'].sort() +regs['wtap_register'].sort() + +reg_code = open(tmp_filename, "w") + +reg_code.write(preamble) + +# Make the routine to register all protocols +if registertype == "plugin" or registertype == "plugin_wtap": + reg_code.write(""" +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <gmodule.h> + +#include "moduleinfo.h" + +#ifndef ENABLE_STATIC +G_MODULE_EXPORT const gchar version[] = VERSION; + +/* Start the functions we need for the plugin stuff */ + +G_MODULE_EXPORT void +plugin_register (void) +{ +"""); +else: + reg_code.write(""" +#include "register.h" +void +register_all_protocols(register_cb cb, gpointer client_data) +{ +"""); + +for symbol in regs['proto_reg']: + if registertype == "plugin" or registertype == "plugin_wtap": + line = " {extern void %s (void); %s ();}\n" % (symbol, symbol) + else: + line = " {extern void %s (void); if(cb) (*cb)(RA_REGISTER, \"%s\", client_data); %s ();}\n" % (symbol, symbol, symbol) + reg_code.write(line) + +reg_code.write("}\n") + + +# Make the routine to register all protocol handoffs +if registertype == "plugin" or registertype == "plugin_wtap": + reg_code.write(""" +G_MODULE_EXPORT void +plugin_reg_handoff(void) +{ +"""); +else: + reg_code.write(""" +void +register_all_protocol_handoffs(register_cb cb, gpointer client_data) +{ +"""); + +for symbol in regs['handoff_reg']: + if registertype == "plugin" or registertype == "plugin_wtap": + line = " {extern void %s (void); %s ();}\n" % (symbol, symbol) + else: + line = " {extern void %s (void); if(cb) (*cb)(RA_HANDOFF, \"%s\", client_data); %s ();}\n" % (symbol, symbol, symbol) + reg_code.write(line) + +reg_code.write("}\n") + +if registertype == "plugin": + reg_code.write("#endif\n"); +elif registertype == "plugin_wtap": + reg_code.write(""" +G_MODULE_EXPORT void +register_wtap_module(void) +{ +"""); + + for symbol in regs['wtap_register']: + line = " {extern void %s (void); %s ();}\n" % (symbol, symbol) + reg_code.write(line) + + reg_code.write("}\n"); + reg_code.write("#endif\n"); +else: + reg_code.write(""" +static gulong proto_reg_count(void) +{ +"""); + + line = " return %d;\n" % len(regs['proto_reg']) + reg_code.write(line) + + reg_code.write(""" +} +"""); + reg_code.write(""" +static gulong handoff_reg_count(void) +{ +"""); + + line = " return %d;\n" % len(regs['handoff_reg']) + reg_code.write(line) + + reg_code.write(""" +} +"""); + reg_code.write(""" +gulong register_count(void) +{ +"""); + + line = " return proto_reg_count() + handoff_reg_count();" + reg_code.write(line) + + reg_code.write(""" +}\n +"""); + + +# Close the file +reg_code.close() + +# Remove the old final_file if it exists. +try: + os.stat(final_filename) + os.remove(final_filename) +except OSError: + pass + +# Move from tmp file to final file +os.rename(tmp_filename, final_filename) + + -- GitLab