GrammaTech / ddisasm

A fast and accurate disassembler
https://grammatech.github.io/ddisasm/
GNU Affero General Public License v3.0
645 stars 60 forks source link

document the usage of pkg-config --libs libselinux on Linux #67

Open gogo2464 opened 11 months ago

gogo2464 commented 11 months ago

I used to take so much time to find the good linker to my reversed application when suddenly I found the command pkg-config --libs "libselinux" that in accordance with ldd "$(which ls)" could find the right library linkage from the ldd command.

example:

$ ldd "$(which ls)"
    linux-vdso.so.1 (0x00007ffd1258c000)
    libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f51a542c000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f51a5258000)
    libpcre2-8.so.0 => /lib/x86_64-linux-gnu/libpcre2-8.so.0 (0x00007f51a51c0000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f51a51ba000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f51a54ae000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f51a5198000)
$ pkg-config --libs "libselinux"
-lselinux

$ apt-cache search selinux
selinux-utils
libselinux1-dev
...

sudo apt install --yes selinux-utils libselinux1-dev

$ gcc -nostartfiles ls.s  -o ls-out -l selinux

I suggest to add this trick to the doc.

Assign me to this issue please :)

Best regards.

aeflores commented 11 months ago

We typically recommend using gtirb-pprinter --binary to reassemble (it will create the compilation command with the necessary library dependencies). Have you had problems with that approach?

gtirb-pprinter ls.gtirb --binary ls-out

Also, if you already have the libraries from ldd, you can link them directly, right?

gcc -nostartfiles ls.s  -o ls-out -l:libselinux.so.1
gogo2464 commented 11 months ago

I prefer to use a Makefile. Do you think people could enjoy this improvement? Seems more portable.