[core] Manually release ElfImg (#747)

This commit is contained in:
LoveSy 2021-06-15 10:06:53 +08:00 committed by GitHub
parent b49001cfab
commit cef4137c7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 11 additions and 7 deletions

View File

@ -99,16 +99,14 @@ android {
"-D__FILE__=__FILE_NAME__", "-D__FILE__=__FILE_NAME__",
"-DRIRU_MODULE", "-DRIRU_MODULE",
"-DRIRU_MODULE_API_VERSION=$moduleMaxRiruApiVersion", "-DRIRU_MODULE_API_VERSION=$moduleMaxRiruApiVersion",
"""-DMODULE_NAME=\"$riruModuleId\"""" """-DMODULE_NAME=\"$riruModuleId\"""",
// "-DRIRU_MODULE_VERSION=$verCode", // this will stop ccache from hitting
// """-DRIRU_MODULE_VERSION_NAME=\"$verName\"""",
) )
cppFlags("-std=c++20", *flags) cppFlags("-std=c++20", *flags)
cFlags("-std=c18", *flags) cFlags("-std=c18", *flags)
arguments( arguments(
"-DANDROID_STL=none", "-DANDROID_STL=none",
"-DVERSION_CODE=$verCode", "-DVERSION_CODE=$verCode",
"-DVERSION_NAME=$verName" "-DVERSION_NAME=$verName",
) )
targets("lspd") targets("lspd")
} }

View File

@ -18,6 +18,7 @@
## Copyright (C) 2021 LSPosed Contributors ## Copyright (C) 2021 LSPosed Contributors
## ##
project(libcxx)
cmake_minimum_required(VERSION 3.4.1) cmake_minimum_required(VERSION 3.4.1)
find_program(CCACHE ccache) find_program(CCACHE ccache)

View File

@ -231,6 +231,7 @@ namespace lspd {
} else { } else {
auto context = Context::ReleaseInstance(); auto context = Context::ReleaseInstance();
auto service = Service::ReleaseInstance(); auto service = Service::ReleaseInstance();
art_img.reset();
LOGD("skipped %s", process_name.get()); LOGD("skipped %s", process_name.get());
setAllowUnload(true); setAllowUnload(true);
} }

View File

@ -58,6 +58,10 @@ namespace SandHook {
return base != nullptr; return base != nullptr;
} }
const std::string name() const {
return elf;
}
~ElfImg(); ~ElfImg();
private: private:

View File

@ -47,7 +47,7 @@ namespace lspd {
return; return;
} }
LOGD("Start to install inline hooks"); LOGD("Start to install inline hooks");
SandHook::ElfImg &handle_libart = *art_img; const auto &handle_libart = *art_img;
if (!handle_libart.isValid()) { if (!handle_libart.isValid()) {
LOGE("Failed to fetch libart.so"); LOGE("Failed to fetch libart.so");
} }

View File

@ -39,7 +39,7 @@ namespace lspd {
void *sym_openDexFileNative = nullptr; void *sym_openDexFileNative = nullptr;
void *sym_setTrusted = nullptr; void *sym_setTrusted = nullptr;
void *sym_set_table_override = nullptr; void *sym_set_table_override = nullptr;
std::unique_ptr<SandHook::ElfImg> art_img = nullptr; std::unique_ptr<const SandHook::ElfImg> art_img = nullptr;
bool findLibArt() { bool findLibArt() {
art_img = std::make_unique<SandHook::ElfImg>(kLibArtName); art_img = std::make_unique<SandHook::ElfImg>(kLibArtName);

View File

@ -32,7 +32,7 @@ namespace SandHook {
namespace lspd { namespace lspd {
extern bool sym_initialized; extern bool sym_initialized;
extern std::unique_ptr<SandHook::ElfImg> art_img; extern std::unique_ptr<const SandHook::ElfImg> art_img;
extern void *sym_do_dlopen; extern void *sym_do_dlopen;
extern void *sym_openInMemoryDexFilesNative; extern void *sym_openInMemoryDexFilesNative;
extern void *sym_createCookieWithArray; extern void *sym_createCookieWithArray;