summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2013-06-13 22:46:38 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2013-06-13 22:46:38 (GMT)
commit0f3bbcb376ee4f76142ac4ddf729403fecac2641 (patch)
tree1015b219c8125afe0689384d04f6e37130bd2fba /src
parentaed45245289e3e16d421aa6154dcb803e86addaa (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')
-rw-r--r--src/analysis/binaries/file.c43
-rw-r--r--src/analysis/binary.c3
-rw-r--r--src/format/format.c2
3 files changed, 46 insertions, 2 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));
diff --git a/src/analysis/binary.c b/src/analysis/binary.c
index e3b3e9d..05c4e99 100644
--- a/src/analysis/binary.c
+++ b/src/analysis/binary.c
@@ -151,6 +151,9 @@ static void g_loaded_binary_dispose(GLoadedBinary *binary)
if (binary->proc != NULL)
g_object_unref(G_OBJECT(binary->proc));
+ if (binary->bin_data != NULL)
+ free(binary->bin_data);
+
/* TODO... */
G_OBJECT_CLASS(g_loaded_binary_parent_class)->dispose(G_OBJECT(binary));
diff --git a/src/format/format.c b/src/format/format.c
index 846d038..d30eb66 100644
--- a/src/format/format.c
+++ b/src/format/format.c
@@ -531,9 +531,7 @@ GBinFormat *load_new_format(FormatType type, const char *filename, bin_t **conte
if (_formats[i].type == type && _formats[i].match(type, *content, *length))
{
log_variadic_message(LMT_INFO, _("%s is matching..."), _formats[i].name);
-
result = _formats[i].load(*content, *length);
-
}
return result;