Click here to Skip to main content
15,896,557 members
Articles / Desktop Programming / MFC

A Great Protocol Analyser

Rate me:
Please Sign up or sign in to vote.
3.39/5 (12 votes)
16 Aug 2007CPOL2 min read 39.9K   2.9K   32  
A programmable, easy-to-use protocol decoder for parsing and displaying binary package
#if !defined(_VIRTUALIST_H)
#define _VIRTUALIST_H

#include "PubHeader.h"
#include "otstr.h"
#include "Array.h"

/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////

#ifdef _DLL_PROJECT
class CLASS_EXPORT GridItem
#else
class GridItem
#endif
{
public:
    enum { MAX_COLUMN_NUM=5 };
    
protected:
    DWORD wParam;
    void* pColData[MAX_COLUMN_NUM];

public:
    GridItem();
   ~GridItem(); 
    
    inline bool    SetItem(long nCol,void *data);
    inline void*   GetItem(long nCol);

    inline void    SetParam(DWORD param);
    inline DWORD&  GetParam();
    
    inline void    Clear();
};

//////////////////////////////////////////////////////////////
#ifdef _DLL_PROJECT
template class CLASS_EXPORT TArray<GridItem>;
#endif

#ifdef _DLL_PROJECT
class CLASS_EXPORT ObGrid
#else
class ObGrid
#endif
{
public:
    ObGrid();
    virtual ~ObGrid();
    
    bool  SetColumn(int num, ...);
    char* GetColumnName(long nCol);
    
    long  GetItemCount();
    
    long  InsertItem(long nItem, DWORD param=0);    // nItem=-1 mean Add, return index of the new Item

    virtual bool DeleteItem(long nItem);
    virtual void DeleteAllItems();
    
    DWORD GetItemParam(long nItem);

    void* GetItemData(long nItem, long nCol);
    bool  SetItemData(long nItem, long nCol, void* pData);  
    
protected:
    int   m_ColumnNum;
    OTSTR m_ColumnName[GridItem::MAX_COLUMN_NUM];
    
    TArray<GridItem>  m_ItemList;

    static GridItem   m_NullItem;
};

///////////////////////////////////////////////////
///////////////////////////////////////////////////
enum { LFMT_AUTOFIT=1, 
       LFMT_DIS_RIGHTSEPMARK=2,  
       LFMT_LEFT =4,
       LFMT_RIGHT=0,
       LFMT_HIDE =8
};

#ifdef _DLL_PROJECT
class CLASS_EXPORT VirtualList: public ObGrid
#else
class VirtualList: public ObGrid
#endif
{
public:
    struct DumpAttr
    {
        WORD AttrBits;
        long nInitWidth;        // 
        long nNowWidth;
        long nPreSpaceLen;      // 
        long nSepSpaceLen;      // 
        char strFormat[10];
    };

public:
    VirtualList();
    virtual ~VirtualList();

    bool   DeleteItem(long nItem);
    void   DeleteAllItems();

    char*  GetItemData(long nItem, long nCol);
    bool   SetItemData(long nItem, long nCol, char* szText);

    long   GetColumnDataWidth(long nCol);

    ///////////////////////////////////////////
    bool   DumpAttr_set(int num, ...);         
    bool   DumpAttr_setColumnFmtBits(long nCol, WORD Attr);  
    void   UpdateColumnWidth();
    
    OTSTR& Dump_RowSeperator();
    bool   Dump_Header(OTSTR& strContent);
    bool   Dump_Item(long nItem, OTSTR& strContent);
    bool   Dump_Item(long nItem, long nToCol, bool bEnableSepMarkCheck, OTSTR& strContent); 
    long   GetColDumpWidth(long nCol);
    
protected:
    DumpAttr m_ColDumpAttr[GridItem::MAX_COLUMN_NUM];
    OTSTR    m_strRowSeperator;

    void     GenerateRowSeperator();
};



#endif 

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions