summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2019-09-11 21:25:13 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2019-09-11 21:25:13 (GMT)
commit83faef9c8f78b20cb031af686f763cfb215cf9d7 (patch)
treeea95f741855044f4473573726804c6c2bcac5db1 /src
parent3e1347d378e7ff0e21fb53b61e0317b8dfe52fc9 (diff)
Reactivated bookmarks for disassembled code.
Diffstat (limited to 'src')
-rw-r--r--src/analysis/db/collection.c10
-rw-r--r--src/analysis/db/item-int.h9
-rw-r--r--src/analysis/db/item.c68
-rw-r--r--src/analysis/db/item.h18
-rw-r--r--src/analysis/db/items/bookmark.c71
-rw-r--r--src/analysis/db/misc/rlestr.c13
-rw-r--r--src/arch/vmpa.c24
-rw-r--r--src/glibext/gbuffercache.h5
8 files changed, 174 insertions, 44 deletions
diff --git a/src/analysis/db/collection.c b/src/analysis/db/collection.c
index cdc91aa..0f4e771 100644
--- a/src/analysis/db/collection.c
+++ b/src/analysis/db/collection.c
@@ -375,14 +375,10 @@ bool g_db_collection_unpack(GDbCollection *collec, packed_buffer *pbuf, sqlite3
if (result)
{
if (collec->binary != NULL && g_db_item_is_active(item))
- result = g_db_item_apply(item, collec->binary);
+ g_db_item_apply(item, collec->binary);
- if (result && db != NULL)
- result = g_db_collection_store_item(collec, item, db);
-
- /* En cas d'erreur, il faut retirer l'élément */
- if (!result)
- _g_db_collection_remove_item(collec, item, true, false);
+ if (db != NULL)
+ g_db_collection_store_item(collec, item, db);
}
diff --git a/src/analysis/db/item-int.h b/src/analysis/db/item-int.h
index 3a5f47d..923ea3a 100644
--- a/src/analysis/db/item-int.h
+++ b/src/analysis/db/item-int.h
@@ -71,8 +71,17 @@ struct _GDbItem
char *label; /* Représentation humaine */
+ union
+ {
+ DbItemFlags flags; /* Propriétés de l'élément */
+ gint atomic_flags; /* Accès atomique */
+
+ };
+
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 2bbc683..c59ef64 100644
--- a/src/analysis/db/item.c
+++ b/src/analysis/db/item.c
@@ -596,6 +596,74 @@ bool g_db_item_is_volatile(const GDbItem *item)
}
+/******************************************************************************
+* *
+* Paramètres : item = base d'éléments à mettre à jour. *
+* flag = type de propriété à traiter. *
+* *
+* Description : Ajoute une propriété à un élément de base de données. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_db_item_add_flag(GDbItem *item, DbItemFlags flag)
+{
+ g_atomic_int_add(&item->atomic_flags, flag);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : item = base d'éléments à mettre à jour. *
+* flag = type de propriété à traiter. *
+* *
+* Description : Retire une propriété à un élément de base de données. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_db_item_remove_flag(GDbItem *item, DbItemFlags flag)
+{
+ gint mask; /* Masque à appliquer */
+
+ mask = flag;
+ mask = ~mask;
+
+ g_atomic_int_and(&item->atomic_flags, mask);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : item = base d'éléments à consulter. *
+* *
+* Description : Indique les propriétés particulières appliquées à l'élément. *
+* *
+* Retour : Propriétés actives de l'élément. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+DbItemFlags g_db_item_get_flags(const GDbItem *item)
+{
+ DbItemFlags result; /* Fanions à retourner */
+
+ result = g_atomic_int_get(&item->atomic_flags);
+
+ return result;
+
+}
+
+
/* ---------------------------------------------------------------------------------- */
/* MANIPULATIONS AVEC UNE BASE DE DONNEES */
diff --git a/src/analysis/db/item.h b/src/analysis/db/item.h
index 6644507..3444b73 100644
--- a/src/analysis/db/item.h
+++ b/src/analysis/db/item.h
@@ -40,6 +40,15 @@
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 */
+
+} DbItemFlags;
+
+
#define G_TYPE_DB_ITEM g_db_item_get_type()
#define G_DB_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_db_item_get_type(), GDbItem))
#define G_IS_DB_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_db_item_get_type()))
@@ -103,6 +112,15 @@ 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);
+
+/* Retire une propriété à un élément de base de données. */
+void g_db_item_remove_flag(GDbItem *, DbItemFlags);
+
+/* Indique les propriétés particulières appliquées à l'élément. */
+DbItemFlags g_db_item_get_flags(const GDbItem *);
+
/* --------------------- MANIPULATIONS AVEC UNE BASE DE DONNEES --------------------- */
diff --git a/src/analysis/db/items/bookmark.c b/src/analysis/db/items/bookmark.c
index 266b04c..819528d 100644
--- a/src/analysis/db/items/bookmark.c
+++ b/src/analysis/db/items/bookmark.c
@@ -34,6 +34,7 @@
#include "../collection-int.h"
#include "../item-int.h"
+#include "../../../glibext/gbinarycursor.h"
@@ -206,6 +207,9 @@ static void g_db_bookmark_class_init(GDbBookmarkClass *klass)
static void g_db_bookmark_init(GDbBookmark *bookmark)
{
+ init_vmpa(&bookmark->addr, VMPA_NO_PHYSICAL, VMPA_NO_VIRTUAL);
+
+ init_dynamic_rle_string(&bookmark->comment, NULL);
}
@@ -440,37 +444,60 @@ static void g_db_bookmark_build_label(GDbBookmark *bookmark)
static bool g_db_bookmark_run(GDbBookmark *bookmark, GLoadedBinary *binary, bool *prev, bool set)
{
- return false;
-#if 0
bool result; /* Bilan à faire remonter */
- GCodeBuffer *buffer; /* Tampon de lignes à traiter */
+ GBufferCache *cache; /* Tampon d'impression colorée */
+ GLineCursor *cursor; /* Emplacement dans un tampon */
+ size_t index; /* Indice de ligne à traiter */
GBufferLine *line; /* Ligne de tampon à marquer */
- result = true;
+ result = false;
+
+ cache = g_loaded_binary_get_disassembled_cache(binary);
+ if (cache == NULL) goto exit;
+
+ g_buffer_cache_lock(cache);
+
+ /* Recherche de la ligne concernée */
+
+ cursor = g_binary_cursor_new();
+ g_binary_cursor_update(G_BINARY_CURSOR(cursor), &bookmark->addr);
- buffer = g_loaded_binary_get_disassembled_buffer(binary);
+ index = g_buffer_cache_find_index_by_cursor(cache, cursor, true);
- line = g_code_buffer_find_line_by_addr(buffer, &bookmark->addr, BLF_HAS_CODE, NULL);
- if (line == NULL)
+ g_object_unref(G_OBJECT(cursor));
+
+ line = g_buffer_cache_find_line_by_index(cache, index);
+
+ /* Application du changement */
+
+ result = (line != NULL);
+
+ if (result)
{
- result = false;
- goto exit;
- }
+ *prev = g_buffer_line_get_flags(line) & BLF_BOOKMARK;
- *prev = g_buffer_line_get_flags(line) & BLF_BOOKMARK;
+ if (set)
+ g_buffer_line_add_flag(line, BLF_BOOKMARK);
- if (set)
- g_buffer_line_add_flag(line, BLF_BOOKMARK);
+ else
+ g_buffer_line_remove_flag(line, BLF_BOOKMARK);
- else
- g_buffer_line_remove_flag(line, BLF_BOOKMARK);
+ g_object_unref(G_OBJECT(line));
+
+ g_buffer_cache_throw_update_at_index(cache, index);
+
+ }
- g_object_unref(G_OBJECT(line));
+ /* Sortie */
+
+ g_buffer_cache_unlock(cache);
+
+ g_object_unref(G_OBJECT(cache));
exit:
return result;
-#endif
+
}
@@ -490,8 +517,11 @@ static bool g_db_bookmark_run(GDbBookmark *bookmark, GLoadedBinary *binary, bool
static bool g_db_bookmark_apply(GDbBookmark *bookmark, GLoadedBinary *binary)
{
bool result; /* Bilan à faire remonter */
+ DbItemFlags flags; /* Propriétés de l'élément */
- result = g_db_bookmark_run(bookmark, binary, &bookmark->prev_state, true);
+ flags = g_db_item_get_flags(G_DB_ITEM(bookmark));
+
+ result = g_db_bookmark_run(bookmark, binary, &bookmark->prev_state, (flags & DIF_ERASER) == 0);
return result;
@@ -514,9 +544,12 @@ static bool g_db_bookmark_apply(GDbBookmark *bookmark, GLoadedBinary *binary)
static bool g_db_bookmark_cancel(GDbBookmark *bookmark, GLoadedBinary *binary)
{
bool result; /* Bilan à faire remonter */
+ DbItemFlags flags; /* Propriétés de l'élément */
+
+ flags = g_db_item_get_flags(G_DB_ITEM(bookmark));
if (!bookmark->prev_state)
- result = g_db_bookmark_run(bookmark, binary, (bool []) { 0 }, false);
+ result = g_db_bookmark_run(bookmark, binary, (bool []) { 0 }, (flags & DIF_ERASER) != 0);
else
result = true;
diff --git a/src/analysis/db/misc/rlestr.c b/src/analysis/db/misc/rlestr.c
index f26c146..0fe182b 100644
--- a/src/analysis/db/misc/rlestr.c
+++ b/src/analysis/db/misc/rlestr.c
@@ -105,6 +105,9 @@ void init_static_rle_string(rle_string *str, const char *data)
void dup_into_rle_string(rle_string *str, const char *data)
{
+ if (str->data != NULL)
+ unset_rle_string(str);
+
if (data != NULL)
{
str->data = strdup(data);
@@ -144,6 +147,11 @@ void set_dynamic_rle_string(rle_string *str, char *data)
str->length = strlen(data);
str->dynamic = true;
}
+ else
+ {
+ str->data = NULL;
+ str->length = 0;
+ }
}
@@ -172,6 +180,11 @@ void set_static_rle_string(rle_string *str, const char *data)
str->length = strlen(data);
str->dynamic = false;
}
+ else
+ {
+ str->data = NULL;
+ str->length = 0;
+ }
}
diff --git a/src/arch/vmpa.c b/src/arch/vmpa.c
index a2a3ba5..70ea52b 100644
--- a/src/arch/vmpa.c
+++ b/src/arch/vmpa.c
@@ -813,36 +813,24 @@ bool store_vmpa(const vmpa2t *addr, const char *base, bound_value **values, size
asprintf(&value->name, "%s%sphys", base != NULL ? base : "", base != NULL ? "_" : "");
value->built_name = true;
+ value->type = SQLITE_INT64;
+
value->has_value = (addr != NULL);
if (value->has_value)
- {
- if (addr->physical != VMPA_NO_PHYSICAL)
- {
- value->type = SQLITE_INT64;
- value->integer64 = addr->physical;
- }
- else
- value->type = SQLITE_NULL;
- }
+ value->integer64 = addr->physical;
value = &(*values)[*count - 1];
asprintf(&value->name, "%s%svirt", base != NULL ? base : "", base != NULL ? "_" : "");
value->built_name = true;
+ value->type = SQLITE_INT64;
+
value->has_value = (addr != NULL);
if (value->has_value)
- {
- if (addr->virtual != VMPA_NO_VIRTUAL)
- {
- value->type = SQLITE_INT64;
- value->integer64 = addr->virtual;
- }
- else
- value->type = SQLITE_NULL;
- }
+ value->integer64 = addr->virtual;
return true;
diff --git a/src/glibext/gbuffercache.h b/src/glibext/gbuffercache.h
index 8059357..0086b38 100644
--- a/src/glibext/gbuffercache.h
+++ b/src/glibext/gbuffercache.h
@@ -99,6 +99,11 @@ void g_buffer_cache_get_line_cursor(const GBufferCache *, size_t, gint, GLineCur
/* Détermine l'ensemble des propriétés attachées à une ligne. */
BufferLineFlags g_buffer_cache_get_line_flags(const GBufferCache *, size_t);
+#define g_buffer_cache_lock(c)
+#define g_buffer_cache_unlock(c)
+
+#define g_buffer_cache_throw_update_at_index(c, i) // check locked
+
/* Retrouve une ligne au sein d'un tampon avec un indice. */
GBufferLine *g_buffer_cache_find_line_by_index(const GBufferCache *, size_t);