18
18
#include < libproc.h>
19
19
#include < sys/syscall.h>
20
20
#include < mach-o/dyld.h>
21
+ #include < filesystem>
21
22
#endif // defined
22
23
23
24
#if defined(__APPLE__)
25
+ std::string StripPath (const std::string& path_to_strip)
26
+ {
27
+ return std::filesystem::path (path_to_strip).filename ().string ();
28
+ }
29
+
24
30
void GetDesktopResolution (int &width, int &height) noexcept
25
31
{
26
32
auto get_screen_resolution = [&]{
@@ -163,9 +169,13 @@ bool IsThreadAlive(std::int32_t tid) noexcept
163
169
for (std::uint32_t i = 0 ; i < count; ++i)
164
170
{
165
171
const char * name = _dyld_get_image_name (i);
166
- if (! strcasestr ( name, partial_module_name) )
172
+ if (name)
167
173
{
168
- result.push_back (name);
174
+ std::string module_name = StripPath (name);
175
+ if (!strcasestr (module_name.c_str (), partial_module_name))
176
+ {
177
+ result.push_back (name);
178
+ }
169
179
}
170
180
}
171
181
@@ -178,43 +188,47 @@ bool IsThreadAlive(std::int32_t tid) noexcept
178
188
for (std::uint32_t i = 0 ; i < count; ++i)
179
189
{
180
190
const char * name = _dyld_get_image_name (i);
181
- if (strcasestr ( name, module_name) )
191
+ if (name)
182
192
{
183
- return dlopen (name, RTLD_NOLOAD);
184
-
185
- /* const struct mach_header* header = _dyld_get_image_header(i);
186
- //std::intptr_t offset = _dyld_get_image_vmaddr_slide(i);
187
-
188
- const struct load_command* cmd = reinterpret_cast<const struct load_command*>(reinterpret_cast<const char *>(header) + sizeof(struct mach_header));
189
- if (header->magic == MH_MAGIC_64)
193
+ std::string stripped_name = StripPath (name);
194
+ if (strcasestr (stripped_name.c_str (), module_name))
190
195
{
191
- cmd = reinterpret_cast<const struct load_command*>(reinterpret_cast<const char *>(header) + sizeof(struct mach_header_64));
192
- }
196
+ return dlopen (name, RTLD_NOLOAD);
193
197
194
- for (std::uint32_t j = 0; j < header->ncmds; ++j)
195
- {
196
- if (cmd->cmd == LC_SEGMENT)
197
- {
198
- const struct segment_command* seg = reinterpret_cast<const struct segment_command*>(cmd);
199
- void* base_addr = reinterpret_cast<void*>(seg->vmaddr); //seg->vmaddr + offset;
198
+ /* const struct mach_header* header = _dyld_get_image_header(i);
199
+ //std::intptr_t offset = _dyld_get_image_vmaddr_slide(i);
200
200
201
- Dl_info info = {0};
202
- dladdr(base_addr, &info);
203
- return dlopen(info.dli_fname, RTLD_NOLOAD);
201
+ const struct load_command* cmd = reinterpret_cast<const struct load_command*>(reinterpret_cast<const char *>(header) + sizeof(struct mach_header));
202
+ if (header->magic == MH_MAGIC_64)
203
+ {
204
+ cmd = reinterpret_cast<const struct load_command*>(reinterpret_cast<const char *>(header) + sizeof(struct mach_header_64));
204
205
}
205
206
206
- if (cmd->cmd == LC_SEGMENT_64 )
207
+ for (std::uint32_t j = 0; j < header->ncmds; ++j )
207
208
{
208
- const struct segment_command_64* seg = reinterpret_cast<const struct segment_command_64*>(cmd);
209
- void* base_addr = reinterpret_cast<void*>(seg->vmaddr); //seg->vmaddr + offset;
209
+ if (cmd->cmd == LC_SEGMENT)
210
+ {
211
+ const struct segment_command* seg = reinterpret_cast<const struct segment_command*>(cmd);
212
+ void* base_addr = reinterpret_cast<void*>(seg->vmaddr); //seg->vmaddr + offset;
210
213
211
- Dl_info info = {0};
212
- dladdr(base_addr, &info);
213
- return dlopen(info.dli_fname, RTLD_NOLOAD);
214
- }
214
+ Dl_info info = {0};
215
+ dladdr(base_addr, &info);
216
+ return dlopen(info.dli_fname, RTLD_NOLOAD);
217
+ }
215
218
216
- cmd = reinterpret_cast<const struct load_command*>(reinterpret_cast<const char*>(cmd) + cmd->cmdsize);
217
- }*/
219
+ if (cmd->cmd == LC_SEGMENT_64)
220
+ {
221
+ const struct segment_command_64* seg = reinterpret_cast<const struct segment_command_64*>(cmd);
222
+ void* base_addr = reinterpret_cast<void*>(seg->vmaddr); //seg->vmaddr + offset;
223
+
224
+ Dl_info info = {0};
225
+ dladdr(base_addr, &info);
226
+ return dlopen(info.dli_fname, RTLD_NOLOAD);
227
+ }
228
+
229
+ cmd = reinterpret_cast<const struct load_command*>(reinterpret_cast<const char*>(cmd) + cmd->cmdsize);
230
+ }*/
231
+ }
218
232
}
219
233
}
220
234
return dlopen (module_name, RTLD_NOLOAD);
0 commit comments