-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathLibrary.h
65 lines (60 loc) · 1.39 KB
/
Library.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (c) 2024 Project Nova LLC
#pragma once
#include <pthread.h>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <string>
#include <jni.h>
#include <stdint.h>
#include <unistd.h>
#include <cstddef>
#include <cstdint>
#include "Log.h"
#include "Util.h"
namespace Library
{
void* FindByName(const char* library_name)
{
FILE* fp = fopen("/proc/self/maps", "rt");
if (fp != NULL)
{
char line[512], mod_name[64];
void* base;
while (fgets(line, sizeof(line), fp))
{
if (std::sscanf(line, _("%llx-%*llx %*s %*ld %*s %*d %s"), &base, mod_name))
{
if (std::strstr(mod_name, library_name))
{
fclose(fp);
return base;
}
}
}
}
return nullptr;
}
bool IsLoaded(const char* lib)
{
char line[512] = { 0 };
FILE* fp = fopen(_("/proc/self/maps"), _("rt"));
if (fp != NULL)
{
while (fgets(line, sizeof(line), fp))
{
if (strstr(line, lib))
return true;
}
fclose(fp);
}
return false;
}
void WaitFor(const char* lib)
{
while (!IsLoaded(lib))
{
sleep(1);
}
}
}