- char *elf;
- Elf64_Shdr *shdr, *dynsect, *dynstrtab = 0;
-
- elf = (char *)content;
- for (i = 0; i < hdr->e_shnum; i++) {
- shdr = (Elf64_Shdr *)(elf + hdr->e_shoff + i * hdr->e_shentsize);
- if (shdr->sh_type == SHT_DYNAMIC) {
- dynsect = shdr;
- } else if (shdr->sh_type == SHT_STRTAB && i == hdr->e_shstrndx) {
- dynstrtab = shdr;
- }
- }
- if (!dynstrtab) {
- exit(8);
- }
- if (!dynsect) {
- exit(9);
- }
-
- char *name;
- Elf64_Shdr *dyntab;
- name = elf + dynstrtab->sh_offset;
- for (i = 0; i < hdr->e_shnum; i++) {
- shdr = (Elf64_Shdr *)(elf + hdr->e_shoff + i * hdr->e_shentsize);
- if (shdr->sh_type == SHT_STRTAB && !strcmp(".dynstr", name+shdr->sh_name)) {
- dyntab = shdr;
- }
- }
- if (!dyntab) {
- exit(10);
- }
-
- char *dynname;
- Elf64_Dyn *dent;
- dynname = elf + dyntab->sh_offset;
-
- for (dent = (Elf64_Dyn *)(elf + dynsect->sh_offset); dent->d_tag != DT_NULL; dent++) {
- if (dent->d_tag == DT_SONAME) {
- char *soname = dynname + dent->d_un.d_val;
- sqlite3_prepare_v2(db, "insert into elflibraries (file,soname) values (?,?)",-1, &ifile, 0);
- sqlite3_bind_text(ifile,1,hash,64,SQLITE_STATIC);
- sqlite3_bind_text(ifile,2,soname,-1,SQLITE_STATIC);
- rc = sqlite3_step(ifile);
- if (rc != SQLITE_DONE) {
- SQLERROR(sqlite3_errmsg(db));
- sqlite3_finalize(ifile);
- fprintf(stderr, "error setting library soname\n");
- return 0;
- }
+ char *soname = libelf_soname(content);
+ if (soname) {
+
+ sqlite3_prepare_v2(db, "insert into elflibraries (file,soname) values (?,?)",-1, &ifile, 0);
+ sqlite3_bind_text(ifile,1,hash,64,SQLITE_STATIC);
+ sqlite3_bind_text(ifile,2,soname,-1,SQLITE_STATIC);
+ rc = sqlite3_step(ifile);
+ if (rc != SQLITE_DONE) {
+ SQLERROR(sqlite3_errmsg(db));