From 607a867355b2ffe09a76f3b4ea8dbc4be1dc477f Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Thu, 12 Sep 2019 19:47:59 +0200 Subject: Replaced some database item properties by new flags. --- plugins/arm/v7/fetch.c | 2 +- plugins/dalvik/link.c | 2 +- plugins/fmtp/parser.c | 2 +- plugins/lnxsyscalls/writer.c | 2 +- plugins/pychrysalide/analysis/db/constants.c | 2 + plugins/pychrysalide/analysis/db/item.c | 70 ---------------------------- src/analysis/binary.c | 4 +- src/analysis/db/item-int.h | 4 -- src/analysis/db/item.c | 44 ++--------------- src/analysis/db/item.h | 12 ++--- 10 files changed, 16 insertions(+), 128 deletions(-) diff --git a/plugins/arm/v7/fetch.c b/plugins/arm/v7/fetch.c index 6252990..6777fdc 100644 --- a/plugins/arm/v7/fetch.c +++ b/plugins/arm/v7/fetch.c @@ -506,7 +506,7 @@ void help_fetching_with_instruction_ldr_literal_with_orig(GArchInstruction *inst else { comment = g_db_comment_new_inlined(&loaded_addr, BLF_HAS_CODE, false); - g_db_item_set_volatile(G_DB_ITEM(comment), true); + g_db_item_add_flag(G_DB_ITEM(comment), DIF_VOLATILE); g_db_comment_add_dynamic_text(comment, desc); diff --git a/plugins/dalvik/link.c b/plugins/dalvik/link.c index 4960917..8aa8ff7 100644 --- a/plugins/dalvik/link.c +++ b/plugins/dalvik/link.c @@ -360,7 +360,7 @@ void handle_dalvik_packed_switch_links(GArchInstruction *instr, GArchProcessor * item = g_db_comment_new_area(&comment->handler, BLF_NONE, msg, true); - g_db_item_set_volatile(G_DB_ITEM(item), true); + g_db_item_add_flag(G_DB_ITEM(item), DIF_VOLATILE); g_proc_context_add_db_item(context, G_DB_ITEM(item)); free(msg); diff --git a/plugins/fmtp/parser.c b/plugins/fmtp/parser.c index ac22e55..88762b5 100644 --- a/plugins/fmtp/parser.c +++ b/plugins/fmtp/parser.c @@ -127,7 +127,7 @@ static bool parse_field_definition(const fmt_field_def *def, GBinFormat *format, addr = get_mrange_addr(g_arch_instruction_get_range(instr)); comment = g_db_comment_new_inlined(addr, BLF_HAS_CODE, false); - g_db_item_set_volatile(G_DB_ITEM(comment), true); + g_db_item_add_flag(G_DB_ITEM(comment), DIF_VOLATILE); switch (def->ctype) { diff --git a/plugins/lnxsyscalls/writer.c b/plugins/lnxsyscalls/writer.c index caa5501..2334596 100644 --- a/plugins/lnxsyscalls/writer.c +++ b/plugins/lnxsyscalls/writer.c @@ -213,7 +213,7 @@ void write_all_comments(comment_writer *writer, GPreloadInfo *preload) if (comment == NULL) { comment = g_db_comment_new_inlined(&target->addr, BLF_HAS_CODE, false); - g_db_item_set_volatile(G_DB_ITEM(comment), true); + g_db_item_add_flag(G_DB_ITEM(comment), DIF_VOLATILE); g_object_ref(G_OBJECT(comment)); diff --git a/plugins/pychrysalide/analysis/db/constants.c b/plugins/pychrysalide/analysis/db/constants.c index fb30c7e..0c03cfc 100644 --- a/plugins/pychrysalide/analysis/db/constants.c +++ b/plugins/pychrysalide/analysis/db/constants.c @@ -54,6 +54,8 @@ bool define_db_item_constants(PyTypeObject *type) result = add_const_to_group(values, "NONE", DIF_NONE); if (result) result = add_const_to_group(values, "ERASER", DIF_ERASER); + if (result) result = add_const_to_group(values, "VOLATILE", DIF_VOLATILE); + if (result) result = add_const_to_group(values, "BROKEN", DIF_BROKEN); if (!result) { diff --git a/plugins/pychrysalide/analysis/db/item.c b/plugins/pychrysalide/analysis/db/item.c index 7bb96c2..9505838 100644 --- a/plugins/pychrysalide/analysis/db/item.c +++ b/plugins/pychrysalide/analysis/db/item.c @@ -48,12 +48,6 @@ static PyObject *py_db_item_remove_flag(PyObject *, PyObject *); /* Décrit l'élément de collection en place. */ static PyObject *py_db_item_get_label(PyObject *, void *); -/* Indique si l'élément contient des données à oublier ou non. */ -static PyObject *py_db_item_get_volatile(PyObject *, void *); - -/* Définit si l'élément contient des données à oublier ou non. */ -static int py_db_item_set_volatile(PyObject *, PyObject *, void *); - /* Indique les propriétés particulières appliquées à l'élément. */ static PyObject *py_db_item_get_flags(PyObject *, void *); @@ -184,66 +178,6 @@ static PyObject *py_db_item_get_label(PyObject *self, void *closure) * Paramètres : self = objet Python concerné par l'appel. * * closure = non utilisé ici. * * * -* Description : Indique si l'élément contient des données à oublier ou non. * -* * -* Retour : Etat de la sauegarde de l'élément consulté. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_db_item_get_volatile(PyObject *self, void *closure) -{ - PyObject *result; /* Valeur à retourner */ - GDbItem *item; /* Elément à consulter */ - - item = G_DB_ITEM(pygobject_get(self)); - - result = (g_db_item_is_volatile(item) ? Py_True : Py_False); - Py_INCREF(result); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = objet Python concerné par l'appel. * -* value = valeur fournie à intégrer ou prendre en compte. * -* closure = non utilisé ici. * -* * -* Description : Définit si l'élément contient des données à oublier ou non. * -* * -* Retour : Bilan de l'opération pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static int py_db_item_set_volatile(PyObject *self, PyObject *value, void *closure) -{ - GDbItem *item; /* Elément à modifier */ - - if (!PyBool_Check(value)) - { - PyErr_SetString(PyExc_TypeError, _("The attribute value must be a boolean.")); - return -1; - } - - item = G_DB_ITEM(pygobject_get(self)); - g_db_item_set_volatile(item, (bool)(value == Py_True)); - - return 0; - -} - - -/****************************************************************************** -* * -* Paramètres : self = objet Python concerné par l'appel. * -* closure = non utilisé ici. * -* * * Description : Indique les propriétés particulières appliquées à l'élément. * * * * Retour : Propriétés actives de l'élément. * @@ -297,10 +231,6 @@ PyTypeObject *get_python_db_item_type(void) }; static PyGetSetDef py_db_item_getseters[] = { - { - "volatile", py_db_item_get_volatile, py_db_item_set_volatile, - "Define if a Database item can be forgotten.", NULL - }, DB_ITEM_LABEL_ATTRIB, DB_ITEM_FLAGS_ATTRIB, { NULL } diff --git a/src/analysis/binary.c b/src/analysis/binary.c index 070e175..ac7556c 100644 --- a/src/analysis/binary.c +++ b/src/analysis/binary.c @@ -1077,7 +1077,7 @@ bool _g_loaded_binary_add_to_collection(GLoadedBinary *binary, GDbItem *item, bo if (collec == NULL) return false; /* S'il n'y a pas besoin de sauvegarde... */ - if (g_db_item_is_volatile(item)) + if (g_db_item_get_flags(item) & DIF_VOLATILE) result = _g_db_collection_add_item(collec, item, lock); /* Sinon on envoie par le réseau ! */ @@ -1158,7 +1158,7 @@ bool _g_loaded_binary_remove_from_collection(GLoadedBinary *binary, DBFeatures f if (collec == NULL) return false; /* S'il n'y a pas besoin de sauvegarde... */ - if (g_db_item_is_volatile(item)) + if (g_db_item_get_flags(item) & DIF_VOLATILE) result = _g_db_collection_remove_item(collec, item, lock, true); /* Sinon on envoie par le réseau ! */ diff --git a/src/analysis/db/item-int.h b/src/analysis/db/item-int.h index e530442..bdaf38e 100644 --- a/src/analysis/db/item-int.h +++ b/src/analysis/db/item-int.h @@ -76,10 +76,6 @@ struct _GDbItem }; - bool is_volatile; /* Pas besoin de sauvegarde ? */ - - bool broken; /* Changement applicable ? */ - }; /* Base d'un élément pour collection générique (classe) */ diff --git a/src/analysis/db/item.c b/src/analysis/db/item.c index 227d99f..a403537 100644 --- a/src/analysis/db/item.c +++ b/src/analysis/db/item.c @@ -118,7 +118,7 @@ static void g_db_item_init(GDbItem *item) { set_static_rle_string(&item->author, ""); - item->is_volatile = false; + g_atomic_int_set(&item->atomic_flags, DIF_NONE); } @@ -420,6 +420,9 @@ bool g_db_item_apply(GDbItem *item, GLoadedBinary *binary) result = G_DB_ITEM_GET_CLASS(item)->apply(item, binary); + if (!result) + g_db_item_add_flag(item, DIF_BROKEN); + return result; } @@ -569,45 +572,6 @@ bool g_db_item_is_active(const GDbItem *item) /****************************************************************************** * * -* Paramètres : item = base d'éléments à modifier. * -* is_volatile = état du besoin en sauvegarde. * -* * -* Description : Définit si l'élément contient des données à oublier ou non. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void g_db_item_set_volatile(GDbItem *item, bool is_volatile) -{ - item->is_volatile = is_volatile; - -} - - -/****************************************************************************** -* * -* Paramètres : item = base d'éléments à consulter. * -* * -* Description : Indique si l'élément contient des données à oublier ou non. * -* * -* Retour : Etat du besoin en sauvegarde. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool g_db_item_is_volatile(const GDbItem *item) -{ - return item->is_volatile; - -} - - -/****************************************************************************** -* * * Paramètres : item = base d'éléments à mettre à jour. * * flag = type de propriété à traiter. * * * diff --git a/src/analysis/db/item.h b/src/analysis/db/item.h index 383f9ed..fc6475e 100644 --- a/src/analysis/db/item.h +++ b/src/analysis/db/item.h @@ -43,8 +43,10 @@ typedef struct _GLoadedBinary GLoadedBinary; /* Propriétés particulières pour un élément */ typedef enum _DbItemFlags { - DIF_NONE = (0 << 0), /* Propriétés par défaut */ - DIF_ERASER = (1 << 0), /* Suppression de l'effet */ + DIF_NONE = (0 << 0), /* Propriétés par défaut */ + DIF_ERASER = (1 << 0), /* Suppression de l'effet */ + DIF_VOLATILE = (1 << 1), /* Abscence de sauvegarde */ + DIF_BROKEN = (1 << 2), /* Application impossible */ } DbItemFlags; @@ -106,12 +108,6 @@ bool g_db_item_set_activity(GDbItem *, GLoadedBinary *, timestamp_t *); /* Indique si l'élément est activé ou désactivé. */ bool g_db_item_is_active(const GDbItem *); -/* Définit si l'élément contient des données à oublier ou non. */ -void g_db_item_set_volatile(GDbItem *, bool); - -/* Indique si l'élément contient des données à oublier ou non. */ -bool g_db_item_is_volatile(const GDbItem *); - /* Ajoute une propriété à un élément de base de données. */ void g_db_item_add_flag(GDbItem *, DbItemFlags); -- cgit v0.11.2-87-g4458