2023课设学习内容
Wireshark插件编写学习笔记
1. 我的插件选择
在我开始编写Wireshark插件之前,首先需要明确我的插件是属于Dissectors还是Tap。我需要思考插件的目标:是解析特定协议还是在数据包处理流程中执行某些操作。根据需求,我选择了Dissectors作为我的插件类型。
2. 插件编写流程
a. 插件代码编写
i. Dissector
#include "packet.h"
#include "proto.h"
#include "tvbuff.h"
static dissector_handle_t my_dissector;
void dissect_my_protocol(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
// 解析协议的逻辑
// 使用 proto_tree_add_item 等函数添加解析结果到解析树中
}
void my_dissector_init(void) {
my_dissector = create_dissector_handle(dissect_my_protocol, proto_my_protocol);
dissector_add("my_protocol", my_dissector);
}
void my_dissector_cleanup(void) {
dissector_delete(my_dissector);
}
#ifndef ENABLE_STATIC
void plugin_register(void) {
my_dissector_init();
}
void plugin_unregister(void) {
my_dissector_cleanup();
}
#endif
ii. Tap
#include "packet.h"
#include "proto.h"
void tap_my_protocol(packet_info *pinfo, epan_dissect_t *edt, void *userdata) {
// 在数据包处理前或后执行的逻辑
}
void my_tap_init(void) {
register_tap_listener(tap_my_protocol, NULL);
}
void my_tap_cleanup(void) {
remove_tap_listener(tap_my_protocol, NULL);
}
#ifndef ENABLE_STATIC
void plugin_register(void) {
my_tap_init();
}
void plugin_unregister(void) {
my_tap_cleanup();
}
#endif
b. Wireshark API的运用
深入了解Wireshark API是插件编写的关键。我需要熟悉epan/packet.h中的tvbuff_t、proto_tree等结构和函数,以正确地解析和显示协议信息。
3. 编译插件
插件的编译需要使用Wireshark提供的插件编译工具,例如make-dissector-reg。这一步骤是确保插件能够在Wireshark中正常运行的重要环节。
4. 加载和调试插件
将编译好的插件复制到Wireshark插件目录,或通过Wireshark设置加载。为了确保插件的正确性,我需要使用Wireshark自带的调试工具或GDB等工具进行调试。
5. 知识点总结
- Wireshark插件的选择,我需要明确插件类型,是Dissectors还是Tap。
- 插件编写流程,包括选择插件类型、编写插件代码(Dissector或Tap)。
- Wireshark API的理解,特别是
tvbuff_t、proto_tree等结构和函数。 - 插件的编译,使用Wireshark提供的插件编译工具。
- 插件的加载和调试,将插件复制到Wireshark插件目录,通过Wireshark设置加载,并使用调试工具进行调试。这是确保插件正确性的重要步骤。
posted on 2023-11-17 11:47 20211406张顺扬 阅读(35) 评论(0) 收藏 举报
浙公网安备 33010602011771号