diff options
Diffstat (limited to 'src/analysis')
-rw-r--r-- | src/analysis/binaries/file.c | 59 |
1 files changed, 19 insertions, 40 deletions
diff --git a/src/analysis/binaries/file.c b/src/analysis/binaries/file.c index a724cb7..d49ecb4 100644 --- a/src/analysis/binaries/file.c +++ b/src/analysis/binaries/file.c @@ -24,16 +24,14 @@ #include "file.h" -#include <fcntl.h> #include <string.h> -#include <unistd.h> -#include <sys/mman.h> -#include <sys/stat.h> #include "../binary-int.h" #include "../../common/extstr.h" +#include "../../core/formats.h" #include "../../core/processors.h" +#include "../../glibext/gbincontent.h" #include "../../gui/panels/log.h" @@ -161,11 +159,8 @@ 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 */ - const char *target; /* Architecture requise */ + GBinContent *content; /* Contenu binaire chargé */ + const char *target; /* Sous-traitance requise */ const char *desc; /* Description humaine associée*/ result = g_object_new(G_TYPE_FILE_BINARY, NULL); @@ -175,47 +170,31 @@ GLoadedBinary *g_file_binary_new_from_file(const char *filename) result->filename = strdup(filename); - /* Récupération des données */ + content = g_binary_content_new_from_file(filename); + if (content == NULL) goto lbf_error; - fd = open(filename, O_RDONLY); - if (fd == -1) - { - perror("open"); - goto lbf_error; - } + ///// + loaded->bin_data = g_binary_content_get(content, &loaded->bin_length); + /////// - 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) + target = find_matching_format(content); + desc = get_binary_format_name(target); + + if (desc == NULL) { - close(fd); - perror("mmap"); + g_object_unref(G_OBJECT(content)); + log_simple_message(LMT_INFO, _("Unknown binary format")); goto lbf_error; } + else + log_variadic_message(LMT_INFO, _("Detected format: %s"), desc); - 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)); + loaded->format = G_EXE_FORMAT(load_new_named_format(target, content)); if (loaded->format == NULL) { - log_simple_message(LMT_INFO, _("Unknown binary format")); + log_simple_message(LMT_ERROR, _("Error while loading the binary")); goto lbf_error; } |