📄 undebugdlg.cpp
字号:
// UnDebugDlg.cpp : implementation file
//
#include "stdafx.h"
#include "UnDebug.h"
#include "UnDebugDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include <tlhelp32.h>
/////////////////////////////////////////////////////////////////////////////
// CUnDebugDlg dialog
CUnDebugDlg::CUnDebugDlg(CWnd* pParent /*=NULL*/)
: CDialog(CUnDebugDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CUnDebugDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CUnDebugDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CUnDebugDlg)
DDX_Control(pDX, IDC_TREE1, m_tree);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CUnDebugDlg, CDialog)
//{{AFX_MSG_MAP(CUnDebugDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CUnDebugDlg message handlers
BOOL CUnDebugDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
DetectDebug();
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CUnDebugDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CUnDebugDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CUnDebugDlg::DetectDebug()
{
HANDLE handle=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
PROCESSENTRY32* info=new PROCESSENTRY32;
info->dwSize=sizeof(PROCESSENTRY32);
int i=0;
HTREEITEM hItem[100];
int MyParentProcessID=0;//自身的父进程ID
int ExplorerProcessID=0;//Explorer.exe的进程ID
if (Process32First(handle,info))
{
while (Process32Next(handle,info))
{
CString exe;
exe.Format("%s",info->szExeFile);
CString ProcessID;
ProcessID.Format("进程ID:%d",info->th32ProcessID);
CString ParentID;
ParentID.Format("父进程ID:%d",info->th32ParentProcessID);
//比较进程名,这里忽略大小写
if (stricmp(exe.GetBuffer(exe.GetLength()),"explorer.exe")==0)
ExplorerProcessID=info->th32ProcessID;//获得EXPLORER的进程ID
//通过结构info->szExeFile获得的文件名在WIN2K/XP中无文件的详细路径
//但是在WIN98却有详细路径,此时可通过GetModuleFileName获取文件名来比较
if (stricmp(exe.GetBuffer(exe.GetLength()),"UnDebug.exe")==0)
MyParentProcessID=info->th32ParentProcessID;//获得自身父进程ID
hItem[i]=m_tree.InsertItem(exe,TVI_ROOT,TVI_LAST);
m_tree.InsertItem(ProcessID,hItem[i],TVI_LAST);
m_tree.InsertItem(ParentID,hItem[i],TVI_LAST);
m_tree.Expand(hItem[i],TVE_EXPAND);
i++;
}
}
CString sta;
sta.Format("进程总数目:%d 个",i);
SetDlgItemText(IDC_STATUS,sta);
CloseHandle(handle);
delete info;
//检测自身的父进程是否是EXPLORER
if (MyParentProcessID!=ExplorerProcessID)
{
MessageBox("注意:程序检测到了调试器,该调试器将被结束进程...");
//MyParentProcessID是自身程序的父进程,也就是“调试器”
HANDLE handle=OpenProcess(PROCESS_ALL_ACCESS,TRUE,MyParentProcessID)
if(handle!=NULL)
TerminateProcess(handle,0);
//exit(1); //自身也强行退出
}
else
MessageBox("注意:没有检测到调试器...");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -