首页 > 其他分享 >wireshark集成Backward-cpp编译

wireshark集成Backward-cpp编译

时间:2023-02-26 20:23:33浏览次数:57  
标签:CMakeLists backward proto cpp Backward epan wireshark

原文地址:https://www.cnblogs.com/liqinglucky/p/backward-in-wireshark.html

在之前的文章中已经介绍过ubuntu系统wireshark源码编译与安装Backward-cpp: Segmentation fault时打印backtrace。现在对wireshark的CMakeLists.txt中添加backward-cpp编译。测试wireshark程序中打印backtrace。

一 添加Backward-cpp

改动很简单,只需在wireshark的CMakeLists.txt中添加backward-cpp编译。见C程序集成Backward-cpp使用示例

CMakeLists.txt的修改

include(FetchContent)
FetchContent_Declare(backward GIT_REPOSITORY https://github.com/bombela/backward-cpp  GIT_TAG v1.6) 
FetchContent_MakeAvailable(backward)

add_executable(wireshark WIN32 MACOSX_BUNDLE ${wireshark_FILES} ${EXTRA_BUNDLE_FILES} ${BACKWARD_ENABLE}) 
add_backward(${PROJECT_NAME})

git diff如下

wireshark-4.0.2# ls
CMakeLists.txt                  

wireshark-4.0.2# git diff
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 092dc7b..f368142 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2598,8 +2599,16 @@ if(BUILD_wireshark AND QT_FOUND)
                ${SPEEXDSP_LIBRARIES}
                ${MINIZIP_LIBRARIES}
        )
+include(FetchContent)
+
+FetchContent_Declare(backward
+        GIT_REPOSITORY https://github.com/bombela/backward-cpp
+        GIT_TAG v1.6)
+FetchContent_MakeAvailable(backward)

-       add_executable(wireshark WIN32 MACOSX_BUNDLE ${wireshark_FILES} ${EXTRA_BUNDLE_FILES})
+       add_executable(wireshark WIN32 MACOSX_BUNDLE ${wireshark_FILES} ${EXTRA_BUNDLE_FILES} ${BACKWARD_ENABLE})
+       add_backward(${PROJECT_NAME})
+       message("project name:" ${PROJECT_NAME})

为了方便测试,在代码中故意访问空指针使程序产生crash。

epan/proto.c的修改

static void
proto_cleanup_base(void)
{
	protocol_t *protocol=NULL;
	header_field_info *hfinfo;
    printf("%s %u\n", __FUNCTION__, protocol->proto_id);   //访问空指针

接下来编译看使用效果。wireshark编译需要10分钟左右。

二 运行测试

在wireshark源代码中加了测试代码后,直接启动wireshark就可以看到效果。

测试如下:

wireshark-4.0.2/build# run/wireshark
Stack trace (most recent call last):
#6    Object "", at 0xffffffffffffffff, in
#5    Object "/wireshark-4.0.2/build/run/wireshark", at 0x5575765bb3ad, in _start
#4    Source "../csu/libc-start.c", line 308, in __libc_start_main [0x7fe2bee83082]
#3    Source "/wireshark-4.0.2/ui/qt/main.cpp", line 738, in main [0x5575765b7e6c]
        735:        "-G" flag, as the "-G" flag dumps information registered by the
        736:        dissectors, and we must do it before we read the preferences, in
        737:        case any dissectors register preferences. */
      > 738:     if (!epan_init(splash_update, NULL, TRUE)) {
        739:         SimpleDialog::displayQueuedMessages(main_w);
        740:         ret_val = INIT_FAILED;
        741:         goto clean_exit;
#2    Source "/wireshark-4.0.2/epan/epan.c", line 315, in epan_init [0x7fe2c2d8e2ba]
        312:            reassembly_tables_init();
        313:         conversation_filters_init();
        314:            g_slist_foreach(epan_plugins, epan_plugin_init, NULL);
      > 315:            proto_init(epan_plugin_register_all_procotols, epan_plugin_register_all_handoffs, cb, client_data);
        316:            g_slist_foreach(epan_plugins, epan_plugin_register_all_tap_listeners, NULL);
        317:            packet_cache_proto_handles();
        318:            dfilter_init();
#1    Source "/wireshark-4.0.2/epan/proto.c", line 543, in proto_init [0x7fe2c2dc8898]
        540:       register_cb cb,
        541:       gpointer client_data)
        542: {
      > 543:    proto_cleanup_base();
        544:
        545:    proto_names        = g_hash_table_new(g_str_hash, g_str_equal);
        546:    proto_short_names  = g_hash_table_new(g_str_hash, g_str_equal);
#0    Source "/wireshark-4.0.2/epan/proto.c", line 630, in proto_cleanup_base [0x7fe2c2dae200]
        627: {
        628:    protocol_t *protocol=NULL;
        629:    header_field_info *hfinfo;
      > 630:     printf("%s %u\n", __FUNCTION__, protocol->proto_id);
        631:
        632:    /* Free the abbrev/ID hash table */
        633:    if (gpa_name_map) {
Segmentation fault (Address not mapped to object [0x20])
Segmentation fault

Segmentation fault打印出的backtrace已经带了代码段与行号这些详细信息。集成backward-cpp成功!

标签:CMakeLists,backward,proto,cpp,Backward,epan,wireshark
From: https://www.cnblogs.com/liqinglucky/p/backward-in-wireshark.html

相关文章