31 using namespace mageec;
41 if (sectionname == NULL)
43 if (!strcmp (sectionname,
".note.gnu.build-id"))
45 if (!strcmp (sectionname,
".gnu.hash"))
47 if (!strcmp (sectionname,
".gnu.version"))
49 if (!strcmp (sectionname,
".gnu.version_r"))
63 if (elf_version (EV_CURRENT) == EV_NONE)
66 int fd = open (filename, O_RDONLY, 0);
70 elf = elf_begin (fd, ELF_C_READ, NULL);
74 kind = elf_kind (elf);
75 if (kind != ELF_K_ELF)
78 if (elf_getshdrstrndx (elf, &sheaderindex) != 0)
81 section = elf_nextscn (elf, NULL);
83 while (section != NULL)
87 if (gelf_getshdr(section, &sechdr) != &sechdr)
90 name = elf_strptr (elf, sheaderindex, sechdr.sh_name);
97 data =
static_cast<unsigned char *
>(realloc (data, datasize +
101 memcpy((data+datasize), name, strlen(name));
102 datasize += strlen(name);
105 data =
static_cast<unsigned char *
>(realloc (data, datasize +
106 sizeof(sechdr.sh_size) +
107 sizeof(sechdr.sh_addr)));
110 memcpy((data+datasize), &sechdr.sh_size,
sizeof(sechdr.sh_size));
111 memcpy((data+datasize+
sizeof(sechdr.sh_size)), &sechdr.sh_addr,
112 sizeof(sechdr.sh_addr));
113 datasize +=
sizeof(sechdr.sh_size) +
sizeof(sechdr.sh_addr);
116 elfdata = elf_rawdata (section, NULL);
119 if (elfdata->d_size > 0 && elfdata->d_buf != NULL) {
120 data =
static_cast<unsigned char *
>(realloc (data, datasize +
124 memcpy((data+datasize), elfdata->d_buf, elfdata->d_size);
125 datasize += elfdata->d_size;
129 section = elf_nextscn (elf, section);