24 #include <sys/times.h>
25 #include <sys/param.h>
31 #include <mach-o/dyld.h>
48 #include <boost/filesystem/path.hpp>
49 #include <boost/filesystem/operations.hpp>
69 ::dladdr(FuncPtrCast<void*>(funct),
m_dlinfo.
get());
73 return ::basename(const_cast<char*>(
m_dlinfo->dli_fname));
77 return const_cast<char*
>(
m_dlinfo->dli_fname);
88 ModuleInfo::operator
const Dl_info&()
const {
97 static string module(
"");
100 string mod = ::basename(const_cast<char *>((reinterpret_cast<Dl_info*>(
moduleHandle()))->dli_fname));
101 module = mod.
substr(static_cast<string::size_type>(0), mod.
rfind(
'.'));
109 static string module(
"");
110 if ( module ==
"" ) {
112 char name[PATH_MAX] = {
"Unknown.module"};
115 (
reinterpret_cast<Dl_info*
>(
moduleHandle())->dli_fname);
116 if (::realpath(path, name)) {
129 int loc = module.
rfind(
'.')+1;
132 }
else if (module[loc] ==
'e' or module[loc] ==
'E') {
134 }
else if (module[loc] ==
's' and module[loc+1] ==
'o') {
146 static void* hP =
reinterpret_cast<void*
>(pid);
151 s_module_handle = handle;
155 if (0 == s_module_handle) {
158 if (0 != ::dladdr(FuncPtrCast<void*>(
moduleHandle), &info)) {
163 return s_module_handle;
168 static Dl_info infoBuf;
169 static Dl_info *info;
172 void* handle = ::dlopen(0, RTLD_LAZY);
174 void* func = ::dlsym(handle,
"main");
176 if (0 != ::dladdr(func, &infoBuf)) {
187 static string module(
"");
188 if (module.
length() == 0) {
196 path self_proc {
"/proc/self"};
198 path exe = self_proc /
"exe";
200 if (not boost::filesystem::exists(exe)) {
202 self_str <<
"/proc/" << ::getpid();
203 self_proc =
path(self_str.str());
219 string address, perms, offset, dev, pathname;
222 if (not(iss >> address >> perms >> offset >> dev >> inode >> pathname)) {
225 if (perms ==
"r-xp" and boost::filesystem::exists(pathname)) {
232 return linked_modules;
238 if (s_linkedModules.size() == 0) {
245 return s_linkedModules;
252 char pathbuf[PATH_MAX + 1];
253 unsigned int bufsize =
sizeof(pathbuf);
254 _NSGetExecutablePath(pathbuf, &bufsize);
255 path self_exe =
path(
string(pathbuf));
262 return boost::filesystem::canonical(self_exe);
ELEMENTS_API ModuleType moduleType()
Get type of the module.
std::unique_ptr< Dl_info > m_dlinfo
defines a Small helper function that allows the cast from void * to function pointer ...
ELEMENTS_API void setModuleHandle(ImageHandle handle)
Attach module handle.
ELEMENTS_API const std::vector< std::string > linkedModules()
Vector of names of linked modules.
ELEMENTS_API const std::string & moduleNameFull()
Get the full name of the (executable/DLL) file.
ELEMENTS_API std::vector< boost::filesystem::path > linkedModulePaths()
void * ImageHandle
Definition of an image handle.
ELEMENTS_API ProcessHandle processHandle()
Handle to running process.
const std::string name() const
boost::filesystem::path path
ELEMENTS_API const std::string & exeName()
Name of the executable file running.
const std::string libraryName() const
ELEMENTS_API ImageHandle moduleHandle()
Handle to currently executed module.
ELEMENTS_API const std::string & moduleName()
Get the name of the (executable/DLL) file without file-type.
ELEMENTS_API boost::filesystem::path getExecutablePath()
Get the full executable path.
ELEMENTS_API ImageHandle exeHandle()
Handle to the executable file running.
OS specific details to access at run-time the module configuration of the process.
const void * addresse() const