| 46 | } |
| 47 | |
| 48 | uintptr_t VtableHook::FindSteamclient(size_t& outSize) |
| 49 | { |
| 50 | FILE* f = fopen("/proc/self/maps", "r"); |
| 51 | if (!f) |
| 52 | { |
| 53 | Log::Error("cannot open /proc/self/maps"); |
| 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | uintptr_t labeledMin = 0; |
| 58 | uintptr_t labeledMax = 0; |
| 59 | g_readableCount = 0; |
| 60 | g_writableCount = 0; |
| 61 | char line[512]; |
| 62 | |
| 63 | while (fgets(line, sizeof(line), f)) |
| 64 | { |
| 65 | uintptr_t start_addr, end_addr; |
| 66 | if (sscanf(line, "%" SCNxPTR "-%" SCNxPTR, &start_addr, &end_addr) < 2) |
| 67 | continue; |
| 68 | if (strstr(line, "steamclient.so")) |
| 69 | { |
| 70 | if (labeledMin == 0 || start_addr < labeledMin) |
| 71 | labeledMin = start_addr; |
| 72 | if (end_addr > labeledMax) |
| 73 | labeledMax = end_addr; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | if (labeledMin == 0) |
| 78 | { |
| 79 | fclose(f); |
| 80 | Log::Error("steamclient.so not found in /proc/self/maps"); |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | // Anchor base on ELF magic to correct for labeled-min offset. |
| 85 | uintptr_t base = FindElfBaseBackward(labeledMin); |
| 86 | if (base == 0) |
| 87 | { |
| 88 | Log::Warn("ELF magic not found backward from labeled steamclient.so start %p, using labeled min", |
| 89 | (void*)labeledMin); |
| 90 | base = labeledMin; |
| 91 | } |
| 92 | else if (base != labeledMin) |
| 93 | { |
| 94 | Log::Info("corrected steamclient.so base from labeled %p to ELF-magic %p (gap=0x%zx)", |
| 95 | (void*)labeledMin, (void*)base, labeledMin - base); |
| 96 | } |
| 97 | |
| 98 | // Capture readable mappings within +/-16 MiB of labeled span. |
| 99 | // .data.rel.ro may be in anonymous mappings outside the labeled range. |
| 100 | // Slot-pointer validation still uses the tight labeled span. |
| 101 | const uintptr_t adjacency = 16ULL * 1024 * 1024; |
| 102 | const uintptr_t scanLo = (base > adjacency) ? base - adjacency : 0; |
| 103 | const uintptr_t scanHi = labeledMax + adjacency; |
| 104 | |
| 105 | rewind(f); |
nothing calls this directly
no test coverage detected