diff options
Diffstat (limited to 'plugins/apihashing/custom/add1505-shl5.c')
| -rw-r--r-- | plugins/apihashing/custom/add1505-shl5.c | 325 | 
1 files changed, 325 insertions, 0 deletions
| diff --git a/plugins/apihashing/custom/add1505-shl5.c b/plugins/apihashing/custom/add1505-shl5.c new file mode 100644 index 0000000..db96cf1 --- /dev/null +++ b/plugins/apihashing/custom/add1505-shl5.c @@ -0,0 +1,325 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * add1505-shl5.c - transormation en empreinte d'API add1505-shl5 + * + * 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 Foobar.  If not, see <http://www.gnu.org/licenses/>. + */ + + +#include "add1505-shl5.h" + + +#include <malloc.h> + + +#include <analysis/scan/patterns/modifier-int.h> + + + + +/* ----------------------- RECHERCHE D'UN MOTIF DE TEXTE BRUT ----------------------- */ + + +/* Initialise la classe des transmissions en empreintes add1505-shl5. */ +static void g_scan_add1505_shl5_modifier_class_init(GScanAdd1505Shl5ModifierClass *); + +/* Initialise une instance de transmission en empreinte add1505-shl5. */ +static void g_scan_add1505_shl5_modifier_init(GScanAdd1505Shl5Modifier *); + +/* Supprime toutes les références externes. */ +static void g_scan_add1505_shl5_modifier_dispose(GScanAdd1505Shl5Modifier *); + +/* Procède à la libération totale de la mémoire. */ +static void g_scan_add1505_shl5_modifier_finalize(GScanAdd1505Shl5Modifier *); + + + +/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */ + + +/* Fournit le nom d'appel d'un modificateur pour motif. */ +static char *g_scan_add1505_shl5_modifier_get_name(const GScanAdd1505Shl5Modifier *); + +/* Calcule l'empreinte add1505-shl5 d'un motif de recherche. */ +static uint32_t compute_add1505_shl5_hash32(const sized_binary_t *); + +/* Transforme une séquence d'octets pour motif de recherche. */ +static bool g_scan_add1505_shl5_modifier_transform(const GScanAdd1505Shl5Modifier *, const sized_binary_t *, size_t, sized_binary_t **, size_t *); + +/* Retrouve l'origine d'une correspondance à partir d'un indice. */ +static char *g_scan_add1505_shl5_modifier_get_path(const GScanAdd1505Shl5Modifier *, size_t *); + + + +/* ---------------------------------------------------------------------------------- */ +/*                         RECHERCHE D'UN MOTIF DE TEXTE BRUT                         */ +/* ---------------------------------------------------------------------------------- */ + + +/* Indique le type défini pour une transormation en empreinte add1505-shl5. */ +G_DEFINE_TYPE(GScanAdd1505Shl5Modifier, g_scan_add1505_shl5_modifier, G_TYPE_API_HASH_MODIFIER); + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : klass = classe à initialiser.                                * +*                                                                             * +*  Description : Initialise la classe des transmissions en empreintes add1505-shl5.  * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_scan_add1505_shl5_modifier_class_init(GScanAdd1505Shl5ModifierClass *klass) +{ +    GObjectClass *object;                   /* Autre version de la classe  */ +    GScanTokenModifierClass *modifier;      /* Version de classe parente   */ + +    object = G_OBJECT_CLASS(klass); + +    object->dispose = (GObjectFinalizeFunc/* ! */)g_scan_add1505_shl5_modifier_dispose; +    object->finalize = (GObjectFinalizeFunc)g_scan_add1505_shl5_modifier_finalize; + +    modifier = G_SCAN_TOKEN_MODIFIER_CLASS(klass); + +    modifier->get_name = (get_scan_modifier_name_fc)g_scan_add1505_shl5_modifier_get_name; + +    modifier->transform = (transform_scan_token_fc)g_scan_add1505_shl5_modifier_transform; +    modifier->get_path = (get_modifier_path)g_scan_add1505_shl5_modifier_get_path; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : modifier = instance à initialiser.                           * +*                                                                             * +*  Description : Initialise une instance de transmission en empreinte add1505-shl5.  * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_scan_add1505_shl5_modifier_init(GScanAdd1505Shl5Modifier *modifier) +{ + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : modifier = instance d'objet GLib à traiter.                  * +*                                                                             * +*  Description : Supprime toutes les références externes.                     * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_scan_add1505_shl5_modifier_dispose(GScanAdd1505Shl5Modifier *modifier) +{ +    G_OBJECT_CLASS(g_scan_add1505_shl5_modifier_parent_class)->dispose(G_OBJECT(modifier)); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : modifier = instance d'objet GLib à traiter.                  * +*                                                                             * +*  Description : Procède à la libération totale de la mémoire.                * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_scan_add1505_shl5_modifier_finalize(GScanAdd1505Shl5Modifier *modifier) +{ +    G_OBJECT_CLASS(g_scan_add1505_shl5_modifier_parent_class)->finalize(G_OBJECT(modifier)); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : -                                                            * +*                                                                             * +*  Description : Construit un modificateur livrant des empreintes add1505-shl5.      * +*                                                                             * +*  Retour      : Mécanisme mis en place.                                      * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GScanTokenModifier *g_scan_add1505_shl5_modifier_new(void) +{ +    GScanTokenModifier *result;                    /* Structure à retourner       */ + +    result = g_object_new(G_TYPE_SCAN_ADD1505_SHL5_MODIFIER, NULL); + +    return result; + +} + + + +/* ---------------------------------------------------------------------------------- */ +/*                       IMPLEMENTATION DES FONCTIONS DE CLASSE                       */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : modifier = modificateur à consulter.                         * +*                                                                             * +*  Description : Fournit le nom d'appel d'un modificateur pour motif.         * +*                                                                             * +*  Retour      : Désignation humaine.                                         * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static char *g_scan_add1505_shl5_modifier_get_name(const GScanAdd1505Shl5Modifier *modifier) +{ +    char *result;                           /* Désignation à retourner     */ + +    result = strdup("add1505-shl5"); + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : src = séquence d'octets à traiter.                           * +*                                                                             * +*  Description : Calcule l'empreinte add1505-shl5 d'un motif de recherche.    * +*                                                                             * +*  Retour      : Valeur entière de l'empreinte déterminée.                    * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static uint32_t compute_add1505_shl5_hash32(const sized_binary_t *src) +{ +    uint32_t result;                        /* Valeur à retourner          */ +    size_t i;                               /* Boucle de parcours          */ + +    result = 0x1505; + +    for (i = 0; i < src->len; i++) +    { +        result += (result << 5); +        result += src->data[i]; +    } + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : modifier = modificateur à solliciter.                        * +*                src      = séquences d'octets à traiter.                     * +*                scount   = quantité de ces séquences.                        * +*                dest     = nouvelle(s) séquence(s) d'octets obtenue(s) [OUT] * +*                dcount   = quantité de ces séquences.                        * +*                                                                             * +*  Description : Transforme une séquence d'octets pour motif de recherche.    * +*                                                                             * +*  Retour      : Bilan de l'opération : succès ou échec.                      * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static bool g_scan_add1505_shl5_modifier_transform(const GScanAdd1505Shl5Modifier *modifier, const sized_binary_t *src, size_t scount, sized_binary_t **dest, size_t *dcount) +{ +    bool result;                            /* Bilan d'opération à renvoyer*/ +    sized_binary_t *binary;                 /* Raccourci vers le stockage  */ +    size_t i;                               /* Boucle de parcours #1       */ +    const sized_binary_t *_src;             /* Source courante             */ +    uint32_t hash;                          /* Valeur d'empreinte calculée */ + +    result = true; + +    *dcount = scount; +    *dest = calloc(*dcount, sizeof(sized_binary_t)); + +    binary = &(*dest)[0]; + +    for (i = 0; i < scount; i++, binary++) +    { +        _src = src + i; + +        hash = compute_add1505_shl5_hash32(_src); + +        binary->data = malloc(sizeof(hash) * sizeof(bin_t)); +        binary->len = sizeof(hash); + +        memcpy(binary->data, &hash, sizeof(hash)); + +    } + +    return result; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : modifier = modificateur à consulter.                         * +*                index    = indice de la combinaison ciblée. [OUT]            * +*                                                                             * +*  Description : Retrouve l'origine d'une correspondance à partir d'un indice.* +*                                                                             * +*  Retour      : Version humainement lisible de la combinaison.               * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static char *g_scan_add1505_shl5_modifier_get_path(const GScanAdd1505Shl5Modifier *modifier, size_t *index) +{ +    char *result;                           /* Combinaison à retourner     */ + +    if (*index > 0) +    { +        result = NULL; +        (*index)--; +    } + +    else +        result = strdup("add1505-shl5"); + +    return result; + +} | 
