📄 decode.cpp
字号:
// decode.cpp : Defines the initialization routines for the DLL.
//
#include "stdafx.h"
#include "decode.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//
// Note!
//
// If this DLL is dynamically linked against the MFC
// DLLs, any functions exported from this DLL which
// call into MFC must have the AFX_MANAGE_STATE macro
// added at the very beginning of the function.
//
// For example:
//
// extern "C" BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // normal function body here
// }
//
// It is very important that this macro appear in each
// function, prior to any calls into MFC. This means that
// it must appear as the first statement within the
// function, even before any object variable declarations
// as their constructors may generate calls into the MFC
// DLL.
//
// Please see MFC Technical Notes 33 and 58 for additional
// details.
//
/////////////////////////////////////////////////////////////////////////////
// CDecodeApp
BEGIN_MESSAGE_MAP(CDecodeApp, CWinApp)
//{{AFX_MSG_MAP(CDecodeApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDecodeApp construction
CDecodeApp::CDecodeApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// get one byte hex string.
char *CDecodeApp::ConvertOneByte(BYTE u_byte, char *v_pOutput)
{
BYTE temp;
temp = (u_byte >> 4) & 0x0f;
if(temp < 10)
{
v_pOutput[0] = temp + 0x30;
}
else
{
v_pOutput[0] = temp + 55;
}
temp = u_byte & 0x0f;
if(temp < 10)
{
v_pOutput[1] = temp + 0x30;
}
else
{
v_pOutput[1] = temp + 55;
}
v_pOutput[2] = ' ';
v_pOutput[3] = 0;
return v_pOutput;
}
BOOL CDecodeApp::GetH1H0(BYTE *u_pMsg, DWORD u_msgLength, char *v_pH1H0)
{
BYTE msuType;
if(SS7_FISU_LENGTH == u_msgLength)
{
v_pH1H0[0] = 0;
}
else if(SS7_LSSU_LENGTH == u_msgLength)
{
v_pH1H0[0] = 0;
}
else
{
msuType = u_pMsg[SS7_SI_OFFSET] & SS7_SI_MASK;
if(SS7_SI_SNMU == msuType)
{
m_snmu.GetH1H0(u_pMsg, u_msgLength, v_pH1H0);
}
else if(SS7_SI_STMU == msuType)
{
m_stmu.GetH1H0(u_pMsg, u_msgLength, v_pH1H0);
}
else if(SS7_SI_SCCP == msuType)
{
m_sccp.GetH1H0(u_pMsg, u_msgLength, v_pH1H0);
}
else if(SS7_SI_TUP == msuType)
{
m_tup.GetH1H0(u_pMsg, u_msgLength, v_pH1H0);
}
else if(SS7_SI_ISUP == msuType)
{
m_isup.GetH1H0(u_pMsg, u_msgLength, v_pH1H0);
}
else
{
sprintf(v_pH1H0, "*"); //暂时不解析的MSU。
}
}
return TRUE;
}
BOOL CDecodeApp::GetSls(BYTE *u_pMsg, DWORD u_msgLength, char *v_pSls)
{
BYTE msuType;
if(SS7_FISU_LENGTH == u_msgLength)
{
v_pSls[0] = 0;
}
else if(SS7_LSSU_LENGTH == u_msgLength)
{
v_pSls[0] = 0;
}
else
{
msuType = u_pMsg[SS7_SI_OFFSET] & SS7_SI_MASK;
if(SS7_SI_SNMU == msuType)
{
m_snmu.GetSls(u_pMsg, u_msgLength, v_pSls);
}
else if(SS7_SI_STMU == msuType)
{
m_stmu.GetSls(u_pMsg, u_msgLength, v_pSls);
}
else if(SS7_SI_SCCP == msuType)
{
m_sccp.GetSls(u_pMsg, u_msgLength, v_pSls);
}
else if(SS7_SI_TUP == msuType)
{
m_tup.GetSls(u_pMsg, u_msgLength, v_pSls);
}
else if(SS7_SI_ISUP == msuType)
{
m_isup.GetSls(u_pMsg, u_msgLength, v_pSls);
}
else
{
sprintf(v_pSls, "*"); //暂时不解析的MSU。
}
}
return TRUE;
}
BOOL CDecodeApp::GetCic(BYTE *u_pMsg, DWORD u_msgLength, char *v_pCic)
{
BYTE msuType;
if(SS7_FISU_LENGTH == u_msgLength)
{
v_pCic[0] = 0;
}
else if(SS7_LSSU_LENGTH == u_msgLength)
{
v_pCic[0] = 0;
}
else
{
msuType = u_pMsg[SS7_SI_OFFSET] & SS7_SI_MASK;
if(SS7_SI_SNMU == msuType)
{
m_snmu.GetCic(u_pMsg, u_msgLength, v_pCic);
}
else if(SS7_SI_STMU == msuType)
{
m_stmu.GetCic(u_pMsg, u_msgLength, v_pCic);
}
else if(SS7_SI_SCCP == msuType)
{
m_sccp.GetCic(u_pMsg, u_msgLength, v_pCic);
}
else if(SS7_SI_TUP == msuType)
{
m_tup.GetCic(u_pMsg, u_msgLength, v_pCic);
}
else if(SS7_SI_ISUP == msuType)
{
m_isup.GetCic(u_pMsg, u_msgLength, v_pCic);
}
else
{
sprintf(v_pCic, "*"); //暂时不解析的MSU。
}
}
return TRUE;
}
BOOL CDecodeApp::GetData(BYTE *u_pMsg, DWORD u_msgLength, char *v_pData)
{
BYTE msuType;
if(SS7_FISU_LENGTH == u_msgLength)
{
v_pData[0] = 0;
}
else if(SS7_LSSU_LENGTH == u_msgLength)
{
m_lssu.GetData(u_pMsg, u_msgLength, v_pData);
}
else
{
msuType = u_pMsg[SS7_SI_OFFSET] & SS7_SI_MASK;
if(SS7_SI_SNMU == msuType)
{
m_snmu.GetData(u_pMsg, u_msgLength, v_pData);
}
else if(SS7_SI_STMU == msuType)
{
m_stmu.GetData(u_pMsg, u_msgLength, v_pData);
}
else if(SS7_SI_SCCP == msuType)
{
m_sccp.GetData(u_pMsg, u_msgLength, v_pData);
}
else if(SS7_SI_TUP == msuType)
{
m_tup.GetData(u_pMsg, u_msgLength, v_pData);
}
else if(SS7_SI_ISUP == msuType)
{
m_isup.GetData(u_pMsg, u_msgLength, v_pData);
}
else
{
sprintf(v_pData, "*"); //暂时不解析的MSU。
}
}
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// get message content.
BOOL CDecodeApp::GetMessageContent(BYTE *u_pMsg, DWORD u_msgLength, char *v_pDecodeResult)
{
DWORD pos;
DWORD i;
pos = 0;
for(i=0; i<u_msgLength; i++)
{
ConvertOneByte(u_pMsg[i], &v_pDecodeResult[pos]);
pos += 3;
}
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// get message decoding info
BOOL CDecodeApp::GetMessageDecodeInfo(BYTE *u_pMsg, DWORD u_msgLength, char *v_pDecodeResult)
{
char *pAfterHead;
int headStrLen;
BYTE temp;
if(SS7_FISU_LENGTH == u_msgLength)
{
fisuDecode(u_pMsg, v_pDecodeResult);
}
else if(SS7_LSSU_LENGTH == u_msgLength)
{
m_lssu.GetMessageDecodeInfo(u_pMsg, u_msgLength, v_pDecodeResult);
}
else if(u_msgLength > 5)
{
msuHeadDecode(u_pMsg, v_pDecodeResult, &headStrLen);
pAfterHead = &v_pDecodeResult[headStrLen];
//temp = u_pMsg[3] & 0x0f;
temp = u_pMsg[SS7_SI_OFFSET] & 0x0f;
switch(temp)
{
case SS7_SI_SNMU: //0
//sprintf(pAfterHead, "Message Type: MSU, 信令网管理消息 \n");
m_snmu.GetMessageDecodeInfo(u_pMsg, u_msgLength, pAfterHead);
break;
case SS7_SI_STMU: //1
//sprintf(pAfterHead, "Message Type: MSU, 信令网测试和维护消息 \n");
m_stmu.GetMessageDecodeInfo(u_pMsg, u_msgLength, pAfterHead);
break;
case 2:
//sprintf(pAfterHead, "Message Type: MSU, 备用 \n");
break;
case SS7_SI_SCCP: //3
//sprintf(pAfterHead, "Message Type: MSU, SCCP \n");
m_sccp.GetMessageDecodeInfo(u_pMsg, u_msgLength, pAfterHead);
break;
case SS7_SI_TUP: //4
//sprintf(pAfterHead, "Message Type: MSU, TUP \n");
m_tup.GetMessageDecodeInfo(u_pMsg, u_msgLength, pAfterHead);
break;
case SS7_SI_ISUP: //5
//sprintf(pAfterHead, "Message Type: MSU, ISUP \n");
m_isup.GetMessageDecodeInfo(u_pMsg, u_msgLength, pAfterHead);
break;
case 6:
//sprintf(pAfterHead, "Message Type: MSU, DUP(与呼叫和电路有关) \n");
break;
case 7:
//sprintf(pAfterHead, "Message Type: MSU, DUP(性能登记和撤消消息) \n");
break;
default:
//sprintf(pAfterHead, "Message Type: MSU, 备用 \n");
break;
}
}
return TRUE;
}
BOOL CDecodeApp::msuHeadDecode(BYTE *u_pMsg, char *v_pDecodeResult, int *v_pHeadStrLen)
{
char *msuTpye[16] = {"信令网管理消息",
"信令网测试维护消息",
"Reserved",
"SCCP",
"TUP",
"ISUP",
"DUP(与呼叫和电路有关)",
"DUP(性能登记和撤消消息)",
"Reserved","Reserved","Reserved","Reserved",
"Reserved","Reserved","Reserved","Reserved" };
char *netType[4] = {"International Network",
"International Reserved",
"National Network",
"National Reserved" };
int strLength;
//BSN
strLength = 0;
sprintf(&v_pDecodeResult[strLength], \
"%02X BSN :%d \n",
u_pMsg[0], u_pMsg[0] & 0x7F);
//BIB
strLength = strlen(v_pDecodeResult);
sprintf(&v_pDecodeResult[strLength], \
" BIB :%d....... \n", \
(u_pMsg[0] >> 7) & 0x01);
//FSN
strLength = strlen(v_pDecodeResult);
sprintf(&v_pDecodeResult[strLength], \
"%02X FSN :%d \n",
u_pMsg[1], u_pMsg[1] & 0x7F);
//FIB
strLength = strlen(v_pDecodeResult);
sprintf(&v_pDecodeResult[strLength], \
" FIB :%d....... \n", \
(u_pMsg[1] >> 7) & 0x01);
//LI
strLength = strlen(v_pDecodeResult);
sprintf(&v_pDecodeResult[strLength], \
"%02X LI :%d Length Indicator\n",
u_pMsg[2], u_pMsg[2] & 0x3F);
strLength = strlen(v_pDecodeResult);
sprintf(&v_pDecodeResult[strLength], \
" SPARE :%d%d...... \n",
(u_pMsg[2] >> 7) & 0x01, (u_pMsg[2] >> 6) & 0x01);
//SIO
strLength = strlen(v_pDecodeResult);
sprintf(&v_pDecodeResult[strLength], \
"%02X SIO :....%d%d%d%d %s \n",
u_pMsg[3],
(u_pMsg[3] >> 3) & 0x01, (u_pMsg[3] >> 2) & 0x01,
(u_pMsg[3] >> 1) & 0x01, u_pMsg[3] & 0x01,
msuTpye[u_pMsg[3] & 0x0F] );
strLength = strlen(v_pDecodeResult);
sprintf(&v_pDecodeResult[strLength], \
" SPARE :..%d%d.... \n",
(u_pMsg[3] >> 5) & 0x01, (u_pMsg[3] >> 4) & 0x01);
//NI
strLength = strlen(v_pDecodeResult);
sprintf(&v_pDecodeResult[strLength], \
" NI :%d%d...... %s \n",
(u_pMsg[3] >> 7) & 0x01, (u_pMsg[3] >> 6) & 0x01,
netType[(u_pMsg[3] >> 6) & 0x03] );
if(0x03 == (u_pMsg[3] & 0x0f))
{
return TRUE; //MSU SCCP
}
//DPC
strLength = strlen(v_pDecodeResult);
sprintf(&v_pDecodeResult[strLength], \
"%02X %02X %02X DPC : \n",
u_pMsg[6], u_pMsg[5], u_pMsg[4]);
//OPC
strLength = strlen(v_pDecodeResult);
sprintf(&v_pDecodeResult[strLength], \
"%02X %02X %02X OPC : \n",
u_pMsg[9], u_pMsg[8], u_pMsg[7]);
*v_pHeadStrLen = strlen(v_pDecodeResult);
return TRUE;
}
void CDecodeApp::fisuDecode(BYTE *u_pMsg, char *v_pDecodeResult)
{
int strLength;
strLength = 0;
sprintf(&v_pDecodeResult[strLength], \
"%02X BSN :%d \n",
u_pMsg[0], u_pMsg[0] & 0x7F);
strLength = strlen(v_pDecodeResult);
sprintf(&v_pDecodeResult[strLength], \
" BIB :%d....... \n", \
(u_pMsg[0] >> 7) & 0x01);
strLength = strlen(v_pDecodeResult);
sprintf(&v_pDecodeResult[strLength], \
"%02X FSN :%d \n",
u_pMsg[1], u_pMsg[1] & 0x7F);
strLength = strlen(v_pDecodeResult);
sprintf(&v_pDecodeResult[strLength], \
" FIB :%d....... \n", \
(u_pMsg[1] >> 7) & 0x01);
strLength = strlen(v_pDecodeResult);
sprintf(&v_pDecodeResult[strLength], \
"%02X LI :%d Length Indicator. \n",
u_pMsg[2], u_pMsg[2] & 0x3F);
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CDecodeApp object
CDecodeApp theApp;
/////////////////////////////////////////////////////////////////////////////
// API for GUI module.
////u_pMsg = EM_MSG_FORMAT::msg[320 - 12]; /*消息内容 */
DECODE_DLLAPI void decodeMsg(
BYTE *u_pMsg,
DWORD u_msgLength,
char *v_pH1H0,
char *v_pSls,
char *v_pCic,
char *v_pData,
char *v_pMsgContent,
char *v_pMsgDecode
)
{
int temp;
theApp.GetH1H0(u_pMsg, u_msgLength, v_pH1H0);
theApp.GetSls(u_pMsg, u_msgLength, v_pSls);
theApp.GetCic(u_pMsg, u_msgLength, v_pCic);
theApp.GetData(u_pMsg, u_msgLength, v_pData);
sprintf(v_pMsgContent, "Message Content: \n\n");
temp = strlen(v_pMsgContent);
theApp.GetMessageContent(u_pMsg, u_msgLength, &v_pMsgContent[temp]);
sprintf(v_pMsgDecode, "Message Info: \n\n");
temp = strlen(v_pMsgDecode);
theApp.GetMessageDecodeInfo(u_pMsg, u_msgLength, &v_pMsgDecode[temp]);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -