Here are the required steps using Igor Skochinsky's answer:
- Clone musl git repository:
git clone --depth=1 git://git.musl-libc.org/musl
cd musl; ./configure; make -s -j2
- Extract Flair tool from IDA SDK. Run
pelf
(ELF parser) with the musl static
library which is compiled in above step:
cd ./lib
~/flair/bin/linux/pelf libc.a
The output will be something like below:
Fatal [/mnt/c/MyFiles/libc.a] (__init_tls.lo): Unknown relocation type 42 (offset in section=0x3a).
- To fix the unsupported relocation error, run
pelf
with -r
option:
./flair/bin/linux/pelf -r42:58:0 libc.a musl.pat
The -r
option is specified as -rN:O:L
where N is relocation type, mark as
variable L bytes at offset O from the relocation address. This creates a PAT file.
- Now run
sigmake
to create the Flair signature file:
./flair/bin/linux/sigmake -n musl musl.pat musl.sig
If the output does not show any warning then the SIG file is OK. But if there
any collisions with the function signature the output will be something like below:
libc.sig: modules/leaves: 1550/1775, COLLISIONS: 41
To mitigate the error, remove comments from musl.exc
collision file. Then run
the above sigmake
command again. There will be a musl.sig
file which can be
imported in IDA Pro from File > Load File > FLIRT signature file.
FLIRT signature depends on the C/C++ compiler. For my case it is clang. I found
it in the exception handling function. There will be a static string like CLNGC++\0
.
The string can not be found in IDA's String Window. So, one has to find the
exception handling function first. The trick is that the function is called whenever
a error value returns.