Re: Read current executable even if it's been deleted?
site_archiver@lists.apple.com Delivered-To: darwin-kernel@lists.apple.com Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mocatta.net; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:cc; bh=/new6p/LqLe48LTzzdY1MuHv5hVZ7LRDPzPBrYNBNzY=; b=IFVlbgsjkxSt1S/Sdhvkn0c/6gEI+wK/Or7kxVMBHJ0asUSo9f5+i+Thp5T4mniz2d Hf84q3QxQojgT66j+J5dHxKmygl2GCsYjk9Iq+8RTMDJ0N/ciZXh7iXuPMlRhKTLAD1W JMZE2S9QeiEk1ro3cpobntd01xT7KaXYvGuq4= Thank you all, the _dyld_*_image API sounds like it does the job. I'll investigate and post back if I have any issues. Alec On Tue, Jul 3, 2018 at 7:10 PM, N <scandium@me.com> wrote:
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 <alec@mocatta.net> 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 (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/darwin-kernel/scandium%40me.com
This email sent to scandium@me.com
_______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-kernel mailing list (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/darwin-kernel/site_archiver%40lists.... This email sent to site_archiver@lists.apple.com
participants (1)
-
Alec Mocatta