Date: Mon, 1 Jul 2019 23:15:23 -0400 From: Shawn Webb <shawn.webb@hardenedbsd.org> To: Yuri <yuri@rawbw.com> Cc: Freebsd hackers list <freebsd-hackers@FreeBSD.org> Subject: Re: Question: Is there a way to get the list of all dynamic libraries needed by a given elf through API? Message-ID: <20190702031523.lhlrqnlo7pxccl42@mutt-hbsd> In-Reply-To: <dfac779f-fa4f-a292-1a76-a9e7db5e024a@rawbw.com> References: <dfac779f-fa4f-a292-1a76-a9e7db5e024a@rawbw.com>
next in thread | previous in thread | raw e-mail | index | archive | help
--3nmsf3huqkgjbmlp Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Jul 01, 2019 at 07:54:27PM -0700, Yuri wrote: > I want to get the same information that 'ldd <elf-file>' returns, but fro= m a > C/C++ program without launching external processes. >=20 > It is possible to find the list of elf's shared library dependencies using > libelf. But I couldn't find how to map library names to full library path= s. >=20 >=20 > ldd(1) sets a certain environment variable, forks and calls execl(3), and > the "ld.so magic" does the rest. >=20 >=20 > Obviously, if one needs to do the same from their own C program, forking = is > a much less attractive option compared to the API way. >=20 >=20 > Is there an API to find such mappings? If no, why doesn't it exist? Hey Yuri, If you're not afraid to get your hands, feet, and pet rock named Steve dirty with the one true language of love, C, and you can link against libraries in base, take a look at libelf. If you want to use a scripting language, ldd is still the right tool for the job. Taking a look at the manpage for ldd(1), which will eventually point us to rtld(1), which will teach us that we can end up with something like: $ ldd -f '%p\n' /bin/ls /lib/libutil.so.9 /lib/libncursesw.so.8 /lib/libthr.so.3 /lib/librt.so.1 /lib/libm.so.5 /lib/libexecinfo.so.1 /lib/libc.so.7 (That is verbatim on my HardenedBSD dev laptop. The multitude of libraries is due to SafeStack and CFI.) So, what you're looking for is technically documented, but not in a straightforward manner. Thanks, --=20 Shawn Webb Cofounder / Security Engineer HardenedBSD Tor-ified Signal: +1 443-546-8752 Tor+XMPP+OTR: lattera@is.a.hacker.sx GPG Key ID: 0xFF2E67A277F8E1FA GPG Key Fingerprint: D206 BB45 15E0 9C49 0CF9 3633 C85B 0AF8 AB23 0FB2 --3nmsf3huqkgjbmlp Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEA6TL67gupaZ9nzhT/y5nonf44foFAl0azEUACgkQ/y5nonf4 4frJjA/+PiYNUyqaO4gfU78N1mO5R5vo4Y0oJ4WXu1+FMFC/ntWmuGStjJlM2iP8 1wJfzJV2bU+wEVGnpk07XkV19VPrVHDKlLc4gIqeiOrh6PMIQTMWiKo/JTUey4V+ sk+MRgCijgo7c0rvqpv1taW1TFSQQhuXK/UlhkAe9IQLxP/koJZTNI6QOi0aVsAt ZgaHSbOMgGRTbvhnu2cSHLuUkd1k2MHgNbHAty0Sqbw8RYI25KgQhKFC/NE6Srm7 c0z4U7HEiG+lgsaKUYxniRAjfwPdINr0dW8Auh1KdzRMjnDZKjl5+qiNOSzed8NN h7L6oYF5paadnHE25SUcy+nkwuapsHhM7lw2uW//le0JPdtebSdoZ2cGd/dskcFN y5gMX0Rr2mcs5Tc1fOTMAjGaLd0nHrMHRiL3p2PmuxKROc839vuExtqbAk+qaGaJ crlolDMv4khpcnE3sB4pM3DQ5yFcFvI2OvxRzGOcvFfAAf13fiD/X9qmLB3uEjKK JzaIF7SvOaxA54sm3WbeBo+imIESyga29HxRIAbtgb5V+RzCSHeH+4lBHCQ4FJos 1Xy/olJFt8L+Fb6XSMp4RutQ5xJhkmbB370wpeZfHKW1njY79Fc5soOmfpIgLktF 9/OySB6xg4eM755w11u8wai7I0MIdSJFy6i2iuXSr7ku+cKC7xE= =oA5P -----END PGP SIGNATURE----- --3nmsf3huqkgjbmlp--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20190702031523.lhlrqnlo7pxccl42>