WIN32 specific Blacklisted libraries check:

1) Polished up wording of the error messages.
2) Made some messages in the SysInfo dialog localized.
3) Renamed LibraryCheck.cpp/hpp to BlacklistedLibraryCheck.cpp/hpp
4) CPPized the BlacklistedLibraryCheck WIN32 C code.
This commit is contained in:
Vojtech Bubnik 2021-07-30 15:52:43 +02:00
parent 64c8a6de8f
commit 2f6f1f0e55
5 changed files with 58 additions and 64 deletions

View file

@ -1,4 +1,4 @@
#include "LibraryCheck.hpp"
#include "BlacklistedLibraryCheck.hpp"
#include <cstdio>
#include <boost/nowide/convert.hpp>
@ -12,61 +12,46 @@ namespace Slic3r {
#ifdef WIN32
//only dll name with .dll suffix - currently case sensitive
const std::vector<std::wstring> LibraryCheck::blacklist({ L"NahimicOSD.dll" });
const std::vector<std::wstring> BlacklistedLibraryCheck::blacklist({ L"NahimicOSD.dll" });
bool LibraryCheck::get_blacklisted(std::vector<std::wstring>& names)
bool BlacklistedLibraryCheck::get_blacklisted(std::vector<std::wstring>& names)
{
if (m_found.empty())
return false;
for (const auto& lib : m_found)
names.emplace_back(lib);
return true;
}
std::wstring LibraryCheck::get_blacklisted_string()
std::wstring BlacklistedLibraryCheck::get_blacklisted_string()
{
std::wstring ret;
if (m_found.empty())
return ret;
//ret = L"These libraries has been detected inside of the PrusaSlicer process.\n"
// L"We suggest stopping or uninstalling these services if you experience crashes while using PrusaSlicer.\n\n";
for (const auto& lib : m_found)
{
ret += lib;
ret += L"\n";
}
ret += lib + L"\n";
return ret;
}
bool LibraryCheck::perform_check()
{
DWORD processID = GetCurrentProcessId();
HMODULE hMods[1024];
HANDLE hProcess;
DWORD cbNeeded;
unsigned int i;
bool BlacklistedLibraryCheck::perform_check()
{
// Get a handle to the process.
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID);
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, GetCurrentProcessId());
if (NULL == hProcess)
return false;
// Get a list of all the modules in this process.
HMODULE hMods[1024];
DWORD cbNeeded;
if (EnumProcessModulesEx(hProcess, hMods, sizeof(hMods), &cbNeeded, LIST_MODULES_ALL))
{
//printf("Total Dlls: %d\n", cbNeeded / sizeof(HMODULE));
for (i = 0; i < (cbNeeded / sizeof(HMODULE)); i++)
for (unsigned int i = 0; i < cbNeeded / sizeof(HMODULE); ++ i)
{
TCHAR szModName[MAX_PATH];
wchar_t szModName[MAX_PATH];
// Get the full path to the module's file.
if (GetModuleFileNameEx(hProcess, hMods[i], szModName,
sizeof(szModName) / sizeof(TCHAR)))
if (GetModuleFileNameExW(hProcess, hMods[i], szModName, MAX_PATH))
{
// Add to list if blacklisted
if(LibraryCheck::is_blacklisted(szModName)) {
if (BlacklistedLibraryCheck::is_blacklisted(szModName)) {
//wprintf(L"Contains library: %s\n", szModName);
if (std::find(m_found.begin(), m_found.end(), szModName) == m_found.end())
m_found.emplace_back(szModName);
@ -79,23 +64,22 @@ bool LibraryCheck::perform_check()
CloseHandle(hProcess);
//printf("\n");
return !m_found.empty();
}
bool LibraryCheck::is_blacklisted(std::wstring dllpath)
bool BlacklistedLibraryCheck::is_blacklisted(const std::wstring &dllpath)
{
std::wstring dllname = boost::filesystem::path(dllpath).filename().wstring();
//std::transform(dllname.begin(), dllname.end(), dllname.begin(), std::tolower);
if (std::find(LibraryCheck::blacklist.begin(), LibraryCheck::blacklist.end(), dllname) != LibraryCheck::blacklist.end()) {
if (std::find(BlacklistedLibraryCheck::blacklist.begin(), BlacklistedLibraryCheck::blacklist.end(), dllname) != BlacklistedLibraryCheck::blacklist.end()) {
//std::wprintf(L"%s is blacklisted\n", dllname.c_str());
return true;
}
//std::wprintf(L"%s is NOT blacklisted\n", dllname.c_str());
return false;
}
bool LibraryCheck::is_blacklisted(std::string dllpath)
bool BlacklistedLibraryCheck::is_blacklisted(const std::string &dllpath)
{
return LibraryCheck::is_blacklisted(boost::nowide::widen(dllpath));
return BlacklistedLibraryCheck::is_blacklisted(boost::nowide::widen(dllpath));
}
#endif //WIN32

View file

@ -1,5 +1,5 @@
#ifndef slic3r_LibraryCheck_hpp_
#define slic3r_LibraryCheck_hpp_
#ifndef slic3r_BlacklistedLibraryCheck_hpp_
#define slic3r_BlacklistedLibraryCheck_hpp_
#ifdef WIN32
#include <windows.h>
@ -10,30 +10,31 @@
namespace Slic3r {
#ifdef WIN32
class LibraryCheck
class BlacklistedLibraryCheck
{
public:
static LibraryCheck& get_instance()
static BlacklistedLibraryCheck& get_instance()
{
static LibraryCheck instance;
static BlacklistedLibraryCheck instance;
return instance;
}
private:
LibraryCheck() {}
BlacklistedLibraryCheck() = default;
std::vector<std::wstring> m_found;
public:
LibraryCheck(LibraryCheck const&) = delete;
void operator=(LibraryCheck const&) = delete;
BlacklistedLibraryCheck(BlacklistedLibraryCheck const&) = delete;
void operator=(BlacklistedLibraryCheck const&) = delete;
// returns all found blacklisted dlls
bool get_blacklisted(std::vector<std::wstring>& names);
std::wstring get_blacklisted_string();
// returns true if enumerating found blacklisted dll
bool perform_check();
static bool is_blacklisted(std::string dllpath);
static bool is_blacklisted(std::wstring dllpath);
// UTF-8 encoded path
static bool is_blacklisted(const std::string &dllpath);
static bool is_blacklisted(const std::wstring &dllpath);
private:
static const std::vector<std::wstring> blacklist;
};
@ -42,4 +43,4 @@ private:
} // namespace Slic3r
#endif //slic3r_LibraryCheck_hpp_
#endif //slic3r_BlacklistedLibraryCheck_hpp_

View file

@ -125,8 +125,8 @@ add_library(libslic3r STATIC
"${CMAKE_CURRENT_BINARY_DIR}/libslic3r_version.h"
Line.cpp
Line.hpp
LibraryCheck.cpp
LibraryCheck.hpp
BlacklistedLibraryCheck.cpp
BlacklistedLibraryCheck.hpp
LocalesUtils.cpp
LocalesUtils.hpp
Model.cpp