金山卫士是一款由金山网络技术有限公司出品的查杀木马能力强、检测漏洞快、体积小巧的免费安全软件。它采用金山领先的云安全技术,不仅能查杀上亿已知木马,还能5分钟内发现新木马;漏洞检测针对windows7优化,速度更快;更有实时保护、插件清理、修复IE等功能,全面保护电脑的系统安全。
源码分为七个部分:
pcmamager :开源卫士整体
kclear :卫士垃圾清理
ksm :卫士主界面
karpfw :卫士ARP防火墙
sysopt :系统优化 之 开机加速器
bksafevul:漏洞扫描器
ppro:隐私保护器
项目目录如图:
下面进行代码分析,先从bksafevul(漏洞扫描器)开始。
项目如图:
ksafevul.exe 提供可视化的漏洞修复功能
ksafevul.dll 漏洞修复引擎
leakscan_test.exe 命令行版本例子程序
data\*.* 漏洞库目录
office.dat 微软office 32位软件补丁
office64.dat 微软office 64位软件补丁
system.dat windows 32位补丁
system64.dat window 64位补丁
soft.dat 第三方软件补丁
程序效果如图:
现在根据功能来分析!~
== 漏洞修复sdk 功能 =
1. 漏洞的快速扫描,主要是坚持系统是否存在补丁,一旦发现补丁就快速返回,另外针对x64 位系统只能通过接口来获取补丁的做了速度优化。
2. 漏洞全盘扫描,获取全部补丁,以及下载等。
3. 漏洞的修复。
4. 漏洞库升级,需要knup.dll。
程序入口代码:
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int /*nCmdShow*/) { # ifdef _DEBUG //bkconsole theConsole; # endif HRESULT hRet = E_FAIL; // g_dwMainThreadId = ::GetCurrentThreadId(); //初始化路径 操作注册表 hRet = _Module.Init(hInstance); if (FAILED(hRet)) return -1; //确认管理员权限 if (FALSE == _Module.CheckIntegrityLevel()) return -2; //初始化控件 ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); //加载riched20.dll字符编辑器相关文件。 _Module.InitRichEdit2(); //运行主程序 接下来就是加载图片了(BkResManager::SetResourcePath(strPath)) …… _Module.RunMain(); ::CoUninitialize(); return 0; }
//加载UI void CBKSafeVulModule::_InitUIResource() { BkString::Load(IDR_BK_STRING_DEF); BkFontPool::SetDefaultFont(BkString::Get(IDS_APP_FONT), -12); BkSkin::LoadSkins(IDR_BK_SKIN_DEF); BkStyle::LoadStyles(IDR_BK_STYLE_DEF); }
//开始扫描漏洞 void CBeikeSafeMainDlg::StartScanLeak() { m_viewVulfix.ShowWindow(SW_SHOW); if(!m_bVulfixInited || m_bVulfixRescanRequired) { BOOL toRescan = TRUE; if(m_bVulfixRescanRequired && theEngine && theEngine->m_isRepairing) { toRescan = FALSE; } m_bVulfixInited = TRUE; m_bVulfixRescanRequired = FALSE; if(toRescan) m_viewVulfix.m_viewSoftVul.InitEnv(); } }
//初始化扫描引擎 void CBeikeVulfixHandler::InitEnv() { if(!theEngine) { theEngine = new CVulEngine; theEngine->_InitFunctions(); m_WinInfo.Init(); //m_WinInfo64 = IsWin64(); } //开始扫描 PostMessage( WMH_SCAN_START, 0, 0); }
//对应的功能函数声明 LRESULT OnScanStart(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnScanDone(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); bool _RepairSingle( int arrVulIds, T_VulListItemData* pItemData );
//开始扫描 LRESULT CBeikeVulfixHandler::OnScanStart( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled ) { OnBkBtnScan(); return 0; }
void CBeikeVulfixHandler::OnBkBtnScan() { if(m_firstInited) { // Clean downloaded files BOOL bSave = BKSafeConfig::Get_Vulfix_SaveDownFile(); if( !bSave ) theEngine->m_fixLog.CleanFiles(FALSE, NULL); m_firstInited = FALSE; SetItemVisible(1015, !theEngine->IsSystemSupported()); } ResetListCtrl(m_wndListCtrlVul); if( theEngine->ScanVul( m_RefWin.m_hWnd ) ) { m_dwScanBeginTime = GetTickCount(); m_bScanStarted = FALSE; m_nScanState = 0; m_nTotalItem = 0; m_nCurrentItem = 0; _SetDisplayState(SCANSTATE_SCANNING); _SetScanProgress( 0 ); m_RefWin.SetTimer(0, 200, NULL); m_wndListCtrlVul.SetEmptyString(BkString::Get(IDS_VULFIX_5027)); m_RefWin.StartIconAnimate( IDC_IMG_VULFIX_SCAN_ANIMATION, IDC_PROGRESS_VULFIX_SCANNING, 300); SetItemDWordAttribute(IDC_PROGRESS_VULFIX_SCANNING, "showpercent", 0); } }
//修复 bool CBeikeVulfixHandler::_RepairSingle( int arrVulIds, T_VulListItemData* pItemData ) { if(!theEngine->CheckRepairPrequisite(pItemData->nType==VTYPE_OFFICE)) return FALSE; CSimpleArray<int> vulId; CSimpleArray<int> softId; if ( pItemData->nType == VTYPE_SOFTLEAK ) softId.Add(arrVulIds); else vulId.Add(arrVulIds); m_nRepairTotal = 1; m_nRepairInstalled = 0; m_nRepairDownloaded = 0; m_nRepairProcessed = 0; m_nRepairCurrentRate = 0; m_RefWin.StartIconAnimate(30100); _SetDisplayState(SCANSTATE_REPAIRING); _UpdateRepairTitle(); // Fill the list ctrl ResetListCtrl(m_wndListCtrlVulFixing); AppendItem2RepairList( m_wndListCtrlVulFixing, new T_VulListItemData( *pItemData ) ); // Fix return theEngine->RepairAll( m_RefWin.m_hWnd, vulId, softId); }
测试漏洞代码:
int _tmain(int argc, _TCHAR* argv[]) { _tsetlocale(0, _T("chs")); //模拟参数 argc = 2; argv[0] = L""; argv[1] = L"1"; if ( argc < 2 ) { _tprintf( _T("参数:\n") ); _tprintf( _T("1: 测试快速扫描\n") ); _tprintf( _T("2: 测试全面扫描\n") ); _tprintf( _T("3: 测试修复功能\n") ); return 0; } if ( 0 == _tcsicmp( argv[1], _T("1") ) ) { _tprintf(_T("测试快速扫描\n")); PressAnyKeyToContinue(); TestQuickScan(); goto Exit0; } if ( 0 == _tcsicmp( argv[1], _T("2") ) ) { _tprintf(_T("测试全面扫描\n")); PressAnyKeyToContinue(); TestFullScan(); goto Exit0; } if ( 0 == _tcsicmp( argv[1], _T("3") ) ) { _tprintf(_T("测试修复功能,为避免风险,可选和软件漏洞不做修复\n")); PressAnyKeyToContinue(); TestRepair(); } Exit0: PressAnyKeyToContinue(); return 0; }
TestQuickScan() HRESULT WINAPI ExpressScanLeak(IVulCollection **pVulCollection, DWORD dwFlags, BOOL bQuickScan); 如果成功, 先调用 IVulCollection::get_Status 如果S_OK, 则根据status 来判断是否有漏洞风险, -1, 0 表示可能无风险, 1 表示可能有风险 否则,根据 IVulCollection::get_VulCount 和 IVulCollection::get_Item 来判断是否有漏洞存在, 具体看例子中函数 DumpIVulCollection
TestRepair() 使用接口 IVulfix 的方法 Scan 扫描漏洞, 扫描完成后使用方法 GetResults, GetSoftVuls 分别获取系统漏洞列表, 和软件漏洞列表 使用接口 IRepairVul 修复漏洞
漏洞修复测试代码结束!
进入karpfw(卫士ARP防火墙 英文: Kavass arp firewall)。程序效果如图:
代码分析:
//程序的初始化 LRESULT CMainDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) { HICON hIcon = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME), IMAGE_ICON, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR); SetIcon(hIcon, TRUE); HICON hIconSmall = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME), IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR); SetIcon(hIconSmall, FALSE); // 创建大字体 CFontHandle hFont = GetFont(); LOGFONT logFont = { 0 }; hFont.GetLogFont(&logFont); logFont.lfHeight = -14; logFont.lfWeight = FW_BOLD; m_fontBig.CreateFontIndirect(&logFont); DoDataExchange(); CString strTitle = _T("金山卫士ARP防火墙"); SetBkSkin(m_bmpSkin); InitSkinDialog(m_bmpCloseBtn, NULL, strTitle); SetWindowPos(NULL, 0, 0, 496, 184, SWP_NOMOVE); CenterWindow(); m_btnEnable.InitButton(m_bmpEnableBtn); m_btnEnable.SetWindowText(_T("")); m_btnEnable.SetWindowPos(NULL, 412, 53, 0, 0, SWP_NOSIZE); m_btnDisable.InitButton(m_bmpDisableBtn); m_btnDisable.SetWindowText(_T("")); m_btnDisable.SetWindowPos(NULL, 412, 53, 0, 0, SWP_NOSIZE); m_lnkSetting.SetWindowPos(NULL, 424, 100, 0, 0, SWP_NOSIZE); //GetDlgItem(IDC_LOG_GROUP).SetWindowPos(NULL, 11, 120, 476, 104, 0); GetDlgItem(IDC_TXT_LOG).SetWindowPos(NULL, 20, 136, 0, 0, SWP_NOSIZE); m_lnkVersion.SetWindowPos(NULL, 20, 160, 0, 0, SWP_NOSIZE); m_lnkBBS.SetWindowPos(NULL, 120, 160, 0, 0, SWP_NOSIZE); m_lnkViewLog.SetWindowPos(NULL, 460, 136, 0, 0, SWP_NOSIZE); GetDlgItem(IDC_LINE).SetWindowPos(NULL, 20, 127, 466, 1, 0); CString strVersion = _T("版本:"); strVersion += _Module.GetProductVersion(); m_lnkVersion.SetWindowText(strVersion); if (m_piArpSetting) { m_piArpSetting->IsArpFwEnable(&m_bFwEnable); } //更新UI UpdateUI(); //创建线程开始工作 StartWork(); return TRUE; }
//工作线程 UINT CMainDlg::WorkThreadProc(LPVOID pSetting) { CMainDlg* pThis = (CMainDlg*)pSetting; IArpFwSetting* piArpSetting = NULL; HANDLE hExitSignal = NULL; HRESULT hRetCode; wchar_t szLastLog[512] = { 0 }; KAV_PROCESS_ERROR(pThis); piArpSetting = pThis->m_piArpSetting; KAV_PROCESS_ERROR(piArpSetting); hExitSignal = pThis->m_hExitSignal; KAV_PROCESS_ERROR(hExitSignal); for (;;) { BOOL bEnable = FALSE; if (::WaitForSingleObject(hExitSignal, 1000) == WAIT_OBJECT_0) break; hRetCode = piArpSetting->IsArpFwEnable(&bEnable); if (FAILED(hRetCode)) continue; pThis->PostMessage(WM_ARPFW_STATE, bEnable, 0); hRetCode = piArpSetting->GetLastLog(512, szLastLog); if (FAILED(hRetCode)) continue; pThis->SendMessage(WM_ARPFW_LASTLOG, (WPARAM)szLastLog); } Exit0: _endthreadex(0); return 0; }
//控制arp的对象 KComInterfacePtr<IArpFwSetting> m_spIArpFwSetting; KComInterfacePtr<IKArpSp> m_spIArpFwSp;
//实例化 m_spIArpFwSetting.LoadInterface(_T("arpsetting.dll")); m_spIArpFwSp.LoadInterface(_T("arpproxy.dll"));
//加载 BOOL CArpSetting::Install() { BOOL retval = FALSE; BOOL bRetCode; KAV_PROCESS_ERROR(m_spIArpFwSetting); bRetCode = m_spIArpFwSetting->InstallArpFw(); KAV_PROCESS_ERROR(bRetCode); retval = TRUE; Exit0: return retval; } //卸载 BOOL CArpSetting::UnInstall() { BOOL retval = FALSE; BOOL bRetCode; KAV_PROCESS_ERROR(m_spIArpFwSetting); bRetCode = m_spIArpFwSetting->UnInstallArpFw(); KAV_PROCESS_ERROR(bRetCode); retval = TRUE; Exit0: return retval; } //开启 BOOL CArpSetting::StartSP() { BOOL retval = FALSE; BOOL bRetCode; KAV_PROCESS_ERROR(m_spIArpFwSp); KxeBaseInit(); bRetCode = m_spIArpFwSp->Start(); KAV_PROCESS_ERROR(bRetCode); retval = TRUE; Exit0: return retval; } //停止 BOOL CArpSetting::StopSP() { BOOL retval = FALSE; BOOL bRetCode; KAV_PROCESS_ERROR(m_spIArpFwSp); bRetCode = m_spIArpFwSp->Stop(); KAV_PROCESS_ERROR(bRetCode); KxeBaseUnInit(); retval = TRUE; Exit0: return retval; }
接着进入kclear(卫士垃圾清理 英文: Kavass Clear)!
项目如图:
效果如图:
该项目需要用到ATL_Server开发包!
关键代码:
//清除实例对象 IKClear* m_piKClear;
//初始化清除实例对象 BOOL MainWnd::InitKClear() { BOOL retval = FALSE; CreateKClearObject_t CreateKClearObject = NULL; TCHAR szKClearPath[MAX_PATH] = { 0 }; HRESULT hr; HMODULE hKClear = NULL; IKClear* piKClear = NULL; HWND hWnd = NULL; if (!m_hKClear) { ::GetModuleFileName(NULL, szKClearPath, MAX_PATH); PathRemoveFileSpec(szKClearPath); PathAppend(szKClearPath, _T("kclear.dll")); hKClear = LoadLibrary(szKClearPath); if (!hKClear) goto clean0; m_hKClear = hKClear; } if (!m_piKClear) { CreateKClearObject = (CreateKClearObject_t)GetProcAddress(m_hKClear, "CreateKClearObject"); if (!CreateKClearObject) goto clean0; hr = CreateKClearObject(__uuidof(IKClear), (void**)&piKClear); if (FAILED(hr)) goto clean0; m_piKClear = piKClear; } if (!m_wndKClear.m_hWnd) { hWnd = m_piKClear->CreateKClear(m_hWnd); m_wndKClear.m_hWnd = hWnd; m_wndKClear.ShowWindow(SW_SHOW); } retval = TRUE; clean0: if (!retval) { UnInitKClear(); } return retval; } //释放清除对象资源 void MainWnd::UnInitKClear() { if (m_wndKClear.m_hWnd) { m_wndKClear.DestroyWindow(); } // if (m_piKClear) // { // m_piKClear->Release(); // m_piKClear = NULL; // } // // if (m_hKClear) // { // FreeLibrary(m_hKClear); // m_hKClear = NULL; // } }
int MainWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) { SetWindowPos(NULL, 0, 0, 800, 570, SWP_NOREPOSITION); CenterWindow(); InitKClear(); return 0; }
清除操作完毕!~~
接着进入sysopt(系统优化 开机加速)!
项目如图:
效果如图:
//关键对象
CBeikeSafeSysOptUIHandler* m_sysoptHandler;
//构造 m_sysoptHandler = new CBeikeSafeSysOptUIHandler(this);
//初始化 (*m_sysoptHandler).Init(); (*m_sysoptHandler).FirstShow();
//操作关键类 class CBeikeSafeSysOptUIHandler : public IEnumRunCallBackNull, public IAutoOptLstCBack, public IListOpCallback { public: CBeikeSafeSysOptUIHandler(CBeikeSafeMainDlg* refDialog) : m_dlg(refDialog) , m_pRunOptEng(NULL) , m_nState(STATE_RUNOPT_NULL) , m_bFirstShowed(FALSE) , m_bFirstScanRunEnd(FALSE) , m_bSkipToOnekeyOpt(FALSE) , m_hOptimizeThread(NULL) , m_bOpting(FALSE) , m_bRefreshList(FALSE) , m_nIgnoredCount(0) , m_bReportOnekeyOpt(TRUE) { } virtual ~CBeikeSafeSysOptUIHandler() { if (m_pRunOptEng!=NULL) { CRunOptLoader::GetGlobalPtr()->FreeOptEng(m_pRunOptEng); m_pRunOptEng = NULL; } if (m_hOptimizeThread != NULL) { ::CloseHandle(m_hOptimizeThread); m_hOptimizeThread = NULL; } } public: BOOL IsOpPermit() { return (m_nState==STATE_RUNOPT_NULL); } void Init(); void FirstShow(); void SecondShow(); BOOL OnBkRunTypeSelChange(int nTabItemIDOld, int nTabItemIDNew); BOOL OnBkSysOptSelChange(int nTabItemIDOld, int nTabItemIDNew); void InitEng() { if (m_pRunOptEng==NULL) m_pRunOptEng = CRunOptLoader::GetGlobalPtr()->GetOptEng(); } BOOL FindRunItem(CKsafeRunInfo* pInfo); BOOL _FindRunItem(CKsafeRunInfo* pInfo); void EndScan(); void RestoreEnd(); void PostRestoreRunItem(DWORD nType,BOOL bEnable,LPCTSTR lpName); LRESULT OnWmScanEnd(UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT OnWmRestoreEnd(UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT OnWmFindItem(UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT OnWmFirstIn(UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT OnOnekeyOptEnd(UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT OnRefreshOnekeyOpt(UINT uMsg, WPARAM wParam, LPARAM lParam); BOOL OnClickButton(CKsafeRunInfo* pInfo); BOOL OnDeleteItem(CKsafeRunInfo* pInfo); BOOL OnClickLabel(DWORD nIndex, CKsafeRunInfo* pInfo); void ClickCheck(); void UpdateClearInterface(int nSel); public: void OnBkShowDisableItem(); void OnListReSize(CRect rcWnd); void RefreshItemList(); void OnBkCancelAll(); void OnBkCancelAll2(); void OnBkBtnWaitMore(); void OnBkRunOptTopMore(); void RefreshCLRState(int nSel=-1, BOOL bDowning=FALSE); void RefreshUpdateState(int nSel=-1, BOOL bDowning=FALSE); void RefreshTabNumber(DWORD nNewTab=-1); void SetTopRunDiv(DWORD nType); void GetRunListByCheckState(); void InitAutoOptList(); void OnBkBtnDoOpt(); void OnAutoOptCheckAll(); void OnAutoOptCheckAll2(); void OnBkBtnRefresh(); void OnBkBtnContinueOpt(); void OnBkLnkViewRun(); void OnBkLnkViewServ(); void OnBkLnkViewTask(); void OnTimer(UINT_PTR nIDEvent);//优化时定时器刷新显示loading动画 void ShowOptDetail(); void OnBkLnkCleanTrash(); void OnBkLnkSoftMgr_ZJBJ(); void OnBkCheckHideSystem(); void ShowNoTaskInfo(); static DWORD WINAPI OneKeyOptProc(LPVOID lpParam); BOOL Is3XXInstalled(); void OnBkLnkShowIgnored(); void OnBkLnkAddToIgnored(); void SaveIgnoreID(); void LoadIgnoredID(); void GetIgnoredItem(); void OnBkLnkRefreshList(); protected: CBeikeSafeMainDlg* m_dlg; CRunOptListView m_runList; IRunOptimizeEng* m_pRunOptEng; DWORD m_nState; BOOL m_bFirstShowed; BOOL m_bFirstScanRunEnd; BOOL m_bOpting; BOOL m_bSkipToOnekeyOpt; BOOL m_bRefreshList; //runlist刷新后置为TRUE,为TRUE则InitAutoOptList,再置为FALSE BOOL m_bReportOnekeyOpt; //进入一键优化tab,是否要上报 CAutoRunOptList m_list; HANDLE m_hOptimizeThread; CString m_strIniFilePath; CString m_strIgnoredIniPath; int m_nIgnoredCount; CSimpleArray<int> m_arrayIgnoredID; CSimpleArray<CKsafeRunInfo*> m_arrayItem; //所有启动项 CSimpleArray<CKsafeRunInfo*> m_arrayIgnoredItem; //忽略项 CSimpleArray<CKsafeRunInfo*> m_arrayOnekeyOptItem; //除去忽略项之后的启动项 public: BK_NOTIFY_MAP(IDC_RICHVIEW_WIN) BK_NOTIFY_TAB_SELCHANGE(IDC_TAB_RUNOPT_TYPE,OnBkRunTypeSelChange) BK_NOTIFY_TAB_SELCHANGE(IDC_TAB_SYSOPT_LEFT,OnBkSysOptSelChange) BK_NOTIFY_ID_COMMAND(IDC_CHECKBOX_SHOW_DISABLE,OnBkShowDisableItem) BK_NOTIFY_ID_COMMAND(IDC_LBL_RUNOPT_REFRESH,OnBkLnkRefreshList) BK_NOTIFY_ID_COMMAND(IDC_BTN_SYSOPT_WAIT_MORE,OnBkBtnWaitMore) BK_NOTIFY_ID_COMMAND(IDC_BTN_RUNOPT_CANCEL_ALL,OnBkCancelAll) BK_NOTIFY_ID_COMMAND(IDC_LBL_RUNOPT_TOP_MORE,OnBkRunOptTopMore) BK_NOTIFY_ID_COMMAND(IDC_BTN_RUN_AUTOOPT_DO,OnBkBtnDoOpt) BK_NOTIFY_ID_COMMAND(IDC_CHECKBOX_AUTOOPT_ALL,OnAutoOptCheckAll) BK_NOTIFY_ID_COMMAND(IDC_CHECKBOX_AUTOOPT_ALL2,OnAutoOptCheckAll2) BK_NOTIFY_ID_COMMAND(IDC_LNK_AUTOOPT_BTM_REFRESH,OnBkBtnRefresh) BK_NOTIFY_ID_COMMAND(IDC_BTN_AUTOOPT_BTM_CONTINUE,OnBkBtnContinueOpt) BK_NOTIFY_ID_COMMAND(IDC_LNK_SHOW_IGNORED,OnBkLnkShowIgnored) BK_NOTIFY_ID_COMMAND(IDC_LNK_VIEW_IGNORED,OnBkLnkShowIgnored) BK_NOTIFY_ID_COMMAND(IDC_LNK_ADDTO_IGNORED,OnBkLnkAddToIgnored) BK_NOTIFY_ID_COMMAND(IDC_LNK_ADDTO_IGNORED2,OnBkLnkAddToIgnored) BK_NOTIFY_ID_COMMAND(IDC_LNK_VIEW_RUN,OnBkLnkViewRun) BK_NOTIFY_ID_COMMAND(IDC_LNK_VIEW_SERV,OnBkLnkViewServ) BK_NOTIFY_ID_COMMAND(IDC_LNK_VIEW_TASK,OnBkLnkViewTask) BK_NOTIFY_ID_COMMAND(IDC_LNK_AUTOOPT_CANCELALL,OnBkCancelAll2) BK_NOTIFY_ID_COMMAND(IDC_CHECKBOX_RUNOPT_HIDE_SYSTEM,OnBkCheckHideSystem) BK_NOTIFY_REALWND_RESIZED(IDC_LST_RUNOPT, OnListReSize) BK_NOTIFY_MAP_END() BEGIN_MSG_MAP_EX(CBeikeSafeSysOptUIHandler) MSG_WM_TIMER(OnTimer) //优化时定时器刷新显示loading动画 MSG_BK_NOTIFY(IDC_RICHVIEW_WIN) MESSAGE_HANDLER_EX(MSG_SYSOPT_RUN_SCAN_END, OnWmScanEnd) MESSAGE_HANDLER_EX(MSG_SYSOPT_RUN_RESTORE_END, OnWmRestoreEnd) MESSAGE_HANDLER_EX(MSG_SYSOPT_RUN_SCAN_FIND, OnWmFindItem) MESSAGE_HANDLER_EX(MSG_SYSOPT_RUN_FIRST_IN, OnWmFirstIn) MESSAGE_HANDLER_EX(MSG_SYSOPT_ONEKEYOPT_END, OnOnekeyOptEnd); MESSAGE_HANDLER_EX(MSG_SYSOPT_REFRESH_ONEKEYOPT, OnRefreshOnekeyOpt) END_MSG_MAP() };
接着进入ksm(金山卫士主界面)了!
效果如图:
//显示视图 CEmbeddedView m_viewVulfix;
m_viewVulfix.Create(GetViewHWND(), NULL, WS_CHILD|WS_CLIPCHILDREN, 0, 3000); ATLVERIFY( m_viewVulfix.Load( IDR_BK_VULDLG_MAIN ) ); m_viewVulfix.m_viewSoftVul.SetMainDlg( this ); m_viewVulfix.Init(m_hWnd);
//操作关键类 class CBeikeVulfixHandler : public CBaseViewHandler<CEmbeddedView> , public CBkSafeUIHandlerBase { public: CBeikeVulfixHandler(CEmbeddedView &mainDlg); ~CBeikeVulfixHandler(void); public: BOOL Init(HWND hMainWnd, HWND hWndParent); void InitEnv(); void SetMainDlg(CBeikeSafeMainDlg *pMainDlg); STATE_CLOSE_CHECK CloseCheck(); void _SetDisplayState(TScanSoftState st, TRepairSubState subst=REPAIRSTATE_ING, LPCTSTR szMsg=NULL); protected: CBeikeSafeMainDlg *m_MainDlg; HWND m_hMainWnd; BOOL m_firstInited; DWORD m_dwPos; CListViewCtrlEx m_wndListCtrlVul, m_wndListCtrlVulFixing; BOOL m_bRelateInfoShowing; CRichEditCtrlEx m_ctlRichEdit; int m_nCurrentRelateInfoItem; CHyperTextCtrl m_ctlNaviLink; bool m_bScanStarted; // 看是否正在扫描xml, 还是还在等待信息(Win7 & Vista) // scan int m_nScanState, m_nTotalItem, m_nCurrentItem; DWORD m_dwScanBeginTime; // Repair int m_nRepairTotal, m_nRepairInstalled, m_nRepairDownloaded, m_nRepairProcessed; int m_nRepairCurrentRate; CString m_strLastScanTime; T_WindowsInfo m_WinInfo; BOOL m_WinInfo64; // INT m_nNumMust, m_nNumOption, m_nNumSP; // BK HANDLER void OnBkBtnSwitchRelateInfo(); void OnBkBtnSelectAll(); void OnBkBtnSelectNone(); void OnBkBtnSelectAllSuggested(); void OnBkBtnSelectAllOptional(); void OnBkBtnIgnore(); // 忽略 void OnBkBtnScan(); void OnBkBtnCancelScan(); void OnBkBtnBeginRepair(); void OnBkBtnCancelRepair(); void OnBkBtnRunBackground(); void OnBkBtnReboot(); void OnBkBtnEnableRelateCOM(); void OnBkBtnDisableRelateCOM(); void OnBkBtnViewInstalled(); void OnBkBtnViewIgnored(); void OnBkBtnViewSupersede(); void OnBkBtnViewInvalid(); void OnBkBtnErrorRepair(); void OnBkBtnVisitVulPurposePage(); void OnBkBtnExport(); void OnListReSize(CRect rcWnd); void OnDownListReSize(CRect rcWnd); public: // WM HANDLER LRESULT OnListBoxVulFixNotify(int idCtrl, LPNMHDR pnmh, BOOL& bHandled); LRESULT OnVulFixEventHandle(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnListLinkClicked(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnScanStart(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnScanDone(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnRepaireDone(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnRichEditLink(int idCtrl, LPNMHDR pnmh, BOOL& bHandled); LRESULT OnStnClickedNavi(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags); protected: int FindListItem( int nID ); void _ShutdownComputer(BOOL bReboot); void _DisplayRelateVulFixInfo( int nItem ); void _SetScanProgress( int nPos ); void _SetRepairProgress( int nPos ); void _UpdateRepairTitle(); void _EnableRelateCOM( BOOL bEnable ); void _FillScanResult(); bool _RepairSingle( int arrVulIds, T_VulListItemData* pItemData ); void _EnableSelectedOpBtn(INT nMust, INT nSP, INT nOption); void _NotifyTrayIcon(LPCTSTR szText, INT nTimeOut, BOOL bDelayShow=TRUE); void _ViewDetail(INT nSelTab); void _UpdateViewDetailBtnsNumber( INT nFixed, INT nIgnored, INT nReplaced, INT nInvalid ); void _PromptAutoShutdown(); void _UpdateScanResultTitle( INT nTipIcon, LPCTSTR szTips ); BOOL _ExportResult( LPCTSTR szFileName, T_ExportInfoArray &arrExportInfo ); public: BK_NOTIFY_MAP(IDC_RICHVIEW_WIN_VULFIX) // 系统漏洞 BK_NOTIFY_ID_COMMAND(IDC_DIV_VULFIX_RESULT_SPLITTER, OnBkBtnSwitchRelateInfo) //选择全部 BK_NOTIFY_ID_COMMAND(IDC_LBL_VULFIX_RESULT_CHECK_ALL, OnBkBtnSelectAll) //一个也不选 BK_NOTIFY_ID_COMMAND(IDC_LBL_VULFIX_RESULT_UNCHECK_ALL, OnBkBtnSelectNone) //全部单选 BK_NOTIFY_ID_COMMAND(IDC_LBL_VULFIX_RESULT_CHECK_OPTIONAL, OnBkBtnSelectAllOptional) //开始修复 BK_NOTIFY_ID_COMMAND(IDC_LBL_VULFIX_RESULT_FIX, OnBkBtnBeginRepair) //开始扫描 BK_NOTIFY_ID_COMMAND(IDC_LBL_VULFIX_RESULT_RESCAN, OnBkBtnScan) //忽略 BK_NOTIFY_ID_COMMAND(IDC_LBL_VULFIX_RESULT_IGNORE, OnBkBtnIgnore) // 扫描中 BK_NOTIFY_ID_COMMAND(IDC_BTN_VULFIX_SCAN_CANCEL, OnBkBtnCancelScan) // 漏洞修复 BK_NOTIFY_ID_COMMAND(IDC_LBL_VULFIX_REPAIR_TOP_CANCEL, OnBkBtnCancelRepair) //后台 BK_NOTIFY_ID_COMMAND(IDC_LBL_VULFIX_REPAIR_TOP_BACKRUN, OnBkBtnRunBackground) //重启 BK_NOTIFY_ID_COMMAND(IDC_LBL_VULFIX_REPAIR_TOP_REBOOT, OnBkBtnReboot) //开始扫描 BK_NOTIFY_ID_COMMAND(IDC_LBL_VULFIX_REPAIR_TOP_RESCAN, OnBkBtnScan) //重启 BK_NOTIFY_ID_COMMAND(IDC_LBL_VULFIX_REPAIR_TOP_REBOOT2, OnBkBtnReboot) //开始扫描 BK_NOTIFY_ID_COMMAND(IDC_LBL_VULFIX_REPAIR_TOP_RESCAN2, OnBkBtnScan) //重启 BK_NOTIFY_ID_COMMAND(IDC_DIV_VULFIX_REPAIR_BTM_DONE_PART, OnBkBtnReboot) //开始扫描 BK_NOTIFY_ID_COMMAND(IDC_LBL_VULFIX_REPAIR_TOP_RESCAN3, OnBkBtnScan) BK_NOTIFY_ID_COMMAND(1052, OnBkBtnScan) // 修复, 所有下载失败, 则直接显示重新扫描 //扫描失败 BK_NOTIFY_ID_COMMAND(IDC_LBL_VULFIX_ERROR_REPAIR, OnBkBtnErrorRepair) BK_NOTIFY_ID_COMMAND(1034, OnBkBtnVisitVulPurposePage) //输出信息 BK_NOTIFY_ID_COMMAND(2001, OnBkBtnExport) BK_NOTIFY_REALWND_RESIZED(IDC_LST_VULFIX_RESULT_LIST, OnListReSize) BK_NOTIFY_REALWND_RESIZED(IDC_LST_VULFIX_FIXING_LIST, OnDownListReSize) // 查看已忽略/已安装 //BK_NOTIFY_ID_COMMAND(IDC_LBL_VULFIX_SHOW_IGNORED_DLG, OnBkBtnViewIgnored) //BK_NOTIFY_ID_COMMAND(IDC_LBL_VULFIX_SHOW_INSTALLED_DLG, OnBkBtnViewInstalled) //BK_NOTIFY_ID_COMMAND(IDC_LBL_VULFIX_SHOW_SUPERSEDED_DLG, OnBkBtnViewSupersede) //BK_NOTIFY_ID_COMMAND(IDC_LBL_VULFIX_SHOW_INVALID_DLG, OnBkBtnViewInvalid) BK_NOTIFY_MAP_END() BEGIN_MSG_MAP_EX(CBeikeVulfixHandler) MSG_BK_NOTIFY(IDC_RICHVIEW_WIN_VULFIX) MESSAGE_HANDLER(WMH_SCAN_START, OnScanStart) MESSAGE_HANDLER(WMH_SCAN_DONE, OnScanDone) MESSAGE_HANDLER(WMH_REPAIR_DONE, OnRepaireDone) MESSAGE_HANDLER(WMH_SCAN_SOFT_DONE, OnScanDone) MESSAGE_RANGE_HANDLER(WMH_VULFIX_BASE, WMH_VULFIX_BASE+EVulfix_Task_Error, OnVulFixEventHandle) MESSAGE_HANDLER(WMH_LISTEX_LINK, OnListLinkClicked) NOTIFY_ID_HANDLER(IDC_LST_VULFIX_RESULT_LIST, OnListBoxVulFixNotify) NOTIFY_HANDLER(IDC_TXT_VULFIX_VUL_DESCRIPTION, EN_LINK, OnRichEditLink) COMMAND_HANDLER(1016, STN_CLICKED, OnStnClickedNavi) //MSG_WM_CHAR(OnChar) END_MSG_MAP() };至于里面是怎么操作的!本文就不讨论了!
最后是pcmanager了,它是开源卫士完整版,也就是前面的集合了!~
学习的目标是成熟!~~~