diff options
| author | Cyrille Bagard <nocbos@gmail.com> | 2023-09-27 23:08:50 (GMT) | 
|---|---|---|
| committer | Cyrille Bagard <nocbos@gmail.com> | 2023-09-27 23:08:50 (GMT) | 
| commit | 641761e51672fa33f27acdcdb40b46b506ab07dc (patch) | |
| tree | 8db1ce412b87f0217b250ff371ebcc51ab3905cf /src | |
| parent | a5cd93644fbb16dfc181f630b1c8d739fdc685fb (diff) | |
Replace interface by inheritance for binary content objects.
Diffstat (limited to 'src')
| -rw-r--r-- | src/analysis/content-int.h | 29 | ||||
| -rw-r--r-- | src/analysis/content.c | 296 | ||||
| -rw-r--r-- | src/analysis/content.h | 20 | ||||
| -rw-r--r-- | src/analysis/contents/Makefile.am | 3 | ||||
| -rw-r--r-- | src/analysis/contents/encapsulated-int.h | 62 | ||||
| -rw-r--r-- | src/analysis/contents/encapsulated.c | 195 | ||||
| -rw-r--r-- | src/analysis/contents/file-int.h | 58 | ||||
| -rw-r--r-- | src/analysis/contents/file.c | 154 | ||||
| -rw-r--r-- | src/analysis/contents/memory-int.h | 11 | ||||
| -rw-r--r-- | src/analysis/contents/memory.c | 169 | ||||
| -rw-r--r-- | src/analysis/contents/restricted-int.h | 59 | ||||
| -rw-r--r-- | src/analysis/contents/restricted.c | 177 | ||||
| -rw-r--r-- | src/analysis/contents/restricted.h | 3 | ||||
| -rw-r--r-- | src/analysis/type.c | 6 | 
14 files changed, 760 insertions, 482 deletions
diff --git a/src/analysis/content-int.h b/src/analysis/content-int.h index 4ef64f9..3475b3f 100644 --- a/src/analysis/content-int.h +++ b/src/analysis/content-int.h @@ -2,7 +2,7 @@  /* Chrysalide - Outil d'analyse de fichiers binaires   * content-int.h - définitions internes propres aux contenus binaires   * - * Copyright (C) 2015-2019 Cyrille Bagard + * Copyright (C) 2015-2023 Cyrille Bagard   *   *  This file is part of Chrysalide.   * @@ -26,6 +26,7 @@  #include "content.h" +#include "storage/serialize-int.h" @@ -83,11 +84,24 @@ typedef bool (* read_uleb128_fc) (const GBinContent *, vmpa2t *, uleb128_t *);  /* Lit un nombre signé encodé au format LEB128. */  typedef bool (* read_leb128_fc) (const GBinContent *, vmpa2t *, leb128_t *); +/* Charge un objet depuis une mémoire tampon. */ +typedef bool (* load_content_cb) (GBinContent *, GObjectStorage *, packed_buffer_t *); -/* Accès à un contenu binaire quelconque (interface) */ -struct _GBinContentIface +/* Sauvegarde un objet dans une mémoire tampon. */ +typedef bool (* store_content_cb) (const GBinContent *, GObjectStorage *, packed_buffer_t *); + + +/* Accès à un contenu binaire quelconque (instance) */ +struct _GBinContent  { -    GTypeInterface base_iface;              /* A laisser en premier        */ +    GObject parent;                         /* A laisser en premier        */ + +}; + +/* Accès à un contenu binaire quelconque (classe) */ +struct _GBinContentClass +{ +    GObjectClass parent;                    /* A laisser en premier        */      set_content_attributes set_attribs;     /* Enregistrement d'attributs  */      get_content_attributes get_attribs;     /* Fourniture d'attributs      */ @@ -116,11 +130,10 @@ struct _GBinContentIface      read_uleb128_fc read_uleb128;           /* Lecture d'un LEB non signé  */      read_leb128_fc read_leb128;             /* Lecture d'un LEB signé      */ -}; - +    load_content_cb load;                   /* Chargement                  */ +    store_content_cb store;                 /* Enregistrement              */ -/* Redéfinition */ -typedef GBinContentIface GBinContentInterface; +}; diff --git a/src/analysis/content.c b/src/analysis/content.c index 6d8075c..0560d73 100644 --- a/src/analysis/content.c +++ b/src/analysis/content.c @@ -35,20 +35,94 @@ -/* Procède à l'initialisation de l'interface de rassemblement. */ -static void g_binary_content_default_init(GBinContentInterface *); +/* -------------------------- ENSEMBLE DE DONNEES BINAIRES -------------------------- */ +/* Initialise la classe des contenus binaires à parcourir. */ +static void g_binary_content_class_init(GBinContentClass *); -/* Détermine le type d'une interface pour la lecture de binaire. */ -G_DEFINE_INTERFACE(GBinContent, g_binary_content, G_TYPE_OBJECT); +/* Initialise l'instance de contenu binaire à parcourir. */ +static void g_binary_content_init(GBinContent *); + +/* Procède à l'initialisation de l'interface de sérialisation. */ +static void g_binary_content_serializable_interface_init(GSerializableObjectIface *); + +/* Supprime toutes les références externes. */ +static void g_binary_content_dispose(GBinContent *); + +/* Procède à la libération totale de la mémoire. */ +static void g_binary_content_finalize(GBinContent *); + + + +/* -------------------- CONSERVATION ET RECHARGEMENT DES DONNEES -------------------- */ + + +/* Charge un contenu depuis une mémoire tampon. */ +static bool g_binary_content_load(GBinContent *, GObjectStorage *, packed_buffer_t *); + +/* Sauvegarde un contenu dans une mémoire tampon. */ +static bool g_binary_content_store(const GBinContent *, GObjectStorage *, packed_buffer_t *); + + + +/* ---------------------------------------------------------------------------------- */ +/*                            ENSEMBLE DE DONNEES BINAIRES                            */ +/* ---------------------------------------------------------------------------------- */ + + +/* Détermine le type d'un contenu binaire à parcourir. */ +G_DEFINE_TYPE_WITH_CODE(GBinContent, g_binary_content, G_TYPE_OBJECT, +                        G_IMPLEMENT_INTERFACE(G_TYPE_SERIALIZABLE_OBJECT, g_binary_content_serializable_interface_init)); + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : klass = classe à initialiser.                                * +*                                                                             * +*  Description : Initialise la classe des contenus binaires à parcourir.      * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_binary_content_class_init(GBinContentClass *klass) +{ +    GObjectClass *object;                   /* Autre version de la classe  */ + +    object = G_OBJECT_CLASS(klass); + +    object->dispose = (GObjectFinalizeFunc/* ! */)g_binary_content_dispose; +    object->finalize = (GObjectFinalizeFunc)g_binary_content_finalize; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : content = instance à initialiser.                            * +*                                                                             * +*  Description : Initialise l'instance de contenu binaire à parcourir.        * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_binary_content_init(GBinContent *content) +{ + +}  /******************************************************************************  *                                                                             *  *  Paramètres  : iface = interface GLib à initialiser.                        *  *                                                                             * -*  Description : Procède à l'initialisation de l'interface de rassemblement.  * +*  Description : Procède à l'initialisation de l'interface de sérialisation.  *  *                                                                             *  *  Retour      : -                                                            *  *                                                                             * @@ -56,8 +130,48 @@ G_DEFINE_INTERFACE(GBinContent, g_binary_content, G_TYPE_OBJECT);  *                                                                             *  ******************************************************************************/ -static void g_binary_content_default_init(GBinContentInterface *iface) +static void g_binary_content_serializable_interface_init(GSerializableObjectIface *iface)  { +    iface->load = (load_serializable_object_cb)g_binary_content_load; +    iface->store = (store_serializable_object_cb)g_binary_content_store; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : content = instance d'objet GLib à traiter.                   * +*                                                                             * +*  Description : Supprime toutes les références externes.                     * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_binary_content_dispose(GBinContent *content) +{ +    G_OBJECT_CLASS(g_binary_content_parent_class)->dispose(G_OBJECT(content)); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : content = instance d'objet GLib à traiter.                   * +*                                                                             * +*  Description : Procède à la libération totale de la mémoire.                * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_binary_content_finalize(GBinContent *content) +{ +    G_OBJECT_CLASS(g_binary_content_parent_class)->finalize(G_OBJECT(content));  } @@ -77,11 +191,11 @@ static void g_binary_content_default_init(GBinContentInterface *iface)  void g_binary_content_set_attributes(GBinContent *content, GContentAttributes *attribs)  { -    GBinContentIface *iface;                /* Interface utilisée          */ +    GBinContentClass *class;                /* Classe de l'instance        */ -    iface = G_BIN_CONTENT_GET_IFACE(content); +    class = G_BIN_CONTENT_GET_CLASS(content); -    iface->set_attribs(content, attribs); +    class->set_attribs(content, attribs);  } @@ -101,11 +215,11 @@ void g_binary_content_set_attributes(GBinContent *content, GContentAttributes *a  GContentAttributes *g_binary_content_get_attributes(const GBinContent *content)  {      GContentAttributes *result;             /* Instance à retourner        */ -    GBinContentIface *iface;                /* Interface utilisée          */ +    GBinContentClass *class;                /* Classe de l'instance        */ -    iface = G_BIN_CONTENT_GET_IFACE(content); +    class = G_BIN_CONTENT_GET_CLASS(content); -    result = iface->get_attribs(content); +    result = class->get_attribs(content);      return result; @@ -127,11 +241,11 @@ GContentAttributes *g_binary_content_get_attributes(const GBinContent *content)  GBinContent *g_binary_content_get_root(GBinContent *content)  {      GBinContent *result;                    /* Contenu en place à renvoyer */ -    GBinContentIface *iface;                /* Interface utilisée          */ +    GBinContentClass *class;                /* Classe de l'instance        */ -    iface = G_BIN_CONTENT_GET_IFACE(content); +    class = G_BIN_CONTENT_GET_CLASS(content); -    result = iface->get_root(content); +    result = class->get_root(content);      return result; @@ -154,11 +268,11 @@ GBinContent *g_binary_content_get_root(GBinContent *content)  char *g_binary_content_describe(const GBinContent *content, bool full)  {      char *result;                           /* Description à retourner     */ -    GBinContentIface *iface;                /* Interface utilisée          */ +    GBinContentClass *class;                /* Classe de l'instance        */ -    iface = G_BIN_CONTENT_GET_IFACE(content); +    class = G_BIN_CONTENT_GET_CLASS(content); -    result = iface->describe(content, full); +    result = class->describe(content, full);      return result; @@ -181,7 +295,7 @@ const gchar *g_binary_content_get_checksum(GBinContent *content)  {      const gchar *result;                    /* Empreinte à retourner       */      GChecksum *checksum;                    /* Calcul de l'empreinte       */ -    GBinContentIface *iface;                /* Interface utilisée          */ +    GBinContentClass *class;                /* Classe de l'instance        */      checksum = g_object_get_data(G_OBJECT(content), "checksum"); @@ -192,9 +306,9 @@ const gchar *g_binary_content_get_checksum(GBinContent *content)          g_checksum_reset(checksum); -        iface = G_BIN_CONTENT_GET_IFACE(content); +        class = G_BIN_CONTENT_GET_CLASS(content); -        iface->compute_checksum(content, checksum); +        class->compute_checksum(content, checksum);          g_object_set_data_full(G_OBJECT(content), "checksum", checksum, (GDestroyNotify)g_checksum_free); @@ -221,11 +335,11 @@ const gchar *g_binary_content_get_checksum(GBinContent *content)  phys_t g_binary_content_compute_size(const GBinContent *content)  { -    GBinContentIface *iface;                /* Interface utilisée          */ +    GBinContentClass *class;                /* Classe de l'instance        */ -    iface = G_BIN_CONTENT_GET_IFACE(content); +    class = G_BIN_CONTENT_GET_CLASS(content); -    return iface->compute_size(content); +    return class->compute_size(content);  } @@ -245,11 +359,11 @@ phys_t g_binary_content_compute_size(const GBinContent *content)  void g_binary_content_compute_start_pos(const GBinContent *content, vmpa2t *pos)  { -    GBinContentIface *iface;                /* Interface utilisée          */ +    GBinContentClass *class;                /* Classe de l'instance        */ -    iface = G_BIN_CONTENT_GET_IFACE(content); +    class = G_BIN_CONTENT_GET_CLASS(content); -    return iface->compute_start_pos(content, pos); +    return class->compute_start_pos(content, pos);  } @@ -269,11 +383,11 @@ void g_binary_content_compute_start_pos(const GBinContent *content, vmpa2t *pos)  void g_binary_content_compute_end_pos(const GBinContent *content, vmpa2t *pos)  { -    GBinContentIface *iface;                /* Interface utilisée          */ +    GBinContentClass *class;                /* Classe de l'instance        */ -    iface = G_BIN_CONTENT_GET_IFACE(content); +    class = G_BIN_CONTENT_GET_CLASS(content); -    return iface->compute_end_pos(content, pos); +    return class->compute_end_pos(content, pos);  } @@ -294,11 +408,11 @@ void g_binary_content_compute_end_pos(const GBinContent *content, vmpa2t *pos)  bool g_binary_content_seek(const GBinContent *content, vmpa2t *addr, phys_t length)  { -    GBinContentIface *iface;                /* Interface utilisée          */ +    GBinContentClass *class;                /* Classe de l'instance        */ -    iface = G_BIN_CONTENT_GET_IFACE(content); +    class = G_BIN_CONTENT_GET_CLASS(content); -    return iface->seek(content, addr, length); +    return class->seek(content, addr, length);  } @@ -319,11 +433,11 @@ bool g_binary_content_seek(const GBinContent *content, vmpa2t *addr, phys_t leng  const bin_t *g_binary_content_get_raw_access(const GBinContent *content, vmpa2t *addr, phys_t length)  { -    GBinContentIface *iface;                /* Interface utilisée          */ +    GBinContentClass *class;                /* Classe de l'instance        */ -    iface = G_BIN_CONTENT_GET_IFACE(content); +    class = G_BIN_CONTENT_GET_CLASS(content); -    return iface->get_raw_access(content, addr, length); +    return class->get_raw_access(content, addr, length);  } @@ -346,11 +460,11 @@ const bin_t *g_binary_content_get_raw_access(const GBinContent *content, vmpa2t  bool g_binary_content_read_raw(const GBinContent *content, vmpa2t *addr, phys_t length, bin_t *out)  {      bool result;                            /* Bilan à remonter            */ -    GBinContentIface *iface;                /* Interface utilisée          */ +    GBinContentClass *class;                /* Classe de l'instance        */ -    iface = G_BIN_CONTENT_GET_IFACE(content); +    class = G_BIN_CONTENT_GET_CLASS(content); -    result = iface->read_raw(content, addr, length, out); +    result = class->read_raw(content, addr, length, out);      return result; @@ -375,11 +489,11 @@ bool g_binary_content_read_raw(const GBinContent *content, vmpa2t *addr, phys_t  bool g_binary_content_read_u4(const GBinContent *content, vmpa2t *addr, bool *low, uint8_t *val)  {      bool result;                            /* Bilan à remonter            */ -    GBinContentIface *iface;                /* Interface utilisée          */ +    GBinContentClass *class;                /* Classe de l'instance        */ -    iface = G_BIN_CONTENT_GET_IFACE(content); +    class = G_BIN_CONTENT_GET_CLASS(content); -    result = iface->read_u4(content, addr, low, val); +    result = class->read_u4(content, addr, low, val);      return result; @@ -404,11 +518,11 @@ bool g_binary_content_read_u4(const GBinContent *content, vmpa2t *addr, bool *lo  bool g_binary_content_read_u8(const GBinContent *content, vmpa2t *addr, uint8_t *val)  {      bool result;                            /* Bilan à remonter            */ -    GBinContentIface *iface;                /* Interface utilisée          */ +    GBinContentClass *class;                /* Classe de l'instance        */ -    iface = G_BIN_CONTENT_GET_IFACE(content); +    class = G_BIN_CONTENT_GET_CLASS(content); -    result = iface->read_u8(content, addr, val); +    result = class->read_u8(content, addr, val);      return result; @@ -433,11 +547,11 @@ bool g_binary_content_read_u8(const GBinContent *content, vmpa2t *addr, uint8_t  bool g_binary_content_read_u16(const GBinContent *content, vmpa2t *addr, SourceEndian endian, uint16_t *val)  {      bool result;                            /* Bilan à remonter            */ -    GBinContentIface *iface;                /* Interface utilisée          */ +    GBinContentClass *class;                /* Classe de l'instance        */ -    iface = G_BIN_CONTENT_GET_IFACE(content); +    class = G_BIN_CONTENT_GET_CLASS(content); -    result = iface->read_u16(content, addr, endian, val); +    result = class->read_u16(content, addr, endian, val);      return result; @@ -462,11 +576,11 @@ bool g_binary_content_read_u16(const GBinContent *content, vmpa2t *addr, SourceE  bool g_binary_content_read_u32(const GBinContent *content, vmpa2t *addr, SourceEndian endian, uint32_t *val)  {      bool result;                            /* Bilan à remonter            */ -    GBinContentIface *iface;                /* Interface utilisée          */ +    GBinContentClass *class;                /* Classe de l'instance        */ -    iface = G_BIN_CONTENT_GET_IFACE(content); +    class = G_BIN_CONTENT_GET_CLASS(content); -    result = iface->read_u32(content, addr, endian, val); +    result = class->read_u32(content, addr, endian, val);      return result; @@ -491,11 +605,11 @@ bool g_binary_content_read_u32(const GBinContent *content, vmpa2t *addr, SourceE  bool g_binary_content_read_u64(const GBinContent *content, vmpa2t *addr, SourceEndian endian, uint64_t *val)  {      bool result;                            /* Bilan à remonter            */ -    GBinContentIface *iface;                /* Interface utilisée          */ +    GBinContentClass *class;                /* Classe de l'instance        */ -    iface = G_BIN_CONTENT_GET_IFACE(content); +    class = G_BIN_CONTENT_GET_CLASS(content); -    result = iface->read_u64(content, addr, endian, val); +    result = class->read_u64(content, addr, endian, val);      return result; @@ -519,11 +633,11 @@ bool g_binary_content_read_u64(const GBinContent *content, vmpa2t *addr, SourceE  bool g_binary_content_read_uleb128(const GBinContent *content, vmpa2t *addr, uleb128_t *val)  {      bool result;                            /* Bilan à remonter            */ -    GBinContentIface *iface;                /* Interface utilisée          */ +    GBinContentClass *class;                /* Classe de l'instance        */ -    iface = G_BIN_CONTENT_GET_IFACE(content); +    class = G_BIN_CONTENT_GET_CLASS(content); -    result = iface->read_uleb128(content, addr, val); +    result = class->read_uleb128(content, addr, val);      return result; @@ -547,11 +661,73 @@ bool g_binary_content_read_uleb128(const GBinContent *content, vmpa2t *addr, ule  bool g_binary_content_read_leb128(const GBinContent *content, vmpa2t *addr, leb128_t *val)  {      bool result;                            /* Bilan à remonter            */ -    GBinContentIface *iface;                /* Interface utilisée          */ +    GBinContentClass *class;                /* Classe de l'instance        */ + +    class = G_BIN_CONTENT_GET_CLASS(content); + +    result = class->read_leb128(content, addr, val); + +    return result; + +} + + + +/* ---------------------------------------------------------------------------------- */ +/*                      CONSERVATION ET RECHARGEMENT DES DONNEES                      */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : content = élément GLib à constuire.                          * +*                storage = conservateur de données à manipuler ou NULL.       * +*                pbuf    = zone tampon à lire.                                * +*                                                                             * +*  Description : Charge un contenu depuis une mémoire tampon.                 * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static bool g_binary_content_load(GBinContent *content, GObjectStorage *storage, packed_buffer_t *pbuf) +{ +    bool result;                            /* Bilan à retourner           */ +    GBinContentClass *class;                /* Classe de l'instance        */ + +    class = G_BIN_CONTENT_GET_CLASS(content); + +    result = class->load(content, storage, pbuf); + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : content = élément GLib à consulter.                          * +*                storage = conservateur de données à manipuler ou NULL.       * +*                pbuf    = zone tampon à remplir.                             * +*                                                                             * +*  Description : Sauvegarde un contenu dans une mémoire tampon.               * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static bool g_binary_content_store(const GBinContent *content, GObjectStorage *storage, packed_buffer_t *pbuf) +{ +    bool result;                            /* Bilan à retourner           */ +    GBinContentClass *class;                /* Classe de l'instance        */ -    iface = G_BIN_CONTENT_GET_IFACE(content); +    class = G_BIN_CONTENT_GET_CLASS(content); -    result = iface->read_leb128(content, addr, val); +    result = class->store(content, storage, pbuf);      return result; diff --git a/src/analysis/content.h b/src/analysis/content.h index afb721e..5279890 100644 --- a/src/analysis/content.h +++ b/src/analysis/content.h @@ -36,22 +36,22 @@ -#define G_TYPE_BIN_CONTENT             (g_binary_content_get_type()) -#define G_BIN_CONTENT(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_BIN_CONTENT, GBinContent)) -#define G_BIN_CONTENT_CLASS(vtable)    (G_TYPE_CHECK_CLASS_CAST((vtable), G_TYPE_BIN_CONTENT, GBinContentIface)) -#define G_IS_BIN_CONTENT(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_BIN_CONTENT)) -#define G_IS_BIN_CONTENT_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE((vtable), G_TYPE_BIN_CONTENT)) -#define G_BIN_CONTENT_GET_IFACE(inst)  (G_TYPE_INSTANCE_GET_INTERFACE((inst), G_TYPE_BIN_CONTENT, GBinContentIface)) +#define G_TYPE_BIN_CONTENT            g_binary_content_get_type() +#define G_BIN_CONTENT(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_BIN_CONTENT, GBinContent)) +#define G_IS_BIN_CONTENT(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_BIN_CONTENT)) +#define G_BIN_CONTENT_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_BIN_CONTENT, GBinContentClass)) +#define G_IS_BIN_CONTENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_BIN_CONTENT)) +#define G_BIN_CONTENT_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_BIN_CONTENT, GBinContentClass)) -/* Accès à un contenu binaire quelconque (coquille vide) */ +/* Accès à un contenu binaire quelconque (instance) */  typedef struct _GBinContent GBinContent; -/* Accès à un contenu binaire quelconque (interface) */ -typedef struct _GBinContentIface GBinContentIface; +/* Accès à un contenu binaire quelconque (classe) */ +typedef struct _GBinContentClass GBinContentClass; -/* Détermine le type d'une interface pour la lecture de binaire. */ +/* Détermine le type d'un contenu binaire à parcourir. */  GType g_binary_content_get_type(void) G_GNUC_CONST;  /* Associe un ensemble d'attributs au contenu binaire. */ diff --git a/src/analysis/contents/Makefile.am b/src/analysis/contents/Makefile.am index 1263f42..e1cf04f 100644 --- a/src/analysis/contents/Makefile.am +++ b/src/analysis/contents/Makefile.am @@ -2,10 +2,13 @@  noinst_LTLIBRARIES  = libanalysiscontents.la  libanalysiscontents_la_SOURCES =		\ +	encapsulated-int.h					\  	encapsulated.h encapsulated.c		\ +	file-int.h							\  	file.h file.c						\  	memory-int.h						\  	memory.h memory.c					\ +	restricted-int.h					\  	restricted.h restricted.c  libanalysiscontents_la_CFLAGS = $(TOOLKIT_CFLAGS) diff --git a/src/analysis/contents/encapsulated-int.h b/src/analysis/contents/encapsulated-int.h new file mode 100644 index 0000000..5ccd318 --- /dev/null +++ b/src/analysis/contents/encapsulated-int.h @@ -0,0 +1,62 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * encapsulated-int.h - prototypes internes pour le chargement de données binaires à partir d'un contenu restreint + * + * Copyright (C) 2023 Cyrille Bagard + * + *  This file is part of Chrysalide. + * + *  Chrysalide is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 3 of the License, or + *  (at your option) any later version. + * + *  Chrysalide is distributed in the hope that it will be useful, + *  but WITHOUT ANY WARRANTY; without even the implied warranty of + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *  GNU General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with Chrysalide.  If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _ANALYSIS_CONTENTS_ENCAPSULATED_INT_H +#define _ANALYSIS_CONTENTS_ENCAPSULATED_INT_H + + +#include "encapsulated.h" + + +#include "../content-int.h" + + + +/* Contenu de données binaires issues d'un contenu restreint (instance) */ +struct _GEncapsContent +{ +    GBinContent parent;                     /* A laisser en premier        */ + +    GBinContent *base;                      /* Base offrant une extraction */ +    char *path;                             /* Chemin vers le contenu ciblé*/ +    GBinContent *endpoint;                  /* Contenu ciblé               */ + +    char *full_desc;                        /* Description de l'ensemble   */ +    char *desc;                             /* Description de l'ensemble   */ + +}; + +/* Contenu de données binaires issues d'un contenu restreint (classe) */ +struct _GEncapsContentClass +{ +    GBinContentClass parent;                /* A laisser en premier        */ + +}; + + +/* Met en place un contenu de données brutes encapsulées. */ +bool g_encaps_content_create(GEncapsContent *, GBinContent *, const char *, GBinContent *); + + + +#endif  /* _ANALYSIS_CONTENTS_ENCAPSULATED_INT_H */ diff --git a/src/analysis/contents/encapsulated.c b/src/analysis/contents/encapsulated.c index dadc0a5..e0e6ed1 100644 --- a/src/analysis/contents/encapsulated.c +++ b/src/analysis/contents/encapsulated.c @@ -28,7 +28,7 @@  #include <string.h> -#include "../content-int.h" +#include "encapsulated-int.h"  #include "../db/misc/rlestr.h"  #include "../storage/serialize-int.h"  #include "../../common/extstr.h" @@ -38,40 +38,12 @@  /* -------------------------- ENSEMBLE DE DONNEES BINAIRES -------------------------- */ -/* Contenu de issu d'un contenu plus global (instance) */ -struct _GEncapsContent -{ -    GObject parent;                         /* A laisser en premier        */ - -    GBinContent *base;                      /* Base offrant une extraction */ -    char *path;                             /* Chemin vers le contenu ciblé*/ -    GBinContent *endpoint;                  /* Contenu ciblé               */ - -    char *full_desc;                        /* Description de l'ensemble   */ -    char *desc;                             /* Description de l'ensemble   */ - -}; - -/* Contenu de issu d'un contenu plus global (classe) */ -struct _GEncapsContentClass -{ -    GObjectClass parent;                    /* A laisser en premier        */ - -}; - -  /* Initialise la classe des contenus de données encapsulés. */  static void g_encaps_content_class_init(GEncapsContentClass *);  /* Initialise une instance de contenu de données encapsulé. */  static void g_encaps_content_init(GEncapsContent *); -/* Procède à l'initialisation de l'interface de sérialisation. */ -static void g_encaps_content_serializable_init(GSerializableObjectInterface *); - -/* Procède à l'initialisation de l'interface de lecture. */ -static void g_encaps_content_interface_init(GBinContentInterface *); -  /* Supprime toutes les références externes. */  static void g_encaps_content_dispose(GEncapsContent *); @@ -80,7 +52,7 @@ static void g_encaps_content_finalize(GEncapsContent *); -/* ---------------------- INTERACTIONS AVEC UN CONTENU BINAIRE ---------------------- */ +/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */  /* Associe un ensemble d'attributs au contenu binaire. */ @@ -137,11 +109,6 @@ static bool g_encaps_content_read_uleb128(const GEncapsContent *, vmpa2t *, uleb  /* Lit un nombre signé encodé au format LEB128. */  static bool g_encaps_content_read_leb128(const GEncapsContent *, vmpa2t *, leb128_t *); - - -/* -------------------- CONSERVATION ET RECHARGEMENT DES DONNEES -------------------- */ - -  /* Charge un contenu depuis une mémoire tampon. */  static bool g_encaps_content_load(GEncapsContent *, GObjectStorage *, packed_buffer_t *); @@ -156,9 +123,7 @@ static bool g_encaps_content_store(const GEncapsContent *, GObjectStorage *, pac  /* Indique le type défini par la GLib pour les contenus encapsulés. */ -G_DEFINE_TYPE_WITH_CODE(GEncapsContent, g_encaps_content, G_TYPE_OBJECT, -                        G_IMPLEMENT_INTERFACE(G_TYPE_BIN_CONTENT, g_encaps_content_interface_init) -                        G_IMPLEMENT_INTERFACE(G_TYPE_SERIALIZABLE_OBJECT, g_encaps_content_serializable_init)); +G_DEFINE_TYPE(GEncapsContent, g_encaps_content, G_TYPE_BIN_CONTENT);  /****************************************************************************** @@ -176,88 +141,53 @@ G_DEFINE_TYPE_WITH_CODE(GEncapsContent, g_encaps_content, G_TYPE_OBJECT,  static void g_encaps_content_class_init(GEncapsContentClass *klass)  {      GObjectClass *object;                   /* Autre version de la classe  */ +    GBinContentClass *content;              /* Version parente de la classe*/      object = G_OBJECT_CLASS(klass);      object->dispose = (GObjectFinalizeFunc/* ! */)g_encaps_content_dispose;      object->finalize = (GObjectFinalizeFunc)g_encaps_content_finalize; -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : content = instance à initialiser.                            * -*                                                                             * -*  Description : Initialise une instance de contenu de données encapsulé.     * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_encaps_content_init(GEncapsContent *content) -{ -    content->base = NULL; -    content->path = NULL; -    content->endpoint = NULL; - -    content->full_desc = NULL; -    content->desc = NULL; +    content = G_BIN_CONTENT_CLASS(klass); -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : iface = interface GLib à initialiser.                        * -*                                                                             * -*  Description : Procède à l'initialisation de l'interface de lecture.        * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ +    content->set_attribs = (set_content_attributes)g_encaps_content_set_attributes; +    content->get_attribs = (get_content_attributes)g_encaps_content_get_attributes; -static void g_encaps_content_interface_init(GBinContentInterface *iface) -{ -    iface->set_attribs = (set_content_attributes)g_encaps_content_set_attributes; -    iface->get_attribs = (get_content_attributes)g_encaps_content_get_attributes; +    content->get_root = (get_content_root_fc)g_encaps_content_get_root; -    iface->get_root = (get_content_root_fc)g_encaps_content_get_root; +    content->describe = (describe_content_fc)g_encaps_content_describe; -    iface->describe = (describe_content_fc)g_encaps_content_describe; +    content->compute_checksum = (compute_checksum_fc)g_encaps_content_compute_checksum; -    iface->compute_checksum = (compute_checksum_fc)g_encaps_content_compute_checksum; +    content->compute_size = (compute_size_fc)g_encaps_content_compute_size; +    content->compute_start_pos = (compute_start_pos_fc)g_encaps_content_compute_start_pos; +    content->compute_end_pos = (compute_end_pos_fc)g_encaps_content_compute_end_pos; -    iface->compute_size = (compute_size_fc)g_encaps_content_compute_size; -    iface->compute_start_pos = (compute_start_pos_fc)g_encaps_content_compute_start_pos; -    iface->compute_end_pos = (compute_end_pos_fc)g_encaps_content_compute_end_pos; +    content->seek = (seek_fc)g_encaps_content_seek; -    iface->seek = (seek_fc)g_encaps_content_seek; +    content->get_raw_access = (get_raw_access_fc)g_encaps_content_get_raw_access; -    iface->get_raw_access = (get_raw_access_fc)g_encaps_content_get_raw_access; +    content->read_raw = (read_raw_fc)g_encaps_content_read_raw; +    content->read_u4 = (read_u4_fc)g_encaps_content_read_u4; +    content->read_u8 = (read_u8_fc)g_encaps_content_read_u8; +    content->read_u16 = (read_u16_fc)g_encaps_content_read_u16; +    content->read_u32 = (read_u32_fc)g_encaps_content_read_u32; +    content->read_u64 = (read_u64_fc)g_encaps_content_read_u64; -    iface->read_raw = (read_raw_fc)g_encaps_content_read_raw; -    iface->read_u4 = (read_u4_fc)g_encaps_content_read_u4; -    iface->read_u8 = (read_u8_fc)g_encaps_content_read_u8; -    iface->read_u16 = (read_u16_fc)g_encaps_content_read_u16; -    iface->read_u32 = (read_u32_fc)g_encaps_content_read_u32; -    iface->read_u64 = (read_u64_fc)g_encaps_content_read_u64; +    content->read_uleb128 = (read_uleb128_fc)g_encaps_content_read_uleb128; +    content->read_leb128 = (read_leb128_fc)g_encaps_content_read_leb128; -    iface->read_uleb128 = (read_uleb128_fc)g_encaps_content_read_uleb128; -    iface->read_leb128 = (read_leb128_fc)g_encaps_content_read_leb128; +    content->load = (load_content_cb)g_encaps_content_load; +    content->store = (store_content_cb)g_encaps_content_store;  }  /******************************************************************************  *                                                                             * -*  Paramètres  : iface = interface GLib à initialiser.                        * +*  Paramètres  : content = instance à initialiser.                            *  *                                                                             * -*  Description : Procède à l'initialisation de l'interface de sérialisation.  * +*  Description : Initialise une instance de contenu de données encapsulé.     *  *                                                                             *  *  Retour      : -                                                            *  *                                                                             * @@ -265,10 +195,14 @@ static void g_encaps_content_interface_init(GBinContentInterface *iface)  *                                                                             *  ******************************************************************************/ -static void g_encaps_content_serializable_init(GSerializableObjectInterface *iface) +static void g_encaps_content_init(GEncapsContent *content)  { -    iface->load = (load_serializable_object_cb)g_encaps_content_load; -    iface->store = (store_serializable_object_cb)g_encaps_content_store; +    content->base = NULL; +    content->path = NULL; +    content->endpoint = NULL; + +    content->full_desc = NULL; +    content->desc = NULL;  } @@ -337,30 +271,59 @@ static void g_encaps_content_finalize(GEncapsContent *content)  GBinContent *g_encaps_content_new(GBinContent *base, const char *path, GBinContent *endpoint)  { -    GEncapsContent *result;                 /* Structure à retourner      */ +    GBinContent *result;                    /* Structure à retourner       */      result = g_object_new(G_TYPE_ENCAPS_CONTENT, NULL); +    if (!g_encaps_content_create(G_ENCAPS_CONTENT(result), base, path, endpoint)) +        g_clear_object(&result); + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : content  = instance à initialiser pleinement.                * +*                base     = contenu binaire d'où réaliser une extraction.     * +*                path     = chemin vers le contenu finalement ciblé.          * +*                endpoint = contenu final rendu accessible.                   * +*                                                                             * +*  Description : Met en place un contenu de données brutes encapsulées.       * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +bool g_encaps_content_create(GEncapsContent *content, GBinContent *base, const char *path, GBinContent *endpoint) +{ +    bool result;                            /* Bilan à retourner           */ +      g_object_ref(base);      g_object_ref(endpoint); -    result->base = base; -    result->path = strdup(path); -    result->endpoint = endpoint; +    content->base = base; +    content->path = strdup(path); +    content->endpoint = endpoint;      /* Description complète */ -    result->full_desc = g_binary_content_describe(result->base, true); +    content->full_desc = g_binary_content_describe(content->base, true); -    result->full_desc = stradd(result->full_desc, G_DIR_SEPARATOR_S); +    content->full_desc = stradd(content->full_desc, G_DIR_SEPARATOR_S); -    result->full_desc = stradd(result->full_desc, path); +    content->full_desc = stradd(content->full_desc, path);      /* Description partielle */ -    result->desc = strdup(path); +    content->desc = strdup(path); + +    result = true; -    return G_BIN_CONTENT(result); +    return result;  } @@ -442,7 +405,7 @@ GBinContent *g_encaps_content_get_endpoint(const GEncapsContent *content)  /* ---------------------------------------------------------------------------------- */ -/*                        INTERACTIONS AVEC UN CONTENU BINAIRE                        */ +/*                       IMPLEMENTATION DES FONCTIONS DE CLASSE                       */  /* ---------------------------------------------------------------------------------- */ @@ -554,11 +517,11 @@ static char *g_encaps_content_describe(const GEncapsContent *content, bool full)  static void g_encaps_content_compute_checksum(GEncapsContent *content, GChecksum *checksum)  { -    GBinContentIface *iface;                /* Interface utilisée          */ +    GBinContentClass *class;                /* Classe de l'instance        */ -    iface = G_BIN_CONTENT_GET_IFACE(content->endpoint); +    class = G_BIN_CONTENT_GET_CLASS(content); -    iface->compute_checksum(content->endpoint, checksum); +    class->compute_checksum(content->endpoint, checksum);  } @@ -882,12 +845,6 @@ static bool g_encaps_content_read_leb128(const GEncapsContent *content, vmpa2t *  } - -/* ---------------------------------------------------------------------------------- */ -/*                      CONSERVATION ET RECHARGEMENT DES DONNEES                      */ -/* ---------------------------------------------------------------------------------- */ - -  /******************************************************************************  *                                                                             *  *  Paramètres  : content = élément GLib à constuire.                          * diff --git a/src/analysis/contents/file-int.h b/src/analysis/contents/file-int.h new file mode 100644 index 0000000..dc61bdc --- /dev/null +++ b/src/analysis/contents/file-int.h @@ -0,0 +1,58 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * file-int.h - prototypes internes pour le chargement de données binaires à partir d'un fichier + * + * Copyright (C) 2023 Cyrille Bagard + * + *  This file is part of Chrysalide. + * + *  Chrysalide is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 3 of the License, or + *  (at your option) any later version. + * + *  Chrysalide is distributed in the hope that it will be useful, + *  but WITHOUT ANY WARRANTY; without even the implied warranty of + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *  GNU General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with Chrysalide.  If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _ANALYSIS_CONTENTS_FILE_INT_H +#define _ANALYSIS_CONTENTS_FILE_INT_H + + +#include "file.h" + + +#include "memory-int.h" + + + +/* Contenu de données binaires issues d'un fichier (instance) */ +struct _GFileContent +{ +    GMemoryContent parent;                  /* A laisser en premier        */ + +    char *filename;                         /* Fichier chargé en mémoire   */ +    int fd;                                 /* Flux ouvert en lectureu     */ + +}; + +/* Contenu de données binaires issues d'un fichier (classe) */ +struct _GFileContentClass +{ +    GMemoryContentClass parent;             /* A laisser en premier        */ + +}; + + +/* Met en place un contenu d'un fichier donné. */ +bool g_file_content_create(GFileContent *, const char *); + + + +#endif  /* _ANALYSIS_CONTENTS_FILE_INT_H */ diff --git a/src/analysis/contents/file.c b/src/analysis/contents/file.c index 7497667..545d869 100644 --- a/src/analysis/contents/file.c +++ b/src/analysis/contents/file.c @@ -25,6 +25,7 @@  #include <fcntl.h> +#include <libgen.h>  #include <malloc.h>  #include <string.h>  #include <unistd.h> @@ -32,8 +33,7 @@  #include <sys/stat.h> -#include "memory-int.h" -#include "../content-int.h" +#include "file-int.h"  #include "../db/misc/rlestr.h"  #include "../storage/serialize-int.h"  #include "../../core/logs.h" @@ -43,33 +43,12 @@  /* -------------------------- ENSEMBLE DE DONNEES BINAIRES -------------------------- */ -/* Contenu de données binaires issues d'un fichier (instance) */ -struct _GFileContent -{ -    GMemoryContent parent;                  /* A laisser en premier        */ - -    char *filename;                         /* Fichier chargé en mémoire   */ -    int fd;                                 /* Flux ouvert en lectureu     */ - -}; - -/* Contenu de données binaires issues d'un fichier (classe) */ -struct _GFileContentClass -{ -    GMemoryContentClass parent;             /* A laisser en premier        */ - -}; - -  /* Initialise la classe des contenus de données binaires. */  static void g_file_content_class_init(GFileContentClass *);  /* Initialise une instance de contenu de données binaires. */  static void g_file_content_init(GFileContent *); -/* Procède à l'initialisation de l'interface de sérialisation. */ -static void g_file_content_serializable_init(GSerializableObjectInterface *); -  /* Supprime toutes les références externes. */  static void g_file_content_dispose(GFileContent *); @@ -77,9 +56,13 @@ static void g_file_content_dispose(GFileContent *);  static void g_file_content_finalize(GFileContent *); -/* -------------------- CONSERVATION ET RECHARGEMENT DES DONNEES -------------------- */ + +/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */ +/* Fournit le nom associé au contenu binaire. */ +static char *g_file_content_describe(const GFileContent *, bool); +  /* Charge un contenu depuis une mémoire tampon. */  static bool g_file_content_load(GFileContent *, GObjectStorage *, packed_buffer_t *); @@ -94,8 +77,7 @@ static bool g_file_content_store(const GFileContent *, GObjectStorage *, packed_  /* Indique le type défini par la GLib pour les contenus de données. */ -G_DEFINE_TYPE_WITH_CODE(GFileContent, g_file_content, G_TYPE_MEMORY_CONTENT, -                        G_IMPLEMENT_INTERFACE(G_TYPE_SERIALIZABLE_OBJECT, g_file_content_serializable_init)); +G_DEFINE_TYPE(GFileContent, g_file_content, G_TYPE_MEMORY_CONTENT);  /****************************************************************************** @@ -113,12 +95,20 @@ G_DEFINE_TYPE_WITH_CODE(GFileContent, g_file_content, G_TYPE_MEMORY_CONTENT,  static void g_file_content_class_init(GFileContentClass *klass)  {      GObjectClass *object;                   /* Autre version de la classe  */ +    GBinContentClass *content;              /* Version parente de la classe*/      object = G_OBJECT_CLASS(klass);      object->dispose = (GObjectFinalizeFunc/* ! */)g_file_content_dispose;      object->finalize = (GObjectFinalizeFunc)g_file_content_finalize; +    content = G_BIN_CONTENT_CLASS(klass); + +    content->describe = (describe_content_fc)g_file_content_describe; + +    content->load = (load_content_cb)g_file_content_load; +    content->store = (store_content_cb)g_file_content_store; +  } @@ -144,26 +134,6 @@ static void g_file_content_init(GFileContent *content)  /******************************************************************************  *                                                                             * -*  Paramètres  : iface = interface GLib à initialiser.                        * -*                                                                             * -*  Description : Procède à l'initialisation de l'interface de sérialisation.  * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_file_content_serializable_init(GSerializableObjectInterface *iface) -{ -    iface->load = (load_serializable_object_cb)g_file_content_load; -    iface->store = (store_serializable_object_cb)g_file_content_store; - -} - - -/****************************************************************************** -*                                                                             *  *  Paramètres  : content = instance d'objet GLib à traiter.                   *  *                                                                             *  *  Description : Supprime toutes les références externes.                     * @@ -213,6 +183,8 @@ static void g_file_content_finalize(GFileContent *content)  } + +  /******************************************************************************  *                                                                             *  *  Paramètres  : filename = chemin d'accès au fichier à charger.              * @@ -227,13 +199,42 @@ static void g_file_content_finalize(GFileContent *content)  GBinContent *g_file_content_new(const char *filename)  { -    GFileContent *result;                   /* Structure à retourner       */ +    GBinContent *result;                    /* Structure à retourner       */ + +    result = g_object_new(G_TYPE_FILE_CONTENT, NULL); + +    if (!g_file_content_create(G_FILE_CONTENT(result), filename)) +        g_clear_object(&result); + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : content  = instance à initialiser pleinement.                * +*                filename = chemin d'accès au fichier à charger.              * +*                                                                             * +*  Description : Met en place un contenu d'un fichier donné.                  * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +bool g_file_content_create(GFileContent *content, const char *filename) +{ +    bool result;                            /* Bilan à retourner           */      int fd;                                 /* Descripteur du fichier      */      struct stat info;                       /* Informations sur le fichier */      int ret;                                /* Bilan d'un appel            */ -    void *content;                          /* Contenu brut du fichier     */ +    void *data;                             /* Contenu brut du fichier     */      GMemoryContent *base;                   /* Structure parente           */ +    result = false; +      /* Récupération des données */      fd = open(filename, O_RDONLY); @@ -251,8 +252,8 @@ GBinContent *g_file_content_new(const char *filename)          goto file_error;      } -    content = mmap(NULL, info.st_size, PROT_READ, MAP_PRIVATE, fd, 0); -    if (content == MAP_FAILED) +    data = mmap(NULL, info.st_size, PROT_READ, MAP_PRIVATE, fd, 0); +    if (data == MAP_FAILED)      {          close(fd);          LOG_ERROR_N("mmap"); @@ -261,20 +262,18 @@ GBinContent *g_file_content_new(const char *filename)      /* Constitution du contenu officiel */ -    result = g_object_new(G_TYPE_FILE_CONTENT, NULL); - -    result->filename = strdup(filename); +    content->filename = strdup(filename); -    base = G_MEMORY_CONTENT(result); +    base = G_MEMORY_CONTENT(content); -    base->data = content; +    base->data = data;      base->length = info.st_size; -    return G_BIN_CONTENT(result); +    result = true;   file_error: -    return NULL; +    return result;  } @@ -304,12 +303,51 @@ const char *g_file_content_get_filename(const GFileContent *content)  /* ---------------------------------------------------------------------------------- */ -/*                      CONSERVATION ET RECHARGEMENT DES DONNEES                      */ +/*                       IMPLEMENTATION DES FONCTIONS DE CLASSE                       */  /* ---------------------------------------------------------------------------------- */  /******************************************************************************  *                                                                             * +*  Paramètres  : content = contenu binaire à consulter.                       * +*                full    = précise s'il s'agit d'une version longue ou non.   * +*                                                                             * +*  Description : Fournit le nom associé au contenu binaire.                   * +*                                                                             * +*  Retour      : Nom de fichier avec chemin absolu au besoin.                 * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static char *g_file_content_describe(const GFileContent *content, bool full) +{ +    char *result;                           /* Description à retourner     */ +    char *tmp;                              /* Copie modifiable            */ +    char *base;                             /* Description à recopier      */ + +    if (full) +        result = strdup(content->filename); + +    else +    { +        tmp = strdup(content->filename); + +        base = basename(tmp); + +        result = strdup(base); + +        free(tmp); + +    } + +    return result; + +} + + +/****************************************************************************** +*                                                                             *  *  Paramètres  : content = élément GLib à constuire.                          *  *                storage = conservateur de données à manipuler ou NULL.       *  *                pbuf    = zone tampon à lire.                                * diff --git a/src/analysis/contents/memory-int.h b/src/analysis/contents/memory-int.h index 749e984..d3012c7 100644 --- a/src/analysis/contents/memory-int.h +++ b/src/analysis/contents/memory-int.h @@ -28,11 +28,14 @@  #include "memory.h" +#include "../content-int.h" + +  /* Contenu de données binaires résidant en mémoire (instance) */  struct _GMemoryContent  { -    GObject parent;                         /* A laisser en premier        */ +    GBinContent parent;                     /* A laisser en premier        */      GContentAttributes *attribs;            /* Attributs liés au contenu   */ @@ -48,10 +51,14 @@ struct _GMemoryContent  /* Contenu de données binaires résidant en mémoire (classe) */  struct _GMemoryContentClass  { -    GObjectClass parent;                    /* A laisser en premier        */ +    GBinContentClass parent;                /* A laisser en premier        */  }; +/* Met en place un contenu de données brutes depuis la mémoire. */ +bool g_memory_content_create(GMemoryContent *, const bin_t *, phys_t); + +  #endif  /* _ANALYSIS_CONTENTS_MEMORY_INT_H */ diff --git a/src/analysis/contents/memory.c b/src/analysis/contents/memory.c index f80a01a..f8ff863 100644 --- a/src/analysis/contents/memory.c +++ b/src/analysis/contents/memory.c @@ -51,12 +51,6 @@ static void g_memory_content_class_init(GMemoryContentClass *);  /* Initialise une instance de contenu de données en mémoire. */  static void g_memory_content_init(GMemoryContent *); -/* Procède à l'initialisation de l'interface de lecture. */ -static void g_memory_content_interface_init(GBinContentInterface *); - -/* Procède à l'initialisation de l'interface de sérialisation. */ -static void g_memory_content_serializable_init(GSerializableObjectInterface *); -  /* Supprime toutes les références externes. */  static void g_memory_content_dispose(GMemoryContent *); @@ -65,7 +59,7 @@ static void g_memory_content_finalize(GMemoryContent *); -/* ---------------------- INTERACTIONS AVEC UN CONTENU BINAIRE ---------------------- */ +/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */  /* Associe un ensemble d'attributs au contenu binaire. */ @@ -122,11 +116,6 @@ static bool g_memory_content_read_uleb128(const GMemoryContent *, vmpa2t *, uleb  /* Lit un nombre signé encodé au format LEB128. */  static bool g_memory_content_read_leb128(const GMemoryContent *, vmpa2t *, leb128_t *); - - -/* -------------------- CONSERVATION ET RECHARGEMENT DES DONNEES -------------------- */ - -  /* Charge un contenu depuis une mémoire tampon. */  static bool g_memory_content_load(GMemoryContent *, GObjectStorage *, packed_buffer_t *); @@ -141,9 +130,7 @@ static bool g_memory_content_store(const GMemoryContent *, GObjectStorage *, pac  /* Indique le type défini par la GLib pour les contenus de données en mémoire. */ -G_DEFINE_TYPE_WITH_CODE(GMemoryContent, g_memory_content, G_TYPE_OBJECT, -                        G_IMPLEMENT_INTERFACE(G_TYPE_BIN_CONTENT, g_memory_content_interface_init) -                        G_IMPLEMENT_INTERFACE(G_TYPE_SERIALIZABLE_OBJECT, g_memory_content_serializable_init)); +G_DEFINE_TYPE(GMemoryContent, g_memory_content, G_TYPE_BIN_CONTENT);  /****************************************************************************** @@ -161,12 +148,45 @@ G_DEFINE_TYPE_WITH_CODE(GMemoryContent, g_memory_content, G_TYPE_OBJECT,  static void g_memory_content_class_init(GMemoryContentClass *klass)  {      GObjectClass *object;                   /* Autre version de la classe  */ +    GBinContentClass *content;              /* Version parente de la classe*/      object = G_OBJECT_CLASS(klass);      object->dispose = (GObjectFinalizeFunc/* ! */)g_memory_content_dispose;      object->finalize = (GObjectFinalizeFunc)g_memory_content_finalize; +    content = G_BIN_CONTENT_CLASS(klass); + +    content->set_attribs = (set_content_attributes)g_memory_content_set_attributes; +    content->get_attribs = (get_content_attributes)g_memory_content_get_attributes; + +    content->get_root = (get_content_root_fc)g_memory_content_get_root; + +    content->describe = (describe_content_fc)g_memory_content_describe; + +    content->compute_checksum = (compute_checksum_fc)g_memory_content_compute_checksum; + +    content->compute_size = (compute_size_fc)g_memory_content_compute_size; +    content->compute_start_pos = (compute_start_pos_fc)g_memory_content_compute_start_pos; +    content->compute_end_pos = (compute_end_pos_fc)g_memory_content_compute_end_pos; + +    content->seek = (seek_fc)g_memory_content_seek; + +    content->get_raw_access = (get_raw_access_fc)g_memory_content_get_raw_access; + +    content->read_raw = (read_raw_fc)g_memory_content_read_raw; +    content->read_u4 = (read_u4_fc)g_memory_content_read_u4; +    content->read_u8 = (read_u8_fc)g_memory_content_read_u8; +    content->read_u16 = (read_u16_fc)g_memory_content_read_u16; +    content->read_u32 = (read_u32_fc)g_memory_content_read_u32; +    content->read_u64 = (read_u64_fc)g_memory_content_read_u64; + +    content->read_uleb128 = (read_uleb128_fc)g_memory_content_read_uleb128; +    content->read_leb128 = (read_leb128_fc)g_memory_content_read_leb128; + +    content->load = (load_content_cb)g_memory_content_load; +    content->store = (store_content_cb)g_memory_content_store; +  } @@ -206,70 +226,6 @@ static void g_memory_content_init(GMemoryContent *content)  /******************************************************************************  *                                                                             * -*  Paramètres  : iface = interface GLib à initialiser.                        * -*                                                                             * -*  Description : Procède à l'initialisation de l'interface de lecture.        * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_memory_content_interface_init(GBinContentInterface *iface) -{ -    iface->set_attribs = (set_content_attributes)g_memory_content_set_attributes; -    iface->get_attribs = (get_content_attributes)g_memory_content_get_attributes; - -    iface->get_root = (get_content_root_fc)g_memory_content_get_root; - -    iface->describe = (describe_content_fc)g_memory_content_describe; - -    iface->compute_checksum = (compute_checksum_fc)g_memory_content_compute_checksum; - -    iface->compute_size = (compute_size_fc)g_memory_content_compute_size; -    iface->compute_start_pos = (compute_start_pos_fc)g_memory_content_compute_start_pos; -    iface->compute_end_pos = (compute_end_pos_fc)g_memory_content_compute_end_pos; - -    iface->seek = (seek_fc)g_memory_content_seek; - -    iface->get_raw_access = (get_raw_access_fc)g_memory_content_get_raw_access; - -    iface->read_raw = (read_raw_fc)g_memory_content_read_raw; -    iface->read_u4 = (read_u4_fc)g_memory_content_read_u4; -    iface->read_u8 = (read_u8_fc)g_memory_content_read_u8; -    iface->read_u16 = (read_u16_fc)g_memory_content_read_u16; -    iface->read_u32 = (read_u32_fc)g_memory_content_read_u32; -    iface->read_u64 = (read_u64_fc)g_memory_content_read_u64; - -    iface->read_uleb128 = (read_uleb128_fc)g_memory_content_read_uleb128; -    iface->read_leb128 = (read_leb128_fc)g_memory_content_read_leb128; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : iface = interface GLib à initialiser.                        * -*                                                                             * -*  Description : Procède à l'initialisation de l'interface de sérialisation.  * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_memory_content_serializable_init(GSerializableObjectInterface *iface) -{ -    iface->load = (load_serializable_object_cb)g_memory_content_load; -    iface->store = (store_serializable_object_cb)g_memory_content_store; - -} - - -/****************************************************************************** -*                                                                             *  *  Paramètres  : content = instance d'objet GLib à traiter.                   *  *                                                                             *  *  Description : Supprime toutes les références externes.                     * @@ -335,32 +291,62 @@ static void g_memory_content_finalize(GMemoryContent *content)  GBinContent *g_memory_content_new(const bin_t *data, phys_t size)  { -    GMemoryContent *result;                 /* Structure à retourner       */ +    GBinContent *result;                    /* Structure à retourner       */ + +    result = g_object_new(G_TYPE_MEMORY_CONTENT, NULL); + +    if (!g_memory_content_create(G_MEMORY_CONTENT(result), data, size)) +        g_clear_object(&result); + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : content = instance à initialiser pleinement.                 * +*                data    = données du contenu volatile.                       * +*                size    = quantité de ces données.                           * +*                                                                             * +*  Description : Met en place un contenu de données brutes depuis la mémoire. * +*                                                                             * +*  Retour      : Bilan de l'opération.                                        * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +bool g_memory_content_create(GMemoryContent *content, const bin_t *data, phys_t size) +{ +    bool result;                            /* Bilan à retourner           */      bin_t *allocated;                       /* Zone de réception           */      allocated = malloc(size);      if (allocated == NULL)      {          LOG_ERROR_N("malloc"); -        return NULL; +        goto exit;      }      memcpy(allocated, data, size); -    result = g_object_new(G_TYPE_MEMORY_CONTENT, NULL); +    content->data = allocated; +    content->length = size; +    content->allocated = true; -    result->data = allocated; -    result->length = size; -    result->allocated = true; +    result = true; -    return G_BIN_CONTENT(result); + exit: + +    return result;  }  /* ---------------------------------------------------------------------------------- */ -/*                        INTERACTIONS AVEC UN CONTENU BINAIRE                        */ +/*                       IMPLEMENTATION DES FONCTIONS DE CLASSE                       */  /* ---------------------------------------------------------------------------------- */ @@ -710,15 +696,12 @@ static bool g_memory_content_read_u8(const GMemoryContent *content, vmpa2t *addr  {      bool result;                            /* Bilan de lecture à renvoyer */      phys_t pos;                             /* Tête de lecture courante    */ -    phys_t length;                          /* Taille de la surface dispo. */      pos = get_phy_addr(addr);      if (pos == VMPA_NO_PHYSICAL)          return false; -    length = length; -      result = read_u8(val, content->data, &pos, content->length);      if (result) @@ -902,12 +885,6 @@ static bool g_memory_content_read_leb128(const GMemoryContent *content, vmpa2t *  } - -/* ---------------------------------------------------------------------------------- */ -/*                      CONSERVATION ET RECHARGEMENT DES DONNEES                      */ -/* ---------------------------------------------------------------------------------- */ - -  /******************************************************************************  *                                                                             *  *  Paramètres  : content = élément GLib à constuire.                          * diff --git a/src/analysis/contents/restricted-int.h b/src/analysis/contents/restricted-int.h new file mode 100644 index 0000000..ab86359 --- /dev/null +++ b/src/analysis/contents/restricted-int.h @@ -0,0 +1,59 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * restricted-int.h - prototypes internes pour le chargement de données binaires à partir d'un contenu restreint + * + * Copyright (C) 2023 Cyrille Bagard + * + *  This file is part of Chrysalide. + * + *  Chrysalide is free software; you can redistribute it and/or modify + *  it under the terms of the GNU General Public License as published by + *  the Free Software Foundation; either version 3 of the License, or + *  (at your option) any later version. + * + *  Chrysalide is distributed in the hope that it will be useful, + *  but WITHOUT ANY WARRANTY; without even the implied warranty of + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *  GNU General Public License for more details. + * + *  You should have received a copy of the GNU General Public License + *  along with Chrysalide.  If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _ANALYSIS_CONTENTS_RESTRICTED_INT_H +#define _ANALYSIS_CONTENTS_RESTRICTED_INT_H + + +#include "restricted.h" + + +#include "../content-int.h" + + + +/* Contenu de données binaires issues d'un contenu restreint (instance) */ +struct _GRestrictedContent +{ +    GBinContent parent;                     /* A laisser en premier        */ + +    GBinContent *internal;                  /* Contenu de sous-traitance   */ + +    mrange_t range;                         /* Restriction de couverture   */ + +}; + +/* Contenu de données binaires issues d'un contenu restreint (classe) */ +struct _GRestrictedContentClass +{ +    GBinContentClass parent;                /* A laisser en premier        */ + +}; + + +/* Met en place un contenu restreint de données brutes. */ +bool g_restricted_content_create(GRestrictedContent *, GBinContent *, const mrange_t *); + + + +#endif  /* _ANALYSIS_CONTENTS_RESTRICTED_INT_H */ diff --git a/src/analysis/contents/restricted.c b/src/analysis/contents/restricted.c index 55bc83f..9b4e1c8 100644 --- a/src/analysis/contents/restricted.c +++ b/src/analysis/contents/restricted.c @@ -28,7 +28,7 @@  #include <string.h> -#include "../content-int.h" +#include "restricted-int.h"  #include "../db/misc/rlestr.h"  #include "../storage/serialize-int.h"  #include "../../common/extstr.h" @@ -39,37 +39,12 @@  /* -------------------------- ENSEMBLE DE DONNEES BINAIRES -------------------------- */ -/* Contenu de données binaires issues d'un contenu restreint (instance) */ -struct _GRestrictedContent -{ -    GObject parent;                         /* A laisser en premier        */ - -    GBinContent *internal;                  /* Contenu de sous-traitance   */ - -    mrange_t range;                         /* Restriction de couverture   */ - -}; - -/* Contenu de données binaires issues d'un contenu restreint (classe) */ -struct _GRestrictedContentClass -{ -    GObjectClass parent;                    /* A laisser en premier        */ - -}; - -  /* Initialise la classe des contenus de données binaires. */  static void g_restricted_content_class_init(GRestrictedContentClass *);  /* Initialise une instance de contenu de données binaires. */  static void g_restricted_content_init(GRestrictedContent *); -/* Procède à l'initialisation de l'interface de lecture. */ -static void g_restricted_content_interface_init(GBinContentInterface *); - -/* Procède à l'initialisation de l'interface de sérialisation. */ -static void g_restricted_content_serializable_init(GSerializableObjectInterface *); -  /* Supprime toutes les références externes. */  static void g_restricted_content_dispose(GRestrictedContent *); @@ -78,7 +53,7 @@ static void g_restricted_content_finalize(GRestrictedContent *); -/* ---------------------- INTERACTIONS AVEC UN CONTENU BINAIRE ---------------------- */ +/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */  /* Associe un ensemble d'attributs au contenu binaire. */ @@ -135,11 +110,6 @@ static bool g_restricted_content_read_uleb128(const GRestrictedContent *, vmpa2t  /* Lit un nombre signé encodé au format LEB128. */  static bool g_restricted_content_read_leb128(const GRestrictedContent *, vmpa2t *, leb128_t *); - - -/* -------------------- CONSERVATION ET RECHARGEMENT DES DONNEES -------------------- */ - -  /* Charge un contenu depuis une mémoire tampon. */  static bool g_restricted_content_load(GRestrictedContent *, GObjectStorage *, packed_buffer_t *); @@ -154,9 +124,7 @@ static bool g_restricted_content_store(const GRestrictedContent *, GObjectStorag  /* Indique le type défini par la GLib pour les contenus de données. */ -G_DEFINE_TYPE_WITH_CODE(GRestrictedContent, g_restricted_content, G_TYPE_OBJECT, -                        G_IMPLEMENT_INTERFACE(G_TYPE_BIN_CONTENT, g_restricted_content_interface_init) -                        G_IMPLEMENT_INTERFACE(G_TYPE_SERIALIZABLE_OBJECT, g_restricted_content_serializable_init)); +G_DEFINE_TYPE(GRestrictedContent, g_restricted_content, G_TYPE_BIN_CONTENT);  /****************************************************************************** @@ -174,88 +142,53 @@ G_DEFINE_TYPE_WITH_CODE(GRestrictedContent, g_restricted_content, G_TYPE_OBJECT,  static void g_restricted_content_class_init(GRestrictedContentClass *klass)  {      GObjectClass *object;                   /* Autre version de la classe  */ +    GBinContentClass *content;              /* Version parente de la classe*/      object = G_OBJECT_CLASS(klass);      object->dispose = (GObjectFinalizeFunc/* ! */)g_restricted_content_dispose;      object->finalize = (GObjectFinalizeFunc)g_restricted_content_finalize; -} +    content = G_BIN_CONTENT_CLASS(klass); +    content->set_attribs = (set_content_attributes)g_restricted_content_set_attributes; +    content->get_attribs = (get_content_attributes)g_restricted_content_get_attributes; -/****************************************************************************** -*                                                                             * -*  Paramètres  : content = instance à initialiser.                            * -*                                                                             * -*  Description : Initialise une instance de contenu de données binaires.      * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ +    content->get_root = (get_content_root_fc)g_restricted_content_get_root; -static void g_restricted_content_init(GRestrictedContent *content) -{ -    vmpa2t dummy;                           /* Localisation nulle          */ +    content->describe = (describe_content_fc)g_restricted_content_describe; -    content->internal = NULL; +    content->compute_checksum = (compute_checksum_fc)g_restricted_content_compute_checksum; -    init_vmpa(&dummy, VMPA_NO_PHYSICAL, VMPA_NO_VIRTUAL); -    init_mrange(&content->range, &dummy, 0); +    content->compute_size = (compute_size_fc)g_restricted_content_compute_size; +    content->compute_start_pos = (compute_start_pos_fc)g_restricted_content_compute_start_pos; +    content->compute_end_pos = (compute_end_pos_fc)g_restricted_content_compute_end_pos; -} +    content->seek = (seek_fc)g_restricted_content_seek; +    content->get_raw_access = (get_raw_access_fc)g_restricted_content_get_raw_access; -/****************************************************************************** -*                                                                             * -*  Paramètres  : iface = interface GLib à initialiser.                        * -*                                                                             * -*  Description : Procède à l'initialisation de l'interface de lecture.        * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_restricted_content_interface_init(GBinContentInterface *iface) -{ -    iface->set_attribs = (set_content_attributes)g_restricted_content_set_attributes; -    iface->get_attribs = (get_content_attributes)g_restricted_content_get_attributes; - -    iface->get_root = (get_content_root_fc)g_restricted_content_get_root; +    content->read_raw = (read_raw_fc)g_restricted_content_read_raw; +    content->read_u4 = (read_u4_fc)g_restricted_content_read_u4; +    content->read_u8 = (read_u8_fc)g_restricted_content_read_u8; +    content->read_u16 = (read_u16_fc)g_restricted_content_read_u16; +    content->read_u32 = (read_u32_fc)g_restricted_content_read_u32; +    content->read_u64 = (read_u64_fc)g_restricted_content_read_u64; -    iface->describe = (describe_content_fc)g_restricted_content_describe; +    content->read_uleb128 = (read_uleb128_fc)g_restricted_content_read_uleb128; +    content->read_leb128 = (read_leb128_fc)g_restricted_content_read_leb128; -    iface->compute_checksum = (compute_checksum_fc)g_restricted_content_compute_checksum; - -    iface->compute_size = (compute_size_fc)g_restricted_content_compute_size; -    iface->compute_start_pos = (compute_start_pos_fc)g_restricted_content_compute_start_pos; -    iface->compute_end_pos = (compute_end_pos_fc)g_restricted_content_compute_end_pos; - -    iface->seek = (seek_fc)g_restricted_content_seek; - -    iface->get_raw_access = (get_raw_access_fc)g_restricted_content_get_raw_access; - -    iface->read_raw = (read_raw_fc)g_restricted_content_read_raw; -    iface->read_u4 = (read_u4_fc)g_restricted_content_read_u4; -    iface->read_u8 = (read_u8_fc)g_restricted_content_read_u8; -    iface->read_u16 = (read_u16_fc)g_restricted_content_read_u16; -    iface->read_u32 = (read_u32_fc)g_restricted_content_read_u32; -    iface->read_u64 = (read_u64_fc)g_restricted_content_read_u64; - -    iface->read_uleb128 = (read_uleb128_fc)g_restricted_content_read_uleb128; -    iface->read_leb128 = (read_leb128_fc)g_restricted_content_read_leb128; +    content->load = (load_content_cb)g_restricted_content_load; +    content->store = (store_content_cb)g_restricted_content_store;  }  /******************************************************************************  *                                                                             * -*  Paramètres  : iface = interface GLib à initialiser.                        * +*  Paramètres  : content = instance à initialiser.                            *  *                                                                             * -*  Description : Procède à l'initialisation de l'interface de sérialisation.  * +*  Description : Initialise une instance de contenu de données binaires.      *  *                                                                             *  *  Retour      : -                                                            *  *                                                                             * @@ -263,10 +196,14 @@ static void g_restricted_content_interface_init(GBinContentInterface *iface)  *                                                                             *  ******************************************************************************/ -static void g_restricted_content_serializable_init(GSerializableObjectInterface *iface) +static void g_restricted_content_init(GRestrictedContent *content)  { -    iface->load = (load_serializable_object_cb)g_restricted_content_load; -    iface->store = (store_serializable_object_cb)g_restricted_content_store; +    vmpa2t dummy;                           /* Localisation nulle          */ + +    content->internal = NULL; + +    init_vmpa(&dummy, VMPA_NO_PHYSICAL, VMPA_NO_VIRTUAL); +    init_mrange(&content->range, &dummy, 0);  } @@ -313,8 +250,8 @@ static void g_restricted_content_finalize(GRestrictedContent *content)  /******************************************************************************  *                                                                             * -*  Paramètres  : content = contenu binaire où puiser les données à fournir.   * -*                range   = espace de restrictions pour les accès.             * +*  Paramètres  : internal = contenu binaire où puiser les données à fournir.  * +*                range    = espace de restrictions pour les accès.            *  *                                                                             *  *  Description : Charge en mémoire le contenu d'un contenu restreint.         *  *                                                                             * @@ -324,47 +261,47 @@ static void g_restricted_content_finalize(GRestrictedContent *content)  *                                                                             *  ******************************************************************************/ -GBinContent *g_restricted_content_new(GBinContent *content, const mrange_t *range) +GBinContent *g_restricted_content_new(GBinContent *internal, const mrange_t *range)  { -    GRestrictedContent *result;              /* Structure à retourner      */ +    GBinContent *result;                    /* Structure à retourner       */      result = g_object_new(G_TYPE_RESTRICTED_CONTENT, NULL); -    result->internal = content; -    g_object_ref(G_OBJECT(result->internal)); +    if (!g_restricted_content_create(G_RESTRICTED_CONTENT(result), internal, range)) +        g_clear_object(&result); -    copy_mrange(&result->range, range); - -    return G_BIN_CONTENT(result); +    return result;  }  /******************************************************************************  *                                                                             * -*  Paramètres  : content = contenu binaire où puiser les données à fournir.   * -*                range   = espace de restrictions pour les accès.             * +*  Paramètres  : content  = instance à initialiser pleinement.                * +*                base     = contenu binaire d'où réaliser une extraction.     * +*                path     = chemin vers le contenu finalement ciblé.          * +*                endpoint = contenu final rendu accessible.                   *  *                                                                             * -*  Description : Charge en mémoire le contenu d'un contenu restreint.         * +*  Description : Met en place un contenu restreint de données brutes.         *  *                                                                             * -*  Retour      : Représentation de contenu à manipuler ou NULL en cas d'échec.* +*  Retour      : Bilan de l'opération.                                        *  *                                                                             *  *  Remarques   : -                                                            *  *                                                                             *  ******************************************************************************/ -GBinContent *g_restricted_content_new_ro(const GBinContent *content, const mrange_t *range) +bool g_restricted_content_create(GRestrictedContent *content, GBinContent *internal, const mrange_t *range)  { -    GRestrictedContent *result;              /* Structure à retourner      */ +    bool result;                            /* Bilan à retourner           */ -    result = g_object_new(G_TYPE_RESTRICTED_CONTENT, NULL); +    content->internal = internal; +    g_object_ref(G_OBJECT(content->internal)); -    result->internal = (GBinContent *)content; -    g_object_ref(G_OBJECT(result->internal)); +    copy_mrange(&content->range, range); -    copy_mrange(&result->range, range); +    result = true; -    return G_BIN_CONTENT(result); +    return result;  } @@ -1027,12 +964,6 @@ static bool g_restricted_content_read_leb128(const GRestrictedContent *content,  } - -/* ---------------------------------------------------------------------------------- */ -/*                      CONSERVATION ET RECHARGEMENT DES DONNEES                      */ -/* ---------------------------------------------------------------------------------- */ - -  /******************************************************************************  *                                                                             *  *  Paramètres  : content = élément GLib à constuire.                          * diff --git a/src/analysis/contents/restricted.h b/src/analysis/contents/restricted.h index 402282a..1cea390 100644 --- a/src/analysis/contents/restricted.h +++ b/src/analysis/contents/restricted.h @@ -53,9 +53,6 @@ GType g_restricted_content_get_type(void);  /* Charge en mémoire le contenu d'un contenu restreint. */  GBinContent *g_restricted_content_new(GBinContent *, const mrange_t *); -/* Charge en mémoire le contenu d'un contenu restreint. */ -GBinContent *g_restricted_content_new_ro(const GBinContent *, const mrange_t *); -  /* Indique l'espace de restriction appliqué à un contenu. */  void g_restricted_content_get_range(const GRestrictedContent *, mrange_t *); diff --git a/src/analysis/type.c b/src/analysis/type.c index f05b9a8..9ed5f3f 100644 --- a/src/analysis/type.c +++ b/src/analysis/type.c @@ -43,7 +43,7 @@ static void g_data_type_class_init(GDataTypeClass *);  static void g_data_type_init(GDataType *);  /* Procède à l'initialisation de l'interface de sérialisation. */ -static void g_serializable_object_interface_init(GSerializableObjectIface *); +static void g_data_type_serializable_interface_init(GSerializableObjectIface *);  /* Supprime toutes les références externes. */  static void g_data_type_dispose(GDataType *); @@ -67,7 +67,7 @@ static bool g_data_type_store(const GDataType *, GObjectStorage *, packed_buffer  /* Indique le type défini pour un type quelconque. */  G_DEFINE_TYPE_WITH_CODE(GDataType, g_data_type, G_TYPE_OBJECT, -                        G_IMPLEMENT_INTERFACE(G_TYPE_SERIALIZABLE_OBJECT, g_serializable_object_interface_init)); +                        G_IMPLEMENT_INTERFACE(G_TYPE_SERIALIZABLE_OBJECT, g_data_type_serializable_interface_init));  /****************************************************************************** @@ -136,7 +136,7 @@ static void g_data_type_init(GDataType *type)  *                                                                             *  ******************************************************************************/ -static void g_serializable_object_interface_init(GSerializableObjectIface *iface) +static void g_data_type_serializable_interface_init(GSerializableObjectIface *iface)  {      iface->load = (load_serializable_object_cb)g_data_type_load;      iface->store = (store_serializable_object_cb)g_data_type_store;  | 
