3 #include <crt_externs.h>
6 #include <mach-o/ldsyms.h>
7 #include <mach-o/dyld_images.h>
8 #include <mach-o/arch.h>
10 #include <sys/sysctl.h>
12 __attribute__((constructor
))
14 init(int argc
, const char *argv
[], const char *envp
[], const char *appl
[], void *vars
__attribute__((unused
)))
18 printf("argv = %p\n", argv
);
19 for (i
= 0; argv
[i
]; i
++) {
20 printf("argv[%2d] = %p %.100s%s\n", i
, argv
[i
], argv
[i
], strlen(argv
[i
]) > 100 ? "..." : "");
22 printf("envp = %p\n", envp
);
23 for (i
= 0; envp
[i
]; i
++) {
24 printf("envp[%2d] = %p %.100s%s\n", i
, envp
[i
], envp
[i
], strlen(envp
[i
]) > 100 ? "..." : "");
26 printf("appl = %p\n", appl
);
27 for (i
= 0; appl
[i
]; i
++) {
28 printf("appl[%2d] = %p %.100s%s\n", i
, appl
[i
], appl
[i
], strlen(appl
[i
]) > 100 ? "..." : "");
37 size_t len
= sizeof(stackaddr
);
38 const NXArchInfo
*arch
= NXGetArchInfoFromCpuType(_mh_execute_header
.cputype
, _mh_execute_header
.cpusubtype
& ~CPU_SUBTYPE_MASK
);
40 printf("executable load address = 0x%016llx\n", (uint64_t)(uintptr_t)&_mh_execute_header
);
41 printf("executable cputype 0x%08x cpusubtype 0x%08x (%s:%s)\n",
42 _mh_execute_header
.cputype
,
43 _mh_execute_header
.cpusubtype
,
44 arch
? arch
->name
: "unknown",
45 arch
? arch
->description
: "unknown");
47 ret
= sysctlbyname("kern.usrstack64", &stackaddr
, &len
, NULL
, 0);
49 err(1, "sysctlbyname");
52 printf(" stack address = 0x%016llx\n", stackaddr
);
58 task_dyld_info_data_t info
;
59 mach_msg_type_number_t size
= TASK_DYLD_INFO_COUNT
;
61 struct dyld_all_image_infos
*all_image_infos
;
63 kret
= task_info(mach_task_self(), TASK_DYLD_INFO
,
64 (void *)&info
, &size
);
65 if (kret
!= KERN_SUCCESS
) {
66 errx(1, "task_info: %s", mach_error_string(kret
));
69 all_image_infos
= (struct dyld_all_image_infos
*)(uintptr_t)info
.all_image_info_addr
;
71 printf(" dyld load address = 0x%016llx\n", (uint64_t)(uintptr_t)all_image_infos
->dyldImageLoadAddress
);
72 printf(" shared cache slide = 0x%016llx\n", (uint64_t)(uintptr_t)all_image_infos
->sharedCacheSlide
);
76 main(int argc
, char *argv
[])