Install native hook iff needed (#496)
* iff: https://en.wikipedia.org/wiki/If_and_only_if
This commit is contained in:
parent
2eae90dfe7
commit
362ab24859
|
|
@ -68,7 +68,7 @@ namespace lspd {
|
||||||
fseek(f, 0, SEEK_END);
|
fseek(f, 0, SEEK_END);
|
||||||
dex.resize(ftell(f));
|
dex.resize(ftell(f));
|
||||||
rewind(f);
|
rewind(f);
|
||||||
if (dex.size() != fread(dex.data(), 1, dex.size(), f)) {
|
if (dex.size() != fread(dex.data(), sizeof(decltype(dex)::value_type), dex.size(), f)) {
|
||||||
LOGE("Read dex failed");
|
LOGE("Read dex failed");
|
||||||
dex.resize(0);
|
dex.resize(0);
|
||||||
}
|
}
|
||||||
|
|
@ -90,8 +90,7 @@ namespace lspd {
|
||||||
auto initMid = JNI_GetMethodID(env, in_memory_classloader, "<init>",
|
auto initMid = JNI_GetMethodID(env, in_memory_classloader, "<init>",
|
||||||
"(Ljava/nio/ByteBuffer;Ljava/lang/ClassLoader;)V");
|
"(Ljava/nio/ByteBuffer;Ljava/lang/ClassLoader;)V");
|
||||||
auto byte_buffer_class = JNI_FindClass(env, "java/nio/ByteBuffer");
|
auto byte_buffer_class = JNI_FindClass(env, "java/nio/ByteBuffer");
|
||||||
auto dex_buffer = env->NewDirectByteBuffer(reinterpret_cast<void *>(dex.data()),
|
auto dex_buffer = env->NewDirectByteBuffer(dex.data(), dex.size());
|
||||||
dex.size());
|
|
||||||
if (auto my_cl = JNI_NewObject(env, in_memory_classloader, initMid,
|
if (auto my_cl = JNI_NewObject(env, in_memory_classloader, initMid,
|
||||||
dex_buffer, sys_classloader)) {
|
dex_buffer, sys_classloader)) {
|
||||||
inject_class_loader_ = JNI_NewGlobalRef(env, my_cl);
|
inject_class_loader_ = JNI_NewGlobalRef(env, my_cl);
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ namespace lspd {
|
||||||
jclass class_linker_class_ = nullptr;
|
jclass class_linker_class_ = nullptr;
|
||||||
jmethodID post_fixup_static_mid_ = nullptr;
|
jmethodID post_fixup_static_mid_ = nullptr;
|
||||||
bool skip_ = false;
|
bool skip_ = false;
|
||||||
std::vector<char> dex{};
|
std::vector<std::byte> dex{};
|
||||||
|
|
||||||
Context() {}
|
Context() {}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,11 @@ namespace lspd {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegisterNativeLib(const std::string &library_name) {
|
void RegisterNativeLib(const std::string &library_name) {
|
||||||
|
static bool initialized = []() {
|
||||||
|
InstallNativeAPI();
|
||||||
|
return true;
|
||||||
|
}();
|
||||||
|
if (UNLIKELY(!initialized)) return;
|
||||||
LOGD("native_api: Registered %s", library_name.c_str());
|
LOGD("native_api: Registered %s", library_name.c_str());
|
||||||
moduleNativeLibs.push_back(library_name);
|
moduleNativeLibs.push_back(library_name);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ namespace lspd {
|
||||||
InstallRiruHooks();
|
InstallRiruHooks();
|
||||||
// install ART hooks
|
// install ART hooks
|
||||||
InstallArtHooks(handle_libart);
|
InstallArtHooks(handle_libart);
|
||||||
InstallNativeAPI();
|
// InstallNativeAPI();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstallArtHooks(void *art_handle) {
|
void InstallArtHooks(void *art_handle) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue