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
|
/* Chrysalide - Outil d'analyse de fichiers binaires
* speed.c - mesure de temps d'exécution internes
*
* Copyright (C) 2015-2017 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 Chrysalide. If not, see <http://www.gnu.org/licenses/>.
*/
#include "speed.h"
#include <malloc.h>
#include <time.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <plugins/plugin-def.h>
DEFINE_CHRYSALIDE_ACTIVE_PLUGIN("Speed Measure", "Tracks to time spent for disassembling code", "0.1.0",
PGA_DISASSEMBLY_STARTED, PGA_DISASSEMBLY_ENDED);
/* Mémorisation des résultats de chronométrages */
typedef struct _speed_measure
{
clock_t points[2]; /* Points de mesure successifs */
unsigned long usages[2]; /* Taux d'utilisation du CPU */
} speed_measure;
/******************************************************************************
* *
* Paramètres : plugin = greffon à manipuler. *
* action = type d'action attendue. *
* binary = binaire dont le contenu est en cours de traitement. *
* *
* Description : Exécute une action pendant un désassemblage de binaire. *
* *
* Retour : - *
* *
* Remarques : - *
* *
******************************************************************************/
G_MODULE_EXPORT void process_binary_disassembly(const GPluginModule *plugin, PluginAction action, GLoadedBinary *binary)
{
speed_measure *measure; /* Suivi des progressions */
void take_measure(clock_t *point, unsigned long *usage)
{
struct rusage rusage; /* Notification des usages */
*point = clock();
getrusage(RUSAGE_THREAD, &rusage);
*usage = rusage.ru_utime.tv_sec * 1000000 + rusage.ru_utime.tv_usec;
*usage += rusage.ru_stime.tv_sec * 1000000 + rusage.ru_stime.tv_usec;
}
switch (action)
{
case PGA_DISASSEMBLY_STARTED:
measure = (speed_measure *)calloc(1, sizeof(speed_measure));
g_object_set_data(G_OBJECT(binary), "speed_measure", measure);
take_measure(&measure->points[0], &measure->usages[0]);
break;
case PGA_DISASSEMBLY_ENDED:
measure = (speed_measure *)g_object_get_data(G_OBJECT(binary), "speed_measure");
take_measure(&measure->points[1], &measure->usages[1]);
#define SHOW_SPEED(pg, sm, title, p0, p1) \
g_plugin_module_log_variadic_message(pg, LMT_INFO, title ": %.2g (%.2g)", \
(double)(sm->points[p1] - sm->points[p0]) / CLOCKS_PER_SEC, \
(sm->usages[p1] - sm->usages[p0]) / 1000000.0);
SHOW_SPEED(plugin, measure, "Whole elapsed time for disassembly", 0, 1);
g_object_set_data(G_OBJECT(binary), "speed_measure", NULL);
free(measure);
break;
default:
break;
}
}
|