PKG_CHECK_MODULES(UUID_DEPS REQUIRED uuid)
PKG_CHECK_MODULES(VCONF_DEPS REQUIRED vconf)
PKG_CHECK_MODULES(XDGMIME_DEPS REQUIRED xdgmime)
-PKG_CHECK_MODULES(LIBELF_DEPS REQUIRED libelf)
## Target sources
AUX_SOURCE_DIRECTORY(src SRCS)
#include <elf.h>
#include <errno.h>
#include <fcntl.h>
-#include <gelf.h>
-#include <libelf.h>
#include <linux/limits.h>
#include <string.h>
#include <sys/stat.h>
}
bool ExecChecker::CheckMainSymbol() {
- int fd = open(path_.c_str(), O_RDONLY);
- if (fd < 0) {
- LOGE_STD("Failed to open file(%s). errno(%d)", path_.c_str(), errno);
- return false;
- }
-
- elf_version(EV_CURRENT);
-
- auto elf_destructor = [fd] (Elf* elf) -> void {
- close(fd);
- elf_end(elf);
- };
- auto elf = std::unique_ptr<Elf, decltype(elf_destructor)>
- (elf_begin(fd, ELF_C_READ, nullptr), elf_destructor);
- if (elf == nullptr) {
- LOGE_STD("Out of memory");
- return false;
- }
-
- Elf_Scn* scn = nullptr;
- GElf_Shdr shdr;
- while ((scn = elf_nextscn(elf.get(), scn)) != nullptr) {
- gelf_getshdr(scn, &shdr);
- if (shdr.sh_type == SHT_SYMTAB)
- break;
- }
-
- Elf_Data* data = elf_getdata(scn, nullptr);
- int count = (shdr.sh_entsize == 0 ? 0 : shdr.sh_size / shdr.sh_entsize);
-
- for (int i = 0; i < count; ++i) {
- GElf_Sym sym;
- gelf_getsym(data, i, &sym);
- char* symbol = elf_strptr(elf.get(), shdr.sh_link, sym.st_name);
- if (symbol != nullptr && strcmp("main", symbol) == 0)
- return true;
- }
-
- LOGW_STD("Not found main symbol(%s)", path_.c_str());
+ // TODO: Implement finding main symbol using Elf64_Sym & Elf32_Sym
return false;
}