#include "stdafx.h"
#include "PrivacyProtectionGUI.h"
#include "kmaindlg.h"
#include <Psapi.h>
#include "KLogic.h"
#include <atlpath.h>
#include "KClipBoardDlg.h"
#include <GdiplusGpStubs.h>
#include <GdiplusFlat.h>
#include "GdiplusImaging.h"
#include "beikesafemsgbox.h"
#include "AskExitDlg.h"
#include "KWarningDlg.h"
using namespace Gdiplus;
using namespace DllExports;
#include "kutfconv.h"
#include "./Carmera/serachcamera.h"
#include "KAddSoftwareDlg.h"
#include "KXmlWriter.h"
#include "KXmlReader.h"
#include "MinAskDlg.h"
#include "KSignCache.h"
#define MONITOR_TIMER 500
#define TRAY_ICON_ID 101
#define TIP_TIMER 501
#define CLSID_BMP _T("{557CF400-1A04-11D3-9A73-0000F81EF32E}")
#define CLSID_JPEG _T("{557CF401-1A04-11D3-9A73-0000F81EF32E}")
#define CLSID_GIF _T("{557CF402-1A04-11D3-9A73-0000F81EF32E}")
#define CLSID_TIFF _T("{557CF405-1A04-11D3-9A73-0000F81EF32E}")
#define CLSID_PNG _T("{557CF406-1A04-11D3-9A73-0000F81EF32E}")
#define GUID_Compress _T("{E09D739D-CCD4-44EE-8EBA-3FBF8BE4FC58}")
#define GUID_ColorDepth _T("{66087055-AD66-4C7C-9A18-38A2310B8337}")
#define GUID_Quality _T("{1D5BE4B5-FA4A-452D-9CDD-5DB35105E7EB}")
#define GUID_Transform _T("{8D0EB2D1-A58E-4EA8-AA14-108074B7B6F9}")
#define GUID_SaveFlag _T("{292266FC-AC40-47BF-8CFC-A85B89A655DE}")
//#define MAX_UPLOAD_SIZE 1024 * 1024 * 2
//#define SAVE_SIZE 5000
//////////////////////////////////////////////////////////////////////////
bool KCreateLongDir(
LPCWSTR lpPathName,
LPSECURITY_ATTRIBUTES lpSecurityAttributes
)
{
if (lpPathName == NULL)
{
return false;
}
if (::PathIsDirectoryW(lpPathName))
{
return true;
}
else
{
WCHAR szFatherPath[MAX_PATH];
::lstrcpynW(szFatherPath, lpPathName, MAX_PATH);
LPWSTR lpSlash = ::wcsrchr(szFatherPath, TEXT('\\'));
if (lpSlash != NULL)
{
*lpSlash = 0;
}
// 递归,先创建基层目录,再创建子目录。
if (lpSlash == NULL || KCreateLongDir(szFatherPath, lpSecurityAttributes))
{
if (::CreateDirectoryW(lpPathName, lpSecurityAttributes))
{
return true;
}
}
return false;
}
}
BOOL KDelAndUninstallSvr(LPWSTR szSvrName)
{
SC_HANDLE hServiceMgr = NULL, hServiceTwdm = NULL;
SERVICE_STATUS SvrSta;
hServiceMgr = OpenSCManagerW( NULL, NULL, SC_MANAGER_ALL_ACCESS );
if( hServiceMgr == NULL )
{return FALSE;}
hServiceTwdm = OpenServiceW( hServiceMgr, szSvrName, SERVICE_ALL_ACCESS );
if( hServiceTwdm == NULL ) {
CloseServiceHandle( hServiceMgr );
return FALSE;
}
//动态卸载驱动程序。
DeleteService( hServiceTwdm );
if (hServiceTwdm) {
CloseServiceHandle( hServiceTwdm );
hServiceTwdm = NULL;
}
if (hServiceMgr) {
CloseServiceHandle( hServiceMgr );
hServiceMgr = NULL;
}
WCHAR wszFolderPath[MAX_PATH + 1];
if (!::SHGetSpecialFolderPathW(NULL, wszFolderPath, CSIDL_APPDATA, 0)) {return FALSE;}
WCHAR wszPath[MAX_PATH + 1];
::GetModuleFileNameW(NULL, wszPath, MAX_PATH);
::PathStripPathW(wszPath);
::PathAppendW(wszFolderPath, wszPath);
::PathAppendW(wszFolderPath, L"ksafefilemon.sys");
::DeleteFile(wszFolderPath);
return TRUE;
}
BOOL KIsInstalled(LPWSTR szServiceName)
{
BOOL bResult = FALSE;
//打开服务控制管理器
SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (hSCM != NULL)
{
//打开服务
SC_HANDLE hService = ::OpenServiceW(hSCM, szServiceName, SERVICE_QUERY_CONFIG);
if (hService != NULL)
{
bResult = TRUE;
::CloseServiceHandle(hService);
}
::CloseServiceHandle(hSCM);
}
return bResult;
}
BOOL KInstallSys(LPWSTR szServiceName, LPWSTR szFilePath)
{
WCHAR wszMes[255] = {0};
BOOL nRet = FALSE;
SC_HANDLE hSCM = NULL;
SC_HANDLE hService = NULL;
if (KIsInstalled(szServiceName)) {
OutputDebugString(L"KIsInstalled");
nRet = TRUE;
goto _Exit;
}
hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (hSCM == NULL)
{
wsprintf(wszMes, L"OpenSCManager Fail %x\n", GetLastError ());
OutputDebugString(wszMes);
nRet = FALSE;
goto _Exit;
}
hService = ::CreateServiceW(
hSCM, szServiceName, szServiceName,
SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER,
SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL,
szFilePath, NULL, NULL, L"", NULL, NULL);
if (hService == NULL)
{
wsprintf(wszMes, L"CreateServiceW Fail %x\n", GetLastError ());
OutputDebugString(wszMes);
::CloseServiceHandle(hSCM);
if (GetLastError() == 0x00000431) {
nRet = TRUE;
} else {
nRet = FALSE;
}
goto _Exit;
}
OutputDebugString(L"CreateServiceW Suc");
nRet = TRUE;
_Exit:
if (hService) {
::CloseServiceHandle(hService);
hService = NULL;
}
if (hSCM) {
::CloseServiceHandle(hSCM);
hSCM = NULL;
}
return nRet;
}
HRESULT KStartServices( LPCWSTR lpwszServiceName )
{
HRESULT hresult = S_OK;
SC_HANDLE hScManager = NULL;
SC_HANDLE hService = NULL;
SERVICE_STATUS ServiceStatus;
WCHAR wszMes[255] = {0};
hScManager = ::OpenSCManager( NULL, NULL, GENERIC_READ | GENERIC_EXECUTE );
if ( NULL == hScManager )
{
OutputDebugStringW(L"Couldn't Open SCManager");
hresult = E_FAIL;
goto Exit0;
}
hService = ::OpenServiceW( hScManager, lpwszServiceName, GENERIC_READ | GENERIC_EXECUTE );
if ( NULL == hService )
{
OutputDebugStringW(L"Couldn't Open Service");
hresult = E_FAIL;
goto Exit0;
}
if ( ::QueryServiceStatus (hService, &ServiceStatus ) )
{
if ( ( ServiceStatus.dwCurrentState != SERVICE_STOPPED ) )
{
OutputDebugStringW(L"ServiceStatus.dwCurrentState != SERVICE_STOPPED");
hresult = S_OK;
goto Exit0;
}
}
if (!::StartService( hService, 0, NULL ) )
{
DWORD dwLastError = GetLastError ();
if ( ERROR_SERVICE_ALREADY_RUNNING == dwLastError )
{
OutputDebugStringW(L"ERROR_SERVICE_ALREADY_RUNNING");
hresult = S_OK;
goto Exit0;
}
wsprintf(wszMes, L"StartService~ %x\n", dwLastError);
OutputDebugString(wszMes);
int nCount = 5;
while(nCount--> 0)
{
::Sleep(1000);
if ( ::QueryServiceStatus (hService, &ServiceStatus ) )
{
if ( ( ServiceStatus.dwCurrentState == SERVICE_RUNNING ) )
{
OutputDebugStringW(L"dwCurrentState != SERVICE_RUNNING");
hresult = S_OK;
goto Exit0;
}
wsprintf(wszMes, L"QueryServiceStatus %x\n", ServiceStatus.dwCurrentState);
OutputDebugString(wszMes);
}
wsprintf(wszMes, L"QueryServiceStatus Fail %x\n", GetLastError());
OutputDebugString(wszMes);
}
hresult = E_FAIL;
}
OutputDebugStringW(L"Ok!");
Exit0:
if ( hService )
{
::CloseServiceHandle ( hService );
hService = NULL;
}
if ( hScManager )
{
::CloseServiceHandle ( hScManager );
hScManager = NULL;
}
wsprintf(wszMes, L"KStartServices end %x\n", hresult);
OutputDebugString(wszMes);
return hresult;
}
DWORD WINAPI KMainDlg::KpReleaseAndSatrtSys(LPVOID lpThreadParameter)
{
HINSTANCE hInstance = ::GetModuleHandle(NULL);//当前exe文件的句柄
HRSRC hResInfo = ::FindResourceW(hInstance, MAKEINTRESOURCE(IDR_SYS), L"SYS");
if (!hResInfo) {return FALSE;}
HGLOBAL hgRes = ::LoadResource(hInstance, hResInfo);
if (!hgRes) {return FALSE;}
void* pvRes = ::LockResource(hgRes);
if (!pvRes) {return FALSE;}
DWORD cbRes = ::SizeofResource(hInstance, hResInfo);
if (10 > cbRes) {return FALSE;}
WCHAR wszFolderPath[MAX_PATH + 1];
if (!::SHGetSpecialFolderPathW(NULL, wszFolderPath, CSIDL_APPDATA, 0)) {return FALSE;}
WCHAR wszPath[MAX_PATH + 1];
::GetMod
评论10
最新资源