From 58aef08fe1cc856a40cfd62bbfc82906de350b6d Mon Sep 17 00:00:00 2001 From: boykopovar Date: Sun, 6 Sep 2026 13:49:24 +0300 Subject: [PATCH] feat(nid): add nid_no_patch rule --- core/libs/nid/include/nid/NidPatcherUtils.hpp | 7 +++++++ core/libs/nid/src/ElfNidPatcher.cpp | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/core/libs/nid/include/nid/NidPatcherUtils.hpp b/core/libs/nid/include/nid/NidPatcherUtils.hpp index 2873f2f00..38671236a 100644 --- a/core/libs/nid/include/nid/NidPatcherUtils.hpp +++ b/core/libs/nid/include/nid/NidPatcherUtils.hpp @@ -13,9 +13,16 @@ namespace Internal { constexpr char kNidPostfix[] = "_nid_postfix"; constexpr std::size_t kNidPostfixLen = sizeof(kNidPostfix) - 1u; +constexpr char kNidNoPatch[] = "_nid_no_patch"; +constexpr std::size_t kNidNoPatchLen = sizeof(kNidNoPatch) - 1u; constexpr char kNidDisambigMarker[] = "_nid_disambig"; constexpr std::size_t kNidDisambigMarkerLen = sizeof(kNidDisambigMarker) - 1u; +inline bool IsNidNoPatch(const std::string& name) { + return name.size() >= kNidNoPatchLen && + name.compare(name.size() - kNidNoPatchLen, kNidNoPatchLen, kNidNoPatch) == 0; +} + inline std::string StripNidPostfix(const std::string& name) { std::string result = name; if (result.size() >= kNidPostfixLen && diff --git a/core/libs/nid/src/ElfNidPatcher.cpp b/core/libs/nid/src/ElfNidPatcher.cpp index 3c0cae853..8fb9fbb3b 100644 --- a/core/libs/nid/src/ElfNidPatcher.cpp +++ b/core/libs/nid/src/ElfNidPatcher.cpp @@ -485,12 +485,12 @@ void ElfNidPatcher::PatchNids(std::vector& elf, const std::string& if (sym.st_name == 0u) continue; - const std::uint8_t binding = sym.st_info >> 4u; - const bool isPatchable = binding != kStbLocal && sym.st_shndx != kShnUndef; - const std::string symName = ReadCStr(origDynStr, sym.st_name); if (symName.empty()) continue; + const std::uint8_t binding = sym.st_info >> 4u; + const bool isPatchable = binding != kStbLocal && sym.st_shndx != kShnUndef && !IsNidNoPatch(symName); + std::string newValue = symName; if (isPatchable) { const std::string stripped = StripNidPostfix(symName);