diff --git a/shared/utils/utils.h b/shared/utils/utils.h index 690a2921..0170d779 100644 --- a/shared/utils/utils.h +++ b/shared/utils/utils.h @@ -291,9 +291,15 @@ uintptr_t findPattern(uintptr_t dwAddress, const char* pattern, uintptr_t dwSear // Returns the first match, if any. uintptr_t findUniquePattern(bool& multiple, uintptr_t dwAddress, const char* pattern, const char* label = 0, uintptr_t dwSearchRangeLen = 0x1000000); +/// @brief Attempts to match the pattern provided with all regions of mapped read memory with the file provided +uintptr_t findUniquePatternInMappedFile(bool& multiple, const char* pattern, const char* file, const char* label = 0); + /// @brief Attempts to match the pattern provided with all regions of mapped read memory with the libil2cpp.so uintptr_t findUniquePatternInLibil2cpp(bool& multiple, const char* pattern, const char* label = 0); +/// @brief Attempts to match the pattern provided with all regions of mapped read memory with the libunity.so +uintptr_t findUniquePatternInLibunity(bool& multiple, const char* pattern, const char* label = 0); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index c0fc412e..019bee26 100644 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -232,13 +232,13 @@ uintptr_t findUniquePattern(bool& multiple, uintptr_t dwAddress, const char* pat return firstMatchAddr; } -uintptr_t findUniquePatternInLibil2cpp(bool& multiple, const char* pattern, const char* label) { +uintptr_t findUniquePatternInMappedFile(bool& multiple, const char* pattern, const char* file, const char* label) { // Essentially call findUniquePattern for each segment listed in /proc/self/maps std::ifstream procMap("/proc/self/maps"); std::string line; - uintptr_t match = 0; + uintptr_t firstMatchAddr = 0; while (std::getline(procMap, line)) { - if (line.find("libil2cpp.so") == std::string::npos) { + if (line.find(file) == std::string::npos) { continue; } auto idx = line.find_first_of('-'); @@ -255,11 +255,21 @@ uintptr_t findUniquePatternInLibil2cpp(bool& multiple, const char* pattern, cons auto perms = line.substr(spaceIdx + 1, 4); if (perms.find('r') != std::string::npos) { // Search between start and end - match = findUniquePattern(multiple, startAddr, pattern, label, endAddr - startAddr); + uintptr_t match = findUniquePattern(multiple, startAddr, pattern, label, endAddr - startAddr); + if(!firstMatchAddr) + firstMatchAddr = match; } } procMap.close(); - return match; + return firstMatchAddr; +} + +uintptr_t findUniquePatternInLibil2cpp(bool& multiple, const char* pattern, const char* label) { + return findUniquePatternInMappedFile(multiple, pattern, "libil2cpp.so", label); +} + +uintptr_t findUniquePatternInLibunity(bool& multiple, const char* pattern, const char* label) { + return findUniquePatternInMappedFile(multiple, pattern, "libunity.so", label); } // C# SPECIFIC