|
9 | 9 |
|
10 | 10 | namespace VirtualMap { |
11 | 11 |
|
| 12 | +void logPossibleStrings(const char *start, size_t size, |
| 13 | + size_t min_string_length = 4) { |
| 14 | + const char *end = start + size; |
| 15 | + const char *ptr = start; |
| 16 | + |
| 17 | + LOGD("--- Starting String Dump (min length: %zu, range size: %zu) ---", |
| 18 | + min_string_length, size); |
| 19 | + |
| 20 | + while (ptr < end) { |
| 21 | + // Find the beginning of a potential string (a printable character) |
| 22 | + if (isprint(static_cast<unsigned char>(*ptr))) { |
| 23 | + const char *string_start = ptr; |
| 24 | + const char *string_end = ptr + 1; |
| 25 | + |
| 26 | + // Find the end of the sequence of printable characters |
| 27 | + while (string_end < end && |
| 28 | + isprint(static_cast<unsigned char>(*string_end))) { |
| 29 | + string_end++; |
| 30 | + } |
| 31 | + |
| 32 | + size_t length = string_end - string_start; |
| 33 | + |
| 34 | + // If the sequence meets our minimum length, log it |
| 35 | + if (length >= min_string_length) { |
| 36 | + // Safely create a std::string from the non-null-terminated segment |
| 37 | + std::string found_str(string_start, length); |
| 38 | + |
| 39 | + // Log the string and its memory offset using LOGD's format string |
| 40 | + LOGI("Offset 0x%zx: \"%s\"", (size_t)(string_start - start), |
| 41 | + found_str.c_str()); |
| 42 | + } |
| 43 | + |
| 44 | + // Advance the main pointer past the sequence we just processed |
| 45 | + ptr = string_end; |
| 46 | + } else { |
| 47 | + // Not a printable character, just move to the next byte |
| 48 | + ptr++; |
| 49 | + } |
| 50 | + } |
| 51 | + LOGD("--- Finished String Dump ---"); |
| 52 | +} |
| 53 | + |
| 54 | +void DumpStackStrings() { |
| 55 | + for (auto &map : MapInfo::Scan()) { |
| 56 | + if (map.dev == 0 && map.inode == 0 && map.offset == 0 && |
| 57 | + map.path == "[anon:stack_and_tls:main]") { |
| 58 | + logPossibleStrings(reinterpret_cast<const char *>(map.start), |
| 59 | + map.end - map.start, 3); |
| 60 | + } |
| 61 | + } |
| 62 | +} |
| 63 | + |
12 | 64 | MapInfo *DetectInjection() { |
13 | 65 | int jit_cache_count = 0; |
14 | 66 | int jit_zygote_cache_count = 0; |
|
0 commit comments