summaryrefslogtreecommitdiff
path: root/src/panel/strings.c
blob: bed27ae6732f6ca03b04818264aa1662aa323527 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150

/* OpenIDA - Outil d'analyse de fichiers binaires
 * strings.c - panneau d'affichage des chaînes de caractères
 *
 * Copyright (C) 2008-2009 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 this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */


#include "strings.h"


#include "../format/format.h"



/* Colonnes de la liste des symboles */
typedef enum _StringsColumn
{
    STC_ADDRESS,                            /* Adresse mémoire du symbole  */
    STC_STRING,                             /* Désignation humaine         */

    STC_COUNT                               /* Nombre de colonnes          */

} StringsColumn;


#define _(str) str


/******************************************************************************
*                                                                             *
*  Paramètres  : ref = adresse de l'espace de référencements.                 *
*                                                                             *
*  Description : Construit le panneau d'affichage des symboles.               *
*                                                                             *
*  Retour      : Adresse du panneau mis en place.                             *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

GtkWidget *build_strings_panel(GObject *ref)
{
    GtkWidget *result;                      /* Panneau à retourner         */
    GtkTreeStore *store;                    /* Modèle de gestion           */
    GtkWidget *treeview;                    /* Affichage de la liste       */
    GtkCellRenderer *renderer;              /* Moteur de rendu de colonne  */
    GtkTreeViewColumn *column;              /* Colonne de la liste         */
    GtkTreeSelection *select;               /* Sélection dans la liste     */

    result = gtk_scrolled_window_new(NULL, NULL);
    gtk_widget_show(result);

    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(result), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
    gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(result), GTK_SHADOW_IN);

    store = gtk_tree_store_new(STC_COUNT, G_TYPE_STRING, G_TYPE_STRING);
    g_object_set_data(G_OBJECT(result), "store", store);

    treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
    gtk_widget_show(treeview);
    gtk_container_add(GTK_CONTAINER(result), treeview);

    g_object_unref(G_OBJECT(store));

    column = gtk_tree_view_column_new();
    gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
    gtk_tree_view_set_expander_column(GTK_TREE_VIEW(treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes(_("Address"), renderer, "text", STC_ADDRESS, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);

    renderer = gtk_cell_renderer_text_new();
    column = gtk_tree_view_column_new_with_attributes(_("String"), renderer, "text", STC_STRING, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);


    /*
    select = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
    gtk_tree_selection_set_mode(select, GTK_SELECTION_SINGLE);
    g_signal_connect(G_OBJECT(select), "changed", G_CALLBACK(change_symbols_selection), ref);
    */



    return result;

}



/******************************************************************************
*                                                                             *
*  Paramètres  : panel  = panneau à mettre à jour.                            *
*                format = données sur l'exécutable à représenter.             *
*                                                                             *
*  Description : Affiche la liste des symboles présents dans un exécutable.   *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

void handle_new_exe_on_strings_panel(GtkWidget *panel, const GExeFormat *format)
{
    GtkTreeStore *store;                    /* Modèle de gestion           */
    size_t count;                           /* Nombre des chaînes          */
    GBinSymbol **symbols;                   /* Liste des chaînes trouvées  */
    size_t i;                               /* Boucle de parcours          */
    char address[11];                       /* Conversion de l'adresse     */
    GtkTreeIter iter;                       /* Point d'insertion           */

    store = g_object_get_data(G_OBJECT(panel), "store");

    symbols = g_binary_format_get_symbols(G_BIN_FORMAT(format), &count);

    for (i = 0; i < count; i++)
    {
        if (g_binary_symbol_get_target_type(symbols[i]) != STP_STRING) continue;

        /* FIXME : adresses autres que 32 bits */
        snprintf(address, 11, "0x%08llx", g_binary_symbol_get_address(symbols[i]));

        gtk_tree_store_append(store, &iter, NULL);
        gtk_tree_store_set(store, &iter,
                           STC_ADDRESS, address,
                           STC_STRING, g_binary_symbol_to_string(symbols[i]),
                           -1);

    }

}