diff options
Diffstat (limited to 'src/app.c')
-rw-r--r-- | src/app.c | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/src/app.c b/src/app.c new file mode 100644 index 0000000..bb0fa8a --- /dev/null +++ b/src/app.c @@ -0,0 +1,137 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * app.c - fichier d'entrée du programme + * + * Copyright (C) 2024 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include <assert.h> +#include <fcntl.h> +#include <gio/gdesktopappinfo.h> +#include <gio/gio.h> +#include <sys/auxv.h> + + +#include "app.h" +#include "common/io.h" +#include "common/xdg.h" +#include "core/logs.h" +#include "glibext/helpers.h" + + + +#define CHRYSALIDE_APP_ID "re.chrysalide.framework.gui" // REMME + + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Installe au besoin une définition locale pour le système. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void ensure_wm_icon_and_name(void) +{ + GDesktopAppInfo *info; /* Information du système */ + GKeyFile *kfile; /* Définition d'application */ + unsigned long exec_path; /* Chemin du programme */ + char *filename; /* Nom de fichier à écrire */ + GBytes *res; /* Données brutes d'une image */ + gsize size; /* Taille de ces données */ + gconstpointer data; /* Pointeur vers les données */ + int fd; /* Flux ouvert en écriture */ + + /* Evaluation du besoin */ + + info = g_desktop_app_info_new(CHRYSALIDE_APP_ID ".desktop"); + + /** + * Si l'exécutable n'est pas valide (inconnu de $PATH), + * la variable info n'est pas initialisée. + */ + + if (info != NULL) + { + unref_object(info); + goto done; + } + + /* Mise en place d'une définition d'application */ + + exec_path = getauxval(AT_EXECFN); + assert(exec_path != 0); + + kfile = g_key_file_new(); + + g_key_file_set_string(kfile, "Desktop Entry", "Name", "Chrysalide"); + g_key_file_set_string(kfile, "Desktop Entry", "Comment[fr]", "Cadriciel de rétronception ciblant principalement les systèmes embarqués"); + g_key_file_set_string(kfile, "Desktop Entry", "Comment", "Reverse Engineering Framework focused on embedded systems"); + g_key_file_set_string(kfile, "Desktop Entry", "Type", "Application"); + g_key_file_set_string(kfile, "Desktop Entry", "Exec", (const char *)exec_path); + g_key_file_set_string(kfile, "Desktop Entry", "Icon", "chrysalide-logo"); + g_key_file_set_string(kfile, "Desktop Entry", "StartupNotify", "true"); + g_key_file_set_string(kfile, "Desktop Entry", "MimeType", "application/vnd.android.package-archive"); + + filename = get_xdg_data_dir("applications/re.chrysalide.framework.gui.desktop", true); + + g_key_file_save_to_file(kfile, filename, NULL); + + free(filename); + + g_key_file_free(kfile); + + /* Ecriture de l'image */ + + res = g_resources_lookup_data("/re/chrysalide/framework/images/chrysalide-logo.svg", + G_RESOURCE_LOOKUP_FLAGS_NONE, NULL); + assert(res != NULL); + + data = g_bytes_get_data(res, &size); + + filename = get_xdg_data_dir("icons/hicolor/scalable/apps/chrysalide-logo.svg", true); + + fd = open(filename, O_WRONLY | O_CREAT); + + if (fd == -1) + LOG_ERROR_N("open"); + + else + { + safe_write(fd, data, size); + close(fd); + } + + free(filename); + + g_bytes_unref(res); + + /* Sortie */ + + done: + + ; + +} |