Re: Read current executable even if it's been deleted?
Re: Read current executable even if it's been deleted?
- Subject: Re: Read current executable even if it's been deleted?
- From: N <email@hidden>
- Date: Tue, 03 Jul 2018 20:10:28 +0200
You can use _dyld_*_image API, see dyld/include/mach-o/dyld.h. Because the
loader does not preserve the on-disk copy of the image in memory,
the resulting image will likely be different from the on-disk image, but
depending on your goal this should not matter.
> On 3 Jul 2018, at 01:34, Alec Mocatta <email@hidden> wrote:
>
> Linux has a path in the /proc filesystem – /proc/self/exe – which lets one
> read the contents of ones own executable, even if it has since been deleted
> or was exec'd in an atypical manner (e.g. execve("/proc/self/fd/123", ...)).
>
> On Darwin/macOS I can use _NSGetExecutablePath() to get the path to the
> current executable. The problem is this breaks in the aforementioned cases:
> namely deletion/moving.
>
> Is there a way to read the contents of ones own executable, that works in the
> face of deletion/moving?
>
> Thanks,
> Alec
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Darwin-kernel mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden