summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornorly <ny-git@enpas.org>2013-02-23 16:08:26 +0000
committernorly <ny-git@enpas.org>2013-02-23 16:09:15 +0000
commit9b3f4d15112365dbda20c668d0d57a74bd05e60c (patch)
tree39de5a71062270f6d181b74b32dd8beb1da434ec
parent6e4cbafe0876ff14ff03a14ab80951167ef67e06 (diff)
Refactor mdoel-related code
-rw-r--r--include/libelfu/libelfu.h3
-rw-r--r--include/libelfu/modelops.h20
-rw-r--r--include/libelfu/modeltypes.h (renamed from include/libelfu/model.h)19
-rw-r--r--src/main.c6
-rw-r--r--src/model/check.c12
-rw-r--r--src/model/count.c4
-rw-r--r--src/model/fromFile.c12
-rw-r--r--src/model/section-name.c4
-rw-r--r--src/model/toFile.c12
9 files changed, 46 insertions, 46 deletions
diff --git a/include/libelfu/libelfu.h b/include/libelfu/libelfu.h
index 3c62aad..1fc613a 100644
--- a/include/libelfu/libelfu.h
+++ b/include/libelfu/libelfu.h
@@ -6,7 +6,8 @@
#include <libelfu/generic.h>
#include <libelfu/elfops.h>
-#include <libelfu/model.h>
+#include <libelfu/modeltypes.h>
+#include <libelfu/modelops.h>
#endif
diff --git a/include/libelfu/modelops.h b/include/libelfu/modelops.h
new file mode 100644
index 0000000..9475eba
--- /dev/null
+++ b/include/libelfu/modelops.h
@@ -0,0 +1,20 @@
+#ifndef __LIBELFU_MODELOPS_H__
+#define __LIBELFU_MODELOPS_H__
+
+#include <elf.h>
+#include <gelf.h>
+
+#include <libelfu/modeltypes.h>
+
+
+size_t elfu_mCountScns(ElfuElf *me);
+size_t elfu_mCountPhdrs(ElfuElf *me);
+
+char* elfu_mScnName(ElfuElf *me, ElfuScn *ms);
+
+int elfu_mCheck(ElfuElf *me);
+
+ElfuElf* elfu_mFromElf(Elf *e);
+ void elfu_mToElf(ElfuElf *me, Elf *e);
+
+#endif
diff --git a/include/libelfu/model.h b/include/libelfu/modeltypes.h
index 588d57a..18f6671 100644
--- a/include/libelfu/model.h
+++ b/include/libelfu/modeltypes.h
@@ -1,12 +1,11 @@
-#ifndef __LIBELFU_MODEL_H__
-#define __LIBELFU_MODEL_H__
+#ifndef __LIBELFU_MODELTYPES_H__
+#define __LIBELFU_MODELTYPES_H__
#include <sys/queue.h>
#include <elf.h>
#include <gelf.h>
-
typedef struct ElfuData {
Elf_Data data;
@@ -41,18 +40,4 @@ typedef struct {
} ElfuElf;
-
-size_t elfu_countSections(ElfuElf *me);
-size_t elfu_countPHDRs(ElfuElf *me);
-
-char* elfu_modelScnName(ElfuElf *me, ElfuScn *ms);
-
-int elfu_modelCheck(ElfuElf *me);
-
-ElfuPhdr* elfu_modelFromPhdr(GElf_Phdr *phdr);
-ElfuScn* elfu_modelFromSection(Elf_Scn *scn);
-ElfuElf* elfu_modelFromElf(Elf *e);
-
-void elfu_modelToElf(ElfuElf *me, Elf *e);
-
#endif
diff --git a/src/main.c b/src/main.c
index eaf2709..991fe09 100644
--- a/src/main.c
+++ b/src/main.c
@@ -63,15 +63,15 @@ int main(int argc, char **argv)
if (opts.fnOutput) {
ElfuElf *me;
- me = elfu_modelFromElf(hIn.e);
+ me = elfu_mFromElf(hIn.e);
if (me) {
printf("Model successfully loaded.\n");
- elfu_modelCheck(me);
+ elfu_mCheck(me);
printf("Model checked.\n");
- elfu_modelToElf(me, hOut.e);
+ elfu_mToElf(me, hOut.e);
printf("Model converted to ELF, ready to be written.\n");
} else {
diff --git a/src/model/check.c b/src/model/check.c
index dd5e8eb..c490d5d 100644
--- a/src/model/check.c
+++ b/src/model/check.c
@@ -43,7 +43,7 @@ static int cmpScnOffs(const void *ms1, const void *ms2)
}
-int elfu_modelCheck(ElfuElf *me)
+int elfu_mCheck(ElfuElf *me)
{
ElfuScn *ms;
size_t numSecs;
@@ -51,7 +51,7 @@ int elfu_modelCheck(ElfuElf *me)
size_t i;
/* Sort sections by offset in file */
- numSecs = elfu_countSections(me);
+ numSecs = elfu_mCountScns(me);
sortedSecs = malloc(numSecs * sizeof(*sortedSecs));
if (!sortedSecs) {
fprintf(stderr, "elfu_check: Failed to allocate memory.\n");
@@ -72,8 +72,8 @@ int elfu_modelCheck(ElfuElf *me)
if (sortedSecs[i]->shdr.sh_offset + elfu_gScnSizeFile(&sortedSecs[i]->shdr)
> sortedSecs[i+1]->shdr.sh_offset) {
fprintf(stderr, "elfu_check: Found overlapping sections: %s and %s.\n",
- elfu_modelScnName(me, sortedSecs[i]),
- elfu_modelScnName(me, sortedSecs[i+1]));
+ elfu_mScnName(me, sortedSecs[i]),
+ elfu_mScnName(me, sortedSecs[i+1]));
}
}
@@ -82,7 +82,7 @@ int elfu_modelCheck(ElfuElf *me)
for (i = 0; i < numSecs; i++) {
if (sortedSecs[i]->shdr.sh_offset < me->ehdr.e_ehsize) {
fprintf(stderr, "elfu_check: Found section overlapping with EHDR: %s.\n",
- elfu_modelScnName(me, sortedSecs[i]));
+ elfu_mScnName(me, sortedSecs[i]));
}
}
@@ -94,7 +94,7 @@ int elfu_modelCheck(ElfuElf *me)
me->ehdr.e_phoff,
me->ehdr.e_phentsize * me->ehdr.e_phnum)) {
fprintf(stderr, "elfu_check: Found section overlapping with PHDRs: %s.\n",
- elfu_modelScnName(me, sortedSecs[i]));
+ elfu_mScnName(me, sortedSecs[i]));
}
}
diff --git a/src/model/count.c b/src/model/count.c
index 274b9d8..b7c8013 100644
--- a/src/model/count.c
+++ b/src/model/count.c
@@ -5,7 +5,7 @@
/* NULL section is not counted! */
-size_t elfu_countSections(ElfuElf *me)
+size_t elfu_mCountScns(ElfuElf *me)
{
ElfuScn *ms;
size_t i = 0;
@@ -20,7 +20,7 @@ size_t elfu_countSections(ElfuElf *me)
}
-size_t elfu_countPHDRs(ElfuElf *me)
+size_t elfu_mCountPhdrs(ElfuElf *me)
{
ElfuPhdr *mp;
size_t i = 0;
diff --git a/src/model/fromFile.c b/src/model/fromFile.c
index 26ce6a7..dedbfa0 100644
--- a/src/model/fromFile.c
+++ b/src/model/fromFile.c
@@ -1,14 +1,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
-
#include <libelf.h>
#include <gelf.h>
-
#include <libelfu/libelfu.h>
-ElfuPhdr* elfu_modelFromPhdr(GElf_Phdr *phdr)
+static ElfuPhdr* modelFromPhdr(GElf_Phdr *phdr)
{
ElfuPhdr *mp;
@@ -23,7 +21,7 @@ ElfuPhdr* elfu_modelFromPhdr(GElf_Phdr *phdr)
}
-ElfuScn* elfu_modelFromSection(Elf_Scn *scn)
+static ElfuScn* modelFromSection(Elf_Scn *scn)
{
ElfuScn *ms;
Elf_Data *data;
@@ -70,7 +68,7 @@ ElfuScn* elfu_modelFromSection(Elf_Scn *scn)
-ElfuElf* elfu_modelFromElf(Elf *e)
+ElfuElf* elfu_mFromElf(Elf *e)
{
ElfuElf *me;
Elf_Scn *scn;
@@ -110,7 +108,7 @@ ElfuElf* elfu_modelFromElf(Elf *e)
scn = elf_getscn(e, 1);
i = 1;
while (scn) {
- ElfuScn *ms = elfu_modelFromSection(scn);
+ ElfuScn *ms = modelFromSection(scn);
if (ms) {
CIRCLEQ_INSERT_TAIL(&me->scnList, ms, elem);
@@ -143,7 +141,7 @@ ElfuElf* elfu_modelFromElf(Elf *e)
break;
}
- mp = elfu_modelFromPhdr(&phdr);
+ mp = modelFromPhdr(&phdr);
if (mp) {
CIRCLEQ_INSERT_TAIL(&me->phdrList, mp, elem);
diff --git a/src/model/section-name.c b/src/model/section-name.c
index 0e5d903..2ecd5f0 100644
--- a/src/model/section-name.c
+++ b/src/model/section-name.c
@@ -1,14 +1,12 @@
#include <assert.h>
#include <stdlib.h>
-
#include <libelf.h>
#include <gelf.h>
-
#include <libelfu/libelfu.h>
-char* elfu_modelScnName(ElfuElf *me, ElfuScn *ms)
+char* elfu_mScnName(ElfuElf *me, ElfuScn *ms)
{
assert(me);
assert(ms);
diff --git a/src/model/toFile.c b/src/model/toFile.c
index 399c25b..0bfbd00 100644
--- a/src/model/toFile.c
+++ b/src/model/toFile.c
@@ -1,14 +1,12 @@
#include <stdio.h>
#include <stdlib.h>
-
#include <libelf.h>
#include <gelf.h>
-
#include <libelfu/libelfu.h>
-static void elfu_modelToPhdrs(ElfuElf *me, Elf *e)
+static void modelToPhdrs(ElfuElf *me, Elf *e)
{
ElfuPhdr *mp;
size_t i;
@@ -36,7 +34,7 @@ static void elfu_modelToPhdrs(ElfuElf *me, Elf *e)
-static void elfu_modelToSection(ElfuScn *ms, Elf *e)
+static void modelToSection(ElfuScn *ms, Elf *e)
{
Elf_Scn *scnOut;
@@ -74,7 +72,7 @@ static void elfu_modelToSection(ElfuScn *ms, Elf *e)
-void elfu_modelToElf(ElfuElf *me, Elf *e)
+void elfu_mToElf(ElfuElf *me, Elf *e)
{
ElfuScn *ms;
@@ -95,12 +93,12 @@ void elfu_modelToElf(ElfuElf *me, Elf *e)
/* Sections */
CIRCLEQ_FOREACH(ms, &me->scnList, elem) {
- elfu_modelToSection(ms, e);
+ modelToSection(ms, e);
}
/* PHDRs */
- elfu_modelToPhdrs(me, e);
+ modelToPhdrs(me, e);
elf_flagelf(e, ELF_C_SET, ELF_F_DIRTY);