diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2019-07-07 21:46:38 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2019-07-07 21:46:38 (GMT) |
commit | 24f4b449d22c918d8f0e6c8fc059e0fa1fa485ff (patch) | |
tree | 0652f6fc72996447cb050fefb9daf6da43de999a /plugins/pychrysalide/format | |
parent | 13a879ebcf58f3868c0275d84dd9886673c9e614 (diff) |
Added support for Android boot images.
Diffstat (limited to 'plugins/pychrysalide/format')
-rw-r--r-- | plugins/pychrysalide/format/Makefile.am | 1 | ||||
-rw-r--r-- | plugins/pychrysalide/format/known.c | 292 | ||||
-rw-r--r-- | plugins/pychrysalide/format/known.h | 42 | ||||
-rw-r--r-- | plugins/pychrysalide/format/module.c | 2 |
4 files changed, 337 insertions, 0 deletions
diff --git a/plugins/pychrysalide/format/Makefile.am b/plugins/pychrysalide/format/Makefile.am index 847f8e4..6d50da7 100644 --- a/plugins/pychrysalide/format/Makefile.am +++ b/plugins/pychrysalide/format/Makefile.am @@ -5,6 +5,7 @@ libpychrysaformat_la_SOURCES = \ executable.h executable.c \ flat.h flat.c \ format.h format.c \ + known.h known.c \ module.h module.c \ strsym.h strsym.c \ symbol.h symbol.c \ diff --git a/plugins/pychrysalide/format/known.c b/plugins/pychrysalide/format/known.c new file mode 100644 index 0000000..e19a4a2 --- /dev/null +++ b/plugins/pychrysalide/format/known.c @@ -0,0 +1,292 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * known.c - équivalent Python du fichier "format/known.c" + * + * Copyright (C) 2019 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 "known.h" + + +#include <pygobject.h> + + +#include <format/known.h> + + +#include "../access.h" +#include "../helpers.h" + + + +/* Assure l'interprétation d'un format en différé. */ +static PyObject *py_known_format_analyze(PyObject *, PyObject *); + +/* Indique la désignation interne du format. */ +static PyObject *py_known_format_get_name(PyObject *, void *); + +/* Indique la désignation humaine du format. */ +static PyObject *py_known_format_get_description(PyObject *, void *); + +/* Fournit une référence vers le contenu binaire analysé. */ +static PyObject *py_known_format_get_content(PyObject *, void *); + + + +#define KNOWN_FORMAT_DOC \ + "KnownFormat is a small class providing basic features for recognized formats." + + + +/****************************************************************************** +* * +* Paramètres : self = objet représentant un format connu. * +* args = arguments fournis pour l'opération. * +* * +* Description : Assure l'interprétation d'un format en différé. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_known_format_analyze(PyObject *self, PyObject *args) +{ + PyObject *result; /* Bilan à retourner */ + int ret; /* Bilan de lecture des args. */ + GKnownFormat *format; /* Format connu manipulé */ + bool status; /* Bilan de l'opération */ + +#define KNOWN_FORMAT_ANALYZE_METHOD PYTHON_METHOD_DEF \ +( \ + analyze, "$self, /, gid, status", \ + METH_VARARGS, py_known_format, \ + "Start the analysis of the known format and return its status." \ +) + + ret = PyArg_ParseTuple(args, "");//|KO!", &gid, &status); + if (!ret) return NULL; + + format = G_KNOWN_FORMAT(pygobject_get(self)); + + status = g_known_format_analyze(format, 0, NULL); + + result = status ? Py_True : Py_False; + Py_INCREF(result); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Indique la désignation interne du format. * +* * +* Retour : Description du format. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_known_format_get_name(PyObject *self, void *closure) +{ + PyObject *result; /* Trouvailles à retourner */ + GKnownFormat *format; /* Format de binaire manipulé */ + const char *name; /* Description interne */ + +#define KNOWN_FORMAT_NAME_ATTRIB PYTHON_GET_DEF_FULL \ +( \ + name, py_known_format, \ + "Internal name of the known format." \ +) + + format = G_KNOWN_FORMAT(pygobject_get(self)); + + name = g_known_format_get_name(format); + + result = PyUnicode_FromString(name); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Indique la désignation humaine du format. * +* * +* Retour : Description du format. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_known_format_get_description(PyObject *self, void *closure) +{ + PyObject *result; /* Trouvailles à retourner */ + GKnownFormat *format; /* Format de binaire manipulé */ + const char *desc; /* Description humaine */ + +#define KNOWN_FORMAT_DESCRIPTION_ATTRIB PYTHON_GET_DEF_FULL \ +( \ + description, py_known_format, \ + "Human description of the known format." \ +) + + format = G_KNOWN_FORMAT(pygobject_get(self)); + + desc = g_known_format_get_description(format); + + result = PyUnicode_FromString(desc); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Fournit une référence vers le contenu binaire analysé. * +* * +* Retour : Gestionnaire de contenu binaire en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_known_format_get_content(PyObject *self, void *closure) +{ + PyObject *result; /* Trouvailles à retourner */ + GKnownFormat *format; /* Format de binaire manipulé */ + GBinContent *content; /* Instance GLib correspondante*/ + +#define KNOWN_FORMAT_CONTENT_ATTRIB PYTHON_GET_DEF_FULL \ +( \ + content, py_known_format, \ + "Binary content linked to the known format." \ +) + + format = G_KNOWN_FORMAT(pygobject_get(self)); + + content = g_known_format_get_content(format); + + result = pygobject_new(G_OBJECT(content)); + + g_object_unref(content); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *get_python_known_format_type(void) +{ + static PyMethodDef py_known_format_methods[] = { + KNOWN_FORMAT_ANALYZE_METHOD, + { NULL } + }; + + static PyGetSetDef py_known_format_getseters[] = { + KNOWN_FORMAT_NAME_ATTRIB, + KNOWN_FORMAT_DESCRIPTION_ATTRIB, + KNOWN_FORMAT_CONTENT_ATTRIB, + { NULL } + }; + + static PyTypeObject py_known_format_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.format.KnownFormat", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_BASETYPE, + + .tp_doc = KNOWN_FORMAT_DOC, + + .tp_methods = py_known_format_methods, + .tp_getset = py_known_format_getseters + + }; + + return &py_known_format_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.format.BinFormat'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool ensure_python_known_format_is_registered(void) +{ + PyTypeObject *type; /* Type Python 'BinFormat' */ + PyObject *module; /* Module à recompléter */ + PyObject *dict; /* Dictionnaire du module */ + + type = get_python_known_format_type(); + + if (!PyType_HasFeature(type, Py_TPFLAGS_READY)) + { + module = get_access_to_python_module("pychrysalide.format"); + + APPLY_ABSTRACT_FLAG(type); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_KNOWN_FORMAT, type, &PyGObject_Type)) + return false; + + } + + return true; + +} diff --git a/plugins/pychrysalide/format/known.h b/plugins/pychrysalide/format/known.h new file mode 100644 index 0000000..16cbf83 --- /dev/null +++ b/plugins/pychrysalide/format/known.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * known.h - prototypes pour l'équivalent Python du fichier "format/known.h" + * + * Copyright (C) 2019 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_FORMAT_KNOWN_H +#define _PLUGINS_PYCHRYSALIDE_FORMAT_KNOWN_H + + +#include <Python.h> +#include <stdbool.h> + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_known_format_type(void); + +/* Prend en charge l'objet 'pychrysalide.format.KnownFormat'. */ +bool ensure_python_known_format_is_registered(void); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_FORMAT_KNOWN_H */ diff --git a/plugins/pychrysalide/format/module.c b/plugins/pychrysalide/format/module.c index 2f90792..f5768d1 100644 --- a/plugins/pychrysalide/format/module.c +++ b/plugins/pychrysalide/format/module.c @@ -31,6 +31,7 @@ #include "executable.h" #include "flat.h" #include "format.h" +#include "known.h" #include "strsym.h" #include "symbol.h" #include "symiter.h" @@ -95,6 +96,7 @@ bool populate_format_module(void) if (result) result = ensure_python_executable_format_is_registered(); if (result) result = ensure_python_flat_format_is_registered(); + if (result) result = ensure_python_known_format_is_registered(); if (result) result = ensure_python_binary_format_is_registered(); if (result) result = ensure_python_string_symbol_is_registered(); if (result) result = ensure_python_binary_symbol_is_registered(); |