diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2013-06-13 22:46:38 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2013-06-13 22:46:38 (GMT) |
commit | 0f3bbcb376ee4f76142ac4ddf729403fecac2641 (patch) | |
tree | 1015b219c8125afe0689384d04f6e37130bd2fba /src/analysis/binaries | |
parent | aed45245289e3e16d421aa6154dcb803e86addaa (diff) |
Fixed Elf format support.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@353 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/analysis/binaries')
-rw-r--r-- | src/analysis/binaries/file.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/analysis/binaries/file.c b/src/analysis/binaries/file.c index 9c43ed5..688b65a 100644 --- a/src/analysis/binaries/file.c +++ b/src/analysis/binaries/file.c @@ -24,7 +24,11 @@ #include "file.h" +#include <fcntl.h> #include <string.h> +#include <unistd.h> +#include <sys/mman.h> +#include <sys/stat.h> #include "../binary-int.h" @@ -156,6 +160,10 @@ GLoadedBinary *g_file_binary_new_from_file(const char *filename) { GFileBinary *result; /* Adresse à retourner */ GLoadedBinary *loaded; /* Version parente */ + int fd; /* Descripteur du fichier */ + struct stat info; /* Informations sur le fichier */ + int ret; /* Bilan d'un appel */ + void *content; /* Contenu brut du fichier */ result = g_object_new(G_TYPE_FILE_BINARY, NULL); loaded = G_LOADED_BINARY(result); @@ -164,6 +172,41 @@ GLoadedBinary *g_file_binary_new_from_file(const char *filename) result->filename = strdup(filename); + /* Récupération des données */ + + fd = open(filename, O_RDONLY); + if (fd == -1) + { + perror("open"); + goto lbf_error; + } + + ret = fstat(fd, &info); + if (ret == -1) + { + close(fd); + perror("fstat"); + goto lbf_error; + } + + content = mmap(NULL, info.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + if (content == MAP_FAILED) + { + close(fd); + perror("mmap"); + goto lbf_error; + } + + loaded->bin_length = info.st_size; + loaded->bin_data = (bin_t *)malloc(info.st_size); + + memcpy(loaded->bin_data, content, info.st_size); + + munmap(content, info.st_size); + close(fd); + + /* Chargement du binaire */ + loaded->format = G_EXE_FORMAT(load_new_format(FMT_EXEC, filename, &loaded->bin_data, &loaded->bin_length)); |