summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2019-08-14 20:53:39 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2019-08-14 20:53:39 (GMT)
commit60b70b8701c822eddc65269773621690932a57bd (patch)
treed3a033c86eb091e3d81dec77b0855406d737596d
parent2c97b766469c25b09c3b173aa6b8abdb066671c1 (diff)
Updated the Python bindings for binary symbols.
-rw-r--r--plugins/elf/symbols.c4
-rw-r--r--plugins/libcsem/exit.c2
-rw-r--r--plugins/mobicore/symbols.c2
-rw-r--r--plugins/pychrysalide/format/constants.c19
-rw-r--r--plugins/pychrysalide/format/symbol.c292
-rw-r--r--src/analysis/binary.c2
-rw-r--r--src/analysis/disass/area.c2
-rw-r--r--src/analysis/disass/output.c2
-rw-r--r--src/analysis/disass/routines.c4
-rw-r--r--src/analysis/routine.c2
-rw-r--r--src/arch/target.c2
-rw-r--r--src/format/strsym.c4
-rw-r--r--src/format/symbol-int.h2
-rw-r--r--src/format/symbol.c12
-rw-r--r--src/format/symbol.h4
-rw-r--r--src/gtkext/gtkgraphdisplay.c2
-rw-r--r--src/gui/dialogs/gotox.c4
-rw-r--r--src/gui/panels/symbols.c6
-rw-r--r--src/panels/strings.c2
-rw-r--r--tests/format/symbol.py44
20 files changed, 257 insertions, 156 deletions
diff --git a/plugins/elf/symbols.c b/plugins/elf/symbols.c
index 46e5ff8..20bd898 100644
--- a/plugins/elf/symbols.c
+++ b/plugins/elf/symbols.c
@@ -209,7 +209,7 @@ static void register_elf_entry_point(GElfFormat *format, virt_t vaddr, phys_t le
symbol = G_BIN_SYMBOL(routine);
g_binary_symbol_set_range(symbol, &range);
- g_binary_symbol_set_target_type(symbol, STP_ENTRY_POINT);
+ g_binary_symbol_set_stype(symbol, STP_ENTRY_POINT);
g_binary_format_add_symbol(base, symbol);
@@ -1198,7 +1198,7 @@ static bool do_elf_relocation_renaming(GElfLoading *loading, GElfFormat *format,
range = g_binary_symbol_get_range(symbol);
- stype = g_binary_symbol_get_target_type(symbol);
+ stype = g_binary_symbol_get_stype(symbol);
if (stype != STP_ROUTINE && stype != STP_CODE_LABEL && stype != STP_ENTRY_POINT)
{
diff --git a/plugins/libcsem/exit.c b/plugins/libcsem/exit.c
index 794369e..73e8e91 100644
--- a/plugins/libcsem/exit.c
+++ b/plugins/libcsem/exit.c
@@ -61,7 +61,7 @@ static void mark_one_kind_of_exit_as_return(const GLoadedBinary *binary, const c
if (!g_binary_format_find_symbol_by_label(format, fname, &symbol))
goto mokoear_exit;
- if (g_binary_symbol_get_target_type(symbol) != STP_ROUTINE)
+ if (g_binary_symbol_get_stype(symbol) != STP_ROUTINE)
goto mokoear_done_with_sym;
range = g_binary_symbol_get_range(symbol);
diff --git a/plugins/mobicore/symbols.c b/plugins/mobicore/symbols.c
index df8d62f..91b7284 100644
--- a/plugins/mobicore/symbols.c
+++ b/plugins/mobicore/symbols.c
@@ -84,7 +84,7 @@ static void register_mclf_entry_point(GMCLFFormat *format, virt_t vaddr, phys_t
symbol = G_BIN_SYMBOL(routine);
g_binary_symbol_set_range(symbol, &range);
- g_binary_symbol_set_target_type(symbol, STP_ENTRY_POINT);
+ g_binary_symbol_set_stype(symbol, STP_ENTRY_POINT);
g_binary_format_add_symbol(base, symbol);
diff --git a/plugins/pychrysalide/format/constants.c b/plugins/pychrysalide/format/constants.c
index 9e63fdd..ea2aedc 100644
--- a/plugins/pychrysalide/format/constants.c
+++ b/plugins/pychrysalide/format/constants.c
@@ -51,6 +51,25 @@ bool define_binary_symbol_constants(PyTypeObject *type)
values = PyDict_New();
+ result = add_const_to_group(values, "DATA", STP_DATA);
+ if (result) result = add_const_to_group(values, "ROUTINE", STP_ROUTINE);
+ if (result) result = add_const_to_group(values, "CODE_LABEL", STP_CODE_LABEL);
+ if (result) result = add_const_to_group(values, "OBJECT", STP_OBJECT);
+ if (result) result = add_const_to_group(values, "ENTRY_POINT", STP_ENTRY_POINT);
+ if (result) result = add_const_to_group(values, "RO_STRING", STP_RO_STRING);
+ if (result) result = add_const_to_group(values, "DYN_STRING", STP_DYN_STRING);
+ if (result) result = add_const_to_group(values, "COUNT", STP_COUNT);
+
+ if (!result)
+ {
+ Py_DECREF(values);
+ goto exit;
+ }
+
+ result = attach_constants_group(type, false, "SymbolType", values, "Available values for symbol types.");
+
+ values = PyDict_New();
+
result = add_const_to_group(values, "INTERNAL", SSS_INTERNAL);
if (result) result = add_const_to_group(values, "EXPORTED", SSS_EXPORTED);
if (result) result = add_const_to_group(values, "IMPORTED", SSS_IMPORTED);
diff --git a/plugins/pychrysalide/format/symbol.c b/plugins/pychrysalide/format/symbol.c
index 932b0fd..86a321c 100644
--- a/plugins/pychrysalide/format/symbol.c
+++ b/plugins/pychrysalide/format/symbol.c
@@ -50,14 +50,8 @@
/* Effectue une comparaison avec un objet Python 'BinSymbol'. */
static PyObject *py_binary_symbol_richcompare(PyObject *, PyObject *, int);
-/* Définit un autre nom pour le symbole. */
-static PyObject *py_binary_symbol_set_alt_label(PyObject *, PyObject *);
-
-/* Fournit le type du symbole. */
-static PyObject *py_binary_symbol_get_target_type(PyObject *, void *);
-
-/* Fournit un étiquette pour viser un symbole. */
-static PyObject *py_binary_symbol_get_label(PyObject *, void *);
+/* Crée un nouvel objet Python de type 'BinSymbol'. */
+static PyObject *py_binary_symbol_new(PyTypeObject *, PyObject *, PyObject *);
/* Fournit l'emplacement où se situe un symbole. */
static PyObject *py_binary_symbol_get_range(PyObject *, void *);
@@ -65,11 +59,23 @@ static PyObject *py_binary_symbol_get_range(PyObject *, void *);
/* Définit la couverture physique / en mémoire d'un symbole. */
static int py_binary_symbol_set_range(PyObject *, PyObject *, void *);
+/* Fournit le type du symbole. */
+static PyObject *py_binary_symbol_get_stype(PyObject *, void *);
+
+/* Définit le type du symbole. */
+static int py_binary_symbol_set_stype(PyObject *, PyObject *, void *);
+
+/* Fournit un étiquette pour viser un symbole. */
+static PyObject *py_binary_symbol_get_label(PyObject *, void *);
+
/* Fournit la visibilité du symbole. */
static PyObject *py_binary_symbol_get_status(PyObject *, void *);
-/* Définit les constantes pour les symboles binaires. */
-static bool py_binary_symbol_define_constants(PyTypeObject *);
+/* Définit la visibilité du symbole. */
+static int py_binary_symbol_set_status(PyObject *, PyObject *, void *);
+
+/* Définit un autre nom pour le symbole. */
+static int py_binary_symbol_set_label(PyObject *, PyObject *, void *);
@@ -124,7 +130,7 @@ static PyObject *py_binary_symbol_richcompare(PyObject *a, PyObject *b, int op)
* args = arguments fournis à l'appel. *
* kwds = arguments de type key=val fournis. *
* *
-* Description : Crée un nouvel objet Python de type 'DbComment'. *
+* Description : Crée un nouvel objet Python de type 'BinSymbol'. *
* *
* Retour : Instance Python mise en place. *
* *
@@ -136,12 +142,23 @@ static PyObject *py_binary_symbol_new(PyTypeObject *type, PyObject *args, PyObje
{
PyObject *result; /* Bilan à retourner */
SymbolType stype; /* Type prévu pour le symbole */
- PyObject *range_obj; /* Objet pour la couverture */
+ mrange_t range; /* Version native d'un espace */
int ret; /* Bilan de lecture des args. */
- mrange_t *range; /* Version native d'un espace */
GBinSymbol *symbol; /* Version GLib du symble */
- ret = PyArg_ParseTuple(args, "lO", &stype, &range_obj);
+#define BINARY_SYMBOL_DOC \
+ "BinSymbol represents all kinds of symbols, such as string, routines or" \
+ " objects. If something can be linked to a physical or virtual location," \
+ " it can be a symbol." \
+ "\n" \
+ "Instances can be created using the following constructor:\n" \
+ "\n" \
+ " BinSymbol(stype, range)" \
+ "\n" \
+ "Where stype is a pychrysalide.format.BinSymbol.SymbolType value, and" \
+ " range a memory space defined by pychrysalide.arch.mrange." \
+
+ ret = PyArg_ParseTuple(args, "kO&", &stype, convert_any_to_mrange, &range);
if (!ret) return NULL;
if (stype >= STP_COUNT)
@@ -150,16 +167,7 @@ static PyObject *py_binary_symbol_new(PyTypeObject *type, PyObject *args, PyObje
return NULL;
}
- ret = PyObject_IsInstance(range_obj, (PyObject *)get_python_mrange_type());
- if (!ret)
- {
- PyErr_SetString(PyExc_TypeError, _("The second argument must be an instance of mrange."));
- return NULL;
- }
-
- range = get_internal_mrange(range_obj);
-
- symbol = g_binary_symbol_new(range, stype);
+ symbol = g_binary_symbol_new(&range, stype);
result = pygobject_new(G_OBJECT(symbol));
g_object_unref(symbol);
@@ -171,31 +179,69 @@ static PyObject *py_binary_symbol_new(PyTypeObject *type, PyObject *args, PyObje
/******************************************************************************
* *
-* Paramètres : self = classe représentant un binaire. *
-* args = arguments fournis à l'appel. *
+* Paramètres : self = objet Python concerné par l'appel. *
+* closure = non utilisé ici. *
* *
-* Description : Définit un autre nom pour le symbole. *
+* Description : Fournit l'emplacement où se situe un symbole. *
* *
-* Retour : None. *
+* Retour : Zone mémoire couverte par le symbole. *
* *
* Remarques : - *
* *
******************************************************************************/
-static PyObject *py_binary_symbol_set_alt_label(PyObject *self, PyObject *args)
+static PyObject *py_binary_symbol_get_range(PyObject *self, void *closure)
{
- const char *alt; /* Etiquette alternative */
- int ret; /* Bilan de lecture des args. */
+ PyObject *result; /* Valeur à retourner */
GBinSymbol *symbol; /* Elément à consulter */
+ const mrange_t *range; /* Couverture courante */
- ret = PyArg_ParseTuple(args, "s", &alt);
- if (!ret) return NULL;
+#define BINARY_SYMBOL_RANGE_ATTRIB PYTHON_GETSET_DEF_FULL \
+( \
+ range, py_binary_symbol, \
+ "Range covered by the symbol." \
+)
symbol = G_BIN_SYMBOL(pygobject_get(self));
+ range = g_binary_symbol_get_range(symbol);
- g_binary_symbol_set_alt_label(symbol, alt);
+ result = build_from_internal_mrange(range);
+
+ return result;
+
+}
- Py_RETURN_NONE;
+
+/******************************************************************************
+* *
+* Paramètres : self = objet Python concerné par l'appel. *
+* value = valeur fournie à intégrer ou prendre en compte. *
+* closure = adresse non utilisée ici. *
+* *
+* Description : Définit la couverture physique / en mémoire d'un symbole. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static int py_binary_symbol_set_range(PyObject *self, PyObject *value, void *closure)
+{
+ int ret; /* Bilan d'analyse */
+ mrange_t *range; /* Espace mémoire à manipuler */
+ GBinSymbol *symbol; /* Elément à consulter */
+
+ ret = PyObject_IsInstance(value, (PyObject *)get_python_mrange_type());
+ if (!ret) return -1;
+
+ range = get_internal_mrange(value);
+
+ symbol = G_BIN_SYMBOL(pygobject_get(self));
+
+ g_binary_symbol_set_range(symbol, range);
+
+ return 0;
}
@@ -213,16 +259,23 @@ static PyObject *py_binary_symbol_set_alt_label(PyObject *self, PyObject *args)
* *
******************************************************************************/
-static PyObject *py_binary_symbol_get_target_type(PyObject *self, void *closure)
+static PyObject *py_binary_symbol_get_stype(PyObject *self, void *closure)
{
PyObject *result; /* Valeur à retourner */
GBinSymbol *symbol; /* Elément à consulter */
SymbolType type; /* Type de symbole représenté */
+#define BINARY_SYMBOL_STYPE_ATTRIB PYTHON_GETSET_DEF_FULL \
+( \
+ stype, py_binary_symbol, \
+ "Type of the current symbol, as a value of type" \
+ " pychrysalide.format.BinSymbol.SymbolType." \
+)
+
symbol = G_BIN_SYMBOL(pygobject_get(self));
- type = g_binary_symbol_get_target_type(symbol);
+ type = g_binary_symbol_get_stype(symbol);
- result = PyLong_FromLong(type);
+ result = cast_with_constants_group(get_python_binary_symbol_type(), "SymbolType", type);
return result;
@@ -232,38 +285,31 @@ static PyObject *py_binary_symbol_get_target_type(PyObject *self, void *closure)
/******************************************************************************
* *
* Paramètres : self = objet Python concerné par l'appel. *
-* closure = non utilisé ici. *
+* value = valeur fournie à intégrer ou prendre en compte. *
+* closure = adresse non utilisée ici. *
* *
-* Description : Fournit un étiquette pour viser un symbole. *
+* Description : Définit le type du symbole. *
* *
-* Retour : Chaîne de caractères renvoyant au symbole. *
+* Retour : Bilan de l'opération. *
* *
* Remarques : - *
* *
******************************************************************************/
-static PyObject *py_binary_symbol_get_label(PyObject *self, void *closure)
+static int py_binary_symbol_set_stype(PyObject *self, PyObject *value, void *closure)
{
- PyObject *result; /* Valeur à retourner */
GBinSymbol *symbol; /* Elément à consulter */
- char *label; /* Désignation courante */
+ SymbolType type; /* Type de symbole à définir */
+
+ if (!PyLong_Check(value))
+ return -1;
symbol = G_BIN_SYMBOL(pygobject_get(self));
- label = g_binary_symbol_get_label(symbol);
+ type = PyLong_AsUnsignedLong(value);
- if (label != NULL)
- {
- result = PyUnicode_FromString(label);
- free(label);
- }
+ g_binary_symbol_set_stype(symbol, type);
- else
- {
- result = Py_None;
- Py_INCREF(result);
- }
-
- return result;
+ return 0;
}
@@ -273,24 +319,31 @@ static PyObject *py_binary_symbol_get_label(PyObject *self, void *closure)
* Paramètres : self = objet Python concerné par l'appel. *
* closure = non utilisé ici. *
* *
-* Description : Fournit l'emplacement où se situe un symbole. *
+* Description : Fournit la visibilité du symbole. *
* *
-* Retour : Zone mémoire couverte par le symbole. *
+* Retour : Etat de la visibilité du symbole représenté. *
* *
* Remarques : - *
* *
******************************************************************************/
-static PyObject *py_binary_symbol_get_range(PyObject *self, void *closure)
+static PyObject *py_binary_symbol_get_status(PyObject *self, void *closure)
{
PyObject *result; /* Valeur à retourner */
GBinSymbol *symbol; /* Elément à consulter */
- const mrange_t *range; /* Couverture courante */
+ SymbolStatus status; /* Visibilité du symbole fourni*/
+
+#define BINARY_SYMBOL_STATUS_ATTRIB PYTHON_GETSET_DEF_FULL \
+( \
+ status, py_binary_symbol, \
+ "Status of the symbol's visibility, as a value of type" \
+ " pychrysalide.format.BinSymbol.SymbolStatus." \
+)
symbol = G_BIN_SYMBOL(pygobject_get(self));
- range = g_binary_symbol_get_range(symbol);
+ status = g_binary_symbol_get_status(symbol);
- result = build_from_internal_mrange(range);
+ result = cast_with_constants_group(get_python_binary_symbol_type(), "SymbolStatus", status);
return result;
@@ -303,28 +356,26 @@ static PyObject *py_binary_symbol_get_range(PyObject *self, void *closure)
* value = valeur fournie à intégrer ou prendre en compte. *
* closure = adresse non utilisée ici. *
* *
-* Description : Définit la couverture physique / en mémoire d'un symbole. *
+* Description : Définit la visibilité du symbole. *
* *
-* Retour : - *
+* Retour : Bilan de l'opération. *
* *
* Remarques : - *
* *
******************************************************************************/
-static int py_binary_symbol_set_range(PyObject *self, PyObject *value, void *closure)
+static int py_binary_symbol_set_status(PyObject *self, PyObject *value, void *closure)
{
- int ret; /* Bilan d'analyse */
- mrange_t *range; /* Espace mémoire à manipuler */
GBinSymbol *symbol; /* Elément à consulter */
+ SymbolStatus status; /* Visibilité à définir */
- ret = PyObject_IsInstance(value, (PyObject *)get_python_mrange_type());
- if (!ret) return -1;
-
- range = get_internal_mrange(value);
+ if (!PyLong_Check(value))
+ return -1;
symbol = G_BIN_SYMBOL(pygobject_get(self));
+ status = PyLong_AsUnsignedLong(value);
- g_binary_symbol_set_range(symbol, range);
+ g_binary_symbol_set_status(symbol, status);
return 0;
@@ -336,30 +387,39 @@ static int py_binary_symbol_set_range(PyObject *self, PyObject *value, void *clo
* Paramètres : self = objet Python concerné par l'appel. *
* closure = non utilisé ici. *
* *
-* Description : Fournit la visibilité du symbole. *
+* Description : Fournit un étiquette pour viser un symbole. *
* *
-* Retour : Etat de la visibilité du symbole représenté. *
+* Retour : Chaîne de caractères renvoyant au symbole. *
* *
* Remarques : - *
* *
******************************************************************************/
-static PyObject *py_binary_symbol_get_status(PyObject *self, void *closure)
+static PyObject *py_binary_symbol_get_label(PyObject *self, void *closure)
{
PyObject *result; /* Valeur à retourner */
GBinSymbol *symbol; /* Elément à consulter */
- SymbolStatus status; /* Visibilité du symbole fourni*/
+ char *label; /* Désignation courante */
-#define BINARY_SYMBOL_STATUS_ATTRIB PYTHON_GET_DEF_FULL \
-( \
- status, py_binary_symbol, \
- "Status of the symbol's visibility." \
+#define BINARY_SYMBOL_LABEL_ATTRIB PYTHON_GETSET_DEF_FULL \
+( \
+ label, py_binary_symbol, \
+ "Label of the symbol, provided by the internal component or by the user." \
)
symbol = G_BIN_SYMBOL(pygobject_get(self));
- status = g_binary_symbol_get_status(symbol);
+ label = g_binary_symbol_get_label(symbol);
- result = cast_with_constants_group(get_python_binary_symbol_type(), "SymbolStatus", status);
+ if (label != NULL)
+ {
+ result = PyUnicode_FromString(label);
+ free(label);
+ }
+ else
+ {
+ result = Py_None;
+ Py_INCREF(result);
+ }
return result;
@@ -368,37 +428,40 @@ static PyObject *py_binary_symbol_get_status(PyObject *self, void *closure)
/******************************************************************************
* *
-* Paramètres : obj_type = type dont le dictionnaire est à compléter. *
+* Paramètres : self = objet Python concerné par l'appel. *
+* value = valeur fournie à intégrer ou prendre en compte. *
+* closure = adresse non utilisée ici. *
* *
-* Description : Définit les constantes pour les symboles binaires. *
+* Description : Définit un autre nom pour le symbole. *
* *
-* Retour : true en cas de succès de l'opération, false sinon. *
+* Retour : Bilan de l'opération. *
* *
* Remarques : - *
* *
******************************************************************************/
-static bool py_binary_symbol_define_constants(PyTypeObject *obj_type)
+static int py_binary_symbol_set_label(PyObject *self, PyObject *value, void *closure)
{
- bool result; /* Bilan à retourner */
+ const char *alt; /* Etiquette alternative */
+ GBinSymbol *symbol; /* Elément à consulter */
+
+ if (value == Py_None)
+ alt = NULL;
+
+ else
+ {
+ if (!PyUnicode_Check(value))
+ return -1;
- result = true;
+ alt = PyUnicode_DATA(value);
- result &= PyDict_AddULongMacro(obj_type, STP_DATA);
- result &= PyDict_AddULongMacro(obj_type, STP_ROUTINE);
- result &= PyDict_AddULongMacro(obj_type, STP_CODE_LABEL);
- result &= PyDict_AddULongMacro(obj_type, STP_OBJECT);
- result &= PyDict_AddULongMacro(obj_type, STP_ENTRY_POINT);
- result &= PyDict_AddULongMacro(obj_type, STP_RO_STRING);
- result &= PyDict_AddULongMacro(obj_type, STP_DYN_STRING);
- result &= PyDict_AddULongMacro(obj_type, STP_COUNT);
+ }
- result &= PyDict_AddULongMacro(obj_type, SSS_INTERNAL);
- result &= PyDict_AddULongMacro(obj_type, SSS_EXPORTED);
- result &= PyDict_AddULongMacro(obj_type, SSS_IMPORTED);
- result &= PyDict_AddULongMacro(obj_type, SSS_DYNAMIC);
+ symbol = G_BIN_SYMBOL(pygobject_get(self));
- return result;
+ g_binary_symbol_set_alt_label(symbol, alt);
+
+ return 0;
}
@@ -418,28 +481,14 @@ static bool py_binary_symbol_define_constants(PyTypeObject *obj_type)
PyTypeObject *get_python_binary_symbol_type(void)
{
static PyMethodDef py_bin_symbol_methods[] = {
- {
- "set_alt_label", py_binary_symbol_set_alt_label,
- METH_VARARGS,
- "set_alt_label($self, alt, /)\n--\n\nSet an alternative label for the symbol."
- },
{ NULL }
};
static PyGetSetDef py_bin_symbol_getseters[] = {
- {
- "target_type", py_binary_symbol_get_target_type, NULL,
- "Type of the current symbol.", NULL
- },
- {
- "label", py_binary_symbol_get_label, NULL,
- "Label of the symbol, provided by the internal component or by an alternative label.", NULL
- },
- {
- "range", py_binary_symbol_get_range, py_binary_symbol_set_range,
- "Range covered by the symbol.", NULL
- },
+ BINARY_SYMBOL_RANGE_ATTRIB,
+ BINARY_SYMBOL_STYPE_ATTRIB,
BINARY_SYMBOL_STATUS_ATTRIB,
+ BINARY_SYMBOL_LABEL_ATTRIB,
{ NULL }
};
@@ -452,7 +501,7 @@ PyTypeObject *get_python_binary_symbol_type(void)
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- .tp_doc = "PyChrysalide binary symbol",
+ .tp_doc = BINARY_SYMBOL_DOC,
.tp_richcompare = py_binary_symbol_richcompare,
@@ -499,9 +548,6 @@ bool ensure_python_binary_symbol_is_registered(void)
if (!register_class_for_pygobject(dict, G_TYPE_BIN_SYMBOL, type, &PyGObject_Type))
return false;
- if (!py_binary_symbol_define_constants(type))
- return false;
-
if (!define_binary_symbol_constants(type))
return false;
diff --git a/src/analysis/binary.c b/src/analysis/binary.c
index cfb4ea0..80d12d3 100644
--- a/src/analysis/binary.c
+++ b/src/analysis/binary.c
@@ -1823,7 +1823,7 @@ static void on_binary_processor_changed(GArchProcessor *proc, GArchInstruction *
* la fonction print_disassembled_instructions().
*/
- stype = g_binary_symbol_get_target_type(symbol);
+ stype = g_binary_symbol_get_stype(symbol);
if (stype == STP_ENTRY_POINT)
flags |= BLF_ENTRYPOINT;
diff --git a/src/analysis/disass/area.c b/src/analysis/disass/area.c
index 9649d6f..5569a11 100644
--- a/src/analysis/disass/area.c
+++ b/src/analysis/disass/area.c
@@ -675,7 +675,7 @@ static void update_address_as_routine(GBinFormat *format, const vmpa2t *addr)
if (found)
{
- sym_type = g_binary_symbol_get_target_type(symbol);
+ sym_type = g_binary_symbol_get_stype(symbol);
wrong_type = (sym_type != STP_ROUTINE && sym_type != STP_ENTRY_POINT);
}
diff --git a/src/analysis/disass/output.c b/src/analysis/disass/output.c
index 83a6815..932e9cc 100644
--- a/src/analysis/disass/output.c
+++ b/src/analysis/disass/output.c
@@ -239,7 +239,7 @@ void print_disassembled_instructions(GBufferCache *cache, GCodingLanguage *lang,
{
/* Coupure pour une nouvelle routine */
- stype = g_binary_symbol_get_target_type(symbol);
+ stype = g_binary_symbol_get_stype(symbol);
if (stype == STP_ROUTINE || stype == STP_ENTRY_POINT)
{
diff --git a/src/analysis/disass/routines.c b/src/analysis/disass/routines.c
index d7821d0..42eee76 100644
--- a/src/analysis/disass/routines.c
+++ b/src/analysis/disass/routines.c
@@ -252,7 +252,7 @@ static void g_routines_study_process(GRoutinesStudy *study, GtkStatusStack *stat
{
symbol = g_binary_format_get_symbol(study->format, i);
- type = g_binary_symbol_get_target_type(symbol);
+ type = g_binary_symbol_get_stype(symbol);
if (type == STP_ROUTINE || type == STP_ENTRY_POINT)
study->fallback(study, G_BIN_ROUTINE(symbol), i);
@@ -302,7 +302,7 @@ void g_routines_study_compute_limits(GRoutinesStudy *study, GBinRoutine *routine
* symboles suivants.
*/
- if (g_binary_symbol_get_target_type(next_symbol) == STP_CODE_LABEL)
+ if (g_binary_symbol_get_stype(next_symbol) == STP_CODE_LABEL)
goto skip_symbol;
range = g_binary_symbol_get_range(next_symbol);
diff --git a/src/analysis/routine.c b/src/analysis/routine.c
index 41e314c..21abe9c 100644
--- a/src/analysis/routine.c
+++ b/src/analysis/routine.c
@@ -110,7 +110,7 @@ static void g_bin_routine_init(GBinRoutine *routine)
symbol = G_BIN_SYMBOL(routine);
- g_binary_symbol_set_target_type(symbol, STP_ROUTINE);
+ g_binary_symbol_set_stype(symbol, STP_ROUTINE);
routine->ret_type = NULL;
diff --git a/src/arch/target.c b/src/arch/target.c
index db4d058..a8acd67 100644
--- a/src/arch/target.c
+++ b/src/arch/target.c
@@ -412,7 +412,7 @@ static char *g_target_operand_build_tooltip(const GTargetOperand *operand, const
if (operand->symbol != NULL && operand->diff == 0)
{
- stype = g_binary_symbol_get_target_type(operand->symbol);
+ stype = g_binary_symbol_get_stype(operand->symbol);
switch (stype)
{
diff --git a/src/format/strsym.c b/src/format/strsym.c
index ed38a6b..ecfcc55 100644
--- a/src/format/strsym.c
+++ b/src/format/strsym.c
@@ -255,7 +255,7 @@ GBinSymbol *g_string_symbol_new_read_only(GBinFormat *format, const mrange_t *ra
parent = G_BIN_SYMBOL(result);
g_binary_symbol_set_range(parent, range);
- g_binary_symbol_set_target_type(parent, STP_RO_STRING);
+ g_binary_symbol_set_stype(parent, STP_RO_STRING);
result->encoding = encoding;
@@ -296,7 +296,7 @@ GBinSymbol *g_string_symbol_new_dynamic(const char *string, const vmpa2t *addr,
init_mrange(&range, addr, strlen(string));
g_binary_symbol_set_range(parent, &range);
- g_binary_symbol_set_target_type(parent, STP_DYN_STRING);
+ g_binary_symbol_set_stype(parent, STP_DYN_STRING);
result->encoding = encoding;
diff --git a/src/format/symbol-int.h b/src/format/symbol-int.h
index 1b8672d..d6717ac 100644
--- a/src/format/symbol-int.h
+++ b/src/format/symbol-int.h
@@ -40,7 +40,7 @@ struct _GBinSymbol
GObject parent; /* A laisser en premier */
mrange_t range; /* Couverture mémoire */
- SymbolType type; /* Type du symbole */
+ SymbolType stype; /* Type du symbole */
SymbolStatus status; /* Visibilité du symbole */
char *alt; /* Nom alternatif */
diff --git a/src/format/symbol.c b/src/format/symbol.c
index 22403c5..149dd2a 100644
--- a/src/format/symbol.c
+++ b/src/format/symbol.c
@@ -123,7 +123,7 @@ static void g_binary_symbol_class_init(GBinSymbolClass *klass)
static void g_binary_symbol_init(GBinSymbol *symbol)
{
- g_binary_symbol_set_target_type(symbol, STP_COUNT);
+ g_binary_symbol_set_stype(symbol, STP_COUNT);
g_binary_symbol_set_status(symbol, SSS_INTERNAL);
@@ -214,7 +214,7 @@ GBinSymbol *g_binary_symbol_new(const mrange_t *range, SymbolType type)
result = g_object_new(G_TYPE_BIN_SYMBOL, NULL);
g_binary_symbol_set_range(result, range);
- g_binary_symbol_set_target_type(result, type);
+ g_binary_symbol_set_stype(result, type);
return result;
@@ -326,9 +326,9 @@ const mrange_t *g_binary_symbol_get_range(const GBinSymbol *symbol)
* *
******************************************************************************/
-void g_binary_symbol_set_target_type(GBinSymbol *symbol, SymbolType type)
+void g_binary_symbol_set_stype(GBinSymbol *symbol, SymbolType type)
{
- symbol->type = type;
+ symbol->stype = type;
}
@@ -345,9 +345,9 @@ void g_binary_symbol_set_target_type(GBinSymbol *symbol, SymbolType type)
* *
******************************************************************************/
-SymbolType g_binary_symbol_get_target_type(const GBinSymbol *symbol)
+SymbolType g_binary_symbol_get_stype(const GBinSymbol *symbol)
{
- return symbol->type;
+ return symbol->stype;
}
diff --git a/src/format/symbol.h b/src/format/symbol.h
index 577a6a0..14fed23 100644
--- a/src/format/symbol.h
+++ b/src/format/symbol.h
@@ -98,10 +98,10 @@ void g_binary_symbol_set_range(GBinSymbol *, const mrange_t *);
const mrange_t *g_binary_symbol_get_range(const GBinSymbol *);
/* Définit le type du symbole. */
-void g_binary_symbol_set_target_type(GBinSymbol *, SymbolType);
+void g_binary_symbol_set_stype(GBinSymbol *, SymbolType);
/* Fournit le type du symbole. */
-SymbolType g_binary_symbol_get_target_type(const GBinSymbol *);
+SymbolType g_binary_symbol_get_stype(const GBinSymbol *);
/* Définit la visibilité du symbole. */
void g_binary_symbol_set_status(GBinSymbol *, SymbolStatus);
diff --git a/src/gtkext/gtkgraphdisplay.c b/src/gtkext/gtkgraphdisplay.c
index aeecc0f..ed3c923 100644
--- a/src/gtkext/gtkgraphdisplay.c
+++ b/src/gtkext/gtkgraphdisplay.c
@@ -941,7 +941,7 @@ static void gtk_graph_display_prepare_for_cursor(GtkGraphDisplay *display, const
if (!found)
goto no_symbol_found;
- type = g_binary_symbol_get_target_type(symbol);
+ type = g_binary_symbol_get_stype(symbol);
if (type != STP_ROUTINE && type != STP_ENTRY_POINT)
goto bad_symbol_type;
diff --git a/src/gui/dialogs/gotox.c b/src/gui/dialogs/gotox.c
index 97c031e..2993999 100644
--- a/src/gui/dialogs/gotox.c
+++ b/src/gui/dialogs/gotox.c
@@ -240,7 +240,7 @@ GtkWidget *create_gotox_dialog_for_entry_points(GtkWindow *parent, GLoadedBinary
symbol != NULL;
symbol = get_symbol_iterator_next(siter))
{
- if (g_binary_symbol_get_target_type(symbol) != STP_ENTRY_POINT)
+ if (g_binary_symbol_get_stype(symbol) != STP_ENTRY_POINT)
goto cgdfep_next;
copy_vmpa(&addr, get_mrange_addr(g_binary_symbol_get_range(symbol)));
@@ -475,7 +475,7 @@ static void add_new_location_to_list(GtkTreeStore *store, GLoadedBinary *binary,
filename = NULL;
else
- switch (g_binary_symbol_get_target_type(symbol))
+ switch (g_binary_symbol_get_stype(symbol))
{
case STP_ENTRY_POINT:
filename = find_pixmap_file("entrypoint.png");
diff --git a/src/gui/panels/symbols.c b/src/gui/panels/symbols.c
index 6ea7a72..7901df0 100644
--- a/src/gui/panels/symbols.c
+++ b/src/gui/panels/symbols.c
@@ -799,7 +799,7 @@ static void reload_symbols_for_new_list_view(const GSymbolsPanel *panel, GtkStat
symbol != NULL;
symbol = get_symbol_iterator_next(siter))
{
- switch (g_binary_symbol_get_target_type(symbol))
+ switch (g_binary_symbol_get_stype(symbol))
{
case STP_ROUTINE:
case STP_ENTRY_POINT:
@@ -1080,7 +1080,7 @@ static void reload_symbols_for_new_tree_view(const GSymbolsPanel *panel, GtkStat
symbol != NULL;
symbol = get_symbol_iterator_next(siter))
{
- switch (g_binary_symbol_get_target_type(symbol))
+ switch (g_binary_symbol_get_stype(symbol))
{
case STP_ROUTINE:
case STP_ENTRY_POINT:
@@ -1480,7 +1480,7 @@ static bool is_symbol_matching(const symbols_update_data *data, const GBinSymbol
#ifndef NDEBUG
- type = g_binary_symbol_get_target_type(symbol);
+ type = g_binary_symbol_get_stype(symbol);
assert(type == STP_ROUTINE || type == STP_ENTRY_POINT || type == STP_OBJECT);
diff --git a/src/panels/strings.c b/src/panels/strings.c
index c60ef0a..25d1e41 100644
--- a/src/panels/strings.c
+++ b/src/panels/strings.c
@@ -137,7 +137,7 @@ void handle_new_exe_on_strings_panel(GtkWidget *panel, const GExeFormat *format)
{
if (g_binary_symbol_get_status(symbols[i]) == SSS_IMPORTED) continue;
- if (g_binary_symbol_get_target_type(symbols[i]) != STP_STRING) continue;
+ if (g_binary_symbol_get_stype(symbols[i]) != STP_STRING) continue;
range = g_binary_symbol_get_range(symbols[i]);
mrange_virt_to_string(range, MDS_UNDEFINED, true, address, NULL);
diff --git a/tests/format/symbol.py b/tests/format/symbol.py
index 5d6be45..5e0ba10 100644
--- a/tests/format/symbol.py
+++ b/tests/format/symbol.py
@@ -14,12 +14,48 @@ class TestBinarySymbols(ChrysalideTestCase):
"""TestCase for format.BinSymbol."""
+ def testSymbolProperties(self):
+ """Validate the basic properties of symbols."""
+
+ saddr = vmpa(0x10, vmpa.VMPA_NO_VIRTUAL)
+ srange = mrange(saddr, 0x3)
+ symbol = BinSymbol(BinSymbol.SymbolType.ENTRY_POINT, srange)
+
+ self.assertEqual(symbol.range.length, 0x3)
+
+ symbol.range = mrange(saddr, 0x4)
+
+ self.assertEqual(symbol.range.length, 0x4)
+
+ self.assertEqual(symbol.stype, BinSymbol.SymbolType.ENTRY_POINT)
+
+ symbol.stype = BinSymbol.SymbolType.DATA
+
+ self.assertEqual(symbol.stype, BinSymbol.SymbolType.DATA)
+
+ self.assertEqual(symbol.status, BinSymbol.SymbolStatus.INTERNAL)
+
+ symbol.status = BinSymbol.SymbolStatus.EXPORTED
+
+ self.assertEqual(symbol.status, BinSymbol.SymbolStatus.EXPORTED)
+
+ self.assertEqual(symbol.label, None)
+
+ symbol.label = 'AAA'
+
+ self.assertEqual(symbol.label, 'AAA')
+
+ symbol.label = None
+
+ self.assertEqual(symbol.label, None)
+
+
def testSymbolDefaultStatus(self):
"""Validate the default status for symbols."""
saddr = vmpa(0x10, vmpa.VMPA_NO_VIRTUAL)
srange = mrange(saddr, 0x3)
- symbol = BinSymbol(BinSymbol.STP_ENTRY_POINT, srange)
+ symbol = BinSymbol(BinSymbol.SymbolType.ENTRY_POINT, srange)
self.assertEqual(symbol.status, BinSymbol.SymbolStatus.INTERNAL)
@@ -31,15 +67,15 @@ class TestBinarySymbols(ChrysalideTestCase):
saddr = vmpa(0x100, vmpa.VMPA_NO_VIRTUAL)
srange = mrange(saddr, 0x3)
- symbol0 = BinSymbol(BinSymbol.STP_ENTRY_POINT, srange)
+ symbol0 = BinSymbol(BinSymbol.SymbolType.ENTRY_POINT, srange)
saddr = vmpa(0x10, vmpa.VMPA_NO_VIRTUAL)
srange = mrange(saddr, 0x3)
- symbol1 = BinSymbol(BinSymbol.STP_ENTRY_POINT, srange)
+ symbol1 = BinSymbol(BinSymbol.SymbolType.ENTRY_POINT, srange)
saddr = vmpa(0x100, vmpa.VMPA_NO_VIRTUAL)
srange = mrange(saddr, 0x30)
- symbol2 = BinSymbol(BinSymbol.STP_ENTRY_POINT, srange)
+ symbol2 = BinSymbol(BinSymbol.SymbolType.ENTRY_POINT, srange)
self.assertTrue(symbol0 == symbol0)