| 211 | } |
| 212 | |
| 213 | static std::vector<uint8_t> SerializeMessage(void* msg) { |
| 214 | if (!msg || !g_serializeToArray) return {}; |
| 215 | |
| 216 | // vtable[9] = ByteSizeLong (offset +36 on 32-bit) |
| 217 | uint32_t* vtable = *(uint32_t**)msg; |
| 218 | if (!vtable || !vtable[9]) return {}; |
| 219 | using ByteSizeFn = int(__attribute__((cdecl)) *)(void*); |
| 220 | ProtoCrashGuard guard; |
| 221 | int sig = sigsetjmp(g_protoJmpBuf, 1); |
| 222 | if (sig != 0) { |
| 223 | LOG("[Hook] SerializeToArray helper crashed with signal %d", sig); |
| 224 | return {}; |
| 225 | } |
| 226 | |
| 227 | int size = ((ByteSizeFn)vtable[9])(msg); |
| 228 | if (size <= 0 || size > 64 * 1024 * 1024) return {}; |
| 229 | |
| 230 | std::vector<uint8_t> buf(size); |
| 231 | g_serializeToArray(msg, buf.data()); |
| 232 | return buf; |
| 233 | } |
| 234 | |
| 235 | static bool ParseIntoMessage(void* msg, const uint8_t* data, size_t len) { |
| 236 | if (!msg || !g_parseFromArray || !data || len == 0) return false; |
no outgoing calls
no test coverage detected