Skip to content

Commit cc9ca0b

Browse files
committed
feat: add pl_resolve_signature
1 parent c37037a commit cc9ca0b

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

src/pl/Hook.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ namespace pl::hook {
7070
GlossInit(true);
7171
inited = true;
7272
}
73-
7473
std::lock_guard<std::mutex> lock(mtx);
7574
auto &map = hooks();
7675
auto it = map.find(target);
@@ -117,7 +116,6 @@ namespace pl::hook {
117116
if (!removed) return false;
118117

119118
if (h->chain.empty()) {
120-
GlossHookDelete(h->glossHandle);
121119
map.erase(it);
122120
} else {
123121
h->rebuildChain();

src/pl/Signature.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,10 @@ namespace pl::signature {
130130
return pat;
131131
}
132132

133-
134-
uintptr_t resolveSignature(const std::string &signature, const std::string &moduleName) {
135-
const std::string combinedKey = moduleName + "::" + signature;
133+
uintptr_t pl_resolve_signature(const char* signature, const char* moduleName) {
134+
std::string combinedKey;
135+
combinedKey.reserve(strlen(moduleName) + strlen(signature) + 2);
136+
combinedKey.append(moduleName).append("::").append(signature);
136137

137138
{
138139
std::shared_lock lk(cacheMutex);
@@ -152,7 +153,7 @@ namespace pl::signature {
152153
}
153154

154155
if (mod.handle) {
155-
if (void *sym = dlsym(mod.handle, signature.c_str())) {
156+
if (void *sym = dlsym(mod.handle, signature)) {
156157
uintptr_t addr = reinterpret_cast<uintptr_t>(sym);
157158
std::unique_lock lk(cacheMutex);
158159
sigCache[combinedKey] = addr;
@@ -193,4 +194,9 @@ namespace pl::signature {
193194
return result;
194195
}
195196

196-
} // namespace pl::signature
197+
uintptr_t resolveSignature(const std::string &signature, const std::string &moduleName) {
198+
return pl_resolve_signature(signature.c_str(), moduleName.c_str());
199+
}
200+
} // namespace pl::signature
201+
202+

src/pl/Signature.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@
33
#include <string>
44
#include "pl/internal/Macro.h"
55

6+
#ifdef __cplusplus
67
namespace pl::signature {
7-
8-
uintptr_t resolveSignature(const std::string &signature,
9-
const std::string &moduleName = "libminecraftpe.so");
10-
11-
} // namespace signature
12-
8+
#endif
9+
PLCAPI uintptr_t pl_resolve_signature(const char* signature, const char* moduleName);
1310
#ifdef __cplusplus
14-
extern "C" {
11+
} // namespace pl::hook
1512
#endif
1613

17-
PLCAPI uintptr_t resolve_signature(const char* signature, const char* moduleName);
1814

19-
#ifdef __cplusplus
20-
}
21-
#endif
15+
namespace pl::signature {
16+
[[deprecated("use pl_resolve_signature() instead")]]
17+
uintptr_t resolveSignature(const std::string &signature,
18+
const std::string &moduleName = "libminecraftpe.so");
19+
20+
} // namespace signature

0 commit comments

Comments
 (0)