|
1 | 1 | #include <dlfcn.h>
|
2 | 2 | #include <sys/types.h>
|
| 3 | +#include <fcntl.h> |
| 4 | +#include <zconf.h> |
| 5 | +#include <unistd.h> |
| 6 | +#include <cstring> |
| 7 | +#include <cstdio> |
| 8 | +#include "logging.h" |
3 | 9 |
|
4 | 10 | #ifdef __LP64__
|
5 |
| -#define MEMTRACK_LIBRARY "/system/lib64/libmemtrack_real.so" |
| 11 | +#define LIB_PATH "/system/lib64" |
6 | 12 | #else
|
7 |
| -#define MEMTRACK_LIBRARY "/system/lib/libmemtrack_real.so" |
| 13 | +#define LIB_PATH "/system/lib" |
8 | 14 | #endif
|
9 | 15 |
|
| 16 | +static void *init() { |
| 17 | + char path[PATH_MAX] = {0}, buf[64] = {0}; |
| 18 | + |
| 19 | + int fd = open("/data/adb/riru/random_name", O_RDONLY); |
| 20 | + if (fd > 0 && read(fd, buf, 64)) { |
| 21 | + read(fd, buf, 64); |
| 22 | + snprintf(path, PATH_MAX, "%s/lib%s.so", LIB_PATH, buf); |
| 23 | + close(fd); |
| 24 | + if (access(path, F_OK) == 0) { |
| 25 | + return dlopen(path, RTLD_NOW | RTLD_GLOBAL); |
| 26 | + } |
| 27 | + } |
| 28 | + return nullptr; |
| 29 | +} |
| 30 | + |
| 31 | +static void *handle = init(); |
| 32 | + |
10 | 33 | extern "C" {
|
11 |
| -static void *handle = dlopen(MEMTRACK_LIBRARY, RTLD_NOW | RTLD_GLOBAL); |
12 | 34 |
|
13 | 35 | #define FUNC_DEF(NAME, RET, ...) \
|
14 | 36 | static void* sym_##NAME = handle ? dlsym(handle, #NAME) : NULL; \
|
@@ -161,56 +183,66 @@ FUNC_DEF(_ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9a
|
161 | 183 | if (!sym__ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEE8__appendEm)
|
162 | 184 | return;
|
163 | 185 |
|
164 |
| - return ((_ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEE8__appendEm_t) sym__ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEE8__appendEm)(a1, a2); |
| 186 | + return ((_ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEE8__appendEm_t) sym__ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEE8__appendEm)( |
| 187 | + a1, a2); |
165 | 188 | }
|
166 | 189 |
|
167 | 190 | FUNC_DEF(_ZNSt3__114__split_bufferIN7android8hardware8memtrack4V1_014MemtrackRecordERNS_9allocatorIS5_EEEC2EjjS8_, int, uint a1, uint a2, void *a3) {
|
168 | 191 | if (!sym__ZNSt3__114__split_bufferIN7android8hardware8memtrack4V1_014MemtrackRecordERNS_9allocatorIS5_EEEC2EjjS8_)
|
169 | 192 | return 0;
|
170 | 193 |
|
171 |
| - return ((_ZNSt3__114__split_bufferIN7android8hardware8memtrack4V1_014MemtrackRecordERNS_9allocatorIS5_EEEC2EjjS8__t) sym__ZNSt3__114__split_bufferIN7android8hardware8memtrack4V1_014MemtrackRecordERNS_9allocatorIS5_EEEC2EjjS8_)(a1, a2, a3); |
| 194 | + return ((_ZNSt3__114__split_bufferIN7android8hardware8memtrack4V1_014MemtrackRecordERNS_9allocatorIS5_EEEC2EjjS8__t) sym__ZNSt3__114__split_bufferIN7android8hardware8memtrack4V1_014MemtrackRecordERNS_9allocatorIS5_EEEC2EjjS8_)( |
| 195 | + a1, a2, a3); |
172 | 196 | }
|
173 | 197 |
|
174 | 198 | FUNC_DEF(_ZNSt3__113__vector_baseIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEED2Ev, void, void **a1) {
|
175 | 199 | if (!sym__ZNSt3__113__vector_baseIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEED2Ev)
|
176 | 200 | return;
|
177 | 201 |
|
178 |
| - return ((_ZNSt3__113__vector_baseIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEED2Ev_t) sym__ZNSt3__113__vector_baseIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEED2Ev)(a1); |
| 202 | + return ((_ZNSt3__113__vector_baseIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEED2Ev_t) sym__ZNSt3__113__vector_baseIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEED2Ev)( |
| 203 | + a1); |
179 | 204 | }
|
180 | 205 |
|
181 | 206 | FUNC_DEF(_ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEE8__appendEj, int, int a1, uint a2) {
|
182 | 207 | if (!sym__ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEE8__appendEj)
|
183 | 208 | return 0;
|
184 | 209 |
|
185 |
| - return ((_ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEE8__appendEj_t) sym__ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEE8__appendEj)(a1, a2); |
| 210 | + return ((_ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEE8__appendEj_t) sym__ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEE8__appendEj)( |
| 211 | + a1, a2); |
186 | 212 | }
|
187 | 213 |
|
188 |
| -FUNC_DEF(_ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEE26__swap_out_circular_bufferERNS_14__split_bufferIS5_RS7_EE, int, int *a1, void *a2) { |
| 214 | +FUNC_DEF( |
| 215 | + _ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEE26__swap_out_circular_bufferERNS_14__split_bufferIS5_RS7_EE, |
| 216 | + int, int *a1, void *a2) { |
189 | 217 | if (!sym__ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEE26__swap_out_circular_bufferERNS_14__split_bufferIS5_RS7_EE)
|
190 | 218 | return 0;
|
191 | 219 |
|
192 |
| - return ((_ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEE26__swap_out_circular_bufferERNS_14__split_bufferIS5_RS7_EE_t) sym__ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEE26__swap_out_circular_bufferERNS_14__split_bufferIS5_RS7_EE)(a1, a2); |
| 220 | + return ((_ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEE26__swap_out_circular_bufferERNS_14__split_bufferIS5_RS7_EE_t) sym__ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEE26__swap_out_circular_bufferERNS_14__split_bufferIS5_RS7_EE)( |
| 221 | + a1, a2); |
193 | 222 | }
|
194 | 223 |
|
195 | 224 | FUNC_DEF(_ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEE8allocateEj, int, void *a1, uint a2) {
|
196 | 225 | if (!sym__ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEE8allocateEj)
|
197 | 226 | return 0;
|
198 | 227 |
|
199 |
| - return ((_ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEE8allocateEj_t) sym__ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEE8allocateEj)(a1, a2); |
| 228 | + return ((_ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEE8allocateEj_t) sym__ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEE8allocateEj)( |
| 229 | + a1, a2); |
200 | 230 | }
|
201 | 231 |
|
202 | 232 | FUNC_DEF(_ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEE6resizeEj, int, int a1, uint a2) {
|
203 | 233 | if (!sym__ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEE6resizeEj)
|
204 | 234 | return 0;
|
205 | 235 |
|
206 |
| - return ((_ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEE6resizeEj_t) sym__ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEE6resizeEj)(a1, a2); |
| 236 | + return ((_ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEE6resizeEj_t) sym__ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEE6resizeEj)( |
| 237 | + a1, a2); |
207 | 238 | }
|
208 | 239 |
|
209 | 240 | FUNC_DEF(_ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEEC2ERKS8_, int, void *a1, void *a2) {
|
210 | 241 | if (!sym__ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEEC2ERKS8_)
|
211 | 242 | return 0;
|
212 | 243 |
|
213 |
| - return ((_ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEEC2ERKS8__t) sym__ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEEC2ERKS8_)(a1, a2); |
| 244 | + return ((_ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEEC2ERKS8__t) sym__ZNSt3__16vectorIN7android8hardware8memtrack4V1_014MemtrackRecordENS_9allocatorIS5_EEEC2ERKS8_)( |
| 245 | + a1, a2); |
214 | 246 | }
|
215 | 247 |
|
216 | 248 | struct memtrack_proc;
|
|
0 commit comments