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