Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | List of all members
Botan::Dynamically_Loaded_Library Class Reference

`#include <dyn_load.h>`

## Public Member Functions
| Dynamically_Loaded_Library (const std::string &lib_name)
template<typename T >
T | resolve (const std::string &symbol)
void * | resolve_symbol (const std::string &symbol)
| ~Dynamically_Loaded_Library ()

## Detailed Description

Represents a DLL or shared object

Definition at line 19 of file dyn_load.h.

## Constructor & Destructor Documentation

Botan::Dynamically_Loaded_Library::Dynamically_Loaded_Library | ( | const std::string & | lib_name | ) |

Load a DLL (or fail with an exception)

Parameters

  lib_name | name or path to a library

If you don't use a full path, the search order will be defined by whatever the system linker does by default. Always using fully qualified pathnames can help prevent code injection attacks (eg via manipulation of LD_LIBRARY_PATH on Linux)

Definition at line 32 of file dyn_load.cpp.

33 :
34 m_lib_name(library), m_lib(nullptr)
35 {
36 #if defined(BOTAN_TARGET_OS_HAS_DLOPEN)
37 m_lib = ::dlopen(m_lib_name.c_str(), RTLD_LAZY);
38
39 if(!m_lib)
40 raise_runtime_loader_exception(m_lib_name, dlerror());
41
42 #elif defined(BOTAN_TARGET_OS_HAS_LOADLIBRARY)
43 m_lib = ::LoadLibraryA(m_lib_name.c_str());
44
45 if(!m_lib)
46 raise_runtime_loader_exception(m_lib_name, "LoadLibrary failed");
47 #endif
48
49 if(!m_lib)
50 raise_runtime_loader_exception(m_lib_name, "Dynamic load not supported");
51 }

Botan::Dynamically_Loaded_Library::~Dynamically_Loaded_Library | ( |  | ) |

Unload the DLL

Warning
  Any pointers returned by resolve()/resolve_symbol() should not be used after this destructor runs.

Definition at line 53 of file dyn_load.cpp.

54 {
55 #if defined(BOTAN_TARGET_OS_HAS_DLOPEN)
56 ::dlclose(m_lib);
57 #elif defined(BOTAN_TARGET_OS_HAS_LOADLIBRARY)
58 ::FreeLibrary((HMODULE)m_lib);
59 #endif
60 }

## Member Function Documentation

template<typename T >

T Botan::Dynamically_Loaded_Library::resolve | ( | const std::string & | symbol | ) |
| inline

Convenience function for casting symbol to the right type

Parameters

  symbol | names the symbol to load

Returns
  address of the loaded symbol

Definition at line 53 of file dyn_load.h.

Referenced by Botan::PKCS11::LowLevel::C_GetFunctionList().

54 {
55 return reinterpret_cast<T>(resolve_symbol(symbol));
56 }
Botan::Dynamically_Loaded_Library::resolve_symbol
void * resolve_symbol(const std::string &symbol)
Definition: dyn_load.cpp:62

void * Botan::Dynamically_Loaded_Library::resolve_symbol | ( | const std::string & | symbol | ) |

Load a symbol (or fail with an exception)

Parameters

  symbol | names the symbol to load

Returns
  address of the loaded symbol

Definition at line 62 of file dyn_load.cpp.

63 {
64 void* addr = nullptr;
65
66 #if defined(BOTAN_TARGET_OS_HAS_DLOPEN)
67 addr = ::dlsym(m_lib, symbol.c_str());
68 #elif defined(BOTAN_TARGET_OS_HAS_LOADLIBRARY)
69 addr = reinterpret_cast<void*>(::GetProcAddress((HMODULE)m_lib,
70 symbol.c_str()));
71 #endif
72
73 if(!addr)
74 throw Exception("Failed to resolve symbol " + symbol +
75 " in " + m_lib_name);
76
77 return addr;
78 }

The documentation for this class was generated from the following files:

- src/lib/utils/dyn_load/dyn_load.h
- src/lib/utils/dyn_load/dyn_load.cpp