Из оставленного комментария для другого ответа :
Полосатый ELF будет лишен записи .symtab
. Команда file
проходит через все заголовки раздела ELF, пока не будет найден раздел таблицы символов. Если один не может быть найден, двоичный файл считается раздетым.
Библиотека libelf позволяет программе манипулировать объектными файлами ELF, архивными файлами и членами архива. Справочные страницы elf (3E) содержат документацию по использованию библиотеки. В следующем коде приведен пример определения того, удаляется ли исполняемый файл путем поиска существования раздела таблицы символов (.symtab
).
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
/* Include for ELF processing */
#include <libelf.h>
#include <gelf.h>
int main(int argc, char ** argv)
{
int fd;
const char *file = argv[0];
Elf *elf; /* ELF pointer for libelf */
Elf_Scn *scn; /* section descriptor pointer */
GElf_Shdr shdr; /* section header */
/* Open ELF file to obtain file descriptor */
if((fd = open(file, O_RDONLY)) < 0)
{
fprintf(stderr, "Error opening file %s\n", file);
exit(EXIT_FAILURE);
}
/* Protect program from using an older library */
if(elf_version(EV_CURRENT) == EV_NONE)
{
fprintf(stderr, "WARNING - ELF Library is out of date!\n");
exit(EXIT_FAILURE);
}
/* Initialize elf pointer for examining contents of file */
elf = elf_begin(fd, ELF_C_READ, NULL);
/* Initialize section descriptor pointer so that elf_nextscn()
* returns a pointer to the section descriptor at index 1. */
scn = NULL;
/* Iterate through ELF sections */
while((scn = elf_nextscn(elf, scn)) != NULL)
{
/* Retrieve section header */
gelf_getshdr(scn, &shdr);
/* If a section header holding a symbol table (.symtab)
* is found, this ELF file has not been stripped. */
if(shdr.sh_type == SHT_SYMTAB)
{
printf("NOT STRIPPED\n");
break;
}
}
elf_end(elf);
close(fd);
exit(EXIT_SUCCESS);
}