📄 wizspy.c
字号:
/*
*
* Copyright (C) 2003 Xiangbin Lee <honeycombs@sina.com> <honeycombs@263.net>
*
* 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.
*/
#include "protocal.h"
#include "ipexport.h"
#include "netdrv.h"
#include "spyfun.h"
#include "hexviewdlg.h"
#include "getipdlg.h"
/* The Widgets list for dialog
1.dialog preview:
______________________________________________________
/v| _ X \
--------------------------------------------------------
| | |
| area A span_ha area E |
| | |
-------------- span_va --------------------------------
| | |
| span_hb |
| area C | area D |
| | |
-------------------------------------------------------
2.main gtk ctrl relations :
main dialog
{
va span_vb return
|+ha span_ha
| |-A area A, message list [text area]
| |-E area E, packet list, [clist]
|+hb span_hb
|-C area C, packet tree, [tree view]
|-D area D, frame show, [draw area]
E
|- area E1, Ether packet list , [clist]
|- area E2, Ip packet list , [clist]
}
setting
{
B (dialog + option notbook, [notebook])
|- area B1, system setting , [dialog or frame]
|- area B2, packet invald , [dialog or frame]
|- area B3, protocal invald , [dialog or frame]
|- area B4, ip invald , [dialog or frame]
}
*/
/* for area A */
GTK_TextArea spytext_areaa={0,0,0,0,};
void wizspy_areaa_addtext(gchar *msg)
{
GtkTextIter iter;
if(spytext_areaa.regsignal!=GTK_WIDGET_REG)
return ;
if(msg[strlen(msg)-1]!='\n')
strcat((char *)msg,"\n");
gtk_text_buffer_get_iter_at_offset (spytext_areaa.buffer, &iter, 0);
gtk_text_buffer_insert (spytext_areaa.buffer, &iter,msg,-1);
}
void wizspy_areaa_settext(gchar *msg)
{
if(spytext_areaa.regsignal!=GTK_WIDGET_REG)
return ;
gtk_text_buffer_set_text (spytext_areaa.buffer, msg,strlen(msg));
}
/* area B */
/*---------------- B2 ------------------------*/
/*
1.dialog preview:
_________________
| packet invald \
------------------------------------------------
| | | |
| | |---------| | |
| | | dismiss | | |
| used list box | |---------| | |
| | |unused list box |
| | |---------| | |
| | |transfer | | |
| | |---------| | |
| | | |
|----------------------------------------------|
| infomation for list selectd |
|----------------------------------------------|
2.main gtk ctrl relations :
+vbox (main box)
|+hbox
| |-used list box
| |-unused list box
| |+bbox (button box)
| |- button (dismiss)
| |- button (transfer)
|-textarea
*/
GtkScrollCtrl wizspy_areab2={0,0,0,};
GtkScrollCtrl wizspy_areab2_listboxused={0,0,0,};
GtkScrollCtrl wizspy_areab2_listboxunused={0,0,0,};
GTK_TextArea wizspy_areab2_info={0,0,0,0,};
void wizspy_areab2_setinfo(gchar *msg)
{
if(wizspy_areab2_info.regsignal!=GTK_WIDGET_REG)
return ;
gtk_text_buffer_set_text (wizspy_areab2_info.buffer, msg,strlen(msg));
}
GtkListBoxItemData ether_packettype_used[MAX_ETHER_TYPE_NUM];
GtkListBoxItemData ether_packettype_unused[MAX_ETHER_TYPE_NUM];
void wizspy_areab2_clickbutton(GtkWidget *widget,gpointer fundata)
{
gint freei,index,found;
GtkListBoxItemData itemdata;
GtkScrollCtrl *fromctrl, *toctrl;
GtkListBoxItemData *fromdata, *todata;
if(fundata==NULL) // delete
{
fromctrl=&wizspy_areab2_listboxused;
fromdata=ether_packettype_used;
toctrl=&wizspy_areab2_listboxunused;
todata=ether_packettype_unused;
}
else // add
{
fromctrl=&wizspy_areab2_listboxunused;
fromdata=ether_packettype_unused;
toctrl=&wizspy_areab2_listboxused;
todata=ether_packettype_used;
}
index=listbox_getselectitem(*fromctrl,&itemdata);
if(index>=0)
{
found=0;
for(freei=0;freei<MAX_ETHER_TYPE_NUM;freei++)
{
if(eth_p_type[freei].type==itemdata.itemdata)
{
found=1;
break;
}
}
if(!found) return ;
for(freei=0;freei<MAX_ETHER_TYPE_NUM;freei++)
{
if(fromdata[freei].itemdata==itemdata.itemdata
&&(strcmp(fromdata[freei].itemname,itemdata.itemname)==0))
{
fromdata[freei].itemdata=0;
fromdata[freei].itemname[0]=0;
listbox_deleteitem(*fromctrl,index);
found=1;
break;
}
}
if(!found) return ;
for(freei=0;freei<MAX_ETHER_TYPE_NUM;freei++)
{
if(todata[freei].itemdata==0 &&todata[freei].itemname[0]==0)
{
todata[freei].itemdata=itemdata.itemdata;
strcpy(todata[freei].itemname,itemdata.itemname);
listbox_insertitem(*toctrl,itemdata,0);
break;
}
}
}
}
void wizspy_areab2_onclicklist( GtkWidget *gtklist, gpointer func_data )
{
static gchar itemsg[512];
gint ret, freei;
GtkListBoxItemData itemdata;
GtkScrollCtrl *selctrl=(GtkScrollCtrl *)func_data;
if(selctrl==NULL)
return;
ret=listbox_getselectitem(*selctrl,&itemdata);
if(ret>=0)
{
for(freei=0;freei<MAX_ETHER_TYPE_NUM;freei++)
{
if(eth_p_type[freei].type==itemdata.itemdata)
{
sprintf(itemsg," Name: '%s' \n Data: '%d' \n Info: '%s'",
eth_p_type[freei].name,
eth_p_type[freei].type,
eth_p_type[freei].info
);
wizspy_areab2_setinfo(itemsg);
return;
}
}//for(freei=0;freei<MAX_ETHER_TYPE_NUM;freei++)
}//if(ret>=0)
}
GtkWidget *wizspy_areab2_create(GtkWidget *window)
{
gint freei;
GtkWidget *vbox, *hbox,*bbox,*ctrl;
if(wizspy_areab2.regsignal==GTK_WIDGET_REG)
return (wizspy_areab2.scrolled_window);
else wizspy_areab2.regsignal=GTK_WIDGET_REG;
wizspy_areab2.ctrl=gtk_frame_new(NULL);
vbox=gtk_vbox_new (FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 1);
gtk_container_add (GTK_CONTAINER (wizspy_areab2.ctrl), vbox);
/* h box*/
hbox = gtk_hbox_new (FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 1);
gtk_box_pack_start (GTK_BOX (vbox),hbox, TRUE, TRUE, 1);
// add used list box, and add data to this listctrl
ctrl=listbox_createnew(NULL,&wizspy_areab2_listboxused);
gtk_widget_set_size_request (GTK_WIDGET (ctrl), 120, 120);
gtk_box_pack_start (GTK_BOX (hbox),ctrl, TRUE, TRUE, 1);
g_signal_connect (G_OBJECT (wizspy_areab2_listboxused.ctrl), "selection_changed",
G_CALLBACK (wizspy_areab2_onclicklist),
&wizspy_areab2_listboxused);
for(freei=0;freei<MAX_ETHER_TYPE_NUM;freei++)
{
if(ether_packettype_used[freei].itemdata>0
&ðer_packettype_used[freei].itemname[0]!=0)
listbox_insertitem(wizspy_areab2_listboxused,ether_packettype_used[freei],0);
}
// add buttons 'add' and 'delete'
bbox= gtk_vbutton_box_new();
gtk_box_pack_start (GTK_BOX (hbox),bbox, TRUE, TRUE, 1);
gtk_container_set_border_width (GTK_CONTAINER (bbox), 20);
gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_START);
gtk_box_set_spacing (GTK_BOX (bbox), 20);
// button delete
ctrl=gtk_button_new_with_label("--dismiss-->");
gtk_container_add (GTK_CONTAINER (bbox), ctrl);
g_signal_connect (G_OBJECT (ctrl), "clicked",
G_CALLBACK (wizspy_areab2_clickbutton), NULL);
// button add
ctrl=gtk_button_new_with_label("<--transfer-");
gtk_container_add (GTK_CONTAINER (bbox), ctrl);
g_signal_connect (G_OBJECT (ctrl), "clicked",
G_CALLBACK (wizspy_areab2_clickbutton), wizspy_areab2_clickbutton);
// add unused list box
ctrl=listbox_createnew(NULL,&wizspy_areab2_listboxunused);
gtk_widget_set_size_request (GTK_WIDGET (ctrl), 120, 120);
gtk_box_pack_start (GTK_BOX (hbox),ctrl, TRUE, TRUE, 1);
g_signal_connect (G_OBJECT (wizspy_areab2_listboxunused.ctrl), "selection_changed",
G_CALLBACK (wizspy_areab2_onclicklist),
&wizspy_areab2_listboxunused);
for(freei=0;freei<MAX_ETHER_TYPE_NUM;freei++)
{
if(ether_packettype_unused[freei].itemdata>0
&ðer_packettype_unused[freei].itemname[0]!=0)
listbox_insertitem(wizspy_areab2_listboxunused,ether_packettype_unused[freei],0);
}
/* add info texarea */
ctrl= textarea_createlist(NULL,&wizspy_areab2_info);
gtk_widget_set_size_request (GTK_WIDGET (ctrl), 300, 60);
gtk_box_pack_start (GTK_BOX (vbox),ctrl, TRUE, TRUE, 1);
// add main frame to scrool window, and quit
wizspy_areab2.scrolled_window=gtk_append_scrollviewport(wizspy_areab2.ctrl);
if(window!=NULL)
gtk_container_add (GTK_CONTAINER (window), wizspy_areab2.scrolled_window);
gtk_widget_show_all (wizspy_areab2.scrolled_window);
return wizspy_areab2.scrolled_window;
}
/*---------------- B3 ------------------------*/
/*
1.dialog preview:
_________________
| protocal invald \
------------------------------------------------
| | | |
| | |---------| | |
| | | dismiss | | |
| used list box | |---------| | |
| | |unused list box |
| | |---------| | |
| | |transfer | | |
| | |---------| | |
| | | |
|----------------------------------------------|
| infomation for list selectd |
|----------------------------------------------|
2.main gtk ctrl relations :
+vbox (main box)
|+hbox
| |-used list box
| |-unused list box
| |+bbox (button box)
| |- button (dismiss)
| |- button (transfer)
|-textarea
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -