4 * Copyright (C) 2005-2013 Team XBMC
7 * This Program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This Program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with XBMC; see the file COPYING. If not, see
19 * <http://www.gnu.org/licenses/>.
24 #include "LibraryLoader.h"
26 #if defined(__linux__) && !defined(__powerpc__) && !defined(__arm__)
27 #define USE_LDT_KEEPER
28 #include "ldt_keeper.h"
41 unsigned long ordinal;
46 typedef struct ExportEntry
52 typedef struct _LoadedList
58 class DllLoader : public CoffLoader, public LibraryLoader
61 DllLoader(const char *dll, bool track = false, bool bSystemDll = false, bool bLoadSymbols = false, Export* exports = NULL);
65 virtual void Unload();
67 virtual int ResolveExport(const char*, void** ptr, bool logging = true);
68 virtual int ResolveOrdinal(unsigned long ordinal, void** ptr);
69 virtual bool HasSymbols() { return m_bLoadSymbols && !m_bUnloadSymbols; }
70 virtual bool IsSystemDll() { return m_bSystemDll; }
71 virtual HMODULE GetHModule() { return (HMODULE)hModule; }
73 Export* GetExportByFunctionName(const char* sFunctionName);
74 Export* GetExportByOrdinal(unsigned long ordinal);
79 void AddExport(unsigned long ordinal, void* function, void* track_function = NULL);
80 void AddExport(char* sFunctionName, unsigned long ordinal, void* function, void* track_function = NULL);
81 void AddExport(char* sFunctionName, void* function, void* track_function = NULL);
82 void SetExports(Export* exports) { m_pStaticExports = exports; }
85 // Just pointers; dont' delete...
86 ImportDirTable_t *ImportDirTable;
87 ExportDirTable_t *ExportDirTable;
89 bool m_bSystemDll; // true if this dll should not be removed
90 bool m_bLoadSymbols; // when true this dll should not be removed
91 bool m_bUnloadSymbols;
92 ExportEntry* m_pExportHead;
93 Export* m_pStaticExports;
100 void PrintImportLookupTable(unsigned long ImportLookupTable_RVA);
101 void PrintImportTable(ImportDirTable_t *ImportDirTable);
102 void PrintExportTable(ExportDirTable_t *ExportDirTable);
104 int ResolveOrdinal(char*, unsigned long, void**);
105 int ResolveName(char*, char*, void **);
106 char* ResolveReferencedDll(char* dll);
109 static void UnloadSymbols();