summaryrefslogtreecommitdiff
path: root/src/analysis/binaries/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/analysis/binaries/file.c')
-rw-r--r--src/analysis/binaries/file.c43
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));