From c9e91f007e15952e0eeb8b1edff0d122b3a148f5 Mon Sep 17 00:00:00 2001 From: LoveSy Date: Sun, 27 Nov 2022 01:06:31 +0800 Subject: [PATCH] In case mprotect fails --- lsplt/src/main/jni/lsplt.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lsplt/src/main/jni/lsplt.cc b/lsplt/src/main/jni/lsplt.cc index 83fede5..446157d 100644 --- a/lsplt/src/main/jni/lsplt.cc +++ b/lsplt/src/main/jni/lsplt.cc @@ -164,11 +164,12 @@ public: info.hooks.clear(); continue; } - mprotect(reinterpret_cast(info.start), len, PROT_WRITE); - for (auto &[addr, backup] : info.hooks) { - *reinterpret_cast(addr) = backup; + if (!mprotect(reinterpret_cast(info.start), len, PROT_WRITE)) { + for (auto &[addr, backup] : info.hooks) { + *reinterpret_cast(addr) = backup; + } + mprotect(reinterpret_cast(info.start), len, info.perm); } - mprotect(reinterpret_cast(info.start), len, info.perm); info.hooks.clear(); info.backup = 0; }