1.1 --- a/core/PluginSys.cpp Tue Aug 07 18:04:10 2012 +0100
1.2 +++ b/core/PluginSys.cpp Thu Aug 09 01:54:43 2012 +0100
1.3 @@ -789,6 +789,8 @@
1.4 m_AllPluginsLoaded = false;
1.5 m_MyIdent = NULL;
1.6 m_LoadingLocked = false;
1.7 +
1.8 + m_bBlockBadPlugins = true;
1.9 }
1.10
1.11 CPluginManager::~CPluginManager()
1.12 @@ -1030,6 +1032,41 @@
1.13 }
1.14 }
1.15 }
1.16 +
1.17 + if (pPlugin->GetStatus() == Plugin_Created)
1.18 + {
1.19 + unsigned char *pCodeHash = pPlugin->m_pRuntime->GetCodeHash();
1.20 +
1.21 + char codeHashBuf[40];
1.22 + UTIL_Format(codeHashBuf, 40, "plugin_");
1.23 + for (int i = 0; i < 16; i++)
1.24 + UTIL_Format(codeHashBuf + 7 + (i * 2), 3, "%02x", pCodeHash[i]);
1.25 +
1.26 + const char *bulletinUrl = g_pGameConf->GetKeyValue(codeHashBuf);
1.27 + if (bulletinUrl != NULL)
1.28 + {
1.29 + if (m_bBlockBadPlugins)
1.30 + {
1.31 + if (error)
1.32 + {
1.33 + if (bulletinUrl[0] != '\0')
1.34 + {
1.35 + UTIL_Format(error, maxlength, "Known malware detected and blocked. See %s for more info", bulletinUrl);
1.36 + } else {
1.37 + UTIL_Format(error, maxlength, "Possible malware or illegal plugin detected and blocked");
1.38 + }
1.39 + }
1.40 + pPlugin->m_status = Plugin_BadLoad;
1.41 + } else {
1.42 + if (bulletinUrl[0] != '\0')
1.43 + {
1.44 + g_Logger.LogMessage("%s: Known malware detected. See %s for more info, blocking disabled in core.cfg", pPlugin->GetFilename(), bulletinUrl);
1.45 + } else {
1.46 + g_Logger.LogMessage("%s: Possible malware or illegal plugin detected, blocking disabled in core.cfg", pPlugin->GetFilename());
1.47 + }
1.48 + }
1.49 + }
1.50 + }
1.51
1.52 LoadRes loadFailure = LoadRes_Failure;
1.53 /* Get the status */
1.54 @@ -1129,7 +1166,7 @@
1.55
1.56 if ((res=_LoadPlugin(&pl, plugin, false, PluginType_MapUpdated, error, sizeof(error))) == LoadRes_Failure)
1.57 {
1.58 - g_Logger.LogError("[SM] Failed to load plugin \"%s\": %s", plugin, error);
1.59 + g_Logger.LogError("[SM] Failed to load plugin \"%s\": %s.", plugin, error);
1.60 pl->SetErrorState(
1.61 pl->GetStatus() <= Plugin_Created ? Plugin_BadLoad : pl->GetStatus(),
1.62 "%s",
1.63 @@ -1889,6 +1926,27 @@
1.64 g_ShareSys.DestroyIdentity(m_MyIdent);
1.65 }
1.66
1.67 +ConfigResult CPluginManager::OnSourceModConfigChanged(const char *key,
1.68 + const char *value,
1.69 + ConfigSource source,
1.70 + char *error,
1.71 + size_t maxlength)
1.72 +{
1.73 + if (strcmp(key, "BlockBadPlugins") == 0) {
1.74 + if (strcasecmp(value, "yes") == 0)
1.75 + {
1.76 + m_bBlockBadPlugins = true;
1.77 + } else if (strcasecmp(value, "no") == 0) {
1.78 + m_bBlockBadPlugins = false;
1.79 + } else {
1.80 + UTIL_Format(error, maxlength, "Invalid value: must be \"yes\" or \"no\"");
1.81 + return ConfigResult_Reject;
1.82 + }
1.83 + return ConfigResult_Accept;
1.84 + }
1.85 + return ConfigResult_Ignore;
1.86 +}
1.87 +
1.88 void CPluginManager::OnHandleDestroy(HandleType_t type, void *object)
1.89 {
1.90 /* We don't care about the internal object, actually */
1.91 @@ -2269,6 +2327,15 @@
1.92 {
1.93 g_RootMenu.ConsolePrint(" Timestamp: %s", pl->m_DateTime);
1.94 }
1.95 +
1.96 + unsigned char *pCodeHash = pl->m_pRuntime->GetCodeHash();
1.97 + unsigned char *pDataHash = pl->m_pRuntime->GetDataHash();
1.98 +
1.99 + char combinedHash[33];
1.100 + for (int i = 0; i < 16; i++)
1.101 + UTIL_Format(combinedHash + (i * 2), 3, "%02x", pCodeHash[i] ^ pDataHash[i]);
1.102 +
1.103 + g_RootMenu.ConsolePrint(" Hash: %s", combinedHash);
1.104 }
1.105 else
1.106 {