diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2018-05-14 19:40:07 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2018-05-14 19:40:07 (GMT) |
commit | 0286b53bad21abf91cbe17c4772ca9cde6a89cbc (patch) | |
tree | 3bec9dc7e118c00ce9c748576b01606a71880ad7 /src/main.c | |
parent | 267b1ae8608ed4bf52de743798e8647c903ee1b4 (diff) |
Created an instruction database for Chrysalide.
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 73 |
1 files changed, 71 insertions, 2 deletions
@@ -31,6 +31,7 @@ #include <config.h> #include <i18n.h> +#include "analysis/binary.h" #include "analysis/loading.h" #include "analysis/contents/file.h" #include "analysis/db/server.h" @@ -60,6 +61,9 @@ static gboolean load_last_project(GGenConfig *); /* Ouvre les éventuels fichiers fournis au démarrage. */ static int open_binaries(char **, int); +/* Sauvegarde le cache des binaires analysés. */ +static int save_binary_caches(void); + /****************************************************************************** @@ -94,6 +98,7 @@ static void show_chrysalide_help(const char *name) printf("\t-V --verbosity=level\tSet the log level (0 for all messages, %u for none).\n", LMT_COUNT); printf("\t-b --batch\t\tExit after processing files.\n"); + printf("\t-s --save\t\tSave disassembly cache after analysis in batch mode (ignored in normal mode).\n"); printf("\t-p --project=filename\tOpen an existing project or create a new one.\n"); printf("\n"); @@ -152,6 +157,7 @@ int main(int argc, char **argv) bool show_version; /* Affichage de la version ? */ LogMessageType verbosity; /* Niveau de filtre de message */ bool batch_mode; /* Exécution sans GUI ? */ + bool save; /* Sauvegarde du cache ? */ char *prj_filename; /* Chemin vers un projet */ int index; /* Indice d'argument */ int ret; /* Bilan d'un appel */ @@ -172,6 +178,7 @@ int main(int argc, char **argv) { "version", no_argument, NULL, 'v' }, { "verbosity", required_argument, NULL, 'V' }, { "batch", no_argument, NULL, 'b' }, + { "save", no_argument, NULL, 's' }, { "project", required_argument, NULL, 'p' }, { NULL, 0, NULL, 0 } }; @@ -192,11 +199,12 @@ int main(int argc, char **argv) verbosity = LMT_INFO; batch_mode = false; + save = false; prj_filename = NULL; while (true) { - ret = getopt_long(argc, argv, "hvV:bp:", long_options, &index); + ret = getopt_long(argc, argv, "hvV:bsp:", long_options, &index); if (ret == -1) break; switch (ret) @@ -217,6 +225,10 @@ int main(int argc, char **argv) batch_mode = true; break; + case 's': + save = true; + break; + case 'p': prj_filename = optarg; break; @@ -344,8 +356,17 @@ int main(int argc, char **argv) result = open_binaries(argv + optind, argc - optind); if (batch_mode) + { wait_for_all_global_works(); + if (save && result == EXIT_SUCCESS) + { + result = save_binary_caches(); + wait_for_all_global_works(); + } + + } + else gtk_main(); @@ -378,7 +399,6 @@ int main(int argc, char **argv) /****************************************************************************** * * * Paramètres : cfg = configuration globale sur laquelle s'appuyer. * -* ref = espace de référencement global. * * * * Description : Recharge le dernier projet ouvert s'il existe. * * * @@ -450,3 +470,52 @@ static int open_binaries(char **files, int count) return result; } + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Sauvegarde le cache des binaires analysés. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int save_binary_caches(void) +{ + int result; /* Bilan à retourner */ + GStudyProject *project; /* Projet courant à compléter */ + GLoadedContent **loaded; /* Contenus chargés et analysés*/ + size_t count; /* Quantité de ces contenus */ + size_t i; /* Boucle de parcours */ + bool status; /* Bilan de lancement */ + + result = EXIT_SUCCESS; + + project = get_current_project(); + + loaded = g_study_project_get_contents(project, &count); + + for (i = 0; i < count; i++) + { + if (G_IS_LOADED_BINARY(loaded[i])) + { + status = g_loaded_binary_save_cache(G_LOADED_BINARY(loaded[i])); + if (!status) result = EXIT_FAILURE; + } + + g_object_unref(G_OBJECT(loaded[i])); + + } + + if (loaded != NULL) + free(loaded); + + g_object_unref(G_OBJECT(project)); + + return result; + +} |