-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebugDialog.cpp
More file actions
123 lines (106 loc) · 3.1 KB
/
DebugDialog.cpp
File metadata and controls
123 lines (106 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "DebugDialog.h"
#include "resource.h"
BOOL CALLBACK lpDialogFunc(HWND,UINT,WPARAM,LPARAM);
void DebugWindowThread();
HWND m_DbgWnd;
HWND m_DbgList;
HANDLE outHand;
char crlf[]={0x0d,0x0a,0x0d,0x0a};
//Constructor
CDebugWindow::CDebugWindow() : m_isVisible(FALSE)
{
}
// Startups The Debug Dialog
void CDebugWindow::Startup(void)
{
DWORD lpThreadId;
//Create a thread for dialog
m_isVisible = TRUE;
CloseHandle(CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)DebugWindowThread,NULL,0,&lpThreadId));
//Give time for dialog to startup properly
Sleep(10);
}
void DebugWindowThread(){
//start dialog
DialogBox(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_DIALOG1),NULL,(DLGPROC)lpDialogFunc);
}
BOOL CALLBACK lpDialogFunc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam){
switch(uMsg) {
case WM_INITDIALOG:
//Copy HWND's
m_DbgWnd = hDlg;
m_DbgList = GetDlgItem(hDlg,IDC_DBGLIST);
//Open File For Writing
outHand = CreateFile("PacketData.txt",GENERIC_READ+GENERIC_WRITE,FILE_SHARE_READ+FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
SetEndOfFile(outHand);
break;
default:
return 0;
}
return 0;
}
void CDebugWindow::Shutdown(void)
{
//Close Dialog
EndDialog(m_DbgWnd,TRUE);
//Close File Handle
CloseHandle(outHand);
}
void CDebugWindow::AddEventMsg(char* cMsg)
{
DWORD written;
if (m_isVisible) {
SendMessage(m_DbgList,LB_ADDSTRING,0,(LPARAM)cMsg);
//Highlight Last Active Message
SendMessage(m_DbgList,LB_SETCURSEL,SendMessage(m_DbgList,LB_GETCOUNT,0,0)-1,0);
//Write data to file
WriteFile(outHand,cMsg,strlen(cMsg),&written,NULL);
WriteFile(outHand,crlf,4,&written,NULL);
}
}
void CDebugWindow::AddEventMsg(int cMsgType, char* cData, DWORD dwSize, char cKey)
{
DWORD written;
char DbgBuffer[10000];
if (m_isVisible) {
if (cMsgType == MSG_SEND) strcpy(DbgBuffer,"SEND -> ");
else strcpy(DbgBuffer,"RECV -> ");
wsprintf(&DbgBuffer[8],"Size = %lu Key = 0x%.X",dwSize,cKey);
SendMessage(m_DbgList,LB_ADDSTRING,0,(LPARAM)DbgBuffer);
//Write data to file
WriteFile(outHand,DbgBuffer,strlen(DbgBuffer),&written,NULL);
WriteFile(outHand,crlf,2,&written,NULL);
int i=0;
while(i<dwSize){
memset(DbgBuffer,0,sizeof(DbgBuffer));
strcpy(DbgBuffer, "DATA -> ");
for(int j=i;j < i+16 && j < dwSize;j++)
wsprintf(&DbgBuffer[strlen(DbgBuffer)],"%.2X ",(unsigned char)cData[j]);
//Align Spacing
for(int a=strlen(DbgBuffer);a < 56; a+=3)
strcat(DbgBuffer," ");
strcat(DbgBuffer,"\t\t\t");
for(j=i;j < i+16 && j < dwSize;j++)
DbgBuffer[strlen(DbgBuffer)] = isprint((unsigned char)cData[j]) ? cData[j]:'.';
SendMessage(m_DbgList,LB_ADDSTRING,0,(LPARAM)DbgBuffer);
WriteFile(outHand,DbgBuffer,strlen(DbgBuffer),&written,NULL);
WriteFile(outHand,crlf,2,&written,NULL);
i=j;
}
WriteFile(outHand,crlf,2,&written,NULL);
//Highlight Last Active Message
SendMessage(m_DbgList,LB_SETCURSEL,SendMessage(m_DbgList,LB_GETCOUNT,0,0)-1,0);
}
}
void CDebugWindow::ShowWindow(bool isVisible)
{
Sleep(10);
if (isVisible) {
::ShowWindow(m_DbgWnd,SW_SHOW);
m_isVisible = TRUE;
}
else {
::ShowWindow(m_DbgWnd,SW_HIDE);
m_isVisible = FALSE;
}
}