|
@@ -66,165 +66,7 @@ const char * SimplePluginCtx::ctxQueryProp(const char *propName) const
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
-class HelperDll : implements ILoadedDllEntry, public CInterface
|
|
|
-{
|
|
|
- SharedObject so;
|
|
|
- StringAttr name;
|
|
|
- Linked<const IFileIO> dllFile;
|
|
|
- bool logLoad;
|
|
|
-public:
|
|
|
- IMPLEMENT_IINTERFACE;
|
|
|
- HelperDll(const char *_name, const IFileIO *dllFile);
|
|
|
- ~HelperDll();
|
|
|
-
|
|
|
-//interface ILoadedDllEntry
|
|
|
- virtual HINSTANCE getInstance() const;
|
|
|
- virtual void * getEntry(const char * name) const;
|
|
|
- virtual bool IsShared();
|
|
|
- virtual const char * queryVersion() const;
|
|
|
- virtual const char * queryName() const;
|
|
|
- virtual const byte * getResource(unsigned id) const;
|
|
|
- virtual bool getResource(size32_t & len, const void * & data, const char * type, unsigned id, bool trace) const;
|
|
|
-
|
|
|
- bool load(bool isGlobal, bool raiseOnError);
|
|
|
- bool loadCurrentExecutable();
|
|
|
- virtual void logLoaded();
|
|
|
- virtual bool checkVersion(const char *expected);
|
|
|
-};
|
|
|
-
|
|
|
-class PluginDll : public HelperDll
|
|
|
-{
|
|
|
- ECLPluginDefinitionBlockEx pb;
|
|
|
-
|
|
|
-public:
|
|
|
- PluginDll(const char *_name, const IFileIO *_dllFile) : HelperDll(_name, _dllFile) {}
|
|
|
-
|
|
|
- bool init(IPluginContextEx * pluginCtx);
|
|
|
-
|
|
|
- virtual bool checkVersion(const char *expected);
|
|
|
- virtual void logLoaded();
|
|
|
-};
|
|
|
-
|
|
|
-HelperDll::HelperDll(const char *_name, const IFileIO *_dllFile)
|
|
|
-: name(_name), dllFile(_dllFile)
|
|
|
-{
|
|
|
- logLoad = false;
|
|
|
-}
|
|
|
-
|
|
|
-bool HelperDll::load(bool isGlobal, bool raiseOnError)
|
|
|
-{
|
|
|
- if (!so.load(name, isGlobal, raiseOnError))
|
|
|
- return false;
|
|
|
- return true;
|
|
|
-}
|
|
|
-
|
|
|
-bool HelperDll::loadCurrentExecutable()
|
|
|
-{
|
|
|
- if (!so.loadCurrentExecutable())
|
|
|
- return false;
|
|
|
- return true;
|
|
|
-}
|
|
|
-
|
|
|
-HelperDll::~HelperDll()
|
|
|
-{
|
|
|
- if (logLoad)
|
|
|
- DBGLOG("Unloading dll %s", name.get());
|
|
|
-}
|
|
|
-
|
|
|
-HINSTANCE HelperDll::getInstance() const
|
|
|
-{
|
|
|
- return so.getInstanceHandle();
|
|
|
-}
|
|
|
-
|
|
|
-void * HelperDll::getEntry(const char * name) const
|
|
|
-{
|
|
|
- return so.getEntry(name);
|
|
|
-}
|
|
|
-
|
|
|
-bool HelperDll::IsShared()
|
|
|
-{
|
|
|
- return CInterface::IsShared();
|
|
|
-}
|
|
|
-
|
|
|
-const char * HelperDll::queryVersion() const
|
|
|
-{
|
|
|
- return "";
|
|
|
-}
|
|
|
-
|
|
|
-void HelperDll::logLoaded()
|
|
|
-{
|
|
|
- logLoad = true;
|
|
|
- DBGLOG("Loaded DLL %s", name.get());
|
|
|
-}
|
|
|
-
|
|
|
-bool HelperDll::checkVersion(const char *expected)
|
|
|
-{
|
|
|
- return true;
|
|
|
-}
|
|
|
-
|
|
|
-const char * HelperDll::queryName() const
|
|
|
-{
|
|
|
- return name.get();
|
|
|
-}
|
|
|
-
|
|
|
-const byte * HelperDll::getResource(unsigned id) const
|
|
|
-{
|
|
|
-#ifdef _WIN32
|
|
|
- HINSTANCE dllHandle = so.getInstanceHandle();
|
|
|
- HRSRC hrsrc = FindResource(dllHandle, MAKEINTRESOURCE(id), "BIGSTRING");
|
|
|
- if (hrsrc)
|
|
|
- return (const byte *) LoadResource(dllHandle, hrsrc);
|
|
|
- return NULL;
|
|
|
-#else
|
|
|
- StringBuffer resourceName;
|
|
|
- resourceName.appendf("BIGSTRING_%d_txt_start", id);
|
|
|
- return (const byte *) getEntry(resourceName.str());
|
|
|
-#endif
|
|
|
-}
|
|
|
-
|
|
|
-const byte resourceHeaderVersion=1;
|
|
|
-const size32_t resourceHeaderLength = sizeof(byte) + sizeof(byte) + sizeof(bool) + sizeof(size32_t);
|
|
|
-
|
|
|
-
|
|
|
-bool HelperDll::getResource(size32_t & len, const void * & data, const char * type, unsigned id, bool trace) const
|
|
|
-{
|
|
|
-#ifdef _WIN32
|
|
|
- HINSTANCE dllHandle = so.getInstanceHandle();
|
|
|
- HRSRC hrsrc = FindResource(dllHandle, MAKEINTRESOURCE(id), type);
|
|
|
- if (!hrsrc)
|
|
|
- return false;
|
|
|
- len = SizeofResource(dllHandle, hrsrc);
|
|
|
- data = (const byte *) LoadResource(dllHandle, hrsrc);
|
|
|
- return true;
|
|
|
-#else
|
|
|
- StringBuffer symName;
|
|
|
- symName.append(type).append("_").append(id).append("_txt_start");
|
|
|
- data = (const void *) getEntry(symName.str());
|
|
|
- if (!data)
|
|
|
- {
|
|
|
- if (trace)
|
|
|
- printf("Failed to locate symbol %s\n", symName.str());
|
|
|
- return false;
|
|
|
- }
|
|
|
- byte bom;
|
|
|
- byte version;
|
|
|
- bool compressed;
|
|
|
-
|
|
|
- MemoryBuffer mb;
|
|
|
- mb.setBuffer(resourceHeaderLength, const_cast<void *>(data));
|
|
|
- mb.read(bom);
|
|
|
- if (bom!=0x80)
|
|
|
- return false;
|
|
|
- mb.read(version);
|
|
|
- if (version>resourceHeaderVersion)
|
|
|
- return false;
|
|
|
- mb.read(compressed).read(len);
|
|
|
- len+=resourceHeaderLength;
|
|
|
- return true;
|
|
|
-#endif
|
|
|
-}
|
|
|
-
|
|
|
-static bool getResourceFromMappedFile(const char * filename, const byte * start_addr, MemoryBuffer &data, const char * type, unsigned id)
|
|
|
+static bool getResourceFromMappedFile(const char * filename, const byte * start_addr, size32_t & lenData, const void * & data, const char * type, unsigned id)
|
|
|
{
|
|
|
#if defined(_WIN32)
|
|
|
throwUnexpected();
|
|
@@ -239,8 +81,8 @@ static bool getResourceFromMappedFile(const char * filename, const byte * start_
|
|
|
}
|
|
|
|
|
|
unsigned long len = 0;
|
|
|
- unsigned char *data2 = getsectiondata(mh, "__TEXT", sectname.str(), &len);
|
|
|
- data.append(len, data2);
|
|
|
+ data = getsectiondata(mh, "__TEXT", sectname.str(), &len);
|
|
|
+ lenData = (size32_t)len;
|
|
|
return true;
|
|
|
#elif defined (__64BIT__)
|
|
|
// The first bytes are the ELF header
|
|
@@ -275,7 +117,8 @@ static bool getResourceFromMappedFile(const char * filename, const byte * start_
|
|
|
const char * sectionName = symbolTable + section.sh_name;
|
|
|
if (streq(sectionName, sectname))
|
|
|
{
|
|
|
- data.append(section.sh_size, start_addr + section.sh_offset);
|
|
|
+ lenData = (size32_t)section.sh_size;
|
|
|
+ data = start_addr + section.sh_offset;
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
@@ -315,7 +158,8 @@ static bool getResourceFromMappedFile(const char * filename, const byte * start_
|
|
|
const char * sectionName = symbolTable + section.sh_name;
|
|
|
if (streq(sectionName, sectname))
|
|
|
{
|
|
|
- data.append(section.sh_size, start_addr + section.sh_offset);
|
|
|
+ lenData = (size32_t)section.sh_size;
|
|
|
+ data = start_addr + section.sh_offset;
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
@@ -325,6 +169,16 @@ static bool getResourceFromMappedFile(const char * filename, const byte * start_
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
+static bool getResourceFromMappedFile(const char * filename, const byte * start_addr, MemoryBuffer & result, const char * type, unsigned id)
|
|
|
+{
|
|
|
+ size32_t len = 0;
|
|
|
+ const void * data = nullptr;
|
|
|
+ bool ok = getResourceFromMappedFile(filename, start_addr, len, data, type, id);
|
|
|
+ if (ok)
|
|
|
+ result.append(len, data);
|
|
|
+ return ok;
|
|
|
+}
|
|
|
+
|
|
|
extern bool getResourceFromFile(const char *filename, MemoryBuffer &data, const char * type, unsigned id)
|
|
|
{
|
|
|
#ifdef _WIN32
|
|
@@ -379,6 +233,207 @@ extern bool getResourceFromFile(const char *filename, MemoryBuffer &data, const
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
+class HelperDll : implements ILoadedDllEntry, public CInterface
|
|
|
+{
|
|
|
+ SharedObject so;
|
|
|
+ StringAttr name;
|
|
|
+ Linked<const IFileIO> dllFile;
|
|
|
+ Owned<IMemoryMappedFile> mappedDll;
|
|
|
+ bool logLoad;
|
|
|
+public:
|
|
|
+ IMPLEMENT_IINTERFACE;
|
|
|
+ HelperDll(const char *_name, const IFileIO *dllFile);
|
|
|
+ ~HelperDll();
|
|
|
+
|
|
|
+//interface ILoadedDllEntry
|
|
|
+ virtual HINSTANCE getInstance() const;
|
|
|
+ virtual void * getEntry(const char * name) const;
|
|
|
+ virtual bool IsShared();
|
|
|
+ virtual const char * queryVersion() const;
|
|
|
+ virtual const char * queryName() const;
|
|
|
+ virtual const byte * getResource(unsigned id) const;
|
|
|
+ virtual bool getResource(size32_t & len, const void * & data, const char * type, unsigned id, bool trace) const;
|
|
|
+
|
|
|
+ bool load(bool isGlobal, bool raiseOnError);
|
|
|
+ bool loadCurrentExecutable();
|
|
|
+ bool loadResources();
|
|
|
+
|
|
|
+ virtual void logLoaded();
|
|
|
+ virtual bool checkVersion(const char *expected);
|
|
|
+};
|
|
|
+
|
|
|
+class PluginDll : public HelperDll
|
|
|
+{
|
|
|
+ ECLPluginDefinitionBlockEx pb;
|
|
|
+
|
|
|
+public:
|
|
|
+ PluginDll(const char *_name, const IFileIO *_dllFile) : HelperDll(_name, _dllFile) {}
|
|
|
+
|
|
|
+ bool init(IPluginContextEx * pluginCtx);
|
|
|
+
|
|
|
+ virtual bool checkVersion(const char *expected);
|
|
|
+ virtual void logLoaded();
|
|
|
+};
|
|
|
+
|
|
|
+HelperDll::HelperDll(const char *_name, const IFileIO *_dllFile)
|
|
|
+: name(_name), dllFile(_dllFile)
|
|
|
+{
|
|
|
+ logLoad = false;
|
|
|
+}
|
|
|
+
|
|
|
+bool HelperDll::load(bool isGlobal, bool raiseOnError)
|
|
|
+{
|
|
|
+ if (!so.load(name, isGlobal, raiseOnError))
|
|
|
+ return false;
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+bool HelperDll::loadResources()
|
|
|
+{
|
|
|
+#ifdef _WIN32
|
|
|
+ return so.loadResources(name);
|
|
|
+#else
|
|
|
+ Owned<IFile> file = createIFile(name);
|
|
|
+ mappedDll.setown(file->openMemoryMapped());
|
|
|
+ return mappedDll != nullptr;
|
|
|
+#endif
|
|
|
+}
|
|
|
+
|
|
|
+bool HelperDll::loadCurrentExecutable()
|
|
|
+{
|
|
|
+ if (!so.loadCurrentExecutable())
|
|
|
+ return false;
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+HelperDll::~HelperDll()
|
|
|
+{
|
|
|
+ if (logLoad)
|
|
|
+ DBGLOG("Unloading dll %s", name.get());
|
|
|
+}
|
|
|
+
|
|
|
+HINSTANCE HelperDll::getInstance() const
|
|
|
+{
|
|
|
+ if (!so.loaded())
|
|
|
+ throw MakeStringException(0, "Dll %s only loaded for resources", name.str());
|
|
|
+ return so.getInstanceHandle();
|
|
|
+}
|
|
|
+
|
|
|
+void * HelperDll::getEntry(const char * entry) const
|
|
|
+{
|
|
|
+ if (!so.loaded())
|
|
|
+ throw MakeStringException(0, "Dll %s only loaded for resources", name.str());
|
|
|
+ return so.getEntry(entry);
|
|
|
+}
|
|
|
+
|
|
|
+bool HelperDll::IsShared()
|
|
|
+{
|
|
|
+ return CInterface::IsShared();
|
|
|
+}
|
|
|
+
|
|
|
+const char * HelperDll::queryVersion() const
|
|
|
+{
|
|
|
+ return "";
|
|
|
+}
|
|
|
+
|
|
|
+void HelperDll::logLoaded()
|
|
|
+{
|
|
|
+ logLoad = true;
|
|
|
+ DBGLOG("Loaded DLL %s", name.get());
|
|
|
+}
|
|
|
+
|
|
|
+bool HelperDll::checkVersion(const char *expected)
|
|
|
+{
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+const char * HelperDll::queryName() const
|
|
|
+{
|
|
|
+ return name.get();
|
|
|
+}
|
|
|
+
|
|
|
+const byte * HelperDll::getResource(unsigned id) const
|
|
|
+{
|
|
|
+ if (so.loaded())
|
|
|
+ {
|
|
|
+#ifdef _WIN32
|
|
|
+ HINSTANCE dllHandle = so.getInstanceHandle();
|
|
|
+ HRSRC hrsrc = FindResource(dllHandle, MAKEINTRESOURCE(id), "BIGSTRING");
|
|
|
+ if (hrsrc)
|
|
|
+ return (const byte *)LoadResource(dllHandle, hrsrc);
|
|
|
+ return NULL;
|
|
|
+#else
|
|
|
+ StringBuffer resourceName;
|
|
|
+ resourceName.appendf("BIGSTRING_%d_txt_start", id);
|
|
|
+ return (const byte *)getEntry(resourceName.str());
|
|
|
+#endif
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ size32_t len;
|
|
|
+ const void * data;
|
|
|
+ if (getResource(len, data, "BIGSTRING", id, false))
|
|
|
+ return (const byte *)data;
|
|
|
+ return nullptr;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const byte resourceHeaderVersion=1;
|
|
|
+const size32_t resourceHeaderLength = sizeof(byte) + sizeof(byte) + sizeof(bool) + sizeof(size32_t);
|
|
|
+
|
|
|
+
|
|
|
+bool HelperDll::getResource(size32_t & len, const void * & data, const char * type, unsigned id, bool trace) const
|
|
|
+{
|
|
|
+ if (so.loaded())
|
|
|
+ {
|
|
|
+#ifdef _WIN32
|
|
|
+ HINSTANCE dllHandle = so.getInstanceHandle();
|
|
|
+ HRSRC hrsrc = FindResource(dllHandle, MAKEINTRESOURCE(id), type);
|
|
|
+ if (!hrsrc)
|
|
|
+ return false;
|
|
|
+ len = SizeofResource(dllHandle, hrsrc);
|
|
|
+ data = (const byte *)LoadResource(dllHandle, hrsrc);
|
|
|
+ return true;
|
|
|
+#else
|
|
|
+ StringBuffer symName;
|
|
|
+ symName.append(type).append("_").append(id).append("_txt_start");
|
|
|
+ data = (const void *)getEntry(symName.str());
|
|
|
+ if (!data)
|
|
|
+ {
|
|
|
+ if (trace)
|
|
|
+ printf("Failed to locate symbol %s\n", symName.str());
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ byte bom;
|
|
|
+ byte version;
|
|
|
+ bool compressed;
|
|
|
+
|
|
|
+ MemoryBuffer mb;
|
|
|
+ mb.setBuffer(resourceHeaderLength, const_cast<void *>(data));
|
|
|
+ mb.read(bom);
|
|
|
+ if (bom != 0x80)
|
|
|
+ return false;
|
|
|
+ mb.read(version);
|
|
|
+ if (version > resourceHeaderVersion)
|
|
|
+ return false;
|
|
|
+ mb.read(compressed).read(len);
|
|
|
+ len += resourceHeaderLength;
|
|
|
+ return true;
|
|
|
+#endif
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+#ifdef _WIN32
|
|
|
+ return false;
|
|
|
+#endif
|
|
|
+ if (!mappedDll)
|
|
|
+ return false;
|
|
|
+ return getResourceFromMappedFile(name, mappedDll->base(), len, data, type, id);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//-------------------------------------------------------------------------------------------------------------------
|
|
|
+
|
|
|
bool PluginDll::init(IPluginContextEx * pluginCtx)
|
|
|
{
|
|
|
HINSTANCE h = getInstance();
|
|
@@ -445,10 +500,15 @@ void PluginDll::logLoaded()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-extern DLLSERVER_API ILoadedDllEntry * createDllEntry(const char *path, bool isGlobal, const IFileIO *dllFile)
|
|
|
+extern DLLSERVER_API ILoadedDllEntry * createDllEntry(const char *path, bool isGlobal, const IFileIO *dllFile, bool resourcesOnly)
|
|
|
{
|
|
|
Owned<HelperDll> result = new HelperDll(path, dllFile);
|
|
|
- if (!result->load(isGlobal, true))
|
|
|
+ bool ok;
|
|
|
+ if (!resourcesOnly)
|
|
|
+ ok = result->load(isGlobal, true);
|
|
|
+ else
|
|
|
+ ok = result->loadResources();
|
|
|
+ if (!ok)
|
|
|
throw MakeStringException(0, "Failed to create ILoadedDllEntry for dll %s", path);
|
|
|
return result.getClear();
|
|
|
}
|