]>
Commit | Line | Data |
---|---|---|
6d2010ae A |
1 | #include <stdio.h> |
2 | #include <err.h> | |
3 | #include <crt_externs.h> | |
4 | #include <string.h> | |
5 | #include <mach/mach.h> | |
6 | #include <mach-o/ldsyms.h> | |
7 | #include <mach-o/dyld_images.h> | |
8 | #include <stdlib.h> | |
9 | ||
10 | __attribute__((constructor)) | |
11 | void init(int argc, const char *argv[], const char *envp[], const char *appl[], void *vars __attribute__((unused))) { | |
12 | int i; | |
13 | ||
14 | printf("argv = %p\n", argv); | |
15 | for (i=0; argv[i]; i++) { | |
16 | printf("argv[%2d] = %p %.100s%s\n", i, argv[i], argv[i], strlen(argv[i]) > 100 ? "..." : ""); | |
17 | } | |
18 | printf("envp = %p\n", envp); | |
19 | for (i=0; envp[i]; i++) { | |
20 | printf("envp[%2d] = %p %.100s%s\n", i, envp[i], envp[i], strlen(envp[i]) > 100 ? "..." : ""); | |
21 | } | |
22 | printf("appl = %p\n", appl); | |
23 | for (i=0; appl[i]; i++) { | |
24 | printf("appl[%2d] = %p %.100s%s\n", i, appl[i], appl[i], strlen(appl[i]) > 100 ? "..." : ""); | |
25 | } | |
26 | } | |
27 | ||
28 | void printexecinfo(void) | |
29 | { | |
30 | int ret; | |
31 | uint64_t stackaddr; | |
32 | size_t len = sizeof(stackaddr); | |
33 | ||
34 | printf("executable load address = 0x%016llx\n", (uint64_t)(uintptr_t)&_mh_execute_header); | |
35 | ||
36 | ret = sysctlbyname("kern.usrstack64", &stackaddr, &len, NULL, 0); | |
37 | if (ret == -1) | |
38 | err(1, "sysctlbyname"); | |
39 | ||
40 | printf(" stack address = 0x%016llx\n", stackaddr); | |
41 | } | |
42 | ||
43 | void printdyldinfo(void) | |
44 | { | |
45 | task_dyld_info_data_t info; | |
46 | mach_msg_type_number_t size = TASK_DYLD_INFO_COUNT; | |
47 | kern_return_t kret; | |
48 | struct dyld_all_image_infos *all_image_infos; | |
49 | ||
50 | kret = task_info(mach_task_self(), TASK_DYLD_INFO, | |
51 | (void *)&info, &size); | |
52 | if (kret != KERN_SUCCESS) | |
53 | errx(1, "task_info: %s", mach_error_string(kret)); | |
54 | ||
55 | all_image_infos = (struct dyld_all_image_infos *)(uintptr_t)info.all_image_info_addr; | |
56 | ||
57 | printf(" dyld load address = 0x%016llx\n", (uint64_t)(uintptr_t)all_image_infos->dyldImageLoadAddress); | |
58 | printf(" shared cache slide = 0x%016llx\n", (uint64_t)(uintptr_t)all_image_infos->sharedCacheSlide); | |
59 | ||
60 | } | |
61 | ||
62 | int main(int argc, char *argv[]) { | |
63 | ||
64 | printexecinfo(); | |
65 | printdyldinfo(); | |
66 | ||
67 | return 0; | |
68 | } |