| 227 | } |
| 228 | |
| 229 | bool |
| 230 | Plugin::load(void) |
| 231 | { |
| 232 | PluginEntryFunc pluginEntry = nullptr; |
| 233 | |
| 234 | if (this->m_loaded) |
| 235 | return true; |
| 236 | |
| 237 | // Default plugin |
| 238 | if (this->m_handle == nullptr) { |
| 239 | pluginEntry = SigDigger::DefaultPluginEntry; |
| 240 | } else { |
| 241 | pluginEntry = |
| 242 | reinterpret_cast<PluginEntryFunc>(this->resolveSym(SIGDIGGER_PLUGIN_MANGLED_ENTRY)); |
| 243 | const uint32_t *pPluginVer = |
| 244 | SCAST(const uint32_t *, this->resolveSym("plugin_ver")); |
| 245 | const uint32_t *pAPIVer = |
| 246 | SCAST(const uint32_t *, this->resolveSym("api_ver")); |
| 247 | |
| 248 | if (pPluginVer == nullptr || pAPIVer == nullptr || pluginEntry == nullptr) |
| 249 | return false; |
| 250 | |
| 251 | this->m_version = QString::asprintf( |
| 252 | "%d.%d.%d", |
| 253 | 0xff & (*pPluginVer >> 16), |
| 254 | 0xff & (*pPluginVer >> 8), |
| 255 | 0xff & (*pPluginVer >> 0)).toStdString(); |
| 256 | |
| 257 | if (*pAPIVer > SIGDIGGER_API_VERSION) { |
| 258 | SU_ERROR( |
| 259 | "%s: this plugin is not compatible with the current SigDigger version\n", |
| 260 | this->m_path.c_str()); |
| 261 | return false; |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | this->m_loaded = (pluginEntry) (this); |
| 266 | |
| 267 | // Load okay, perform registration |
| 268 | if (this->m_loaded) { |
| 269 | for (auto p : this->m_factorySet) { |
| 270 | if (!p->registerGlobally()) { |
| 271 | SU_ERROR( |
| 272 | "%s: failed to register factory %s globally, unloading plugin\n", |
| 273 | this->m_path.c_str(), |
| 274 | p->name()); |
| 275 | this->unload(); |
| 276 | |
| 277 | break; |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | return this->m_loaded; |
| 283 | } |
| 284 | |
| 285 | bool |
| 286 | Plugin::unload(void) |
no test coverage detected