summaryrefslogtreecommitdiff
path: root/src/analysis
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2015-02-11 17:05:54 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2015-02-11 17:05:54 (GMT)
commitbf879f2562545ab7de23f9d38364b7bd4b43fb2c (patch)
tree6154160307cbca304ea9e1de178d8c2dfc8e0928 /src/analysis
parentabd96dbbe27246e9303173e5e2f47b2e4cedbcb7 (diff)
Registered all the supported formats in the system code.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@471 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/analysis')
-rw-r--r--src/analysis/binaries/file.c59
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;
}