summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/core
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2020-01-03 22:51:31 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2020-01-03 22:51:31 (GMT)
commit8255d60ac64a851c2e7ca37d63aa1ba37d35b704 (patch)
tree06f1855dd7ead9da2acc0c595e3710faf503628f /plugins/pychrysalide/core
parent90b8f66eb8ae62d951dfbd333fb338e38874c9fe (diff)
Used a Python enumeration for verbosity levels.
Diffstat (limited to 'plugins/pychrysalide/core')
-rw-r--r--plugins/pychrysalide/core/Makefile.am1
-rw-r--r--plugins/pychrysalide/core/constants.c75
-rw-r--r--plugins/pychrysalide/core/constants.h39
-rw-r--r--plugins/pychrysalide/core/logs.c95
4 files changed, 153 insertions, 57 deletions
diff --git a/plugins/pychrysalide/core/Makefile.am b/plugins/pychrysalide/core/Makefile.am
index 131e1b9..eadad3f 100644
--- a/plugins/pychrysalide/core/Makefile.am
+++ b/plugins/pychrysalide/core/Makefile.am
@@ -2,6 +2,7 @@
noinst_LTLIBRARIES = libpychrysacore.la
libpychrysacore_la_SOURCES = \
+ constants.h constants.c \
demanglers.h demanglers.c \
global.h global.c \
logs.h logs.c \
diff --git a/plugins/pychrysalide/core/constants.c b/plugins/pychrysalide/core/constants.c
new file mode 100644
index 0000000..e61f451
--- /dev/null
+++ b/plugins/pychrysalide/core/constants.c
@@ -0,0 +1,75 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * constants.c - ajout des constantes liées au coeur du programme
+ *
+ * Copyright (C) 2020 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 "constants.h"
+
+
+#include <core/logs.h>
+
+
+#include "../helpers.h"
+
+
+
+/******************************************************************************
+* *
+* Paramètres : module = module dont le dictionnaire est à compléter. *
+* *
+* Description : Définit les constantes pour les types de messages. *
+* *
+* Retour : true en cas de succès de l'opération, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool define_core_logs_constants(PyObject *module)
+{
+ bool result; /* Bilan à retourner */
+ PyObject *values; /* Groupe de valeurs à établir */
+
+ values = PyDict_New();
+
+ result = add_const_to_group(values, "INFO", LMT_INFO);
+ if (result) result = add_const_to_group(values, "PROCESS", LMT_PROCESS);
+ if (result) result = add_const_to_group(values, "WARNING", LMT_WARNING);
+ if (result) result = add_const_to_group(values, "BAD_BINARY", LMT_BAD_BINARY);
+ if (result) result = add_const_to_group(values, "LMT_ERROR", LMT_ERROR);
+ if (result) result = add_const_to_group(values, "EXT_ERROR", LMT_EXT_ERROR);
+ if (result) result = add_const_to_group(values, "COUNT", LMT_COUNT);
+
+ if (!result)
+ {
+ Py_DECREF(values);
+ goto exit;
+ }
+
+ result = attach_constants_group_to_module(module, false, "LogMessageType", values,
+ "Available types for log messages.");
+
+ exit:
+
+ return result;
+
+}
diff --git a/plugins/pychrysalide/core/constants.h b/plugins/pychrysalide/core/constants.h
new file mode 100644
index 0000000..38a8ebc
--- /dev/null
+++ b/plugins/pychrysalide/core/constants.h
@@ -0,0 +1,39 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * constants.h - prototypes pour l'ajout des constantes liées au coeur du programme
+ *
+ * Copyright (C) 2020 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
+ */
+
+
+#ifndef _PLUGINS_PYCHRYSALIDE_CORE_CONSTANTS_H
+#define _PLUGINS_PYCHRYSALIDE_CORE_CONSTANTS_H
+
+
+#include <Python.h>
+#include <stdbool.h>
+
+
+
+/* Définit les constantes pour les types de messages. */
+bool define_core_logs_constants(PyObject *);
+
+
+
+#endif /* _PLUGINS_PYCHRYSALIDE_CORE_CONSTANTS_H */
diff --git a/plugins/pychrysalide/core/logs.c b/plugins/pychrysalide/core/logs.c
index afab7ab..d4fd0da 100644
--- a/plugins/pychrysalide/core/logs.c
+++ b/plugins/pychrysalide/core/logs.c
@@ -31,6 +31,7 @@
#include <core/logs.h>
+#include "constants.h"
#include "../access.h"
#include "../helpers.h"
#include "../pychrysa.h"
@@ -46,9 +47,6 @@ static PyObject *py_logs_set_verbosity(PyObject *, PyObject *);
/* Affiche un message dans le journal des messages système. */
static PyObject *py_logs_log_message(PyObject *, PyObject *);
-/* Définit les constantes pour les types de message. */
-static bool define_python_log_constants(PyObject *);
-
/******************************************************************************
@@ -69,9 +67,19 @@ static PyObject *py_logs_get_verbosity(PyObject *self, PyObject *args)
PyObject *result; /* Conversion à retourner */
LogMessageType verbosity; /* Niveau de filtre de message */
+#define LOGS_GET_VERBOSITY_METHOD PYTHON_METHOD_DEF \
+( \
+ get_verbosity, "", \
+ METH_NOARGS, py_logs, \
+ "Get the log verbosity, as a pychrysalide.core.LogMessageType level.\n" \
+ "\n" \
+ "A *COUNT* value means no log gets displayed, a null value means" \
+ " all kinds of logs get printed." \
+)
+
verbosity = get_log_verbosity();
- result = PyLong_FromUnsignedLong(verbosity);
+ result = cast_with_constants_group_from_module("pychrysalide.core", "LogMessageType", verbosity);
return result;
@@ -96,6 +104,17 @@ static PyObject *py_logs_set_verbosity(PyObject *self, PyObject *args)
PyObject *result; /* Bilan à retourner */
unsigned long verbosity; /* Niveau de filtre de message */
+#define LOGS_SET_VERBOSITY_METHOD PYTHON_METHOD_DEF \
+( \
+ set_verbosity, "level, /", \
+ METH_VARARGS, py_logs, \
+ "Set the log verbosity. The provided level has to be castable into a" \
+ " pychrysalide.core.LogMessageType value.\n" \
+ "\n" \
+ "A *COUNT* value means no log gets displayed, a null value means" \
+ " all kinds of logs get printed." \
+)
+
if (!PyArg_ParseTuple(args, "k", &verbosity))
return NULL;
@@ -128,6 +147,17 @@ static PyObject *py_logs_log_message(PyObject *self, PyObject *args)
unsigned long type; /* Espèce du message */
const char *msg; /* Contenu du message */
+#define LOGS_LOG_MESSAGE_METHOD PYTHON_METHOD_DEF \
+( \
+ log_message, "type, msg, /", \
+ METH_VARARGS, py_logs, \
+ "Display a message in the log window, in graphical mode, or in the" \
+ " console output if none.\n" \
+ "\n" \
+ "The type of the message has to be a pychrysalide.core.LogMessageType" \
+ " value." \
+)
+
if (!PyArg_ParseTuple(args, "ks", &type, &msg))
return NULL;
@@ -159,37 +189,6 @@ static PyObject *py_logs_log_message(PyObject *self, PyObject *args)
/******************************************************************************
* *
-* Paramètres : dict = dictionnaire de module à compléter. *
-* *
-* Description : Définit les constantes pour les types de message. *
-* *
-* Retour : true en cas de succès de l'opération, false sinon. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static bool define_python_log_constants(PyObject *dict)
-{
- bool result; /* Bilan à retourner */
-
- result = true;
-
- result &= PyModDict_AddULongMacro(dict, LMT_INFO);
- result &= PyModDict_AddULongMacro(dict, LMT_PROCESS);
- result &= PyModDict_AddULongMacro(dict, LMT_WARNING);
- result &= PyModDict_AddULongMacro(dict, LMT_BAD_BINARY);
- result &= PyModDict_AddULongMacro(dict, LMT_ERROR);
- result &= PyModDict_AddULongMacro(dict, LMT_EXT_ERROR);
- result &= PyModDict_AddULongMacro(dict, LMT_COUNT);
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
* Paramètres : - *
* *
* Description : Définit une extension du module 'core' à compléter. *
@@ -204,27 +203,12 @@ bool populate_core_module_with_logs(void)
{
bool result; /* Bilan à retourner */
PyObject *module; /* Module à recompléter */
- PyObject *dict; /* Dictionnaire dudit module */
static PyMethodDef py_logs_methods[] = {
-
- {
- "get_verbosity", py_logs_get_verbosity,
- METH_NOARGS,
- "get_verbosity(, /)\n--\n\nGet the log verbosity."
- },
- {
- "set_verbosity", py_logs_set_verbosity,
- METH_VARARGS,
- "set_verbosity(, /)\n--\n\nSet the log verbosity."
- },
- {
- "log_message", py_logs_log_message,
- METH_VARARGS,
- "log_message(type, msg, /)\n--\n\nDisplay a message in the log window, if any."
- },
+ LOGS_GET_VERBOSITY_METHOD,
+ LOGS_SET_VERBOSITY_METHOD,
+ LOGS_LOG_MESSAGE_METHOD,
{ NULL }
-
};
module = get_access_to_python_module("pychrysalide.core");
@@ -232,10 +216,7 @@ bool populate_core_module_with_logs(void)
result = register_python_module_methods(module, py_logs_methods);
if (result)
- {
- dict = PyModule_GetDict(module);
- result = define_python_log_constants(dict);
- }
+ result = define_core_logs_constants(module);
return result;