3 #include <crt_externs.h>
6 #include <mach-o/ldsyms.h>
7 #include <mach-o/dyld_images.h>
9 #include <sys/sysctl.h>
11 __attribute__((constructor
))
12 void init(int argc
, const char *argv
[], const char *envp
[], const char *appl
[], void *vars
__attribute__((unused
))) {
15 printf("argv = %p\n", argv
);
16 for (i
=0; argv
[i
]; i
++) {
17 printf("argv[%2d] = %p %.100s%s\n", i
, argv
[i
], argv
[i
], strlen(argv
[i
]) > 100 ? "..." : "");
19 printf("envp = %p\n", envp
);
20 for (i
=0; envp
[i
]; i
++) {
21 printf("envp[%2d] = %p %.100s%s\n", i
, envp
[i
], envp
[i
], strlen(envp
[i
]) > 100 ? "..." : "");
23 printf("appl = %p\n", appl
);
24 for (i
=0; appl
[i
]; i
++) {
25 printf("appl[%2d] = %p %.100s%s\n", i
, appl
[i
], appl
[i
], strlen(appl
[i
]) > 100 ? "..." : "");
29 void printexecinfo(void)
33 size_t len
= sizeof(stackaddr
);
35 printf("executable load address = 0x%016llx\n", (uint64_t)(uintptr_t)&_mh_execute_header
);
37 ret
= sysctlbyname("kern.usrstack64", &stackaddr
, &len
, NULL
, 0);
39 err(1, "sysctlbyname");
41 printf(" stack address = 0x%016llx\n", stackaddr
);
44 void printdyldinfo(void)
46 task_dyld_info_data_t info
;
47 mach_msg_type_number_t size
= TASK_DYLD_INFO_COUNT
;
49 struct dyld_all_image_infos
*all_image_infos
;
51 kret
= task_info(mach_task_self(), TASK_DYLD_INFO
,
52 (void *)&info
, &size
);
53 if (kret
!= KERN_SUCCESS
)
54 errx(1, "task_info: %s", mach_error_string(kret
));
56 all_image_infos
= (struct dyld_all_image_infos
*)(uintptr_t)info
.all_image_info_addr
;
58 printf(" dyld load address = 0x%016llx\n", (uint64_t)(uintptr_t)all_image_infos
->dyldImageLoadAddress
);
59 printf(" shared cache slide = 0x%016llx\n", (uint64_t)(uintptr_t)all_image_infos
->sharedCacheSlide
);
63 int main(int argc
, char *argv
[]) {