Menu

#62 Wrong export statement and missing statements

open
nobody
None
5
2006-11-03
2006-11-03
No

The following is wrong and will not work as intended:

BinaryFile.h(44)
// Some Windows voodoo; Windows doesn't seem to export
everything unless you tell it to
#ifdef _WIN32
#if defined _MSC_VER || defined BUILDING_LIBBINARYFILE
#define IMPORT_BINARYFILE __declspec(dllexport)
#else
#define IMPORT_BINARYFILE __declspec(dllimport)
#endif
#else
#define IMPORT_BINARYFILE
#endif

This says:
if windows
if MS compiler: export function
else: import function
else: do nothing

should be (MS, Intel and Borland + support for POSIX
subsystem):

#if defined(_WIN32) || defined(__INTERIX)
#if defined(_MSC_VER) || defined(__BORLANDC__)
#ifdef BINARYFILE_EXPORTS
# define IMPORT_BINARYFILE __declspec(dllexport)
#else
# define IMPORT_BINARYFILE __declspec(dllimport)
#endif
#else
# define IMPORT_BINARYFILE
#endif
#endif

define "BINARYFILE_EXPORTS" only in the project
building the DLL.

Due to the wrong setting, the other -X-BinaryFile DLLs
just export variants of the base DLL exports. They
need their own macro to work. Like this:

DOS4GWBinaryFile.h(33)
// dynamic loading support - MS, Intel and Borland
compilers
#if defined(_WIN32) || defined(__INTERIX)
#if defined _MSC_VER || defined(__BORLANDC__)
#ifdef DOS4GWBINARYFILE_EXPORTS
# define DOS4GW_IMPEXP __declspec(dllexport)
#else
# define DOS4GW_IMPEXP __declspec(dllimport)
#endif
#else
# define DOS4GW_IMPEXP
#endif
#endif

DOS4GWBinaryFile.h(144)
class DOS4GW_IMPEXP DOS4GWBinaryFile : public
BinaryFile

define "DOS4GWBINARYFILE_EXPORTS" only in the project
building the DLL.

When compiling we'll get Compiler Warning (level 1)
C4251 : "class needs to have dll-interface to be used
by clients". This is due to export of an instance of
std::map (std::map<ADDRESS, std::string> dlprocptrs),
which is not allowed by design (make sense BTW). See:
http://msdn2.microsoft.com/en-
us/library/esew7y1w.aspx. To solve this, we can
change "dlprocptrs" to a pointer to be allocated when
needed in every instance of the class. It could look
like this:

DOS4GWBinaryFile.h(214)
std::map<ADDRESS, std::string>* m_pDlprocptrs;
------------
DOS4GWBinaryFile.cpp(38)
DOS4GWBinaryFile::DOS4GWBinaryFile() : m_pFileName(0),
m_pDlprocptrs(0)
------------
DOS4GWBinaryFile.cpp(48)
if(m_pDlprocptrs) delete m_pDlprocptrs;
------------
change all "dlprocptrs." to "m_pDlprocptrs->"
change all "dlprocptrs[var]" to "m_pDlprocptrs-
>operator[](var)"
------------
Allocate "m_pDlprocptrs" when needed (but not in
constructor):

Ex:
std::map<ADDRESS, std::string>&
DOS4GWBinaryFile::getSymbols()
{
if(!m_pDlprocptrs) m_pDlprocptrs= new
std::map<ADDRESS, std::string>;
return *m_pDlprocptrs;
}
bool DOS4GWBinaryFile::IsDynamicLinkedProc(ADDRESS
uNative)
{
if(!m_pDlprocptrs) return false;
...
-------------------------------------------------------
-----
ditto for "ElfBinaryFile", "MachOBinaryFile"
and "Win32BinaryFile"

ElfBinaryFile.h
// dynamic loading support MS, Intel and Borland
compilers
#if defined(_WIN32) || defined(__INTERIX)
#if defined _MSC_VER || defined(__BORLANDC__)
#ifdef ELFBINARYFILE_EXPORTS
# define ELFBIN_IMPEXP __declspec(dllexport)
#else
# define ELFBIN_IMPEXP __declspec(dllimport)
#endif
#else
# define ELFBIN_IMPEXP
#endif
#endif

MachOBinaryFile.h
// dynamic loading support MS, Intel and Borland
compilers
#if defined(_WIN32) || defined(__INTERIX)
#if defined _MSC_VER || defined(__BORLANDC__)
#ifdef MACHOBINARYFILE_EXPORTS
# define MACHOBIN_IMPEXP __declspec(dllexport)
#else
# define MACHOBIN_IMPEXP __declspec(dllimport)
#endif
#else
# define MACHOBIN_IMPEXP
#endif
#endif

Win32BinaryFile.h
// dynamic loading support MS, Intel and Borland
compilers
#if defined(_WIN32) || defined(__INTERIX)
#if defined _MSC_VER || defined(__BORLANDC__)
#ifdef WIN32BINARYFILE_EXPORTS
# define WIN32BIN_IMPEXP __declspec(dllexport)
#else
# define WIN32BIN_IMPEXP __declspec(dllimport)
#endif
#else
# define WIN32BIN_IMPEXP
#endif
#endif

Discussion


Log in to post a comment.

MongoDB Logo MongoDB