summaryrefslogtreecommitdiff
path: root/src/analysis/line_comment.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2009-04-12 19:15:35 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2009-04-12 19:15:35 (GMT)
commit216a3d0121fabd678e50ea6b4fa2447ae9b921f0 (patch)
tree395fcd91b674ff5652e34b46207ba08cc9e7af68 /src/analysis/line_comment.c
parentedac614a164d9cac345d914f4320d71bdb16ab79 (diff)
Created a debugging layout and introduced a heavier use of GLib.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@58 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/analysis/line_comment.c')
-rw-r--r--src/analysis/line_comment.c237
1 files changed, 237 insertions, 0 deletions
diff --git a/src/analysis/line_comment.c b/src/analysis/line_comment.c
new file mode 100644
index 0000000..6df7b96
--- /dev/null
+++ b/src/analysis/line_comment.c
@@ -0,0 +1,237 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * line_comment.c - représentation des lignes commentaires entières
+ *
+ * Copyright (C) 2008 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA 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.
+ *
+ * OpenIDA 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 "line_comment.h"
+
+
+#include <malloc.h>
+#include <string.h>
+
+
+#include "line-int.h"
+
+
+
+/* Ligne de représentation de commentaires entière (instance) */
+struct _GCommentLine
+{
+ GRenderingLine parent; /* Instance parente */
+
+ char *comment; /* Texte à afficher */
+ const disass_options *options; /* Options de représentation */
+
+};
+
+
+/* Ligne de représentation de commentaires entière (classe) */
+struct _GCommentLineClass
+{
+ GRenderingLineClass parent; /* Classe parente */
+
+};
+
+
+/* Initialise la classe des lignes de commentaires entière. */
+static void g_comment_line_class_init(GCommentLineClass *);
+
+/* Initialise la classe des lignes de commentaires entière. */
+static void g_comment_line_init(GCommentLine *);
+
+/* Met à jour la ligne de représentation de commentaires. */
+void g_comment_line_refresh_markup(GCommentLine *);
+
+
+
+/* Indique le type définit par la GLib pour la ligne. */
+G_DEFINE_TYPE(GCommentLine, g_comment_line, G_TYPE_RENDERING_LINE);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des lignes de commentaires entière. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_comment_line_class_init(GCommentLineClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : line = instance à initialiser. *
+* *
+* Description : Initialise la classe des lignes de commentaires entière. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_comment_line_init(GCommentLine *line)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : line = ligne de représentation à actualiser. *
+* *
+* Description : Met à jour la ligne de représentation de commentaires. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_comment_line_refresh_markup(GCommentLine *line)
+{
+ size_t len; /* Taille du contenu */
+ char *content; /* Contenu réellement imprimé */
+ char buffer[CODE_BUFFER_LEN]; /* Zone tampon à utiliser */
+ size_t clen; /* Taille du commentaire */
+
+ len = strlen("<tt>") + 1;
+ content = (char *)calloc(len, sizeof(char));
+ strcpy(content, "<tt>");
+
+ /* Eventuelle adresse virtuelle */
+
+ if (line->options->show_address)
+ {
+ switch (ADM_32BITS /* FIXME */)
+ {
+ case ADM_32BITS:
+ snprintf(buffer, CODE_BUFFER_LEN,
+ "<span foreground='#333333'>0x%08llx</span>",
+ G_RENDERING_LINE(line)->offset);
+ break;
+
+ case ADM_64BITS:
+ snprintf(buffer, CODE_BUFFER_LEN,
+ "<span foreground='#333333'>0x%16llx</span>",
+ G_RENDERING_LINE(line)->offset);
+ break;
+
+ }
+
+ len += strlen(buffer);
+ content = (char *)realloc(content, len * sizeof(char));
+ strcat(content, buffer);
+
+ }
+
+ /* Eventuel code brut (sauté) */
+
+ if (line->options->show_code)
+ {
+ clen = (line->options->show_address ? strlen("\t") : 0);
+ clen += G_RENDERING_LINE(line)->max_bin_len;
+
+ content = (char *)realloc(content, (len + clen) * sizeof(char));
+
+ if (line->options->show_address)
+ {
+ strcat(content, "\t");
+ len += strlen("\t");
+ }
+
+ memset(&content[len - 1], G_RENDERING_LINE(line)->type == RLT_PROTOTYPE ? '-' : ' ',
+ G_RENDERING_LINE(line)->max_bin_len);
+ len += G_RENDERING_LINE(line)->max_bin_len;
+
+ content[len] = '\0';
+
+ }
+
+ /* Commentaire proprement dit */
+
+ clen = (line->options->show_address || line->options->show_code ? strlen("\t") : 0);
+ clen += strlen("<b><span foreground='#003300'>");
+ clen += strlen("; ") + strlen(line->comment);
+ clen += strlen("</span></b>");
+
+ content = (char *)realloc(content, (len + clen) * sizeof(char));
+
+ if (line->options->show_address || line->options->show_code)
+ {
+ strcat(content, "\t");
+ len += strlen("\t");
+ clen -= strlen("\t");
+ }
+
+ snprintf(&content[len - 1], clen + 1, "<b><span foreground='#003300'>; %s</span></b>", line->comment);
+
+ len += clen;
+
+ /* Finalisation */
+
+ len += strlen("</tt>");
+ content = (char *)realloc(content, len * sizeof(char));
+ strcat(content, "</tt>");
+
+ pango_layout_set_markup(G_RENDERING_LINE(line)->layout, content, len - 1);
+
+ free(content);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : offset = emplacement physique ou en mémoire. *
+* comment = texte à afficher au final. *
+* options = paramétrage du rendu. *
+* *
+* Description : Crée une ligne de commentaires entière. *
+* *
+* Retour : Adresse de la structure mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GRenderingLine *g_comment_line_new(uint64_t offset, const char *comment, const disass_options *options)
+{
+ GCommentLine *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_COMMENT_LINE, NULL);
+
+ G_RENDERING_LINE(result)->offset = offset;
+
+ result->comment = strdup(comment);
+
+ return G_RENDERING_LINE(result);
+
+}