/* Chrysalide - Outil d'analyse de fichiers binaires
* core.c - enregistrement des fonctions principales
*
* Copyright (C) 2022 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 Foobar. If not, see .
*/
#include "core.h"
#include
#include "items/count.h"
#include "items/datasize.h"
#include "items/uint.h"
#include "items/console/log.h"
#ifdef HAVE_MAGIC_SUPPORT
# include "items/magic/type.h"
# include "items/magic/mime-encoding.h"
# include "items/magic/mime-type.h"
#endif
#include "items/time/make.h"
#include "items/time/now.h"
/******************************************************************************
* *
* Paramètres : space = espace de noms à composer. *
* *
* Description : Inscrit les principales fonctions dans l'espace racine. *
* *
* Retour : Bilan des enregistrements effectués. *
* *
* Remarques : - *
* *
******************************************************************************/
bool populate_main_scan_namespace(GScanNamespace *space)
{
bool result; /* Bilan à retourner */
GScanNamespace *ns; /* Nouvel espace de noms */
result = true;
#define REGISTER_FUNC(s, f) \
({ \
bool __result; \
__result = g_scan_namespace_register_item(s, f); \
g_object_unref(G_OBJECT(f)); \
__result; \
})
if (result) result = REGISTER_FUNC(space, g_scan_count_function_new());
if (result) result = REGISTER_FUNC(space, g_scan_datasize_function_new());
if (result) result = REGISTER_FUNC(space, g_scan_uint_function_new(MDS_8_BITS_SIGNED, SRE_LITTLE));
if (result) result = REGISTER_FUNC(space, g_scan_uint_function_new(MDS_8_BITS_UNSIGNED, SRE_LITTLE));
if (result) result = REGISTER_FUNC(space, g_scan_uint_function_new(MDS_16_BITS_SIGNED, SRE_LITTLE));
if (result) result = REGISTER_FUNC(space, g_scan_uint_function_new(MDS_16_BITS_SIGNED, SRE_BIG));
if (result) result = REGISTER_FUNC(space, g_scan_uint_function_new(MDS_16_BITS_UNSIGNED, SRE_LITTLE));
if (result) result = REGISTER_FUNC(space, g_scan_uint_function_new(MDS_16_BITS_UNSIGNED, SRE_BIG));
if (result) result = REGISTER_FUNC(space, g_scan_uint_function_new(MDS_32_BITS_SIGNED, SRE_LITTLE));
if (result) result = REGISTER_FUNC(space, g_scan_uint_function_new(MDS_32_BITS_SIGNED, SRE_BIG));
if (result) result = REGISTER_FUNC(space, g_scan_uint_function_new(MDS_32_BITS_UNSIGNED, SRE_LITTLE));
if (result) result = REGISTER_FUNC(space, g_scan_uint_function_new(MDS_32_BITS_UNSIGNED, SRE_BIG));
if (result) result = REGISTER_FUNC(space, g_scan_uint_function_new(MDS_64_BITS_SIGNED, SRE_LITTLE));
if (result) result = REGISTER_FUNC(space, g_scan_uint_function_new(MDS_64_BITS_SIGNED, SRE_BIG));
if (result) result = REGISTER_FUNC(space, g_scan_uint_function_new(MDS_64_BITS_UNSIGNED, SRE_LITTLE));
if (result) result = REGISTER_FUNC(space, g_scan_uint_function_new(MDS_64_BITS_UNSIGNED, SRE_BIG));
/* Console */
if (result)
{
ns = g_scan_namespace_new("console");
result = g_scan_namespace_register_item(space, G_REGISTERED_ITEM(ns));
if (result) result = REGISTER_FUNC(ns, g_scan_console_log_function_new());
g_object_unref(G_OBJECT(ns));
}
/* Magic */
#ifdef HAVE_MAGIC_SUPPORT
if (result)
{
ns = g_scan_namespace_new("magic");
result = g_scan_namespace_register_item(space, G_REGISTERED_ITEM(ns));
if (result) result = REGISTER_FUNC(ns, g_scan_magic_type_function_new());
if (result) result = REGISTER_FUNC(ns, g_scan_mime_encoding_function_new());
if (result) result = REGISTER_FUNC(ns, g_scan_mime_type_function_new());
g_object_unref(G_OBJECT(ns));
}
#endif
/* Time */
if (result)
{
ns = g_scan_namespace_new("time");
result = g_scan_namespace_register_item(space, G_REGISTERED_ITEM(ns));
if (result) result = REGISTER_FUNC(ns, g_scan_time_make_function_new());
if (result) result = REGISTER_FUNC(ns, g_scan_time_now_function_new());
g_object_unref(G_OBJECT(ns));
}
return result;
}