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