summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2017-11-27 22:18:12 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2017-11-27 22:18:12 (GMT)
commit046c2cfac39e686dee65cdf54035dc5a975bc57f (patch)
treeca578f4576c58a57aa257d5140cdeeeaabb3b7b0 /plugins
parent903006678160f620b947d5fbce2a8e257a357d77 (diff)
Added offset and address translations to the Python bindings.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/pychrysa/arch/vmpa.c15
-rw-r--r--plugins/pychrysa/format/executable.c107
2 files changed, 117 insertions, 5 deletions
diff --git a/plugins/pychrysa/arch/vmpa.c b/plugins/pychrysa/arch/vmpa.c
index 8d42a78..af1557d 100644
--- a/plugins/pychrysa/arch/vmpa.c
+++ b/plugins/pychrysa/arch/vmpa.c
@@ -159,25 +159,30 @@ static PyObject *py_vmpa_to_str(PyObject *obj)
{
PyObject *result; /* Chaîne à retourner */
vmpa2t *addr; /* Véritable adresse manipulée */
- off_t physical; /* Position physique */
- uint64_t virtual; /* Adresse virtuelle */
+ phys_t physical; /* Position physique */
+ virt_t virtual; /* Adresse virtuelle */
+ VMPA_BUFFER(phys_str); /* Version humaine de position */
+ VMPA_BUFFER(virt_str); /* Version humaine d'adresse */
addr = &((py_vmpa_t *)obj)->addr;
physical = get_phy_addr(addr);
virtual = get_virt_addr(addr);
+ vmpa2_phys_to_string(addr, MDS_UNDEFINED, phys_str, NULL);
+ vmpa2_phys_to_string(addr, MDS_UNDEFINED, virt_str, NULL);
+
if (physical == VMPA_NO_PHYSICAL && virtual == VMPA_NO_VIRTUAL)
result = PyUnicode_FromFormat("<phy=None, virt=None>");
else if (physical != VMPA_NO_PHYSICAL && virtual == VMPA_NO_VIRTUAL)
- result = PyUnicode_FromFormat("<phy=%d, virt=None>", physical);
+ result = PyUnicode_FromFormat("<phy=%s, virt=None>", phys_str);
else if (physical == VMPA_NO_PHYSICAL && virtual != VMPA_NO_VIRTUAL)
- result = PyUnicode_FromFormat("<phy=None, virt=0x%08x>", virtual);
+ result = PyUnicode_FromFormat("<phy=None, virt=%s>", virt_str);
else
- result = PyUnicode_FromFormat("<phy=%d, virt=0x%08x>", physical, virtual);
+ result = PyUnicode_FromFormat("<phy=%s, virt=%s>", phys_str, virt_str);
return result;
diff --git a/plugins/pychrysa/format/executable.c b/plugins/pychrysa/format/executable.c
index 96b5e82..1b1bfe8 100644
--- a/plugins/pychrysa/format/executable.c
+++ b/plugins/pychrysa/format/executable.c
@@ -33,9 +33,106 @@
#include "format.h"
#include "../helpers.h"
+#include "../arch/vmpa.h"
+/* Fournit l'emplacement correspondant à une position physique. */
+static PyObject *py_exe_format_translate_offset_into_vmpa(PyObject *, PyObject *);
+
+/* Fournit l'emplacement correspondant à une adresse virtuelle. */
+static PyObject *py_exe_format_translate_address_into_vmpa(PyObject *, PyObject *);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : self = description de l'exécutable à consulter. *
+* args = arguments accompagnant l'appel. *
+* *
+* Description : Fournit l'emplacement correspondant à une position physique. *
+* *
+* Retour : Position correspondante ou None. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_exe_format_translate_offset_into_vmpa(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Instance à retourner */
+ GExeFormat *format; /* Version GLib du format */
+ unsigned long long off; /* Adresse en mémoire virtuelle*/
+ int ret; /* Bilan de lecture des args. */
+ vmpa2t pos; /* Position complète déterminée*/
+ bool status; /* Bilan de l'opération */
+
+ format = G_EXE_FORMAT(pygobject_get(self));
+ assert(format != NULL);
+
+ ret = PyArg_ParseTuple(args, "K", &off);
+ if (!ret) return NULL;
+
+ status = g_exe_format_translate_offset_into_vmpa(format, off, &pos);
+
+ if (status)
+ result = build_from_internal_vmpa(&pos);
+
+ else
+ {
+ result = Py_None;
+ Py_INCREF(result);
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : self = description de l'exécutable à consulter. *
+* args = arguments accompagnant l'appel. *
+* *
+* Description : Fournit l'emplacement correspondant à une adresse virtuelle. *
+* *
+* Retour : Position correspondante ou None. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_exe_format_translate_address_into_vmpa(PyObject *self, PyObject *args)
+{
+ PyObject *result; /* Instance à retourner */
+ GExeFormat *format; /* Version GLib du format */
+ unsigned long long addr; /* Adresse en mémoire virtuelle*/
+ int ret; /* Bilan de lecture des args. */
+ vmpa2t pos; /* Position complète déterminée*/
+ bool status; /* Bilan de l'opération */
+
+ format = G_EXE_FORMAT(pygobject_get(self));
+ assert(format != NULL);
+
+ ret = PyArg_ParseTuple(args, "K", &addr);
+ if (!ret) return NULL;
+
+ status = g_exe_format_translate_address_into_vmpa(format, addr, &pos);
+
+ if (status)
+ result = build_from_internal_vmpa(&pos);
+
+ else
+ {
+ result = Py_None;
+ Py_INCREF(result);
+ }
+
+ return result;
+
+}
+
+
/******************************************************************************
* *
* Paramètres : - *
@@ -51,6 +148,16 @@
PyTypeObject *get_python_executable_format_type(void)
{
static PyMethodDef py_exe_format_methods[] = {
+ {
+ "translate_offset_into_vmpa", py_exe_format_translate_offset_into_vmpa,
+ METH_VARARGS,
+ "translate_offset_into_vmpa($self, off, /)\n--\n\nTranslate a physical offset to a full location.."
+ },
+ {
+ "translate_address_into_vmpa", py_exe_format_translate_address_into_vmpa,
+ METH_VARARGS,
+ "translate_address_into_vmpa($self, addr, /)\n--\n\nTranslate a physical offset to a full location.."
+ },
{ NULL }
};