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=me.com; s=04042017; t=1530641432; bh=TPFetqqfO2MGNM61SaXhuWUNnmXEnRvJJUaIlUvXtUA=; h=Content-type:MIME-version:Subject:From:Date:Message-id:To; b=Cgs17UofLaD8DWvM52E0k+MAVnpGF7hJN5HnyQz/zWs/vHhi3HA+CltobJ/BTaVpF 4vUJ4EKYHujy/cW+KgE7jPw18Z0C1bd1GtrHovGAsg3n6qRXXmeufdxSWrKYW1aJ8X XEAVpvMIfiXSg6XOOsy5bLOIXwFernmkO6q3QZpi8wLmO1e5RnBExQ/gEBzqZ4FZzu Gk6tL4EcAxE/hOKxDdSmYEwGJANpHM140XiOKb2Pz7mSQMbvLZidky3jlfhTbz5cWK zsLw1Xyo2JT1JtXkZ0JmE4NRKGSjnLz6bVZfbbECDDGXchYU9LRuxPBMy7Dh/N2f3V 567yKoFo2qNlg== 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)
-
N