Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Searching for program dependencies.

Share your HowTo, Documentation, Tips and Tricks. Not for support questions!.
Post Reply
Message
Author
User avatar
edbarx
Posts: 5401
Joined: 2007-07-18 06:19
Location: 35° 50 N, 14 º 35 E
Been thanked: 2 times

Searching for program dependencies.

#1 Post by edbarx »

We will start with the obvious using apt-cache depends. Let us do it for medit:

Code: Select all

edbarx@sid-inst:~$ apt-cache depends medit
medit
  Depends: libatk1.0-0
  Depends: libc6
  Depends: libcairo2
  Depends: libgcc1
  Depends: libgdk-pixbuf2.0-0
  Depends: libglib2.0-0
  Depends: libgtk2.0-0
  Depends: libice6
  Depends: libpango-1.0-0
  Depends: libpangocairo-1.0-0
  Depends: libpython2.7
  Depends: libsm6
  Depends: libstdc++6
  Depends: libx11-6
  Depends: libxml2
  Depends: python
  Depends: python-support
To list the library dependencies of a program or library, use this command:

Code: Select all

ldd /path/to/executable/file
Example: Let us list the library dependencies of /lib/x86_64-linux-gnu/libsystemd.so.0:

Code: Select all

edbarx@sid-inst:~$ ldd /lib/x86_64-linux-gnu/libsystemd.so.0
	linux-vdso.so.1 (0x00007fff6f9fc000)
	librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f056976a000)
	liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f0569547000)
	libgcrypt.so.20 => /lib/x86_64-linux-gnu/libgcrypt.so.20 (0x00007f0569265000)
	libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f056904e000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f0568e4a000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f0568c2c000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f0568883000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f0569ba2000)
	libgpg-error.so.0 => /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007f0568671000)
To discover what functions are imported by an executable, use the command:

Code: Select all

nm -D /path/to/executable/file | grep " U "
Example: Let us list what /bin/ls imports:

Code: Select all

edbarx@sid-inst:~$ nm -D /bin/ls | grep " U "
                 U abort
                 U acl_extended_file
                 U acl_get_entry
                 U acl_get_tag_type
                 U __assert_fail
                 U bindtextdomain
                 U calloc
                 U clock_gettime
                 U close
                 U closedir

                 [.....]

                 U stpcpy
                 U stpncpy
                 U strchr
                 U strcmp
                 U strcoll
                 U strcpy
                 U strftime
                 U strlen
                 U strncmp
                 U strrchr
                 U strstr
                 U strtoul
                [....]
Example: Let us list the imported functions by /lib/x86_64-linux-gnu/librt.so.1:

Code: Select all

edbarx@sid-inst:~$ nm -D  /lib/x86_64-linux-gnu/librt.so.1 | grep " U "
                 U __assert_fail
                 U calloc
                 U __clock_getcpuclockid
                 U __clock_getres
                 U __clock_gettime
                 U __clock_nanosleep
                 U __clock_settime
                 U __endmntent
                 U errno
                 U fcntl
                 U fdatasync
                 U __fortify_fail
                 U free
                 U fsync
                 U __getmntent_r
                 U getpid
                 U gettimeofday
                 U getuid
                 [.....]
To list what functions are exported by a library or executable, use:
Example: Let us list what libc.so.6 exports:

Code: Select all

edbarx@sid-inst:~$ nm -D /lib/x86_64-linux-gnu/libc.so.6 | grep " T "
0000000000041bc0 T a64l
00000000000363a0 T abort
0000000000038200 T abs
00000000000e70d0 T accept4
00000000000df050 T acct
00000000000438b0 T addseverity
00000000000e60c0 T __adjtimex
00000000000b72d0 T alarm
00000000000b39a0 T alphasort
00000000000e6020 T __arch_prctl
000000000008c890 T __argz_count
000000000008cad0 T argz_delete
000000000008ca80 T __argz_next
000000000008cca0 T __argz_stringify
00000000000a7de0 T asctime
[.....] ( there are many more exported functions )
Example: Let us see what functions /bin/mount exports (programs usually do not export functions):

Code: Select all

edbarx@sid-inst:~$ nm -D /bin/mount | grep " T "
0000000000405c1c T _fini
0000000000402a28 T _init
There is also objdump which can be used to discover what a library contains and even to list its assembly code.

By inspecting what libraries an executable file (program) uses, and what functions a program imports, it is possible to port it to your distribution of choice.
Debian == { > 30, 000 packages }; Debian != systemd
The worst infection of all, is a false sense of security!
It is hard to get away from CLI tools.

Post Reply