diff --git a/resource/log.conf b/resource/log.conf index e4183fd..522e141 100644 --- a/resource/log.conf +++ b/resource/log.conf @@ -1,12 +1,12 @@ * GLOBAL: FORMAT = "%datetime %level [%fbase|%line] %msg" - FILENAME = "logs\\%datetime{%Y%M%d}.log" + FILENAME = "logs\\MemoryCheck.log" ENABLED = true TO_FILE = true ## Notice this TO_STANDARD_OUTPUT = false ## Notice this SUBSECOND_PRECISION = 3 PERFORMANCE_TRACKING = false - MAX_LOG_FILE_SIZE = 2097152 ## Throw log files away after 2MB + MAX_LOG_FILE_SIZE = 20971520 ## Throw log files away after 20MB * DEBUG: ENABLED = true @@ -15,4 +15,6 @@ * INFO: ENABLED = true * ERROR: + ENABLED = true +* WARNING: ENABLED = true \ No newline at end of file diff --git a/src/Config.h b/src/Config.h index d00816d..21dcfae 100644 --- a/src/Config.h +++ b/src/Config.h @@ -39,7 +39,11 @@ public : bool InWhitelists(string& processName) { bool isFind = false; for (auto it : m_Whitelists) { - if (processName == it) { + string exeName = it; + if (exeName.find(".exe") == string::npos) { + exeName += ".exe"; + } + if (processName == exeName) { isFind = true; break; } diff --git a/src/MemoryCheck.cpp b/src/MemoryCheck.cpp index ddd4301..3ade2dd 100644 --- a/src/MemoryCheck.cpp +++ b/src/MemoryCheck.cpp @@ -61,6 +61,7 @@ void MemoryCheck::Init() m_Config = new Config(); m_Config->Init(); + LOG(TRACE) << "init finish..."; } void MemoryCheck::Start() @@ -127,7 +128,7 @@ NTSTATUS MemoryCheck::HbEnumProcesses(PVOID* Processes) std::vector MemoryCheck::GetTopProcesses(int topN) { std::vector processes; - string pslistPath = GetAppPath() + "pslist.exe"; + string pslistPath = StringHelper::GetAppPath() + "pslist.exe"; HANDLE hReadPipe, hWritePipe; SECURITY_ATTRIBUTES sa = { sizeof(SECURITY_ATTRIBUTES), NULL, TRUE }; if (!CreatePipe(&hReadPipe, &hWritePipe, &sa, 0)) { @@ -330,7 +331,7 @@ void MemoryCheck::CheckAndAlert() { if (needClose) { LOG(INFO) << u8"尝试关闭" << log.m_ProcessName.c_str(); - string pskillPath = GetAppPath() + "pskill.exe"; + string pskillPath = StringHelper::GetAppPath() + "pskill.exe"; char cmd[512]; sprintf_s(cmd, sizeof(cmd), "%s /accepteula %s", pskillPath.c_str(), log.m_ProcessName.c_str()); HANDLE hReadPipe, hWritePipe; @@ -598,12 +599,3 @@ BOOLEAN MemoryCheck::PhIsExecutingInWow64(VOID) return FALSE; #endif } - - - -string MemoryCheck::GetAppPath() { - char szFilePath[MAX_PATH + 1] = { 0 }; - GetModuleFileName(NULL, szFilePath, MAX_PATH); - (strrchr(szFilePath, '\\'))[1] = 0; - return string(szFilePath); -} \ No newline at end of file diff --git a/src/MemoryCheck.h b/src/MemoryCheck.h index 73a0471..9b01ed9 100644 --- a/src/MemoryCheck.h +++ b/src/MemoryCheck.h @@ -703,8 +703,6 @@ public: MemoryCheck(const MemoryCheck&) = delete; MemoryCheck& operator=(const MemoryCheck&) = delete; - string GetAppPath(); - private: MemoryCheck() :m_WindowsVersion(0xffffffffUL), m_UseSysApi(false), m_EnableProcessExtension(false), m_Config(nullptr){