diff options
Diffstat (limited to 'src/analysis/scan/conds')
-rw-r--r-- | src/analysis/scan/conds/Makefile.am | 16 | ||||
-rw-r--r-- | src/analysis/scan/conds/binop-int.h | 54 | ||||
-rw-r--r-- | src/analysis/scan/conds/binop.c | 265 | ||||
-rw-r--r-- | src/analysis/scan/conds/binop.h | 68 | ||||
-rw-r--r-- | src/analysis/scan/conds/counter-int.h | 53 | ||||
-rw-r--r-- | src/analysis/scan/conds/counter.c | 232 | ||||
-rw-r--r-- | src/analysis/scan/conds/counter.h | 58 |
7 files changed, 746 insertions, 0 deletions
diff --git a/src/analysis/scan/conds/Makefile.am b/src/analysis/scan/conds/Makefile.am new file mode 100644 index 0000000..402deac --- /dev/null +++ b/src/analysis/scan/conds/Makefile.am @@ -0,0 +1,16 @@ + +noinst_LTLIBRARIES = libanalysisscanconds.la + + +libanalysisscanconds_la_SOURCES = \ + binop-int.h \ + binop.h binop.c \ + counter-int.h \ + counter.h counter.c + +libanalysisscanconds_la_CFLAGS = $(LIBGOBJ_CFLAGS) + + +devdir = $(includedir)/chrysalide/$(subdir:src/%=core/%) + +dev_HEADERS = $(libanalysisscanconds_la_SOURCES:%c=) diff --git a/src/analysis/scan/conds/binop-int.h b/src/analysis/scan/conds/binop-int.h new file mode 100644 index 0000000..0fc5940 --- /dev/null +++ b/src/analysis/scan/conds/binop-int.h @@ -0,0 +1,54 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * binop-int.h - prototypes internes pour les opérations booléennes impliquant deux opérandes + * + * Copyright (C) 2022 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/>. + */ + + +#ifndef _ANALYSIS_SCAN_CONDS_BINOP_INT_H +#define _ANALYSIS_SCAN_CONDS_BINOP_INT_H + + +#include "binop.h" + + +#include "../cond-int.h" + + + +/* Opération booléenne impliquant deux opérandes (instance) */ +struct _GBinaryOperation +{ + GMatchCondition parent; /* A laisser en premier */ + + GMatchCondition *conds[2]; /* Opérandes à manipuler */ + BinOpType type; /* Type de manipulation */ + +}; + +/* Opération booléenne impliquant deux opérandes (classe) */ +struct _GBinaryOperationClass +{ + GMatchConditionClass parent; /* A laisser en premier */ + +}; + + + +#endif /* _ANALYSIS_SCAN_CONDS_BINOP_INT_H */ diff --git a/src/analysis/scan/conds/binop.c b/src/analysis/scan/conds/binop.c new file mode 100644 index 0000000..01e99d9 --- /dev/null +++ b/src/analysis/scan/conds/binop.c @@ -0,0 +1,265 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * binop.c - opérations booléennes impliquant deux opérandes + * + * Copyright (C) 2022 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 "binop.h" + + +#include "binop-int.h" + + + +/* --------------------- INSTANCIATION D'UNE FORME DE CONDITION --------------------- */ + + +/* Initialise la classe des opérations booléennes. */ +static void g_binary_operation_class_init(GBinaryOperationClass *); + +/* Initialise une instance d'opération booléenne. */ +static void g_binary_operation_init(GBinaryOperation *); + +/* Supprime toutes les références externes. */ +static void g_binary_operation_dispose(GBinaryOperation *); + +/* Procède à la libération totale de la mémoire. */ +static void g_binary_operation_finalize(GBinaryOperation *); + + + +/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */ + + +/* Indique le statut d'une condition de validation. */ +static bool g_binary_operation_resolve(const GBinaryOperation *); + +/* Lance l'analyse de contenu binaire selon un motif donné. */ +static void g_binary_operation_analyze(const GBinaryOperation *, const bin_t *, phys_t, phys_t, bool); + + + +/* ---------------------------------------------------------------------------------- */ +/* INSTANCIATION D'UNE FORME DE CONDITION */ +/* ---------------------------------------------------------------------------------- */ + + +/* Indique le type défini pour une opération booléenne de validation. */ +G_DEFINE_TYPE(GBinaryOperation, g_binary_operation, G_TYPE_MATCH_CONDITION); + + +/****************************************************************************** +* * +* Paramètres : klass = classe à initialiser. * +* * +* Description : Initialise la classe des opérations booléennes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_binary_operation_class_init(GBinaryOperationClass *klass) +{ + GObjectClass *object; /* Autre version de la classe */ + GMatchConditionClass *cond; /* Classe parente directe */ + + object = G_OBJECT_CLASS(klass); + + object->dispose = (GObjectFinalizeFunc/* ! */)g_binary_operation_dispose; + object->finalize = (GObjectFinalizeFunc)g_binary_operation_finalize; + + cond = G_MATCH_CONDITION_CLASS(klass); + + cond->resolve = (resolve_cond_fc)g_binary_operation_resolve; + cond->analyze = (analyze_cond_fc)g_binary_operation_analyze; + +} + + +/****************************************************************************** +* * +* Paramètres : op = instance à initialiser. * +* * +* Description : Initialise une instance d'opération booléenne. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_binary_operation_init(GBinaryOperation *op) +{ + op->conds[0] = NULL; + op->conds[1] = NULL; + + op->type = BOT_AND; + +} + + +/****************************************************************************** +* * +* Paramètres : op = instance d'objet GLib à traiter. * +* * +* Description : Supprime toutes les références externes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_binary_operation_dispose(GBinaryOperation *op) +{ + g_clear_object(&op->conds[0]); + g_clear_object(&op->conds[1]); + + G_OBJECT_CLASS(g_binary_operation_parent_class)->dispose(G_OBJECT(op)); + +} + + +/****************************************************************************** +* * +* Paramètres : op = instance d'objet GLib à traiter. * +* * +* Description : Procède à la libération totale de la mémoire. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_binary_operation_finalize(GBinaryOperation *op) +{ + G_OBJECT_CLASS(g_binary_operation_parent_class)->finalize(G_OBJECT(op)); + +} + + +/****************************************************************************** +* * +* Paramètres : op1 = premier opérande à intégrer. * +* op2 = second opérande à intégrer. * +* type = type d'opération à prendre en compte. * +* * +* Description : Met en place une représentation d'opération booléenne. * +* * +* Retour : Condition mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GBinaryOperation *g_binary_operation_new(GMatchCondition *op1, GMatchCondition *op2, BinOpType type) +{ + GBinaryOperation *result; /* Structure à retourner */ + + result = g_object_new(G_TYPE_BINARY_OPERATION, NULL); + + result->conds[0] = op1; + g_object_ref(G_OBJECT(op1)); + + result->conds[1] = op2; + g_object_ref(G_OBJECT(op2)); + + result->type = type; + + return result; + +} + + + +/* ---------------------------------------------------------------------------------- */ +/* IMPLEMENTATION DES FONCTIONS DE CLASSE */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : op = condition à consulter. * +* * +* Description : Indique le statut d'une condition de validation. * +* * +* Retour : Validation de la condition considérée. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool g_binary_operation_resolve(const GBinaryOperation *op) +{ + bool result; /* Bilan à retourner */ + + result = g_match_condition_resolve(op->conds[0]); + + switch (op->type) + { + case BOT_AND: + default: + if (result) + result = g_match_condition_resolve(op->conds[1]); + break; + + case BOT_OR: + if (!result) + result = g_match_condition_resolve(op->conds[1]); + break; + + case BOT_XOR: + result ^= g_match_condition_resolve(op->conds[1]); + break; + + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : op = condition à considérer. * +* data = données binaires brutes à considérer. * +* size = quantité de ces données. * +* pos = position du point d'étude courant. * +* full = force une recherche pleine et entière. * +* * +* Description : Lance l'analyse de contenu binaire selon un motif donné. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_binary_operation_analyze(const GBinaryOperation *op, const bin_t *data, phys_t size, phys_t pos, bool full) +{ + g_match_condition_analyze(op->conds[0], data, size, pos, full); + + if (full || !g_binary_operation_resolve(op)) + g_match_condition_analyze(op->conds[1], data, size, pos, full); + +} diff --git a/src/analysis/scan/conds/binop.h b/src/analysis/scan/conds/binop.h new file mode 100644 index 0000000..55cb515 --- /dev/null +++ b/src/analysis/scan/conds/binop.h @@ -0,0 +1,68 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * binop.h - prototypes pour les opérations booléennes impliquant deux opérandes + * + * Copyright (C) 2022 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/>. + */ + + +#ifndef _ANALYSIS_SCAN_CONDS_BINOP_H +#define _ANALYSIS_SCAN_CONDS_BINOP_H + + +#include <glib-object.h> + + +#include "../cond.h" + + + +#define G_TYPE_BINARY_OPERATION g_binary_operation_get_type() +#define G_BINARY_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_BINARY_OPERATION, GBinaryOperation)) +#define G_IS_BINARY_OPERATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_BINARY_OPERATION)) +#define G_BINARY_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_BINARY_OPERATION, GBinaryOperationClass)) +#define G_IS_BINARY_OPERATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_BINARY_OPERATION)) +#define G_BINARY_OPERATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_BINARY_OPERATION, GBinaryOperationClass)) + + +/* Opération booléenne impliquant deux opérandes (instance) */ +typedef struct _GBinaryOperation GBinaryOperation; + +/* Opération booléenne impliquant deux opérandes (classe) */ +typedef struct _GBinaryOperationClass GBinaryOperationClass; + + +/* Types d'opérations booléennes disponibles */ +typedef enum _BinOpType +{ + BOT_AND, + BOT_OR, + BOT_XOR, + +} BinOpType; + + +/* Indique le type défini pour une opération booléenne de validation. */ +GType g_binary_operation_get_type(void); + +/* Met en place une représentation d'opération booléenne. */ +GBinaryOperation *g_binary_operation_new(GMatchCondition *, GMatchCondition *, BinOpType); + + + +#endif /* _ANALYSIS_SCAN_CONDS_BINOP_H */ diff --git a/src/analysis/scan/conds/counter-int.h b/src/analysis/scan/conds/counter-int.h new file mode 100644 index 0000000..a706fca --- /dev/null +++ b/src/analysis/scan/conds/counter-int.h @@ -0,0 +1,53 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * counter-int.h - prototypes internes pour le décompte de correspondances identifiées dans du contenu binaire + * + * Copyright (C) 2022 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/>. + */ + + +#ifndef _ANALYSIS_SCAN_CONDS_COUNTER_INT_H +#define _ANALYSIS_SCAN_CONDS_COUNTER_INT_H + + +#include "counter.h" + + +#include "../cond-int.h" + + + +/* Décompte des identifications de motifs (instance) */ +struct _GMatchCounter +{ + GMatchCondition parent; /* A laisser en premier */ + + GSearchPattern *pattern; /* Motif associé */ + +}; + +/* Décompte des identifications de motifs (classe) */ +struct _GMatchCounterClass +{ + GMatchConditionClass parent; /* A laisser en premier */ + +}; + + + +#endif /* _ANALYSIS_SCAN_CONDS_COUNTER_INT_H */ diff --git a/src/analysis/scan/conds/counter.c b/src/analysis/scan/conds/counter.c new file mode 100644 index 0000000..7cf36b8 --- /dev/null +++ b/src/analysis/scan/conds/counter.c @@ -0,0 +1,232 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * counter.c - décompte de correspondances identifiées dans du contenu binaire + * + * Copyright (C) 2022 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 "counter.h" + + +#include "counter-int.h" + + + +/* --------------------- INSTANCIATION D'UNE FORME DE CONDITION --------------------- */ + + +/* Initialise la classe des opérations booléennes. */ +static void g_match_counter_class_init(GMatchCounterClass *); + +/* Initialise une instance d'opération booléenne. */ +static void g_match_counter_init(GMatchCounter *); + +/* Supprime toutes les références externes. */ +static void g_match_counter_dispose(GMatchCounter *); + +/* Procède à la libération totale de la mémoire. */ +static void g_match_counter_finalize(GMatchCounter *); + + + +/* --------------------- IMPLEMENTATION DES FONCTIONS DE CLASSE --------------------- */ + + +/* Indique le statut d'une condition de validation. */ +static unsigned long long g_match_counter_resolve_as_number(const GMatchCounter *); + +/* Lance l'analyse de contenu binaire selon un motif donné. */ +static void g_match_counter_analyze(const GMatchCounter *, const bin_t *, phys_t, phys_t, bool); + + + +/* ---------------------------------------------------------------------------------- */ +/* INSTANCIATION D'UNE FORME DE CONDITION */ +/* ---------------------------------------------------------------------------------- */ + + +/* Indique le type défini pour un décompte de résultats lors d'une recherche de motifs. */ +G_DEFINE_TYPE(GMatchCounter, g_match_counter, G_TYPE_MATCH_CONDITION); + + +/****************************************************************************** +* * +* Paramètres : klass = classe à initialiser. * +* * +* Description : Initialise la classe des opérations booléennes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_match_counter_class_init(GMatchCounterClass *klass) +{ + GObjectClass *object; /* Autre version de la classe */ + GMatchConditionClass *cond; /* Classe parente directe */ + + object = G_OBJECT_CLASS(klass); + + object->dispose = (GObjectFinalizeFunc/* ! */)g_match_counter_dispose; + object->finalize = (GObjectFinalizeFunc)g_match_counter_finalize; + + cond = G_MATCH_CONDITION_CLASS(klass); + + cond->resolve_as_num = (resolve_cond_as_number_fc)g_match_counter_resolve_as_number; + cond->analyze = (analyze_cond_fc)g_match_counter_analyze; + +} + + +/****************************************************************************** +* * +* Paramètres : op = instance à initialiser. * +* * +* Description : Initialise une instance d'opération booléenne. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_match_counter_init(GMatchCounter *counter) +{ + counter->pattern = NULL; + +} + + +/****************************************************************************** +* * +* Paramètres : op = instance d'objet GLib à traiter. * +* * +* Description : Supprime toutes les références externes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_match_counter_dispose(GMatchCounter *counter) +{ + g_clear_object(&counter->pattern); + + G_OBJECT_CLASS(g_match_counter_parent_class)->dispose(G_OBJECT(counter)); + +} + + +/****************************************************************************** +* * +* Paramètres : op = instance d'objet GLib à traiter. * +* * +* Description : Procède à la libération totale de la mémoire. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_match_counter_finalize(GMatchCounter *counter) +{ + G_OBJECT_CLASS(g_match_counter_parent_class)->finalize(G_OBJECT(counter)); + +} + + +/****************************************************************************** +* * +* Paramètres : pattern = motif à impliquer. * +* * +* Description : Met en place un décompte de correspondances obtenues. * +* * +* Retour : Condition mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GMatchCounter *g_match_counter_new(GSearchPattern *pattern) +{ + GMatchCounter *result; /* Structure à retourner */ + + result = g_object_new(G_TYPE_MATCH_COUNTER, NULL); + + result->pattern = pattern; + g_object_ref(G_OBJECT(pattern)); + + return result; + +} + + + +/* ---------------------------------------------------------------------------------- */ +/* IMPLEMENTATION DES FONCTIONS DE CLASSE */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : op = condition à consulter. * +* * +* Description : Indique le statut d'une condition de validation. * +* * +* Retour : Forme numérique de la condition considérée pour validation. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static unsigned long long g_match_counter_resolve_as_number(const GMatchCounter *counter) +{ + unsigned long long result; /* Valeur à retourner */ + + result = g_search_pattern_count_matchs(counter->pattern); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : counter = condition à considérer. * +* data = données binaires brutes à considérer. * +* size = quantité de ces données. * +* pos = position du point d'étude courant. * +* full = force une recherche pleine et entière. * +* * +* Description : Lance l'analyse de contenu binaire selon un motif donné. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_match_counter_analyze(const GMatchCounter *counter, const bin_t *data, phys_t size, phys_t pos, bool full) +{ + //g_search_pattern_analyze(counter->pattern, data, size, pos); + +} diff --git a/src/analysis/scan/conds/counter.h b/src/analysis/scan/conds/counter.h new file mode 100644 index 0000000..033ac99 --- /dev/null +++ b/src/analysis/scan/conds/counter.h @@ -0,0 +1,58 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * counter.h - prototypes pour le décompte de correspondances identifiées dans du contenu binaire + * + * Copyright (C) 2022 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/>. + */ + + +#ifndef _ANALYSIS_SCAN_CONDS_COUNTER_H +#define _ANALYSIS_SCAN_CONDS_COUNTER_H + + +#include <glib-object.h> + + +#include "../pattern.h" + + + +#define G_TYPE_MATCH_COUNTER g_match_counter_get_type() +#define G_MATCH_COUNTER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_MATCH_COUNTER, GMatchCounter)) +#define G_IS_MATCH_COUNTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_MATCH_COUNTER)) +#define G_MATCH_COUNTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_MATCH_COUNTER, GMatchCounterClass)) +#define G_IS_MATCH_COUNTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_MATCH_COUNTER)) +#define G_MATCH_COUNTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_MATCH_COUNTER, GMatchCounterClass)) + + +/* Décompte des identifications de motifs (instance) */ +typedef struct _GMatchCounter GMatchCounter; + +/* Décompte des identifications de motifs (classe) */ +typedef struct _GMatchCounterClass GMatchCounterClass; + + +/* Indique le type défini pour un décompte de résultats lors d'une recherche de motifs. */ +GType g_match_counter_get_type(void); + +/* Met en place une représentation d'opération booléenne. */ +GMatchCounter *g_match_counter_new(GSearchPattern *); + + + +#endif /* _ANALYSIS_SCAN_CONDS_COUNTER_H */ |