Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / MFC

A Great Protocol Analyser

3.39/5 (12 votes)
16 Aug 2007CPOL2 min read 1   2.9K  
A programmable, easy-to-use protocol decoder for parsing and displaying binary package
Screenshot - 1small.gif

Background

There are a lot of protocol analysers (such as Ethereal, sniffer tools) in the software market, but it is still difficult to find a decoder which can support custom-defined package. Here, we provide a framework of such a software, hoping it will help you a lot.

Introduction

Protocol analyser is a protocol analyse tool for parsing and displaying received binary data package. With an easy-to-use interface and programmable kernel, it can support a variety of protocols such as IP based protocols (TCP, UDP, etc.), Telecommunication protocols (MTP3, ISUP, TUP, etc.), or you can define new custom decoders of non-standard or rare protocols.

Unlike other protocol analyzer tools, we create advanced features to meet future needs, not only for standard protocols, but also for user-defined protocols.
Instead of waiting long time for a new protocol decoder to be released, you can easily write a script to support new protocols in an incredibly short time by yourself.

It can be used as a message debug tool for protocol analyzers and program developers, especially for those who want to have a tool to support their own protocol or their own frame format, because no other software can be found to meet such specific requirement.

By understanding this project, you could create your own protocol decoders. Or, you could download the newest version of this software here.

Besides, this article gives a demonstration of how to compile a text script, and how to get the grammar elements. It might be useful in software development.

The Framework

Here, we give you a brief description of how to use the main class.

C++
/////////////////////////////////////////////
// 1. Load protocol script ( sample script is give in source folder )
MsgTranslater Translater;
bRT=Translater.LoadScript(m_strFilePath.GetBuffer(0));
if (!bRT)
{
    AfxMessageBox(Translater.m_strLastError.GetBuffer());
    return;
}
...
///////////////////////////////////////////////////////
// 2. Decode 'buf'
bRT=Translater.Translate(true,buf,n);
if (!bRT)
{
    strLastError=Translater.m_strLastError;
}
...
///////////////////////////////////////////////////////
// 3. Save the result in the VariableItem
TVariableItem& VariableItem=Translater.GetResult();
...
///////////////////////////////////////////////////////
// 4. Dump the result by hierarchy
VirtualList DataList;
VariableItem.DumpToList(DataList,Attr);
...
COneLogFile LogFile("Dump\\Tran.txt",true);
...
///////////////////////////////////////////////////////
// 5. Display the decoding result
FILE *fp;
long len;
fp=fopen("Dump\\Tran.txt","rb");
fseek(fp,0L,2);
len=ftell(fp);
fseek(fp,0L,0);
char *buffer=new char[len+2];
buffer[len]='\0';
fread(buffer,len,1,fp);
GetDlgItem(IDC_MYEDIT)->SetWindowText(buffer);
delete buffer;
fclose(fp);

...

History

This is version 0.9, first workable version, and we are still improving it now, because it can become a very useful tool.
You can visit http://Aries-studio.vicp.net/soft/default.html to download the newest version, the help documents and get more information (website is not always open, but don't worry, try it later).

License

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