📄 bodyprotectdlg.cpp
字号:
// BodyProtectDlg.cpp : implementation file
//
#include "stdafx.h"
#include "BodyProtect.h"
#include "BodyProtectDlg.h"
#include "dialogs.h"
#include "des.h"
#include "Enc_Blowfish\blowfish.h"
#include "GenLib\Security\filewipe.h"
//#include "FileEnc\processing.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBodyProtectDlg dialog
CConfigData CBodyProtectDlg::c_configData;
CBodyProtectDlg::CBodyProtectDlg(CWnd* pParent /*=NULL*/)
: CDialog(CBodyProtectDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CBodyProtectDlg)
// 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 CBodyProtectDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBodyProtectDlg)
DDX_Control(pDX, IDC_LIST1, m_listProcess);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBodyProtectDlg, CDialog)
//{{AFX_MSG_MAP(CBodyProtectDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_COMMAND(ID_VIEW_MAIN_WINDOW, OnViewMainWindow)
ON_UPDATE_COMMAND_UI(ID_VIEW_MAIN_WINDOW, OnUpdateViewMainWindow)
ON_MESSAGE(WM_ICON_NOTIFY, OnTrayNotification)
ON_BN_CLICKED(IDC_BTN_PROTECT, OnBtnProtect)
ON_BN_CLICKED(IDC_BTN_CLOSEAPP, OnBtnCloseapp)
ON_BN_CLICKED(IDC_BTN_QUITAPP, OnBtnQuitapp)
ON_BN_CLICKED(IDC_BTN_CONFIG, OnBtnConfig)
ON_BN_CLICKED(IDC_BTN_RESTORE, OnBtnRestore)
ON_BN_CLICKED(IDC_BTN_SETPASS, OnBtnSetpass)
ON_WM_SYSCOMMAND()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBodyProtectDlg message handlers
static BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam)//,CString strExeCode)
{
CListBox * list=(CListBox *)lParam;
char buf[1024];
GetWindowText(hwnd,buf,256);
CString strTitle;
strTitle.Format("%s",buf);
if(strTitle.GetLength()>0)
{
CString strExeCode=CBodyProtectDlg::c_configData.m_strExeCode;
if(strTitle.Find(strExeCode)>=0){
int idx=list->AddString(strTitle);
list->SetItemData(idx,(DWORD)hwnd);
}
}
return TRUE;
}
//配置文件的格式
/*
格式文件标记:"BodyProtectConfigure"
密码长度: int
密码[.....]
加密文件个数:int
加密文件名长度:int
加密文件名字符串 [.....]
*/
//根据文件的全路径名,获得文件全名
static CString GetFileNameFromFullPath(const CString& strFullpath){
CString sPath=strFullpath;
int nLength=sPath.GetLength();
int nFound=sPath.ReverseFind('\\');
CString sFile=strFullpath.Right(nLength-nFound-1);
return sFile;
}
void CBodyProtectDlg::GetProcessList()
{
CListBox * list=(CListBox *)GetDlgItem(IDC_LIST1);
list->ResetContent();
FARPROC EnumProcInstance=MakeProcInstance((FARPROC)EnumWindowsProc,AfxGetInstanceHandle());//,strExeCode);
EnumWindows((WNDENUMPROC)EnumProcInstance,(LPARAM)list);
FreeProcInstance(EnumProcInstance);
CenterWindow();
}
BOOL CBodyProtectDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 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
// TODO: Add extra initialization here
//创建托盘图标
if (!m_TrayIcon.Create(this, WM_ICON_NOTIFY,"木马实时保护程序", NULL, IDR_POPUPMENU))
return -1;
m_TrayIcon.SetIcon(IDI_ICONTRAY);
SetMenu(NULL);
//查找配置文件,如果不存在,则创建空的文件
TCHAR exeFullPath[MAX_PATH];
GetModuleFileName(NULL,exeFullPath,MAX_PATH);
CString strAppPath=exeFullPath;
strAppPath.TrimRight(strrchr(exeFullPath,'\\'));
m_strAppPath=strAppPath;
CFileFind find;
CString strFile=strAppPath+"\\Config.dat";
if(!find.FindFile(strFile)) {
CConfigData config;
config.WriteConfigFile(strFile);
//创建保存加密文件的目录
CString strEncfilePath=strAppPath+"\\EncData";
CreateDirectory(strEncfilePath,NULL);
}
else{
CBodyProtectDlg::c_configData.ReadConfigFile(strFile);
}
GetProcessList();
bool bProtected=IsDataProtected();
SetItemState(bProtected);
return TRUE; // return TRUE unless you set the focus to a control
}
LRESULT CBodyProtectDlg::OnTrayNotification(WPARAM wParam, LPARAM lParam)
{
if (wParam != IDR_POPUPMENU)
return 0L;
CMenu menu, *pSubMenu;
if (LOWORD(lParam) == WM_RBUTTONUP)
{
CPoint pos;
GetCursorPos(&pos);
if (!menu.LoadMenu(IDR_POPUPMENU)) return 0;
if (!(pSubMenu=menu.GetSubMenu(0))) return 0;
::SetMenuDefaultItem(pSubMenu->m_hMenu, 3, TRUE);
SetForegroundWindow();
pSubMenu->TrackPopupMenu(TPM_RIGHTALIGN | TPM_BOTTOMALIGN | TPM_RIGHTBUTTON, pos.x, pos.y,
this);
menu.DestroyMenu();
}
else
if (LOWORD(lParam) == WM_LBUTTONDBLCLK)
{
if (!menu.LoadMenu(IDR_POPUPMENU)) return 0;
if (!(pSubMenu = menu.GetSubMenu(0))) return 0;
SetForegroundWindow();
//激活第2个菜单项
SendMessage(WM_COMMAND, pSubMenu->GetMenuItemID(1), 0);
menu.DestroyMenu();
}
return 0;
}
void CBodyProtectDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else if(nID==SC_MINIMIZE)
{
ShowWindow(SW_SHOWMINIMIZED);
ShowWindow(SW_HIDE);
}
else
CDialog::OnSysCommand(nID, lParam);
}
// 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 CBodyProtectDlg::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 CBodyProtectDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CBodyProtectDlg::OnViewMainWindow()
{
// TODO: Add your command handler code here
if(IsWindowVisible())
{
ShowWindow(SW_SHOWMINIMIZED);
ShowWindow(SW_HIDE);
}
else
{
ShowWindow(SW_SHOW);
ShowWindow(SW_RESTORE);
}
bool bProtected=IsDataProtected();
SetItemState(bProtected);
}
void CBodyProtectDlg::OnUpdateViewMainWindow(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(IsWindowVisible());
}
void CBodyProtectDlg::OnBtnProtect()
{
Protect();
}
void CBodyProtectDlg::OnBtnRestore()
{
// TODO: Add your control notification handler code here
Restore();
}
void CBodyProtectDlg::OnBtnCloseapp()
{
// TODO: Add your control notification handler code here
CListBox * list=(CListBox *)GetDlgItem(IDC_LIST1);
int idx=list->GetCurSel();
if(idx==LB_ERR)
{
MessageBox("You must select a window to active!",
"Error",MB_OK|MB_APPLMODAL);
return;
}
HWND hWnd=(HWND)list->GetItemData(idx);
::PostMessage(hWnd,WM_CLOSE,0,0L);
//EndDialog(IDOK);
}
void CBodyProtectDlg::OnBtnQuitapp()
{
// TODO: Add your control notification handler code here
CListBox * list=(CListBox *)GetDlgItem(IDC_LIST1);
int idx=list->GetCurSel();
if(idx==LB_ERR)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -