⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wizspy.c

📁 Linux 上的socket嗅探器
💻 C
📖 第 1 页 / 共 5 页
字号:
}

/* ----------   B dialog, main create here ------------------------*/
GtkScrollCtrl wizspy_areab={0,0,0,};
GtkWidget *wizspy_areab_create(GtkWidget *window)
{
    GtkWidget *notebook,*label, *areaB1, *areaB2, *areaB3, *areaB4;

    notebook = gtk_notebook_new ();
    gtk_notebook_set_tab_pos ( GTK_NOTEBOOK (notebook), GTK_POS_TOP);
    gtk_notebook_set_show_tabs( GTK_NOTEBOOK (notebook),TRUE );
    gtk_notebook_set_show_border( GTK_NOTEBOOK (notebook),FALSE );

    label = gtk_label_new ("Setting");
    areaB1 = wizspy_areab1_create (NULL);

    gtk_notebook_append_page (GTK_NOTEBOOK(notebook), areaB1, label);
    
    label = gtk_label_new ("Invald Packet"); 
    areaB2 = wizspy_areab2_create (NULL);
    gtk_notebook_append_page (GTK_NOTEBOOK(notebook), areaB2, label);


    label = gtk_label_new ("Invald Protocal");
    areaB3 = wizspy_areab3_create (NULL);
    gtk_notebook_append_page (GTK_NOTEBOOK(notebook), areaB3, label);

    label = gtk_label_new ("Invald Ip");
    areaB4 = wizspy_areab4_create (NULL);
    gtk_notebook_append_page (GTK_NOTEBOOK(notebook), areaB4, label); 
                                           
    wizspy_areab.regsignal=GTK_WIDGET_REG;
    wizspy_areab.ctrl=notebook;
    wizspy_areab.scrolled_window=gtk_append_scrollviewport(notebook);

    if(window!=NULL)
        gtk_container_add (GTK_CONTAINER (window), wizspy_areab.scrolled_window);
    gtk_widget_show_all (wizspy_areab.scrolled_window);

    return wizspy_areab.scrolled_window;
}

static int ifwizspy_setting_onshow=0;
void wizspy_setting_ondestroy(GtkWidget *window)
{
	  gtk_grab_remove(window);
    gtk_widget_destroy(window);

    memset(&wizspy_areab1,0,sizeof(GtkScrollCtrl));
    memset(&wizspy_areab2,0,sizeof(GtkScrollCtrl)); 
    memset(&wizspy_areab2_listboxused,0,sizeof(GtkScrollCtrl));
    memset(&wizspy_areab2_listboxunused,0,sizeof(GtkScrollCtrl));
    memset(&wizspy_areab2_info,0,sizeof(GTK_TextArea )); 
    memset(&wizspy_areab3,0,sizeof(GtkScrollCtrl));
    memset(&wizspy_areab3_listboxused,0,sizeof(GtkScrollCtrl));
    memset(&wizspy_areab3_listboxunused,0,sizeof(GtkScrollCtrl));
    memset(&wizspy_areab3_info,0,sizeof(GTK_TextArea ));
    memset(&wizspy_areab4,0,sizeof(GtkScrollCtrl));
    memset(&wizspy_areab4_listboxsource,0,sizeof(GtkScrollCtrl));
    memset(&wizspy_areab4_listboxdest,0,sizeof(GtkScrollCtrl)); 
    memset(&wizspy_areab,0,sizeof(GtkScrollCtrl));
    
    ifwizspy_setting_onshow=0;
}   

GtkWidget* wizspy_setting_show(void)
{
    GtkWidget *hWin;
    if(ifwizspy_setting_onshow)
       return NULL;
    ifwizspy_setting_onshow=1;
    /* Create a new window */
    hWin = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_widget_set_size_request (GTK_WIDGET(hWin), 580, 350);
    gtk_window_set_title (GTK_WINDOW (hWin), "Setting");
    /* Here we connect the "destroy" event to a signal handler */
    gtk_window_set_position(GTK_WINDOW(hWin),GTK_WIN_POS_CENTER);
    g_signal_connect(GTK_OBJECT(hWin), "delete_event",
        GTK_SIGNAL_FUNC(wizspy_setting_ondestroy),
        GTK_OBJECT(hWin));
	  gtk_grab_add(hWin);
    /* Sets the border width of the window. */
    gtk_container_set_border_width (GTK_CONTAINER(hWin), 10); 
    /* ------------------- add extra code here --------------------- */     
    wizspy_areab_create(hWin);
    /* ------------------------------------------------------------- */
    gtk_widget_show_all(hWin);
    return  hWin;
}

  
/* area D */
GtkHexView wizspy_aread;

GtkWidget *wizspy_aread_create(GtkWidget *window)
{

    GtkWidget *frame;
    GdkColor color[6];
    color[0].red=0x80FF;color[0].green=0x80FF;color[0].blue=0xFFFF;
    color[1].red=0xFFFF;color[1].green=0x0000;color[1].blue=0x0000;
    color[2].red=0x0000;color[2].green=0x80FF;color[2].blue=0xFFFF;
    color[3].red=0xFFFF;color[3].green=0x0000;color[3].blue=0x0000;
    color[4].red=0x0000;color[4].green=0x40FF;color[4].blue=0x80FF;
    color[5].red=0xFFFF;color[5].green=0x0000;color[5].blue=0x0000;

    frame = GtkHexView_Create(&wizspy_aread,window);
      /* set option to show */
    GtkHexView_SetFontColor(&wizspy_aread,color[0],color[1],color[2],color[3],color[4],color[5]);
    GtkHexView_SetLineCharNum(&wizspy_aread, 16,0);
    GtkHexView_SetSelOption(&wizspy_aread, 0,0,0);

    return frame;
}


/* area C */


#define wizspy_treeitemkey  ("WIZ_TREE_KEY")

GtkScrollCtrl spyarea_ctree={0,0,0};

GtkWidget *wizspy_areac_create(GtkWidget *window)
{
    treectrl_createnew(window,&spyarea_ctree);
    gtk_tree_set_view_mode(GTK_TREE(spyarea_ctree.ctrl),GTK_TREE_VIEW_ITEM);
    return spyarea_ctree.scrolled_window;
}


void wizspy_treeitem_signal( GtkWidget *item, gpointer fundata )
{
    if(GTK_IS_WIDGET(item))
    {
        gulong itemdata;
        itemdata=(gulong)g_object_get_data(G_OBJECT(item),wizspy_treeitemkey);
        GtkHexView_SetSelOption(&wizspy_aread,((itemdata>>16)&0xFFFF),(gushort)(itemdata&0xFFFF),1);
    }
}


gint wizspy_export_achetree(GtkWidget *treectrl, ACHETREE *lptree)
{
    ACHETREE *lpchild;
    GtkWidget * item=0;
    gulong itemdata;
    int res=0;
    char itemsg[250];
    if(lptree==NULL)
        return -1;
    lpchild=lptree->lpChild;
    while(lpchild!=NULL)
    {
        if(GetAcheTreeText(lpchild,itemsg)<=0)
            strcpy(itemsg,".?.\0");
            
        /* Create a tree item */
        item = gtk_tree_item_new_with_label(itemsg);

        g_signal_connect (G_OBJECT (item), "select",G_CALLBACK (wizspy_treeitem_signal),NULL);
        /* Add it to the parent tree */
        gtk_tree_append (GTK_TREE (treectrl), item);
        GetAcheTreeData(lpchild,&itemdata);
        g_object_set_data (G_OBJECT (item), wizspy_treeitemkey,(gpointer)itemdata);
        /* Show it - this can be done at any time */
        gtk_widget_show (item);
        
        if(lpchild->curChildNum>0)
        {
            GtkWidget *subtree=0;
            /* Create this item's subtree */
            subtree = gtk_tree_new ();
            /* This has absolutely no effect, because it is completely ignored
               in subtrees */
            gtk_tree_set_selection_mode (GTK_TREE (subtree), GTK_SELECTION_SINGLE);
            /* Set this item's subtree - note that you cannot do this until
               AFTER the item has been added to its parent tree! */
            gtk_tree_item_set_subtree (GTK_TREE_ITEM (item), subtree);

            wizspy_export_achetree(subtree,lpchild);
            
            gtk_tree_item_expand(GTK_TREE_ITEM (item));  
        }
        
        
        lpchild=lpchild->lpnext;
        res++;
        if(res>lptree->curChildNum)
            break;
    }
    return 0;
}


/* list ctrl for area E */
ACHETREE spyarea_treeache;
/* If we come here, then the user has selected a row in the list. */
void wizspy_areae_selection( GtkWidget      *clist,
                     gint            row,
                     gint            column,
                     GdkEventButton *event,
                     gpointer        data )
{
    static unsigned long lastid=0;
    
    SPYLIST * lpkt=NULL;
    GtkWidget    *clistctrl;
    clistctrl=(GtkWidget *)data;

    if(row>=0)
    {
        lpkt= (SPYLIST *)gtk_clist_get_row_data (GTK_CLIST(clistctrl), row);
        if(lpkt!=NULL&&lastid!=lpkt->ID)
        {
            lastid=lpkt->ID;
            InitAcheTree(&spyarea_treeache);
            ExportTree_RecvInfo(&spyarea_treeache, lpkt);
            ExportTree_ETH(&spyarea_treeache,0,lpkt->data,lpkt->dlen);
            gtk_tree_clear_items(GTK_TREE(spyarea_ctree.ctrl),0,0xFFFFFF);
            wizspy_export_achetree(spyarea_ctree.ctrl,&spyarea_treeache);
            AcheTreeDelItems(&spyarea_treeache);

            GtkHexView_SetBufferData(&wizspy_aread,(unsigned char *)(lpkt->data),lpkt->dlen,0);
            GtkHexView_SetSelOption(&wizspy_aread, 0,0,1);
        }
    }
}


gchar *areae_ethlist_defaulttitle[6]=
{
      "ID" ,"DateTime" ,"Length" ,
      "Destination ether addr" ,"Source ether addr" ,"Packet type"
};


gchar *areae_iplist_defaulttitle[13]=
{
    "ID",/* 60 */ "DateTime",/* 140 */
    "Version",/* 60 */ "Protocal",/* 60 */ "Source IP",/* 120 */ "Dest IP",/* 120 */
    "IHL",/* 60 */ "TOS",/* 60 */ "Length",/* 60 */ "Ident",/* 60 */ "Flag",/* 60 */
    "TTL",/* 60 */ "Checksum"/* 60 */
};


GtkScrollCtrl spyareae_ethlist={0,0,0};
GtkScrollCtrl spyareae_iplist={0,0,0};

GtkWidget* wizspy_areae_create(GtkWidget *window)
{
    GtkWidget *notebook,*label;

    notebook = gtk_notebook_new ();
    gtk_notebook_set_tab_pos ( GTK_NOTEBOOK (notebook), GTK_POS_BOTTOM);
    gtk_notebook_set_show_tabs( GTK_NOTEBOOK (notebook),TRUE );
    gtk_notebook_set_show_border( GTK_NOTEBOOK (notebook),FALSE );
                                       

    /* create areae eth packet list*/
    label = gtk_label_new ("Ether packet");
    listctrl_createnew(NULL,&spyareae_ethlist,6, areae_ethlist_defaulttitle);
    gtk_notebook_append_page (GTK_NOTEBOOK(notebook), spyareae_ethlist.scrolled_window, label);
    g_signal_connect (G_OBJECT (spyareae_ethlist.ctrl), "select_row",
                      G_CALLBACK (wizspy_areae_selection),
                      spyareae_ethlist.ctrl);

    gtk_clist_set_column_width (GTK_CLIST(spyareae_ethlist.ctrl),0,60);
    gtk_clist_set_column_width (GTK_CLIST(spyareae_ethlist.ctrl),1,120);
    gtk_clist_set_column_width (GTK_CLIST(spyareae_ethlist.ctrl),2,60);
    gtk_clist_set_column_width (GTK_CLIST(spyareae_ethlist.ctrl),3,140);
    gtk_clist_set_column_width (GTK_CLIST(spyareae_ethlist.ctrl),4,140);
    gtk_clist_set_column_width (GTK_CLIST(spyareae_ethlist.ctrl),5,300); 
    gtk_clist_column_titles_show(GTK_CLIST(spyareae_ethlist.ctrl));

    /* create areae ip packet list*/
    label = gtk_label_new ("Ip packet");

    listctrl_createnew(NULL,&spyareae_iplist,13, areae_iplist_defaulttitle);
    gtk_notebook_append_page (GTK_NOTEBOOK(notebook), spyareae_iplist.scrolled_window, label);
    g_signal_connect (G_OBJECT (spyareae_iplist.ctrl), "select_row",
                      G_CALLBACK (wizspy_areae_selection),
                      spyareae_iplist.ctrl);

    gtk_clist_set_column_width (GTK_CLIST(spyareae_iplist.ctrl),0,60);
    gtk_clist_set_column_width (GTK_CLIST(spyareae_iplist.ctrl),1,120);
    gtk_clist_set_column_width (GTK_CLIST(spyareae_iplist.ctrl),2,60);
    gtk_clist_set_column_width (GTK_CLIST(spyareae_iplist.ctrl),3,120);
    gtk_clist_set_column_width (GTK_CLIST(spyareae_iplist.ctrl),4,120);
    gtk_clist_set_column_width (GTK_CLIST(spyareae_iplist.ctrl),5,120);
    gtk_clist_set_column_width (GTK_CLIST(spyareae_iplist.ctrl),6,60);
    gtk_clist_set_column_width (GTK_CLIST(spyareae_iplist.ctrl),7,60);
    gtk_clist_set_column_width (GTK_CLIST(spyareae_iplist.ctrl),8,60);
    gtk_clist_set_column_width (GTK_CLIST(spyareae_iplist.ctrl),9,60);
    gtk_clist_set_column_width (GTK_CLIST(spyareae_iplist.ctrl),10,60);
    gtk_clist_set_column_width (GTK_CLIST(spyareae_iplist.ctrl),11,60);
    gtk_clist_set_column_width (GTK_CLIST(spyareae_iplist.ctrl),12,60);
    
    gtk_clist_column_titles_show(GTK_CLIST(spyareae_iplist.ctrl));

    /*   end here */
    if(window!=NULL)
        gtk_container_add (GTK_CONTAINER (window), notebook);
    gtk_widget_show_all (notebook);  
    return notebook; 
}



guint areae_ethrownum=0;
guint areae_iprownum=0;
void  wizspy_areae_addpacket(SPYLIST * lpkt)
{
    gint index=0,freei;
    ETHHDR ethhdr;
    IPHDR iphdr;
    
    gchar itemsg[13][256];

    if(lpkt==NULL)
        return ;  
/*----------------------  add ether packet to list---------------------------*/
    if(lpkt->dlen<ETH_HLEN)
        return ;
            
    BufGetETHhdr(&ethhdr,(unsigned char *)(lpkt->data));
    //
    sprintf(itemsg[0],"%ld",lpkt->ID);
    //


    sprintf(itemsg[1],"%d-%02d-%02d %02d:%02d:%02d",
        lpkt->recvtm.year,lpkt->recvtm.month,lpkt->recvtm.day,
        lpkt->recvtm.hour,lpkt->recvtm.minute,lpkt->recvtm.second);
    //
    sprintf(itemsg[2],"%d",lpkt->dlen);
    // Destination ether addr
    sprintf(itemsg[3],"%02X%02X%02X%02X%02X%02X",
                ethhdr.h_dest[0],ethhdr.h_dest[1],ethhdr.h_dest[2],
                ethhdr.h_dest[3],ethhdr.h_dest[4],ethhdr.h_dest[5]);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -