Factor malware checks into its own pass.

This commit is contained in:
David Anderson 2015-09-16 21:05:18 -07:00
parent 3807edbeb8
commit 76d681761d
2 changed files with 39 additions and 35 deletions

View File

@ -930,40 +930,8 @@ LoadRes CPluginManager::_LoadPlugin(CPlugin **aResult, const char *path, bool de
if (pPlugin->m_status == Plugin_Uncompiled) {
pPlugin->TryCompile(error, maxlength);
}
if (pPlugin->GetStatus() == Plugin_Created)
{
unsigned char *pCodeHash = pPlugin->m_pRuntime->GetCodeHash();
char codeHashBuf[40];
ke::SafeSprintf(codeHashBuf, 40, "plugin_");
for (int i = 0; i < 16; i++)
ke::SafeSprintf(codeHashBuf + 7 + (i * 2), 3, "%02x", pCodeHash[i]);
const char *bulletinUrl = g_pGameConf->GetKeyValue(codeHashBuf);
if (bulletinUrl != NULL)
{
if (m_bBlockBadPlugins)
{
if (error)
{
if (bulletinUrl[0] != '\0')
{
ke::SafeSprintf(error, maxlength, "Known malware detected and blocked. See %s for more info", bulletinUrl);
} else {
ke::SafeSprintf(error, maxlength, "Possible malware or illegal plugin detected and blocked");
}
}
pPlugin->m_status = Plugin_BadLoad;
} else {
if (bulletinUrl[0] != '\0')
{
g_Logger.LogMessage("%s: Known malware detected. See %s for more info, blocking disabled in core.cfg", pPlugin->GetFilename(), bulletinUrl);
} else {
g_Logger.LogMessage("%s: Possible malware or illegal plugin detected, blocking disabled in core.cfg", pPlugin->GetFilename());
}
}
}
if (pPlugin->m_status == Plugin_Created) {
MalwareCheckPass(pPlugin, error, maxlength);
}
LoadRes loadFailure = LoadRes_Failure;
@ -1274,6 +1242,37 @@ bool CPluginManager::LoadOrRequireExtensions(CPlugin *pPlugin, unsigned int pass
return true;
}
bool CPluginManager::MalwareCheckPass(CPlugin *pPlugin, char *error, size_t maxlength)
{
unsigned char *pCodeHash = pPlugin->GetRuntime()->GetCodeHash();
char codeHashBuf[40];
ke::SafeSprintf(codeHashBuf, 40, "plugin_");
for (int i = 0; i < 16; i++)
ke::SafeSprintf(codeHashBuf + 7 + (i * 2), 3, "%02x", pCodeHash[i]);
const char *bulletinUrl = g_pGameConf->GetKeyValue(codeHashBuf);
if (!bulletinUrl)
return true;
if (m_bBlockBadPlugins) {
if (bulletinUrl[0] != '\0') {
ke::SafeSprintf(error, maxlength, "Known malware detected and blocked. See %s for more info", bulletinUrl);
} else {
ke::SafeSprintf(error, maxlength, "Possible malware or illegal plugin detected and blocked");
}
pPlugin->m_status = Plugin_BadLoad;
return false;
}
if (bulletinUrl[0] != '\0') {
g_Logger.LogMessage("%s: Known malware detected. See %s for more info, blocking disabled in core.cfg", pPlugin->GetFilename(), bulletinUrl);
} else {
g_Logger.LogMessage("%s: Possible malware or illegal plugin detected, blocking disabled in core.cfg", pPlugin->GetFilename());
}
return true;
}
bool CPluginManager::RunSecondPass(CPlugin *pPlugin, char *error, size_t maxlength)
{
/* Second pass for extension requirements */

View File

@ -459,6 +459,11 @@ private:
*/
void AddPlugin(CPlugin *pPlugin);
/**
* First pass for loading a plugin, and its helpers.
*/
bool MalwareCheckPass(CPlugin *pPlugin, char *error, size_t maxlength);
/**
* Runs the second loading pass on a plugin.
*/