📄 packet-gryphon.c
字号:
offset += 2; for (i = 1; i <= count; i++) { item = proto_tree_add_text(pt, tvb, offset, 112, "Program %d", i); tree = proto_item_add_subtree (item, ett_gryphon_pgm_list); proto_tree_add_text(tree, tvb, offset, 32, "Name: %.32s", tvb_get_ptr(tvb, offset, 32)); offset += 32; proto_tree_add_text(tree, tvb, offset, 80, "Description: %.80s", tvb_get_ptr(tvb, offset, 80)); offset += 80; } return offset;}static intcmd_start(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){ char string[120]; gint length; offset = cmd_delete(tvb, offset, src, msglen, pt); length = tvb_get_nstringz0(tvb, offset, 120, string) + 1; proto_tree_add_text(pt, tvb, offset, length, "Arguments: %s", string); offset += length; length = 3 - (length + 3) % 4; if (length) { proto_tree_add_text(pt, tvb, offset, length, "padding"); offset += length; } return offset;}static intresp_start(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){ proto_tree_add_text(pt, tvb, offset, 1, "Channel (Client) number: %u", tvb_get_guint8(tvb, offset)); proto_tree_add_text(pt, tvb, offset+1, 3, "reserved"); offset += 4; return offset;}static intresp_status(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){ proto_item *item; proto_tree *tree; unsigned int i, copies, length; copies = tvb_get_guint8(tvb, offset); item = proto_tree_add_text(pt, tvb, offset, 1, "Number of running copies: %d", copies); tree = proto_item_add_subtree (item, ett_gryphon_pgm_status); offset += 1; if (copies) { for (i = 1; i <= copies; i++) { proto_tree_add_text(tree, tvb, offset, 1, "Program %d channel (client) number %u", i, tvb_get_guint8(tvb, offset)); offset += 1; } } length = 3 - (copies + 1 + 3) % 4; if (length) { proto_tree_add_text(pt, tvb, offset, length, "padding"); offset += length; } return offset;}static intcmd_options(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){ proto_item *item; proto_tree *tree; unsigned int i, size, padding, option, option_length, option_value; unsigned char *string, *string1; item = proto_tree_add_text(pt, tvb, offset, 1, "Handle: %u", tvb_get_guint8(tvb, offset)); item = proto_tree_add_text(pt, tvb, offset+1, 3, "reserved"); offset += 4; msglen -= 4; for (i = 1; msglen > 0; i++) { option_length = tvb_get_guint8(tvb, offset+1); size = option_length + 2; padding = 3 - ((size + 3) %4); item = proto_tree_add_text(pt, tvb, offset, size + padding, "Option number %d", i); tree = proto_item_add_subtree (item, ett_gryphon_pgm_options); option = tvb_get_guint8(tvb, offset); switch (option_length) { case 1: option_value = tvb_get_guint8(tvb, offset+2); break; case 2: option_value = tvb_get_ntohs(tvb, offset+2); break; case 4: option_value = tvb_get_ntohl(tvb, offset+2); break; default: option_value = 0; } string = "unknown option"; string1 = "unknown option data"; switch (option) { case PGM_CONV: string = "Type of data in the file"; switch (option_value) { case PGM_BIN: string1 = "Binary - Don't modify"; break; case PGM_ASCII: string1 = "ASCII - Remove CR's"; break; } break; case PGM_TYPE: string = "Type of file"; switch (option_value) { case PGM_PGM: string1 = "Executable"; break; case PGM_DATA: string1 = "Data"; break; } break; } proto_tree_add_text(tree, tvb, offset, 1, "%s", string); proto_tree_add_text(tree, tvb, offset+2, option_length, "%s", string1); if (padding) proto_tree_add_text(tree, tvb, offset+option_length+2, padding, "padding"); offset += size + padding; msglen -= size + padding; } return offset;}static intcmd_files(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){ u_char *which; if (tvb_get_guint8(tvb, offset) == 0) which = "First group of names"; else which = "Subsequent group of names"; proto_tree_add_text(pt, tvb, offset, 1, "%s", which); proto_tree_add_text(pt, tvb, offset+1, msglen-1, "Directory: %.*s", msglen-1, tvb_get_ptr(tvb, offset+1, msglen-1)); offset += msglen; return offset;}static intresp_files(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){ u_char *flag; flag = tvb_get_guint8(tvb, offset) ? "Yes": "No"; proto_tree_add_text(pt, tvb, offset, 1, "More filenames to return: %s", flag); proto_tree_add_text(pt, tvb, offset+1, msglen-1, "File and directory names"); offset += msglen; return offset;}static intcmd_usdt(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){ u_char *desc; guint8 assemble_flag; if (tvb_get_guint8(tvb, offset)) desc = "Register with gusdt"; else desc = "Unregister with gusdt"; proto_tree_add_text(pt, tvb, offset, 1, "%s", desc); if (tvb_get_guint8(tvb, offset+1)) desc = "Echo long transmit messages back to the client"; else desc = "Do not echo long transmit messages back to the client"; proto_tree_add_text(pt, tvb, offset+1, 1, "%s", desc); assemble_flag = tvb_get_guint8(tvb, offset+2); if (assemble_flag == 2) desc = "Assemble long received messages but do not send them to the client"; else if (assemble_flag) desc = "Assemble long received messages and send them to the client"; else desc = "Do not assemble long received messages on behalf of the client"; proto_tree_add_text(pt, tvb, offset+2, 1, "%s", desc); offset += 4; return offset;}static intspeed(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){ proto_tree_add_text(pt, tvb, offset, 1, "Baud rate index: %u", tvb_get_guint8(tvb, offset)); proto_tree_add_text(pt, tvb, offset+1, 3, "reserved"); offset += 4; return offset;}static intfilter_block(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){ unsigned int type, operator, i; int length, padding; proto_tree_add_text(pt, tvb, offset, 2, "Filter field starts at byte %d", tvb_get_ntohs(tvb, offset)); length = tvb_get_ntohs(tvb, offset+2); proto_tree_add_text(pt, tvb, offset+2, 2, "Filter field is %d bytes long", length); type = tvb_get_guint8(tvb, offset+4); for (i = 0; i < SIZEOF(filter_data_types); i++) { if (filter_data_types[i].value == type) break; } if (i >= SIZEOF(filter_data_types)) i = SIZEOF(filter_data_types) - 1; proto_tree_add_text(pt, tvb, offset+4, 1, "Filtering on %s", filter_data_types[i].strptr); operator = tvb_get_guint8(tvb, offset+5); for (i = 0; i < SIZEOF(operators); i++) { if (operators[i].value == operator) break; } if (i >= SIZEOF(operators)) i = SIZEOF(operators) - 1; proto_tree_add_text(pt, tvb, offset+5, 1, "Type of comparison: %s", operators[i].strptr); proto_tree_add_text(pt, tvb, offset+6, 2, "reserved"); offset += 8; if (operator == BIT_FIELD_CHECK) { proto_tree_add_text(pt, tvb, offset, length, "Pattern"); proto_tree_add_text(pt, tvb, offset+length, length, "Mask"); } else { switch (length) { case 1: proto_tree_add_text(pt, tvb, offset, 1, "Value: %u", tvb_get_guint8(tvb, offset)); break; case 2: proto_tree_add_text(pt, tvb, offset, 2, "Value: %u", tvb_get_ntohs(tvb, offset)); break; case 4: proto_tree_add_text(pt, tvb, offset, 4, "Value: %u", tvb_get_ntohl(tvb, offset)); break; default: proto_tree_add_text(pt, tvb, offset, length, "Value"); } } offset += length * 2; padding = 3 - (length * 2 + 3) % 4; if (padding) { proto_tree_add_text(pt, tvb, offset, padding, "padding"); offset += padding; } return offset;}static intblm_mode(tvbuff_t *tvb, int offset, int src, int msglen, proto_tree *pt){ char *mode, line[50]; int x, y, seconds; x = tvb_get_ntohl(tvb, offset); y = tvb_get_ntohl(tvb, offset+4); switch (x) { case 0: mode = "Off"; sprintf (line, "reserved"); break; case 1: mode = "Average over time"; seconds = y / 1000; y = y % 1000; sprintf (line, "Averaging period: %d.%03d seconds", seconds, y); break; case 2: mode = "Average over frame count"; sprintf (line, "Averaging period: %d frames", y); break; default: mode = "- unknown -"; sprintf (line, "reserved"); } proto_tree_add_text(pt, tvb, offset, 4, "Mode: %s", mode); offset += 4; proto_tree_add_text(pt, tvb, offset, 4, line, NULL); offset += 4; return offset;}voidproto_register_gryphon(void){ static hf_register_info hf[] = { { &hf_gryph_src, { "Source", "gryph.src", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }}, { &hf_gryph_srcchan, { "Source channel", "gryph.srcchan", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }}, { &hf_gryph_dest, { "Destination", "gryph.dest", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }}, { &hf_gryph_destchan, { "Destination channel", "gryph.dstchan", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }}, { &hf_gryph_type, { "Frame type", "gryph.type", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }}, { &hf_gryph_cmd, { "Command", "gryph.cmd.cmd", FT_UINT8, BASE_DEC, NULL, 0x0, "", HFILL }}, }; static gint *ett[] = { &ett_gryphon, &ett_gryphon_header, &ett_gryphon_body, &ett_gryphon_command_data, &ett_gryphon_response_data, &ett_gryphon_data_header, &ett_gryphon_flags, &ett_gryphon_data_body, &ett_gryphon_cmd_filter_block, &ett_gryphon_cmd_events_data, &ett_gryphon_cmd_config_device, &ett_gryphon_cmd_sched_data, &ett_gryphon_cmd_sched_cmd, &ett_gryphon_cmd_response_block, &ett_gryphon_pgm_list, &ett_gryphon_pgm_status, &ett_gryphon_pgm_options, }; proto_gryphon = proto_register_protocol("DG Gryphon Protocol", "Gryphon", "gryphon"); proto_register_field_array(proto_gryphon, hf, array_length(hf)); proto_register_subtree_array(ett, array_length(ett));}voidproto_reg_handoff_gryphon(void){ dissector_handle_t gryphon_handle; gryphon_handle = create_dissector_handle(dissect_gryphon, proto_gryphon); dissector_add("tcp.port", 7000, gryphon_handle);}/* Start the functions we need for the plugin stuff */G_MODULE_EXPORT voidplugin_reg_handoff(void){ proto_reg_handoff_gryphon();}G_MODULE_EXPORT voidplugin_init(plugin_address_table_t *pat){ /* initialise the table of pointers needed in Win32 DLLs */ plugin_address_table_init(pat); /* register the new protocol, protocol fields, and subtrees */ if (proto_gryphon == -1) { /* execute protocol initialization only once */ proto_register_gryphon(); }}/* End the functions we need for plugin stuff */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -