blob: 6d6a8ea2e040838aa8ebc0f6229530978a0e8423 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#include <assert.h>
#include <dlfcn.h>
#include <stdio.h>
#include <string.h>
void print_libso() {
FILE* m = fopen("/proc/self/maps", "r");
assert(m);
char line[256];
while (fgets(line, sizeof(line), m)) {
if (strstr(line, "lib.so")) {
printf("%s", line);
}
}
fclose(m);
}
int main(int argc, char* argv[]) {
for (int i = 1; i < argc; ++i) {
void* h = dlopen(argv[i], RTLD_LAZY | RTLD_GLOBAL);
if (!h) {
puts(dlerror());
return 1;
}
void (*next)() = dlsym(h, "moose");
assert(next);
next();
// leak lib, we want to priint the mmap.
}
print_libso();
return 0;
}
|