summaryrefslogtreecommitdiff
path: root/src/format
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/format
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/format')
-rwxr-xr-xsrc/format/dex/dex.c17
-rwxr-xr-xsrc/format/dex/dex.h2
-rw-r--r--src/format/dwarf/dwarf.c2
-rw-r--r--src/format/dwarf/dwarf.h2
-rw-r--r--src/format/elf/elf.c23
-rw-r--r--src/format/elf/elf.h4
-rw-r--r--src/format/format-int.h2
-rw-r--r--src/format/format.c154
-rw-r--r--src/format/format.h44
-rwxr-xr-xsrc/format/java/java.c17
-rwxr-xr-xsrc/format/java/java.h2
-rw-r--r--src/format/pe/pe.c12
-rw-r--r--src/format/pe/pe.h2
13 files changed, 48 insertions, 235 deletions
diff --git a/src/format/dex/dex.c b/src/format/dex/dex.c
index c5271e0..476e6f5 100755
--- a/src/format/dex/dex.c
+++ b/src/format/dex/dex.c
@@ -67,9 +67,7 @@ static bool g_dex_format_translate_offset_into_address(const GDexFormat *, off_t
/******************************************************************************
* *
-* Paramètres : type = type de format recherché. *
-* content = contenu binaire à parcourir. *
-* length = taille du contenu en question. *
+* Paramètres : content = contenu binaire à parcourir. *
* *
* Description : Indique si le format peut être pris en charge ici. *
* *
@@ -79,14 +77,17 @@ static bool g_dex_format_translate_offset_into_address(const GDexFormat *, off_t
* *
******************************************************************************/
-bool dex_is_matching(FormatType type, const uint8_t *content, off_t length)
+bool dex_is_matching(GBinContent *content)
{
bool result; /* Bilan à faire connaître */
+ vmpa2t addr; /* Tête de lecture initiale */
+ char magic[DEX_FILE_MAGIC_LEN]; /* Idenfiant standard */
- result = false;
+ init_vmpa(&addr, 0, VMPA_NO_VIRTUAL);
+
+ result = g_binary_content_get_raw(content, &addr, DEX_FILE_MAGIC_LEN, (bin_t *)magic);
- if (length >= DEX_FILE_MAGIC_LEN)
- result = (memcmp(content, DEX_FILE_MAGIC, DEX_FILE_MAGIC_LEN) == 0);
+ result &= (memcmp(magic, DEX_FILE_MAGIC, DEX_FILE_MAGIC_LEN) == 0);
return result;
@@ -166,7 +167,7 @@ GBinFormat *g_dex_format_new(const bin_t *content, off_t length)
result = g_object_new(G_TYPE_DEX_FORMAT, NULL);
- g_binary_format_set_content(G_BIN_FORMAT(result), content, length);
+ //g_binary_format_set_content(G_BIN_FORMAT(result), content, length);
offset = 0;
diff --git a/src/format/dex/dex.h b/src/format/dex/dex.h
index 18f0980..aca6cef 100755
--- a/src/format/dex/dex.h
+++ b/src/format/dex/dex.h
@@ -49,7 +49,7 @@ typedef struct _GDexFormatClass GDexFormatClass;
/* Indique si le format peut être pris en charge ici. */
-bool dex_is_matching(FormatType, const bin_t *, off_t);
+bool dex_is_matching(GBinContent *);
/* Indique le type défini pour un format d'exécutable DEX. */
GType g_dex_format_get_type(void);
diff --git a/src/format/dwarf/dwarf.c b/src/format/dwarf/dwarf.c
index 0292d60..c7b1c23 100644
--- a/src/format/dwarf/dwarf.c
+++ b/src/format/dwarf/dwarf.c
@@ -50,7 +50,7 @@
* *
******************************************************************************/
-bool dwarf_is_matching(FormatType type, const uint8_t *content, off_t length)
+bool dwarf_is_matching(GBinContent *)
{
bool result; /* Bilan à faire connaître */
diff --git a/src/format/dwarf/dwarf.h b/src/format/dwarf/dwarf.h
index e6d573c..2e32c8e 100644
--- a/src/format/dwarf/dwarf.h
+++ b/src/format/dwarf/dwarf.h
@@ -30,7 +30,7 @@
/* Indique si le format peut être pris en charge ici. */
-bool dwarf_is_matching(FormatType, const uint8_t *, off_t);
+bool dwarf_is_matching(GBinContent *);
/* Prend en charge un nouveau format Dwarf. */
GBinFormat *g_dwarf_format_new(const bin_t *, off_t);
diff --git a/src/format/elf/elf.c b/src/format/elf/elf.c
index cc84335..f0c361e 100644
--- a/src/format/elf/elf.c
+++ b/src/format/elf/elf.c
@@ -72,9 +72,7 @@ static bool g_elf_format_translate_offset_into_address(const GElfFormat *, off_t
/******************************************************************************
* *
-* Paramètres : type = type de format recherché. *
-* content = contenu binaire à parcourir. *
-* length = taille du contenu en question. *
+* Paramètres : content = contenu binaire à parcourir. *
* *
* Description : Indique si le format peut être pris en charge ici. *
* *
@@ -84,14 +82,17 @@ static bool g_elf_format_translate_offset_into_address(const GElfFormat *, off_t
* *
******************************************************************************/
-bool elf_is_matching(FormatType type, const bin_t *content, off_t length)
+bool elf_is_matching(GBinContent *content)
{
bool result; /* Bilan à faire connaître */
+ vmpa2t addr; /* Tête de lecture initiale */
+ char magic[4]; /* Idenfiant standard */
+
+ init_vmpa(&addr, 0, VMPA_NO_VIRTUAL);
- result = false;
+ result = g_binary_content_get_raw(content, &addr, 4, (bin_t *)magic);
- if (length >= 4)
- result = (memcmp(content, "\x7f\x45\x4c\x46" /* .ELF */, 4) == 0);
+ result &= (memcmp(magic, "\x7f\x45\x4c\x46" /* .ELF */, 4) == 0);
return result;
@@ -150,7 +151,6 @@ static void g_elf_format_init(GElfFormat *format)
/******************************************************************************
* *
* Paramètres : content = contenu binaire à parcourir. *
-* length = taille du contenu en question. *
* *
* Description : Prend en charge un nouveau format ELF. *
* *
@@ -160,13 +160,13 @@ static void g_elf_format_init(GElfFormat *format)
* *
******************************************************************************/
-GBinFormat *g_elf_format_new(const bin_t *content, off_t length)
+GBinFormat *g_elf_format_new(GBinContent *content)
{
GElfFormat *result; /* Structure à retourner */
result = g_object_new(G_TYPE_ELF_FORMAT, NULL);
- g_binary_format_set_content(G_BIN_FORMAT(result), content, length);
+ g_binary_format_set_content(G_BIN_FORMAT(result), content);
if (!read_elf_header(result, &result->header, &result->is_32b, &result->endian))
{
@@ -196,6 +196,7 @@ GBinFormat *g_elf_format_new(const bin_t *content, off_t length)
}
/* FIXME : à améliorer */
+ /*
if ((ELF_HDR(result, result->header, e_shnum) * ELF_HDR(result, result->header, e_shentsize)) >= length)
{
log_variadic_message(LMT_BAD_BINARY, ("Suspicious section table (bigger than the binary !) ; reset ! -- replacing 0x%04hx by 0x%04hx at offset 0x%x"),
@@ -203,7 +204,7 @@ GBinFormat *g_elf_format_new(const bin_t *content, off_t length)
0, ELF_HDR_OFFSET_OF(result, e_shnum));
ELF_HDR_SET(result, result->header, e_shnum, 0);
}
-
+ */
diff --git a/src/format/elf/elf.h b/src/format/elf/elf.h
index 5ea90fd..f18670c 100644
--- a/src/format/elf/elf.h
+++ b/src/format/elf/elf.h
@@ -49,13 +49,13 @@ typedef struct _GElfFormatClass GElfFormatClass;
/* Indique si le format peut être pris en charge ici. */
-bool elf_is_matching(FormatType, const bin_t *, off_t);
+bool elf_is_matching(GBinContent *);
/* Indique le type défini pour un format d'exécutable ELF. */
GType g_elf_format_get_type(void);
/* Prend en charge un nouveau format ELF. */
-GBinFormat *g_elf_format_new(const bin_t *, off_t);
+GBinFormat *g_elf_format_new(GBinContent *);
diff --git a/src/format/format-int.h b/src/format/format-int.h
index 85244b6..22b0c0f 100644
--- a/src/format/format-int.h
+++ b/src/format/format-int.h
@@ -69,7 +69,7 @@ struct _GBinFormatClass
/* Définit le contenu binaire à analyser. */
-void g_binary_format_set_content(GBinFormat *, const bin_t *, off_t);
+void g_binary_format_set_content(GBinFormat *, GBinContent *) __attribute__ ((deprecated));
diff --git a/src/format/format.c b/src/format/format.c
index b44d8ed..c779947 100644
--- a/src/format/format.c
+++ b/src/format/format.c
@@ -40,16 +40,6 @@
-#ifndef _
-# define _(str) str
-#endif
-
-
-
-
-/* ------------------------ TRAITEMENT INDIVIDUEL DE FORMATS ------------------------ */
-
-
/* Initialise la classe des formats binaires génériques. */
static void g_binary_format_class_init(GBinFormatClass *);
@@ -58,43 +48,6 @@ static void g_binary_format_init(GBinFormat *);
-/* ----------------------- MANIPULATION D'ENSEMBLE DE FORMATS ----------------------- */
-
-
-/* Format d'exécutables enregistré */
-typedef struct _registered_format
-{
- const char *name; /* Désignation du format */
-
- FormatType type; /* Type de format */
-
- format_match_fc match; /* Procédure de reconnaissance */
- format_load_fc load; /* Fonction de chargement */
-
-} registered_format;
-
-
-/* Liste des formats d'exécutables enregistrés */
-static registered_format _formats[FID_COUNT];
-
-
-#define register_format(id, n, t, m, l) \
- do \
- { \
- _formats[id].name = n; \
- _formats[id].type = t; \
- _formats[id].match = m; \
- _formats[id].load = l; \
- } \
- while (0)
-
-
-
-/* ---------------------------------------------------------------------------------- */
-/* TRAITEMENT INDIVIDUEL DE FORMATS */
-/* ---------------------------------------------------------------------------------- */
-
-
/* Indique le type défini pour un format binaire générique. */
G_DEFINE_TYPE(GBinFormat, g_binary_format, G_TYPE_OBJECT);
@@ -149,10 +102,11 @@ static void g_binary_format_init(GBinFormat *format)
* *
******************************************************************************/
-void g_binary_format_set_content(GBinFormat *format, const bin_t *content, off_t length)
+void g_binary_format_set_content(GBinFormat *format, GBinContent *content)
{
- format->content = content;
- format->length = length;
+
+
+ format->content = g_binary_content_get(content, &format->length);
}
@@ -507,103 +461,3 @@ bool g_binary_format_resolve_relative_routine(const GBinFormat *format, const ch
return result;
}
-
-
-
-/* ---------------------------------------------------------------------------------- */
-/* MANIPULATION D'ENSEMBLE DE FORMATS */
-/* ---------------------------------------------------------------------------------- */
-
-
-/******************************************************************************
-* *
-* Paramètres : - *
-* *
-* Description : Procède au chargement des formats binaires reconnus. *
-* *
-* Retour : true pour indiquer un chargement réussi, false sinon. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bool init_all_formats(void)
-{
- register_format(FID_DEX, _("Dalvik Executable"), FMT_EXEC, dex_is_matching, g_dex_format_new);
- //register_format(FID_DWARF, _("Dwarf"), FMT_DEBUG, dwarf_is_matching, g_dwarf_format_new);
- register_format(FID_ELF, _("ELF"), FMT_EXEC, elf_is_matching, g_elf_format_new);
- register_format(FID_JAVA, _("Java"), FMT_EXEC, java_is_matching, g_java_format_new);
- register_format(FID_PE, _("PE"), FMT_EXEC, pe_is_matching, g_pe_format_new);
-
- return true;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : type = type de format recherché. *
-* filename = fichier d'origine des données initiales. *
-* content = contenu binaire à parcourir. [OUT] *
-* length = taille du contenu en question. [OUT] *
-* *
-* Description : Charge si possible un nouveau format binaire. *
-* *
-* Retour : Adresse du nouveau gestionnaire de format ou NULL si erreur. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-GBinFormat *load_new_format(FormatType type, const char *filename, bin_t **content, off_t *length)
-{
- GBinFormat *result; /* Adresse à retourner */
- char *tmp; /* Nom de fichier modifiable */
- GPluginModule **pglist; /* Liste de greffons */
- size_t pgcount; /* Taille de cette liste */
- size_t i; /* Boucle de parcours */
-
- result = NULL;
-
- tmp = strdup(filename);
-
- pgcount = 0;
- pglist = NULL;//get_all_plugins_for_action(PGA_FORMAT_MATCHER, &pgcount);
-
- if (pgcount > 0)
- {
- lnf_rescan:
-
- for (i = 0; i < pgcount; i++)
- switch (0/*g_plugin_module_is_matching(pglist[i], &tmp, content, length)*/)
- {
- case MFA_MATCHED:
- /* FIXME */
- break;
-
- case MFA_RELOAD:
- //goto lnf_rescan;
- break;
-
- default:
- break;
-
- }
-
- free(pglist);
-
- }
-
- if (tmp == NULL)
- free(tmp);
-
- for (i = 0; i < FID_COUNT && result == NULL; i++)
- 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;
-
-}
diff --git a/src/format/format.h b/src/format/format.h
index 0ac658b..b01a9d5 100644
--- a/src/format/format.h
+++ b/src/format/format.h
@@ -33,12 +33,10 @@
#include "symbol.h"
#include "../analysis/routine.h"
#include "../arch/context.h"
+#include "../glibext/gbincontent.h"
-/* ------------------------ TRAITEMENT INDIVIDUEL DE FORMATS ------------------------ */
-
-
#define G_TYPE_BIN_FORMAT g_binary_format_get_type()
#define G_BIN_FORMAT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_binary_format_get_type(), GBinFormat))
#define G_IS_BIN_FORMAT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_binary_format_get_type()))
@@ -91,44 +89,4 @@ bool g_binary_format_resolve_relative_routine(const GBinFormat *, const char **,
-/* ----------------------- MANIPULATION D'ENSEMBLE DE FORMATS ----------------------- */
-
-
-/* Identifiants pour les différents formats */
-typedef enum _FormatIdentifier
-{
- FID_DEX, /* Format DEX */
- //FID_DWARF, /* Format Dwarf */
- FID_ELF, /* Format ELF */
- FID_JAVA, /* Format Java */
- FID_PE, /* Format PE */
-
- FID_COUNT
-
-} FormatIdentifier;
-
-/* Spécialité des formats */
-typedef enum _FormatType
-{
- FMT_EXEC = (1 << 0), /* Format d'exécutable */
- FMT_DEBUG = (1 << 1) /* Format de débogage */
-
-} FormatType;
-
-
-/* Indication à propos du support d'un format */
-typedef bool (* format_match_fc) (FormatType, const bin_t *, off_t);
-
-/* Méthode de chargement d'un format */
-typedef GBinFormat * (* format_load_fc) (const bin_t *, off_t);
-
-
-/* Procède au chargement des formats binaires reconnus. */
-bool init_all_formats(void);
-
-/* Charge si possible un nouveau format binaire. */
-GBinFormat *load_new_format(FormatType, const char *filename, bin_t **, off_t *);
-
-
-
#endif /* _FORMAT_FORMAT_H */
diff --git a/src/format/java/java.c b/src/format/java/java.c
index e477b82..4929b52 100755
--- a/src/format/java/java.c
+++ b/src/format/java/java.c
@@ -58,9 +58,7 @@ static bool g_java_format_translate_offset_into_address(const GJavaFormat *, off
/******************************************************************************
* *
-* Paramètres : type = type de format recherché. *
-* content = contenu binaire à parcourir. *
-* length = taille du contenu en question. *
+* Paramètres : content = contenu binaire à parcourir. *
* *
* Description : Indique si le format peut être pris en charge ici. *
* *
@@ -70,14 +68,17 @@ static bool g_java_format_translate_offset_into_address(const GJavaFormat *, off
* *
******************************************************************************/
-bool java_is_matching(FormatType type, const uint8_t *content, off_t length)
+bool java_is_matching(GBinContent *content)
{
bool result; /* Bilan à faire connaître */
+ vmpa2t addr; /* Tête de lecture initiale */
+ char magic[4]; /* Idenfiant standard */
- result = false;
+ init_vmpa(&addr, 0, VMPA_NO_VIRTUAL);
- if (length >= 4)
- result = (strncmp((const char *)content, "\xca\xfe\xba\xbe", 4) == 0);
+ result = g_binary_content_get_raw(content, &addr, 4, (bin_t *)magic);
+
+ result &= (memcmp(magic, "\xca\xfe\xba\xbe", 4) == 0);
return result;
@@ -152,7 +153,7 @@ GBinFormat *g_java_format_new(const bin_t *content, off_t length)
result = g_object_new(G_TYPE_JAVA_FORMAT, NULL);
- g_binary_format_set_content(G_BIN_FORMAT(result), content, length);
+ //g_binary_format_set_content(G_BIN_FORMAT(result), content, length);
offset = 0;
diff --git a/src/format/java/java.h b/src/format/java/java.h
index e19b03a..2ce8dba 100755
--- a/src/format/java/java.h
+++ b/src/format/java/java.h
@@ -49,7 +49,7 @@ typedef struct _GJavaFormatClass GJavaFormatClass;
/* Indique si le format peut être pris en charge ici. */
-bool java_is_matching(FormatType, const bin_t *, off_t);
+bool java_is_matching(GBinContent *);
/* Indique le type défini pour un format d'exécutable Java. */
GType g_java_format_get_type(void);
diff --git a/src/format/pe/pe.c b/src/format/pe/pe.c
index 88756dd..39560ce 100644
--- a/src/format/pe/pe.c
+++ b/src/format/pe/pe.c
@@ -55,9 +55,7 @@ static bool g_pe_format_translate_offset_into_address(const GPeFormat *, off_t,
/******************************************************************************
* *
-* Paramètres : type = type de format recherché. *
-* content = contenu binaire à parcourir. *
-* length = taille du contenu en question. *
+* Paramètres : content = contenu binaire à parcourir. *
* *
* Description : Indique si le format peut être pris en charge ici. *
* *
@@ -67,13 +65,13 @@ static bool g_pe_format_translate_offset_into_address(const GPeFormat *, off_t,
* *
******************************************************************************/
-bool pe_is_matching(FormatType type, const uint8_t *content, off_t length)
+bool pe_is_matching(GBinContent *content)
{
bool result; /* Bilan à faire connaître */
image_dos_header dos_header; /* En-tête DOS */
result = false;
-
+#if 0
if (length >= 2)
{
result = (strncmp((const char *)content, "\x4d\x5a" /* MZ */, 2) == 0);
@@ -90,7 +88,7 @@ bool pe_is_matching(FormatType type, const uint8_t *content, off_t length)
"\x50\x45\x00\x00" /* PE00 */, 4) == 0);
}
-
+#endif
return result;
}
@@ -168,7 +166,7 @@ GBinFormat *g_pe_format_new(const bin_t *content, off_t length)
result = g_object_new(G_TYPE_PE_FORMAT, NULL);
- g_binary_format_set_content(G_BIN_FORMAT(result), content, length);
+ //g_binary_format_set_content(G_BIN_FORMAT(result), content, length);
offset = 0;
diff --git a/src/format/pe/pe.h b/src/format/pe/pe.h
index 0315ea2..4e1141b 100644
--- a/src/format/pe/pe.h
+++ b/src/format/pe/pe.h
@@ -49,7 +49,7 @@ typedef struct _GPeFormatClass GPeFormatClass;
/* Indique si le format peut être pris en charge ici. */
-bool pe_is_matching(FormatType, const bin_t *, off_t);
+bool pe_is_matching(GBinContent *);
/* Indique le type défini pour un format d'exécutable PE. */
GType g_pe_format_get_type(void);