diff options
Diffstat (limited to 'src/libelfu/model/section.c')
-rw-r--r-- | src/libelfu/model/section.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/libelfu/model/section.c b/src/libelfu/model/section.c index 9ef6fd8..74fbc3a 100644 --- a/src/libelfu/model/section.c +++ b/src/libelfu/model/section.c @@ -198,6 +198,30 @@ ElfuScn** elfu_mScnSortedByOffset(ElfuElf *me, size_t *count) +int elfu_mScnAppendData(ElfuScn *ms, void *buf, size_t len) +{ + char *newbuf; + + assert(ms); + assert(ms->shdr.sh_type != SHT_NOBITS); + assert(ms->databuf); + + newbuf = realloc(ms->databuf, ms->shdr.sh_size + len); + if (!newbuf) { + ELFU_WARN("elfu_mScnAppendData: malloc() failed for newbuf.\n"); + return -1; + } + + ms->databuf = newbuf; + memcpy(newbuf + ms->shdr.sh_size, buf, len); + ms->shdr.sh_size += len; + assert(ms->shdr.sh_size == ms->shdr.sh_size); + + return 0; +} + + + /* * Allocation, destruction */ |