Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions shared/utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
20 changes: 15 additions & 5 deletions src/utils/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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('-');
Expand All @@ -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
Expand Down