summaryrefslogtreecommitdiff
path: root/src/model/insert.c
diff options
context:
space:
mode:
authornorly <ny-git@enpas.org>2013-05-26 12:52:47 +0100
committernorly <ny-git@enpas.org>2013-05-26 12:52:47 +0100
commit5d00dc2e4345796d79424a1ac19e0902009ade36 (patch)
tree1a700a36cc4fa4b46eda6df915c3a54fc2f9a9ba /src/model/insert.c
parent3d899fbfd33a8b44dcbd7dfbc952464731a7e589 (diff)
Inserting section names, first partshotgunparser
Diffstat (limited to 'src/model/insert.c')
-rw-r--r--src/model/insert.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/model/insert.c b/src/model/insert.c
index b18aa8a..1515706 100644
--- a/src/model/insert.c
+++ b/src/model/insert.c
@@ -287,3 +287,52 @@ void elfu_mInsertScnInChainAfter(ElfuElf *me, ElfuScn *oldscn, ElfuScn *newscn)
CIRCLEQ_INSERT_AFTER(&me->scnList, oldscn, newscn, elem);
}
+
+
+
+
+
+/* Insert a name into the section string table (.shstrtab) */
+Elf32_Word elfu_mInsertScnName(ElfuElf *me, char *prefix, char *name)
+{
+ void *newstrlen;
+ char *newstr;
+ void *newbuf;
+
+ assert(me);
+
+ if (!name || !me->shstrtab) {
+ return 0;
+ }
+
+ assert(shstrtab->data.d_buf);
+
+ newstrlen = strlen(name) + 1;
+ if (prefix) {
+ newstrlen += strlen(prefix);
+ }
+
+ newbuf = realloc(me->shstrtab->data.d_buf, me->shstrtab->shdr.sh_size + newstrlen);
+ if (!newbuf) {
+ ELFU_WARN("mInsertScnName: malloc failed for newbuf.\n");
+ free(newstr);
+ return 0;
+ }
+
+ me->shstrtab->data.d_buf = newbuf;
+
+ newstr = &newbuf[me->shstrtab->shdr.sh_size];
+ if (prefix) {
+ strcpy(newstr, prefix);
+ newstr += strlen(prefix);
+ }
+ strcpy(newstr, name);
+
+ me->shstrtab->shdr.sh_size += newstrlen;
+
+ /* Delete section and reinsert it at the end to allow for the larger size */
+ CIRCLEQ_REMOVE(me->scnList, me->shstrtab, elem);
+ CIRCLEQ_INSERT_TAIL(me->scnList, me->shstrtab, elem);
+
+ // TODO: Move this section to the end and move following SHDR/PHDR tables
+}