在网上的一个工程里看到了这么一段输出调试信息的代码(下面的代码经过我的修改了), 觉得用在程序的调试上还可以,于是就拿来用了,他的宏定义的很巧妙,具体为什么我觉得巧妙我会写在代码注释里., 然后光光有这一个类还是没用的,还需要写一个接受调试信息的小工具,代码也在下面,拿去用就好了,不说废话,上代码.
需要包含的头文件:
/*
*************************************************************************************************
声明
*************************************************************************************************
名称: 守侯---远控客户端 (V1.1.0.188)
本软件仅供学习交流使用。
如用本程序于非法用途所导致的后果自负,与作者无关
*************************************************************************************************
简介
本套代码为开源远程控制类型软件测试版本,主要目的学习及交流远控技术.
功能概括
1. 远程屏幕查看及控制,录制远程屏幕到本地AVI文件及保存本地图片.
2. 远程摄象头管理,录制远程摄象头到本地AVI文件及监听远程语音.
3. 远程文件管理
4. 远程进程管理
5. 远程服务管理
6. 远程窗口管理
7. 远程命令行管理
8. 远程键盘记录
9. DDOS模块简单模拟
10. 远程3322动态域名上线测试
*************************************************************************************************
2008-6-12
由于最近工作比较忙,没有太多时间继续完善,所以把代码发给大家一起交流,继续更新.
Client 文件夹为客户端代码
Server 文件夹为服务端代码
Common 文件夹为公用类代码
Exe 文件夹为程序生成目录
把纯真IP数据库文件(QQWry.Dat) 和 客户端放在一起 即可显示物理地址
由于数据库文件比较大,网上下载很多,请自行从网上下载
未实现模块
现在的网络传输模块采用的原始SOCKET阻塞模式,效率不是很高.有时间将改成IOCP异步方式
暂时未实现过防火墙及主动防御模块,考虑用恢复SSDT的方式实现,那位有更好的方法可以联系我一起交流
*************************************************************************************************
鸣谢
在写这套测试版软件过程中借鉴了Gh0st和Vipshell两套远控代码,从里面学到很多,特此感谢两位作者的开源
精神.同时感谢网友Franket提供的资料及建议,多谢了哥们 (^-^).
*************************************************************************************************
本套代码只是初期的测试版本,里面不可避免会有BUG.请发现BUG的朋友发送信息给我,提供BUG描述,我会尽快更新代码.
有问题请联系 QQ:837568664
技术交流群 63666648
Email dongchaomissyou@21cn.com
*************************************************************************************************
感谢作者的开源精神.
修了一下调试信息的格式 删除掉了与主题不相关的信息
*************************************************************************************************
*/
#ifndef _DT_H_
#define _DT_H_
#include <stdarg.h>
#include <windows.h>
#include <stdio.h>
//#ifdef __cplusplus
//错误级别
#define DT_ERROR 0x0
#define DT_WARNNING 0x1
#define DT_TRACE 0x2
class _CDT
{
public:
_CDT(const char* lpszFile, int nLine, int nLevel)
:m_lpszFile(lpszFile), m_nLine(nLine), m_nLevel(nLevel)
{
}
int operator()(const char* lpszFormat, ...)
{
char szFormat[4096];
char szMsg[4096];
DWORD dwPid = GetCurrentProcessId();
sprintf_s(szFormat, 4096, "PID[%d]> %s: $$@@%s(%d)$$@@%s", dwPid, infomation[m_nLevel], m_lpszFile, m_nLine, lpszFormat);
lpszFormat = szFormat;
va_list argList;
va_start(argList, lpszFormat);
vsprintf_s(szMsg, 4096, lpszFormat, argList);
va_end(argList);
int nLen = strlen(szMsg);
for (int i = 0; i < nLen; i++)
{
if (szMsg[i] == '\n')
szMsg[i] = '^';
}
//send message to dt.exe
{
static HWND hwnd = ::FindWindowExA(NULL, NULL, NULL, "DT ");
if (!IsWindow(hwnd))
{
hwnd = ::FindWindowExA(NULL, NULL, NULL, "DT ");
if (!hwnd)
hwnd = ::FindWindowA(NULL, "DebugHelper ");//向后兼容,旧版名称
}
if (hwnd)
{
//::SendMessage(hwnd,WM_SETTEXT,0,(LPARAM)(LPCTSTR)szMsg);
DWORD dwpRet = 0;
LRESULT ret = ::SendMessageTimeout(hwnd, WM_SETTEXT, 0, (LPARAM)(LPCTSTR)szMsg,
SMTO_BLOCK, 1000 * 1000, &dwpRet);
if (!ret)
{
DWORD dwErr = GetLastError();
}
}
}
return 0;
}
protected:
const char* m_lpszFile;
static const char* infomation[3];
int m_nLine;
int m_nLevel;
};
const char* _CDT::infomation[3] = { "Error", "Warning", "Trace" };
//定义_DT启用DT,DW,DE输出
//undef _DT禁用DT,DW,DE输出,禁用后,这些宏不会对程序产生任何影响,也不会向程序增加__FILE__等字符串.
#define _DT
//#undef _DT
#ifdef _DT
//这里并没有定义为DT(X) ...(X)的形式,而是定义了DT 用一个类 重载了它的operator()方法,创造临时对象,这样就做到了类型的检查
#define DT (_CDT( __FILE__, __LINE__,DT_TRACE))
#define DW (_CDT( __FILE__, __LINE__,DT_WARNNING))
#define DE (_CDT( __FILE__, __LINE__,DT_ERROR))
#else
#define DT 0
#define DW 0
#define DE 0
#endif
#endif
// Dt.cpp : Defines the entry point for the application.
// 这里的Dt.cpp和上面的dt.h 不在一个工程里,不要弄错呀
#include "stdafx.h"
#include "Dt.h"
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // current instance
WCHAR szTitle[MAX_LOADSTRING]; // The title bar text
WCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
//Edit,用来输出调试信息的
HWND hEditWindow;
ULONG nSize = 1;
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
// TODO: Place code here.
// Initialize global strings
LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadStringW(hInstance, IDC_DT, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_DT));
MSG msg;
// Main message loop:
while (GetMessage(&msg, nullptr, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEXW wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_DT));
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
return RegisterClassExW(&wcex);
}
//
// FUNCTION: InitInstance(HINSTANCE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
// create a edit save print text.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
hInst = hInstance; // Store instance handle in our global variable
HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);
if (!hWnd)
{
return FALSE;
}
RECT rect;
GetClientRect(hWnd, &rect);
hEditWindow = CreateWindow(L"EDIT", nullptr, WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | ES_MULTILINE | ES_WANTRETURN | ES_NOHIDESEL
, rect.left, rect.top, rect.right, rect.bottom, hWnd, nullptr, nullptr, nullptr);
//设置只读属性
PostMessageW(hEditWindow, EM_SETREADONLY, 1, 0);
LPCSTR lpThankInfomation = "Thank you for use this debug tool!";
nSize += strlen(lpThankInfomation);
SetWindowTextA(hEditWindow, lpThankInfomation);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
// WM_SETTEXT - set print window text
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_COMMAND:
{
int wmId = LOWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_CLEAR:
{
LPCSTR lpThankInfomation = "Thank you for use this debug tool!";
nSize = strlen(lpThankInfomation)+1;
SetWindowTextA(hEditWindow, lpThankInfomation);
}
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
break;
case WM_SETTEXT:
{
//拦截设置窗口标题的这个消息,把它改成输出调试信息
LPCSTR lpTitle = (LPCSTR)lParam;
nSize += strlen(lpTitle) + 2;
LPSTR lpBuffer = (LPSTR)malloc(nSize);
GetWindowTextA(hEditWindow, lpBuffer, nSize);
strcat_s(lpBuffer, nSize, "\r\n");
strcat_s(lpBuffer, nSize, lpTitle);
SetWindowTextA(hEditWindow, lpBuffer);
free(lpBuffer);
return 0;
}
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code that uses hdc here...
EndPaint(hWnd, &ps);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}
