Fix checking plugin crash issue due to plugin packaging error.
parent
519fecbb82
commit
ef5d07771a
|
@ -64,6 +64,9 @@ generic_string commafyInt(size_t n)
|
||||||
|
|
||||||
std::string getFileContent(const TCHAR *file2read)
|
std::string getFileContent(const TCHAR *file2read)
|
||||||
{
|
{
|
||||||
|
if (!::PathFileExists(file2read))
|
||||||
|
return "";
|
||||||
|
|
||||||
const size_t blockSize = 1024;
|
const size_t blockSize = 1024;
|
||||||
char data[blockSize];
|
char data[blockSize];
|
||||||
std::string wholeFileContent = "";
|
std::string wholeFileContent = "";
|
||||||
|
@ -72,7 +75,7 @@ std::string getFileContent(const TCHAR *file2read)
|
||||||
size_t lenFile = 0;
|
size_t lenFile = 0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
lenFile = fread(data, 1, blockSize - 1, fp);
|
lenFile = fread(data, 1, blockSize, fp);
|
||||||
if (lenFile <= 0) break;
|
if (lenFile <= 0) break;
|
||||||
wholeFileContent.append(data, lenFile);
|
wholeFileContent.append(data, lenFile);
|
||||||
}
|
}
|
||||||
|
|
|
@ -505,15 +505,33 @@ DWORD WINAPI PluginsAdminDlg::launchPluginInstallerThread(void* params)
|
||||||
PathAppend(installedPluginPath, lwp->_pluginUpdateInfo->_folderName + TEXT(".dll"));
|
PathAppend(installedPluginPath, lwp->_pluginUpdateInfo->_folderName + TEXT(".dll"));
|
||||||
|
|
||||||
// check installed id to prevent from MITMA
|
// check installed id to prevent from MITMA
|
||||||
|
char sha2hashStr[65] = { '\0' };
|
||||||
std::string content = getFileContent(installedPluginPath.c_str());
|
std::string content = getFileContent(installedPluginPath.c_str());
|
||||||
|
if (content.empty())
|
||||||
|
{
|
||||||
|
// Remove installed plugin
|
||||||
|
NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance())->getNativeLangSpeaker();
|
||||||
|
pNativeSpeaker->messageBox("PluginBuiltWronglyCannotFound",
|
||||||
|
NULL,
|
||||||
|
TEXT("The plugin package is built wrongly. This plugin will be uninstalled."),
|
||||||
|
TEXT("Plugin cannot be found"),
|
||||||
|
MB_OK | MB_APPLMODAL,
|
||||||
|
0,
|
||||||
|
lwp->_pluginUpdateInfo->_displayName.c_str());
|
||||||
|
|
||||||
|
deleteFileOrFolder(installedPluginFolder);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
uint8_t sha2hash[32];
|
uint8_t sha2hash[32];
|
||||||
calc_sha_256(sha2hash, reinterpret_cast<const uint8_t*>(content.c_str()), content.length());
|
calc_sha_256(sha2hash, reinterpret_cast<const uint8_t*>(content.c_str()), content.length());
|
||||||
char sha2hashStr[65] = {'\0'};
|
|
||||||
|
|
||||||
for (size_t i = 0; i < 32; i++)
|
for (size_t i = 0; i < 32; i++)
|
||||||
{
|
{
|
||||||
sprintf(sha2hashStr + i * 2, "%02x", sha2hash[i]);
|
sprintf(sha2hashStr + i * 2, "%02x", sha2hash[i]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
string s = ws2s(lwp->_pluginUpdateInfo->_id);
|
string s = ws2s(lwp->_pluginUpdateInfo->_id);
|
||||||
std::transform(s.begin(), s.end(), s.begin(), ::tolower);
|
std::transform(s.begin(), s.end(), s.begin(), ::tolower);
|
||||||
if (s == sha2hashStr)
|
if (s == sha2hashStr)
|
||||||
|
@ -544,7 +562,7 @@ DWORD WINAPI PluginsAdminDlg::launchPluginInstallerThread(void* params)
|
||||||
pNativeSpeaker->messageBox("PluginIdNotMatchedWillBeRemoved",
|
pNativeSpeaker->messageBox("PluginIdNotMatchedWillBeRemoved",
|
||||||
NULL,
|
NULL,
|
||||||
TEXT("The plugin \"$STR_REPLACE$\" ID is not correct. This plugin will be uninstalled."),
|
TEXT("The plugin \"$STR_REPLACE$\" ID is not correct. This plugin will be uninstalled."),
|
||||||
TEXT("Plugin ID missmathed"),
|
TEXT("Plugin ID mismathed"),
|
||||||
MB_OK | MB_APPLMODAL,
|
MB_OK | MB_APPLMODAL,
|
||||||
0,
|
0,
|
||||||
lwp->_pluginUpdateInfo->_displayName.c_str());
|
lwp->_pluginUpdateInfo->_displayName.c_str());
|
||||||
|
@ -786,6 +804,9 @@ PluginUpdateInfo::PluginUpdateInfo(const generic_string& fullFilePath, const gen
|
||||||
_displayName = filename;
|
_displayName = filename;
|
||||||
|
|
||||||
std::string content = getFileContent(fullFilePath.c_str());
|
std::string content = getFileContent(fullFilePath.c_str());
|
||||||
|
if (content.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
uint8_t sha2hash[32];
|
uint8_t sha2hash[32];
|
||||||
calc_sha_256(sha2hash, reinterpret_cast<const uint8_t*>(content.c_str()), content.length());
|
calc_sha_256(sha2hash, reinterpret_cast<const uint8_t*>(content.c_str()), content.length());
|
||||||
char sha2hashStr[65] = {'\0'};
|
char sha2hashStr[65] = {'\0'};
|
||||||
|
@ -798,7 +819,6 @@ PluginUpdateInfo::PluginUpdateInfo(const generic_string& fullFilePath, const gen
|
||||||
WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance();
|
WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance();
|
||||||
_id = wmc->char2wchar(sha2hashStr, CP_ACP);
|
_id = wmc->char2wchar(sha2hashStr, CP_ACP);
|
||||||
_version.setVersionFrom(fullFilePath);
|
_version.setVersionFrom(fullFilePath);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef const char * (__cdecl * PFUNCGETPLUGINLIST)();
|
typedef const char * (__cdecl * PFUNCGETPLUGINLIST)();
|
||||||
|
|
Loading…
Reference in New Issue