From 9da8f8b37e3edebc917b4e223dd2447cd7cbc818 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Tue, 16 Jan 2018 20:02:56 +0100 Subject: Changed the Python bindings source directory and updated code. --- ChangeLog | 157 +++ configure.ac | 30 +- plugins/Makefile.am | 2 +- plugins/arm/python/instruction.c | 4 +- plugins/arm/python/module.c | 2 +- plugins/arm/python/processor.c | 4 +- plugins/arm/python/v7/instruction.c | 2 +- plugins/arm/python/v7/processor.c | 2 +- plugins/dex/python/class.c | 2 +- plugins/dex/python/format.c | 8 +- plugins/dex/python/module.c | 2 +- plugins/elf/python/constants.c | 2 +- plugins/elf/python/format.c | 6 +- plugins/elf/python/module.c | 2 +- plugins/elf/python/translate.c | 2 +- plugins/pychrysa/Makefile.am | 36 - plugins/pychrysa/access.c | 137 -- plugins/pychrysa/access.h | 40 - plugins/pychrysa/analysis/Makefile.am | 24 - plugins/pychrysa/analysis/binary.c | 381 ------ plugins/pychrysa/analysis/binary.h | 42 - plugins/pychrysa/analysis/block.c | 274 ---- plugins/pychrysa/analysis/block.h | 42 - plugins/pychrysa/analysis/content.c | 460 ------- plugins/pychrysa/analysis/content.h | 42 - plugins/pychrysa/analysis/contents/Makefile.am | 15 - plugins/pychrysa/analysis/contents/file.c | 149 --- plugins/pychrysa/analysis/contents/file.h | 42 - plugins/pychrysa/analysis/contents/module.c | 97 -- plugins/pychrysa/analysis/contents/module.h | 39 - plugins/pychrysa/analysis/contents/restricted.c | 173 --- plugins/pychrysa/analysis/contents/restricted.h | 42 - plugins/pychrysa/analysis/db/Makefile.am | 19 - plugins/pychrysa/analysis/db/certs.c | 327 ----- plugins/pychrysa/analysis/db/certs.h | 42 - plugins/pychrysa/analysis/db/collection.c | 110 -- plugins/pychrysa/analysis/db/collection.h | 42 - plugins/pychrysa/analysis/db/item.c | 182 --- plugins/pychrysa/analysis/db/item.h | 42 - plugins/pychrysa/analysis/db/items/Makefile.am | 14 - plugins/pychrysa/analysis/db/items/comment.c | 241 ---- plugins/pychrysa/analysis/db/items/comment.h | 42 - plugins/pychrysa/analysis/db/items/module.c | 93 -- plugins/pychrysa/analysis/db/items/module.h | 39 - plugins/pychrysa/analysis/db/module.c | 100 -- plugins/pychrysa/analysis/db/module.h | 39 - plugins/pychrysa/analysis/loaded.c | 146 --- plugins/pychrysa/analysis/loaded.h | 42 - plugins/pychrysa/analysis/module.c | 107 -- plugins/pychrysa/analysis/module.h | 39 - plugins/pychrysa/analysis/routine.c | 295 ----- plugins/pychrysa/analysis/routine.h | 42 - plugins/pychrysa/arch/Makefile.am | 25 - plugins/pychrysa/arch/immediate.c | 700 ----------- plugins/pychrysa/arch/immediate.h | 42 - plugins/pychrysa/arch/instriter.c | 276 ----- plugins/pychrysa/arch/instriter.h | 42 - plugins/pychrysa/arch/instruction.c | 462 ------- plugins/pychrysa/arch/instruction.h | 42 - plugins/pychrysa/arch/module.c | 165 --- plugins/pychrysa/arch/module.h | 39 - plugins/pychrysa/arch/operand.c | 109 -- plugins/pychrysa/arch/operand.h | 42 - plugins/pychrysa/arch/processor.c | 459 ------- plugins/pychrysa/arch/processor.h | 42 - plugins/pychrysa/arch/raw.c | 263 ---- plugins/pychrysa/arch/raw.h | 42 - plugins/pychrysa/arch/vmpa.c | 1303 -------------------- plugins/pychrysa/arch/vmpa.h | 71 -- plugins/pychrysa/common/Makefile.am | 17 - plugins/pychrysa/common/bits.c | 653 ---------- plugins/pychrysa/common/bits.h | 48 - plugins/pychrysa/common/fnv1a.c | 145 --- plugins/pychrysa/common/fnv1a.h | 42 - plugins/pychrysa/common/module.c | 99 -- plugins/pychrysa/common/module.h | 39 - plugins/pychrysa/common/pathname.c | 203 --- plugins/pychrysa/common/pathname.h | 42 - plugins/pychrysa/core/Makefile.am | 17 - plugins/pychrysa/core/formats.c | 190 --- plugins/pychrysa/core/formats.h | 42 - plugins/pychrysa/core/logs.c | 278 ----- plugins/pychrysa/core/logs.h | 42 - plugins/pychrysa/core/module.c | 97 -- plugins/pychrysa/core/module.h | 39 - plugins/pychrysa/core/params.c | 179 --- plugins/pychrysa/core/params.h | 42 - plugins/pychrysa/debug/Makefile.am | 19 - plugins/pychrysa/debug/debugger.c | 1185 ------------------ plugins/pychrysa/debug/debugger.h | 42 - plugins/pychrysa/debug/gdbrsp/Makefile.am | 15 - plugins/pychrysa/debug/gdbrsp/gdb.c | 166 --- plugins/pychrysa/debug/gdbrsp/gdb.h | 42 - plugins/pychrysa/debug/gdbrsp/module.c | 86 -- plugins/pychrysa/debug/gdbrsp/module.h | 39 - plugins/pychrysa/debug/module.c | 93 -- plugins/pychrysa/debug/module.h | 39 - plugins/pychrysa/format/Makefile.am | 21 - plugins/pychrysa/format/executable.c | 215 ---- plugins/pychrysa/format/executable.h | 42 - plugins/pychrysa/format/format.c | 680 ---------- plugins/pychrysa/format/format.h | 56 - plugins/pychrysa/format/module.c | 99 -- plugins/pychrysa/format/module.h | 39 - plugins/pychrysa/format/symbol.c | 446 ------- plugins/pychrysa/format/symbol.h | 42 - plugins/pychrysa/format/symiter.c | 276 ----- plugins/pychrysa/format/symiter.h | 42 - plugins/pychrysa/glibext/Makefile.am | 19 - plugins/pychrysa/glibext/buffercache.c | 165 --- plugins/pychrysa/glibext/buffercache.h | 42 - plugins/pychrysa/glibext/bufferline.c | 373 ------ plugins/pychrysa/glibext/bufferline.h | 42 - plugins/pychrysa/glibext/configuration.c | 1165 ----------------- plugins/pychrysa/glibext/configuration.h | 66 - plugins/pychrysa/glibext/linegen.c | 404 ------ plugins/pychrysa/glibext/linegen.h | 42 - plugins/pychrysa/glibext/loadedpanel.c | 166 --- plugins/pychrysa/glibext/loadedpanel.h | 42 - plugins/pychrysa/glibext/module.c | 103 -- plugins/pychrysa/glibext/module.h | 39 - plugins/pychrysa/gtkext/Makefile.am | 18 - plugins/pychrysa/gtkext/blockdisplay.c | 115 -- plugins/pychrysa/gtkext/blockdisplay.h | 42 - plugins/pychrysa/gtkext/bufferdisplay.c | 115 -- plugins/pychrysa/gtkext/bufferdisplay.h | 42 - plugins/pychrysa/gtkext/displaypanel.c | 269 ---- plugins/pychrysa/gtkext/displaypanel.h | 42 - plugins/pychrysa/gtkext/dockable.c | 102 -- plugins/pychrysa/gtkext/dockable.h | 42 - plugins/pychrysa/gtkext/module.c | 95 -- plugins/pychrysa/gtkext/module.h | 39 - plugins/pychrysa/gui/Makefile.am | 19 - plugins/pychrysa/gui/editem.c | 370 ------ plugins/pychrysa/gui/editem.h | 42 - plugins/pychrysa/gui/module.c | 97 -- plugins/pychrysa/gui/module.h | 39 - plugins/pychrysa/gui/panels/Makefile.am | 15 - plugins/pychrysa/gui/panels/module.c | 93 -- plugins/pychrysa/gui/panels/module.h | 39 - plugins/pychrysa/gui/panels/panel.c | 244 ---- plugins/pychrysa/gui/panels/panel.h | 42 - plugins/pychrysa/helpers.c | 473 ------- plugins/pychrysa/helpers.h | 93 -- plugins/pychrysa/plugin.c | 809 ------------ plugins/pychrysa/plugin.h | 75 -- plugins/pychrysa/pychrysa.c | 616 --------- plugins/pychrysa/pychrysa.h | 99 -- plugins/pychrysa/struct.c | 161 --- plugins/pychrysa/struct.h | 42 - plugins/pychrysa/weak.c | 129 -- plugins/pychrysa/weak.h | 50 - plugins/pychrysalide/Makefile.am | 36 + plugins/pychrysalide/access.c | 137 ++ plugins/pychrysalide/access.h | 40 + plugins/pychrysalide/analysis/Makefile.am | 24 + plugins/pychrysalide/analysis/binary.c | 381 ++++++ plugins/pychrysalide/analysis/binary.h | 42 + plugins/pychrysalide/analysis/block.c | 274 ++++ plugins/pychrysalide/analysis/block.h | 42 + plugins/pychrysalide/analysis/content.c | 460 +++++++ plugins/pychrysalide/analysis/content.h | 42 + plugins/pychrysalide/analysis/contents/Makefile.am | 15 + plugins/pychrysalide/analysis/contents/file.c | 149 +++ plugins/pychrysalide/analysis/contents/file.h | 42 + plugins/pychrysalide/analysis/contents/module.c | 97 ++ plugins/pychrysalide/analysis/contents/module.h | 39 + .../pychrysalide/analysis/contents/restricted.c | 173 +++ .../pychrysalide/analysis/contents/restricted.h | 42 + plugins/pychrysalide/analysis/db/Makefile.am | 19 + plugins/pychrysalide/analysis/db/certs.c | 327 +++++ plugins/pychrysalide/analysis/db/certs.h | 42 + plugins/pychrysalide/analysis/db/collection.c | 110 ++ plugins/pychrysalide/analysis/db/collection.h | 42 + plugins/pychrysalide/analysis/db/item.c | 182 +++ plugins/pychrysalide/analysis/db/item.h | 42 + plugins/pychrysalide/analysis/db/items/Makefile.am | 14 + plugins/pychrysalide/analysis/db/items/comment.c | 241 ++++ plugins/pychrysalide/analysis/db/items/comment.h | 42 + plugins/pychrysalide/analysis/db/items/module.c | 93 ++ plugins/pychrysalide/analysis/db/items/module.h | 39 + plugins/pychrysalide/analysis/db/module.c | 100 ++ plugins/pychrysalide/analysis/db/module.h | 39 + plugins/pychrysalide/analysis/loaded.c | 146 +++ plugins/pychrysalide/analysis/loaded.h | 42 + plugins/pychrysalide/analysis/module.c | 107 ++ plugins/pychrysalide/analysis/module.h | 39 + plugins/pychrysalide/analysis/routine.c | 295 +++++ plugins/pychrysalide/analysis/routine.h | 42 + plugins/pychrysalide/arch/Makefile.am | 25 + plugins/pychrysalide/arch/immediate.c | 700 +++++++++++ plugins/pychrysalide/arch/immediate.h | 42 + plugins/pychrysalide/arch/instriter.c | 276 +++++ plugins/pychrysalide/arch/instriter.h | 42 + plugins/pychrysalide/arch/instruction.c | 462 +++++++ plugins/pychrysalide/arch/instruction.h | 42 + plugins/pychrysalide/arch/module.c | 165 +++ plugins/pychrysalide/arch/module.h | 39 + plugins/pychrysalide/arch/operand.c | 109 ++ plugins/pychrysalide/arch/operand.h | 42 + plugins/pychrysalide/arch/processor.c | 459 +++++++ plugins/pychrysalide/arch/processor.h | 42 + plugins/pychrysalide/arch/raw.c | 263 ++++ plugins/pychrysalide/arch/raw.h | 42 + plugins/pychrysalide/arch/vmpa.c | 1303 ++++++++++++++++++++ plugins/pychrysalide/arch/vmpa.h | 71 ++ plugins/pychrysalide/common/Makefile.am | 17 + plugins/pychrysalide/common/bits.c | 653 ++++++++++ plugins/pychrysalide/common/bits.h | 48 + plugins/pychrysalide/common/fnv1a.c | 145 +++ plugins/pychrysalide/common/fnv1a.h | 42 + plugins/pychrysalide/common/module.c | 99 ++ plugins/pychrysalide/common/module.h | 39 + plugins/pychrysalide/common/pathname.c | 203 +++ plugins/pychrysalide/common/pathname.h | 42 + plugins/pychrysalide/core/Makefile.am | 17 + plugins/pychrysalide/core/formats.c | 190 +++ plugins/pychrysalide/core/formats.h | 42 + plugins/pychrysalide/core/logs.c | 278 +++++ plugins/pychrysalide/core/logs.h | 42 + plugins/pychrysalide/core/module.c | 97 ++ plugins/pychrysalide/core/module.h | 39 + plugins/pychrysalide/core/params.c | 179 +++ plugins/pychrysalide/core/params.h | 42 + plugins/pychrysalide/debug/Makefile.am | 19 + plugins/pychrysalide/debug/debugger.c | 1185 ++++++++++++++++++ plugins/pychrysalide/debug/debugger.h | 42 + plugins/pychrysalide/debug/gdbrsp/Makefile.am | 15 + plugins/pychrysalide/debug/gdbrsp/gdb.c | 166 +++ plugins/pychrysalide/debug/gdbrsp/gdb.h | 42 + plugins/pychrysalide/debug/gdbrsp/module.c | 86 ++ plugins/pychrysalide/debug/gdbrsp/module.h | 39 + plugins/pychrysalide/debug/module.c | 93 ++ plugins/pychrysalide/debug/module.h | 39 + plugins/pychrysalide/format/Makefile.am | 21 + plugins/pychrysalide/format/executable.c | 215 ++++ plugins/pychrysalide/format/executable.h | 42 + plugins/pychrysalide/format/format.c | 680 ++++++++++ plugins/pychrysalide/format/format.h | 56 + plugins/pychrysalide/format/module.c | 99 ++ plugins/pychrysalide/format/module.h | 39 + plugins/pychrysalide/format/symbol.c | 446 +++++++ plugins/pychrysalide/format/symbol.h | 42 + plugins/pychrysalide/format/symiter.c | 276 +++++ plugins/pychrysalide/format/symiter.h | 42 + plugins/pychrysalide/glibext/Makefile.am | 19 + plugins/pychrysalide/glibext/buffercache.c | 165 +++ plugins/pychrysalide/glibext/buffercache.h | 42 + plugins/pychrysalide/glibext/bufferline.c | 373 ++++++ plugins/pychrysalide/glibext/bufferline.h | 42 + plugins/pychrysalide/glibext/configuration.c | 1165 +++++++++++++++++ plugins/pychrysalide/glibext/configuration.h | 66 + plugins/pychrysalide/glibext/linegen.c | 404 ++++++ plugins/pychrysalide/glibext/linegen.h | 42 + plugins/pychrysalide/glibext/loadedpanel.c | 166 +++ plugins/pychrysalide/glibext/loadedpanel.h | 42 + plugins/pychrysalide/glibext/module.c | 103 ++ plugins/pychrysalide/glibext/module.h | 39 + plugins/pychrysalide/gtkext/Makefile.am | 18 + plugins/pychrysalide/gtkext/blockdisplay.c | 115 ++ plugins/pychrysalide/gtkext/blockdisplay.h | 42 + plugins/pychrysalide/gtkext/bufferdisplay.c | 115 ++ plugins/pychrysalide/gtkext/bufferdisplay.h | 42 + plugins/pychrysalide/gtkext/displaypanel.c | 269 ++++ plugins/pychrysalide/gtkext/displaypanel.h | 42 + plugins/pychrysalide/gtkext/dockable.c | 102 ++ plugins/pychrysalide/gtkext/dockable.h | 42 + plugins/pychrysalide/gtkext/module.c | 95 ++ plugins/pychrysalide/gtkext/module.h | 39 + plugins/pychrysalide/gui/Makefile.am | 19 + plugins/pychrysalide/gui/editem.c | 370 ++++++ plugins/pychrysalide/gui/editem.h | 42 + plugins/pychrysalide/gui/module.c | 97 ++ plugins/pychrysalide/gui/module.h | 39 + plugins/pychrysalide/gui/panels/Makefile.am | 15 + plugins/pychrysalide/gui/panels/module.c | 93 ++ plugins/pychrysalide/gui/panels/module.h | 39 + plugins/pychrysalide/gui/panels/panel.c | 244 ++++ plugins/pychrysalide/gui/panels/panel.h | 42 + plugins/pychrysalide/helpers.c | 473 +++++++ plugins/pychrysalide/helpers.h | 93 ++ plugins/pychrysalide/plugin.c | 809 ++++++++++++ plugins/pychrysalide/plugin.h | 75 ++ plugins/pychrysalide/pychrysa.c | 616 +++++++++ plugins/pychrysalide/pychrysa.h | 99 ++ plugins/pychrysalide/struct.c | 161 +++ plugins/pychrysalide/struct.h | 42 + plugins/pychrysalide/weak.c | 129 ++ plugins/pychrysalide/weak.h | 50 + 289 files changed, 21388 insertions(+), 21231 deletions(-) delete mode 100644 plugins/pychrysa/Makefile.am delete mode 100644 plugins/pychrysa/access.c delete mode 100644 plugins/pychrysa/access.h delete mode 100644 plugins/pychrysa/analysis/Makefile.am delete mode 100644 plugins/pychrysa/analysis/binary.c delete mode 100644 plugins/pychrysa/analysis/binary.h delete mode 100644 plugins/pychrysa/analysis/block.c delete mode 100644 plugins/pychrysa/analysis/block.h delete mode 100644 plugins/pychrysa/analysis/content.c delete mode 100644 plugins/pychrysa/analysis/content.h delete mode 100644 plugins/pychrysa/analysis/contents/Makefile.am delete mode 100644 plugins/pychrysa/analysis/contents/file.c delete mode 100644 plugins/pychrysa/analysis/contents/file.h delete mode 100644 plugins/pychrysa/analysis/contents/module.c delete mode 100644 plugins/pychrysa/analysis/contents/module.h delete mode 100644 plugins/pychrysa/analysis/contents/restricted.c delete mode 100644 plugins/pychrysa/analysis/contents/restricted.h delete mode 100644 plugins/pychrysa/analysis/db/Makefile.am delete mode 100644 plugins/pychrysa/analysis/db/certs.c delete mode 100644 plugins/pychrysa/analysis/db/certs.h delete mode 100644 plugins/pychrysa/analysis/db/collection.c delete mode 100644 plugins/pychrysa/analysis/db/collection.h delete mode 100644 plugins/pychrysa/analysis/db/item.c delete mode 100644 plugins/pychrysa/analysis/db/item.h delete mode 100644 plugins/pychrysa/analysis/db/items/Makefile.am delete mode 100644 plugins/pychrysa/analysis/db/items/comment.c delete mode 100644 plugins/pychrysa/analysis/db/items/comment.h delete mode 100644 plugins/pychrysa/analysis/db/items/module.c delete mode 100644 plugins/pychrysa/analysis/db/items/module.h delete mode 100644 plugins/pychrysa/analysis/db/module.c delete mode 100644 plugins/pychrysa/analysis/db/module.h delete mode 100644 plugins/pychrysa/analysis/loaded.c delete mode 100644 plugins/pychrysa/analysis/loaded.h delete mode 100644 plugins/pychrysa/analysis/module.c delete mode 100644 plugins/pychrysa/analysis/module.h delete mode 100644 plugins/pychrysa/analysis/routine.c delete mode 100644 plugins/pychrysa/analysis/routine.h delete mode 100644 plugins/pychrysa/arch/Makefile.am delete mode 100644 plugins/pychrysa/arch/immediate.c delete mode 100644 plugins/pychrysa/arch/immediate.h delete mode 100644 plugins/pychrysa/arch/instriter.c delete mode 100644 plugins/pychrysa/arch/instriter.h delete mode 100644 plugins/pychrysa/arch/instruction.c delete mode 100644 plugins/pychrysa/arch/instruction.h delete mode 100644 plugins/pychrysa/arch/module.c delete mode 100644 plugins/pychrysa/arch/module.h delete mode 100644 plugins/pychrysa/arch/operand.c delete mode 100644 plugins/pychrysa/arch/operand.h delete mode 100644 plugins/pychrysa/arch/processor.c delete mode 100644 plugins/pychrysa/arch/processor.h delete mode 100644 plugins/pychrysa/arch/raw.c delete mode 100644 plugins/pychrysa/arch/raw.h delete mode 100644 plugins/pychrysa/arch/vmpa.c delete mode 100644 plugins/pychrysa/arch/vmpa.h delete mode 100644 plugins/pychrysa/common/Makefile.am delete mode 100644 plugins/pychrysa/common/bits.c delete mode 100644 plugins/pychrysa/common/bits.h delete mode 100644 plugins/pychrysa/common/fnv1a.c delete mode 100644 plugins/pychrysa/common/fnv1a.h delete mode 100644 plugins/pychrysa/common/module.c delete mode 100644 plugins/pychrysa/common/module.h delete mode 100644 plugins/pychrysa/common/pathname.c delete mode 100644 plugins/pychrysa/common/pathname.h delete mode 100644 plugins/pychrysa/core/Makefile.am delete mode 100644 plugins/pychrysa/core/formats.c delete mode 100644 plugins/pychrysa/core/formats.h delete mode 100644 plugins/pychrysa/core/logs.c delete mode 100644 plugins/pychrysa/core/logs.h delete mode 100644 plugins/pychrysa/core/module.c delete mode 100644 plugins/pychrysa/core/module.h delete mode 100644 plugins/pychrysa/core/params.c delete mode 100644 plugins/pychrysa/core/params.h delete mode 100644 plugins/pychrysa/debug/Makefile.am delete mode 100644 plugins/pychrysa/debug/debugger.c delete mode 100644 plugins/pychrysa/debug/debugger.h delete mode 100644 plugins/pychrysa/debug/gdbrsp/Makefile.am delete mode 100644 plugins/pychrysa/debug/gdbrsp/gdb.c delete mode 100644 plugins/pychrysa/debug/gdbrsp/gdb.h delete mode 100644 plugins/pychrysa/debug/gdbrsp/module.c delete mode 100644 plugins/pychrysa/debug/gdbrsp/module.h delete mode 100644 plugins/pychrysa/debug/module.c delete mode 100644 plugins/pychrysa/debug/module.h delete mode 100644 plugins/pychrysa/format/Makefile.am delete mode 100644 plugins/pychrysa/format/executable.c delete mode 100644 plugins/pychrysa/format/executable.h delete mode 100644 plugins/pychrysa/format/format.c delete mode 100644 plugins/pychrysa/format/format.h delete mode 100644 plugins/pychrysa/format/module.c delete mode 100644 plugins/pychrysa/format/module.h delete mode 100644 plugins/pychrysa/format/symbol.c delete mode 100644 plugins/pychrysa/format/symbol.h delete mode 100644 plugins/pychrysa/format/symiter.c delete mode 100644 plugins/pychrysa/format/symiter.h delete mode 100644 plugins/pychrysa/glibext/Makefile.am delete mode 100644 plugins/pychrysa/glibext/buffercache.c delete mode 100644 plugins/pychrysa/glibext/buffercache.h delete mode 100644 plugins/pychrysa/glibext/bufferline.c delete mode 100644 plugins/pychrysa/glibext/bufferline.h delete mode 100644 plugins/pychrysa/glibext/configuration.c delete mode 100644 plugins/pychrysa/glibext/configuration.h delete mode 100644 plugins/pychrysa/glibext/linegen.c delete mode 100644 plugins/pychrysa/glibext/linegen.h delete mode 100644 plugins/pychrysa/glibext/loadedpanel.c delete mode 100644 plugins/pychrysa/glibext/loadedpanel.h delete mode 100644 plugins/pychrysa/glibext/module.c delete mode 100644 plugins/pychrysa/glibext/module.h delete mode 100644 plugins/pychrysa/gtkext/Makefile.am delete mode 100644 plugins/pychrysa/gtkext/blockdisplay.c delete mode 100644 plugins/pychrysa/gtkext/blockdisplay.h delete mode 100644 plugins/pychrysa/gtkext/bufferdisplay.c delete mode 100644 plugins/pychrysa/gtkext/bufferdisplay.h delete mode 100644 plugins/pychrysa/gtkext/displaypanel.c delete mode 100644 plugins/pychrysa/gtkext/displaypanel.h delete mode 100644 plugins/pychrysa/gtkext/dockable.c delete mode 100644 plugins/pychrysa/gtkext/dockable.h delete mode 100644 plugins/pychrysa/gtkext/module.c delete mode 100644 plugins/pychrysa/gtkext/module.h delete mode 100644 plugins/pychrysa/gui/Makefile.am delete mode 100644 plugins/pychrysa/gui/editem.c delete mode 100644 plugins/pychrysa/gui/editem.h delete mode 100644 plugins/pychrysa/gui/module.c delete mode 100644 plugins/pychrysa/gui/module.h delete mode 100644 plugins/pychrysa/gui/panels/Makefile.am delete mode 100644 plugins/pychrysa/gui/panels/module.c delete mode 100644 plugins/pychrysa/gui/panels/module.h delete mode 100644 plugins/pychrysa/gui/panels/panel.c delete mode 100644 plugins/pychrysa/gui/panels/panel.h delete mode 100644 plugins/pychrysa/helpers.c delete mode 100644 plugins/pychrysa/helpers.h delete mode 100644 plugins/pychrysa/plugin.c delete mode 100644 plugins/pychrysa/plugin.h delete mode 100644 plugins/pychrysa/pychrysa.c delete mode 100644 plugins/pychrysa/pychrysa.h delete mode 100644 plugins/pychrysa/struct.c delete mode 100644 plugins/pychrysa/struct.h delete mode 100644 plugins/pychrysa/weak.c delete mode 100644 plugins/pychrysa/weak.h create mode 100644 plugins/pychrysalide/Makefile.am create mode 100644 plugins/pychrysalide/access.c create mode 100644 plugins/pychrysalide/access.h create mode 100644 plugins/pychrysalide/analysis/Makefile.am create mode 100644 plugins/pychrysalide/analysis/binary.c create mode 100644 plugins/pychrysalide/analysis/binary.h create mode 100644 plugins/pychrysalide/analysis/block.c create mode 100644 plugins/pychrysalide/analysis/block.h create mode 100644 plugins/pychrysalide/analysis/content.c create mode 100644 plugins/pychrysalide/analysis/content.h create mode 100644 plugins/pychrysalide/analysis/contents/Makefile.am create mode 100644 plugins/pychrysalide/analysis/contents/file.c create mode 100644 plugins/pychrysalide/analysis/contents/file.h create mode 100644 plugins/pychrysalide/analysis/contents/module.c create mode 100644 plugins/pychrysalide/analysis/contents/module.h create mode 100644 plugins/pychrysalide/analysis/contents/restricted.c create mode 100644 plugins/pychrysalide/analysis/contents/restricted.h create mode 100644 plugins/pychrysalide/analysis/db/Makefile.am create mode 100644 plugins/pychrysalide/analysis/db/certs.c create mode 100644 plugins/pychrysalide/analysis/db/certs.h create mode 100644 plugins/pychrysalide/analysis/db/collection.c create mode 100644 plugins/pychrysalide/analysis/db/collection.h create mode 100644 plugins/pychrysalide/analysis/db/item.c create mode 100644 plugins/pychrysalide/analysis/db/item.h create mode 100644 plugins/pychrysalide/analysis/db/items/Makefile.am create mode 100644 plugins/pychrysalide/analysis/db/items/comment.c create mode 100644 plugins/pychrysalide/analysis/db/items/comment.h create mode 100644 plugins/pychrysalide/analysis/db/items/module.c create mode 100644 plugins/pychrysalide/analysis/db/items/module.h create mode 100644 plugins/pychrysalide/analysis/db/module.c create mode 100644 plugins/pychrysalide/analysis/db/module.h create mode 100644 plugins/pychrysalide/analysis/loaded.c create mode 100644 plugins/pychrysalide/analysis/loaded.h create mode 100644 plugins/pychrysalide/analysis/module.c create mode 100644 plugins/pychrysalide/analysis/module.h create mode 100644 plugins/pychrysalide/analysis/routine.c create mode 100644 plugins/pychrysalide/analysis/routine.h create mode 100644 plugins/pychrysalide/arch/Makefile.am create mode 100644 plugins/pychrysalide/arch/immediate.c create mode 100644 plugins/pychrysalide/arch/immediate.h create mode 100644 plugins/pychrysalide/arch/instriter.c create mode 100644 plugins/pychrysalide/arch/instriter.h create mode 100644 plugins/pychrysalide/arch/instruction.c create mode 100644 plugins/pychrysalide/arch/instruction.h create mode 100644 plugins/pychrysalide/arch/module.c create mode 100644 plugins/pychrysalide/arch/module.h create mode 100644 plugins/pychrysalide/arch/operand.c create mode 100644 plugins/pychrysalide/arch/operand.h create mode 100644 plugins/pychrysalide/arch/processor.c create mode 100644 plugins/pychrysalide/arch/processor.h create mode 100644 plugins/pychrysalide/arch/raw.c create mode 100644 plugins/pychrysalide/arch/raw.h create mode 100644 plugins/pychrysalide/arch/vmpa.c create mode 100644 plugins/pychrysalide/arch/vmpa.h create mode 100644 plugins/pychrysalide/common/Makefile.am create mode 100644 plugins/pychrysalide/common/bits.c create mode 100644 plugins/pychrysalide/common/bits.h create mode 100644 plugins/pychrysalide/common/fnv1a.c create mode 100644 plugins/pychrysalide/common/fnv1a.h create mode 100644 plugins/pychrysalide/common/module.c create mode 100644 plugins/pychrysalide/common/module.h create mode 100644 plugins/pychrysalide/common/pathname.c create mode 100644 plugins/pychrysalide/common/pathname.h create mode 100644 plugins/pychrysalide/core/Makefile.am create mode 100644 plugins/pychrysalide/core/formats.c create mode 100644 plugins/pychrysalide/core/formats.h create mode 100644 plugins/pychrysalide/core/logs.c create mode 100644 plugins/pychrysalide/core/logs.h create mode 100644 plugins/pychrysalide/core/module.c create mode 100644 plugins/pychrysalide/core/module.h create mode 100644 plugins/pychrysalide/core/params.c create mode 100644 plugins/pychrysalide/core/params.h create mode 100644 plugins/pychrysalide/debug/Makefile.am create mode 100644 plugins/pychrysalide/debug/debugger.c create mode 100644 plugins/pychrysalide/debug/debugger.h create mode 100644 plugins/pychrysalide/debug/gdbrsp/Makefile.am create mode 100644 plugins/pychrysalide/debug/gdbrsp/gdb.c create mode 100644 plugins/pychrysalide/debug/gdbrsp/gdb.h create mode 100644 plugins/pychrysalide/debug/gdbrsp/module.c create mode 100644 plugins/pychrysalide/debug/gdbrsp/module.h create mode 100644 plugins/pychrysalide/debug/module.c create mode 100644 plugins/pychrysalide/debug/module.h create mode 100644 plugins/pychrysalide/format/Makefile.am create mode 100644 plugins/pychrysalide/format/executable.c create mode 100644 plugins/pychrysalide/format/executable.h create mode 100644 plugins/pychrysalide/format/format.c create mode 100644 plugins/pychrysalide/format/format.h create mode 100644 plugins/pychrysalide/format/module.c create mode 100644 plugins/pychrysalide/format/module.h create mode 100644 plugins/pychrysalide/format/symbol.c create mode 100644 plugins/pychrysalide/format/symbol.h create mode 100644 plugins/pychrysalide/format/symiter.c create mode 100644 plugins/pychrysalide/format/symiter.h create mode 100644 plugins/pychrysalide/glibext/Makefile.am create mode 100644 plugins/pychrysalide/glibext/buffercache.c create mode 100644 plugins/pychrysalide/glibext/buffercache.h create mode 100644 plugins/pychrysalide/glibext/bufferline.c create mode 100644 plugins/pychrysalide/glibext/bufferline.h create mode 100644 plugins/pychrysalide/glibext/configuration.c create mode 100644 plugins/pychrysalide/glibext/configuration.h create mode 100644 plugins/pychrysalide/glibext/linegen.c create mode 100644 plugins/pychrysalide/glibext/linegen.h create mode 100644 plugins/pychrysalide/glibext/loadedpanel.c create mode 100644 plugins/pychrysalide/glibext/loadedpanel.h create mode 100644 plugins/pychrysalide/glibext/module.c create mode 100644 plugins/pychrysalide/glibext/module.h create mode 100644 plugins/pychrysalide/gtkext/Makefile.am create mode 100644 plugins/pychrysalide/gtkext/blockdisplay.c create mode 100644 plugins/pychrysalide/gtkext/blockdisplay.h create mode 100644 plugins/pychrysalide/gtkext/bufferdisplay.c create mode 100644 plugins/pychrysalide/gtkext/bufferdisplay.h create mode 100644 plugins/pychrysalide/gtkext/displaypanel.c create mode 100644 plugins/pychrysalide/gtkext/displaypanel.h create mode 100644 plugins/pychrysalide/gtkext/dockable.c create mode 100644 plugins/pychrysalide/gtkext/dockable.h create mode 100644 plugins/pychrysalide/gtkext/module.c create mode 100644 plugins/pychrysalide/gtkext/module.h create mode 100644 plugins/pychrysalide/gui/Makefile.am create mode 100644 plugins/pychrysalide/gui/editem.c create mode 100644 plugins/pychrysalide/gui/editem.h create mode 100644 plugins/pychrysalide/gui/module.c create mode 100644 plugins/pychrysalide/gui/module.h create mode 100644 plugins/pychrysalide/gui/panels/Makefile.am create mode 100644 plugins/pychrysalide/gui/panels/module.c create mode 100644 plugins/pychrysalide/gui/panels/module.h create mode 100644 plugins/pychrysalide/gui/panels/panel.c create mode 100644 plugins/pychrysalide/gui/panels/panel.h create mode 100644 plugins/pychrysalide/helpers.c create mode 100644 plugins/pychrysalide/helpers.h create mode 100644 plugins/pychrysalide/plugin.c create mode 100644 plugins/pychrysalide/plugin.h create mode 100644 plugins/pychrysalide/pychrysa.c create mode 100644 plugins/pychrysalide/pychrysa.h create mode 100644 plugins/pychrysalide/struct.c create mode 100644 plugins/pychrysalide/struct.h create mode 100644 plugins/pychrysalide/weak.c create mode 100644 plugins/pychrysalide/weak.h diff --git a/ChangeLog b/ChangeLog index bd8482a..c0d10ac 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,162 @@ 18-01-16 Cyrille Bagard + * configure.ac: + * plugins/Makefile.am: + * plugins/arm/python/instruction.c: + * plugins/arm/python/module.c: + * plugins/arm/python/processor.c: + * plugins/arm/python/v7/instruction.c: + * plugins/arm/python/v7/processor.c: + * plugins/dex/python/class.c: + * plugins/dex/python/format.c: + * plugins/dex/python/module.c: + * plugins/elf/python/constants.c: + * plugins/elf/python/format.c: + * plugins/elf/python/module.c: + * plugins/elf/python/translate.c: + Update code. + + * plugins/pychrysalide/Makefile.am: + * plugins/pychrysalide/access.c: + * plugins/pychrysalide/access.h: + * plugins/pychrysalide/analysis/Makefile.am: + * plugins/pychrysalide/analysis/binary.c: + * plugins/pychrysalide/analysis/binary.h: + * plugins/pychrysalide/analysis/block.c: + * plugins/pychrysalide/analysis/block.h: + * plugins/pychrysalide/analysis/content.c: + * plugins/pychrysalide/analysis/content.h: + * plugins/pychrysalide/analysis/contents/Makefile.am: + * plugins/pychrysalide/analysis/contents/file.c: + * plugins/pychrysalide/analysis/contents/file.h: + * plugins/pychrysalide/analysis/contents/module.c: + * plugins/pychrysalide/analysis/contents/module.h: + * plugins/pychrysalide/analysis/contents/restricted.c: + * plugins/pychrysalide/analysis/contents/restricted.h: + * plugins/pychrysalide/analysis/db/Makefile.am: + * plugins/pychrysalide/analysis/db/certs.c: + * plugins/pychrysalide/analysis/db/certs.h: + * plugins/pychrysalide/analysis/db/collection.c: + * plugins/pychrysalide/analysis/db/collection.h: + * plugins/pychrysalide/analysis/db/item.c: + * plugins/pychrysalide/analysis/db/item.h: + * plugins/pychrysalide/analysis/db/items/Makefile.am: + * plugins/pychrysalide/analysis/db/items/comment.c: + * plugins/pychrysalide/analysis/db/items/comment.h: + * plugins/pychrysalide/analysis/db/items/module.c: + * plugins/pychrysalide/analysis/db/items/module.h: + * plugins/pychrysalide/analysis/db/module.c: + * plugins/pychrysalide/analysis/db/module.h: + * plugins/pychrysalide/analysis/loaded.c: + * plugins/pychrysalide/analysis/loaded.h: + * plugins/pychrysalide/analysis/module.c: + * plugins/pychrysalide/analysis/module.h: + * plugins/pychrysalide/analysis/routine.c: + * plugins/pychrysalide/analysis/routine.h: + * plugins/pychrysalide/arch/Makefile.am: + * plugins/pychrysalide/arch/immediate.c: + * plugins/pychrysalide/arch/immediate.h: + * plugins/pychrysalide/arch/instriter.c: + * plugins/pychrysalide/arch/instriter.h: + * plugins/pychrysalide/arch/instruction.c: + * plugins/pychrysalide/arch/instruction.h: + * plugins/pychrysalide/arch/module.c: + * plugins/pychrysalide/arch/module.h: + * plugins/pychrysalide/arch/operand.c: + * plugins/pychrysalide/arch/operand.h: + * plugins/pychrysalide/arch/processor.c: + * plugins/pychrysalide/arch/processor.h: + * plugins/pychrysalide/arch/raw.c: + * plugins/pychrysalide/arch/raw.h: + * plugins/pychrysalide/arch/vmpa.c: + * plugins/pychrysalide/arch/vmpa.h: + * plugins/pychrysalide/common/Makefile.am: + * plugins/pychrysalide/common/bits.c: + * plugins/pychrysalide/common/bits.h: + * plugins/pychrysalide/common/fnv1a.c: + * plugins/pychrysalide/common/fnv1a.h: + * plugins/pychrysalide/common/module.c: + * plugins/pychrysalide/common/module.h: + * plugins/pychrysalide/common/pathname.c: + * plugins/pychrysalide/common/pathname.h: + * plugins/pychrysalide/core/Makefile.am: + * plugins/pychrysalide/core/formats.c: + * plugins/pychrysalide/core/formats.h: + * plugins/pychrysalide/core/logs.c: + * plugins/pychrysalide/core/logs.h: + * plugins/pychrysalide/core/module.c: + * plugins/pychrysalide/core/module.h: + * plugins/pychrysalide/core/params.c: + * plugins/pychrysalide/core/params.h: + * plugins/pychrysalide/debug/Makefile.am: + * plugins/pychrysalide/debug/debugger.c: + * plugins/pychrysalide/debug/debugger.h: + * plugins/pychrysalide/debug/gdbrsp/Makefile.am: + * plugins/pychrysalide/debug/gdbrsp/gdb.c: + * plugins/pychrysalide/debug/gdbrsp/gdb.h: + * plugins/pychrysalide/debug/gdbrsp/module.c: + * plugins/pychrysalide/debug/gdbrsp/module.h: + * plugins/pychrysalide/debug/module.c: + * plugins/pychrysalide/debug/module.h: + * plugins/pychrysalide/format/Makefile.am: + * plugins/pychrysalide/format/executable.c: + * plugins/pychrysalide/format/executable.h: + * plugins/pychrysalide/format/format.c: + * plugins/pychrysalide/format/format.h: + * plugins/pychrysalide/format/module.c: + * plugins/pychrysalide/format/module.h: + * plugins/pychrysalide/format/symbol.c: + * plugins/pychrysalide/format/symbol.h: + * plugins/pychrysalide/format/symiter.c: + * plugins/pychrysalide/format/symiter.h: + * plugins/pychrysalide/glibext/Makefile.am: + * plugins/pychrysalide/glibext/buffercache.c: + * plugins/pychrysalide/glibext/buffercache.h: + * plugins/pychrysalide/glibext/bufferline.c: + * plugins/pychrysalide/glibext/bufferline.h: + * plugins/pychrysalide/glibext/configuration.c: + * plugins/pychrysalide/glibext/configuration.h: + * plugins/pychrysalide/glibext/linegen.c: + * plugins/pychrysalide/glibext/linegen.h: + * plugins/pychrysalide/glibext/loadedpanel.c: + * plugins/pychrysalide/glibext/loadedpanel.h: + * plugins/pychrysalide/glibext/module.c: + * plugins/pychrysalide/glibext/module.h: + * plugins/pychrysalide/gtkext/Makefile.am: + * plugins/pychrysalide/gtkext/blockdisplay.c: + * plugins/pychrysalide/gtkext/blockdisplay.h: + * plugins/pychrysalide/gtkext/bufferdisplay.c: + * plugins/pychrysalide/gtkext/bufferdisplay.h: + * plugins/pychrysalide/gtkext/displaypanel.c: + * plugins/pychrysalide/gtkext/displaypanel.h: + * plugins/pychrysalide/gtkext/dockable.c: + * plugins/pychrysalide/gtkext/dockable.h: + * plugins/pychrysalide/gtkext/module.c: + * plugins/pychrysalide/gtkext/module.h: + * plugins/pychrysalide/gui/Makefile.am: + * plugins/pychrysalide/gui/editem.c: + * plugins/pychrysalide/gui/editem.h: + * plugins/pychrysalide/gui/module.c: + * plugins/pychrysalide/gui/module.h: + * plugins/pychrysalide/gui/panels/Makefile.am: + * plugins/pychrysalide/gui/panels/module.c: + * plugins/pychrysalide/gui/panels/module.h: + * plugins/pychrysalide/gui/panels/panel.c: + * plugins/pychrysalide/gui/panels/panel.h: + * plugins/pychrysalide/helpers.c: + * plugins/pychrysalide/helpers.h: + * plugins/pychrysalide/plugin.c: + * plugins/pychrysalide/plugin.h: + * plugins/pychrysalide/pychrysa.c: + * plugins/pychrysalide/pychrysa.h: + * plugins/pychrysalide/struct.c: + * plugins/pychrysalide/struct.h: + * plugins/pychrysalide/weak.c: + * plugins/pychrysalide/weak.h: + Change the Python bindings source directory and update code. + +18-01-16 Cyrille Bagard + * plugins/pychrysa/format/format.c: Add and remove symbols from the Python API. diff --git a/configure.ac b/configure.ac index 902a5a0..b6d2fdf 100644 --- a/configure.ac +++ b/configure.ac @@ -339,21 +339,21 @@ AC_CONFIG_FILES([Makefile plugins/fmtp/Makefile plugins/libcsem/Makefile plugins/mobicore/Makefile - plugins/pychrysa/Makefile - plugins/pychrysa/analysis/Makefile - plugins/pychrysa/analysis/contents/Makefile - plugins/pychrysa/analysis/db/Makefile - plugins/pychrysa/analysis/db/items/Makefile - plugins/pychrysa/arch/Makefile - plugins/pychrysa/common/Makefile - plugins/pychrysa/core/Makefile - plugins/pychrysa/debug/Makefile - plugins/pychrysa/debug/gdbrsp/Makefile - plugins/pychrysa/format/Makefile - plugins/pychrysa/glibext/Makefile - plugins/pychrysa/gtkext/Makefile - plugins/pychrysa/gui/Makefile - plugins/pychrysa/gui/panels/Makefile + plugins/pychrysalide/Makefile + plugins/pychrysalide/analysis/Makefile + plugins/pychrysalide/analysis/contents/Makefile + plugins/pychrysalide/analysis/db/Makefile + plugins/pychrysalide/analysis/db/items/Makefile + plugins/pychrysalide/arch/Makefile + plugins/pychrysalide/common/Makefile + plugins/pychrysalide/core/Makefile + plugins/pychrysalide/debug/Makefile + plugins/pychrysalide/debug/gdbrsp/Makefile + plugins/pychrysalide/format/Makefile + plugins/pychrysalide/glibext/Makefile + plugins/pychrysalide/gtkext/Makefile + plugins/pychrysalide/gui/Makefile + plugins/pychrysalide/gui/panels/Makefile plugins/python/Makefile plugins/python/apkfiles/Makefile plugins/python/samples/Makefile diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 9f26d8f..6bb44fa 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -1,6 +1,6 @@ if HAVE_PYTHON3_CONFIG - PYTHON3_SUBDIRS = pychrysa python + PYTHON3_SUBDIRS = pychrysalide python endif # androhelpers diff --git a/plugins/arm/python/instruction.c b/plugins/arm/python/instruction.c index bbcde50..f88e998 100644 --- a/plugins/arm/python/instruction.c +++ b/plugins/arm/python/instruction.c @@ -28,8 +28,8 @@ #include -#include -#include +#include +#include #include "../instruction.h" diff --git a/plugins/arm/python/module.c b/plugins/arm/python/module.c index 6d71afe..9e832ba 100644 --- a/plugins/arm/python/module.c +++ b/plugins/arm/python/module.c @@ -28,7 +28,7 @@ #include -#include +#include #include "instruction.h" diff --git a/plugins/arm/python/processor.c b/plugins/arm/python/processor.c index 818809d..9be96ad 100644 --- a/plugins/arm/python/processor.c +++ b/plugins/arm/python/processor.c @@ -28,8 +28,8 @@ #include -#include -#include +#include +#include #include "../processor.h" diff --git a/plugins/arm/python/v7/instruction.c b/plugins/arm/python/v7/instruction.c index 25a49bb..127840f 100644 --- a/plugins/arm/python/v7/instruction.c +++ b/plugins/arm/python/v7/instruction.c @@ -28,7 +28,7 @@ #include -#include +#include #include "../instruction.h" diff --git a/plugins/arm/python/v7/processor.c b/plugins/arm/python/v7/processor.c index 9a0911c..b624f7f 100644 --- a/plugins/arm/python/v7/processor.c +++ b/plugins/arm/python/v7/processor.c @@ -28,7 +28,7 @@ #include -#include +#include #include "../processor.h" diff --git a/plugins/dex/python/class.c b/plugins/dex/python/class.c index ec1c3f7..ab7754e 100644 --- a/plugins/dex/python/class.c +++ b/plugins/dex/python/class.c @@ -28,7 +28,7 @@ #include -#include +#include #include "../class.h" diff --git a/plugins/dex/python/format.c b/plugins/dex/python/format.c index 906b09a..a406f62 100644 --- a/plugins/dex/python/format.c +++ b/plugins/dex/python/format.c @@ -29,10 +29,10 @@ #include -#include -#include -#include -#include +#include +#include +#include +#include #include "../class.h" diff --git a/plugins/dex/python/module.c b/plugins/dex/python/module.c index 8d5092d..acb2370 100644 --- a/plugins/dex/python/module.c +++ b/plugins/dex/python/module.c @@ -28,7 +28,7 @@ #include -#include +#include #include "class.h" diff --git a/plugins/elf/python/constants.c b/plugins/elf/python/constants.c index 91c07ee..1e92616 100644 --- a/plugins/elf/python/constants.c +++ b/plugins/elf/python/constants.c @@ -25,7 +25,7 @@ #include "constants.h" -#include +#include #include "../elf_def.h" diff --git a/plugins/elf/python/format.c b/plugins/elf/python/format.c index f1cf8d6..6b44703 100644 --- a/plugins/elf/python/format.c +++ b/plugins/elf/python/format.c @@ -31,9 +31,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include "constants.h" diff --git a/plugins/elf/python/module.c b/plugins/elf/python/module.c index 72d6dfc..f986659 100644 --- a/plugins/elf/python/module.c +++ b/plugins/elf/python/module.c @@ -28,7 +28,7 @@ #include -#include +#include #include "format.h" diff --git a/plugins/elf/python/translate.c b/plugins/elf/python/translate.c index 2450e1a..2a12220 100644 --- a/plugins/elf/python/translate.c +++ b/plugins/elf/python/translate.c @@ -28,7 +28,7 @@ #include -#include +#include #include "../elf-int.h" diff --git a/plugins/pychrysa/Makefile.am b/plugins/pychrysa/Makefile.am deleted file mode 100644 index 0648bb3..0000000 --- a/plugins/pychrysa/Makefile.am +++ /dev/null @@ -1,36 +0,0 @@ - -pkglib_LTLIBRARIES = pychrysalide.la - -libdir = $(pluginsdir) - -pychrysalide_la_SOURCES = \ - access.h access.c \ - helpers.h helpers.c \ - plugin.h plugin.c \ - pychrysa.h pychrysa.c \ - struct.h struct.c \ - weak.h weak.c - -pychrysalide_la_LIBADD = \ - analysis/libpychrysaanalysis.la \ - arch/libpychrysaarch.la \ - common/libpychrysacommon.la \ - core/libpychrysacore.la \ - debug/libpychrysadebug.la \ - format/libpychrysaformat.la \ - glibext/libpychrysaglibext.la \ - gtkext/libpychrysagtkext.la \ - gui/libpychrysagui.la - -pychrysalide_la_LDFLAGS = -module -avoid-version \ - $(LIBPYTHON_LIBS) $(LIBPYGOBJECT_LIBS) \ - -L../../src/.libs -lchrysadisass -lchrysagui -lchrysagtkext -lchrysacore \ - -L../../src/plugins/.libs -lplugins - - -AM_CPPFLAGS = $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) \ - -I../../src - -AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) - -SUBDIRS = analysis arch common core debug format glibext gtkext gui diff --git a/plugins/pychrysa/access.c b/plugins/pychrysa/access.c deleted file mode 100644 index 21ff68f..0000000 --- a/plugins/pychrysa/access.c +++ /dev/null @@ -1,137 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * access.c - accès aux modules Python en cours d'enregistrement - * - * Copyright (C) 2017 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 "access.h" - - -#include -#include - - -#include - - - -/* Lien entre un module et sa désignation */ -typedef struct _module_access -{ - const char *path; /* Chemin d'accès */ - PyObject *mod; /* Module Python en place */ - -} module_access; - - -/* Conservation de tous les accès */ -static module_access *_pychrysalide_modules = NULL; -static size_t _pychrysalide_count = 0; - - -/* Effectue la comparaison entre deux accès à des modules. */ -static int compare_python_module_accesses(const module_access *, const module_access *); - - - -/****************************************************************************** -* * -* Paramètres : a = premier accès à analyser. * -* b = second accès à analyser. * -* * -* Description : Effectue la comparaison entre deux accès à des modules. * -* * -* Retour : Bilan de la comparaison. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static int compare_python_module_accesses(const module_access *a, const module_access *b) -{ - int result; /* Bilan à retourner */ - - result = strcmp(a->path, b->path); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : path = chemin d'accès à un module Python. * -* mod = module Python en question. * -* * -* Description : Enregistre une référence à un module Python en chargement. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void register_access_to_python_module(const char *path, PyObject *mod) -{ - module_access access; /* Nouvel enregistrement */ - - access.path = path; - access.mod = mod; - - Py_INCREF(mod); - - _pychrysalide_modules = qinsert(_pychrysalide_modules, &_pychrysalide_count, - sizeof(module_access), (__compar_fn_t)compare_python_module_accesses, - &access); - -} - - -/****************************************************************************** -* * -* Paramètres : path = chemin d'accès à un module Python. * -* * -* Description : Fournit la référence à un module Python défini. * -* * -* Retour : Module Python correspondant, ou NULL si aucun de trouvé. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyObject *get_access_to_python_module(const char *path) -{ - PyObject *result; /* Référence à renvoyer */ - module_access key; /* Définition à retrouver */ - module_access *access; /* Accès trouvé à consulter */ - - key.path = path; - - access = bsearch(&key, _pychrysalide_modules, _pychrysalide_count, - sizeof(module_access), (__compar_fn_t)compare_python_module_accesses); - - if (access != NULL) - result = access->mod; - else - result = NULL; - - return result; - -} diff --git a/plugins/pychrysa/access.h b/plugins/pychrysa/access.h deleted file mode 100644 index 52883ec..0000000 --- a/plugins/pychrysa/access.h +++ /dev/null @@ -1,40 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * access.h - prototypes pour l'accès aux modules Python en cours d'enregistrement - * - * Copyright (C) 2017 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 . - */ - - -#ifndef _PLUGINS_PYCHRYSA_ACCESS_H -#define _PLUGINS_PYCHRYSA_ACCESS_H - - -#include - - - -/* Enregistre une référence à un module Python en chargement. */ -void register_access_to_python_module(const char *, PyObject *); - -/* Fournit la référence à un module Python défini. */ -PyObject *get_access_to_python_module(const char *path); - - - -#endif /* _PLUGINS_PYCHRYSA_ACCESS_H */ diff --git a/plugins/pychrysa/analysis/Makefile.am b/plugins/pychrysa/analysis/Makefile.am deleted file mode 100644 index c1639e7..0000000 --- a/plugins/pychrysa/analysis/Makefile.am +++ /dev/null @@ -1,24 +0,0 @@ - -noinst_LTLIBRARIES = libpychrysaanalysis.la - -libpychrysaanalysis_la_SOURCES = \ - binary.h binary.c \ - block.h block.c \ - content.h content.c \ - loaded.h loaded.c \ - module.h module.c \ - routine.h routine.c - -libpychrysaanalysis_la_LIBADD = \ - contents/libpychrysaanalysiscontents.la \ - db/libpychrysaanalysisdb.la - -libpychrysaanalysis_la_LDFLAGS = - - -AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ - -I../../../src - -AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) - -SUBDIRS = contents db diff --git a/plugins/pychrysa/analysis/binary.c b/plugins/pychrysa/analysis/binary.c deleted file mode 100644 index 6be767c..0000000 --- a/plugins/pychrysa/analysis/binary.c +++ /dev/null @@ -1,381 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * binary.c - équivalent Python du fichier "analysis/binary.h" - * - * Copyright (C) 2012-2017 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 "binary.h" - - -#include - - -#include - - -#include - - -#include "content.h" -#include "../helpers.h" - - - -/* Crée un nouvel objet Python de type 'LoadedBinary'. */ -static PyObject *py_loaded_binary_new(PyTypeObject *, PyObject *, PyObject *); - -/* Fournit le nom associé à l'élément binaire. */ -static PyObject *py_loaded_binary_get_name(PyObject *, void *); - -/* Lance l'analyse d'un élément binaire chargé. */ -static PyObject *py_loaded_binary_analyse(PyObject *, PyObject *); - -/* Lance l'analyse d'un binaire chargé et attend sa conclusion. */ -static PyObject *py_loaded_binary_analyse_and_wait(PyObject *, PyObject *); - -/* Fournit le format de fichier reconnu dans le contenu binaire. */ -static PyObject *py_loaded_binary_get_format(PyObject *, void *); - -/* Fournit le processeur de l'architecture liée au binaire. */ -static PyObject *py_loaded_binary_get_processor(PyObject *, void *); - -/* Fournit le tampon associé au contenu assembleur d'un binaire. */ -static PyObject *py_loaded_binary_get_disassembled_cache(PyObject *, void *); - - - -/****************************************************************************** -* * -* Paramètres : type = type de l'objet à instancier. * -* args = arguments fournis à l'appel. * -* kwds = arguments de type key=val fournis. * -* * -* Description : Crée un nouvel objet Python de type 'LoadedBinary'. * -* * -* Retour : Instance Python mise en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_loaded_binary_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - PyObject *result; /* Instance à retourner */ - PyObject *content_obj; /* Objet pour le contenu */ - int ret; /* Bilan de lecture des args. */ - GBinContent *content; /* Instance GLib correspondante*/ - GLoadedBinary *binary; /* Version GLib du format */ - - ret = PyArg_ParseTuple(args, "O", &content_obj); - if (!ret) return NULL; - - ret = PyObject_IsInstance(content_obj, (PyObject *)get_python_binary_content_type()); - if (ret == 0) - { - PyErr_SetString(PyExc_TypeError, _("Expected a BinContent as argument")); - return NULL; - } - - content = G_BIN_CONTENT(pygobject_get(content_obj)); - binary = g_loaded_binary_new(content); - - result = pygobject_new(G_OBJECT(binary)); - - g_object_unref(binary); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = objet Python concerné par l'appel. * -* closure = non utilisé ici. * -* * -* Description : Fournit le nom associé à l'élément binaire. * -* * -* Retour : Nom de fichier avec chemin absolu. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_loaded_binary_get_name(PyObject *self, void *closure) -{ - PyObject *result; /* Trouvailles à retourner */ - GLoadedBinary *binary; /* Version native */ - const char *name; /* Désignation du binaire */ - - binary = G_LOADED_BINARY(pygobject_get(self)); - - name = g_loaded_binary_get_name(binary, true); - - result = PyUnicode_FromString(name); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = contenu binaire à manipuler. * -* args = non utilisé ici. * -* * -* Description : Lance l'analyse d'un élément binaire chargé. * -* * -* Retour : Rien (None). * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_loaded_binary_analyse(PyObject *self, PyObject *args) -{ - GLoadedBinary *binary; /* Version GLib du format */ - - binary = G_LOADED_BINARY(pygobject_get(self)); - - g_loaded_binary_analyse(binary); - - Py_RETURN_NONE; - -} - - -/****************************************************************************** -* * -* Paramètres : self = contenu binaire à manipuler. * -* args = non utilisé ici. * -* * -* Description : Lance l'analyse d'un binaire chargé et attend sa conclusion. * -* * -* Retour : Rien (None). * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_loaded_binary_analyse_and_wait(PyObject *self, PyObject *args) -{ - GLoadedBinary *binary; /* Version GLib du format */ - - binary = G_LOADED_BINARY(pygobject_get(self)); - - g_loaded_binary_analyse_and_wait(binary); - - Py_RETURN_NONE; - -} - - -/****************************************************************************** -* * -* Paramètres : self = objet Python concerné par l'appel. * -* closure = non utilisé ici. * -* * -* Description : Fournit le format de fichier reconnu dans le contenu binaire.* -* * -* Retour : Instance du format reconnu. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_loaded_binary_get_format(PyObject *self, void *closure) -{ - PyObject *result; /* Instance Python à retourner */ - GLoadedBinary *binary; /* Binaire en cours d'analyse */ - GExeFormat *format; /* Format du binaire lié */ - - binary = G_LOADED_BINARY(pygobject_get(self)); - format = g_loaded_binary_get_format(binary); - - result = pygobject_new(G_OBJECT(format)); - - g_object_unref(G_OBJECT(format)); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = objet Python concerné par l'appel. * -* closure = non utilisé ici. * -* * -* Description : Fournit le processeur de l'architecture liée au binaire. * -* * -* Retour : Instance du processeur associé. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_loaded_binary_get_processor(PyObject *self, void *closure) -{ - PyObject *result; /* Instance Python à retourner */ - GLoadedBinary *binary; /* Binaire en cours d'analyse */ - GArchProcessor *proc; /* Architecture visée */ - - binary = G_LOADED_BINARY(pygobject_get(self)); - proc = g_loaded_binary_get_processor(binary); - - result = pygobject_new(G_OBJECT(proc)); - - g_object_unref(G_OBJECT(proc)); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = classe représentant une instruction. * -* closure = adresse non utilisée ici. * -* * -* Description : Fournit le tampon associé au contenu assembleur d'un binaire.* -* * -* Retour : Valeur associée à la propriété consultée. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_loaded_binary_get_disassembled_cache(PyObject *self, void *closure) -{ - PyObject *result; /* Trouvailles à retourner */ - GLoadedBinary *binary; /* Version native */ - GBufferCache *cache; /* Tampon à récupérer */ - - binary = G_LOADED_BINARY(pygobject_get(self)); - cache = g_loaded_binary_get_disassembled_cache(binary); - - result = pygobject_new(G_OBJECT(cache)); - - g_object_unref(G_OBJECT(cache)); - - 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_loaded_binary_type(void) -{ - static PyMethodDef py_loaded_binary_methods[] = { - { - "analyse", py_loaded_binary_analyse, - METH_NOARGS, - "analyse(/)\n--\n\nStart the analysis of the loaded binary and " \ - "send a \"disassembly-done\" signal when done." - }, - { - "analyse_and_wait", py_loaded_binary_analyse_and_wait, - METH_NOARGS, - "analyse_and_wait(/)\n--\n\nRun the analysis of the loaded binary and " \ - "wait for its completion." - }, - { NULL } - }; - - static PyGetSetDef py_loaded_binary_getseters[] = { - { - "name", py_loaded_binary_get_name, NULL, - "Name of the loaded binary.", NULL - }, - { - "format", py_loaded_binary_get_format, NULL, - "File format recognized in the binary content.", NULL - }, - { - "processor", py_loaded_binary_get_processor, NULL, - "Handler for the current binary processor.", NULL - }, - { - "disassembled_cache", py_loaded_binary_get_disassembled_cache, NULL, - "Disassembled buffer cache.", NULL - }, - { NULL } - }; - - static PyTypeObject py_loaded_binary_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.analysis.LoadedBinary", - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyChrysalide loaded binary", - - .tp_methods = py_loaded_binary_methods, - .tp_getset = py_loaded_binary_getseters, - .tp_new = (newfunc)py_loaded_binary_new - - }; - - return &py_loaded_binary_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.analysis.LoadedBinary'.* -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_loaded_binary(PyObject *module) -{ - PyTypeObject *py_loaded_binary_type; /* Type Python 'LoadedBinary' */ - PyObject *dict; /* Dictionnaire du module */ - - py_loaded_binary_type = get_python_loaded_binary_type(); - - dict = PyModule_GetDict(module); - - if (!register_class_for_pygobject(dict, G_TYPE_LOADED_BINARY, py_loaded_binary_type, &PyGObject_Type)) - return false; - - return true; - -} diff --git a/plugins/pychrysa/analysis/binary.h b/plugins/pychrysa/analysis/binary.h deleted file mode 100644 index d134111..0000000 --- a/plugins/pychrysa/analysis/binary.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * binary.h - prototypes pour l'équivalent Python du fichier "analysis/binary.h" - * - * Copyright (C) 2012-2017 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_PYOIDA_ANALYSIS_BINARY_H -#define _PLUGINS_PYOIDA_ANALYSIS_BINARY_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_loaded_binary_type(void); - -/* Prend en charge l'objet 'pychrysalide.analysis.LoadedBinary'. */ -bool register_python_loaded_binary(PyObject *); - - - -#endif /* _PLUGINS_PYOIDA_ANALYSIS_BINARY_H */ diff --git a/plugins/pychrysa/analysis/block.c b/plugins/pychrysa/analysis/block.c deleted file mode 100644 index edd364d..0000000 --- a/plugins/pychrysa/analysis/block.c +++ /dev/null @@ -1,274 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * block.c - équivalent Python du fichier "analysis/block.c" - * - * Copyright (C) 2013-2017 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 "block.h" - - -#include - - -#include - - -#include "../helpers.h" - - - -/* Permet la jonction entre C et Python lors des visites */ -typedef struct _py_block_vdata -{ - PyObject *func; /* Fonction à appeler */ - PyObject *user; /* Donnée à faire suivre */ - -} py_block_vdata; - - -/* Parcourt le bloc d'instructions dans un ordre donné. */ -static bool py_block_visitor_glue(GInstrBlock *, BlockVisitOrder, py_block_vdata *); - -/* Parcourt tous les blocs d'instructions dans un ordre donné. */ -static PyObject *py_instructions_block_visit(PyObject *, PyObject *); - -/* Fournit l'ensemble contenant les blocs liés. */ -static PyObject *py_instructions_block_get_links_block(PyObject *, PyObject *); - -/* Définit les constantes pour les blocs basiques. */ -static bool py_instructions_block_define_constants(PyTypeObject *); - - - -/****************************************************************************** -* * -* Paramètres : block = bloc d'instructions concerné par la visite. * -* order = indication sur la position dans le parcours. * -* data = donnée utilisateur à associer au parcours. * -* * -* Description : Parcourt le bloc d'instructions dans un ordre donné. * -* * -* Retour : true si le parcours a été jusqu'à son terme, false sinon. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool py_block_visitor_glue(GInstrBlock *block, BlockVisitOrder order, py_block_vdata *data) -{ - bool result; /* Bilan à retourner */ - PyObject *args; /* Arguments pour l'appel */ - PyObject *value; /* Retour obtenu */ - - Py_INCREF(data->user); - - args = PyTuple_New(3); - PyTuple_SetItem(args, 0, pygobject_new(G_OBJECT(block))); - PyTuple_SetItem(args, 1, PyLong_FromLong(order)); - PyTuple_SetItem(args, 2, data->user); - - value = _run_python_method(data->func, args); - result = (value == Py_True); - - Py_XDECREF(value); - Py_DECREF(args); - - return result; - -} - - - -/****************************************************************************** -* * -* Paramètres : self = classe représentant un binaire. * -* args = arguments fournis à l'appel. * -* * -* Description : Parcourt tous les blocs d'instructions dans un ordre donné. * -* * -* Retour : True si le parcours a été jusqu'à son terme, False sinon. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_instructions_block_visit(PyObject *self, PyObject *args) -{ - PyObject *result; /* Conclusion à retourner */ - py_block_vdata data; /* Transition entre C et Python*/ - int ret; /* Bilan de lecture des args. */ - GInstrBlock *block; /* Point de départ des visites */ - bool status; /* Bilan du parcours */ - - ret = PyArg_ParseTuple(args, "OO", &data.func, &data.user); - if (!ret) Py_RETURN_NONE; - - if (PyCallable_Check(data.func) != 1) return NULL; - - block = G_INSTR_BLOCK(pygobject_get(self)); - status = g_instr_block_visit(block, (instr_block_visitor_cb)py_block_visitor_glue, &data); - - result = (status ? Py_True : Py_False); - Py_INCREF(result); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = classe représentant un binaire. * -* args = arguments fournis à l'appel. * -* * -* Description : Fournit l'ensemble contenant les blocs liés. * -* * -* Retour : Bloc contenant les blocs liés au bloc. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_instructions_block_get_links_block(PyObject *self, PyObject *args) -{ - PyObject *result; /* Conclusion à retourner */ - GInstrBlock *block; /* Point de départ des visites */ - - block = G_INSTR_BLOCK(pygobject_get(self)); - - block = g_instr_block_get_links_block(block); - - result = pygobject_new(G_OBJECT(block)); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : obj_type = type dont le dictionnaire est à compléter. * -* * -* Description : Définit les constantes pour les blocs basiques. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool py_instructions_block_define_constants(PyTypeObject *obj_type) -{ - bool result; /* Bilan à retourner */ - - result = true; - - result &= PyDict_AddIntMacro(obj_type, BVO_IN); - result &= PyDict_AddIntMacro(obj_type, BVO_PENDING); - result &= PyDict_AddIntMacro(obj_type, BVO_OUT); - - 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_instr_block_type(void) -{ - static PyMethodDef py_instr_block_methods[] = { - { - "visit", (PyCFunction)py_instructions_block_visit, - METH_VARARGS, - "visit($self, cb, data, /)\n--\n\nVisit all the basic blocks, starting at the provided one." - }, - { - "get_links_block", (PyCFunction)py_instructions_block_get_links_block, - METH_VARARGS, - "get_links_block($self, /)\n--\n\nGet the block containing all blocks linked to the caller." - }, - { NULL } - }; - - static PyGetSetDef py_instr_block_getseters[] = { - { NULL } - }; - - static PyTypeObject py_instr_block_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.analysis.InstrBlock", - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyChrysalide basic block", - - .tp_methods = py_instr_block_methods, - .tp_getset = py_instr_block_getseters, - - }; - - return &py_instr_block_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.analysis.InstrBlock'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_instr_block(PyObject *module) -{ - PyTypeObject *py_instr_block_type; /* Type Python 'InstrBlock' */ - PyObject *dict; /* Dictionnaire du module */ - - py_instr_block_type = get_python_instr_block_type(); - - dict = PyModule_GetDict(module); - - if (!register_class_for_pygobject(dict, G_TYPE_INSTR_BLOCK, py_instr_block_type, &PyGObject_Type)) - return false; - - if (!py_instructions_block_define_constants(py_instr_block_type)) - return false; - - return true; - -} diff --git a/plugins/pychrysa/analysis/block.h b/plugins/pychrysa/analysis/block.h deleted file mode 100644 index 1f87445..0000000 --- a/plugins/pychrysa/analysis/block.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * block.h - prototypes pour l'équivalent Python du fichier "analysis/block.h" - * - * Copyright (C) 2013-2017 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_PYOIDA_ANALYSIS_BLOCK_H -#define _PLUGINS_PYOIDA_ANALYSIS_BLOCK_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_instr_block_type(void); - -/* Prend en charge l'objet 'pychrysalide.analysis.InstrBlock'. */ -bool register_python_instr_block(PyObject *); - - - -#endif /* _PLUGINS_PYOIDA_ANALYSIS_BLOCK_H */ diff --git a/plugins/pychrysa/analysis/content.c b/plugins/pychrysa/analysis/content.c deleted file mode 100644 index 1f36eb8..0000000 --- a/plugins/pychrysa/analysis/content.c +++ /dev/null @@ -1,460 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * content.c - prototypes pour l'équivalent Python du fichier "analysis/content.c" - * - * Copyright (C) 2015-2017 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 "content.h" - - -#include -#include - - -#include - - -#include -#include - - -#include "../arch/vmpa.h" - - - -/* Fournit une empreinte unique (SHA256) pour les données. */ -static PyObject *py_binary_content_get_checksum(PyObject *, PyObject *); - -/* Détermine le nombre d'octets lisibles. */ -static PyObject *py_binary_content_compute_size(PyObject *, PyObject *); - -/* Fournit une portion des données représentées. */ -static PyObject *py_binary_content_read_raw(PyObject *, PyObject *); - -/* Lit un nombre non signé sur un octet. */ -static PyObject *py_binary_content_read_u8(PyObject *, PyObject *); - -/* Lit un nombre non signé sur deux octets. */ -static PyObject *py_binary_content_read_u16(PyObject *, PyObject *); - -/* Lit un nombre non signé sur quatre octets. */ -static PyObject *py_binary_content_read_u32(PyObject *, PyObject *); - -/* Lit un nombre non signé sur huit octets. */ -static PyObject *py_binary_content_read_u64(PyObject *, PyObject *); - - - -/****************************************************************************** -* * -* Paramètres : self = contenu binaire à manipuler. * -* args = non utilisé ici. * -* * -* Description : Fournit une empreinte unique (SHA256) pour les données. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_content_get_checksum(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - GBinContent *content; /* Version GLib du format */ - const gchar *checksum; /* Empreinte fournie */ - - content = G_BIN_CONTENT(pygobject_get(self)); - - checksum = g_binary_content_get_checksum(content); - - result = PyUnicode_FromString(checksum); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = contenu binaire à manipuler. * -* args = non utilisé ici. * -* * -* Description : Détermine le nombre d'octets lisibles. * -* * -* Retour : Quantité représentée. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_content_compute_size(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - GBinContent *content; /* Version GLib du format */ - phys_t size; /* Quantité d'octets dispos. */ - - content = G_BIN_CONTENT(pygobject_get(self)); - - size = g_binary_content_compute_size(content); - - result = PyLong_FromUnsignedLongLong(size); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = contenu binaire à manipuler. * -* args = non utilisé ici. * -* * -* Description : Fournit une portion des données représentées. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_content_read_raw(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - GBinContent *content; /* Version GLib du format */ - PyObject *addr_obj; /* Objet pour une position */ - vmpa2t *addr; /* Position interne associée */ - unsigned long long length; /* Quantité de données à lire */ - int ret; /* Bilan de lecture des args. */ - const bin_t *val; /* Valeur lue à faire suivre */ - - content = G_BIN_CONTENT(pygobject_get(self)); - assert(content != NULL); - - ret = PyArg_ParseTuple(args, "OK", &addr_obj, &length); - if (!ret) return NULL; - - addr = get_internal_vmpa(addr_obj); - assert(addr != NULL); - - val = g_binary_content_get_raw_access(content, addr, length); - if (val == NULL) - { - PyErr_SetString(PyExc_Exception, _("Invalid read access.")); - return NULL; - } - - result = PyBytes_FromStringAndSize((char *)val, length); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = contenu binaire à manipuler. * -* args = non utilisé ici. * -* * -* Description : Lit un nombre non signé sur un octet. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_content_read_u8(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - GBinContent *content; /* Version GLib du format */ - int ret; /* Bilan de lecture des args. */ - PyObject *addr_obj; /* Objet pour une position */ - vmpa2t *addr; /* Position interne associée */ - uint8_t val; /* Valeur lue à faire suivre */ - bool status; /* Bilan de l'opération */ - - content = G_BIN_CONTENT(pygobject_get(self)); - assert(content != NULL); - - ret = PyArg_ParseTuple(args, "O", &addr_obj); - if (!ret) return NULL; - - addr = get_internal_vmpa(addr_obj); - assert(addr != NULL); - - status = g_binary_content_read_u8(content, addr, &val); - if (!status) - { - PyErr_SetString(PyExc_Exception, _("Invalid read access.")); - return NULL; - } - - result = PyLong_FromUnsignedLong(val); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = contenu binaire à manipuler. * -* args = non utilisé ici. * -* * -* Description : Lit un nombre non signé sur deux octets. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_content_read_u16(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - GBinContent *content; /* Version GLib du format */ - int ret; /* Bilan de lecture des args. */ - PyObject *addr_obj; /* Objet pour une position */ - unsigned long endianness; /* Boutisme de la lecture */ - vmpa2t *addr; /* Position interne associée */ - uint16_t val; /* Valeur lue à faire suivre */ - bool status; /* Bilan de l'opération */ - - content = G_BIN_CONTENT(pygobject_get(self)); - assert(content != NULL); - - ret = PyArg_ParseTuple(args, "Ok", &addr_obj, &endianness); - if (!ret) return NULL; - - addr = get_internal_vmpa(addr_obj); - assert(addr != NULL); - - status = g_binary_content_read_u16(content, addr, endianness, &val); - if (!status) - { - PyErr_SetString(PyExc_Exception, _("Invalid read access.")); - return NULL; - } - - result = PyLong_FromUnsignedLong(val); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = contenu binaire à manipuler. * -* args = non utilisé ici. * -* * -* Description : Lit un nombre non signé sur quatre octets. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_content_read_u32(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - GBinContent *content; /* Version GLib du format */ - int ret; /* Bilan de lecture des args. */ - PyObject *addr_obj; /* Objet pour une position */ - unsigned long endianness; /* Boutisme de la lecture */ - vmpa2t *addr; /* Position interne associée */ - uint32_t val; /* Valeur lue à faire suivre */ - bool status; /* Bilan de l'opération */ - - content = G_BIN_CONTENT(pygobject_get(self)); - assert(content != NULL); - - ret = PyArg_ParseTuple(args, "Ok", &addr_obj, &endianness); - if (!ret) return NULL; - - addr = get_internal_vmpa(addr_obj); - assert(addr != NULL); - - status = g_binary_content_read_u32(content, addr, endianness, &val); - if (!status) - { - PyErr_SetString(PyExc_Exception, _("Invalid read access.")); - return NULL; - } - - result = PyLong_FromUnsignedLong(val); - - return result; - -} - -/****************************************************************************** -* * -* Paramètres : self = contenu binaire à manipuler. * -* args = non utilisé ici. * -* * -* Description : Lit un nombre non signé sur huit octets. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_content_read_u64(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - GBinContent *content; /* Version GLib du format */ - int ret; /* Bilan de lecture des args. */ - PyObject *addr_obj; /* Objet pour une position */ - unsigned long endianness; /* Boutisme de la lecture */ - vmpa2t *addr; /* Position interne associée */ - uint64_t val; /* Valeur lue à faire suivre */ - bool status; /* Bilan de l'opération */ - - content = G_BIN_CONTENT(pygobject_get(self)); - assert(content != NULL); - - ret = PyArg_ParseTuple(args, "Ok", &addr_obj, &endianness); - if (!ret) return NULL; - - addr = get_internal_vmpa(addr_obj); - assert(addr != NULL); - - status = g_binary_content_read_u64(content, addr, endianness, &val); - if (!status) - { - PyErr_SetString(PyExc_Exception, _("Invalid read access.")); - return NULL; - } - - result = PyLong_FromUnsignedLongLong(val); - - 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_binary_content_type(void) -{ - static PyMethodDef py_binary_content_methods[] = { - { - "get_checksum", py_binary_content_get_checksum, - METH_NOARGS, - "get_checksum($self, /)\n--\n\nCompute a SHA256 hash as chechsum of handled data." - }, - { - "compute_size", py_binary_content_compute_size, - METH_NOARGS, - "compute_size($self, /)\n--\n\nCompute the quantity of readable bytes." - }, - { - "read_raw", py_binary_content_read_raw, - METH_VARARGS, - "read_raw($self, addr, length, /)\n--\n\nRead bytes from a given position." - }, - { - "read_u8", py_binary_content_read_u8, - METH_VARARGS, - "read_u8($self, addr, /)\n--\n\nRead an unsigned byte from a given position." - }, - { - "read_u16", py_binary_content_read_u16, - METH_VARARGS, - "read_u16($self, addr, endianness, /)\n--\n\nRead two unsigned bytes from a given position." - }, - { - "read_u32", py_binary_content_read_u32, - METH_VARARGS, - "read_u32($self, addr, endianness, /)\n--\n\nRead four unsigned bytes from a given position." - }, - { - "read_u64", py_binary_content_read_u64, - METH_VARARGS, - "read_u64($self, addr, endianness, /)\n--\n\nRead eight unsigned bytes from a given position." - }, - { NULL } - }; - - static PyGetSetDef py_binary_content_getseters[] = { - { NULL } - }; - - static PyTypeObject py_binary_content_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.analysis.BinContent", - .tp_basicsize = sizeof(PyObject), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyChrysalide binary content", - - .tp_methods = py_binary_content_methods, - .tp_getset = py_binary_content_getseters - - }; - - return &py_binary_content_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.analysis.BinContent'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_binary_content(PyObject *module) -{ - PyTypeObject *py_binary_content_type; /* Type Python 'BinContent' */ - PyObject *dict; /* Dictionnaire du module */ - - py_binary_content_type = get_python_binary_content_type(); - - dict = PyModule_GetDict(module); - pyg_register_interface(dict, "BinContent", G_TYPE_BIN_CONTENT, py_binary_content_type); - - return true; - -} diff --git a/plugins/pychrysa/analysis/content.h b/plugins/pychrysa/analysis/content.h deleted file mode 100644 index da1b9be..0000000 --- a/plugins/pychrysa/analysis/content.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * content.h - prototypes pour l'équivalent Python du fichier "analysis/content.h" - * - * Copyright (C) 2015-2017 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_PYCHRYSA_ANALYSIS_CONTENT_H -#define _PLUGINS_PYCHRYSA_ANALYSIS_CONTENT_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_binary_content_type(void); - -/* Prend en charge l'objet 'pychrysalide.analysis.BinContent'. */ -bool register_python_binary_content(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSA_ANALYSIS_CONTENT_H */ diff --git a/plugins/pychrysa/analysis/contents/Makefile.am b/plugins/pychrysa/analysis/contents/Makefile.am deleted file mode 100644 index 3cd00a6..0000000 --- a/plugins/pychrysa/analysis/contents/Makefile.am +++ /dev/null @@ -1,15 +0,0 @@ - -noinst_LTLIBRARIES = libpychrysaanalysiscontents.la - -libpychrysaanalysiscontents_la_SOURCES = \ - file.h file.c \ - module.h module.c \ - restricted.h restricted.c - -libpychrysaanalysiscontents_la_LDFLAGS = - - -AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ - -I../../../../src - -AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) diff --git a/plugins/pychrysa/analysis/contents/file.c b/plugins/pychrysa/analysis/contents/file.c deleted file mode 100644 index b033611..0000000 --- a/plugins/pychrysa/analysis/contents/file.c +++ /dev/null @@ -1,149 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * file.c - prototypes pour l'équivalent Python du fichier "analysis/contents/file.c" - * - * Copyright (C) 2015-2017 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 "file.h" - - -#include - - -#include - - -#include "../../helpers.h" - - - -/* Crée un nouvel objet Python de type 'BinContent'. */ -static PyObject *py_file_content_new(PyTypeObject *, PyObject *, PyObject *); - - - -/****************************************************************************** -* * -* Paramètres : type = type de l'objet à instancier. * -* args = arguments fournis à l'appel. * -* kwds = arguments de type key=val fournis. * -* * -* Description : Crée un nouvel objet Python de type 'BinContent'. * -* * -* Retour : Instance Python mise en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_file_content_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - PyObject *result; /* Instance à retourner */ - const char *filename; /* Nom du fichier à charger */ - int ret; /* Bilan de lecture des args. */ - GBinContent *content; /* Version GLib du contenu */ - - ret = PyArg_ParseTuple(args, "s", &filename); - if (!ret) Py_RETURN_NONE; - - content = g_file_content_new(filename); - - result = pygobject_new(G_OBJECT(content)); - - if (content != NULL) - 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_file_content_type(void) -{ - static PyMethodDef py_file_content_methods[] = { - { NULL } - }; - - static PyGetSetDef py_file_content_getseters[] = { - { NULL } - }; - - static PyTypeObject py_file_content_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.analysis.contents.FileContent", - .tp_basicsize = sizeof(PyGObject), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyChrysalide binary file content", - - .tp_methods = py_file_content_methods, - .tp_getset = py_file_content_getseters, - .tp_new = (newfunc)py_file_content_new - - }; - - return &py_file_content_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.....FileContent'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_file_content(PyObject *module) -{ - PyTypeObject *py_file_content_type; /* Type Python 'FileContent' */ - PyObject *dict; /* Dictionnaire du module */ - - py_file_content_type = get_python_file_content_type(); - - dict = PyModule_GetDict(module); - - if (!register_class_for_pygobject(dict, G_TYPE_FILE_CONTENT, py_file_content_type, &PyGObject_Type)) - return false; - - return true; - -} diff --git a/plugins/pychrysa/analysis/contents/file.h b/plugins/pychrysa/analysis/contents/file.h deleted file mode 100644 index 25e11dc..0000000 --- a/plugins/pychrysa/analysis/contents/file.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * file.h - prototypes pour l'équivalent Python du fichier "analysis/contents/file.h" - * - * Copyright (C) 2015-2017 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_PYCHRYSA_ANALYSIS_CONTENTS_FILE_H -#define _PLUGINS_PYCHRYSA_ANALYSIS_CONTENTS_FILE_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_file_content_type(void); - -/* Prend en charge l'objet 'pychrysalide.analysis.contents.FileContent'. */ -bool register_python_file_content(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSA_ANALYSIS_CONTENTS_FILE_H */ diff --git a/plugins/pychrysa/analysis/contents/module.c b/plugins/pychrysa/analysis/contents/module.c deleted file mode 100644 index 2daa62c..0000000 --- a/plugins/pychrysa/analysis/contents/module.c +++ /dev/null @@ -1,97 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * module.c - intégration du répertoire contents en tant que module - * - * Copyright (C) 2015-2017 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 "module.h" - - -#include - - -#include "file.h" -#include "restricted.h" -#include "../../access.h" - - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute le module 'contents' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ -#include "../content.h" -bool add_analysis_contents_module_to_python_module(PyObject *super) -{ - bool result; /* Bilan à retourner */ - PyObject *module; /* Sous-module mis en place */ - int ret; /* Bilan d'un appel */ - - static PyModuleDef py_chrysalide_contents_module = { - - .m_base = PyModuleDef_HEAD_INIT, - - .m_name = "pychrysalide.analysis.contents", - .m_doc = "Python module for Chrysalide.analysis.contents", - - .m_size = -1, - - }; - - result = false; - - module = PyModule_Create(&py_chrysalide_contents_module); - if (module == NULL) return false; - - ret = PyState_AddModule(super, &py_chrysalide_contents_module); - if (ret != 0) goto loading_failed; - - ret = _PyImport_FixupBuiltin(module, "pychrysalide.analysis.contents"); - if (ret != 0) goto loading_failed; - - Py_INCREF(module); - ret = PyModule_AddObject(super, "contents", module); - if (ret != 0) goto loading_failed; - - result = true; - - result &= register_python_binary_content(module); - - result &= register_python_file_content(module); - result &= register_python_restricted_content(module); - - if (result) - register_access_to_python_module("pychrysalide.analysis.contents", module); - - loading_failed: - - assert(result); - - return result; - -} diff --git a/plugins/pychrysa/analysis/contents/module.h b/plugins/pychrysa/analysis/contents/module.h deleted file mode 100644 index 1b6adfa..0000000 --- a/plugins/pychrysa/analysis/contents/module.h +++ /dev/null @@ -1,39 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * module.h - prototypes pour l'intégration du répertoire contents en tant que module - * - * Copyright (C) 2015-2017 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_PYOIDA_ANALYSIS_CONTENTS_MODULE_H -#define _PLUGINS_PYOIDA_ANALYSIS_CONTENTS_MODULE_H - - -#include -#include - - - -/* Ajoute le module 'contents' au module Python. */ -bool add_analysis_contents_module_to_python_module(PyObject *); - - - -#endif /* _PLUGINS_PYOIDA_ANALYSIS_CONTENTS_MODULE_H */ diff --git a/plugins/pychrysa/analysis/contents/restricted.c b/plugins/pychrysa/analysis/contents/restricted.c deleted file mode 100644 index f8b0b98..0000000 --- a/plugins/pychrysa/analysis/contents/restricted.c +++ /dev/null @@ -1,173 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * restricted.c - prototypes pour l'équivalent Python du fichier "analysis/contents/restricted.c" - * - * Copyright (C) 2015-2017 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 "restricted.h" - - -#include - - -#include - - -#include - - -#include "../content.h" -#include "../../helpers.h" -#include "../../arch/vmpa.h" - - - -/* Crée un nouvel objet Python de type 'BinContent'. */ -static PyObject *py_restricted_content_new(PyTypeObject *, PyObject *, PyObject *); - - - -/****************************************************************************** -* * -* Paramètres : type = type de l'objet à instancier. * -* args = arguments fournis à l'appel. * -* kwds = arguments de type key=val fournis. * -* * -* Description : Crée un nouvel objet Python de type 'BinContent'. * -* * -* Retour : Instance Python mise en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_restricted_content_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - PyObject *result; /* Instance à retourner */ - PyObject *content_obj; /* Objet pour le contenu */ - PyObject *range_obj; /* Objet pour la restriction */ - int ret; /* Bilan de lecture des args. */ - GBinContent *content; /* Instance GLib correspondante*/ - mrange_t *range; /* Restriction à appliquer */ - GBinContent *restricted; /* Création GLib à transmettre */ - - ret = PyArg_ParseTuple(args, "OO", &content_obj, &range_obj); - if (!ret) return NULL; - - ret = PyObject_IsInstance(content_obj, (PyObject *)get_python_binary_content_type()); - if (!ret) - { - PyErr_SetString(PyExc_TypeError, _("The first argument must be an instance of BinContent.")); - 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; - } - - content = G_BIN_CONTENT(pygobject_get(content_obj)); - - range = get_internal_mrange(range_obj); - - restricted = g_restricted_content_new(content, range); - - result = pygobject_new(G_OBJECT(restricted)); - - 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_restricted_content_type(void) -{ - static PyMethodDef py_restricted_content_methods[] = { - { NULL } - }; - - static PyGetSetDef py_restricted_content_getseters[] = { - { NULL } - }; - - static PyTypeObject py_restricted_content_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.analysis.contents.RestrictedContent", - .tp_basicsize = sizeof(PyGObject), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyChrysalide binary restricted content", - - .tp_methods = py_restricted_content_methods, - .tp_getset = py_restricted_content_getseters, - .tp_new = (newfunc)py_restricted_content_new - - }; - - return &py_restricted_content_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.....RestrictedContent'.* -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_restricted_content(PyObject *module) -{ - PyTypeObject *py_restricted_content_type;/* Type Python 'BinContent' */ - PyObject *dict; /* Dictionnaire du module */ - - py_restricted_content_type = get_python_restricted_content_type(); - - dict = PyModule_GetDict(module); - - if (!register_class_for_pygobject(dict, G_TYPE_RESTRICTED_CONTENT, - py_restricted_content_type, &PyGObject_Type)) - return false; - - return true; - -} diff --git a/plugins/pychrysa/analysis/contents/restricted.h b/plugins/pychrysa/analysis/contents/restricted.h deleted file mode 100644 index baf4bb2..0000000 --- a/plugins/pychrysa/analysis/contents/restricted.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * restricted.h - prototypes pour l'équivalent Python du fichier "analysis/contents/restricted.h" - * - * Copyright (C) 2015-2017 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_PYCHRYSA_ANALYSIS_CONTENTS_RESTRICTED_H -#define _PLUGINS_PYCHRYSA_ANALYSIS_CONTENTS_RESTRICTED_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_restricted_content_type(void); - -/* Prend en charge l'objet 'pychrysalide.analysis.contents.RestrictedContent'. */ -bool register_python_restricted_content(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSA_ANALYSIS_CONTENTS_RESTRICTED_H */ diff --git a/plugins/pychrysa/analysis/db/Makefile.am b/plugins/pychrysa/analysis/db/Makefile.am deleted file mode 100644 index a6bb701..0000000 --- a/plugins/pychrysa/analysis/db/Makefile.am +++ /dev/null @@ -1,19 +0,0 @@ - -noinst_LTLIBRARIES = libpychrysaanalysisdb.la - -libpychrysaanalysisdb_la_SOURCES = \ - certs.h certs.c \ - collection.h collection.c \ - item.h item.c \ - module.h module.c - -libpychrysaanalysisdb_la_LDFLAGS = \ - items/libpychrysaanalysisdbitems.la - - -AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ - -I../../../../src - -AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) - -SUBDIRS = items diff --git a/plugins/pychrysa/analysis/db/certs.c b/plugins/pychrysa/analysis/db/certs.c deleted file mode 100644 index e0358d1..0000000 --- a/plugins/pychrysa/analysis/db/certs.c +++ /dev/null @@ -1,327 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * certs.c - équivalent Python du fichier "analysis/db/certs.c" - * - * Copyright (C) 2017 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 "certs.h" - - -#include -#include - - -#include -#include - - -#include "../../helpers.h" - - - -/* Traduit en version native une identité de certificat. */ -static bool py_certs_fill_x509_entries(PyObject *, x509_entries *); - -/* Crée un certificat de signature racine. */ -static PyObject *py_certs_make_ca(PyObject *, PyObject *); - -/* Crée un certificat pour application. */ -static PyObject *py_certs_make_request(PyObject *, PyObject *); - -/* Signe un certificat pour application. */ -static PyObject *py_certs_sign_cert(PyObject *, PyObject *); - - - -/****************************************************************************** -* * -* Paramètres : dict = ensemble de propriétés renseignées. * -* out = résumé des entrées regroupées. [OUT] * -* * -* Description : Traduit en version native une identité de certificat. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool py_certs_fill_x509_entries(PyObject *dict, x509_entries *out) -{ - bool result; /* Bilan à retourner */ - PyObject *value; /* Valeur au format Python */ - -#define TRANSLATE_ENTRY(name, dest) \ - do \ - { \ - value = PyDict_GetItemString(dict, name); \ - if (value != NULL) \ - { \ - result = PyUnicode_Check(value); \ - if (result) \ - out->dest = strdup((char *)PyUnicode_DATA(value)); \ - else \ - PyErr_Format(PyExc_TypeError, _("The %s property must be a string."), name); \ - } \ - } \ - while (0) - - result = true; - - memset(out, 0, sizeof(x509_entries)); - - TRANSLATE_ENTRY("C", country); - - if (result) - TRANSLATE_ENTRY("ST", state); - - if (result) - TRANSLATE_ENTRY("L", locality); - - if (result) - TRANSLATE_ENTRY("O", organisation); - - if (result) - TRANSLATE_ENTRY("OU", organisational_unit); - - if (result) - TRANSLATE_ENTRY("CN", common_name); - - if (!result) - free_x509_entries(out); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = NULL car méthode statique. * -* args = paramètres à transmettre à l'appel natif. * -* * -* Description : Crée un certificat de signature racine. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_certs_make_ca(PyObject *self, PyObject *args) -{ - PyObject *result; /* Désignation à retourner */ - const char *dir; /* Répertoire de sortie */ - const char *label; /* Nom principal du certificat */ - unsigned long valid; /* Durée de validité en sec. */ - PyObject *dict; /* Détails identitaires */ - int ret; /* Bilan de lecture des args. */ - x509_entries entries; /* Définition d'une identité */ - bool status; /* Bilan d'une constitution */ - - ret = PyArg_ParseTuple(args, "sskO!", &dir, &label, &valid, &PyDict_Type, &dict); - if (!ret) return NULL; - - status = py_certs_fill_x509_entries(dict, &entries); - if (!status) return NULL; - - status = make_ca(dir, label, valid, &entries); - - free_x509_entries(&entries); - - result = status ? Py_True : Py_False; - - Py_INCREF(result); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = NULL car méthode statique. * -* args = paramètres à transmettre à l'appel natif. * -* * -* Description : Crée un certificat pour application. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_certs_make_request(PyObject *self, PyObject *args) -{ - PyObject *result; /* Désignation à retourner */ - const char *dir; /* Répertoire de sortie */ - const char *label; /* Nom principal du certificat */ - PyObject *dict; /* Détails identitaires */ - int ret; /* Bilan de lecture des args. */ - x509_entries entries; /* Définition d'une identité */ - bool status; /* Bilan d'une constitution */ - - ret = PyArg_ParseTuple(args, "ssO!", &dir, &label, &PyDict_Type, &dict); - if (!ret) return NULL; - - status = py_certs_fill_x509_entries(dict, &entries); - if (!status) return NULL; - - status = make_request(dir, label, &entries); - - free_x509_entries(&entries); - - result = status ? Py_True : Py_False; - - Py_INCREF(result); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = NULL car méthode statique. * -* args = paramètres à transmettre à l'appel natif. * -* * -* Description : Signe un certificat pour application. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_certs_sign_cert(PyObject *self, PyObject *args) -{ - PyObject *result; /* Désignation à retourner */ - const char *csr; /* Requête à satisfaire */ - const char *cacert; /* Certificat de confiance */ - const char *cakey; /* Clef de ce certificat */ - const char *cert; /* Certificat en sortie */ - unsigned long valid; /* Durée de validité en sec. */ - int ret; /* Bilan de lecture des args. */ - bool status; /* Bilan de l'opération */ - - ret = PyArg_ParseTuple(args, "ssssk", &csr, &cacert, &cakey, &cert, &valid); - if (!ret) return NULL; - - status = sign_cert(csr, cacert, cakey, cert, valid); - - result = status ? Py_True : Py_False; - - Py_INCREF(result); - - 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_certs_type(void) -{ - static PyMethodDef py_certs_methods[] = { - - { "make_ca", py_certs_make_ca, - METH_VARARGS | METH_STATIC, - "make_ca(dir, label, valid, entries, /)\n--\n\nCreate a certificate authority." - }, - { "make_request", py_certs_make_request, - METH_VARARGS | METH_STATIC, - "make_request(dir, label, entries, /)\n--\n\nCreate a certificate sign request." - }, - { "sign_cert", py_certs_sign_cert, - METH_VARARGS | METH_STATIC, - "sign_cert(csr, cacert, cakey, cert, valid, /)\n--\n\nSign a certificate sign request.." - }, - { NULL } - - }; - - static PyGetSetDef py_certs_getseters[] = { - - { NULL } - - }; - - static PyTypeObject py_certs_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.analysis.db.certs", - .tp_basicsize = sizeof(PyGObject), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyChrysalide support for DataBase certicates", - - .tp_methods = py_certs_methods, - .tp_getset = py_certs_getseters, - - }; - - return &py_certs_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide....db.certs'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_certs(PyObject *module) -{ - PyTypeObject *py_certs_type; /* Type Python pour 'certs' */ - int ret; /* Bilan d'un appel */ - - py_certs_type = get_python_certs_type(); - - py_certs_type->tp_new = PyType_GenericNew; - - if (PyType_Ready(py_certs_type) != 0) - return false; - - Py_INCREF(py_certs_type); - ret = PyModule_AddObject(module, "certs", (PyObject *)py_certs_type); - - return (ret == 0); - -} diff --git a/plugins/pychrysa/analysis/db/certs.h b/plugins/pychrysa/analysis/db/certs.h deleted file mode 100644 index f7537e5..0000000 --- a/plugins/pychrysa/analysis/db/certs.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * certs.h - prototypes pour l'équivalent Python du fichier "analysis/db/certs.h" - * - * Copyright (C) 2017 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_PYCHRYSA_ANALYSIS_DB_CERTS_H -#define _PLUGINS_PYCHRYSA_ANALYSIS_DB_CERTS_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_certs_type(void); - -/* Prend en charge l'objet 'pychrysalide.analysis.db.certs'. */ -bool register_python_certs(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSA_ANALYSIS_DB_CERTSS_H */ diff --git a/plugins/pychrysa/analysis/db/collection.c b/plugins/pychrysa/analysis/db/collection.c deleted file mode 100644 index 80fcfc2..0000000 --- a/plugins/pychrysa/analysis/db/collection.c +++ /dev/null @@ -1,110 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * collection.c - équivalent Python du fichier "analysis/db/collection.c" - * - * Copyright (C) 2014-2017 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 "collection.h" - - -#include - - -#include -#include - - -#include "../../helpers.h" - - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit un accès à une définition de type à diffuser. * -* * -* Retour : Définition d'objet pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyTypeObject *get_python_db_collection_type(void) -{ - static PyMethodDef py_db_collection_methods[] = { - { NULL } - }; - - static PyGetSetDef py_db_collection_getseters[] = { - - { NULL } - - }; - - static PyTypeObject py_db_collection_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.analysis.db.DbCollection", - .tp_basicsize = sizeof(PyGObject), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyChrysalide collection for DataBase collection", - - .tp_methods = py_db_collection_methods, - .tp_getset = py_db_collection_getseters, - - }; - - return &py_db_collection_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide....db.DbCollection'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_db_collection(PyObject *module) -{ - PyTypeObject *py_db_collection_type; /* Type Python 'DbCollection' */ - PyObject *dict; /* Dictionnaire du module */ - - py_db_collection_type = get_python_db_collection_type(); - - dict = PyModule_GetDict(module); - - if (!register_class_for_pygobject(dict, G_TYPE_DB_COLLECTION, py_db_collection_type, &PyGObject_Type)) - return false; - - return true; - -} diff --git a/plugins/pychrysa/analysis/db/collection.h b/plugins/pychrysa/analysis/db/collection.h deleted file mode 100644 index 2f2d1dd..0000000 --- a/plugins/pychrysa/analysis/db/collection.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * collection.h - prototypes pour l'équivalent Python du fichier "analysis/db/collection.h" - * - * Copyright (C) 2014-2017 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_PYCHRYSA_ANALYSIS_DB_COLLECTION_H -#define _PLUGINS_PYCHRYSA_ANALYSIS_DB_COLLECTION_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_db_collection_type(void); - -/* Prend en charge l'objet 'pychrysalide.analysis.db.DbCollection'. */ -bool register_python_db_collection(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSA_ANALYSIS_DB_COLLECTIONS_H */ diff --git a/plugins/pychrysa/analysis/db/item.c b/plugins/pychrysa/analysis/db/item.c deleted file mode 100644 index 27b5bac..0000000 --- a/plugins/pychrysa/analysis/db/item.c +++ /dev/null @@ -1,182 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * item.c - équivalent Python du fichier "analysis/db/item.c" - * - * Copyright (C) 2014-2017 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 "item.h" - - -#include - - -#include -#include - - -#include "../../helpers.h" - - - -/* Indique si l'élément contient des données à oublier ou non. */ -static PyObject *py_db_item_get_volatile(PyObject *, void *); - -/* Définit si l'élément contient des données à oublier ou non. */ -static int py_db_item_set_volatile(PyObject *, PyObject *, void *); - - - -/****************************************************************************** -* * -* Paramètres : self = objet Python concerné par l'appel. * -* closure = non utilisé ici. * -* * -* Description : Indique si l'élément contient des données à oublier ou non. * -* * -* Retour : Etat de la sauegarde de l'élément consulté. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_db_item_get_volatile(PyObject *self, void *closure) -{ - PyObject *result; /* Valeur à retourner */ - GDbItem *item; /* Elément à consulter */ - - item = G_DB_ITEM(pygobject_get(self)); - - result = (g_db_item_is_volatile(item) ? Py_True : Py_False); - Py_INCREF(result); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = objet Python concerné par l'appel. * -* value = valeur fournie à intégrer ou prendre en compte. * -* closure = non utilisé ici. * -* * -* Description : Définit si l'élément contient des données à oublier ou non. * -* * -* Retour : Bilan de l'opération pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static int py_db_item_set_volatile(PyObject *self, PyObject *value, void *closure) -{ - GDbItem *item; /* Elément à modifier */ - - if (!PyBool_Check(value)) - { - PyErr_SetString(PyExc_TypeError, _("The attribute value must be a boolean.")); - return -1; - } - - item = G_DB_ITEM(pygobject_get(self)); - g_db_item_set_volatile(item, (bool)(value == Py_True)); - - return 0; - -} - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit un accès à une définition de type à diffuser. * -* * -* Retour : Définition d'objet pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyTypeObject *get_python_db_item_type(void) -{ - static PyMethodDef py_db_item_methods[] = { - { NULL } - }; - - static PyGetSetDef py_db_item_getseters[] = { - - { - "volatile", py_db_item_get_volatile, py_db_item_set_volatile, - "Define if a Database item can be forgotten.", NULL - }, - { NULL } - - }; - - static PyTypeObject py_db_item_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.analysis.db.DbItem", - .tp_basicsize = sizeof(PyGObject), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyChrysalide item for DataBase collection", - - .tp_methods = py_db_item_methods, - .tp_getset = py_db_item_getseters, - - }; - - return &py_db_item_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide....db.items.DbItem'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_db_item(PyObject *module) -{ - PyTypeObject *py_db_item_type; /* Type Python 'DbItem' */ - PyObject *dict; /* Dictionnaire du module */ - - py_db_item_type = get_python_db_item_type(); - - dict = PyModule_GetDict(module); - - if (!register_class_for_pygobject(dict, G_TYPE_DB_ITEM, py_db_item_type, &PyGObject_Type)) - return false; - - return true; - -} diff --git a/plugins/pychrysa/analysis/db/item.h b/plugins/pychrysa/analysis/db/item.h deleted file mode 100644 index cfbe48a..0000000 --- a/plugins/pychrysa/analysis/db/item.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * item.h - prototypes pour l'équivalent Python du fichier "analysis/db/item.h" - * - * Copyright (C) 2014-2017 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_PYCHRYSA_ANALYSIS_DB_ITEM_H -#define _PLUGINS_PYCHRYSA_ANALYSIS_DB_ITEM_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_db_item_type(void); - -/* Prend en charge l'objet 'pychrysalide.analysis.db.DbItem'. */ -bool register_python_db_item(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSA_ANALYSIS_DB_ITEM_H */ diff --git a/plugins/pychrysa/analysis/db/items/Makefile.am b/plugins/pychrysa/analysis/db/items/Makefile.am deleted file mode 100644 index b08a558..0000000 --- a/plugins/pychrysa/analysis/db/items/Makefile.am +++ /dev/null @@ -1,14 +0,0 @@ - -noinst_LTLIBRARIES = libpychrysaanalysisdbitems.la - -libpychrysaanalysisdbitems_la_SOURCES = \ - comment.h comment.c \ - module.h module.c - -libpychrysaanalysisdbitems_la_LDFLAGS = - - -AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ - -I../../../../../src - -AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) diff --git a/plugins/pychrysa/analysis/db/items/comment.c b/plugins/pychrysa/analysis/db/items/comment.c deleted file mode 100644 index 28886f5..0000000 --- a/plugins/pychrysa/analysis/db/items/comment.c +++ /dev/null @@ -1,241 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * comment.c - équivalent Python du fichier "analysis/db/items/comment.c" - * - * Copyright (C) 2014-2017 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 "comment.h" - - -#include -#include - - -#include -#include - - -#include "../item.h" -#include "../../../helpers.h" -#include "../../../arch/vmpa.h" - - - -/* Crée un nouvel objet Python de type 'DbComment'. */ -static PyObject *py_db_comment_new(PyTypeObject *, PyObject *, PyObject *); - -/* Fournit le commentaire associé à un commentaire. */ -static PyObject *py_db_comment_get_text(PyObject *, void *); - -/* Définit le commentaire associé à un commentaire. */ -static int py_db_comment_set_text(PyObject *, PyObject *, void *); - - - -/****************************************************************************** -* * -* Paramètres : type = type de l'objet à instancier. * -* args = arguments fournis à l'appel. * -* kwds = arguments de type key=val fournis. * -* * -* Description : Crée un nouvel objet Python de type 'DbComment'. * -* * -* Retour : Instance Python mise en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_db_comment_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - PyObject *result; /* Instance à retourner */ - PyObject *py_vmpa; /* Localisation version Python */ - const char *text; /* Texte à associer */ - int is_volatile; /* Conservation en mémoire */ - int ret; /* Bilan de lecture des args. */ - vmpa2t *addr; /* Localisation version C */ - GDbComment *comment; /* Version GLib du commentaire */ - - ret = PyArg_ParseTuple(args, "Osp", &py_vmpa, &text, &is_volatile); - if (!ret) Py_RETURN_NONE; - - ret = PyObject_IsInstance(py_vmpa, (PyObject *)get_python_vmpa_type()); - if (!ret) return NULL; - - addr = get_internal_vmpa(py_vmpa); - if (py_vmpa == NULL) Py_RETURN_NONE; - - return NULL;/* FIXME */ - //comment = g_db_comment_new(addr, text, is_volatile); - - result = pygobject_new(G_OBJECT(comment)); - g_object_unref(comment); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = objet Python concerné par l'appel. * -* closure = non utilisé ici. * -* * -* Description : Fournit le commentaire associé à un commentaire. * -* * -* Retour : Texte manipulable en Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_db_comment_get_text(PyObject *self, void *closure) -{ - PyObject *result; /* Résultat à retourner */ - GDbComment *comment; /* Commentaire à consulter */ - char *text; /* Contenu textuel associé */ - - comment = G_DB_COMMENT(pygobject_get(self)); - text = g_db_comment_get_text(comment); - - if (text == NULL) - { - result = Py_None; - Py_INCREF(result); - } - else - { - result = PyUnicode_FromString(text); - free(text); - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = objet Python concerné par l'appel. * -* value = valeur fournie à intégrer ou prendre en compte. * -* closure = non utilisé ici. * -* * -* Description : Définit le commentaire associé à un commentaire. * -* * -* Retour : Bilan de l'opération pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static int py_db_comment_set_text(PyObject *self, PyObject *value, void *closure) -{ - GDbComment *comment; /* Commentaire à consulter */ - - if (!PyUnicode_Check(value)) - { - PyErr_SetString(PyExc_TypeError, _("The attribute value must be a string.")); - return -1; - } - - comment = G_DB_COMMENT(pygobject_get(self)); - //g_db_comment_set_text(comment, PyUnicode_DATA(value)); - - return 0; - -} - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit un accès à une définition de type à diffuser. * -* * -* Retour : Définition d'objet pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyTypeObject *get_python_db_comment_type(void) -{ - static PyMethodDef py_db_comment_methods[] = { - { NULL } - }; - - static PyGetSetDef py_db_comment_getseters[] = { - { - "text", py_db_comment_get_text, py_db_comment_set_text, - "Give access to the content of a given comment.", NULL - }, - { NULL } - }; - - static PyTypeObject py_db_comment_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.analysis.db.items.DbComment", - .tp_basicsize = sizeof(PyGObject), - - .tp_flags = Py_TPFLAGS_DEFAULT, - - .tp_doc = "PyChrysalide comment for edited binary", - - .tp_methods = py_db_comment_methods, - .tp_getset = py_db_comment_getseters, - .tp_new = (newfunc)py_db_comment_new - - }; - - return &py_db_comment_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide....db.items.DbComment'.* -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_db_comment(PyObject *module) -{ - PyTypeObject *py_db_comment_type; /* Type Python 'DbComment' */ - PyObject *dict; /* Dictionnaire du module */ - - py_db_comment_type = get_python_db_comment_type(); - - dict = PyModule_GetDict(module); - - if (!register_class_for_pygobject(dict, G_TYPE_DB_COMMENT, py_db_comment_type, get_python_db_item_type())) - return false; - - return true; - -} diff --git a/plugins/pychrysa/analysis/db/items/comment.h b/plugins/pychrysa/analysis/db/items/comment.h deleted file mode 100644 index bf74ad0..0000000 --- a/plugins/pychrysa/analysis/db/items/comment.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * comment.h - prototypes pour l'équivalent Python du fichier "analysis/db/items/comment.h" - * - * Copyright (C) 2014-2017 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_PYCHRYSA_ANALYSIS_DB_ITEMS_COMMENT_H -#define _PLUGINS_PYCHRYSA_ANALYSIS_DB_ITEMS_COMMENT_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_db_comment_type(void); - -/* Prend en charge l'objet 'pychrysalide.analysis.db.items.DbComment'. */ -bool register_python_db_comment(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSA_ANALYSIS_DB_ITEMS_COMMENT_H */ diff --git a/plugins/pychrysa/analysis/db/items/module.c b/plugins/pychrysa/analysis/db/items/module.c deleted file mode 100644 index cf0fe56..0000000 --- a/plugins/pychrysa/analysis/db/items/module.c +++ /dev/null @@ -1,93 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * module.c - intégration du répertoire items en tant que module - * - * Copyright (C) 2014-2017 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 "module.h" - - -#include - - -#include "comment.h" -#include "../../../access.h" - - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute le module 'items' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool add_analysis_db_items_module_to_python_module(PyObject *super) -{ - bool result; /* Bilan à retourner */ - PyObject *module; /* Sous-module mis en place */ - int ret; /* Bilan d'un appel */ - - static PyModuleDef py_chrysalide_items_module = { - - .m_base = PyModuleDef_HEAD_INIT, - - .m_name = "pychrysalide.analysis.db.items", - .m_doc = "Python module for Chrysalide.analysis.db.items", - - .m_size = -1, - - }; - - result = false; - - module = PyModule_Create(&py_chrysalide_items_module); - if (module == NULL) return false; - - ret = PyState_AddModule(super, &py_chrysalide_items_module); - if (ret != 0) goto loading_failed; - - ret = _PyImport_FixupBuiltin(module, "pychrysalide.analysis.db.items"); - if (ret != 0) goto loading_failed; - - Py_INCREF(module); - ret = PyModule_AddObject(super, "items", module); - if (ret != 0) goto loading_failed; - - result = true; - - result &= register_python_db_comment(module); - - if (result) - register_access_to_python_module("pychrysalide.analysis.db.items", module); - - loading_failed: - - assert(result); - - return result; - -} diff --git a/plugins/pychrysa/analysis/db/items/module.h b/plugins/pychrysa/analysis/db/items/module.h deleted file mode 100644 index 12d9f43..0000000 --- a/plugins/pychrysa/analysis/db/items/module.h +++ /dev/null @@ -1,39 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * module.h - prototypes pour l'intégration du répertoire items en tant que module - * - * Copyright (C) 2014-2017 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_PYCHRYSA_ANALYSIS_DB_ITEMS_MODULE_H -#define _PLUGINS_PYCHRYSA_ANALYSIS_DB_ITEMS_MODULE_H - - -#include -#include - - - -/* Ajoute le module 'items' au module Python. */ -bool add_analysis_db_items_module_to_python_module(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSA_ANALYSIS_DB_ITEMS_MODULE_H */ diff --git a/plugins/pychrysa/analysis/db/module.c b/plugins/pychrysa/analysis/db/module.c deleted file mode 100644 index 1c4da25..0000000 --- a/plugins/pychrysa/analysis/db/module.c +++ /dev/null @@ -1,100 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * module.c - intégration du répertoire db en tant que module - * - * Copyright (C) 2014-2017 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 "module.h" - - -#include - - -#include "certs.h" -#include "collection.h" -#include "item.h" -#include "items/module.h" -#include "../../access.h" - - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute le module 'db' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool add_analysis_db_module_to_python_module(PyObject *super) -{ - bool result; /* Bilan à retourner */ - PyObject *module; /* Sous-module mis en place */ - int ret; /* Bilan d'un appel */ - - static PyModuleDef py_chrysalide_db_module = { - - .m_base = PyModuleDef_HEAD_INIT, - - .m_name = "pychrysalide.analysis.db", - .m_doc = "Python module for Chrysalide.analysis.db", - - .m_size = -1, - - }; - - result = false; - - module = PyModule_Create(&py_chrysalide_db_module); - if (module == NULL) return false; - - ret = PyState_AddModule(super, &py_chrysalide_db_module); - if (ret != 0) goto loading_failed; - - ret = _PyImport_FixupBuiltin(module, "pychrysalide.analysis.db"); - if (ret != 0) goto loading_failed; - - Py_INCREF(module); - ret = PyModule_AddObject(super, "db", module); - if (ret != 0) goto loading_failed; - - result = true; - - result &= register_python_certs(module); - result &= register_python_db_collection(module); - result &= register_python_db_item(module); - - result &= add_analysis_db_items_module_to_python_module(module); - - if (result) - register_access_to_python_module("pychrysalide.analysis.db", module); - - loading_failed: - - assert(result); - - return result; - -} diff --git a/plugins/pychrysa/analysis/db/module.h b/plugins/pychrysa/analysis/db/module.h deleted file mode 100644 index 9adeb20..0000000 --- a/plugins/pychrysa/analysis/db/module.h +++ /dev/null @@ -1,39 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * module.h - prototypes pour l'intégration du répertoire db en tant que module - * - * Copyright (C) 2014-2017 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_PYCHRYSA_ANALYSIS_DB_MODULE_H -#define _PLUGINS_PYCHRYSA_ANALYSIS_DB_MODULE_H - - -#include -#include - - - -/* Ajoute le module 'db' au module Python. */ -bool add_analysis_db_module_to_python_module(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSA_ANALYSIS_DB_MODULE_H */ diff --git a/plugins/pychrysa/analysis/loaded.c b/plugins/pychrysa/analysis/loaded.c deleted file mode 100644 index b38025a..0000000 --- a/plugins/pychrysa/analysis/loaded.c +++ /dev/null @@ -1,146 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * loaded.c - prototypes pour l'équivalent Python du fichier "analysis/loaded.c" - * - * Copyright (C) 2017 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 "loaded.h" - - -#include -#include - - -#include - - -#include - - - -/* Détermine le nombre de vues disponibles pour un contenu. */ -static PyObject *py_loaded_content_count_views(PyObject *, PyObject *); - - - -/****************************************************************************** -* * -* Paramètres : self = contenu chargé à manipuler. * -* args = non utilisé ici. * -* * -* Description : Détermine le nombre de vues disponibles pour un contenu. * -* * -* Retour : Quantité strictement positive. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_loaded_content_count_views(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - GLoadedContent *content; /* Version GLib du format */ - size_t count; /* Quantité à retourner */ - - content = G_LOADED_CONTENT(pygobject_get(self)); - - count = g_loaded_content_count_views(content); - - result = PyLong_FromUnsignedLongLong(count); - - 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_loaded_content_type(void) -{ - static PyMethodDef py_loaded_content_methods[] = { - { - "count_views", py_loaded_content_count_views, - METH_NOARGS, - "count_views($self, /)\n--\n\nCompute the quantity of available views." - }, - { NULL } - }; - - static PyGetSetDef py_loaded_content_getseters[] = { - { NULL } - }; - - static PyTypeObject py_loaded_content_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.analysis.LoadedContent", - .tp_basicsize = sizeof(PyObject), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyChrysalide loaded content", - - .tp_methods = py_loaded_content_methods, - .tp_getset = py_loaded_content_getseters - - }; - - return &py_loaded_content_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.....LoadedContent'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_loaded_content(PyObject *module) -{ - PyTypeObject *py_loaded_content_type; /* Type Python 'LoadedContent' */ - PyObject *dict; /* Dictionnaire du module */ - - py_loaded_content_type = get_python_loaded_content_type(); - - dict = PyModule_GetDict(module); - pyg_register_interface(dict, "LoadedContent", G_TYPE_LOADED_CONTENT, py_loaded_content_type); - - return true; - -} diff --git a/plugins/pychrysa/analysis/loaded.h b/plugins/pychrysa/analysis/loaded.h deleted file mode 100644 index 3238202..0000000 --- a/plugins/pychrysa/analysis/loaded.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * loaded.h - prototypes pour l'équivalent Python du fichier "analysis/loaded.h" - * - * Copyright (C) 2017 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_PYCHRYSA_ANALYSIS_LOADED_H -#define _PLUGINS_PYCHRYSA_ANALYSIS_LOADED_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_loaded_content_type(void); - -/* Prend en charge l'objet 'pychrysalide.analysis.LoadedContent'. */ -bool register_python_loaded_content(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSA_ANALYSIS_CONTENT_H */ diff --git a/plugins/pychrysa/analysis/module.c b/plugins/pychrysa/analysis/module.c deleted file mode 100644 index f4a0f5b..0000000 --- a/plugins/pychrysa/analysis/module.c +++ /dev/null @@ -1,107 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * module.c - intégration du répertoire analysis en tant que module - * - * Copyright (C) 2012-2017 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 "module.h" - - -#include - - -#include "binary.h" -#include "block.h" -#include "content.h" -#include "loaded.h" -#include "routine.h" -#include "contents/module.h" -#include "db/module.h" -#include "../access.h" - - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute le module 'analysis' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool add_analysis_module_to_python_module(PyObject *super) -{ - bool result; /* Bilan à retourner */ - PyObject *module; /* Sous-module mis en place */ - int ret; /* Bilan d'un appel */ - - static PyModuleDef py_chrysalide_analysis_module = { - - .m_base = PyModuleDef_HEAD_INIT, - - .m_name = "pychrysalide.analysis", - .m_doc = "Python module for Chrysalide.analysis", - - .m_size = -1, - - }; - - result = false; - - module = PyModule_Create(&py_chrysalide_analysis_module); - if (module == NULL) return false; - - ret = PyState_AddModule(super, &py_chrysalide_analysis_module); - if (ret != 0) goto loading_failed; - - ret = _PyImport_FixupBuiltin(module, "pychrysalide.analysis"); - if (ret != 0) goto loading_failed; - - Py_INCREF(module); - ret = PyModule_AddObject(super, "analysis", module); - if (ret != 0) goto loading_failed; - - result = true; - - result &= register_python_loaded_content(module); - - result &= register_python_loaded_binary(module); - result &= register_python_instr_block(module); - //result &= register_python_binary_content(module); - result &= register_python_binary_routine(module); - - result &= add_analysis_contents_module_to_python_module(module); - result &= add_analysis_db_module_to_python_module(module); - - if (result) - register_access_to_python_module("pychrysalide.analysis", module); - - loading_failed: - - assert(result); - - return result; - -} diff --git a/plugins/pychrysa/analysis/module.h b/plugins/pychrysa/analysis/module.h deleted file mode 100644 index 310fc0c..0000000 --- a/plugins/pychrysa/analysis/module.h +++ /dev/null @@ -1,39 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * module.h - prototypes pour l'intégration du répertoire analysis en tant que module - * - * Copyright (C) 2012-2017 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_ANALYSIS_MODULE_H -#define _PLUGINS_PYCHRYSALIDE_ANALYSIS_MODULE_H - - -#include -#include - - - -/* Ajoute le module 'analysis' au module Python. */ -bool add_analysis_module_to_python_module(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_MODULE_H */ diff --git a/plugins/pychrysa/analysis/routine.c b/plugins/pychrysa/analysis/routine.c deleted file mode 100644 index 37f36a7..0000000 --- a/plugins/pychrysa/analysis/routine.c +++ /dev/null @@ -1,295 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * routine.c - équivalent Python du fichier "analysis/routine.c" - * - * Copyright (C) 2013-2017 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 "routine.h" - - -#include -#include - - -#include - - -#include -#include - - -#include "block.h" -#include "../helpers.h" -#include "../format/symbol.h" - - - -/* Crée un nouvel objet Python de type 'BinRoutine'. */ -static PyObject *py_binary_routine_new(PyTypeObject *, PyObject *, PyObject *); - -/* Fournit le nom humain d'une routine. */ -static PyObject *py_binary_routine_get_name(PyObject *, void *); - -/* Définit le nom humain d'une routine. */ -static int py_binary_routine_set_name(PyObject *, PyObject *, void *); - -/* Fournit les blocs basiques de la routine. */ -static PyObject *py_binary_routine_get_basic_blocks(PyObject *, void *); - - - -/****************************************************************************** -* * -* Paramètres : type = type de l'objet à instancier. * -* args = arguments fournis à l'appel. * -* kwds = arguments de type key=val fournis. * -* * -* Description : Crée un nouvel objet Python de type 'BinaryRoutine'. * -* * -* Retour : Instance Python mise en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_routine_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - PyObject *result; /* Création à retourner */ - - result = pygobject_new(G_OBJECT(g_binary_routine_new())); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = objet Python concerné par l'appel. * -* closure = non utilisé ici. * -* * -* Description : Fournit le nom humain d'une routine. * -* * -* Retour : Désignation humainement lisible ou None si non définie. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_routine_get_name(PyObject *self, void *closure) -{ - PyObject *result; /* Valeur à retourner */ - GBinRoutine *routine; /* Elément à consulter */ - const char *name; /* Désignation courante */ - - routine = G_BIN_ROUTINE(pygobject_get(self)); - name = g_binary_routine_get_name(routine); - - if (name != NULL) - result = PyUnicode_FromString(name); - else - { - result = Py_None; - Py_INCREF(result); - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = objet Python concerné par l'appel. * -* value = valeur fournie à intégrer ou prendre en compte. * -* closure = non utilisé ici. * -* * -* Description : Définit le nom humain d'une routine. * -* * -* Retour : Bilan de l'opération pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static int py_binary_routine_set_name(PyObject *self, PyObject *value, void *closure) -{ - GBinRoutine *routine; /* Elément à consulter */ - - if (!PyUnicode_Check(value) && value != Py_None) - { - PyErr_SetString(PyExc_TypeError, _("The attribute value must be a string.")); - return -1; - } - - routine = G_BIN_ROUTINE(pygobject_get(self)); - - if (!PyUnicode_Check(value)) - g_binary_routine_set_name(routine, strdup(PyUnicode_DATA(value))); - else - g_binary_routine_set_name(routine, NULL); - - return 0; - -} - - -/****************************************************************************** -* * -* Paramètres : self = classe représentant une routine binaire. * -* closure = adresse non utilisée ici. * -* * -* Description : Fournit les blocs basiques de la routine. * -* * -* Retour : Ensemble de blocs déterminés via les instructions. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_routine_get_basic_blocks(PyObject *self, void *closure) -{ - PyObject *result; /* Eléments à retourner */ - GBinRoutine *routine; /* Version native */ - GBlockList *blocks; /* Blocs basiques de routine */ - - routine = G_BIN_ROUTINE(pygobject_get(self)); - blocks = g_binary_routine_get_basic_blocks(routine); - - result = pygobject_new(G_OBJECT(blocks)); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = objet Python concerné par l'appel. * -* value = valeur fournie à intégrer ou prendre en compte. * -* closure = non utilisé ici. * -* * -* Description : Définit les blocs basiques de la routine. * -* * -* Retour : Bilan de l'opération pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static int py_binary_routine_set_basic_blocks(PyObject *self, PyObject *value, void *closure) -{ - GBinRoutine *routine; /* Elément à consulter */ - int ret; /* Bilan de lecture des args. */ - GBlockList *blocks; /* Blocs basiques à intégrer */ - - ret = PyObject_IsInstance(value, (PyObject *)get_python_instr_block_type()); - if (!ret) return -1; - - routine = G_BIN_ROUTINE(pygobject_get(self)); - blocks = G_BLOCK_LIST(pygobject_get(value)); - - g_binary_routine_set_basic_blocks(routine, blocks); - - return 0; - -} - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit un accès à une définition de type à diffuser. * -* * -* Retour : Définition d'objet pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyTypeObject *get_python_binary_routine_type(void) -{ - static PyMethodDef py_binary_routine_methods[] = { - { NULL } - }; - - static PyGetSetDef py_binary_routine_getseters[] = { - { - "name", py_binary_routine_get_name, py_binary_routine_set_name, - "Name of the current routine.", NULL - }, - { - "basic_blocks", py_binary_routine_get_basic_blocks, py_binary_routine_set_basic_blocks, - "Basic blocks of the binary routine.", NULL - }, - { NULL } - }; - - static PyTypeObject py_binary_routine_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.analysis.BinRoutine", - - .tp_flags = Py_TPFLAGS_DEFAULT, - - .tp_doc = "PyChrysalide binary routine", - - .tp_methods = py_binary_routine_methods, - .tp_getset = py_binary_routine_getseters, - .tp_new = (newfunc)py_binary_routine_new - - }; - - return &py_binary_routine_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.analysis.BinRoutine'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_binary_routine(PyObject *module) -{ - PyTypeObject *py_binary_routine_type; /* Type Python 'BinRoutine' */ - PyObject *dict; /* Dictionnaire du module */ - - py_binary_routine_type = get_python_binary_routine_type(); - - dict = PyModule_GetDict(module); - - if (!register_class_for_pygobject(dict, G_TYPE_BIN_ROUTINE, - py_binary_routine_type, get_python_binary_symbol_type())) - return false; - - return true; - -} diff --git a/plugins/pychrysa/analysis/routine.h b/plugins/pychrysa/analysis/routine.h deleted file mode 100644 index 57ad7bc..0000000 --- a/plugins/pychrysa/analysis/routine.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * routine.h - prototypes pour l'équivalent Python du fichier "analysis/routine.h" - * - * Copyright (C) 2013-2017 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_PYOIDA_ANALYSIS_ROUTINE_H -#define _PLUGINS_PYOIDA_ANALYSIS_ROUTINE_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_binary_routine_type(void); - -/* Prend en charge l'objet 'pychrysalide.analysis.BinRoutine'. */ -bool register_python_binary_routine(PyObject *); - - - -#endif /* _PLUGINS_PYOIDA_ANALYSIS_ROUTINE_H */ diff --git a/plugins/pychrysa/arch/Makefile.am b/plugins/pychrysa/arch/Makefile.am deleted file mode 100644 index 694c9e0..0000000 --- a/plugins/pychrysa/arch/Makefile.am +++ /dev/null @@ -1,25 +0,0 @@ - -noinst_LTLIBRARIES = libpychrysaarch.la - -libpychrysaarch_la_SOURCES = \ - immediate.h immediate.c \ - instriter.h instriter.c \ - instruction.h instruction.c \ - module.h module.c \ - operand.h operand.c \ - processor.h processor.c \ - raw.h raw.c \ - vmpa.h vmpa.c - -libpychrysaarch_la_LIBADD = - - -libpychrysaarch_la_LDFLAGS = - - -AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ - -I../../../src - -AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) - -SUBDIRS = diff --git a/plugins/pychrysa/arch/immediate.c b/plugins/pychrysa/arch/immediate.c deleted file mode 100644 index f1ec125..0000000 --- a/plugins/pychrysa/arch/immediate.c +++ /dev/null @@ -1,700 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * immediate.c - équivalent Python du fichier "arch/immediate.h" - * - * Copyright (C) 2012-2017 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 "immediate.h" - - -#include - - -#include - - -#include - - -#include "operand.h" -#include "../helpers.h" - - - -/* Fournit la valeur portée par une opérande numérique. */ -static PyObject *py_imm_operand_get_value(PyObject *, void *); - -/* Indique si l'affichage est complété avec des zéros. */ -static PyObject *py_imm_operand_get_padding_by_default(PyObject *self, void *); - -/* Précise si des zéro doivent compléter l'affichage ou non. */ -static int py_imm_operand_set_padding_by_default(PyObject *, PyObject *, void *); - -/* Indique si l'affichage est complété avec des zéros. */ -static PyObject *py_imm_operand_get_padding(PyObject *self, void *); - -/* Précise si des zéro doivent compléter l'affichage ou non. */ -static int py_imm_operand_set_padding(PyObject *, PyObject *, void *); - -/* Indique le format textuel par défaut de la valeur. */ -static PyObject *py_imm_operand_get_default_display(PyObject *, void *); - -/* Définit le format textuel par défaut de la valeur. */ -static int py_imm_operand_set_default_display(PyObject *, PyObject *, void *); - -/* Indique la grande ligne du format textuel de la valeur. */ -static PyObject *py_imm_operand_get_display(PyObject *, void *); - -/* Définit la grande ligne du format textuel de la valeur. */ -static int py_imm_operand_set_display(PyObject *, PyObject *, void *); - -/* Construit la chaîne de caractères correspondant à l'opérande. */ -static PyObject *py_imm_operand_to_string(PyObject *, PyObject *); - -/* Crée un nouvel objet Python de type 'ImmOperand'. */ -static PyObject *py_imm_operand_new(PyTypeObject *, PyObject *, PyObject *); - -/* Définit les constantes pour les opérandes d'immédiats. */ -static bool py_imm_operand_define_constants(PyTypeObject *); - - - -/****************************************************************************** -* * -* Paramètres : self = objet Python concerné par l'appel. * -* closure = non utilisé ici. * -* * -* Description : Renseigne la taille de la valeur indiquée à la construction. * -* * -* Retour : Taille de la valeur représentée en mémoire. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_imm_operand_get_size(PyObject *self, void *closure) -{ - PyObject *result; /* Instance Python à retourner */ - GImmOperand *operand; /* Version GLib de l'opérande */ - MemoryDataSize size; /* Type de donnée représentée */ - - operand = G_IMM_OPERAND(pygobject_get(self)); - assert(operand != NULL); - - size = g_imm_operand_get_size(operand); - - result = Py_BuildValue("I", size); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = objet Python concerné par l'appel. * -* closure = non utilisé ici. * -* * -* Description : Fournit la valeur portée par une opérande numérique. * -* * -* Retour : Valeur contenue dans l'opérande, ou None en cas de soucis. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_imm_operand_get_value(PyObject *self, void *closure) -{ - PyObject *result; /* Instance Python à retourner */ - GImmOperand *operand; /* Version GLib de l'opérande */ - MemoryDataSize size; /* Type de donnée représentée */ - uint8_t uval8; /* Valeur sur 8 bits */ - uint16_t uval16; /* Valeur sur 16 bits */ - uint32_t uval32; /* Valeur sur 32 bits */ - uint64_t uval64; /* Valeur sur 64 bits */ - int8_t sval8; /* Valeur sur 8 bits */ - int16_t sval16; /* Valeur sur 16 bits */ - int32_t sval32; /* Valeur sur 32 bits */ - int64_t sval64; /* Valeur sur 64 bits */ - - operand = G_IMM_OPERAND(pygobject_get(self)); - assert(operand != NULL); - - size = g_imm_operand_get_size(operand); - - switch (size) - { - /* Pour GCC... */ - case MDS_UNDEFINED: - result = Py_None; - Py_INCREF(result); - break; - case MDS_4_BITS_UNSIGNED: - case MDS_8_BITS_UNSIGNED: - g_imm_operand_get_value(operand, size, &uval8); - result = PyLong_FromUnsignedLong(uval8); - break; - case MDS_16_BITS_UNSIGNED: - g_imm_operand_get_value(operand, size, &uval16); - result = PyLong_FromUnsignedLong(uval16); - break; - case MDS_32_BITS_UNSIGNED: - g_imm_operand_get_value(operand, size, &uval32); - result = PyLong_FromUnsignedLong(uval32); - break; - case MDS_64_BITS_UNSIGNED: - g_imm_operand_get_value(operand, size, &uval64); - result = PyLong_FromUnsignedLongLong(uval64); - break; - case MDS_4_BITS_SIGNED: - case MDS_8_BITS_SIGNED: - g_imm_operand_get_value(operand, size, &sval8); - result = PyLong_FromLong(sval8); - break; - case MDS_16_BITS_SIGNED: - g_imm_operand_get_value(operand, size, &sval16); - result = PyLong_FromLong(sval16); - break; - case MDS_32_BITS_SIGNED: - g_imm_operand_get_value(operand, size, &sval32); - result = PyLong_FromLong(sval32); - break; - case MDS_64_BITS_SIGNED: - g_imm_operand_get_value(operand, size, &sval64); - result = PyLong_FromLongLong(sval64); - break; - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = objet Python concerné par l'appel. * -* closure = non utilisé ici. * -* * -* Description : Indique si l'affichage est complété avec des zéros. * -* * -* Retour : true si des zéro sont ajoutés à l'affichage, false sinon. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_imm_operand_get_padding_by_default(PyObject *self, void *closure) -{ - PyObject *result; /* Instance Python à retourner */ - GImmOperand *operand; /* Version GLib de l'opérande */ - bool padding; /* Bourrage en préfixe ? */ - - operand = G_IMM_OPERAND(pygobject_get(self)); - assert(operand != NULL); - - padding = g_imm_operand_does_padding_by_default(operand); - - result = Py_BuildValue("p", padding); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = objet Python concerné par l'appel. * -* value = valeur fournie à intégrer ou prendre en compte. * -* closure = non utilisé ici. * -* * -* Description : Précise si des zéro doivent compléter l'affichage ou non. * -* * -* Retour : Bilan de l'opération pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static int py_imm_operand_set_padding_by_default(PyObject *self, PyObject *value, void *closure) -{ - bool padding; /* Bourrage en préfixe ? */ - GImmOperand *operand; /* Version GLib de l'opérande */ - - if (!PyBool_Check(value)) - { - PyErr_SetString(PyExc_TypeError, _("Invalid padding state")); - return -1; - } - - padding = (value == Py_True); - - operand = G_IMM_OPERAND(pygobject_get(self)); - assert(operand != NULL); - - g_imm_operand_pad_by_default(operand, padding); - - return 0; - -} - - -/****************************************************************************** -* * -* Paramètres : self = objet Python concerné par l'appel. * -* closure = non utilisé ici. * -* * -* Description : Indique si l'affichage est complété avec des zéros. * -* * -* Retour : true si des zéro sont ajoutés à l'affichage, false sinon. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_imm_operand_get_padding(PyObject *self, void *closure) -{ - PyObject *result; /* Instance Python à retourner */ - GImmOperand *operand; /* Version GLib de l'opérande */ - bool padding; /* Bourrage en préfixe ? */ - - operand = G_IMM_OPERAND(pygobject_get(self)); - assert(operand != NULL); - - padding = g_imm_operand_does_padding(operand); - - result = Py_BuildValue("p", padding); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = objet Python concerné par l'appel. * -* value = valeur fournie à intégrer ou prendre en compte. * -* closure = non utilisé ici. * -* * -* Description : Précise si des zéro doivent compléter l'affichage ou non. * -* * -* Retour : Bilan de l'opération pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static int py_imm_operand_set_padding(PyObject *self, PyObject *value, void *closure) -{ - bool padding; /* Bourrage en préfixe ? */ - GImmOperand *operand; /* Version GLib de l'opérande */ - - if (!PyBool_Check(value)) - { - PyErr_SetString(PyExc_TypeError, _("Invalid padding state")); - return -1; - } - - padding = (value == Py_True); - - operand = G_IMM_OPERAND(pygobject_get(self)); - assert(operand != NULL); - - g_imm_operand_pad(operand, padding); - - return 0; - -} - - -/****************************************************************************** -* * -* Paramètres : self = objet Python concerné par l'appel. * -* closure = non utilisé ici. * -* * -* Description : Indique le format textuel par défaut de la valeur. * -* * -* Retour : Format global d'un affichage de valeur. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_imm_operand_get_default_display(PyObject *self, void *closure) -{ - PyObject *result; /* Instance Python à retourner */ - GImmOperand *operand; /* Version GLib de l'opérande */ - ImmOperandDisplay display; /* Type d'affichage courant */ - - operand = G_IMM_OPERAND(pygobject_get(self)); - assert(operand != NULL); - - display = g_imm_operand_get_default_display(operand); - - result = Py_BuildValue("I", display); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = objet Python concerné par l'appel. * -* value = valeur fournie à intégrer ou prendre en compte. * -* closure = non utilisé ici. * -* * -* Description : Définit le format textuel par défaut de la valeur. * -* * -* Retour : Bilan de l'opération pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static int py_imm_operand_set_default_display(PyObject *self, PyObject *value, void *closure) -{ - ImmOperandDisplay display; /* Type d'affichage demandé */ - GImmOperand *operand; /* Version GLib de l'opérande */ - - if (!PyLong_Check(value)) - { - PyErr_SetString(PyExc_TypeError, _("Invalid display type")); - return -1; - } - - display = PyLong_AsUnsignedLong(value); - - if (!(IOD_BIN <= display && display <= IOD_CHAR)) - { - PyErr_SetString(PyExc_TypeError, _("Invalid display type")); - return -1; - } - - operand = G_IMM_OPERAND(pygobject_get(self)); - assert(operand != NULL); - - g_imm_operand_set_default_display(operand, display); - - return 0; - -} - - -/****************************************************************************** -* * -* Paramètres : self = objet Python concerné par l'appel. * -* closure = non utilisé ici. * -* * -* Description : Indique la grande ligne du format textuel de la valeur. * -* * -* Retour : Format global d'un affichage de valeur. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_imm_operand_get_display(PyObject *self, void *closure) -{ - PyObject *result; /* Instance Python à retourner */ - GImmOperand *operand; /* Version GLib de l'opérande */ - ImmOperandDisplay display; /* Type d'affichage courant */ - - operand = G_IMM_OPERAND(pygobject_get(self)); - assert(operand != NULL); - - display = g_imm_operand_get_display(operand); - - result = Py_BuildValue("I", display); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = objet Python concerné par l'appel. * -* value = valeur fournie à intégrer ou prendre en compte. * -* closure = non utilisé ici. * -* * -* Description : Définit la grande ligne du format textuel de la valeur. * -* * -* Retour : Bilan de l'opération pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static int py_imm_operand_set_display(PyObject *self, PyObject *value, void *closure) -{ - ImmOperandDisplay display; /* Type d'affichage demandé */ - GImmOperand *operand; /* Version GLib de l'opérande */ - - if (!PyLong_Check(value)) - { - PyErr_SetString(PyExc_TypeError, _("Invalid display type")); - return -1; - } - - display = PyLong_AsUnsignedLong(value); - - if (!(IOD_BIN <= display && display <= IOD_CHAR)) - { - PyErr_SetString(PyExc_TypeError, _("Invalid display type")); - return -1; - } - - operand = G_IMM_OPERAND(pygobject_get(self)); - assert(operand != NULL); - - g_imm_operand_set_display(operand, display); - - return 0; - -} - - -/****************************************************************************** -* * -* Paramètres : self = operande à manipuler. * -* args = arguments accompagnant l'appel. * -* * -* Description : Construit la chaîne de caractères correspondant à l'opérande.* -* * -* Retour : Chaîne de caractères mise en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_imm_operand_to_string(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - GImmOperand *operand; /* Version GLib de l'opérande */ - unsigned int raw_syntax; /* Affichage brut à utiliser */ - int ret; /* Bilan de lecture des args. */ - AsmSyntax syntax; /* Affichage final à utiliser */ - char value[IMM_MAX_SIZE]; /* Valeur humainement lisible */ - - operand = G_IMM_OPERAND(pygobject_get(self)); - assert(operand != NULL); - - ret = PyArg_ParseTuple(args, "I", &raw_syntax); - if (!ret) return NULL; - - syntax = raw_syntax; - - if (syntax != ASX_INTEL && syntax != ASX_ATT) - { - PyErr_SetString(PyExc_ValueError, _("Invalid syntax type")); - return NULL; - } - - g_imm_operand_to_string(operand, syntax, value); - - result = PyUnicode_FromString(value); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : type = type de l'objet à instancier. * -* args = arguments fournis à l'appel. * -* kwds = arguments de type key=val fournis. * -* * -* Description : Crée un nouvel objet Python de type 'ImmOperand'. * -* * -* Retour : Instance Python mise en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_imm_operand_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - PyObject *result; /* Instance à retourner */ - unsigned int raw_size; /* Taille obtenue de Python */ - unsigned long long value; /* Valeur brute à représenter */ - int ret; /* Bilan de lecture des args. */ - MemoryDataSize size; /* Taille des données finale */ - GArchOperand *operand; /* Création GLib à transmettre */ - - ret = PyArg_ParseTuple(args, "IK", &raw_size, &value); - if (!ret) return NULL; - - size = raw_size; - - if (size != MDS_UNDEFINED - && !(MDS_4_BITS_UNSIGNED <= size && size <= MDS_64_BITS_UNSIGNED) - && !(MDS_4_BITS_SIGNED <= size && size <= MDS_64_BITS_SIGNED)) - { - PyErr_SetString(PyExc_ValueError, _("Invalid size to build an immediate operand")); - return NULL; - } - - operand = g_imm_operand_new_from_value(size, value); - - result = pygobject_new(G_OBJECT(operand)); - - g_object_unref(operand); - - return (PyObject *)result; - -} - - -/****************************************************************************** -* * -* Paramètres : obj_type = type dont le dictionnaire est à compléter. * -* * -* Description : Définit les constantes pour les opérandes d'immédiats. * -* * -* Retour : true en cas de succès de l'opération, false sinon. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool py_imm_operand_define_constants(PyTypeObject *obj_type) -{ - bool result; /* Bilan à retourner */ - - result = true; - - result &= PyDict_AddIntMacro(obj_type, IOD_BIN); - result &= PyDict_AddIntMacro(obj_type, IOD_OCT); - result &= PyDict_AddIntMacro(obj_type, IOD_DEC); - result &= PyDict_AddIntMacro(obj_type, IOD_HEX); - result &= PyDict_AddIntMacro(obj_type, IOD_CHAR); - result &= PyDict_AddIntMacro(obj_type, IOD_COUNT); - - 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_imm_operand_type(void) -{ - static PyMethodDef py_imm_operand_methods[] = { - { - "to_string", py_imm_operand_to_string, - METH_VARARGS, - "to_string($self, syntax, /)\n--\n\nConvert the immediate operand to a string." - }, - { NULL } - }; - - static PyGetSetDef py_imm_operand_getseters[] = { - { - "size", py_imm_operand_get_size, NULL, - "Size of the value contained in the operand.", NULL - }, - { - "value", py_imm_operand_get_value, NULL, - "Value of the immediate operand.", NULL - }, - { - "padding", py_imm_operand_get_padding, py_imm_operand_set_padding, - "Status of padding with zeros in front of the textual representation.", NULL - }, - { - "default_padding", py_imm_operand_get_padding_by_default, py_imm_operand_set_padding_by_default, - "Status of default padding with zeros in front of the textual representation.", NULL - }, - { - "default_display", py_imm_operand_get_default_display, py_imm_operand_set_default_display, - "Definition of the immediate operand default textual representation.", NULL - }, - { - "display", py_imm_operand_get_display, py_imm_operand_set_display, - "Definition of the immediate operand current textual representation.", NULL - }, - { NULL } - }; - - static PyTypeObject py_imm_operand_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.arch.ImmOperand", - .tp_basicsize = sizeof(PyGObject), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyChrysalide immediate operand.", - - .tp_methods = py_imm_operand_methods, - .tp_getset = py_imm_operand_getseters, - .tp_new = py_imm_operand_new - - }; - - return &py_imm_operand_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.arch.ImmOperand'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_imm_operand(PyObject *module) -{ - PyTypeObject *py_imm_operand_type; /* Type Python 'BinContent' */ - PyObject *dict; /* Dictionnaire du module */ - - py_imm_operand_type = get_python_imm_operand_type(); - - dict = PyModule_GetDict(module); - - if (!register_class_for_pygobject(dict, G_TYPE_IMM_OPERAND, - py_imm_operand_type, get_python_arch_operand_type())) - return false; - - if (!py_imm_operand_define_constants(py_imm_operand_type)) - return false; - - return true; - -} diff --git a/plugins/pychrysa/arch/immediate.h b/plugins/pychrysa/arch/immediate.h deleted file mode 100644 index d6e5eba..0000000 --- a/plugins/pychrysa/arch/immediate.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * immediate.h - prototypes pour l'équivalent Python du fichier "arch/immediate.h" - * - * Copyright (C) 2017 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_PYOIDA_ARCH_IMMEDIATE_H -#define _PLUGINS_PYOIDA_ARCH_IMMEDIATE_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_imm_operand_type(void); - -/* Prend en charge l'objet 'pychrysalide.arch.ImmOperand'. */ -bool register_python_imm_operand(PyObject *); - - - -#endif /* _PLUGINS_PYOIDA_ARCH_IMMEDIATE_H */ diff --git a/plugins/pychrysa/arch/instriter.c b/plugins/pychrysa/arch/instriter.c deleted file mode 100644 index 244a825..0000000 --- a/plugins/pychrysa/arch/instriter.c +++ /dev/null @@ -1,276 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * instriter.c - équivalent Python du fichier "arch/instriter.c" - * - * Copyright (C) 2016-2017 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 "instriter.h" - - -#include - - -#include - - -#include "processor.h" - - - -/* Transcription d'un itérateur en Python */ -typedef struct _PyInstrIterator -{ - PyObject_HEAD; /* A laisser en premier */ - - instr_iter_t *native; /* Version native de l'objet */ - bool first_time; /* Premier élément retourné ? */ - -} PyInstrIterator; - - -/* Libère de la mémoire un itérateur sur des instructions. */ -static void py_instr_iterator_dealloc(PyInstrIterator *); - -/* Fournit l'instruction qui en suit une autre. */ -static PyObject *py_instr_iterator_next(PyInstrIterator *); - -/* Initialise un nouvel itérateur. */ -static int py_instr_iterator_init(PyInstrIterator *, PyObject *, PyObject *); - -/* Construit un nouvel itérateur. */ -static PyObject *py_instr_iterator_new(PyTypeObject *, PyObject *, PyObject *); - - - -/****************************************************************************** -* * -* Paramètres : self = itérateur à supprimer. * -* * -* Description : Libère de la mémoire un itérateur sur des instructions. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void py_instr_iterator_dealloc(PyInstrIterator *self) -{ - delete_instruction_iterator(self->native); - - Py_TYPE(self)->tp_free((PyObject *)self); - -} - - -/****************************************************************************** -* * -* Paramètres : self = itérateur à manipuler. * -* * -* Description : Fournit l'instruction qui en suit une autre. * -* * -* Retour : Instruction suivante trouvée, ou NULL. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_instr_iterator_next(PyInstrIterator *self) -{ - PyObject *result; /* Résultat à retourner */ - GArchInstruction *next; /* Instruction suivante */ - - if (self->first_time) - { - next = get_instruction_iterator_current(self->native); - self->first_time = false; - } - - else - next = get_instruction_iterator_next(self->native); - - if (next != NULL) - { - result = pygobject_new(G_OBJECT(next)); - g_object_unref(G_OBJECT(next)); - } - - else - { - PyErr_SetNone(PyExc_StopIteration); - result = NULL; - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = instance d'objet à initialiser. * -* args = arguments passés pour l'appel. * -* kwds = mots clefs éventuellement fournis en complément. * -* * -* Description : Initialise un nouvel itérateur. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static int py_instr_iterator_init(PyInstrIterator *self, PyObject *args, PyObject *kwds) -{ - int result; /* Bilan à retourner */ - PyObject *proc_obj; /* Processeur version Python */ - unsigned long index; /* Indice de première instruc. */ - int ret; /* Bilan de lecture des args. */ - GArchProcessor *proc; /* Version native du processeur*/ - - result = -1; - - ret = PyArg_ParseTuple(args, "Ok", &proc_obj, &index); - if (ret == 0) goto piii_exit; - - ret = PyObject_IsInstance(proc_obj, (PyObject *)get_python_arch_processor_type()); - if (!ret) goto piii_exit; - - proc = G_ARCH_PROCESSOR(pygobject_get(proc_obj)); - - self->native = create_instruction_iterator(proc, index); - self->first_time = true; - - result = 0; - - piii_exit: - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : type = type d'objet à mettre en place. * -* args = arguments passés pour l'appel. * -* kwds = mots clefs éventuellement fournis en complément. * -* * -* Description : Construit un nouvel itérateur. * -* * -* Retour : Définition d'objet pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_instr_iterator_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - PyInstrIterator *result; /* Nouvelle instance à renvoyer*/ - int ret; /* Bilan de l'initialisation */ - - result = (PyInstrIterator *)type->tp_alloc(type, 0); - - if (result != NULL) - { - ret = py_instr_iterator_init(result, args, kwds); - - if (ret != 0) - { - Py_DECREF(result); - result = NULL; - } - - } - - return (PyObject *)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_instr_iterator_type(void) -{ - static PyTypeObject py_instr_iterator_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.arch.InstrIterator", - .tp_basicsize = sizeof(PyInstrIterator), - - .tp_dealloc = (destructor)py_instr_iterator_dealloc, - - .tp_flags = Py_TPFLAGS_DEFAULT, - - .tp_doc = "Iterator for Chrysalide instructions loaded in a given processor.", - - .tp_iter = PyObject_SelfIter, - .tp_iternext = (iternextfunc)py_instr_iterator_next, - - .tp_init = (initproc)py_instr_iterator_init, - .tp_new = py_instr_iterator_new, - - }; - - return &py_instr_iterator_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.arch.InstrIterator'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_instr_iterator(PyObject *module) -{ - PyTypeObject *py_instr_iterator_type; /* Type Python 'BinContent' */ - int ret; /* Bilan d'un appel */ - - py_instr_iterator_type = get_python_instr_iterator_type(); - - if (PyType_Ready(py_instr_iterator_type) < 0) - return false; - - Py_INCREF(py_instr_iterator_type); - ret = PyModule_AddObject(module, "InstrIterator", (PyObject *)py_instr_iterator_type); - - return (ret == 0); - -} diff --git a/plugins/pychrysa/arch/instriter.h b/plugins/pychrysa/arch/instriter.h deleted file mode 100644 index 3cb0e38..0000000 --- a/plugins/pychrysa/arch/instriter.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * instriter.h - prototypes pour l'équivalent Python du fichier "arch/instriter.h" - * - * Copyright (C) 2016-2017 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_ARCH_INSTRITER_H -#define _PLUGINS_PYCHRYSALIDE_ARCH_INSTRITER_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_instr_iterator_type(void); - -/* Prend en charge l'objet 'pychrysalide.arch.InstrIterator'. */ -bool register_python_instr_iterator(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSALIDE_ARCH_INSTRITER_H */ diff --git a/plugins/pychrysa/arch/instruction.c b/plugins/pychrysa/arch/instruction.c deleted file mode 100644 index bb977ce..0000000 --- a/plugins/pychrysa/arch/instruction.c +++ /dev/null @@ -1,462 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * instruction.c - équivalent Python du fichier "arch/instruction.h" - * - * Copyright (C) 2012-2017 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 "instruction.h" - - -#include -#include - - -#include - - -#include "vmpa.h" -#include "../helpers.h" -#include "../glibext/linegen.h" - - - - -/* ------------------- DEFINITION DES LIAISONS ENTRE INSTRUCTIONS ------------------- */ - - - - - -/* --------------------- INSTRUCTIONS D'ARCHITECTURES EN PYTHON --------------------- */ - - - -/* Fournit la place mémoire d'une instruction. */ -static PyObject *py_arch_instruction_get_range(PyObject *, void *); - -/* Définit la localisation d'une instruction. */ -static int py_arch_instruction_set_range(PyObject *, PyObject *, void *); - - - -/* Fournit le nom humain de l'instruction manipulée. */ -static PyObject *py_arch_instruction_get_keyword(PyObject *, void *); - - - -/* Fournit tous les opérandes d'une instruction. */ -static PyObject *py_arch_instruction_get_operands(PyObject *, void *); - - - - - - - - - - -/* ---------------------------------------------------------------------------------- */ -/* DEFINITION DES LIAISONS ENTRE INSTRUCTIONS */ -/* ---------------------------------------------------------------------------------- */ - - - - -/* Fournit les origines d'une instruction donnée. */ -static PyObject *py_arch_instruction_get_sources(PyObject *, void *); - -/* Fournit les destinations d'une instruction donnée. */ -static PyObject *py_arch_instruction_get_destinations(PyObject *, void *); - - - - -/****************************************************************************** -* * -* Paramètres : self = instruction d'architecture à manipuler. * -* unused = adresse non utilisée ici. * -* * -* Description : Fournit les origines d'une instruction donnée. * -* * -* Retour : Nombre de ces origines. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_arch_instruction_get_sources(PyObject *self, void *unused) -{ - PyObject *result; /* Instance à retourner */ - GArchInstruction *instr; /* Version native */ - instr_link_t *source; /* Origine des liens */ - size_t count; /* Nombre de liens présents */ - size_t i; /* Boucle de parcours */ - PyObject *linked; /* Source de lien Python */ - PyObject *type; /* Nature du lien en Python */ - int ret; /* Bilan d'une écriture d'arg. */ - - instr = G_ARCH_INSTRUCTION(pygobject_get(self)); - - g_arch_instruction_lock_src(instr); - - count = g_arch_instruction_count_sources(instr); - - result = PyTuple_New(count); - - for (i = 0; i < count; i++) - { - source = g_arch_instruction_get_source(instr, i); - - linked = pygobject_new(G_OBJECT(source->linked)); - type = PyLong_FromLong(source->type); - - ret = PyTuple_SetItem(result, i, Py_BuildValue("(OO)", linked, type)); - assert(ret == 0); - - } - - g_arch_instruction_unlock_src(instr); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = instruction d'architecture à manipuler. * -* unused = adresse non utilisée ici. * -* * -* Description : Fournit les destinations d'une instruction donnée. * -* * -* Retour : Nombre de ces destinations. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_arch_instruction_get_destinations(PyObject *self, void *unused) -{ - PyObject *result; /* Instance à retourner */ - GArchInstruction *instr; /* Version native */ - instr_link_t *dest; /* Destination des liens */ - size_t count; /* Nombre de liens présents */ - size_t i; /* Boucle de parcours */ - PyObject *linked; /* Destination de lien Python */ - PyObject *type; /* Nature du lien en Python */ - int ret; /* Bilan d'une écriture d'arg. */ - - instr = G_ARCH_INSTRUCTION(pygobject_get(self)); - - g_arch_instruction_lock_dest(instr); - - count = g_arch_instruction_count_destinations(instr); - - result = PyTuple_New(count); - - for (i = 0; i < count; i++) - { - dest = g_arch_instruction_get_destination(instr, i); - - linked = pygobject_new(G_OBJECT(dest->linked)); - type = PyLong_FromLong(dest->type); - - ret = PyTuple_SetItem(result, i, Py_BuildValue("(OO)", linked, type)); - assert(ret == 0); - - } - - g_arch_instruction_unlock_dest(instr); - - return result; - -} - - - - - - - - - - - - -/****************************************************************************** -* * -* Paramètres : self = classe représentant une instruction. * -* closure = adresse non utilisée ici. * -* * -* Description : Fournit la place mémoire d'une instruction. * -* * -* Retour : Valeur associée à la propriété consultée. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_arch_instruction_get_range(PyObject *self, void *closure) -{ - PyObject *result; /* Conversion à retourner */ - GArchInstruction *instr; /* Version native */ - const mrange_t *range; /* Espace mémoire à exporter */ - - instr = G_ARCH_INSTRUCTION(pygobject_get(self)); - range = g_arch_instruction_get_range(instr); - - result = build_from_internal_mrange(range); - - return result; - -} - - -/****************************************************************************** -* * -* 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 localisation d'une instruction. * -* * -* Retour : Bilan de l'opération pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static int py_arch_instruction_set_range(PyObject *self, PyObject *value, void *closure) -{ - int ret; /* Bilan d'analyse */ - mrange_t *range; /* Espace mémoire à manipuler */ - GArchInstruction *instr; /* Version native */ - - ret = PyObject_IsInstance(value, (PyObject *)get_python_mrange_type()); - if (!ret) return -1; - - range = get_internal_mrange(value); - - instr = G_ARCH_INSTRUCTION(pygobject_get(self)); - g_arch_instruction_set_range(instr, range); - - return 0; - -} - - - - - - - -/****************************************************************************** -* * -* Paramètres : self = classe représentant une instruction. * -* unused = adresse non utilisée ici. * -* * -* Description : Fournit le nom humain de l'instruction manipulée. * -* * -* Retour : Valeur associée à la propriété consultée. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_arch_instruction_get_keyword(PyObject *self, void *unused) -{ - PyObject *result; /* Trouvailles à retourner */ - GArchInstruction *instr; /* Version native */ - const char *kw; /* Valeur récupérée */ - - instr = G_ARCH_INSTRUCTION(pygobject_get(self)); - kw = g_arch_instruction_get_keyword(instr, 0/* FIXME*/); - - result = PyUnicode_FromString(kw); - - return result; - -} - - - - - -/****************************************************************************** -* * -* Paramètres : self = objet représentant une instruction. * -* unused = adresse non utilisée ici. * -* * -* Description : Fournit tous les opérandes d'une instruction. * -* * -* Retour : Valeur associée à la propriété consultée. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_arch_instruction_get_operands(PyObject *self, void *unused) -{ - PyObject *result; /* Instance à retourner */ - GArchInstruction *instr; /* Version native */ - size_t count; /* Nombre d'opérandes présents */ - size_t i; /* Boucle de parcours */ - GArchOperand *operand; /* Opérande à manipuler */ - PyObject *opobj; /* Version Python */ - int ret; /* Bilan d'une écriture d'arg. */ - - instr = G_ARCH_INSTRUCTION(pygobject_get(self)); - - g_arch_instruction_lock_operands(instr); - - count = _g_arch_instruction_count_operands(instr); - - result = PyTuple_New(count); - - for (i = 0; i < count; i++) - { - operand = _g_arch_instruction_get_operand(instr, i); - - opobj = pygobject_new(G_OBJECT(operand)); - - ret = PyTuple_SetItem(result, i, Py_BuildValue("O", opobj)); - assert(ret == 0); - - g_object_unref(G_OBJECT(operand)); - - } - - g_arch_instruction_unlock_operands(instr); - - 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_arch_instruction_type(void) -{ - static PyMethodDef py_arch_instruction_methods[] = { - { NULL } - }; - - static PyGetSetDef py_arch_instruction_getseters[] = { - { - "range", py_arch_instruction_get_range, py_arch_instruction_set_range, - "Give access to the memory range covered by the current instruction.", NULL - }, - { - "keyword", (getter)py_arch_instruction_get_keyword, (setter)NULL, - "Give le name of the assembly instruction.", NULL - }, - { - "operands", (getter)py_arch_instruction_get_operands, (setter)NULL, - "Provide the list of instruction attached operands.", NULL - }, - { - "sources", (getter)py_arch_instruction_get_sources, (setter)NULL, - "Provide the instructions list driving to the current instruction." - }, - { - "destinations", (getter)py_arch_instruction_get_destinations, (setter)NULL, - "Provide the instructions list following the current instruction." - }, - { NULL } - }; - - static PyTypeObject py_arch_instruction_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.arch.ArchInstruction", - .tp_basicsize = sizeof(PyGObject), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyChrysalide instruction for a given architecture.", - - .tp_methods = py_arch_instruction_methods, - .tp_getset = py_arch_instruction_getseters, - - }; - - return &py_arch_instruction_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.arch.ArchInstruction'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_arch_instruction(PyObject *module) -{ - PyTypeObject *py_arch_instruction_type; /* Type Python 'ArchInstruc...'*/ - PyObject *dict; /* Dictionnaire du module */ - PyTypeObject *py_line_generator_type; /* Type Python 'LineGenerator' */ - - py_arch_instruction_type = get_python_arch_instruction_type(); - - APPLY_ABSTRACT_FLAG(py_arch_instruction_type); - - dict = PyModule_GetDict(module); - - py_line_generator_type = get_python_line_generator_type(); - - if (!_register_class_for_pygobject(dict, G_TYPE_ARCH_INSTRUCTION, py_arch_instruction_type, - &PyGObject_Type, py_line_generator_type, NULL)) - return false; - - return true; - -} diff --git a/plugins/pychrysa/arch/instruction.h b/plugins/pychrysa/arch/instruction.h deleted file mode 100644 index 85a1552..0000000 --- a/plugins/pychrysa/arch/instruction.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * instruction.h - prototypes pour l'équivalent Python du fichier "arch/instruction.h" - * - * Copyright (C) 2012-2017 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_PYOIDA_ARCH_INSTRUCTION_H -#define _PLUGINS_PYOIDA_ARCH_INSTRUCTION_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_arch_instruction_type(void); - -/* Prend en charge l'objet 'pychrysalide.arch.ArchInstruction'. */ -bool register_python_arch_instruction(PyObject *); - - - -#endif /* _PLUGINS_PYOIDA_ARCH_INSTRUCTION_H */ diff --git a/plugins/pychrysa/arch/module.c b/plugins/pychrysa/arch/module.c deleted file mode 100644 index 54b470c..0000000 --- a/plugins/pychrysa/arch/module.c +++ /dev/null @@ -1,165 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * module.c - intégration du répertoire arch en tant que module - * - * Copyright (C) 2012-2017 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 "module.h" - - -#include - - -#include - - -#include "immediate.h" -#include "instriter.h" -#include "instruction.h" -#include "operand.h" -#include "processor.h" -#include "raw.h" -#include "vmpa.h" -#include "../access.h" -#include "../helpers.h" - - - -/* Définit les constantes de base pour une architecture. */ -static bool py_base_define_constants(PyTypeObject *); - - - -/****************************************************************************** -* * -* Paramètres : obj_type = type dont le dictionnaire est à compléter. * -* * -* Description : Définit les constantes de base pour une architecture. * -* * -* Retour : true en cas de succès de l'opération, false sinon. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool py_base_define_constants(PyTypeObject *obj_type) -{ - bool result; /* Bilan à retourner */ - - result = true; - - result &= PyDict_AddIntMacro(obj_type, MDS_UNDEFINED); - - result &= PyDict_AddIntMacro(obj_type, MDS_4_BITS_UNSIGNED); - result &= PyDict_AddIntMacro(obj_type, MDS_8_BITS_UNSIGNED); - result &= PyDict_AddIntMacro(obj_type, MDS_16_BITS_UNSIGNED); - result &= PyDict_AddIntMacro(obj_type, MDS_32_BITS_UNSIGNED); - result &= PyDict_AddIntMacro(obj_type, MDS_64_BITS_UNSIGNED); - - result &= PyDict_AddIntMacro(obj_type, MDS_4_BITS_SIGNED); - result &= PyDict_AddIntMacro(obj_type, MDS_8_BITS_SIGNED); - result &= PyDict_AddIntMacro(obj_type, MDS_16_BITS_SIGNED); - result &= PyDict_AddIntMacro(obj_type, MDS_32_BITS_SIGNED); - result &= PyDict_AddIntMacro(obj_type, MDS_64_BITS_SIGNED); - - result &= PyDict_AddIntMacro(obj_type, MDS_4_BITS); - result &= PyDict_AddIntMacro(obj_type, MDS_8_BITS); - result &= PyDict_AddIntMacro(obj_type, MDS_16_BITS); - result &= PyDict_AddIntMacro(obj_type, MDS_32_BITS); - result &= PyDict_AddIntMacro(obj_type, MDS_64_BITS); - - result &= PyDict_AddIntMacro(obj_type, ASX_INTEL); - result &= PyDict_AddIntMacro(obj_type, ASX_ATT); - result &= PyDict_AddIntMacro(obj_type, ASX_COUNT); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute le module 'arch' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool add_arch_module_to_python_module(PyObject *super) -{ - bool result; /* Bilan à retourner */ - PyObject *module; /* Sous-module mis en place */ - int ret; /* Bilan d'un appel */ - - static PyModuleDef py_chrysalide_arch_module = { - - .m_base = PyModuleDef_HEAD_INIT, - - .m_name = "pychrysalide.arch", - .m_doc = "Python module for Chrysalide.arch", - - .m_size = -1, - - }; - - result = false; - - module = PyModule_Create(&py_chrysalide_arch_module); - if (module == NULL) return false; - - ret = PyState_AddModule(super, &py_chrysalide_arch_module); - if (ret != 0) goto loading_failed; - - ret = _PyImport_FixupBuiltin(module, "pychrysalide.arch"); - if (ret != 0) goto loading_failed; - - Py_INCREF(module); - ret = PyModule_AddObject(super, "arch", module); - if (ret != 0) goto loading_failed; - - result = true; - - result &= py_base_define_constants(Py_TYPE(module)); - - result &= register_python_arch_instruction(module); - result &= register_python_arch_operand(module); - result &= register_python_arch_processor(module); - result &= register_python_instr_iterator(module); - result &= register_python_raw_instruction(module); - result &= register_python_vmpa(module); - result &= register_python_mrange(module); - - result &= register_python_imm_operand(module); - - if (result) - register_access_to_python_module("pychrysalide.arch", module); - - loading_failed: - - assert(result); - - return result; - -} diff --git a/plugins/pychrysa/arch/module.h b/plugins/pychrysa/arch/module.h deleted file mode 100644 index 07d3575..0000000 --- a/plugins/pychrysa/arch/module.h +++ /dev/null @@ -1,39 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * module.h - prototypes pour l'intégration du répertoire arch en tant que module - * - * Copyright (C) 2012-2017 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_ARCH_MODULE_H -#define _PLUGINS_PYCHRYSALIDE_ARCH_MODULE_H - - -#include -#include - - - -/* Ajoute le module 'arch' au module Python. */ -bool add_arch_module_to_python_module(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSALIDE_ARCH_MODULE_H */ diff --git a/plugins/pychrysa/arch/operand.c b/plugins/pychrysa/arch/operand.c deleted file mode 100644 index 427f92b..0000000 --- a/plugins/pychrysa/arch/operand.c +++ /dev/null @@ -1,109 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * operand.c - équivalent Python du fichier "arch/operand.h" - * - * Copyright (C) 2012-2017 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 "operand.h" - - -#include - - -#include - - -#include "../helpers.h" - - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit un accès à une définition de type à diffuser. * -* * -* Retour : Définition d'objet pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyTypeObject *get_python_arch_operand_type(void) -{ - static PyMethodDef py_arch_operand_methods[] = { - { NULL } - }; - - static PyGetSetDef py_arch_operand_getseters[] = { - { NULL } - }; - - static PyTypeObject py_arch_operand_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.arch.ArchOperand", - .tp_basicsize = sizeof(PyGObject), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyChrysalide instruction operand.", - - .tp_methods = py_arch_operand_methods, - .tp_getset = py_arch_operand_getseters, - - }; - - return &py_arch_operand_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.arch.ArchOperand'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_arch_operand(PyObject *module) -{ - PyTypeObject *py_arch_operand_type; /* Type Python 'BinContent' */ - PyObject *dict; /* Dictionnaire du module */ - - py_arch_operand_type = get_python_arch_operand_type(); - - APPLY_ABSTRACT_FLAG(py_arch_operand_type); - - dict = PyModule_GetDict(module); - - if (!register_class_for_pygobject(dict, G_TYPE_ARCH_OPERAND, py_arch_operand_type, &PyGObject_Type)) - return false; - - return true; - -} diff --git a/plugins/pychrysa/arch/operand.h b/plugins/pychrysa/arch/operand.h deleted file mode 100644 index 3c5ef6a..0000000 --- a/plugins/pychrysa/arch/operand.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * operand.h - prototypes pour l'équivalent Python du fichier "arch/operand.h" - * - * Copyright (C) 2017 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_PYOIDA_ARCH_OPERAND_H -#define _PLUGINS_PYOIDA_ARCH_OPERAND_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_arch_operand_type(void); - -/* Prend en charge l'objet 'pychrysalide.arch.ArchOperand'. */ -bool register_python_arch_operand(PyObject *); - - - -#endif /* _PLUGINS_PYOIDA_ARCH_OPERAND_H */ diff --git a/plugins/pychrysa/arch/processor.c b/plugins/pychrysa/arch/processor.c deleted file mode 100644 index 65431af..0000000 --- a/plugins/pychrysa/arch/processor.c +++ /dev/null @@ -1,459 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * processor.c - équivalent Python du fichier "arch/processor.c" - * - * Copyright (C) 2012-2017 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 "processor.h" - - -#include -#include - - -#include - - -#include - - -#include "instriter.h" -#include "instruction.h" -#include "vmpa.h" -#include "../helpers.h" - - - - - - - - - - - - - - - - -/* ------------------ CONSERVATION DES SOUCIS DURANT LE CHARGEMENT ------------------ */ - - -/* Etend la liste des soucis détectés avec de nouvelles infos. */ -static PyObject *py_arch_processor_add_error(PyObject *, PyObject *); - -/* Fournit les éléments concernant tous les soucis détectés. */ -static PyObject *py_arch_processor_get_errors(PyObject *, void *); - - - -/* ------------------ MANIPULATIONS DES INSTRUCTIONS DESASSEMBLEES ------------------ */ - - -/* Fournit les instructions désassemblées pour une architecture. */ -static PyObject *py_arch_processor_get_instrs(PyObject *, void *); - -/* Note les instructions désassemblées avec une architecture. */ -static int py_arch_processor_set_instrs(PyObject *, PyObject *, void *); - -/* Recherche une instruction d'après son adresse. */ -static PyObject *py_arch_processor_find_instr_by_addr(PyObject *, PyObject *); - - - - - -/* Définit les constantes pour les types d'erreurs. */ -static bool define_python_arch_processor_constants(PyTypeObject *); - - - -/* ---------------------------------------------------------------------------------- */ -/* CONSERVATION DES SOUCIS DURANT LE CHARGEMENT */ -/* ---------------------------------------------------------------------------------- */ - - -/****************************************************************************** -* * -* Paramètres : self = architecture concernée par la procédure. * -* args = instruction représentant le point de départ. * -* * -* Description : Etend la liste des soucis détectés avec de nouvelles infos. * -* * -* Retour : None. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_arch_processor_add_error(PyObject *self, PyObject *args) -{ - ArchProcessingError type; /* Type d'erreur détectée */ - vmpa2t addr; /* Position d'une erreur */ - const char *desc; /* Description d'une erreur */ - int ret; /* Bilan de lecture des args. */ - GArchProcessor *proc; /* Processeur manipulé */ - - ret = PyArg_ParseTuple(args, "IO&s", &type, convert_any_to_vmpa, &addr, &desc); - if (!ret) return NULL; - - proc = G_ARCH_PROCESSOR(pygobject_get(self)); - - g_arch_processor_add_error(proc, type, &addr, desc); - - Py_RETURN_NONE; - -} - - -/****************************************************************************** -* * -* Paramètres : self = objet Python concerné par l'appel. * -* closure = non utilisé ici. * -* * -* Description : Fournit les éléments concernant tous les soucis détectés. * -* * -* Retour : Liste des erreurs relevées au niveau de l'assembleur. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_arch_processor_get_errors(PyObject *self, void *closure) -{ - PyObject *result; /* Instance Python à retourner */ - GArchProcessor *proc; /* Architecture visée */ - size_t count; /* Nombre d'éléments à traiter */ - size_t i; /* Boucle de parcours */ -#ifndef NDEBUG - bool status; /* Bilan d'un appel */ -#endif - ArchProcessingError type; /* Type d'erreur détectée */ - vmpa2t addr; /* Position d'une erreur */ - char *desc; /* Description d'une erreur */ - PyObject *error; /* Nouvelle erreur à rajouter */ - - proc = G_ARCH_PROCESSOR(pygobject_get(self)); - - g_arch_processor_lock_errors(proc); - - count = g_arch_processor_count_errors(proc); - - result = PyTuple_New(count); - - for (i = 0; i < count; i++) - { -#ifndef NDEBUG - status = g_arch_processor_get_error(proc, i, &type, &addr, &desc); - assert(status); -#else - g_arch_processor_get_error(proc, i, &type, &addr, &desc); -#endif - - error = Py_BuildValue("IO&s", type, build_from_internal_vmpa, &addr, desc); - - PyTuple_SetItem(result, i, error); - - } - - g_arch_processor_unlock_errors(proc); - - return result; - -} - - - -/* ---------------------------------------------------------------------------------- */ -/* MANIPULATIONS DES INSTRUCTIONS DESASSEMBLEES */ -/* ---------------------------------------------------------------------------------- */ - - -/****************************************************************************** -* * -* Paramètres : self = objet Python concerné par l'appel. * -* closure = non utilisé ici. * -* * -* Description : Fournit les instructions désassemblées pour une architecture.* -* * -* Retour : Liste des instructions désassemblées ou None si aucune. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_arch_processor_get_instrs(PyObject *self, void *closure) -{ - PyObject *result; /* Instance Python à retourner */ - PyTypeObject *iterator_type; /* Type Python de l'itérateur */ - PyObject *args; /* Liste des arguments d'appel */ - - iterator_type = get_python_instr_iterator_type(); - - args = Py_BuildValue("On", self, 0); - - result = PyObject_CallObject((PyObject *)iterator_type, args); - - Py_DECREF(args); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = objet Python concerné par l'appel. * -* value = valeur fournie à intégrer ou prendre en compte. * -* closure = non utilisé ici. * -* * -* Description : Note les instructions désassemblées avec une architecture. * -* * -* Retour : Bilan de l'opération pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static int py_arch_processor_set_instrs(PyObject *self, PyObject *value, void *closure) -{ - size_t count; /* Nombre d'instructions */ - GArchInstruction **list; /* Liste d'instructions */ - size_t i; /* Boucle de parcours */ - PyObject *instr; /* Instruction en Python */ - GArchProcessor *proc; /* Architecture visée */ - - if (!PyTuple_Check(value)) - { - PyErr_SetString(PyExc_TypeError, _("The attribute value must be a tuple of instructions.")); - return -1; - } - - count = PyTuple_Size(value); - - list = (GArchInstruction **)calloc(count, sizeof(GArchInstruction *)); - - for (i = 0; i < count; i++) - { - instr = PyTuple_GetItem(value, i); - - if (!PyObject_TypeCheck(value, get_python_arch_instruction_type())) - { - PyErr_SetString(PyExc_TypeError, _("The attribute value must be a tuple of instructions.")); - count = i; - goto papsi_error; - } - - list[i] = G_ARCH_INSTRUCTION(pygobject_get(instr)); - g_object_ref(G_OBJECT(list[i])); - - } - - proc = G_ARCH_PROCESSOR(pygobject_get(self)); - - g_arch_processor_set_instructions(proc, list, count); - - return 0; - - papsi_error: - - for (i = 0; i < count; i++) - g_object_unref(G_OBJECT(list[i])); - - free(list); - - return -1; - -} - - -/****************************************************************************** -* * -* Paramètres : self = processeur d'architecture à manipuler. * -* args = instruction représentant le point de départ. * -* * -* Description : Recherche une instruction d'après son adresse. * -* * -* Retour : Instruction trouvée à l'adresse donnée, None si aucune. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_arch_processor_find_instr_by_addr(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - PyObject *addr_obj; /* Objet pour une localisation */ - int ret; /* Bilan de lecture des args. */ - GArchProcessor *proc; /* Processeur manipulé */ - vmpa2t *addr; /* Localisation à retrouver */ - GArchInstruction *found; /* Instruction liée trouvée */ - - ret = PyArg_ParseTuple(args, "O", &addr_obj); - if (!ret) return NULL; - - ret = PyObject_IsInstance(addr_obj, (PyObject *)get_python_vmpa_type()); - if (!ret) return NULL; - - proc = G_ARCH_PROCESSOR(pygobject_get(self)); - addr = get_internal_vmpa(addr_obj); - - found = g_arch_processor_find_instr_by_address(proc, addr); - - if (found != NULL) - { - result = pygobject_new(G_OBJECT(found)); - g_object_unref(G_OBJECT(found)); - } - - else - { - result = Py_None; - Py_INCREF(result); - } - - return result; - -} - - - - - - -/****************************************************************************** -* * -* Paramètres : obj_type = type dont le dictionnaire est à compléter. * -* * -* Description : Définit les constantes pour les types d'erreurs. * -* * -* Retour : true en cas de succès de l'opération, false sinon. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool define_python_arch_processor_constants(PyTypeObject *obj_type) -{ - bool result; /* Bilan à retourner */ - - result = true; - - result &= PyDict_AddIntMacro(obj_type, APE_DISASSEMBLY); - result &= PyDict_AddIntMacro(obj_type, APE_LABEL); - - 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_arch_processor_type(void) -{ - static PyMethodDef py_arch_processor_methods[] = { - { - "add_error", py_arch_processor_add_error, - METH_VARARGS, - "add_error($self, type, addr, desc, /)\n--\n\nExtend the list of detected disassembling errors." - }, - { - "find_instr_by_addr", py_arch_processor_find_instr_by_addr, - METH_VARARGS, - "find_instr_by_addr($self, addr, /)\n--\n\nLook for an instruction located at a given address." - }, - { NULL } - }; - - static PyGetSetDef py_arch_processor_getseters[] = { - { - "errors", py_arch_processor_get_errors, NULL, - "List of all detected errors which occurred during the disassembling process.", NULL - }, - { - "instrs", py_arch_processor_get_instrs, py_arch_processor_set_instrs, - "Give access to the disassembled instructions run by the current processor.", NULL - }, - { NULL } - }; - - static PyTypeObject py_arch_processor_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.arch.ArchProcessor", - .tp_basicsize = sizeof(PyGObject), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyChrysalide processor for a given architecture.", - - .tp_methods = py_arch_processor_methods, - .tp_getset = py_arch_processor_getseters, - - }; - - return &py_arch_processor_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.arch.ArchProcessor'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_arch_processor(PyObject *module) -{ - PyTypeObject *py_arch_processor_type; /* Type Python 'BinContent' */ - PyObject *dict; /* Dictionnaire du module */ - - py_arch_processor_type = get_python_arch_processor_type(); - - dict = PyModule_GetDict(module); - - if (!register_class_for_pygobject(dict, G_TYPE_ARCH_PROCESSOR, py_arch_processor_type, &PyGObject_Type)) - return false; - - if (!define_python_arch_processor_constants(py_arch_processor_type)) - return false; - - return true; - -} diff --git a/plugins/pychrysa/arch/processor.h b/plugins/pychrysa/arch/processor.h deleted file mode 100644 index ff6ccb3..0000000 --- a/plugins/pychrysa/arch/processor.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * processor.h - prototypes pour l'équivalent Python du fichier "arch/processor.h" - * - * Copyright (C) 2012-2017 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_ARCH_PROCESSOR_H -#define _PLUGINS_PYCHRYSALIDE_ARCH_PROCESSOR_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_arch_processor_type(void); - -/* Prend en charge l'objet 'pychrysalide.arch.ArchProcessor'. */ -bool register_python_arch_processor(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSALIDE_ARCH_PROCESSOR_H */ diff --git a/plugins/pychrysa/arch/raw.c b/plugins/pychrysa/arch/raw.c deleted file mode 100644 index 39b5fe7..0000000 --- a/plugins/pychrysa/arch/raw.c +++ /dev/null @@ -1,263 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * raw.c - équivalent Python du fichier "arch/raw.h" - * - * Copyright (C) 2017 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 "raw.h" - - -#include - - -#include - - -#include "instruction.h" -#include "../helpers.h" - - - -/* Indique si le contenu de l'instruction est du bourrage. */ -static PyObject *py_arch_instruction_is_padding(PyObject *, void *); - -/* Marque l'instruction comme ne contenant que du bourrage. */ -static int py_arch_instruction_mark_as_padding(PyObject *, PyObject *, void *); - -/* Indique si le contenu de l'instruction est un texte. */ -static PyObject *py_arch_instruction_is_string(PyObject *, void *); - -/* Marque l'instruction comme contenant une chaîne de texte. */ -static int py_arch_instruction_mark_as_string(PyObject *, PyObject *, void *); - - - -/****************************************************************************** -* * -* Paramètres : self = classe représentant une instruction. * -* closure = adresse non utilisée ici. * -* * -* Description : Indique si le contenu de l'instruction est du bourrage. * -* * -* Retour : Valeur associée à la propriété consultée. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_arch_instruction_is_padding(PyObject *self, void *closure) -{ - PyObject *result; /* Conversion à retourner */ - GRawInstruction *instr; /* Version native */ - bool state; /* Etat courant à consulter */ - - instr = G_RAW_INSTRUCTION(pygobject_get(self)); - - state = g_raw_instruction_is_padding(instr); - - result = state ? Py_True : Py_False; - Py_INCREF(result); - - - return result; - -} - - -/****************************************************************************** -* * -* 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 : Marque l'instruction comme ne contenant que du bourrage. * -* * -* Retour : Bilan de l'opération pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static int py_arch_instruction_mark_as_padding(PyObject *self, PyObject *value, void *closure) -{ - bool state; /* Nouvel état à définir */ - GRawInstruction *instr; /* Version native */ - - if (value != Py_True && value != Py_False) - return -1; - - state = (value == Py_True); - - instr = G_RAW_INSTRUCTION(pygobject_get(self)); - - g_raw_instruction_mark_as_padding(instr, state); - - return 0; - -} - - -/****************************************************************************** -* * -* Paramètres : self = classe représentant une instruction. * -* closure = adresse non utilisée ici. * -* * -* Description : Indique si le contenu de l'instruction est un texte. * -* * -* Retour : Valeur associée à la propriété consultée. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_arch_instruction_is_string(PyObject *self, void *closure) -{ - PyObject *result; /* Conversion à retourner */ - GRawInstruction *instr; /* Version native */ - bool state; /* Etat courant à consulter */ - - instr = G_RAW_INSTRUCTION(pygobject_get(self)); - - state = g_raw_instruction_is_string(instr); - - result = state ? Py_True : Py_False; - Py_INCREF(result); - - - return result; - -} - - -/****************************************************************************** -* * -* 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 : Marque l'instruction comme contenant une chaîne de texte. * -* * -* Retour : Bilan de l'opération pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static int py_arch_instruction_mark_as_string(PyObject *self, PyObject *value, void *closure) -{ - bool state; /* Nouvel état à définir */ - GRawInstruction *instr; /* Version native */ - - if (value != Py_True && value != Py_False) - return -1; - - state = (value == Py_True); - - instr = G_RAW_INSTRUCTION(pygobject_get(self)); - - g_raw_instruction_mark_as_string(instr, state); - - return 0; - -} - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit un accès à une définition de type à diffuser. * -* * -* Retour : Définition d'objet pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyTypeObject *get_python_raw_instruction_type(void) -{ - static PyMethodDef py_raw_instruction_methods[] = { - { NULL } - }; - - static PyGetSetDef py_raw_instruction_getseters[] = { - { - "is_padding", py_arch_instruction_is_padding, py_arch_instruction_mark_as_padding, - "Report if the instruction is seen as padding.", NULL - }, - { - "is_string", py_arch_instruction_is_string, py_arch_instruction_mark_as_string, - "Report if the instruction is seen as a string.", NULL - }, - { NULL } - }; - - static PyTypeObject py_raw_instruction_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.arch.RawInstruction", - .tp_basicsize = sizeof(PyGObject), - - .tp_flags = Py_TPFLAGS_DEFAULT, - - .tp_doc = "PyChrysalide raw instruction for a all architectures.", - - .tp_methods = py_raw_instruction_methods, - .tp_getset = py_raw_instruction_getseters, - - }; - - return &py_raw_instruction_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.arch.ArchInstruction'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_raw_instruction(PyObject *module) -{ - PyTypeObject *py_raw_instruction_type; /* Type Python 'RawInstruction'*/ - PyObject *dict; /* Dictionnaire du module */ - PyTypeObject *base; /* Base parente pour héritage */ - - py_raw_instruction_type = get_python_raw_instruction_type(); - - dict = PyModule_GetDict(module); - - base = get_python_arch_instruction_type(); - - if (!register_class_for_pygobject(dict, G_TYPE_RAW_INSTRUCTION, py_raw_instruction_type, base)) - return false; - - return true; - -} diff --git a/plugins/pychrysa/arch/raw.h b/plugins/pychrysa/arch/raw.h deleted file mode 100644 index 4c1db7a..0000000 --- a/plugins/pychrysa/arch/raw.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * raw.h - prototypes pour l'équivalent Python du fichier "arch/raw.h" - * - * Copyright (C) 2017 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_PYCHRYSA_ARCH_RAW_H -#define _PLUGINS_PYCHRYSA_ARCH_RAW_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_raw_instruction_type(void); - -/* Prend en charge l'objet 'pychrysalide.arch.RawInstruction'. */ -bool register_python_raw_instruction(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSA_ARCH_RAW_H */ diff --git a/plugins/pychrysa/arch/vmpa.c b/plugins/pychrysa/arch/vmpa.c deleted file mode 100644 index 413d67b..0000000 --- a/plugins/pychrysa/arch/vmpa.c +++ /dev/null @@ -1,1303 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * vmpa.c - équivalent Python du fichier "arch/vmpa.c" - * - * Copyright (C) 2014-2017 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 "vmpa.h" - - -#include -#include - - -#include - - -#include "../helpers.h" - - - - - -#include /* TODO : à bouger vers base ? */ - - - - -/* ---------------------- DEFINITION D'UNE POSITION EN MEMOIRE ---------------------- */ - - - -typedef struct _py_vmpa_t -{ - PyObject_HEAD - - vmpa2t addr; - -} py_vmpa_t; - - - - -/* Fournit une représentation d'une variable 'vmpa_t'. */ -static PyObject *py_vmpa_to_str(PyObject *); - -/* Effectue une comparaison avec un objet Python 'vmpa_t'. */ -static PyObject *py_vmpa_richcompare(PyObject *, PyObject *, int); - -/* Fournit une partie du contenu de la position représentée. */ -static PyObject *py_vmpa_get_value(PyObject *, void *); - -/* Définit une partie du contenu de la position représentée. */ -static int py_vmpa_set_value(PyObject *, PyObject *, void *); - -/* Crée un nouvel objet Python de type 'vmpa2t'. */ -static PyObject *py_vmpa_new(PyTypeObject *, PyObject *, PyObject *); - -/* Effectue une conversion d'un objet Python en type 'vmpa_t'. */ -static bool convert_pyobj_to_vmpa(PyObject *, vmpa2t *); - -/* Effectue une opération de type 'add' avec le type 'vmpa'. */ -static PyObject *py_vmpa_nb_add(PyObject *, PyObject *); - -/* Définit les constantes pour les localisations. */ -static bool py_vmpa_define_constants(PyTypeObject *); - - - -/* ------------------------ DEFINITION D'UNE ZONE EN MEMOIRE ------------------------ */ - - -/* Couverture mémoire */ -typedef struct _py_mrange_t -{ - PyObject_HEAD /* Préambule Python */ - - mrange_t range; /* Informations internes */ - -} py_mrange_t; - - -/* Fournit une représentation d'une variable 'mrange_t'. */ -static PyObject *py_mrange_to_str(PyObject *); - - - -/* Effectue une comparaison avec un objet Python 'mrange_t'. */ -static PyObject *py_mrange_richcompare(PyObject *, PyObject *, int); - - - -/* Indique si une zone en contient une autre ou non. */ -static PyObject *py_mrange_contains(PyObject *, PyObject *); - - - - -/* Fournit la position de départ de la zone mémoire représentée. */ -static PyObject *py_mrange_get_addr(PyObject *, void *); - -/* Définit la position de départ de la zone mémoire représentée. */ -static int py_mrange_set_addr(PyObject *, PyObject *, void *); - -/* Fournit la taille de la zone mémoire représentée. */ -static PyObject *py_mrange_get_length(PyObject *, void *); - -/* Définit la taille de la zone mémoire représentée. */ -static int py_mrange_set_length(PyObject *, PyObject *, void *); - -/* Calcule la position extérieure finale d'une couverture. */ -static PyObject *py_mrange_get_end_addr(PyObject *, void *); - - - - -/* Crée un nouvel objet Python de type 'mrange'. */ -static PyObject *py_mrange_new(PyTypeObject *, PyObject *, PyObject *); - - - - - - - -/* ---------------------------------------------------------------------------------- */ -/* DEFINITION D'UNE POSITION EN MEMOIRE */ -/* ---------------------------------------------------------------------------------- */ - - - - -/****************************************************************************** -* * -* Paramètres : obj = objet Python à traiter. * -* * -* Description : Fournit une représentation d'une variable 'vmpa_t'. * -* * -* Retour : Chaîne de caractère pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_vmpa_to_str(PyObject *obj) -{ - PyObject *result; /* Chaîne à retourner */ - vmpa2t *addr; /* Véritable adresse manipulée */ - 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(""); - - else if (physical != VMPA_NO_PHYSICAL && virtual == VMPA_NO_VIRTUAL) - result = PyUnicode_FromFormat("", phys_str); - - else if (physical == VMPA_NO_PHYSICAL && virtual != VMPA_NO_VIRTUAL) - result = PyUnicode_FromFormat("", virt_str); - - else - result = PyUnicode_FromFormat("", phys_str, virt_str); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : a = premier object Python à consulter. * -* b = second object Python à consulter. * -* op = type de comparaison menée. * -* * -* Description : Effectue une comparaison avec un objet Python 'vmpa_t'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_vmpa_richcompare(PyObject *a, PyObject *b, int op) -{ - PyObject *result; /* Bilan à retourner */ - vmpa2t *addr_a; /* Première adresse à traiter */ - vmpa2t addr_b; /* Seconde adresse à traiter */ - int comp; /* Résultat d'une comparaison */ - - addr_a = &((py_vmpa_t *)a)->addr; - - if (!convert_pyobj_to_vmpa(b, &addr_b)) - return NULL; - - comp = cmp_vmpa(addr_a, &addr_b); - - switch (op) - { - case Py_LT: - result = comp < 0 ? Py_True : Py_False; - break; - - case Py_LE: - result = comp <= 0 ? Py_True : Py_False; - break; - - case Py_EQ: - result = comp == 0 ? Py_True : Py_False; - break; - - case Py_NE: - result = comp != 0 ? Py_True : Py_False; - break; - - case Py_GT: - result = comp > 0 ? Py_True : Py_False; - break; - - case Py_GE: - result = comp >= 0 ? Py_True : Py_False; - break; - - default: - assert(false); - result = Py_NotImplemented; - break; - - } - - Py_INCREF(result); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = définition d'adresse visée par la procédure. * -* closure = sélection de la valeur à traiter. * -* * -* Description : Fournit une partie du contenu de la position représentée. * -* * -* Retour : Nombre positif ou nul ou None. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_vmpa_get_value(PyObject *self, void *closure) -{ - PyObject *result; /* Valeur à retourner */ - py_vmpa_t *vmpa; /* Véritable objet Python */ - char *key; /* Contenu à cibler précisément*/ - - vmpa = (py_vmpa_t *)self; - - key = (char *)closure; - - if (strcmp(key, "phys") == 0) - { - if (get_phy_addr(&vmpa->addr) == VMPA_NO_PHYSICAL) - { - result = Py_None; - Py_INCREF(result); - } - else result = Py_BuildValue("K", get_phy_addr(&vmpa->addr)); - } - else - { - if (get_virt_addr(&vmpa->addr) == VMPA_NO_VIRTUAL) - { - result = Py_None; - Py_INCREF(result); - } - else result = Py_BuildValue("K", get_virt_addr(&vmpa->addr)); - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = définition d'adresse visée par la procédure. * -* value = valeur fournie à intégrer ou prendre en compte. * -* closure = sélection de la valeur à traiter. * -* * -* Description : Définit une partie du contenu de la position représentée. * -* * -* Retour : Bilan de l'opération pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static int py_vmpa_set_value(PyObject *self, PyObject *value, void *closure) -{ - int result; /* Bilan à faire remonter */ - py_vmpa_t *vmpa; /* Véritable objet Python */ - char *key; /* Contenu à cibler précisément*/ - PY_LONG_LONG val; /* Valeur traduite génériquemt */ - int overflow; /* Détection d'une grosse val. */ - - result = 0; - - vmpa = (py_vmpa_t *)self; - - key = (char *)closure; - - if (strcmp(key, "phys") == 0) - { - if (value == Py_None) - init_vmpa(&vmpa->addr, VMPA_NO_PHYSICAL, get_virt_addr(&vmpa->addr)); - - else - { - val = PyLong_AsLongLongAndOverflow(value, &overflow); - - if (val == -1 && (overflow == 1 || PyErr_Occurred())) - { - result = -1; - PyErr_Clear(); - } - else init_vmpa(&vmpa->addr, val, get_virt_addr(&vmpa->addr)); - - } - - } - else - { - if (value == Py_None) - init_vmpa(&vmpa->addr, get_phy_addr(&vmpa->addr), VMPA_NO_VIRTUAL); - - else - { - val = PyLong_AsLongLongAndOverflow(value, &overflow); - - if (val == -1 && (overflow == 1 || PyErr_Occurred())) - { - result = -1; - PyErr_Clear(); - } - else init_vmpa(&vmpa->addr, get_phy_addr(&vmpa->addr), val); - - } - - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : type = type de l'objet à instancier. * -* args = arguments fournis à l'appel. * -* kwds = arguments de type key=val fournis. * -* * -* Description : Crée un nouvel objet Python de type 'vmpa2t'. * -* * -* Retour : Instance Python mise en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_vmpa_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - py_vmpa_t *result; /* Instance à retourner */ - unsigned long long phy; /* Position physique */ - unsigned long long virt; /* Adresse en mémoire virtuelle*/ - int ret; /* Bilan de lecture des args. */ - - phy = VMPA_NO_PHYSICAL; - virt = VMPA_NO_VIRTUAL; - - ret = PyArg_ParseTuple(args, "|KK", &phy, &virt); - if (!ret) Py_RETURN_NONE; - - result = (py_vmpa_t *)type->tp_alloc(type, 0); - - init_vmpa(&result->addr, phy, virt); - - return (PyObject *)result; - -} - - - - - - -/****************************************************************************** -* * -* Paramètres : obj = objet Python à tenter de convertir. * -* addr = structure équivalente pour Chrysalide. * -* * -* Description : Effectue une conversion d'un objet Python en type 'vmpa_t'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool convert_pyobj_to_vmpa(PyObject *obj, vmpa2t *addr) -{ - bool result; /* Résulats à retourner */ - PyTypeObject *py_vmpa_type; /* Type Python pour 'vmpa' */ - int ret; /* Bilan d'un appel */ - PY_LONG_LONG value; /* Valeur de type générique */ - int overflow; /* Détection d'une grosse val. */ - - result = false; - - py_vmpa_type = get_python_vmpa_type(); - - ret = PyObject_IsInstance(obj, (PyObject *)py_vmpa_type); - - /* S'il n'y a rien à faire... */ - if (ret == 1) - { - *addr = ((py_vmpa_t *)obj)->addr; - result = true; - } - - /* Sinon on demande à Python... */ - else - { - value = PyLong_AsLongLongAndOverflow(obj, &overflow); - - if (value == -1 && (overflow == 1 || PyErr_Occurred())) - { - PyErr_Clear(); - PyErr_SetString(PyExc_TypeError, _("Unable to cast object as VMPA.")); - } - - else - { - init_vmpa(addr, value, value); - result = true; - } - - } - - return result; - -} - - - - -/****************************************************************************** -* * -* Paramètres : o1 = premier élément concerné par l'opération. * -* o2 = second élément concerné par l'opération. * -* * -* Description : Effectue une opération de type 'add' avec le type 'vmpa'. * -* * -* Retour : Résultat de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_vmpa_nb_add(PyObject *o1, PyObject *o2) -{ - PyObject *result; /* Résultat à retourner */ - vmpa2t addr1; /* Première adresse à traiter */ - vmpa2t addr2; /* Seconde adresse à traiter */ - PyTypeObject *py_vmpa_type; /* Type Python pour 'vmpa' */ - - if (!convert_pyobj_to_vmpa(o1, &addr1)) - return NULL; - - if (!convert_pyobj_to_vmpa(o2, &addr2)) - return NULL; - - py_vmpa_type = get_python_vmpa_type(); - - result = PyObject_CallObject((PyObject *)py_vmpa_type, NULL); - - init_vmpa(&((py_vmpa_t *)result)->addr, - addr1.physical + addr2.physical, - addr1.virtual + addr2.virtual); - - return result; - -} - - - - - -void change_editor_items_current_view_content(void/*GtkDisplayPanel*/ *view) -{ - /* FIXME */ - -} - - - - -/****************************************************************************** -* * -* Paramètres : obj_type = type dont le dictionnaire est à compléter. * -* * -* Description : Définit les constantes pour les localisations. * -* * -* Retour : true en cas de succès de l'opération, false sinon. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool py_vmpa_define_constants(PyTypeObject *obj_type) -{ - bool result; /* Bilan à retourner */ - - result = true; - - result &= PyDict_AddIntMacro(obj_type, VMPA_NO_PHYSICAL); - result &= PyDict_AddIntMacro(obj_type, VMPA_NO_VIRTUAL); - - /* TODO : à bouger vers base ? */ - result &= PyDict_AddIntMacro(obj_type, SRE_LITTLE); - result &= PyDict_AddIntMacro(obj_type, SRE_MIDDLE); - result &= PyDict_AddIntMacro(obj_type, SRE_BIG); - - 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_vmpa_type(void) -{ - static PyNumberMethods py_vmpa_nb_proto = { - - .nb_add = py_vmpa_nb_add, - - /* - binaryfunc nb_add; - binaryfunc nb_subtract; - binaryfunc nb_multiply; - binaryfunc nb_remainder; - binaryfunc nb_divmod; - ternaryfunc nb_power; - unaryfunc nb_negative; - unaryfunc nb_positive; - unaryfunc nb_absolute; - inquiry nb_bool; - unaryfunc nb_invert; - binaryfunc nb_lshift; - binaryfunc nb_rshift; - binaryfunc nb_and; - binaryfunc nb_xor; - binaryfunc nb_or; - unaryfunc nb_int; - void *nb_reserved; - unaryfunc nb_float; - - binaryfunc nb_inplace_add; - binaryfunc nb_inplace_subtract; - binaryfunc nb_inplace_multiply; - binaryfunc nb_inplace_remainder; - ternaryfunc nb_inplace_power; - binaryfunc nb_inplace_lshift; - binaryfunc nb_inplace_rshift; - binaryfunc nb_inplace_and; - binaryfunc nb_inplace_xor; - binaryfunc nb_inplace_or; - - binaryfunc nb_floor_divide; - binaryfunc nb_true_divide; - binaryfunc nb_inplace_floor_divide; - binaryfunc nb_inplace_true_divide; - - unaryfunc nb_index; - - */ - - }; - - static PyGetSetDef py_vmpa_getseters[] = { - - { - "phys", py_vmpa_get_value, py_vmpa_set_value, - "Give access to the physical offset of the location.", "phys" - }, - - { - "virt", py_vmpa_get_value, py_vmpa_set_value, - "Give access to the virtual address of the location.", "virt" - }, - { NULL } - - }; - - static PyTypeObject py_vmpa_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.arch.vmpa", - .tp_basicsize = sizeof(py_vmpa_t), - - .tp_as_number = &py_vmpa_nb_proto, - - .tp_str = py_vmpa_to_str, - - .tp_flags = Py_TPFLAGS_DEFAULT, - - .tp_doc = "Python object for vmpa_t.", - - .tp_richcompare = py_vmpa_richcompare, - - .tp_getset = py_vmpa_getseters, - .tp_new = (newfunc)py_vmpa_new - - }; - - return &py_vmpa_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.arch.vmpa'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_vmpa(PyObject *module) -{ - PyTypeObject *py_vmpa_type; /* Type Python pour 'vmpa' */ - int ret; /* Bilan d'un appel */ - - py_vmpa_type = get_python_vmpa_type(); - - if (PyType_Ready(py_vmpa_type) != 0) - return false; - - if (!py_vmpa_define_constants(py_vmpa_type)) - return false; - - Py_INCREF(py_vmpa_type); - ret = PyModule_AddObject(module, "vmpa", (PyObject *)py_vmpa_type); - - return (ret == 0); - -} - - -/****************************************************************************** -* * -* Paramètres : obj = objet Python à traiter. * -* * -* Description : Donne accès au coeur d'un objet 'pychrysalide.arch.vmpa'. * -* * -* Retour : Localistion réelle ou NULL en cas de mauvaise conversion. * -* * -* Remarques : - * -* * -******************************************************************************/ - -vmpa2t *get_internal_vmpa(PyObject *obj) -{ - int ret; /* Bilan d'analyse */ - - ret = PyObject_IsInstance(obj, (PyObject *)get_python_vmpa_type()); - if (!ret) return NULL; - - return &((py_vmpa_t *)obj)->addr; - -} - - -/****************************************************************************** -* * -* Paramètres : addr = structure interne à copier en objet Python. * -* * -* Description : Convertit une structure de type 'vmpa2t' en objet Python. * -* * -* Retour : Object Python résultant de la conversion opérée. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyObject *build_from_internal_vmpa(const vmpa2t *addr) -{ - py_vmpa_t *result; /* Instance à retourner */ - PyTypeObject *type; /* Type à instancier */ - - type = get_python_vmpa_type(); - - result = (py_vmpa_t *)type->tp_alloc(type, 0); - - copy_vmpa(&result->addr, addr); - - return (PyObject *)result; - -} - - -/****************************************************************************** -* * -* Paramètres : arg = argument quelconque à tenter de convertir. * -* dst = destination des valeurs récupérées en cas de succès. * -* * -* Description : Tente de convertir en adresse n'importe quoi. * -* * -* Retour : Bilan de l'opération, voire indications supplémentaires. * -* * -* Remarques : - * -* * -******************************************************************************/ - -int convert_any_to_vmpa(PyObject *arg, void *dst) -{ - int result; /* Bilan à retourner */ - int ret; /* Test intermédiaire */ - vmpa2t *src; /* Modèle de données à copier */ - PY_LONG_LONG value; /* Valeur de type générique */ - int overflow; /* Détection d'une grosse val. */ - - result = 0; - - /* Si l'objet est au bon format, rien à faire ! */ - - ret = PyObject_IsInstance(arg, (PyObject *)get_python_vmpa_type()); - - if (ret == 1) - { - src = get_internal_vmpa(arg); - copy_vmpa((vmpa2t *)dst, src); - - result = 1; - goto catv_done; - - } - - /* Sinon on demande à Python... */ - - value = PyLong_AsLongLongAndOverflow(arg, &overflow); - - if (value == -1 && (overflow == 1 || PyErr_Occurred())) - PyErr_Clear(); - - else - { - init_vmpa((vmpa2t *)dst, VMPA_NO_PHYSICAL, value); - - result = 1; - goto catv_done; - - } - - PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to vmpa"); - - catv_done: - - return result; - -} - - - -/* ---------------------------------------------------------------------------------- */ -/* DEFINITION D'UNE ZONE EN MEMOIRE */ -/* ---------------------------------------------------------------------------------- */ - - - - - - - -/****************************************************************************** -* * -* Paramètres : obj = objet Python à traiter. * -* * -* Description : Fournit une représentation d'une variable 'mrange_t'. * -* * -* Retour : Chaîne de caractère pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_mrange_to_str(PyObject *obj) -{ - PyObject *result; /* Chaîne à retourner */ - - result = PyUnicode_FromFormat(""); - - return result; - -} - - - - -/****************************************************************************** -* * -* Paramètres : a = premier object Python à consulter. * -* b = second object Python à consulter. * -* op = type de comparaison menée. * -* * -* Description : Effectue une comparaison avec un objet Python 'mrange_t'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_mrange_richcompare(PyObject *a, PyObject *b, int op) -{ - PyObject *result; /* Bilan à retourner */ - mrange_t *range_a; /* Premier espace à traiter */ - mrange_t *range_b; /* Second espace à traiter */ - int status; /* Résultat d'une comparaison */ - - range_a = get_internal_mrange(a); - - range_b = get_internal_mrange(b); - if (range_b == NULL) return NULL; - - status = cmp_mrange(range_a, range_b); - - result = status_to_rich_cmp_state(status, op); - - Py_INCREF(result); - - return result; - -} - - - - - - - - - -/****************************************************************************** -* * -* Paramètres : self = contenu binaire à manipuler. * -* args = non utilisé ici. * -* * -* Description : Indique si une zone en contient une autre ou non. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_mrange_contains(PyObject *self, PyObject *args) -{ - PyObject *result; /* Bilan à faire remonter */ - int ret; /* Bilan de lecture des args. */ - PyObject *range_obj; /* Objet pour un intervale */ - mrange_t *range; /* Région mémoire de contenance*/ - mrange_t *sub; /* Région mémoire contenue ? */ - - ret = PyArg_ParseTuple(args, "O", &range_obj); - if (!ret) return NULL; - - ret = PyObject_IsInstance(range_obj, (PyObject *)get_python_mrange_type()); - if (!ret) return NULL; - - range = get_internal_mrange(self); - sub = get_internal_mrange(range_obj); - - result = (mrange_contains_mrange(range, sub) ? Py_True : Py_False); - - Py_INCREF(result); - - return result; - -} - - - - - -/****************************************************************************** -* * -* Paramètres : self = définition de l'espace visé par la procédure. * -* closure = élément non utilisé ici. * -* * -* Description : Fournit la position de départ de la zone mémoire représentée.* -* * -* Retour : Nouvelle objet mis en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_mrange_get_addr(PyObject *self, void *closure) -{ - PyObject *result; /* Valeur à retourner */ - mrange_t *range; /* Espace mémoire à manipuler */ - - range = get_internal_mrange(self); - - result = build_from_internal_vmpa(get_mrange_addr(range)); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = définition de l'espace visé par la procédure. * -* value = valeur fournie à intégrer ou prendre en compte. * -* closure = élément non utilisé ici. * -* * -* Description : Définit la position de départ de la zone mémoire représentée.* -* * -* Retour : Bilan de l'opération pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static int py_mrange_set_addr(PyObject *self, PyObject *value, void *closure) -{ - int result; /* Bilan à faire remonter */ - vmpa2t *addr; /* Localisation version C */ - mrange_t *range; /* Espace mémoire à manipuler */ - - result = 0; - - addr = get_internal_vmpa(value); - if (addr == NULL) return -1; - - range = get_internal_mrange(self); - - init_mrange(range, addr, get_mrange_length(range)); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = définition de l'espace visé par la procédure. * -* closure = élément non utilisé ici. * -* * -* Description : Fournit la taille de la zone mémoire représentée. * -* * -* Retour : Nouvelle objet mis en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_mrange_get_length(PyObject *self, void *closure) -{ - PyObject *result; /* Valeur à retourner */ - mrange_t *range; /* Espace mémoire à manipuler */ - - range = get_internal_mrange(self); - - result = Py_BuildValue("K", get_mrange_length(range)); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = définition de l'espace visé par la procédure. * -* value = valeur fournie à intégrer ou prendre en compte. * -* closure = élément non utilisé ici. * -* * -* Description : Définit la taille de la zone mémoire représentée. * -* * -* Retour : Bilan de l'opération pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static int py_mrange_set_length(PyObject *self, PyObject *value, void *closure) -{ - int result; /* Bilan à faire remonter */ - mrange_t *range; /* Espace mémoire à manipuler */ - PY_LONG_LONG val; /* Valeur traduite génériquemt */ - int overflow; /* Détection d'une grosse val. */ - vmpa2t tmp; /* Copie pour recopie */ - - result = 0; - - range = get_internal_mrange(self); - - val = PyLong_AsLongLongAndOverflow(value, &overflow); - - if (val == -1 && (overflow == 1 || PyErr_Occurred())) - { - result = -1; - PyErr_Clear(); - } - else - { - copy_vmpa(&tmp, get_mrange_addr(range)); - init_mrange(range, &tmp, val); - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = définition de l'espace visé par la procédure. * -* closure = élément non utilisé ici. * -* * -* Description : Calcule la position extérieure finale d'une couverture. * -* * -* Retour : Nouvelle objet mis en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_mrange_get_end_addr(PyObject *self, void *closure) -{ - PyObject *result; /* Valeur à retourner */ - mrange_t *range; /* Espace mémoire à manipuler */ - vmpa2t end; /* Adresse à reproduire */ - - range = get_internal_mrange(self); - compute_mrange_end_addr(range, &end); - - result = build_from_internal_vmpa(&end); - - return result; - -} - - - - - - - - - -/****************************************************************************** -* * -* Paramètres : type = type de l'objet à instancier. * -* args = arguments fournis à l'appel. * -* kwds = arguments de type key=val fournis. * -* * -* Description : Crée un nouvel objet Python de type 'mrange'. * -* * -* Retour : Instance Python mise en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_mrange_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - py_mrange_t *result; /* Instance à retourner */ - PyObject *py_vmpa; /* Localisation version Python */ - unsigned long long length; /* Taille physique */ - int ret; /* Bilan de lecture des args. */ - vmpa2t *addr; /* Localisation version C */ - - ret = PyArg_ParseTuple(args, "OK", &py_vmpa, &length); - if (!ret) return NULL; - - ret = PyObject_IsInstance(py_vmpa, (PyObject *)get_python_vmpa_type()); - if (!ret) return NULL; - - addr = get_internal_vmpa(py_vmpa); - if (addr == NULL) return NULL; - - result = (py_mrange_t *)type->tp_alloc(type, 0); - - init_mrange(&result->range, addr, length); - - return (PyObject *)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_mrange_type(void) -{ - static PyMethodDef py_mrange_methods[] = { - { "contains", py_mrange_contains, - METH_VARARGS, - "contains($self, other, /)\n--\nTell if the current range contains another given range or address." - }, -#if 0 - { "read_u8", py_arch_instruction_read_u8, - METH_VARARGS, - "read_u8($self, addr, /)\n--\n\nRead an unsigned byte from a given position." - }, -#endif - { NULL } - }; - - static PyGetSetDef py_mrange_getseters[] = { - { - "addr", py_mrange_get_addr, py_mrange_set_addr, - "Give access to the start location of the memory range.", NULL - }, - { - "length", py_mrange_get_length, py_mrange_set_length, - "Give access to the length of the memory range.", NULL - }, - { - "end", py_mrange_get_end_addr, NULL, - "Provide the final external point of the memory range.", NULL - }, - { NULL } - }; - - static PyTypeObject py_mrange_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.arch.mrange", - .tp_basicsize = sizeof(py_mrange_t), - - .tp_str = py_mrange_to_str, - - .tp_flags = Py_TPFLAGS_DEFAULT, - - .tp_doc = "Python object for mrange_t.", - - .tp_richcompare = py_mrange_richcompare, - - .tp_methods = py_mrange_methods, - .tp_getset = py_mrange_getseters, - .tp_new = (newfunc)py_mrange_new - - }; - - return &py_mrange_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.arch.mrange'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_mrange(PyObject *module) -{ - PyTypeObject *py_mrange_type; /* Type Python pour 'mrange' */ - int ret; /* Bilan d'un appel */ - - py_mrange_type = get_python_mrange_type(); - - if (PyType_Ready(py_mrange_type) != 0) - return false; - - Py_INCREF(py_mrange_type); - ret = PyModule_AddObject(module, "mrange", (PyObject *)py_mrange_type); - - return (ret == 0); - -} - - -/****************************************************************************** -* * -* Paramètres : obj = objet Python à traiter. * -* * -* Description : Donne accès au coeur d'un objet 'pychrysalide.arch.mrange'. * -* * -* Retour : Localistion réelle ou NULL en cas de mauvaise conversion. * -* * -* Remarques : - * -* * -******************************************************************************/ - -mrange_t *get_internal_mrange(PyObject *obj) -{ - int ret; /* Bilan d'analyse */ - - ret = PyObject_IsInstance(obj, (PyObject *)get_python_mrange_type()); - if (!ret) return NULL; - - return &((py_mrange_t *)obj)->range; - -} - - -/****************************************************************************** -* * -* Paramètres : range = structure interne à copier en objet Python. * -* * -* Description : Convertit une structure de type 'mrange_t' en objet Python. * -* * -* Retour : Object Python résultant de la conversion opérée. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyObject *build_from_internal_mrange(const mrange_t *range) -{ - py_mrange_t *result; /* Instance à retourner */ - PyTypeObject *type; /* Type à instancier */ - - type = get_python_mrange_type(); - - result = (py_mrange_t *)type->tp_alloc(type, 0); - - copy_mrange(&result->range, range); - - return (PyObject *)result; - -} diff --git a/plugins/pychrysa/arch/vmpa.h b/plugins/pychrysa/arch/vmpa.h deleted file mode 100644 index 46828f5..0000000 --- a/plugins/pychrysa/arch/vmpa.h +++ /dev/null @@ -1,71 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * vmpa.h - prototypes pour l'équivalent Python du fichier "arch/vmpa.h" - * - * Copyright (C) 2014-2017 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_ARCH_VMPA_H -#define _PLUGINS_PYCHRYSALIDE_ARCH_VMPA_H - - -#include -#include - - -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_vmpa_type(void); - -/* Prend en charge l'objet 'pychrysalide.arch.vmpa'. */ -bool register_python_vmpa(PyObject *); - -/* Donne accès au coeur d'un objet 'pychrysalide.arch.vmpa'. */ -vmpa2t *get_internal_vmpa(PyObject *); - -/* Convertit une structure de type 'vmpa2t' en objet Python. */ -PyObject *build_from_internal_vmpa(const vmpa2t *); - -/* Tente de convertir en adresse n'importe quoi. */ -int convert_any_to_vmpa(PyObject *, void *); - - - -/* ------------------------ DEFINITION D'UNE ZONE EN MEMOIRE ------------------------ */ - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_mrange_type(void); - -/* Prend en charge l'objet 'pychrysalide.arch.mrange'. */ -bool register_python_mrange(PyObject *); - -/* Donne accès au coeur d'un objet 'pychrysalide.arch.mrange'. */ -mrange_t *get_internal_mrange(PyObject *); - -/* Convertit une structure de type 'mrange_t' en objet Python. */ -PyObject *build_from_internal_mrange(const mrange_t *); - - - -#endif /* _PLUGINS_PYCHRYSALIDE_ARCH_VMPA_H */ diff --git a/plugins/pychrysa/common/Makefile.am b/plugins/pychrysa/common/Makefile.am deleted file mode 100644 index 0637229..0000000 --- a/plugins/pychrysa/common/Makefile.am +++ /dev/null @@ -1,17 +0,0 @@ - -noinst_LTLIBRARIES = libpychrysacommon.la - -libpychrysacommon_la_SOURCES = \ - bits.h bits.c \ - fnv1a.h fnv1a.c \ - module.h module.c \ - pathname.h pathname.c - - -libpychrysacommon_la_LDFLAGS = - - -AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ - -I../../../src - -AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) diff --git a/plugins/pychrysa/common/bits.c b/plugins/pychrysa/common/bits.c deleted file mode 100644 index 33f81c3..0000000 --- a/plugins/pychrysa/common/bits.c +++ /dev/null @@ -1,653 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * bits.c - équivalent Python du fichier "common/bits.c" - * - * Copyright (C) 2017 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 "bits.h" - - -#include "../helpers.h" - - - -/* Encapsulation d'un champ de bits */ -typedef struct _py_bitfield_t -{ - PyObject_HEAD /* A laisser en premier */ - - bitfield_t *native; /* Champ de bits représenté */ - -} py_bitfield_t; - - - -/* Crée un nouvel objet Python de type 'bitfield_t'. */ -static PyObject *py_bitfield_new(PyTypeObject *, PyObject *, PyObject *); - -/* Crée une copie d'un champ de bits classique. */ -static PyObject *py_bitfield_dup(PyObject *, PyObject *); - -/* Effectue une opération de type 'and' avec le type 'bitfield'. */ -static PyObject *py_bitfield_nb_and(PyObject *, PyObject *); - -/* Effectue une opération de type 'or' avec le type 'bitfield'. */ -static PyObject *py_bitfield_nb_or(PyObject *, PyObject *); - -/* Effectue une comparaison avec un objet Python 'bitfield'. */ -static PyObject *py_bitfield_richcompare(PyObject *, PyObject *, int); - -/* Bascule à 0 un champ de bits dans son intégralité. */ -static PyObject *py_bitfield_reset_all(PyObject *, PyObject *); - -/* Bascule à 1 un champ de bits dans son intégralité. */ -static PyObject *py_bitfield_set_all(PyObject *, PyObject *); - -/* Bascule à 0 une partie d'un champ de bits. */ -static PyObject *py_bitfield_reset(PyObject *, PyObject *); - -/* Bascule à 1 une partie d'un champ de bits. */ -static PyObject *py_bitfield_set(PyObject *, PyObject *); - -/* Détermine si un bit est à 1 dans un champ de bits. */ -static PyObject *py_bitfield_test(PyObject *, PyObject *); - -/* Détermine si un ensemble de bits est à 0 dans un champ. */ -static PyObject *py_bitfield_test_none(PyObject *, PyObject *); - -/* Détermine si un ensemble de bits est à 1 dans un champ. */ -static PyObject *py_bitfield_test_all(PyObject *, PyObject *); - - - -/****************************************************************************** -* * -* Paramètres : type = type de l'objet à instancier. * -* args = arguments fournis à l'appel. * -* kwds = arguments de type key=val fournis. * -* * -* Description : Crée un nouvel objet Python de type 'bitfield_t'. * -* * -* Retour : Instance Python mise en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_bitfield_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - py_bitfield_t *result; /* Instance à retourner */ - unsigned long length; /* Taille du champ à créer */ - int state; /* Initialisation par défaut */ - int ret; /* Bilan de lecture des args. */ - - ret = PyArg_ParseTuple(args, "kp", &length, &state); - if (!ret) return NULL; - - result = (py_bitfield_t *)type->tp_alloc(type, 0); - - result->native = create_bit_field(length, state); - - return (PyObject *)result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = champ de bits à dupliquer. * -* args = non utilisé ici. * -* * -* Description : Crée une copie d'un champ de bits classique. * -* * -* Retour : Champ de bits mis en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_bitfield_dup(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - py_bitfield_t *bf; /* Instance à manipuler */ - - bf = (py_bitfield_t *)self; - - result = build_from_internal_bitfield(bf->native);; - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : o1 = premier élément concerné par l'opération. * -* o2 = second élément concerné par l'opération. * -* * -* Description : Effectue une opération de type 'and' avec le type 'bitfield'.* -* * -* Retour : Résultat de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_bitfield_nb_and(PyObject *o1, PyObject *o2) -{ - PyObject *result; /* Résultat à retourner */ - int ret; /* Bilan de compatibilité */ - py_bitfield_t *bf_1; /* Instance à manipuler #1 */ - py_bitfield_t *bf_2; /* Instance à manipuler #2 */ - py_bitfield_t *new; /* Nouvelle version en place */ - - ret = PyObject_IsInstance(o2, (PyObject *)get_python_bitfield_type()); - if (!ret) - { - result = NULL; - goto pbna_done; - } - - bf_1 = (py_bitfield_t *)o1; - bf_2 = (py_bitfield_t *)o2; - - result = build_from_internal_bitfield(bf_1->native); - - new = (py_bitfield_t *)result; - - and_bit_field(new->native, bf_2->native); - - pbna_done: - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : o1 = premier élément concerné par l'opération. * -* o2 = second élément concerné par l'opération. * -* * -* Description : Effectue une opération de type 'or' avec le type 'bitfield'. * -* * -* Retour : Résultat de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_bitfield_nb_or(PyObject *o1, PyObject *o2) -{ - PyObject *result; /* Résultat à retourner */ - int ret; /* Bilan de compatibilité */ - py_bitfield_t *bf_1; /* Instance à manipuler #1 */ - py_bitfield_t *bf_2; /* Instance à manipuler #2 */ - py_bitfield_t *new; /* Nouvelle version en place */ - - ret = PyObject_IsInstance(o2, (PyObject *)get_python_bitfield_type()); - if (!ret) - { - result = NULL; - goto pbna_done; - } - - bf_1 = (py_bitfield_t *)o1; - bf_2 = (py_bitfield_t *)o2; - - result = build_from_internal_bitfield(bf_1->native); - - new = (py_bitfield_t *)result; - - or_bit_field(new->native, bf_2->native); - - pbna_done: - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : a = premier object Python à consulter. * -* b = second object Python à consulter. * -* op = type de comparaison menée. * -* * -* Description : Effectue une comparaison avec un objet Python 'bitfield'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_bitfield_richcompare(PyObject *a, PyObject *b, int op) -{ - PyObject *result; /* Bilan à retourner */ - int ret; /* Bilan de lecture des args. */ - py_bitfield_t *bf_a; /* Instance à manipuler #1 */ - py_bitfield_t *bf_b; /* Instance à manipuler #2 */ - int status; /* Résultat d'une comparaison */ - - ret = PyObject_IsInstance(b, (PyObject *)get_python_bitfield_type()); - if (!ret) - { - result = Py_NotImplemented; - goto cmp_done; - } - - bf_a = (py_bitfield_t *)a; - bf_b = (py_bitfield_t *)b; - - status = compare_bit_fields(bf_a->native, bf_b->native); - - result = status_to_rich_cmp_state(status, op); - - cmp_done: - - Py_INCREF(result); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = champ de bits à modifier. * -* args = non utilisé ici. * -* * -* Description : Bascule à 0 un champ de bits dans son intégralité. * -* * -* Retour : Rien (None). * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_bitfield_reset_all(PyObject *self, PyObject *args) -{ - py_bitfield_t *bf; /* Instance à manipuler */ - - bf = (py_bitfield_t *)self; - - reset_all_in_bit_field(bf->native); - - Py_RETURN_NONE; - -} - - -/****************************************************************************** -* * -* Paramètres : self = champ de bits à modifier. * -* args = non utilisé ici. * -* * -* Description : Bascule à 1 un champ de bits dans son intégralité. * -* * -* Retour : Rien (None). * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_bitfield_set_all(PyObject *self, PyObject *args) -{ - py_bitfield_t *bf; /* Instance à manipuler */ - - bf = (py_bitfield_t *)self; - - set_all_in_bit_field(bf->native); - - Py_RETURN_NONE; - -} - - -/****************************************************************************** -* * -* Paramètres : self = champ de bits à consulter. * -* args = arguments fournis pour la conduite de l'opération. * -* * -* Description : Bascule à 0 une partie d'un champ de bits. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_bitfield_reset(PyObject *self, PyObject *args) -{ - unsigned long first; /* Indice du premier bit testé */ - unsigned long count; /* Nombre de bits à analyser */ - int ret; /* Bilan de lecture des args. */ - py_bitfield_t *bf; /* Instance à manipuler */ - - ret = PyArg_ParseTuple(args, "kk", &first, &count); - if (!ret) return NULL; - - bf = (py_bitfield_t *)self; - - reset_in_bit_field(bf->native, first, count); - - Py_RETURN_NONE; - -} - - -/****************************************************************************** -* * -* Paramètres : self = champ de bits à consulter. * -* args = arguments fournis pour la conduite de l'opération. * -* * -* Description : Bascule à 1 une partie d'un champ de bits. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_bitfield_set(PyObject *self, PyObject *args) -{ - unsigned long first; /* Indice du premier bit testé */ - unsigned long count; /* Nombre de bits à analyser */ - int ret; /* Bilan de lecture des args. */ - py_bitfield_t *bf; /* Instance à manipuler */ - - ret = PyArg_ParseTuple(args, "kk", &first, &count); - if (!ret) return NULL; - - bf = (py_bitfield_t *)self; - - set_in_bit_field(bf->native, first, count); - - Py_RETURN_NONE; - -} - - -/****************************************************************************** -* * -* Paramètres : self = champ de bits à consulter. * -* args = arguments fournis pour la conduite de l'opération. * -* * -* Description : Détermine si un bit est à 1 dans un champ de bits. * -* * -* Retour : true si le bit correspondant est à l'état haut. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_bitfield_test(PyObject *self, PyObject *args) -{ - PyObject *result; /* Bilan à faire remonter */ - unsigned long n; /* Indice du bit à traiter */ - int ret; /* Bilan de lecture des args. */ - py_bitfield_t *bf; /* Instance à manipuler */ - bool status; /* Bilan d'analyse */ - - ret = PyArg_ParseTuple(args, "k", &n); - if (!ret) return NULL; - - bf = (py_bitfield_t *)self; - - status = test_in_bit_field(bf->native, n); - - result = status ? Py_True : Py_False; - - Py_INCREF(result); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = champ de bits à consulter. * -* args = arguments fournis pour la conduite de l'opération. * -* * -* Description : Détermine si un ensemble de bits est à 0 dans un champ. * -* * -* Retour : True si les bits correspondants sont à l'état bas. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_bitfield_test_none(PyObject *self, PyObject *args) -{ - PyObject *result; /* Bilan à faire remonter */ - unsigned long first; /* Indice du premier bit testé */ - unsigned long count; /* Nombre de bits à analyser */ - int ret; /* Bilan de lecture des args. */ - py_bitfield_t *bf; /* Instance à manipuler */ - bool status; /* Bilan d'analyse */ - - ret = PyArg_ParseTuple(args, "kk", &first, &count); - if (!ret) return NULL; - - bf = (py_bitfield_t *)self; - - status = test_none_in_bit_field(bf->native, first, count); - - result = status ? Py_True : Py_False; - - Py_INCREF(result); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = champ de bits à consulter. * -* args = arguments fournis pour la conduite de l'opération. * -* * -* Description : Détermine si un ensemble de bits est à 1 dans un champ. * -* * -* Retour : True si les bits correspondants sont à l'état haut. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_bitfield_test_all(PyObject *self, PyObject *args) -{ - PyObject *result; /* Bilan à faire remonter */ - unsigned long first; /* Indice du premier bit testé */ - unsigned long count; /* Nombre de bits à analyser */ - int ret; /* Bilan de lecture des args. */ - py_bitfield_t *bf; /* Instance à manipuler */ - bool status; /* Bilan d'analyse */ - - ret = PyArg_ParseTuple(args, "kk", &first, &count); - if (!ret) return NULL; - - bf = (py_bitfield_t *)self; - - status = test_all_in_bit_field(bf->native, first, count); - - result = status ? Py_True : Py_False; - - Py_INCREF(result); - - 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_bitfield_type(void) -{ - static PyNumberMethods py_bitfield_nb_proto = { - - .nb_and = py_bitfield_nb_and, - .nb_or = py_bitfield_nb_or - - }; - - static PyMethodDef py_bitfield_methods[] = { - { - "dup", py_bitfield_dup, - METH_NOARGS, - "dup(self, /)\n--\n\nDuplicate a bitfield." - }, - { - "reset_all", py_bitfield_reset_all, - METH_NOARGS, - "reset_all(self, /)\n--\n\nSwitch to 0 all bits in a bitfield." - }, - { - "set_all", py_bitfield_set_all, - METH_NOARGS, - "set_all(self, /)\n--\n\nSwitch to 1 all bits in a bitfield." - }, - { - "reset", py_bitfield_reset, - METH_VARARGS, - "reset(self, first, count, /)\n--\n\nSwitch to 0 a part of bits in a bitfield." - }, - { - "set", py_bitfield_set, - METH_VARARGS, - "set(self, first, count, /)\n--\n\nSwitch to 1 a part of bits in a bitfield." - }, - { - "test", py_bitfield_test, - METH_VARARGS, - "test(self, n, /)\n--\n\nTest if a given bit is set in a bitfield." - }, - { - "test_none", py_bitfield_test_none, - METH_VARARGS, - "test_none(self, first, count, /)\n--\n\nTest a range of bits to 0." - }, - { - "test_all", py_bitfield_test_all, - METH_VARARGS, - "test_all(self, first, count, /)\n--\n\nTest a range of bits to 1." - }, - { NULL } - }; - - static PyGetSetDef py_bitfield_getseters[] = { - { NULL } - }; - - static PyTypeObject py_bitfield_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.common.bitfield", - .tp_basicsize = sizeof(py_bitfield_t), - - .tp_as_number = &py_bitfield_nb_proto, - - .tp_flags = Py_TPFLAGS_DEFAULT, - - .tp_doc = "Python object for bitfield_t.", - - .tp_richcompare = py_bitfield_richcompare, - - .tp_methods = py_bitfield_methods, - .tp_getset = py_bitfield_getseters, - .tp_new = (newfunc)py_bitfield_new - - }; - - return &py_bitfield_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.common.bitfield'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_bitfield(PyObject *module) -{ - PyTypeObject *py_bitfield_type; /* Type Python pour 'bitfield' */ - int ret; /* Bilan d'un appel */ - - py_bitfield_type = get_python_bitfield_type(); - - if (PyType_Ready(py_bitfield_type) != 0) - return false; - - Py_INCREF(py_bitfield_type); - ret = PyModule_AddObject(module, "bitfield", (PyObject *)py_bitfield_type); - - return (ret == 0); - -} - - -/****************************************************************************** -* * -* Paramètres : field = structure interne à copier en objet Python. * -* * -* Description : Convertit une structure de type 'bitfield' en objet Python. * -* * -* Retour : Object Python résultant de la conversion opérée. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyObject *build_from_internal_bitfield(const bitfield_t *field) -{ - py_bitfield_t *result; /* Instance à retourner */ - PyTypeObject *type; /* Type à instancier */ - - type = get_python_bitfield_type(); - - result = (py_bitfield_t *)type->tp_alloc(type, 0); - - result->native = dup_bit_field(field); - - return (PyObject *)result; - -} diff --git a/plugins/pychrysa/common/bits.h b/plugins/pychrysa/common/bits.h deleted file mode 100644 index 41465ce..0000000 --- a/plugins/pychrysa/common/bits.h +++ /dev/null @@ -1,48 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * bits.h - prototypes pour l'équivalent Python du fichier "common/bits.h" - * - * Copyright (C) 2017 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_PYCHRYSA_COMMON_BITS_H -#define _PLUGINS_PYCHRYSA_COMMON_BITS_H - - -#include -#include - - -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_bitfield_type(void); - -/* Prend en charge l'objet 'pychrysalide.common.bitfield'. */ -bool register_python_bitfield(PyObject *); - -/* Convertit une structure de type 'bitfield' en objet Python. */ -PyObject *build_from_internal_bitfield(const bitfield_t *); - - - -#endif /* _PLUGINS_PYCHRYSA_COMMON_BITS_H */ diff --git a/plugins/pychrysa/common/fnv1a.c b/plugins/pychrysa/common/fnv1a.c deleted file mode 100644 index cc2c342..0000000 --- a/plugins/pychrysa/common/fnv1a.c +++ /dev/null @@ -1,145 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * fnv1a.c - équivalent Python du fichier "common/fnv1a.c" - * - * Copyright (C) 2015-2017 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 "fnv1a.h" - - -#include - - -#include - - - -/* Détermine l'empreinte FNV1a d'une chaîne de caractères. */ -static PyObject *py_fnv1a_hash(PyObject *, PyObject *); - - - -/****************************************************************************** -* * -* Paramètres : self = NULL car méthode statique. * -* args = arguments fournis lors de l'appel à la fonction. * -* * -* Description : Détermine l'empreinte FNV1a d'une chaîne de caractères. * -* * -* Retour : Numéro de révision. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_fnv1a_hash(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - const char *str; /* Chaîne à traiter. */ - int ret; /* Bilan de lecture des args. */ - fnv64_t value; /* Empreinte calculée */ - - ret = PyArg_ParseTuple(args, "s", &str); - if (!ret) Py_RETURN_NONE; - - value = fnv_64a_hash(str); - - result = Py_BuildValue("K", (unsigned long long)value); - - 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_fnv1a_type(void) -{ - static PyMethodDef py_fnv1a_methods[] = { - - { "hash", py_fnv1a_hash, - METH_VARARGS | METH_STATIC, - "hash(str, /)\n--\n\nCompute the FNV-1a hash from a given string." - }, - { NULL } - - }; - - static PyTypeObject py_fnv1a_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.core.fnv1a", - .tp_basicsize = sizeof(PyObject), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IS_ABSTRACT, - - .tp_doc = "Python version for Chrysalide of the Fowler-Noll-Vo hash function.", - - .tp_methods = py_fnv1a_methods - - }; - - return &py_fnv1a_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.core.fnv1a'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_fnv1a(PyObject *module) -{ - PyTypeObject *py_fnv1a_type; /* Type Python pour 'fnv1a' */ - int ret; /* Bilan d'un appel */ - - py_fnv1a_type = get_python_fnv1a_type(); - - //py_fnv1a_type->tp_new = PyType_GenericNew; - - if (PyType_Ready(py_fnv1a_type) != 0) - return false; - - Py_INCREF(py_fnv1a_type); - ret = PyModule_AddObject(module, "fnv1a", (PyObject *)py_fnv1a_type); - - return (ret == 0); - -} diff --git a/plugins/pychrysa/common/fnv1a.h b/plugins/pychrysa/common/fnv1a.h deleted file mode 100644 index 0a40770..0000000 --- a/plugins/pychrysa/common/fnv1a.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * fnv1a.h - prototypes pour l'équivalent Python du fichier "common/fnv1a.c" - * - * Copyright (C) 2015-2017 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_COMMON_FNV1A_H -#define _PLUGINS_PYCHRYSALIDE_COMMON_FNV1A_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_fnv1a_type(void); - -/* Prend en charge l'objet 'pychrysalide.common.fnv1a'. */ -bool register_python_fnv1a(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSALIDE_COMMON_FNV1A_H */ diff --git a/plugins/pychrysa/common/module.c b/plugins/pychrysa/common/module.c deleted file mode 100644 index 7ff7528..0000000 --- a/plugins/pychrysa/common/module.c +++ /dev/null @@ -1,99 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * module.c - intégration du répertoire common en tant que module - * - * Copyright (C) 2015-2017 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 "module.h" - - -#include "bits.h" -#include "fnv1a.h" -#include "pathname.h" -#include "../access.h" - - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute le module 'common' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool add_common_module_to_python_module(PyObject *super) -{ - bool result; /* Bilan à retourner */ - PyObject *module; /* Sous-module mis en place */ - int ret; /* Bilan d'un appel */ - - static PyModuleDef py_chrysalide_common_module = { - - .m_base = PyModuleDef_HEAD_INIT, - - .m_name = "pychrysalide.common", - .m_doc = "Python module for Chrysalide.common", - - .m_size = -1, - - }; - - result = false; - - module = PyModule_Create(&py_chrysalide_common_module); - if (module == NULL) return false; - - ret = PyState_AddModule(super, &py_chrysalide_common_module); - if (ret != 0) goto acmtpm_exit; - - ret = _PyImport_FixupBuiltin(module, "pychrysalide.common"); - if (ret != 0) goto acmtpm_exit; - - Py_INCREF(module); - ret = PyModule_AddObject(super, "common", module); - if (ret != 0) goto acmtpm_exit; - - result = true; - - result &= register_python_bitfield(module); - result &= register_python_fnv1a(module); - result &= register_python_pathname(module); - - if (result) - register_access_to_python_module("pychrysalide.common", module); - - acmtpm_exit: - - if (!result) - { - printf("something went wrong in %s...\n", __FUNCTION__); - /* ... */ - - } - - return result; - -} diff --git a/plugins/pychrysa/common/module.h b/plugins/pychrysa/common/module.h deleted file mode 100644 index 446f6fe..0000000 --- a/plugins/pychrysa/common/module.h +++ /dev/null @@ -1,39 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * module.h - prototypes pour l'intégration du répertoire common en tant que module - * - * Copyright (C) 2015-2017 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_COMMON_MODULE_H -#define _PLUGINS_PYCHRYSALIDE_COMMON_MODULE_H - - -#include -#include - - - -/* Ajoute le module 'common' au module Python. */ -bool add_common_module_to_python_module(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSALIDE_COMMON_MODULE_H */ diff --git a/plugins/pychrysa/common/pathname.c b/plugins/pychrysa/common/pathname.c deleted file mode 100644 index 40977df..0000000 --- a/plugins/pychrysa/common/pathname.c +++ /dev/null @@ -1,203 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * pathname.c - équivalent Python du fichier "common/pathname.c" - * - * Copyright (C) 2015-2017 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 "pathname.h" - - -#include -#include - - -#include - - -#include - - - -/* Calcule le chemin relatif entre deux fichiers donnés. */ -static PyObject *py_build_relative_filename(PyObject *, PyObject *); - -/* Calcule le chemin absolu d'un fichier par rapport à un autre. */ -static PyObject *py_build_absolute_filename(PyObject *, PyObject *); - - - -/****************************************************************************** -* * -* Paramètres : self = NULL car méthode statique. * -* args = arguments fournis lors de l'appel à la fonction. * -* * -* Description : Calcule le chemin relatif entre deux fichiers donnés. * -* * -* Retour : Chemin relatif obtenu. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_build_relative_filename(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - const char *ref; /* Fichier de référence */ - const char *target; /* Fichier à cibler */ - int ret; /* Bilan de lecture des args. */ - char *relative; /* Chemin d'accès construit */ - - ret = PyArg_ParseTuple(args, "ss", &ref, &target); - if (!ret) Py_RETURN_NONE; - - relative = build_relative_filename(ref, target); - - result = PyUnicode_FromString(relative); - - free(relative); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = NULL car méthode statique. * -* args = arguments fournis lors de l'appel à la fonction. * -* * -* Description : Calcule le chemin absolu d'un fichier par rapport à un autre.* -* * -* Retour : Chemin absolu obtenu. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_build_absolute_filename(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - const char *ref; /* Fichier de référence */ - const char *target; /* Fichier à cibler */ - int ret; /* Bilan de lecture des args. */ - char *relative; /* Chemin d'accès construit */ - - ret = PyArg_ParseTuple(args, "ss", &ref, &target); - if (!ret) Py_RETURN_NONE; - - relative = build_absolute_filename(ref, target); - - if (relative == NULL) - { - PyErr_SetString(PyExc_ValueError, _("Relative path is too deep.")); - result = NULL; - } - else - { - result = PyUnicode_FromString(relative); - - free(relative); - - } - - 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_pathname_type(void) -{ - static PyMethodDef py_pathname_methods[] = { - - { "build_relative_filename", py_build_relative_filename, - METH_VARARGS | METH_STATIC, - "build_relative_filename(ref, target, /)\n--\n\nCompute the relative path between two files." - }, - { "build_absolute_filename", py_build_absolute_filename, - METH_VARARGS | METH_STATIC, - "build_absolute_filename(ref, target, /)\n--\n\nCompute the absolute path for a file." - }, - { NULL } - - }; - - static PyTypeObject py_pathname_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.core.pathname", - .tp_basicsize = sizeof(PyObject), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IS_ABSTRACT, - - .tp_doc = "Path manipulations in Python for Chrysalide.", - - .tp_methods = py_pathname_methods - - }; - - return &py_pathname_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.core.pathname'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_pathname(PyObject *module) -{ - PyTypeObject *py_pathname_type; /* Type Python pour 'pathname' */ - int ret; /* Bilan d'un appel */ - - py_pathname_type = get_python_pathname_type(); - - //py_pathname_type->tp_new = PyType_GenericNew; - - if (PyType_Ready(py_pathname_type) != 0) - return false; - - Py_INCREF(py_pathname_type); - ret = PyModule_AddObject(module, "pathname", (PyObject *)py_pathname_type); - - return (ret == 0); - -} diff --git a/plugins/pychrysa/common/pathname.h b/plugins/pychrysa/common/pathname.h deleted file mode 100644 index a3940c9..0000000 --- a/plugins/pychrysa/common/pathname.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * pathname.h - prototypes pour l'équivalent Python du fichier "common/pathname.c" - * - * Copyright (C) 2015-2017 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_COMMON_PATHNAME_H -#define _PLUGINS_PYCHRYSALIDE_COMMON_PATHNAME_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_pathname_type(void); - -/* Prend en charge l'objet 'pychrysalide.common.pathname'. */ -bool register_python_pathname(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSALIDE_COMMON_PATHNAME_H */ diff --git a/plugins/pychrysa/core/Makefile.am b/plugins/pychrysa/core/Makefile.am deleted file mode 100644 index 71abfa4..0000000 --- a/plugins/pychrysa/core/Makefile.am +++ /dev/null @@ -1,17 +0,0 @@ - -noinst_LTLIBRARIES = libpychrysacore.la - -libpychrysacore_la_SOURCES = \ - formats.h formats.c \ - logs.h logs.c \ - module.h module.c \ - params.h params.c - - -libpychrysacore_la_LDFLAGS = - - -AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ - -I../../../src - -AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) diff --git a/plugins/pychrysa/core/formats.c b/plugins/pychrysa/core/formats.c deleted file mode 100644 index 621277a..0000000 --- a/plugins/pychrysa/core/formats.c +++ /dev/null @@ -1,190 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * formats.c - équivalent Python du fichier "core/formats.c" - * - * Copyright (C) 2015-2017 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 "formats.h" - - -#include - - -#include - - -#include "../helpers.h" - - - -/* Fournit le nom humain du format binaire visé. */ -static PyObject *py_formats_get_binary_format_name(PyObject *, PyObject *); - -/* Définit les constantes pour les paramètres. */ -static bool py_formats_define_constants(PyTypeObject *); - - - -/****************************************************************************** -* * -* Paramètres : self = NULL car méthode statique. * -* args = non utilisé ici. * -* * -* Description : Fournit le nom humain du format binaire visé. * -* * -* Retour : Désignation humaine trouvée ou None. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_formats_get_binary_format_name(PyObject *self, PyObject *args) -{ - PyObject *result; /* Désignation à retourner */ - const char *key; /* Nom court du format */ - int ret; /* Bilan de lecture des args. */ - const char *name; /* Désignation humaine */ - - ret = PyArg_ParseTuple(args, "s", &key); - if (!ret) return NULL; - - name = get_binary_format_name(key); - - if (name != NULL) - result = PyUnicode_FromString(name); - - else - { - result = Py_None; - Py_INCREF(result); - } - - 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_formats_type(void) -{ - static PyMethodDef py_formats_methods[] = { - - { "get_binary_format_name", py_formats_get_binary_format_name, - METH_VARARGS | METH_STATIC, - "get_binary_format_name(key, /)\n--\n\nGive access to the main configuration of Chrysalide." - }, - { NULL } - - }; - - static PyTypeObject py_formats_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.core.formats", - .tp_basicsize = sizeof(PyObject), - - .tp_flags = Py_TPFLAGS_DEFAULT, - - .tp_doc = "Python object for parameters", - - .tp_methods = py_formats_methods - - }; - - return &py_formats_type; - -} - - -/****************************************************************************** -* * -* Paramètres : obj_type = type dont le dictionnaire est à compléter. * -* * -* Description : Définit les constantes pour les paramètres. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool py_formats_define_constants(PyTypeObject *obj_type) -{ - bool result; /* Bilan à retourner */ - - result = true; - - result &= PyDict_AddIntMacro(obj_type, FMS_MATCHED); - result &= PyDict_AddIntMacro(obj_type, FMS_FORWARDED); - result &= PyDict_AddIntMacro(obj_type, FMS_UNKNOWN); - - result &= PyDict_AddIntMacro(obj_type, FMS_COUNT); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.core.formats'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_formats(PyObject *module) -{ - PyTypeObject *py_formats_type; /* Type Python pour 'formats' */ - int ret; /* Bilan d'un appel */ - - py_formats_type = get_python_formats_type(); - - py_formats_type->tp_new = PyType_GenericNew; - - if (PyType_Ready(py_formats_type) != 0) - return false; - - if (!py_formats_define_constants(py_formats_type)) - return false; - - Py_INCREF(py_formats_type); - ret = PyModule_AddObject(module, "formats", (PyObject *)py_formats_type); - - return (ret == 0); - -} diff --git a/plugins/pychrysa/core/formats.h b/plugins/pychrysa/core/formats.h deleted file mode 100644 index ca12c3e..0000000 --- a/plugins/pychrysa/core/formats.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * formats.h - prototypes pour l'équivalent Python du fichier "core/formats.h" - * - * Copyright (C) 2015-2017 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_FORMATS_H -#define _PLUGINS_PYCHRYSALIDE_CORE_FORMATS_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_formats_type(void); - -/* Prend en charge l'objet 'pychrysalide.core.formats'. */ -bool register_python_formats(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSALIDE_CORE_FORMATS_H */ diff --git a/plugins/pychrysa/core/logs.c b/plugins/pychrysa/core/logs.c deleted file mode 100644 index 8a922c1..0000000 --- a/plugins/pychrysa/core/logs.c +++ /dev/null @@ -1,278 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * logs.c - équivalent Python du fichier "gui/panels/logs.c" - * - * Copyright (C) 2017 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 "logs.h" - - -#include - - -#include - - -#include "../helpers.h" - - - -/* Fournit la verbosité des messages système. */ -static PyObject *py_logs_get_verbosity(PyObject *, PyObject *); - -/* Définit la verbosité des messages système. */ -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(PyTypeObject *); - - - -/****************************************************************************** -* * -* Paramètres : self = classe assurant le lien avec l'éditeur de messages. * -* args = arguments fournis à l'appel. * -* * -* Description : Fournit la verbosité des messages système. * -* * -* Retour : Plus faible niveau des types de message affichés. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_logs_get_verbosity(PyObject *self, PyObject *args) -{ - PyObject *result; /* Conversion à retourner */ - LogMessageType verbosity; /* Niveau de filtre de message */ - - verbosity = get_log_verbosity(); - - result = PyLong_FromUnsignedLong(verbosity); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = classe assurant le lien avec l'éditeur de messages. * -* args = arguments fournis à l'appel. * -* * -* Description : Définit la verbosité des messages système. * -* * -* Retour : Rien en équivalent Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_logs_set_verbosity(PyObject *self, PyObject *args) -{ - PyObject *result; /* Bilan à retourner */ - unsigned long verbosity; /* Niveau de filtre de message */ - - if (!PyArg_ParseTuple(args, "k", &verbosity)) - return NULL; - - set_log_verbosity(verbosity); - - result = Py_None; - Py_INCREF(result); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = classe assurant le lien avec l'éditeur de messages. * -* args = arguments fournis à l'appel. * -* * -* Description : Affiche un message dans le journal des messages système. * -* * -* Retour : Rien en équivalent Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_logs_log_message(PyObject *self, PyObject *args) -{ - PyObject *result; /* Bilan à retourner */ - unsigned long type; /* Espèce du message */ - const char *msg; /* Contenu du message */ - - if (!PyArg_ParseTuple(args, "ks", &type, &msg)) - return NULL; - - switch (type) - { - case LMT_INFO: - case LMT_PROCESS: - case LMT_WARNING: - case LMT_ERROR: - case LMT_BAD_BINARY: - log_simple_message(type, msg); - result = Py_None; - Py_INCREF(result); - break; - - default: - PyErr_SetString(PyExc_ValueError, - _("Invalid type of message")); - result = NULL; - break; - - } - - 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_logs_type(void) -{ - static PyMethodDef py_logs_methods[] = { - { - "get_verbosity", (PyCFunction)py_logs_get_verbosity, - METH_NOARGS | METH_STATIC, - "get_verbosity(, /)\n--\n\nGet the log verbosity." - }, - { - "set_verbosity", (PyCFunction)py_logs_set_verbosity, - METH_VARARGS | METH_STATIC, - "set_verbosity(, /)\n--\n\nSet the log verbosity." - }, - { - "log_message", (PyCFunction)py_logs_log_message, - METH_VARARGS | METH_STATIC, - "log_message(type, msg, /)\n--\n\nDisplay a message in the log window, if any." - }, - { NULL } - - }; - - static PyGetSetDef py_logs_getseters[] = { - { NULL } - }; - - static PyTypeObject py_logs_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.core.logs", - .tp_basicsize = sizeof(PyObject) + 80, - - .tp_flags = Py_TPFLAGS_DEFAULT, - - .tp_doc = "Python object for logs", - - .tp_methods = py_logs_methods, - .tp_getset = py_logs_getseters - - }; - - return &py_logs_type; - -} - - -/****************************************************************************** -* * -* Paramètres : obj_type = type dont le dictionnaire est à 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(PyTypeObject *obj_type) -{ - bool result; /* Bilan à retourner */ - - result = true; - - result &= PyDict_AddIntMacro(obj_type, LMT_INFO); - result &= PyDict_AddIntMacro(obj_type, LMT_PROCESS); - result &= PyDict_AddIntMacro(obj_type, LMT_WARNING); - result &= PyDict_AddIntMacro(obj_type, LMT_ERROR); - result &= PyDict_AddIntMacro(obj_type, LMT_BAD_BINARY); - result &= PyDict_AddIntMacro(obj_type, LMT_COUNT); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.gui.panels.LogPanel'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_logs(PyObject *module) -{ - PyTypeObject *py_logs_type; /* Type Python pour 'logs' */ - int ret; /* Bilan d'un appel */ - - py_logs_type = get_python_logs_type(); - - py_logs_type->tp_new = PyType_GenericNew; - - if (PyType_Ready(py_logs_type) != 0) - return false; - - if (!define_python_log_constants(py_logs_type)) - return false; - - Py_INCREF(py_logs_type); - ret = PyModule_AddObject(module, "logs", (PyObject *)py_logs_type); - - return (ret == 0); - -} diff --git a/plugins/pychrysa/core/logs.h b/plugins/pychrysa/core/logs.h deleted file mode 100644 index f1c7faf..0000000 --- a/plugins/pychrysa/core/logs.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * logs.h - prototypes pour l'équivalent Python du fichier "core/logs.h" - * - * Copyright (C) 2017 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_PYCHRYSA_CORE_LOGS_H -#define _PLUGINS_PYCHRYSA_CORE_LOGS_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_logs_type(void); - -/* Prend en charge l'objet 'pychrysalide.core.logs'. */ -bool register_python_logs(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSA_CORE_LOGS_H */ diff --git a/plugins/pychrysa/core/module.c b/plugins/pychrysa/core/module.c deleted file mode 100644 index ff7f828..0000000 --- a/plugins/pychrysa/core/module.c +++ /dev/null @@ -1,97 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * module.c - intégration du répertoire core en tant que module - * - * Copyright (C) 2014-2017 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 "module.h" - - -#include - - -#include "formats.h" -#include "logs.h" -#include "params.h" -#include "../access.h" - - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute le module 'core' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool add_core_module_to_python_module(PyObject *super) -{ - bool result; /* Bilan à retourner */ - PyObject *module; /* Sous-module mis en place */ - int ret; /* Bilan d'un appel */ - - static PyModuleDef py_chrysalide_core_module = { - - .m_base = PyModuleDef_HEAD_INIT, - - .m_name = "pychrysalide.core", - .m_doc = "Python module for Chrysalide.core", - - .m_size = -1, - - }; - - result = false; - - module = PyModule_Create(&py_chrysalide_core_module); - if (module == NULL) return false; - - ret = PyState_AddModule(super, &py_chrysalide_core_module); - if (ret != 0) goto loading_failed; - - ret = _PyImport_FixupBuiltin(module, "pychrysalide.core"); - if (ret != 0) goto loading_failed; - - Py_INCREF(module); - ret = PyModule_AddObject(super, "core", module); - if (ret != 0) goto loading_failed; - - result = true; - - result &= register_python_formats(module); - result &= register_python_logs(module); - result &= register_python_params(module); - - if (result) - register_access_to_python_module("pychrysalide.core", module); - - loading_failed: - - assert(result); - - return result; - -} diff --git a/plugins/pychrysa/core/module.h b/plugins/pychrysa/core/module.h deleted file mode 100644 index 8581425..0000000 --- a/plugins/pychrysa/core/module.h +++ /dev/null @@ -1,39 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * module.h - prototypes pour l'intégration du répertoire core en tant que module - * - * Copyright (C) 2014-2017 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_MODULE_H -#define _PLUGINS_PYCHRYSALIDE_CORE_MODULE_H - - -#include -#include - - - -/* Ajoute le module 'core' au module Python. */ -bool add_core_module_to_python_module(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSALIDE_CORE_MODULE_H */ diff --git a/plugins/pychrysa/core/params.c b/plugins/pychrysa/core/params.c deleted file mode 100644 index df71a88..0000000 --- a/plugins/pychrysa/core/params.c +++ /dev/null @@ -1,179 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * params.c - équivalent Python du fichier "core/params.c" - * - * Copyright (C) 2014-2017 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 "params.h" - - -#include - - -#include - - -#include "../helpers.h" - - - -/* Fournit la version du programme global. */ -static PyObject *py_params_get_main_configuration(PyObject *, PyObject *); - -/* Définit les constantes pour les paramètres. */ -static bool py_params_define_constants(PyTypeObject *); - - - -/****************************************************************************** -* * -* Paramètres : self = NULL car méthode statique. * -* args = non utilisé ici. * -* * -* Description : Fournit la version du programme global. * -* * -* Retour : Numéro de révision. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_params_get_main_configuration(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance GLib à retourner */ - GGenConfig *config; /* Configuration à convertir */ - - config = get_main_configuration(); - - result = pygobject_new(G_OBJECT(config)); - Py_XINCREF(result); - - 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_params_type(void) -{ - static PyMethodDef py_params_methods[] = { - - { "get_main_configuration", py_params_get_main_configuration, - METH_NOARGS | METH_STATIC, - "Give access to the main configuration of Chrysalide." - }, - { NULL } - - }; - - static PyTypeObject py_params_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.core.params", - .tp_basicsize = sizeof(PyObject), - - .tp_flags = Py_TPFLAGS_DEFAULT, - - .tp_doc = "Python object for parameters", - - .tp_methods = py_params_methods - - }; - - return &py_params_type; - -} - - -/****************************************************************************** -* * -* Paramètres : obj_type = type dont le dictionnaire est à compléter. * -* * -* Description : Définit les constantes pour les paramètres. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool py_params_define_constants(PyTypeObject *obj_type) -{ - bool result; /* Bilan à retourner */ - - result = true; - - result &= PyDict_AddStringMacro(obj_type, MPK_LAST_PROJECT); - result &= PyDict_AddStringMacro(obj_type, MPK_ELLIPSIS_HEADER); - result &= PyDict_AddStringMacro(obj_type, MPK_ELLIPSIS_TAB); - result &= PyDict_AddStringMacro(obj_type, MPK_KEYBINDINGS_EDIT); - result &= PyDict_AddStringMacro(obj_type, MPK_AUTO_SAVE); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.core.params'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_params(PyObject *module) -{ - PyTypeObject *py_params_type; /* Type Python pour 'params' */ - int ret; /* Bilan d'un appel */ - - py_params_type = get_python_params_type(); - - py_params_type->tp_new = PyType_GenericNew; - - if (PyType_Ready(py_params_type) != 0) - return false; - - if (!py_params_define_constants(py_params_type)) - return false; - - Py_INCREF(py_params_type); - ret = PyModule_AddObject(module, "params", (PyObject *)py_params_type); - - return (ret == 0); - -} diff --git a/plugins/pychrysa/core/params.h b/plugins/pychrysa/core/params.h deleted file mode 100644 index e7297b3..0000000 --- a/plugins/pychrysa/core/params.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * params.h - prototypes pour l'équivalent Python du fichier "core/params.h" - * - * Copyright (C) 2014-2017 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_PARAMS_H -#define _PLUGINS_PYCHRYSALIDE_CORE_PARAMS_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_params_type(void); - -/* Prend en charge l'objet 'pychrysalide.core.params'. */ -bool register_python_params(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSALIDE_CORE_PARAMS_H */ diff --git a/plugins/pychrysa/debug/Makefile.am b/plugins/pychrysa/debug/Makefile.am deleted file mode 100644 index 8011c49..0000000 --- a/plugins/pychrysa/debug/Makefile.am +++ /dev/null @@ -1,19 +0,0 @@ - -noinst_LTLIBRARIES = libpychrysadebug.la - -libpychrysadebug_la_SOURCES = \ - debugger.h debugger.c \ - module.h module.c - -libpychrysadebug_la_LIBADD = \ - gdbrsp/libpychrysadebuggdbrsp.la - -libpychrysadebug_la_LDFLAGS = - - -AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ - -I../../../src - -AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) - -SUBDIRS = gdbrsp diff --git a/plugins/pychrysa/debug/debugger.c b/plugins/pychrysa/debug/debugger.c deleted file mode 100644 index 20b94c7..0000000 --- a/plugins/pychrysa/debug/debugger.c +++ /dev/null @@ -1,1185 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * debugger.c - instances Python de débogueurs - * - * Copyright (C) 2012-2017 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 "debugger.h" - - -#include -#include -#include - - -#include - - -#include "../helpers.h" -#include "../arch/vmpa.h" - - - - - -/* Fournit les identifiants de tous les threads actifs. */ -static PyObject *py_binary_debugger_list_all_threads(PyObject *, PyObject *); - - - -/* Lit une valeur de 8 bits à une adresse arbitraire. */ -static PyObject *py_binary_debugger_read_memory_u8(PyObject *, PyObject *); - -/* Lit une valeur de 16 bits à une adresse arbitraire. */ -static PyObject *py_binary_debugger_read_memory_u16(PyObject *, PyObject *); - -/* Lit une valeur de 32 bits à une adresse arbitraire. */ -static PyObject *py_binary_debugger_read_memory_u32(PyObject *, PyObject *); - -/* Lit une valeur de 64 bits à une adresse arbitraire. */ -static PyObject *py_binary_debugger_read_memory_u64(PyObject *, PyObject *); - -/* Liste l'ensemble des registres appartenant à un groupe. */ -static PyObject *py_binary_debugger_get_register_names(PyObject *, PyObject *); - -/* Indique la taille associée à un registre donné. */ -static PyObject *py_binary_debugger_get_register_size(PyObject *, PyObject *); - -/* Lit une valeur de 8 bits à partir d'un registre. */ -static PyObject *py_binary_debugger_read_register_u8(PyObject *, PyObject *); - -/* Lit une valeur de 16 bits à partir d'un registre. */ -static PyObject *py_binary_debugger_read_register_u16(PyObject *, PyObject *); - -/* Lit une valeur de 32 bits à partir d'un registre. */ -static PyObject *py_binary_debugger_read_register_u32(PyObject *, PyObject *); - -/* Lit une valeur de 64 bits à partir d'un registre. */ -static PyObject *py_binary_debugger_read_register_u64(PyObject *, PyObject *); - -/* Ecrit une valeur de 8 bits dans un registre. */ -static PyObject *py_binary_debugger_write_register_u8(PyObject *, PyObject *); - -/* Ecrit une valeur de 16 bits dans un registre. */ -static PyObject *py_binary_debugger_write_register_u16(PyObject *, PyObject *); - -/* Ecrit une valeur de 32 bits dans un registre. */ -static PyObject *py_binary_debugger_write_register_u32(PyObject *, PyObject *); - -/* Ecrit une valeur de 64 bits dans un registre. */ -static PyObject *py_binary_debugger_write_register_u64(PyObject *, PyObject *); - - - -/* Remonte la pile d'appels jusqu'au point courant. */ -static PyObject *py_binary_debugger_get_call_stack(PyObject *, PyObject *); - - - -/* Ajoute un point d'arrêt basique en mémoire. */ -static PyObject *py_binary_debugger_add_mem_bp(PyObject *, PyObject *); - -/* Retire un point d'arrêt basique en mémoire. */ -static PyObject *py_binary_debugger_delete_mem_bp(PyObject *, PyObject *); - - - -/* Redémarre le processus de débogage. */ -static PyObject *py_binary_debugger_restart(PyObject *, PyObject *); - -/* Remet en marche le débogueur courant. */ -static PyObject *py_binary_debugger_resume(PyObject *, PyObject *); - -/* Relance l'exécution pour une seule instruction. */ -static PyObject *py_binary_debugger_stepi(PyObject *, PyObject *); - - - - - - - - - - - - - - - - -/****************************************************************************** -* * -* Paramètres : self = contenu binaire à manipuler. * -* args = arguments non utilisés ici. * -* * -* Description : Fournit les identifiants de tous les threads actifs. * -* * -* Retour : Liste contenant identifiants et désignations de threads. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_debugger_list_all_threads(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - GBinaryDebugger *debugger; /* Version GLib du format */ - size_t count; /* Quantité de threads actifs */ - dbg_thread_desc *threads; /* Liste des threads actifs */ - size_t i; /* Boucle de parcours */ - PyObject *thread; /* Détails sur un thread donné */ - - debugger = G_BINARY_DEBUGGER(pygobject_get(self)); - assert(debugger != NULL); - - threads = g_binary_debugger_list_all_threads(debugger, &count); - - result = PyTuple_New(count); - - for (i = 0; i < count; i++) - { - thread = PyTuple_New(2); - PyTuple_SetItem(result, i, thread); - - PyTuple_SetItem(thread, 0, PyLong_FromLong(threads[i].id)); - PyTuple_SetItem(thread, 1, PyUnicode_FromString(threads[i].name)); - - } - - delete_dbg_thread_desc(threads, count); - - return result; - -} - - - - - - - -/****************************************************************************** -* * -* Paramètres : self = contenu binaire à manipuler. * -* args = arguments accompagnant l'appel. * -* * -* Description : Lit une valeur de 8 bits à une adresse arbitraire. * -* * -* Retour : Valeur lue ou None. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_debugger_read_memory_u8(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - GBinaryDebugger *debugger; /* Version GLib du format */ - int ret; /* Bilan de lecture des args. */ - vmpa2t addr; /* Position interne associée */ - uint8_t value; /* Valeur lue en mémoire */ - bool status; /* Bilan de l'opération */ - - debugger = G_BINARY_DEBUGGER(pygobject_get(self)); - assert(debugger != NULL); - - ret = PyArg_ParseTuple(args, "O&", convert_any_to_vmpa, &addr); - if (!ret) return NULL; - - status = g_binary_debugger_read_memory_u8(debugger, get_virt_addr(&addr), &value); - - if (status) - result = PyLong_FromUnsignedLongLong(value); - - else - { - result = Py_None; - Py_INCREF(result); - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = contenu binaire à manipuler. * -* args = arguments accompagnant l'appel. * -* * -* Description : Lit une valeur de 16 bits à une adresse arbitraire. * -* * -* Retour : Valeur lue ou None. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_debugger_read_memory_u16(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - GBinaryDebugger *debugger; /* Version GLib du format */ - int ret; /* Bilan de lecture des args. */ - vmpa2t addr; /* Position interne associée */ - uint16_t value; /* Valeur lue en mémoire */ - bool status; /* Bilan de l'opération */ - - debugger = G_BINARY_DEBUGGER(pygobject_get(self)); - assert(debugger != NULL); - - ret = PyArg_ParseTuple(args, "O&", convert_any_to_vmpa, &addr); - if (!ret) return NULL; - - status = g_binary_debugger_read_memory_u16(debugger, get_virt_addr(&addr), &value); - - if (status) - result = PyLong_FromUnsignedLongLong(value); - - else - { - result = Py_None; - Py_INCREF(result); - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = contenu binaire à manipuler. * -* args = arguments accompagnant l'appel. * -* * -* Description : Lit une valeur de 32 bits à une adresse arbitraire. * -* * -* Retour : Valeur lue ou None. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_debugger_read_memory_u32(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - GBinaryDebugger *debugger; /* Version GLib du format */ - int ret; /* Bilan de lecture des args. */ - vmpa2t addr; /* Position interne associée */ - uint32_t value; /* Valeur lue en mémoire */ - bool status; /* Bilan de l'opération */ - - debugger = G_BINARY_DEBUGGER(pygobject_get(self)); - assert(debugger != NULL); - - ret = PyArg_ParseTuple(args, "O&", convert_any_to_vmpa, &addr); - if (!ret) return NULL; - - status = g_binary_debugger_read_memory_u32(debugger, get_virt_addr(&addr), &value); - - if (status) - result = PyLong_FromUnsignedLongLong(value); - - else - { - result = Py_None; - Py_INCREF(result); - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = contenu binaire à manipuler. * -* args = arguments accompagnant l'appel. * -* * -* Description : Lit une valeur de 64 bits à une adresse arbitraire. * -* * -* Retour : Valeur lue ou None. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_debugger_read_memory_u64(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - GBinaryDebugger *debugger; /* Version GLib du format */ - int ret; /* Bilan de lecture des args. */ - vmpa2t addr; /* Position interne associée */ - uint64_t value; /* Valeur lue en mémoire */ - bool status; /* Bilan de l'opération */ - - debugger = G_BINARY_DEBUGGER(pygobject_get(self)); - assert(debugger != NULL); - - ret = PyArg_ParseTuple(args, "O&", convert_any_to_vmpa, &addr); - if (!ret) return NULL; - - status = g_binary_debugger_read_memory_u64(debugger, get_virt_addr(&addr), &value); - - if (status) - result = PyLong_FromUnsignedLongLong(value); - - else - { - result = Py_None; - Py_INCREF(result); - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = instance de débogueur à consulter. * -* args = arguments accompagnant l'appel. * -* * -* Description : Liste l'ensemble des registres appartenant à un groupe. * -* * -* Retour : Liste de noms à libérer de la mémoire après utilisation. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_debugger_get_register_names(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - GBinaryDebugger *debugger; /* Version GLib du format */ - const char *group; /* Nom du registre à manipuler */ - int ret; /* Bilan de lecture des args. */ - char **list; /* Liste de noms de registre */ - size_t count; /* Taille de cette liste */ - size_t i; /* Boucle de parcours */ - - debugger = G_BINARY_DEBUGGER(pygobject_get(self)); - assert(debugger != NULL); - - ret = PyArg_ParseTuple(args, "|s", &group); - if (!ret) return NULL; - - list = g_binary_debugger_get_register_names(debugger, group, &count); - - result = PyTuple_New(count); - - for (i = 0; i < count; i++) - { - PyTuple_SetItem(result, i, PyUnicode_FromString(list[i])); - free(list[i]); - } - - if (list != NULL) - free(list); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = instance de débogueur à consulter. * -* args = arguments accompagnant l'appel. * -* * -* Description : Indique la taille associée à un registre donné. * -* * -* Retour : Taille en bits, ou 0 si le registre n'a pas été trouvé. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_debugger_get_register_size(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - GBinaryDebugger *debugger; /* Version GLib du format */ - const char *reg; /* Nom du registre à manipuler */ - int ret; /* Bilan de lecture des args. */ - unsigned int size; /* Taille associée au registre */ - - debugger = G_BINARY_DEBUGGER(pygobject_get(self)); - assert(debugger != NULL); - - ret = PyArg_ParseTuple(args, "s", ®); - if (!ret) return NULL; - - size = g_binary_debugger_get_register_size(debugger, reg); - - result = PyLong_FromUnsignedLong(size); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = contenu binaire à manipuler. * -* args = arguments accompagnant l'appel. * -* * -* Description : Lit une valeur de 8 bits à partir d'un registre. * -* * -* Retour : Valeur lue ou None. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_debugger_read_register_u8(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - GBinaryDebugger *debugger; /* Version GLib du format */ - const char *reg; /* Nom du registre à manipuler */ - int ret; /* Bilan de lecture des args. */ - uint8_t value; /* Valeur lue en mémoire */ - bool status; /* Bilan de l'opération */ - - debugger = G_BINARY_DEBUGGER(pygobject_get(self)); - assert(debugger != NULL); - - ret = PyArg_ParseTuple(args, "s", ®); - if (!ret) return NULL; - - status = g_binary_debugger_read_register_u8(debugger, reg, &value); - - if (status) - result = PyLong_FromUnsignedLongLong(value); - - else - { - result = Py_None; - Py_INCREF(result); - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = contenu binaire à manipuler. * -* args = arguments accompagnant l'appel. * -* * -* Description : Lit une valeur de 16 bits à partir d'un registre. * -* * -* Retour : Valeur lue ou None. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_debugger_read_register_u16(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - GBinaryDebugger *debugger; /* Version GLib du format */ - const char *reg; /* Nom du registre à manipuler */ - int ret; /* Bilan de lecture des args. */ - uint16_t value; /* Valeur lue en mémoire */ - bool status; /* Bilan de l'opération */ - - debugger = G_BINARY_DEBUGGER(pygobject_get(self)); - assert(debugger != NULL); - - ret = PyArg_ParseTuple(args, "s", ®); - if (!ret) return NULL; - - status = g_binary_debugger_read_register_u16(debugger, reg, &value); - - if (status) - result = PyLong_FromUnsignedLongLong(value); - - else - { - result = Py_None; - Py_INCREF(result); - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = contenu binaire à manipuler. * -* args = arguments accompagnant l'appel. * -* * -* Description : Lit une valeur de 32 bits à partir d'un registre. * -* * -* Retour : Valeur lue ou None. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_debugger_read_register_u32(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - GBinaryDebugger *debugger; /* Version GLib du format */ - const char *reg; /* Nom du registre à manipuler */ - int ret; /* Bilan de lecture des args. */ - uint32_t value; /* Valeur lue en mémoire */ - bool status; /* Bilan de l'opération */ - - debugger = G_BINARY_DEBUGGER(pygobject_get(self)); - assert(debugger != NULL); - - ret = PyArg_ParseTuple(args, "s", ®); - if (!ret) return NULL; - - status = g_binary_debugger_read_register_u32(debugger, reg, &value); - - if (status) - result = PyLong_FromUnsignedLongLong(value); - - else - { - result = Py_None; - Py_INCREF(result); - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = contenu binaire à manipuler. * -* args = arguments accompagnant l'appel. * -* * -* Description : Lit une valeur de 64 bits à partir d'un registre. * -* * -* Retour : Valeur lue ou None. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_debugger_read_register_u64(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - GBinaryDebugger *debugger; /* Version GLib du format */ - const char *reg; /* Nom du registre à manipuler */ - int ret; /* Bilan de lecture des args. */ - uint64_t value; /* Valeur lue en mémoire */ - bool status; /* Bilan de l'opération */ - - debugger = G_BINARY_DEBUGGER(pygobject_get(self)); - assert(debugger != NULL); - - ret = PyArg_ParseTuple(args, "s", ®); - if (!ret) return NULL; - - status = g_binary_debugger_read_register_u64(debugger, reg, &value); - - if (status) - result = PyLong_FromUnsignedLongLong(value); - - else - { - result = Py_None; - Py_INCREF(result); - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = contenu binaire à manipuler. * -* args = arguments accompagnant l'appel. * -* * -* Description : Ecrit une valeur de 8 bits dans un registre. * -* * -* Retour : Valeur lue ou None. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_debugger_write_register_u8(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - GBinaryDebugger *debugger; /* Version GLib du format */ - const char *reg; /* Nom du registre à manipuler */ - int ret; /* Bilan de lecture des args. */ - uint8_t value; /* Valeur lue en mémoire */ - bool status; /* Bilan de l'opération */ - - debugger = G_BINARY_DEBUGGER(pygobject_get(self)); - assert(debugger != NULL); - - ret = PyArg_ParseTuple(args, "sB", ®, &value); - if (!ret) return NULL; - - status = g_binary_debugger_write_register_u8(debugger, reg, &value); - - result = status ? Py_True : Py_False; - Py_INCREF(result); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = contenu binaire à manipuler. * -* args = arguments accompagnant l'appel. * -* * -* Description : Ecrit une valeur de 16 bits dans un registre. * -* * -* Retour : Valeur lue ou None. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_debugger_write_register_u16(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - GBinaryDebugger *debugger; /* Version GLib du format */ - const char *reg; /* Nom du registre à manipuler */ - int ret; /* Bilan de lecture des args. */ - uint16_t value; /* Valeur lue en mémoire */ - bool status; /* Bilan de l'opération */ - - debugger = G_BINARY_DEBUGGER(pygobject_get(self)); - assert(debugger != NULL); - - ret = PyArg_ParseTuple(args, "sH", ®, &value); - if (!ret) return NULL; - - status = g_binary_debugger_write_register_u16(debugger, reg, &value); - - result = status ? Py_True : Py_False; - Py_INCREF(result); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = contenu binaire à manipuler. * -* args = arguments accompagnant l'appel. * -* * -* Description : Ecrit une valeur de 32 bits dans un registre. * -* * -* Retour : Valeur lue ou None. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_debugger_write_register_u32(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - GBinaryDebugger *debugger; /* Version GLib du format */ - const char *reg; /* Nom du registre à manipuler */ - int ret; /* Bilan de lecture des args. */ - uint32_t value; /* Valeur lue en mémoire */ - bool status; /* Bilan de l'opération */ - - debugger = G_BINARY_DEBUGGER(pygobject_get(self)); - assert(debugger != NULL); - - ret = PyArg_ParseTuple(args, "sI", ®, &value); - if (!ret) return NULL; - - status = g_binary_debugger_write_register_u32(debugger, reg, &value); - - result = status ? Py_True : Py_False; - Py_INCREF(result); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = contenu binaire à manipuler. * -* args = arguments accompagnant l'appel. * -* * -* Description : Ecrit une valeur de 64 bits dans un registre. * -* * -* Retour : Valeur lue ou None. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_debugger_write_register_u64(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - GBinaryDebugger *debugger; /* Version GLib du format */ - const char *reg; /* Nom du registre à manipuler */ - int ret; /* Bilan de lecture des args. */ - uint64_t value; /* Valeur lue en mémoire */ - bool status; /* Bilan de l'opération */ - - debugger = G_BINARY_DEBUGGER(pygobject_get(self)); - assert(debugger != NULL); - - ret = PyArg_ParseTuple(args, "sK", ®, &value); - if (!ret) return NULL; - - status = g_binary_debugger_write_register_u64(debugger, reg, &value); - - result = status ? Py_True : Py_False; - Py_INCREF(result); - - return result; - -} - - - - - - - - -/****************************************************************************** -* * -* Paramètres : self = contenu binaire à manipuler. * -* args = arguments accompagnant l'appel. * -* * -* Description : Remonte la pile d'appels jusqu'au point courant. * -* * -* Retour : Pile d'appels sous forme de liste ou None en cas d'erreur. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_debugger_get_call_stack(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - GBinaryDebugger *debugger; /* Version GLib du format */ - virt_t *callstack; /* Pile d'appels obtenue */ - size_t size; /* Hauteur de cette pile */ - bool status; /* Bilan de l'opération */ - size_t i; /* Boucle de parcours */ - - debugger = G_BINARY_DEBUGGER(pygobject_get(self)); - assert(debugger != NULL); - - status = g_binary_debugger_get_call_stack(debugger, &callstack, &size); - - if (!status) - { - result = Py_None; - Py_INCREF(result); - } - - else - { - result = PyTuple_New(size); - - for (i = 0; i < size; i++) - PyTuple_SetItem(result, i, PyLong_FromUnsignedLongLong(callstack[i])); - - if (callstack != NULL) - free(callstack); - - } - - return result; - -} - - - - - - - - -/****************************************************************************** -* * -* Paramètres : self = contenu binaire à manipuler. * -* args = arguments accompagnant l'appel. * -* * -* Description : Ajoute un point d'arrêt basique en mémoire. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_debugger_add_mem_bp(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - GBinaryDebugger *debugger; /* Version GLib du format */ - vmpa2t addr; /* Position interne associée */ - int ret; /* Bilan de lecture des args. */ - bool status; /* Bilan de l'opération */ - - debugger = G_BINARY_DEBUGGER(pygobject_get(self)); - assert(debugger != NULL); - - ret = PyArg_ParseTuple(args, "O&", convert_any_to_vmpa, &addr); - if (!ret) return NULL; - - status = g_binary_debugger_add_memory_breakpoint(debugger, get_virt_addr(&addr)); - - result = status ? Py_True : Py_False; - Py_INCREF(result); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = contenu binaire à manipuler. * -* args = arguments accompagnant l'appel. * -* * -* Description : Retire un point d'arrêt basique en mémoire. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_debugger_delete_mem_bp(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - GBinaryDebugger *debugger; /* Version GLib du format */ - vmpa2t addr; /* Position interne associée */ - int ret; /* Bilan de lecture des args. */ - bool status; /* Bilan de l'opération */ - - debugger = G_BINARY_DEBUGGER(pygobject_get(self)); - assert(debugger != NULL); - - ret = PyArg_ParseTuple(args, "O&", convert_any_to_vmpa, &addr); - if (!ret) return NULL; - - status = g_binary_debugger_delete_memory_breakpoint(debugger, get_virt_addr(&addr)); - - result = status ? Py_True : Py_False; - Py_INCREF(result); - - return result; - -} - - - - - - - - -/****************************************************************************** -* * -* Paramètres : self = contenu binaire à manipuler. * -* args = arguments non utilisés ici. * -* * -* Description : Redémarre le processus de débogage. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_debugger_restart(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - GBinaryDebugger *debugger; /* Version GLib du format */ - bool status; /* Bilan de l'opération */ - - debugger = G_BINARY_DEBUGGER(pygobject_get(self)); - assert(debugger != NULL); - - status = g_binary_debugger_restart(debugger); - - result = status ? Py_True : Py_False; - Py_INCREF(result); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = contenu binaire à manipuler. * -* args = arguments non utilisés ici. * -* * -* Description : Remet en marche le débogueur courant. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_debugger_resume(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - GBinaryDebugger *debugger; /* Version GLib du format */ - bool status; /* Bilan de l'opération */ - - debugger = G_BINARY_DEBUGGER(pygobject_get(self)); - assert(debugger != NULL); - - status = g_binary_debugger_resume(debugger); - - result = status ? Py_True : Py_False; - Py_INCREF(result); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = contenu binaire à manipuler. * -* args = arguments non utilisés ici. * -* * -* Description : Relance l'exécution pour une seule instruction. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_debugger_stepi(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - GBinaryDebugger *debugger; /* Version GLib du format */ - bool status; /* Bilan de l'opération */ - - debugger = G_BINARY_DEBUGGER(pygobject_get(self)); - assert(debugger != NULL); - - status = g_binary_debugger_stepi(debugger, false); - - result = status ? Py_True : Py_False; - Py_INCREF(result); - - 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_binary_debugger_type(void) -{ - static PyMethodDef py_binary_debugger_methods[] = { - { - "list_all_threads", py_binary_debugger_list_all_threads, - METH_NOARGS, - "list_all_threads($self, /)\n--\n\nList all current active threads." - }, - { - "read_mem_u8", py_binary_debugger_read_memory_u8, - METH_VARARGS, - "read_mem_u8($self, addr, /)\n--\n\nRead a 8-bit value from a given address." - }, - { - "read_mem_u16", py_binary_debugger_read_memory_u16, - METH_VARARGS, - "read_mem_u16($self, addr, /)\n--\n\nRead a 16-bit value from a given address." - }, - { - "read_mem_u32", py_binary_debugger_read_memory_u32, - METH_VARARGS, - "read_mem_u32($self, addr, /)\n--\n\nRead a 32-bit value from a given address." - }, - { - "read_mem_u64", py_binary_debugger_read_memory_u64, - METH_VARARGS, - "read_mem_u64($self, addr, /)\n--\n\nRead a 64-bit value from a given address." - }, - { - "get_reg_names", py_binary_debugger_get_register_names, - METH_VARARGS, - "get_reg_names($self, [grp]/)\n--\n\nGet the names of all registers belonging to an optional group." - }, - { - "get_reg_size", py_binary_debugger_get_register_size, - METH_VARARGS, - "get_reg_size($self, name, /)\n--\n\nGet the size of a given register." - }, - { - "read_reg_u8", py_binary_debugger_read_register_u8, - METH_VARARGS, - "read_reg_u8($self, reg, /)\n--\n\nRead a 8-bit value from a named register." - }, - { - "read_reg_u16", py_binary_debugger_read_register_u16, - METH_VARARGS, - "read_reg_u16($self, reg, /)\n--\n\nRead a 16-bit value from a named register." - }, - { - "read_reg_u32", py_binary_debugger_read_register_u32, - METH_VARARGS, - "read_reg_u32($self, reg, /)\n--\n\nRead a 32-bit value from a named register." - }, - { - "read_reg_u64", py_binary_debugger_read_register_u64, - METH_VARARGS, - "read_reg_u64($self, reg, /)\n--\n\nRead a 64-bit value from a named register." - }, - { - "write_reg_u8", py_binary_debugger_write_register_u8, - METH_VARARGS, - "write_reg_u8($self, reg, val, /)\n--\n\nWrite a 8-bit value into a named register." - }, - { - "write_reg_u16", py_binary_debugger_write_register_u16, - METH_VARARGS, - "write_reg_u16($self, reg, val, /)\n--\n\nWrite a 16-bit value into a named register." - }, - { - "write_reg_u32", py_binary_debugger_write_register_u32, - METH_VARARGS, - "write_reg_u32($self, reg, val, /)\n--\n\nWrite a 32-bit value into a named register." - }, - { - "write_reg_u64", py_binary_debugger_write_register_u64, - METH_VARARGS, - "write_reg_u64($self, reg, val, /)\n--\n\nWrite a 64-bit value into a named register." - }, - { - "get_call_stack", py_binary_debugger_get_call_stack, - METH_NOARGS, - "get_call_stack($self, /)\n--\n\nGet the current call stack." - }, - { - "add_mem_bp", py_binary_debugger_add_mem_bp, - METH_VARARGS, - "add_mem_bp($self, addr, /)\n--\n\nInsert a memory breakpoint at a given address." - }, - { - "delete_mem_bp", py_binary_debugger_delete_mem_bp, - METH_VARARGS, - "delete_mem_bp($self, addr, /)\n--\n\nRemove a memory breakpoint at a given address." - }, - { - "restart", py_binary_debugger_restart, - METH_NOARGS, - "restart($self, /)\n--\n\nRestart the current debugging session." - }, - { - "resume", py_binary_debugger_resume, - METH_NOARGS, - "resume($self, /)\n--\n\nResume the current debugging session." - }, - { - "stepi", py_binary_debugger_stepi, - METH_NOARGS, - "stepi($self, /)\n--\n\nExecute one machine instruction, then stop and return to the debugger." - }, - { NULL } - }; - - static PyGetSetDef py_binary_debugger_getseters[] = { - { NULL } - }; - - static PyTypeObject py_binary_debugger_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.analysis.BinaryDebugger", - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyChrysalide loaded binary", - - .tp_methods = py_binary_debugger_methods, - .tp_getset = py_binary_debugger_getseters - - }; - - return &py_binary_debugger_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.....BinaryDebugger'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_binary_debugger(PyObject *module) -{ - PyTypeObject *py_binary_debugger_type; /* Type Python 'BinaryDebugger'*/ - PyObject *dict; /* Dictionnaire du module */ - - py_binary_debugger_type = get_python_binary_debugger_type(); - - dict = PyModule_GetDict(module); - - if (!register_class_for_pygobject(dict, G_TYPE_BINARY_DEBUGGER, py_binary_debugger_type, &PyGObject_Type)) - return false; - - return true; - -} diff --git a/plugins/pychrysa/debug/debugger.h b/plugins/pychrysa/debug/debugger.h deleted file mode 100644 index 97f91ac..0000000 --- a/plugins/pychrysa/debug/debugger.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * debugger.h - prototypes pour les instances Python de débogueurs - * - * Copyright (C) 2012-2017 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_DEBUG_DEBUGGER_H -#define _PLUGINS_PYCHRYSALIDE_DEBUG_DEBUGGER_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_binary_debugger_type(void); - -/* Prend en charge l'objet 'pychrysalide.debug.BinaryDebugger'. */ -bool register_python_binary_debugger(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSALIDE_DEBUG_DEBUGGER_H */ diff --git a/plugins/pychrysa/debug/gdbrsp/Makefile.am b/plugins/pychrysa/debug/gdbrsp/Makefile.am deleted file mode 100644 index cf7b78a..0000000 --- a/plugins/pychrysa/debug/gdbrsp/Makefile.am +++ /dev/null @@ -1,15 +0,0 @@ - -noinst_LTLIBRARIES = libpychrysadebuggdbrsp.la - -libpychrysadebuggdbrsp_la_SOURCES = \ - gdb.h gdb.c \ - module.h module.c - - -libpychrysadebuggdbrsp_la_LDFLAGS = - - -AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ - -I../../../../src - -AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) diff --git a/plugins/pychrysa/debug/gdbrsp/gdb.c b/plugins/pychrysa/debug/gdbrsp/gdb.c deleted file mode 100644 index a4cde20..0000000 --- a/plugins/pychrysa/debug/gdbrsp/gdb.c +++ /dev/null @@ -1,166 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * gdb.c - équivalent Python du fichier "debug/gdbrsp/gdb.c" - * - * Copyright (C) 2016 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 "gdb.h" - - -#include - - -#include - - -#include - - -#include "../debugger.h" -#include "../../helpers.h" -#include "../../analysis/binary.h" - - - -/* Crée un nouvel objet Python de type 'GdbDebugger'. */ -static PyObject *py_gdb_debugger_new(PyTypeObject *, PyObject *, PyObject *); - - - -/****************************************************************************** -* * -* Paramètres : type = type de l'objet à instancier. * -* args = arguments fournis à l'appel. * -* kwds = arguments de type key=val fournis. * -* * -* Description : Crée un nouvel objet Python de type 'GdbDebugger'. * -* * -* Retour : Instance Python mise en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_gdb_debugger_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - PyObject *result; /* Instance à retourner */ - PyObject *binary_obj; /* Objet pour le binaire lié */ - const char *server; /* Nom du serveur à contacter */ - unsigned short port; /* Port de connexion */ - int ret; /* Bilan de lecture des args. */ - GLoadedBinary *binary; /* Binaire chargé en mémoire */ - GBinaryDebugger *debugger; /* Création GLib à transmettre */ - - ret = PyArg_ParseTuple(args, "OsH", &binary_obj, &server, &port); - if (!ret) return NULL; - - ret = PyObject_IsInstance(binary_obj, (PyObject *)get_python_loaded_binary_type()); - if (!ret) - { - PyErr_SetString(PyExc_TypeError, _("The first argument must be an instance of LoadedBinary.")); - return NULL; - } - - binary = G_LOADED_BINARY(pygobject_get(binary_obj)); - - debugger = g_gdb_debugger_new(binary, server, port); - - result = pygobject_new(G_OBJECT(debugger)); - - g_object_unref(debugger); - - return (PyObject *)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_gdb_debugger_type(void) -{ - static PyMethodDef py_gdb_debugger_methods[] = { - { NULL } - }; - - static PyGetSetDef py_gdb_debugger_getseters[] = { - { NULL } - }; - - static PyTypeObject py_gdb_debugger_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.debug.gdbrsp.GdbDebugger", - .tp_basicsize = sizeof(PyGObject), - - .tp_flags = Py_TPFLAGS_DEFAULT, - - .tp_doc = "PyChrysalide GDB debugger", - - .tp_methods = py_gdb_debugger_methods, - .tp_getset = py_gdb_debugger_getseters, - .tp_new = (newfunc)py_gdb_debugger_new - - }; - - return &py_gdb_debugger_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide....gdbrsp.GdbDebugger'.* -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_gdb_debugger(PyObject *module) -{ - PyTypeObject *py_gdb_debugger_type; /* Type Python 'GdbDebugger' */ - PyObject *dict; /* Dictionnaire du module */ - - py_gdb_debugger_type = get_python_gdb_debugger_type(); - - dict = PyModule_GetDict(module); - - if (!register_class_for_pygobject(dict, G_TYPE_GDB_DEBUGGER, - py_gdb_debugger_type, get_python_binary_debugger_type())) - return false; - - return true; - -} diff --git a/plugins/pychrysa/debug/gdbrsp/gdb.h b/plugins/pychrysa/debug/gdbrsp/gdb.h deleted file mode 100644 index c3d1330..0000000 --- a/plugins/pychrysa/debug/gdbrsp/gdb.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * gdb.h - prototypes pour l'équivalent Python du fichier "debug/gdbrsp/gdb.h" - * - * Copyright (C) 2016 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_PYCHRYSA_DEBUG_GDBRSP_DEBUGGER_H -#define _PLUGINS_PYCHRYSA_DEBUG_GDBRSP_DEBUGGER_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_gdb_debugger_type(void); - -/* Prend en charge l'objet 'pychrysalide.debug.gdbrsp.GdbDebugger'. */ -bool register_python_gdb_debugger(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSA_DEBUG_GDBRSP_DEBUGGER_H */ diff --git a/plugins/pychrysa/debug/gdbrsp/module.c b/plugins/pychrysa/debug/gdbrsp/module.c deleted file mode 100644 index 6e7896c..0000000 --- a/plugins/pychrysa/debug/gdbrsp/module.c +++ /dev/null @@ -1,86 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * module.c - intégration du répertoire gdbrsp en tant que module - * - * Copyright (C) 2012 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 "module.h" - - -#include "gdb.h" - - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute le module 'debug.gdbrsp' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool add_debug_gdbrsp_module_to_python_module(PyObject *super) -{ - bool result; /* Bilan à retourner */ - PyObject *module; /* Sous-module mis en place */ - int ret; /* Bilan d'un appel */ - - static PyModuleDef py_chrysalide_gdbrsp_module = { - - .m_base = PyModuleDef_HEAD_INIT, - - .m_name = "pychrysalide.debug.gdbrsp", - .m_doc = "Python module for Chrysalide.debug.gdbrsp", - - .m_size = -1, - - }; - - result = false; - - module = PyModule_Create(&py_chrysalide_gdbrsp_module); - if (module == NULL) return false; - - ret = PyState_AddModule(super, &py_chrysalide_gdbrsp_module); - if (ret != 0) goto loading_failed; - - ret = _PyImport_FixupBuiltin(module, "pychrysalide.debug.gdbrsp"); - if (ret != 0) goto loading_failed; - - Py_INCREF(module); - ret = PyModule_AddObject(super, "gdbrsp", module); - if (ret != 0) goto loading_failed; - - result = true; - - result &= register_python_gdb_debugger(module); - - loading_failed: - - assert(result); - - return result; - -} diff --git a/plugins/pychrysa/debug/gdbrsp/module.h b/plugins/pychrysa/debug/gdbrsp/module.h deleted file mode 100644 index 78e62b0..0000000 --- a/plugins/pychrysa/debug/gdbrsp/module.h +++ /dev/null @@ -1,39 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * module.h - prototypes pour l'intégration du répertoire gdbrsp en tant que module - * - * Copyright (C) 2012-2016 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_PYCHRYSA_DEBUG_GDBRSP_MODULE_H -#define _PLUGINS_PYCHRYSA_DEBUG_GDBRSP_MODULE_H - - -#include -#include - - - -/* Ajoute le module 'debug.gdbrsp' au module Python. */ -bool add_debug_gdbrsp_module_to_python_module(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSA_DEBUG_GDBRSP_MODULE_H */ diff --git a/plugins/pychrysa/debug/module.c b/plugins/pychrysa/debug/module.c deleted file mode 100644 index ea586be..0000000 --- a/plugins/pychrysa/debug/module.c +++ /dev/null @@ -1,93 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * module.c - intégration du répertoire debug en tant que module - * - * Copyright (C) 2012-2017 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 "module.h" - - -#include "debugger.h" -#include "gdbrsp/module.h" -#include "../access.h" - - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute le module 'debug' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool add_debug_module_to_python_module(PyObject *super) -{ - bool result; /* Bilan à retourner */ - PyObject *module; /* Sous-module mis en place */ - int ret; /* Bilan d'un appel */ - - static PyModuleDef py_chrysalide_debug_module = { - - .m_base = PyModuleDef_HEAD_INIT, - - .m_name = "pychrysalide.debug", - .m_doc = "Python module for Chrysalide.debug", - - .m_size = -1, - - }; - - result = false; - - module = PyModule_Create(&py_chrysalide_debug_module); - if (module == NULL) return false; - - ret = PyState_AddModule(super, &py_chrysalide_debug_module); - if (ret != 0) goto loading_failed; - - ret = _PyImport_FixupBuiltin(module, "pychrysalide.debug"); - if (ret != 0) goto loading_failed; - - Py_INCREF(module); - ret = PyModule_AddObject(super, "debug", module); - if (ret != 0) goto loading_failed; - - result = true; - - result &= register_python_binary_debugger(module); - - result &= add_debug_gdbrsp_module_to_python_module(module); - - if (result) - register_access_to_python_module("pychrysalide.debug", module); - - loading_failed: - - assert(result); - - return result; - -} diff --git a/plugins/pychrysa/debug/module.h b/plugins/pychrysa/debug/module.h deleted file mode 100644 index bbd1971..0000000 --- a/plugins/pychrysa/debug/module.h +++ /dev/null @@ -1,39 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * module.h - prototypes pour l'intégration du répertoire debug en tant que module - * - * Copyright (C) 2012-2017 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_PYCHRYSA_DEBUG_MODULE_H -#define _PLUGINS_PYCHRYSA_DEBUG_MODULE_H - - -#include -#include - - - -/* Ajoute le module 'debug' au module Python. */ -bool add_debug_module_to_python_module(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSA_DEBUG_MODULE_H */ diff --git a/plugins/pychrysa/format/Makefile.am b/plugins/pychrysa/format/Makefile.am deleted file mode 100644 index 325206c..0000000 --- a/plugins/pychrysa/format/Makefile.am +++ /dev/null @@ -1,21 +0,0 @@ - -noinst_LTLIBRARIES = libpychrysaformat.la - -libpychrysaformat_la_SOURCES = \ - executable.h executable.c \ - format.h format.c \ - module.h module.c \ - symbol.h symbol.c \ - symiter.h symiter.c - -libpychrysaformat_la_LIBADD = - -libpychrysaformat_la_LDFLAGS = - - -AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ - -I../../../src - -AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) - -SUBDIRS = diff --git a/plugins/pychrysa/format/executable.c b/plugins/pychrysa/format/executable.c deleted file mode 100644 index 1b1bfe8..0000000 --- a/plugins/pychrysa/format/executable.c +++ /dev/null @@ -1,215 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * executable.c - équivalent Python du fichier "format/executable.h" - * - * Copyright (C) 2012-2017 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 "executable.h" - - -#include - - -#include - - -#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 : - * -* * -* Description : Fournit un accès à une définition de type à diffuser. * -* * -* Retour : Définition d'objet pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -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 } - }; - - static PyGetSetDef py_exe_format_getseters[] = { - { NULL } - }; - - static PyTypeObject py_exe_format_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.format.ExeFormat", - .tp_basicsize = sizeof(PyGObject), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyChrysalide executable format", - - .tp_methods = py_exe_format_methods, - .tp_getset = py_exe_format_getseters, - - }; - - return &py_exe_format_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.format.ExeFormat'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_executable_format(PyObject *module) -{ - PyTypeObject *py_exe_format_type; /* Type Python 'ExeFormat' */ - PyObject *dict; /* Dictionnaire du module */ - - py_exe_format_type = get_python_executable_format_type(); - - dict = PyModule_GetDict(module); - - if (!register_class_for_pygobject(dict, G_TYPE_EXE_FORMAT, py_exe_format_type, get_python_binary_format_type())) - return false; - - return true; - -} diff --git a/plugins/pychrysa/format/executable.h b/plugins/pychrysa/format/executable.h deleted file mode 100644 index cfb633f..0000000 --- a/plugins/pychrysa/format/executable.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * executable.h - prototypes pour l'équivalent Python du fichier "format/executable.h" - * - * Copyright (C) 2012-2017 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_PYCHRYSA_FORMAT_EXECUTABLE_H -#define _PLUGINS_PYCHRYSA_FORMAT_EXECUTABLE_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_executable_format_type(void); - -/* Prend en charge l'objet 'pychrysalide.format.ExeFormat'. */ -bool register_python_executable_format(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSA_FORMAT_EXECUTABLE_H */ diff --git a/plugins/pychrysa/format/format.c b/plugins/pychrysa/format/format.c deleted file mode 100644 index 3bfc705..0000000 --- a/plugins/pychrysa/format/format.c +++ /dev/null @@ -1,680 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * format.c - équivalent Python du fichier "format/format.c" - * - * Copyright (C) 2012-2017 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 "format.h" - - -#include - - -#include - - -#include "symbol.h" -#include "symiter.h" -#include "../helpers.h" -#include "../arch/vmpa.h" - - - -/* ---------------------------- FORMAT BINAIRE GENERIQUE ---------------------------- */ - - - -/* Ajoute un symbole à la collection du format binaire. */ -static PyObject *py_binary_format_add_symbol(PyObject *, PyObject *); - -/* Retire un symbole de la collection du format binaire. */ -static PyObject *py_binary_format_remove_symbol(PyObject *, PyObject *); - -/* Recherche le symbole correspondant à une étiquette. */ -static PyObject *py_binary_format_find_symbol_by_label(PyObject *, PyObject *); - -/* Recherche le symbole suivant celui lié à une adresse. */ -static PyObject *py_binary_format_find_symbol_at(PyObject *, PyObject *); - -/* Recherche le symbole suivant celui lié à une adresse. */ -static PyObject *py_binary_format_find_next_symbol_at(PyObject *, PyObject *); - -/* Recherche le symbole correspondant à une adresse. */ -static PyObject *py_binary_format_resolve_symbol(PyObject *, PyObject *); - -/* Fournit une référence vers le contenu binaire analysé. */ -static PyObject *py_binary_format_get_content(PyObject *, void *); - -/* Fournit la liste de tous les symboles détectés. */ -static PyObject *py_binary_format_get_symbols(PyObject *, void *); - - - -/* ------------------ CONSERVATION DES SOUCIS DURANT LE CHARGEMENT ------------------ */ - - -/* Etend la liste des soucis détectés avec de nouvelles infos. */ -static PyObject *py_binary_format_add_error(PyObject *, PyObject *); - -/* Fournit les éléments concernant tous les soucis détectés. */ -static PyObject *py_binary_format_get_errors(PyObject *, void *); - - - - - - -/* Définit les constantes pour les types d'erreurs. */ -static bool define_python_binary_format_constants(PyTypeObject *); - - - -/* ---------------------------------------------------------------------------------- */ -/* FORMAT BINAIRE GENERIQUE */ -/* ---------------------------------------------------------------------------------- */ - - - - - -/****************************************************************************** -* * -* Paramètres : self = classe représentant un format. * -* args = arguments fournis à l'appel. * -* * -* Description : Ajoute un symbole à la collection du format binaire. * -* * -* Retour : True si le symbole était bien localisé et a été inséré. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_format_add_symbol(PyObject *self, PyObject *args) -{ - PyObject *result; /* Valeur à retourner */ - PyObject *symbol_obj; /* Version Python d'un symbole */ - int ret; /* Bilan de lecture des args. */ - GBinFormat *format; /* Format de binaire manipulé */ - GBinSymbol *symbol; /* Enventuel symbole trouvé */ - bool added; /* Bilan de l'appel interne */ - - ret = PyArg_ParseTuple(args, "O!", get_python_binary_symbol_type(), &symbol_obj); - if (!ret) return NULL; - - format = G_BIN_FORMAT(pygobject_get(self)); - symbol = G_BIN_SYMBOL(pygobject_get(symbol_obj)); - - added = g_binary_format_add_symbol(format, symbol); - - result = added ? Py_True : Py_False; - Py_INCREF(result); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = classe représentant un format. * -* args = arguments fournis à l'appel. * -* * -* Description : Retire un symbole de la collection du format binaire. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_format_remove_symbol(PyObject *self, PyObject *args) -{ - PyObject *result; /* Valeur à retourner */ - PyObject *symbol_obj; /* Version Python d'un symbole */ - int ret; /* Bilan de lecture des args. */ - GBinFormat *format; /* Format de binaire manipulé */ - GBinSymbol *symbol; /* Enventuel symbole trouvé */ - - ret = PyArg_ParseTuple(args, "O!", get_python_binary_symbol_type(), &symbol_obj); - if (!ret) return NULL; - - format = G_BIN_FORMAT(pygobject_get(self)); - symbol = G_BIN_SYMBOL(pygobject_get(symbol_obj)); - - g_binary_format_remove_symbol(format, symbol); - - result = Py_None; - Py_INCREF(result); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = classe représentant un binaire. * -* args = arguments fournis à l'appel. * -* * -* Description : Recherche le symbole correspondant à une étiquette. * -* * -* Retour : Symbol trouvé si l'opération a été un succès, None sinon. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_format_find_symbol_by_label(PyObject *self, PyObject *args) -{ - PyObject *result; /* Valeur à retourner */ - PyObject *label; /* Etiquette à retrouver */ - int ret; /* Bilan de lecture des args. */ - GBinFormat *format; /* Format de binaire manipulé */ - GBinSymbol *symbol; /* Enventuel symbole trouvé */ - bool found; /* Bilan de la recherche */ - - ret = PyArg_ParseTuple(args, "O", &label); - if (!ret) return NULL; - - ret = PyUnicode_Check(label); - if (!ret) return NULL; - - format = G_BIN_FORMAT(pygobject_get(self)); - - found = g_binary_format_find_symbol_by_label(format, PyUnicode_DATA(label), &symbol); - - if (found) - result = pygobject_new(G_OBJECT(symbol)); - else - { - result = Py_None; - Py_INCREF(result); - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = classe représentant un binaire. * -* args = arguments fournis à l'appel. * -* * -* Description : Recherche le symbole suivant celui lié à une adresse. * -* * -* Retour : Symbol trouvé si l'opération a été un succès, None sinon. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_format_find_symbol_at(PyObject *self, PyObject *args) -{ - PyObject *result; /* Valeur à retourner */ - PyObject *py_vmpa; /* Localisation version Python */ - int ret; /* Bilan de lecture des args. */ - GBinFormat *format; /* Format de binaire manipulé */ - GBinSymbol *symbol; /* Enventuel symbole trouvé */ - bool found; /* Bilan de la recherche */ - - ret = PyArg_ParseTuple(args, "O", &py_vmpa); - if (!ret) return NULL; - - ret = PyObject_IsInstance(py_vmpa, (PyObject *)get_python_vmpa_type()); - if (!ret) return NULL; - - format = G_BIN_FORMAT(pygobject_get(self)); - - found = g_binary_format_find_symbol_at(format, get_internal_vmpa(py_vmpa), &symbol); - - if (found) - { - result = pygobject_new(G_OBJECT(symbol)); - g_object_unref(G_OBJECT(symbol)); - } - else - { - result = Py_None; - Py_INCREF(result); - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = classe représentant un binaire. * -* args = arguments fournis à l'appel. * -* * -* Description : Recherche le symbole suivant celui lié à une adresse. * -* * -* Retour : Symbol trouvé si l'opération a été un succès, None sinon. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_format_find_next_symbol_at(PyObject *self, PyObject *args) -{ - PyObject *result; /* Valeur à retourner */ - PyObject *py_vmpa; /* Localisation version Python */ - int ret; /* Bilan de lecture des args. */ - GBinFormat *format; /* Format de binaire manipulé */ - GBinSymbol *symbol; /* Enventuel symbole trouvé */ - bool found; /* Bilan de la recherche */ - - ret = PyArg_ParseTuple(args, "O", &py_vmpa); - if (!ret) return NULL; - - ret = PyObject_IsInstance(py_vmpa, (PyObject *)get_python_vmpa_type()); - if (!ret) return NULL; - - format = G_BIN_FORMAT(pygobject_get(self)); - - found = g_binary_format_find_next_symbol_at(format, get_internal_vmpa(py_vmpa), &symbol); - - if (found) - { - result = pygobject_new(G_OBJECT(symbol)); - g_object_unref(G_OBJECT(symbol)); - } - else - { - result = Py_None; - Py_INCREF(result); - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = classe représentant un format binaire. * -* args = arguments fournis à l'appel. * -* * -* Description : Recherche le symbole correspondant à une adresse. * -* * -* Retour : Tuple (nom, décallage) ou Py_None. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_format_resolve_symbol(PyObject *self, PyObject *args) -{ - PyObject *result; /* Valeur à retourner */ - PyObject *py_vmpa; /* Localisation version Python */ - int strict; /* Tolérance acceptée */ - int ret; /* Bilan de lecture des args. */ - GBinFormat *format; /* Format de binaire manipulé */ - GBinSymbol *symbol; /* Enventuel symbole trouvé */ - phys_t diff; /* Décallage éventuel mesuré */ - bool found; /* Bilan de la recherche */ - - ret = PyArg_ParseTuple(args, "Op", &py_vmpa, &strict); - if (!ret) return NULL; - - ret = PyObject_IsInstance(py_vmpa, (PyObject *)get_python_vmpa_type()); - if (!ret) return NULL; - - format = G_BIN_FORMAT(pygobject_get(self)); - - found = g_binary_format_resolve_symbol(format, get_internal_vmpa(py_vmpa), strict, &symbol, &diff); - - if (found) - { - result = PyTuple_New(2); - PyTuple_SetItem(result, 0, pygobject_new(G_OBJECT(symbol))); - PyTuple_SetItem(result, 1, PyLong_FromUnsignedLongLong(diff)); - - g_object_unref(G_OBJECT(symbol)); - - } - else - { - result = Py_None; - Py_INCREF(result); - } - - 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_binary_format_get_content(PyObject *self, void *closure) -{ - PyObject *result; /* Trouvailles à retourner */ - GBinFormat *format; /* Format de binaire manipulé */ - GBinContent *content; /* Instance GLib correspondante*/ - - format = G_BIN_FORMAT(pygobject_get(self)); - - content = g_binary_format_get_content(format); - - result = pygobject_new(G_OBJECT(content)); - - g_object_unref(content); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = classe représentant un format binaire. * -* closure = adresse non utilisée ici. * -* * -* Description : Fournit la liste de tous les symboles détectés. * -* * -* Retour : Tableau créé ou NULL si aucun symbole trouvé. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_format_get_symbols(PyObject *self, void *closure) -{ - PyObject *result; /* Instance Python à retourner */ - PyTypeObject *iterator_type; /* Type Python de l'itérateur */ - PyObject *args; /* Liste des arguments d'appel */ - - iterator_type = get_python_sym_iterator_type(); - - args = Py_BuildValue("On", self, 0); - - result = PyObject_CallObject((PyObject *)iterator_type, args); - - Py_DECREF(args); - - return result; - -} - - - -/* ---------------------------------------------------------------------------------- */ -/* CONSERVATION DES SOUCIS DURANT LE CHARGEMENT */ -/* ---------------------------------------------------------------------------------- */ - - -/****************************************************************************** -* * -* Paramètres : self = architecture concernée par la procédure. * -* args = instruction représentant le point de départ. * -* * -* Description : Etend la liste des soucis détectés avec de nouvelles infos. * -* * -* Retour : None. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_format_add_error(PyObject *self, PyObject *args) -{ - BinaryFormatError type; /* Type d'erreur détectée */ - vmpa2t addr; /* Position d'une erreur */ - const char *desc; /* Description d'une erreur */ - int ret; /* Bilan de lecture des args. */ - GBinFormat *format; /* Format binaire manipulé */ - - ret = PyArg_ParseTuple(args, "IO&s", &type, convert_any_to_vmpa, &addr, &desc); - if (!ret) return NULL; - - format = G_BIN_FORMAT(pygobject_get(self)); - - g_binary_format_add_error(format, type, &addr, desc); - - Py_RETURN_NONE; - -} - - -/****************************************************************************** -* * -* Paramètres : self = objet Python concerné par l'appel. * -* closure = non utilisé ici. * -* * -* Description : Fournit les éléments concernant tous les soucis détectés. * -* * -* Retour : Liste des erreurs relevées au niveau de l'assembleur. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_format_get_errors(PyObject *self, void *closure) -{ - PyObject *result; /* Instance Python à retourner */ - GBinFormat *format; /* Format binaire manipulé */ - size_t count; /* Nombre d'éléments à traiter */ - size_t i; /* Boucle de parcours */ -#ifndef NDEBUG - bool status; /* Bilan d'un appel */ -#endif - BinaryFormatError type; /* Type d'erreur détectée */ - vmpa2t addr; /* Position d'une erreur */ - char *desc; /* Description d'une erreur */ - PyObject *error; /* Nouvelle erreur à rajouter */ - - format = G_BIN_FORMAT(pygobject_get(self)); - - g_binary_format_lock_errors(format); - - count = g_binary_format_count_errors(format); - - result = PyTuple_New(count); - - for (i = 0; i < count; i++) - { -#ifndef NDEBUG - status = g_binary_format_get_error(format, i, &type, &addr, &desc); - assert(status); -#else - g_binary_format_get_error(format, i, &type, &addr, &desc); -#endif - - error = Py_BuildValue("IO&s", type, build_from_internal_vmpa, &addr, desc); - - PyTuple_SetItem(result, i, error); - - } - - g_binary_format_unlock_errors(format); - - return result; - -} - - - - - - - -/****************************************************************************** -* * -* Paramètres : obj_type = type dont le dictionnaire est à compléter. * -* * -* Description : Définit les constantes pour les types d'erreurs. * -* * -* Retour : true en cas de succès de l'opération, false sinon. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool define_python_binary_format_constants(PyTypeObject *obj_type) -{ - bool result; /* Bilan à retourner */ - - result = true; - - result &= PyDict_AddIntMacro(obj_type, BFE_SPECIFICATION); - result &= PyDict_AddIntMacro(obj_type, BFE_STRUCTURE); - - 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_binary_format_type(void) -{ - static PyMethodDef py_bin_format_methods[] = { - { - "add_symbol", py_binary_format_add_symbol, - METH_VARARGS, - "add_symbol($self, symbol, /)\n--\n\nRegister a new symbol for the format." - }, - { - "remove_symbol", py_binary_format_remove_symbol, - METH_VARARGS, - "remove_symbol($self, symbol, /)\n--\n\nUnregister a symbol from the format." - }, - { - "find_symbol_by_label", py_binary_format_find_symbol_by_label, - METH_VARARGS, - "find_symbol_by_label($self, label, /)\n--\n\nFind a symbol by its label." - }, - { - "find_symbol_at", py_binary_format_find_symbol_at, - METH_VARARGS, - "find_symbol_at($self, addr, /)\n--\n\nFind a symbol at a given address." - }, - { - "find_next_symbol_at", py_binary_format_find_next_symbol_at, - METH_VARARGS, - "find_next_symbol_at($self, addr, /)\n--\n\nFind the symbol next to the one found at a given address." - }, - { - "resolve_symbol", py_binary_format_resolve_symbol, - METH_VARARGS, - "resolve_symbol($self, addr, strict, /)\n--\n\nSearch a position inside a routine by a given address." - }, - { - "add_error", py_binary_format_add_error, - METH_VARARGS, - "add_error($self, type, addr, desc, /)\n--\n\nExtend the list of detected disassembling errors." - }, - { NULL } - }; - - static PyGetSetDef py_bin_format_getseters[] = { - { - "content", py_binary_format_get_content, NULL, - "Content of the binary format.", NULL - }, - { - "symbols", py_binary_format_get_symbols, NULL, - "Iterable list of all symbols found in the binary format.", NULL - }, - { - "errors", py_binary_format_get_errors, NULL, - "List of all detected errors which occurred while loading the binary.", NULL - }, - { NULL } - }; - - static PyTypeObject py_bin_format_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.format.BinFormat", - .tp_basicsize = sizeof(PyGObject), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyChrysalide binary format", - - .tp_methods = py_bin_format_methods, - .tp_getset = py_bin_format_getseters - - }; - - return &py_bin_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 register_python_binary_format(PyObject *module) -{ - PyTypeObject *py_bin_format_type; /* Type Python 'BinFormat' */ - PyObject *dict; /* Dictionnaire du module */ - - py_bin_format_type = get_python_binary_format_type(); - - APPLY_ABSTRACT_FLAG(py_bin_format_type); - - dict = PyModule_GetDict(module); - - if (!register_class_for_pygobject(dict, G_TYPE_BIN_FORMAT, py_bin_format_type, &PyGObject_Type)) - return false; - - if (!define_python_binary_format_constants(py_bin_format_type)) - return false; - - return true; - -} diff --git a/plugins/pychrysa/format/format.h b/plugins/pychrysa/format/format.h deleted file mode 100644 index 08f9e6b..0000000 --- a/plugins/pychrysa/format/format.h +++ /dev/null @@ -1,56 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * format.h - prototypes pour l'équivalent Python du fichier "format/format.h" - * - * Copyright (C) 2012-2017 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_PYCHRYSA_FORMAT_FORMAT_H -#define _PLUGINS_PYCHRYSA_FORMAT_FORMAT_H - - -#include -#include - - - -/* ------------------------ PARCOURS DE SYMBOLES DE BINAIRES ------------------------ */ - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_binary_symbol_iterator_type(void); - -/* Prend en charge l'objet 'pychrysalide...BinSymbolIterator'. */ -bool register_python_binary_symbol_iterator(PyObject *); - - - -/* ---------------------------- FORMAT BINAIRE GENERIQUE ---------------------------- */ - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_binary_format_type(void); - -/* Prend en charge l'objet 'pychrysalide.format.BinFormat'. */ -bool register_python_binary_format(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSA_FORMAT_FORMAT_H */ diff --git a/plugins/pychrysa/format/module.c b/plugins/pychrysa/format/module.c deleted file mode 100644 index 1daeb3f..0000000 --- a/plugins/pychrysa/format/module.c +++ /dev/null @@ -1,99 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * module.c - intégration du répertoire format en tant que module - * - * Copyright (C) 2012-2017 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 "module.h" - - -#include - - -#include "executable.h" -#include "format.h" -#include "symbol.h" -#include "symiter.h" -#include "../access.h" - - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute le module 'format' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool add_format_module_to_python_module(PyObject *super) -{ - bool result; /* Bilan à retourner */ - PyObject *module; /* Sous-module mis en place */ - int ret; /* Bilan d'un appel */ - - static PyModuleDef py_chrysalide_format_module = { - - .m_base = PyModuleDef_HEAD_INIT, - - .m_name = "pychrysalide.format", - .m_doc = "Python module for Chrysalide.format", - - .m_size = -1, - - }; - - result = false; - - module = PyModule_Create(&py_chrysalide_format_module); - if (module == NULL) return false; - - ret = PyState_AddModule(super, &py_chrysalide_format_module); - if (ret != 0) goto loading_failed; - - ret = _PyImport_FixupBuiltin(module, "pychrysalide.format"); - if (ret != 0) goto loading_failed; - - Py_INCREF(module); - ret = PyModule_AddObject(super, "format", module); - if (ret != 0) goto loading_failed; - - result = true; - - result &= register_python_binary_format(module); - result &= register_python_executable_format(module); - result &= register_python_binary_symbol(module); - result &= register_python_sym_iterator(module); - - if (result) - register_access_to_python_module("pychrysalide.format", module); - - loading_failed: - - assert(result); - - return result; - -} diff --git a/plugins/pychrysa/format/module.h b/plugins/pychrysa/format/module.h deleted file mode 100644 index 0557722..0000000 --- a/plugins/pychrysa/format/module.h +++ /dev/null @@ -1,39 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * module.h - prototypes pour l'intégration du répertoire format en tant que module - * - * Copyright (C) 2012-2017 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_PYOIDA_FORMAT_MODULE_H -#define _PLUGINS_PYOIDA_FORMAT_MODULE_H - - -#include -#include - - - -/* Ajoute le module 'format' au module Python. */ -bool add_format_module_to_python_module(PyObject *); - - - -#endif /* _PLUGINS_PYOIDA_FORMAT_MODULE_H */ diff --git a/plugins/pychrysa/format/symbol.c b/plugins/pychrysa/format/symbol.c deleted file mode 100644 index 5ddaca2..0000000 --- a/plugins/pychrysa/format/symbol.c +++ /dev/null @@ -1,446 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * symbol.c - équivalent Python du fichier "format/symbol.h" - * - * Copyright (C) 2015-2017 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 "symbol.h" - - -#include - - -#include - - -#include - - -#include "../helpers.h" -#include "../analysis/routine.h" -#include "../analysis/db/items/comment.h" -#include "../arch/instruction.h" -#include "../arch/vmpa.h" - - - -/* 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 *); - -/* Fournit l'emplacement où se situe un symbole. */ -static PyObject *py_binary_symbol_get_range(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 *); - - - -/****************************************************************************** -* * -* Paramètres : a = premier object Python à consulter. * -* b = second object Python à consulter. * -* op = type de comparaison menée. * -* * -* Description : Effectue une comparaison avec un objet Python 'BinSymbol'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_symbol_richcompare(PyObject *a, PyObject *b, int op) -{ - PyObject *result; /* Bilan à retourner */ - int ret; /* Bilan de lecture des args. */ - const GBinSymbol *sym_a; /* Premier élément à traiter */ - const GBinSymbol *sym_b; /* Second élément à traiter */ - int status; /* Résultat d'une comparaison */ - - ret = PyObject_IsInstance(b, (PyObject *)get_python_binary_symbol_type()); - if (!ret) - { - result = Py_NotImplemented; - goto cmp_done; - } - - sym_a = G_BIN_SYMBOL(pygobject_get(a)); - sym_a = G_BIN_SYMBOL(pygobject_get(b)); - - status = g_binary_symbol_cmp(&sym_a, &sym_b); - - result = status_to_rich_cmp_state(status, op); - - cmp_done: - - Py_INCREF(result); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : type = type de l'objet à instancier. * -* args = arguments fournis à l'appel. * -* kwds = arguments de type key=val fournis. * -* * -* Description : Crée un nouvel objet Python de type 'DbComment'. * -* * -* Retour : Instance Python mise en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_symbol_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - PyObject *result; /* Bilan à retourner */ - SymbolType stype; /* Type prévu pour le symbole */ - PyObject *range_obj; /* Objet pour la couverture */ - 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); - if (!ret) return NULL; - - if (stype >= STP_COUNT) - { - PyErr_SetString(PyExc_ValueError, _("Invalid type of symbol.")); - 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); - - result = pygobject_new(G_OBJECT(symbol)); - g_object_unref(symbol); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = classe représentant un binaire. * -* args = arguments fournis à l'appel. * -* * -* Description : Définit un autre nom pour le symbole. * -* * -* Retour : None. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_symbol_set_alt_label(PyObject *self, PyObject *args) -{ - const char *alt; /* Etiquette alternative */ - int ret; /* Bilan de lecture des args. */ - GBinSymbol *symbol; /* Elément à consulter */ - - ret = PyArg_ParseTuple(args, "s", &alt); - if (!ret) return NULL; - - symbol = G_BIN_SYMBOL(pygobject_get(self)); - - g_binary_symbol_set_alt_label(symbol, alt); - - Py_RETURN_NONE; - -} - - -/****************************************************************************** -* * -* Paramètres : self = objet Python concerné par l'appel. * -* closure = non utilisé ici. * -* * -* Description : Fournit le type du symbole. * -* * -* Retour : Type de symbole représenté. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_symbol_get_target_type(PyObject *self, void *closure) -{ - PyObject *result; /* Valeur à retourner */ - GBinSymbol *symbol; /* Elément à consulter */ - SymbolType type; /* Type de symbole représenté */ - - symbol = G_BIN_SYMBOL(pygobject_get(self)); - type = g_binary_symbol_get_target_type(symbol); - - result = PyLong_FromLong(type); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = objet Python concerné par l'appel. * -* closure = non utilisé ici. * -* * -* Description : Fournit un étiquette pour viser un symbole. * -* * -* Retour : Chaîne de caractères renvoyant au symbole. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_symbol_get_label(PyObject *self, void *closure) -{ - PyObject *result; /* Valeur à retourner */ - GBinSymbol *symbol; /* Elément à consulter */ - const char *label; /* Désignation courante */ - - symbol = G_BIN_SYMBOL(pygobject_get(self)); - label = g_binary_symbol_get_label(symbol); - - if (label != NULL) - result = PyUnicode_FromString(label); - - else - { - result = Py_None; - Py_INCREF(result); - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = objet Python concerné par l'appel. * -* closure = non utilisé ici. * -* * -* Description : Fournit l'emplacement où se situe un symbole. * -* * -* Retour : Zone mémoire couverte par le symbole. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_symbol_get_range(PyObject *self, void *closure) -{ - PyObject *result; /* Valeur à retourner */ - GBinSymbol *symbol; /* Elément à consulter */ - const mrange_t *range; /* Couverture courante */ - - symbol = G_BIN_SYMBOL(pygobject_get(self)); - range = g_binary_symbol_get_range(symbol); - - result = build_from_internal_mrange(range); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = objet Python concerné par l'appel. * -* closure = non utilisé ici. * -* * -* Description : Fournit la visibilité du symbole. * -* * -* Retour : Etat de la visibilité du symbole représenté. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_binary_symbol_get_status(PyObject *self, void *closure) -{ - PyObject *result; /* Valeur à retourner */ - GBinSymbol *symbol; /* Elément à consulter */ - SymbolStatus status; /* Visibilité du symbole fourni*/ - - symbol = G_BIN_SYMBOL(pygobject_get(self)); - status = g_binary_symbol_get_status(symbol); - - result = PyLong_FromLong(status); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : obj_type = type dont le dictionnaire est à compléter. * -* * -* Description : Définit les constantes pour les symboles binaires. * -* * -* Retour : true en cas de succès de l'opération, false sinon. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool py_binary_symbol_define_constants(PyTypeObject *obj_type) -{ - bool result; /* Bilan à retourner */ - - result = true; - - result &= PyDict_AddIntMacro(obj_type, STP_DATA); - result &= PyDict_AddIntMacro(obj_type, STP_ROUTINE); - result &= PyDict_AddIntMacro(obj_type, STP_CODE_LABEL); - result &= PyDict_AddIntMacro(obj_type, STP_OBJECT); - result &= PyDict_AddIntMacro(obj_type, STP_ENTRY_POINT); - result &= PyDict_AddIntMacro(obj_type, STP_STRING); - result &= PyDict_AddIntMacro(obj_type, STP_RO_STRING); - result &= PyDict_AddIntMacro(obj_type, STP_COUNT); - - 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_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, NULL, - "Range covered by the symbol.", NULL - }, - { - "status", py_binary_symbol_get_status, NULL, - "Status of the symbol's visibility.", NULL - }, - { NULL } - }; - - static PyTypeObject py_bin_symbol_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.format.BinSymbol", - .tp_basicsize = sizeof(PyGObject), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyChrysalide binary symbol", - - .tp_richcompare = py_binary_symbol_richcompare, - - .tp_methods = py_bin_symbol_methods, - .tp_getset = py_bin_symbol_getseters, - .tp_new = (newfunc)py_binary_symbol_new - - }; - - return &py_bin_symbol_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.format.BinSymbol'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_binary_symbol(PyObject *module) -{ - PyTypeObject *py_bin_symbol_type; /* Type Python 'BinSymbol' */ - PyObject *dict; /* Dictionnaire du module */ - - py_bin_symbol_type = get_python_binary_symbol_type(); - - dict = PyModule_GetDict(module); - - if (!register_class_for_pygobject(dict, G_TYPE_BIN_SYMBOL, py_bin_symbol_type, &PyGObject_Type)) - return false; - - if (!py_binary_symbol_define_constants(py_bin_symbol_type)) - return false; - - return true; - -} diff --git a/plugins/pychrysa/format/symbol.h b/plugins/pychrysa/format/symbol.h deleted file mode 100644 index 0fe2ed8..0000000 --- a/plugins/pychrysa/format/symbol.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * symbol.h - prototypes pour l'équivalent Python du fichier "format/symbol.h" - * - * Copyright (C) 2015-2017 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_PYCHRYSA_FORMAT_SYMBOL_H -#define _PLUGINS_PYCHRYSA_FORMAT_SYMBOL_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_binary_symbol_type(void); - -/* Prend en charge l'objet 'pychrysalide.format.BinSymbol'. */ -bool register_python_binary_symbol(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSA_FORMAT_EXECUTABLE_H */ diff --git a/plugins/pychrysa/format/symiter.c b/plugins/pychrysa/format/symiter.c deleted file mode 100644 index db0b744..0000000 --- a/plugins/pychrysa/format/symiter.c +++ /dev/null @@ -1,276 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * symiter.c - équivalent Python du fichier "format/symiter.c" - * - * Copyright (C) 2017 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 "symiter.h" - - -#include - - -#include - - -#include "format.h" - - - -/* Transcription d'un itérateur en Python */ -typedef struct _PySymIterator -{ - PyObject_HEAD; /* A laisser en premier */ - - sym_iter_t *native; /* Version native de l'objet */ - bool first_time; /* Premier élément retourné ? */ - -} PySymIterator; - - -/* Libère de la mémoire un itérateur sur des symboles. */ -static void py_sym_iterator_dealloc(PySymIterator *); - -/* Fournit le symbole qui en suit un autr. */ -static PyObject *py_sym_iterator_next(PySymIterator *); - -/* Initialise un nouvel itérateur. */ -static int py_sym_iterator_init(PySymIterator *, PyObject *, PyObject *); - -/* Construit un nouvel itérateur. */ -static PyObject *py_sym_iterator_new(PyTypeObject *, PyObject *, PyObject *); - - - -/****************************************************************************** -* * -* Paramètres : self = itérateur à supprimer. * -* * -* Description : Libère de la mémoire un itérateur sur des symboles. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void py_sym_iterator_dealloc(PySymIterator *self) -{ - delete_symbol_iterator(self->native); - - Py_TYPE(self)->tp_free((PyObject *)self); - -} - - -/****************************************************************************** -* * -* Paramètres : self = itérateur à manipuler. * -* * -* Description : Fournit le symbole qui en suit un autre. * -* * -* Retour : Symbole suivant trouvé, ou NULL. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_sym_iterator_next(PySymIterator *self) -{ - PyObject *result; /* Résultat à retourner */ - GBinSymbol *next; /* Symbole suivant */ - - if (self->first_time) - { - next = get_symbol_iterator_current(self->native); - self->first_time = false; - } - - else - next = get_symbol_iterator_next(self->native); - - if (next != NULL) - { - result = pygobject_new(G_OBJECT(next)); - g_object_unref(G_OBJECT(next)); - } - - else - { - PyErr_SetNone(PyExc_StopIteration); - result = NULL; - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = instance d'objet à initialiser. * -* args = arguments passés pour l'appel. * -* kwds = mots clefs éventuellement fournis en complément. * -* * -* Description : Initialise un nouvel itérateur. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static int py_sym_iterator_init(PySymIterator *self, PyObject *args, PyObject *kwds) -{ - int result; /* Bilan à retourner */ - PyObject *fmt_obj; /* Format version Python */ - unsigned long index; /* Indice de premier symbole */ - int ret; /* Bilan de lecture des args. */ - GBinFormat *format; /* Version native du format */ - - result = -1; - - ret = PyArg_ParseTuple(args, "Ok", &fmt_obj, &index); - if (ret == 0) goto psii_exit; - - ret = PyObject_IsInstance(fmt_obj, (PyObject *)get_python_binary_format_type()); - if (!ret) goto psii_exit; - - format = G_BIN_FORMAT(pygobject_get(fmt_obj)); - - self->native = create_symbol_iterator(format, index); - self->first_time = true; - - result = 0; - - psii_exit: - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : type = type d'objet à mettre en place. * -* args = arguments passés pour l'appel. * -* kwds = mots clefs éventuellement fournis en complément. * -* * -* Description : Construit un nouvel itérateur. * -* * -* Retour : Définition d'objet pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_sym_iterator_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - PySymIterator *result; /* Nouvelle instance à renvoyer*/ - int ret; /* Bilan de l'initialisation */ - - result = (PySymIterator *)type->tp_alloc(type, 0); - - if (result != NULL) - { - ret = py_sym_iterator_init(result, args, kwds); - - if (ret != 0) - { - Py_DECREF(result); - result = NULL; - } - - } - - return (PyObject *)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_sym_iterator_type(void) -{ - static PyTypeObject py_sym_iterator_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.format.SymIterator", - .tp_basicsize = sizeof(PySymIterator), - - .tp_dealloc = (destructor)py_sym_iterator_dealloc, - - .tp_flags = Py_TPFLAGS_DEFAULT, - - .tp_doc = "Iterator for Chrysalide symbols registered in a given format.", - - .tp_iter = PyObject_SelfIter, - .tp_iternext = (iternextfunc)py_sym_iterator_next, - - .tp_init = (initproc)py_sym_iterator_init, - .tp_new = py_sym_iterator_new, - - }; - - return &py_sym_iterator_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.format.SymIterator'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_sym_iterator(PyObject *module) -{ - PyTypeObject *py_sym_iterator_type; /* Type Python 'BinContent' */ - int ret; /* Bilan d'un appel */ - - py_sym_iterator_type = get_python_sym_iterator_type(); - - if (PyType_Ready(py_sym_iterator_type) < 0) - return false; - - Py_INCREF(py_sym_iterator_type); - ret = PyModule_AddObject(module, "SymIterator", (PyObject *)py_sym_iterator_type); - - return (ret == 0); - -} diff --git a/plugins/pychrysa/format/symiter.h b/plugins/pychrysa/format/symiter.h deleted file mode 100644 index 6cc1d29..0000000 --- a/plugins/pychrysa/format/symiter.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * symiter.h - prototypes pour l'équivalent Python du fichier "format/symiter.h" - * - * Copyright (C) 2017 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_SYMITER_H -#define _PLUGINS_PYCHRYSALIDE_FORMAT_SYMITER_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_sym_iterator_type(void); - -/* Prend en charge l'objet 'pychrysalide.format.SymIterator'. */ -bool register_python_sym_iterator(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSALIDE_FORMAT_SYMITER_H */ diff --git a/plugins/pychrysa/glibext/Makefile.am b/plugins/pychrysa/glibext/Makefile.am deleted file mode 100644 index e4d5243..0000000 --- a/plugins/pychrysa/glibext/Makefile.am +++ /dev/null @@ -1,19 +0,0 @@ - -noinst_LTLIBRARIES = libpychrysaglibext.la - -libpychrysaglibext_la_SOURCES = \ - buffercache.h buffercache.c \ - bufferline.h bufferline.c \ - configuration.h configuration.c \ - linegen.h linegen.c \ - loadedpanel.h loadedpanel.c \ - module.h module.c - - -libpychrysaglibext_la_LDFLAGS = - - -AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ - -I../../../src - -AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) diff --git a/plugins/pychrysa/glibext/buffercache.c b/plugins/pychrysa/glibext/buffercache.c deleted file mode 100644 index f61d34f..0000000 --- a/plugins/pychrysa/glibext/buffercache.c +++ /dev/null @@ -1,165 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * buffercache.c - équivalent Python du fichier "glibext/gbuffercache.h" - * - * Copyright (C) 2016-2017 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 "buffercache.h" - - -#include - - -#include - - -#include "../arch/vmpa.h" -#include "../helpers.h" - - - -#if 0 -/* Retrouve une ligne au sein d'un tampon avec une adresse. */ -static PyObject *py_code_buffer_find_line_by_addr(PyObject *, PyObject *); - - - -/****************************************************************************** -* * -* Paramètres : self = classe représentant un tampon de code. * -* args = arguments fournis à l'appel. * -* * -* Description : Retrouve une ligne au sein d'un tampon avec une adresse. * -* * -* Retour : Instance de la ligne trouvée. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_code_buffer_find_line_by_addr(PyObject *self, PyObject *args) -{ - PyObject *result; /* Trouvailles à retourner */ - PyObject *py_vmpa; /* Localisation version Python */ - int ret; /* Bilan de lecture des args. */ - vmpa2t *addr; /* Adresse visée par l'opérat° */ - GBuffercache *buffer; /* Version native */ - GBufferLine *line; /* Ligne trouvée */ - - ret = PyArg_ParseTuple(args, "O", &py_vmpa); - if (!ret) return NULL; - - ret = PyObject_IsInstance(py_vmpa, (PyObject *)get_python_vmpa_type()); - if (!ret) return NULL; - - addr = get_internal_vmpa(py_vmpa); - if (addr == NULL) return NULL; - - buffer = G_CODE_BUFFER(pygobject_get(self)); - - line = g_code_buffer_find_line_by_addr(buffer, addr, 0, NULL); - if (line == NULL) Py_RETURN_NONE; - - result = pygobject_new(G_OBJECT(line)); - - return result; - -} -#endif - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit un accès à une définition de type à diffuser. * -* * -* Retour : Définition d'objet pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyTypeObject *get_python_buffer_cache_type(void) -{ - static PyMethodDef py_buffer_cache_methods[] = { -#if 0 - { - "find_line_by_addr", (PyCFunction)py_buffer_cache_find_line_by_addr, - METH_VARARGS, - "find_line_by_addr($self, addr, /)\n--\n\nFind a buffer line with a given address." - }, -#endif - { NULL } - }; - - static PyGetSetDef py_buffer_cache_getseters[] = { - { NULL } - }; - - static PyTypeObject py_buffer_cache_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.glibext.Buffercache", - .tp_basicsize = sizeof(PyGObject), - - .tp_flags = Py_TPFLAGS_DEFAULT, - - .tp_doc = "PyChrysalide code buffer", - - .tp_methods = py_buffer_cache_methods, - .tp_getset = py_buffer_cache_getseters, - - }; - - return &py_buffer_cache_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.glibext.BufferCache'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_buffer_cache(PyObject *module) -{ - PyTypeObject *py_buffer_cache_type; /* Type Python 'BufferCache' */ - PyObject *dict; /* Dictionnaire du module */ - - py_buffer_cache_type = get_python_buffer_cache_type(); - - dict = PyModule_GetDict(module); - - if (!register_class_for_pygobject(dict, G_TYPE_BUFFER_CACHE, py_buffer_cache_type, &PyGObject_Type)) - return false; - - return true; - -} diff --git a/plugins/pychrysa/glibext/buffercache.h b/plugins/pychrysa/glibext/buffercache.h deleted file mode 100644 index 8d88e08..0000000 --- a/plugins/pychrysa/glibext/buffercache.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * buffercache.h - prototypes pour l'équivalent Python du fichier "glibext/buffercache.h" - * - * Copyright (C) 2016-2017 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_PYCHRYSA_GLIBEXT_BUFFERCACHE_H -#define _PLUGINS_PYCHRYSA_GLIBEXT_BUFFERCACHE_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_buffer_cache_type(void); - -/* Prend en charge l'objet 'pychrysalide.glibext.CodeBuffer'. */ -bool register_python_buffer_cache(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSA_GLIBEXT_BUFFERCACHE_H */ diff --git a/plugins/pychrysa/glibext/bufferline.c b/plugins/pychrysa/glibext/bufferline.c deleted file mode 100644 index bfb894b..0000000 --- a/plugins/pychrysa/glibext/bufferline.c +++ /dev/null @@ -1,373 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * bufferline.c - équivalent Python du fichier "glibext/gbufferline.h" - * - * Copyright (C) 2012-2017 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 "bufferline.h" - - -#include -#include - - -#include - - -#include - - -#include "../helpers.h" -#include "../arch/vmpa.h" - - - -/* Reconstruit et fournit le texte présent sur une ligne tampon. */ -static PyObject *py_buffer_line_get_text(PyObject *, PyObject *); - -/* Ajoute une propriété particulière à une ligne donnée. */ -static PyObject *py_buffer_line_add_flag(PyObject *, PyObject *); - -/* Retire une propriété particulière à une ligne donnée. */ -static PyObject *py_buffer_line_remove_flag(PyObject *, PyObject *); - -/* Fournit l'emplacement où se situe un symbole. */ -static PyObject *py_buffer_line_get_range(PyObject *, void *); - -/* Renseigne sur les propriétés particulières liées à une ligne. */ -static PyObject *py_buffer_line_get_flags(PyObject *, void *); - -/* Définit les constantes pour les lignes de tampon. */ -static bool py_buffer_line_define_constants(PyTypeObject *); - - - -/****************************************************************************** -* * -* Paramètres : self = classe représentant une ligne de tampon. * -* args = arguments fournis à l'appel. * -* * -* Description : Reconstruit et fournit le texte présent sur une ligne tampon.* -* * -* Retour : Texte reconstruit pour l'occasion. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_buffer_line_get_text(PyObject *self, PyObject *args) -{ - PyObject *result; /* Trouvailles à retourner */ - BufferLineColumn first; /* Première colonne à parcourir*/ - BufferLineColumn end; /* Dernière colonne à parcourir*/ - int markup; /* Besoin de décorations ? */ - int ret; /* Bilan de lecture des args. */ - GBufferLine *line; /* Version native */ - char *text; /* Texte reconstruit à libérer */ - - ret = PyArg_ParseTuple(args, "IIp", &first, &end, &markup); - if (!ret) return NULL; - - if (first >= BLC_COUNT || end >= BLC_COUNT) - { - PyErr_SetString(PyExc_ValueError, _("Invalid range in arguments")); - return NULL; - } - - line = G_BUFFER_LINE(pygobject_get(self)); - text = g_buffer_line_get_text(line, first, end, markup); - - result = PyUnicode_FromString(text); - - free(text); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = classe représentant une ligne de tampon. * -* args = arguments fournis à l'appel. * -* * -* Description : Ajoute une propriété particulière à une ligne donnée. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_buffer_line_add_flag(PyObject *self, PyObject *args) -{ - BufferLineFlags flag; /* Drapeau à considérer */ - int ret; /* Bilan de lecture des args. */ - GBufferLine *line; /* Version native */ - - ret = PyArg_ParseTuple(args, "I", &flag); - if (!ret) return NULL; - - if ((flag & ~BLF_ALL) != 0) - { - PyErr_SetString(PyExc_ValueError, _("Invalid flag")); - return NULL; - } - - line = G_BUFFER_LINE(pygobject_get(self)); - g_buffer_line_add_flag(line, flag); - - Py_RETURN_NONE; - -} - - -/****************************************************************************** -* * -* Paramètres : self = classe représentant une ligne de tampon. * -* args = arguments fournis à l'appel. * -* * -* Description : Retire une propriété particulière à une ligne donnée. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_buffer_line_remove_flag(PyObject *self, PyObject *args) -{ - BufferLineFlags flag; /* Drapeau à considérer */ - int ret; /* Bilan de lecture des args. */ - GBufferLine *line; /* Version native */ - - ret = PyArg_ParseTuple(args, "I", &flag); - if (!ret) return NULL; - - if ((flag & ~BLF_ALL) != 0) - { - PyErr_SetString(PyExc_ValueError, _("Invalid flag")); - return NULL; - } - - line = G_BUFFER_LINE(pygobject_get(self)); - g_buffer_line_remove_flag(line, flag); - - Py_RETURN_NONE; - -} - - -/****************************************************************************** -* * -* Paramètres : self = objet Python concerné par l'appel. * -* closure = non utilisé ici. * -* * -* Description : Indique la zone mémoire où se situe la ligne. * -* * -* Retour : Emplacement mémoire virtuel ou physique. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_buffer_line_get_range(PyObject *self, void *closure) -{ - PyObject *result; /* Valeur à retourner */ - GBufferLine *line; /* Elément à consulter */ - const mrange_t *range; /* Couverture courante */ - - line = G_BUFFER_LINE(pygobject_get(self)); - range = g_buffer_line_get_range(line); - - result = build_from_internal_mrange(range); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = objet Python concerné par l'appel. * -* closure = non utilisé ici. * -* * -* Description : Renseigne sur les propriétés particulières liées à une ligne.* -* * -* Retour : Propriétés intégrées. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_buffer_line_get_flags(PyObject *self, void *closure) -{ - PyObject *result; /* Valeur à retourner */ - GBufferLine *line; /* Elément à consulter */ - BufferLineFlags flags; /* Drapeaux à exporter */ - - line = G_BUFFER_LINE(pygobject_get(self)); - flags = g_buffer_line_get_flags(line); - - result = PyLong_FromLong(flags); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : obj_type = type dont le dictionnaire est à compléter. * -* * -* Description : Définit les constantes pour les lignes de tampon. * -* * -* Retour : true en cas de succès de l'opération, false sinon. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool py_buffer_line_define_constants(PyTypeObject *obj_type) -{ - bool result; /* Bilan à retourner */ - - result = true; - - result &= PyDict_AddIntMacro(obj_type, BLC_PHYSICAL); - result &= PyDict_AddIntMacro(obj_type, BLC_VIRTUAL); - result &= PyDict_AddIntMacro(obj_type, BLC_BINARY); - result &= PyDict_AddIntMacro(obj_type, BLC_ASSEMBLY_HEAD); - result &= PyDict_AddIntMacro(obj_type, BLC_ASSEMBLY); - result &= PyDict_AddIntMacro(obj_type, BLC_COMMENTS); - result &= PyDict_AddIntMacro(obj_type, BLC_COUNT); - result &= PyDict_AddIntMacro(obj_type, BLC_LAST_USED); - result &= PyDict_AddIntMacro(obj_type, BLC_INVALID); - result &= PyDict_AddIntMacro(obj_type, BLC_MAIN); - result &= PyDict_AddIntMacro(obj_type, BLC_FIRST); - result &= PyDict_AddIntMacro(obj_type, BLC_DISPLAY); - - result &= PyDict_AddIntMacro(obj_type, BLF_NONE); - result &= PyDict_AddIntMacro(obj_type, BLF_HAS_CODE); - result &= PyDict_AddIntMacro(obj_type, BLF_ENTRYPOINT); - result &= PyDict_AddIntMacro(obj_type, BLF_BOOKMARK); - - 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_buffer_line_type(void) -{ - static PyMethodDef py_buffer_line_methods[] = { - { - "get_text", py_buffer_line_get_text, - METH_VARARGS, - "get_text($self, first_col, last_col, markup, /)\n--\n\nProvide the text of a buffer line." - }, - { - "add_flag", py_buffer_line_add_flag, - METH_VARARGS, - "add_flag($self, flag, /)\n--\n\nAdd a flag to the buffer line." - }, - { - "remove_flag", py_buffer_line_remove_flag, - METH_VARARGS, - "remove_flag($self, flag, /)\n--\n\nRemove a flag from the buffer line." - }, - { NULL } - }; - - static PyGetSetDef py_buffer_line_getseters[] = { - { - "range", py_buffer_line_get_range, NULL, - "Range covered by the line.", NULL - }, - { - "flags", py_buffer_line_get_flags, NULL, - "Current flags of the buffer line.", NULL - }, - { NULL } - }; - - static PyTypeObject py_buffer_line_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.glibext.BufferLine", - .tp_basicsize = sizeof(PyGObject), - - .tp_flags = Py_TPFLAGS_DEFAULT, - - .tp_doc = "PyChrysalide buffer line", - - .tp_methods = py_buffer_line_methods, - .tp_getset = py_buffer_line_getseters, - - }; - - return &py_buffer_line_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.glibext.BufferLine'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_buffer_line(PyObject *module) -{ - PyTypeObject *py_buffer_line_type; /* Type Python 'BufferLine' */ - PyObject *dict; /* Dictionnaire du module */ - - py_buffer_line_type = get_python_buffer_line_type(); - - dict = PyModule_GetDict(module); - - if (!register_class_for_pygobject(dict, G_TYPE_BUFFER_LINE, py_buffer_line_type, &PyGObject_Type)) - return false; - - if (!py_buffer_line_define_constants(py_buffer_line_type)) - return false; - - return true; - -} diff --git a/plugins/pychrysa/glibext/bufferline.h b/plugins/pychrysa/glibext/bufferline.h deleted file mode 100644 index 86b567f..0000000 --- a/plugins/pychrysa/glibext/bufferline.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * bufferline.h - prototypes pour l'équivalent Python du fichier "glibext/bufferline.h" - * - * Copyright (C) 2012-2017 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_PYCHRYSA_GLIBEXT_BUFFERLINE_H -#define _PLUGINS_PYCHRYSA_GLIBEXT_BUFFERLINE_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_buffer_line_type(void); - -/* Prend en charge l'objet 'pychrysalide.glibext.BufferLine'. */ -bool register_python_buffer_line(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSA_GLIBEXT_BUFFERLINE_H */ diff --git a/plugins/pychrysa/glibext/configuration.c b/plugins/pychrysa/glibext/configuration.c deleted file mode 100644 index a780f73..0000000 --- a/plugins/pychrysa/glibext/configuration.c +++ /dev/null @@ -1,1165 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * configuration.c - prototypes pour l'équivalent Python du fichier "glibext/configuration.c" - * - * Copyright (C) 2014-2017 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 "configuration.h" - - -#include - - -#include - - -#include "../helpers.h" - - - -/* ---------------------------- ELEMENT DE CONFIGURATION ---------------------------- */ - - -/* Crée un nouvel objet Python de type 'ConfigParam'. */ -static PyObject *py_config_param_new(PyTypeObject *, PyObject *, PyObject *); - -/* Efface toute valeur courante d'un paramètre de configuration. */ -static PyObject *py_config_param_make_empty(PyObject *, PyObject *); - -/* Réinitialise la valeur d'un paramètre de configuration. */ -static PyObject *py_config_param_reset(PyObject *, PyObject *); - -/* Indique le chemin d'accès utilisé pour un paramètre. */ -static PyObject *py_config_param_get_path(PyObject *, void *); - -/* Indique le type de valeur utilisée par un paramètre. */ -static PyObject *py_config_param_get_type(PyObject *, void *); - -/* Indique le statut d'une valeur utilisée par un paramètre. */ -static PyObject *py_config_param_get_state(PyObject *, void *); - -/* Indique la valeur courante d'un paramètre de configuration. */ -static PyObject *py_config_param_get_value(PyObject *, void *); - -/* Modifie la valeur courante d'un paramètre de configuration. */ -static int py_config_param_set_value(PyObject *, PyObject *, void *); - -/* Définit les constantes pour les paramètres. */ -static bool py_config_param_define_constants(PyObject *); - - - -/* ----------------------------- PARCOURS DE PARAMETRES ----------------------------- */ - - -/* Parcours des éléments de configuration */ -typedef struct _pyConfigParamIterator -{ - PyObject_HEAD /* A laisser en premier */ - - GGenConfig *config; /* Configuration à parcourir */ - GList *params; /* Liste de paramètres */ - - GList *last; /* Dernier élément retourné */ - -} pyConfigParamIterator; - - -/* Prend acte d'un compteur de référence à 0. */ -static void py_config_param_iterator_dealloc(PyObject *); - -/* Fournit un itérateur pour paramètres de configuration. */ -static PyObject *py_config_param_iterator_next(PyObject *); - -/* Initialise un objet Python de type 'ConfigParamIterator'. */ -static int py_config_param_iterator_init(PyObject *, PyObject *, PyObject *); - - - -/* ----------------------- GESTION GENERIQUE DE CONFIGURATION ----------------------- */ - - -/* Crée un nouvel objet Python de type 'GenConfig'. */ -static PyObject *py_generic_config_new(PyTypeObject *, PyObject *, PyObject *); - -/* Lit la configuration depuis un fichier. */ -static PyObject *py_generic_config_read(PyObject *, PyObject *); - -/* Ecrit la configuration dans un fichier. */ -static PyObject *py_generic_config_write(PyObject *, PyObject *); - -/* Retrouve un élément de configuration par son chemin. */ -static PyObject *py_generic_config_search(PyObject *, PyObject *); - -/* Ajoute un paramètre à une configuration. */ -static PyObject *py_generic_config_add(PyObject *, PyObject *); - -/* Retire un paramètre d'une configuration. */ -static PyObject *py_generic_config_delete(PyObject *, PyObject *); - -/* Fournit le chemin d'accès au binaire représenté. */ -static PyObject *py_generic_config_get_filename(PyObject *, void *); - - - -/* ---------------------------------------------------------------------------------- */ -/* ELEMENT DE CONFIGURATION */ -/* ---------------------------------------------------------------------------------- */ - - -/****************************************************************************** -* * -* Paramètres : type = type de l'objet à instancier. * -* args = arguments fournis à l'appel. * -* kwds = arguments de type key=val fournis. * -* * -* Description : Crée un nouvel objet Python de type 'ConfigParam'. * -* * -* Retour : Instance Python mise en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_config_param_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - PyObject *result; /* Instance à retourner */ - const char *path; /* Accès au paramètre */ - unsigned int ptype; /* Type de paramètre */ - PyObject *value; /* Valeur par défaut éventuelle*/ - int ret; /* Bilan de lecture des args. */ - GCfgParam *param; /* Paramètre mis en place */ - - value = NULL; - - ret = PyArg_ParseTuple(args, "sI|O", &path, &ptype, &value); - if (!ret) Py_RETURN_NONE; - - if (value == NULL || value == Py_None) - param = g_config_param_new_empty(path, ptype); - - else - switch (ptype) - { - case CPT_BOOLEAN: - if (PyBool_Check(value)) - param = g_config_param_new(path, CPT_BOOLEAN, (bool)(value == Py_True)); - else - param = NULL; - break; - - case CPT_INTEGER: - if (PyLong_Check(value)) - param = g_config_param_new(path, CPT_INTEGER, (int)PyLong_AsLong(value)); - else - param = NULL; - break; - - case CPT_STRING: - if (PyUnicode_Check(value)) - param = g_config_param_new(path, CPT_STRING, PyUnicode_DATA(value)); - else - param = NULL; - break; - - default: - param = NULL; - break; - - } - - if (param != NULL) - { - result = pygobject_new(G_OBJECT(param)); - g_object_unref(param); - } - else result = NULL; - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = paramètre de configuration à manipuler. * -* args = non utilisé ici. * -* * -* Description : Efface toute valeur courante d'un paramètre de configuration.* -* * -* Retour : None. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_config_param_make_empty(PyObject *self, PyObject *args) -{ - GCfgParam *param; /* Paramètre visé par l'opérat°*/ - - param = G_CFG_PARAM(pygobject_get(self)); - - g_config_param_make_empty(param); - - Py_RETURN_NONE; - -} - - -/****************************************************************************** -* * -* Paramètres : self = paramètre de configuration à manipuler. * -* args = non utilisé ici. * -* * -* Description : Réinitialise la valeur d'un paramètre de configuration. * -* * -* Retour : None. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_config_param_reset(PyObject *self, PyObject *args) -{ - GCfgParam *param; /* Paramètre visé par l'opérat°*/ - - param = G_CFG_PARAM(pygobject_get(self)); - - g_config_param_reset(param); - - Py_RETURN_NONE; - -} - - -/****************************************************************************** -* * -* Paramètres : self = paramètre de configuration à manipuler. * -* closure = non utilisé ici. * -* * -* Description : Indique le chemin d'accès utilisé pour un paramètre. * -* * -* Retour : Chemin d'accès en Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_config_param_get_path(PyObject *self, void *closure) -{ - GCfgParam *param; /* Paramètre visé par l'opérat°*/ - const char *path; /* Chemin d'accès à diffuser */ - - param = G_CFG_PARAM(pygobject_get(self)); - path = g_config_param_get_path(param); - - return PyUnicode_FromString(path); - -} - - -/****************************************************************************** -* * -* Paramètres : self = paramètre de configuration à manipuler. * -* closure = non utilisé ici. * -* * -* Description : Indique le type de valeur utilisée par un paramètre. * -* * -* Retour : Type en Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_config_param_get_type(PyObject *self, void *closure) -{ - GCfgParam *param; /* Paramètre visé par l'opérat°*/ - ConfigParamType type; /* Type de paramètre */ - - param = G_CFG_PARAM(pygobject_get(self)); - type = g_config_param_get_ptype(param); - - return PyLong_FromLong(type); - -} - - -/****************************************************************************** -* * -* Paramètres : self = paramètre de configuration à manipuler. * -* closure = non utilisé ici. * -* * -* Description : Indique le statut d'une valeur utilisée par un paramètre. * -* * -* Retour : Etat en Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_config_param_get_state(PyObject *self, void *closure) -{ - GCfgParam *param; /* Paramètre visé par l'opérat°*/ - ConfigParamState state; /* Statut de paramètre */ - - param = G_CFG_PARAM(pygobject_get(self)); - state = g_config_param_get_state(param); - - return PyLong_FromLong(state); - -} - - -/****************************************************************************** -* * -* Paramètres : self = paramètre de configuration à manipuler. * -* closure = non utilisé ici. * -* * -* Description : Indique la valeur courante d'un paramètre de configuration. * -* * -* Retour : Etat en Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_config_param_get_value(PyObject *self, void *closure) -{ - PyObject *result; /* Valeur à retourner */ - GCfgParam *param; /* Paramètre visé par l'opérat°*/ - ConfigParamType type; /* Type de paramètre manipulé */ - bool boolean; /* Valeur booléenne */ - int integer; /* Valeur entière */ - char *string; /* Chaîne de caractères */ - - param = G_CFG_PARAM(pygobject_get(self)); - type = g_config_param_get_ptype(param); - - switch (type) - { - case CPT_BOOLEAN: - g_config_param_get_value(param, &boolean); - result = (boolean ? Py_True : Py_False); - Py_INCREF(result); - break; - - case CPT_INTEGER: - g_config_param_get_value(param, &integer); - result = PyLong_FromLong(integer); - break; - - case CPT_STRING: - g_config_param_get_value(param, &string); - if (string != NULL) - result = PyUnicode_FromString(string); - else - { - result = Py_None; - Py_INCREF(result); - } - break; - - default: - result = NULL; - break; - - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = paramètre de configuration à manipuler. * -* value = nouvelle valeur à convertir et définir. * -* closure = non utilisé ici. * -* * -* Description : Modifie la valeur courante d'un paramètre de configuration. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static int py_config_param_set_value(PyObject *self, PyObject *value, void *closure) -{ - int result; /* Conclusion à remonter */ - GCfgParam *param; /* Paramètre visé par l'opérat°*/ - ConfigParamType type; /* Type de paramètre manipulé */ - - result = -1; - - param = G_CFG_PARAM(pygobject_get(self)); - - if (value == Py_None) - { - g_config_param_make_empty(param); - result = 0; - } - - else - { - type = g_config_param_get_ptype(param); - - switch (type) - { - case CPT_BOOLEAN: - if (PyBool_Check(value)) - { - g_config_param_set_value(param, (bool)(value == Py_True)); - result = 0; - } - break; - - case CPT_INTEGER: - if (PyLong_Check(value)) - { - g_config_param_set_value(param, (int)PyLong_AsLong(value)); - result = 0; - } - break; - - case CPT_STRING: - if (PyUnicode_Check(value)) - { - g_config_param_set_value(param, PyUnicode_DATA(value)); - result = 0; - } - break; - - default: - break; - - } - - } - - 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_config_param_type(void) -{ - static PyMethodDef py_config_param_methods[] = { - { "make_empty", py_config_param_make_empty, - METH_NOARGS, - "Unset the value of the current parameter." - }, - { "reset", py_config_param_reset, - METH_NOARGS, - "Reset the content of the current parameter." - }, - { NULL } - }; - - static PyGetSetDef py_config_param_getseters[] = { - { - "path", py_config_param_get_path, NULL, - "Show the path used as key for a configuration parameter.", NULL - }, - { - "type", py_config_param_get_type, NULL, - "Show the type of value provided by a configuration parameter.", NULL - }, - { - "state", py_config_param_get_state, NULL, - "Show the state of a configuration parameter.", NULL - }, - { - "value", py_config_param_get_value, py_config_param_set_value, - "Handle the value of a configuration parameter.", NULL - }, - { NULL } - }; - - static PyTypeObject py_config_param_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.glibext.ConfigParam", - .tp_basicsize = sizeof(PyGObject), - - .tp_flags = Py_TPFLAGS_DEFAULT, - - .tp_doc = "PyChrysalide generic configuration", - - .tp_methods = py_config_param_methods, - .tp_getset = py_config_param_getseters, - .tp_new = (newfunc)py_config_param_new - - }; - - return &py_config_param_type; - -} - - -/****************************************************************************** -* * -* Paramètres : dict = dictionnaire à compléter. * -* * -* Description : Définit les constantes pour les paramètres. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool py_config_param_define_constants(PyObject *dict) -{ - int ret; /* Bilan d'un ajout */ - -#define DEF_ULONG_CONST(name) \ - ret = PyDict_SetItemString(dict, #name, PyLong_FromUnsignedLong(name)); \ - if (ret == -1) return false; - - DEF_ULONG_CONST(CPT_BOOLEAN); - DEF_ULONG_CONST(CPT_INTEGER); - DEF_ULONG_CONST(CPT_STRING); - DEF_ULONG_CONST(CPT_COUNT); - - DEF_ULONG_CONST(CPS_UNDEFINED); - DEF_ULONG_CONST(CPS_CHANGED); - DEF_ULONG_CONST(CPS_DEFAULT); - DEF_ULONG_CONST(CPS_EMPTY); - - return true; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.glibext.ConfigParam'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_config_param(PyObject *module) -{ - PyTypeObject *py_config_param_type; /* Type Python 'ConfigParam' */ - PyObject *dict; /* Dictionnaire du module */ - - py_config_param_type = get_python_config_param_type(); - - dict = PyModule_GetDict(module); - - if (!register_class_for_pygobject(dict, G_TYPE_CFG_PARAM, py_config_param_type, &PyGObject_Type)) - return false; - - if (!py_config_param_define_constants(py_config_param_type->tp_dict)) - return false; - - return true; - -} - - - -/* ---------------------------------------------------------------------------------- */ -/* PARCOURS DE PARAMETRES */ -/* ---------------------------------------------------------------------------------- */ - - -/****************************************************************************** -* * -* Paramètres : self = instance Python à libérer de la mémoire. * -* * -* Description : Prend acte d'un compteur de référence à 0. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void py_config_param_iterator_dealloc(PyObject *self) -{ - pyConfigParamIterator *iterator; /* Références pour le parcours */ - - /** - * Il aurait été sans doute mieux de reposer ici sur .tp_finalize, - * mais cela semble impliquer de mettre en place tous les mécanismes de GC... - * - * cf. https://docs.python.org/3/extending/newtypes.html#finalization-and-de-allocation - */ - - iterator = (pyConfigParamIterator *)self; - - g_generic_config_runlock(iterator->config); - g_object_unref(G_OBJECT(iterator->config)); - - Py_TYPE(self)->tp_free((PyObject *)self); - -} - - -/****************************************************************************** -* * -* Paramètres : self = itérateur à manipuler. * -* * -* Description : Fournit un itérateur pour paramètres de configuration. * -* * -* Retour : Instance Python prête à emploi. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_config_param_iterator_next(PyObject *self) -{ - PyObject *result; /* Instance à retourner */ - pyConfigParamIterator *iterator; /* Références pour le parcours */ - GList *item; /* Nouvel élément courant */ - - iterator = (pyConfigParamIterator *)self; - - if (iterator->last == NULL) item = iterator->params; - else item = g_list_next(iterator->last); - - iterator->last = item; - - if (item != NULL) - { - result = pygobject_new(G_OBJECT(item->data)); - Py_INCREF(result); - } - else - { - PyErr_SetNone(PyExc_StopIteration); - result = NULL; - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = objet instancié à initialiser. * -* args = arguments fournis à l'appel. * -* kwds = arguments de type key=val fournis. * -* * -* Description : Initialise un objet Python de type 'ConfigParamIterator'. * -* * -* Retour : Instance Python mise en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static int py_config_param_iterator_init(PyObject *self, PyObject *args, PyObject *kwds) -{ - pyConfigParamIterator *iterator; /* Références pour le parcours */ - PyObject *config; /* Configuration format Python */ - int ret; /* Bilan de lecture des args. */ - - ret = PyArg_ParseTuple(args, "O", &config); - if (!ret) return -1; - - ret = PyObject_IsInstance(config, (PyObject *)get_python_generic_config_type()); - if (!ret) return -1; - - iterator = (pyConfigParamIterator *)self; - - iterator->config = G_GEN_CONFIG(pygobject_get(config)); - g_object_ref(G_OBJECT(iterator->config)); - - g_generic_config_rlock(iterator->config); - - iterator->params = g_generic_config_list_params(iterator->config); - - iterator->last = NULL; - - return 0; - -} - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit un accès à une définition de type à diffuser. * -* * -* Retour : Définition d'objet pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyTypeObject *get_python_config_param_iterator_type(void) -{ - static PyTypeObject py_config_param_iterator_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.glibext.ConfigParamIterator", - .tp_basicsize = sizeof(pyConfigParamIterator), - - .tp_dealloc = py_config_param_iterator_dealloc, - - .tp_flags = Py_TPFLAGS_DEFAULT, - - .tp_doc = "Iterator for configuration parameters", - - .tp_iter = PyObject_SelfIter, - .tp_iternext = py_config_param_iterator_next, - - .tp_init = py_config_param_iterator_init, - - .tp_new = PyType_GenericNew, - - }; - - return &py_config_param_iterator_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide...ConfigParamIterator'.* -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_config_param_iterator(PyObject *module) -{ - PyTypeObject *py_config_param_iterator_type;/* Type Python 'Cnf...Iter'*/ - int ret; /* Bilan d'un appel */ - - py_config_param_iterator_type = get_python_config_param_iterator_type(); - - py_config_param_iterator_type->tp_base = &PyBaseObject_Type; - - if (PyType_Ready(py_config_param_iterator_type) != 0) - return false; - - Py_INCREF(py_config_param_iterator_type); - ret = PyModule_AddObject(module, "ConfigParamIterator", (PyObject *)py_config_param_iterator_type); - if (ret != 0) return false; - - return true; - -} - - - -/* ---------------------------------------------------------------------------------- */ -/* GESTION GENERIQUE DE CONFIGURATION */ -/* ---------------------------------------------------------------------------------- */ - - -/****************************************************************************** -* * -* Paramètres : type = type de l'objet à instancier. * -* args = arguments fournis à l'appel. * -* kwds = arguments de type key=val fournis. * -* * -* Description : Crée un nouvel objet Python de type 'GenConfig'. * -* * -* Retour : Instance Python mise en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_generic_config_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - PyObject *result; /* Instance à retourner */ - const char *name; /* Nom du fichier à charger */ - int ret; /* Bilan de lecture des args. */ - GGenConfig *config; /* Version GLib du format */ - - ret = PyArg_ParseTuple(args, "s", &name); - if (!ret) Py_RETURN_NONE; - - config = g_generic_config_new(name); - - result = pygobject_new(G_OBJECT(config)); - g_object_unref(config); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = configuration à manipuler. * -* args = non utilisé ici. * -* * -* Description : Lit la configuration depuis un fichier. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_generic_config_read(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - GGenConfig *config; /* Version GLib du format */ - bool status; /* Bilan de l'opération */ - - config = G_GEN_CONFIG(pygobject_get(self)); - - status = g_generic_config_read(config); - - result = status ? Py_True : Py_False; - Py_INCREF(result); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = configuration à manipuler. * -* args = non utilisé ici. * -* * -* Description : Ecrit la configuration dans un fichier. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_generic_config_write(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - GGenConfig *config; /* Version GLib du format */ - bool status; /* Bilan de l'opération */ - - config = G_GEN_CONFIG(pygobject_get(self)); - - status = g_generic_config_write(config); - - result = status ? Py_True : Py_False; - Py_INCREF(result); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = configuration à manipuler. * -* args = indication sur l'élément à retrouver. * -* * -* Description : Retrouve un élément de configuration par son chemin. * -* * -* Retour : Elément trouvé ou NULL en cas d'échec. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_generic_config_search(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - GGenConfig *config; /* Version GLib du format */ - const char *path; /* Chemin d'accès du paramètre */ - int ret; /* Bilan de lecture des args. */ - GCfgParam *param; /* Paramètre trouvé ou NULL */ - - config = G_GEN_CONFIG(pygobject_get(self)); - - ret = PyArg_ParseTuple(args, "s", &path); - if (!ret) Py_RETURN_NONE; - - param = g_generic_config_search(config, path); - - result = pygobject_new(G_OBJECT(param)); - Py_XINCREF(result); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = configuration à manipuler. * -* args = indication sur l'élément à retrouver. * -* * -* Description : Ajoute un paramètre à une configuration. * -* * -* Retour : Elément ajouté ou NULL en cas d'échec. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_generic_config_add(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - GGenConfig *config; /* Version GLib du format */ - PyObject *param; /* Paramètre transmis */ - int ret; /* Bilan de lecture des args. */ - GCfgParam *added; /* Elément ajouté ou NULL */ - - config = G_GEN_CONFIG(pygobject_get(self)); - - ret = PyArg_ParseTuple(args, "O", ¶m); - if (!ret) Py_RETURN_NONE; - - ret = PyObject_IsInstance(param, (PyObject *)get_python_config_param_type()); - if (!ret) Py_RETURN_NONE; - - added = g_generic_config_add_param(config, G_CFG_PARAM(pygobject_get(param))); - - if (added != NULL) - { - result = pygobject_new(G_OBJECT(added)); - Py_XINCREF(result); - } - else - result = NULL; - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = configuration à manipuler. * -* args = indication sur l'élément à retrouver. * -* * -* Description : Retire un paramètre d'une configuration. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_generic_config_delete(PyObject *self, PyObject *args) -{ - GGenConfig *config; /* Version GLib du format */ - const char *path; /* Chemin d'accès du paramètre */ - int ret; /* Bilan de lecture des args. */ - - config = G_GEN_CONFIG(pygobject_get(self)); - - ret = PyArg_ParseTuple(args, "s", &path); - if (!ret) Py_RETURN_NONE; - - g_generic_config_delete_param(config, path); - - Py_RETURN_NONE; - -} - - -/****************************************************************************** -* * -* Paramètres : self = configuration à manipuler. * -* args = non utilisé ici. * -* * -* Description : Renvoie la liste des paramètres de configuration. * -* * -* Retour : Itérateur pour la liste des paramètres. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_generic_config_list_params(PyObject *self, PyObject *args) -{ - PyObject *result; /* Instance à retourner */ - PyTypeObject *iterator_type; /* Type Python de l'itérateur */ - PyObject *args_list; /* Arguments de mise en place */ - - iterator_type = get_python_config_param_iterator_type(); - - Py_INCREF(self); - - args_list = Py_BuildValue("(O)", self); - result = PyObject_CallObject((PyObject *)iterator_type, args_list); - - Py_DECREF(args_list); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = NULL car méthode statique. * -* closure = non utilisé ici. * -* * -* Description : Fournit le chemin d'accès au binaire représenté. * -* * -* Retour : Chemin d'accès en Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_generic_config_get_filename(PyObject *self, void *closure) -{ - GGenConfig *config; /* Version GLib du format */ - const char *filename; /* Chemin d'accès au fichier */ - - config = G_GEN_CONFIG(pygobject_get(self)); - - filename = g_generic_config_get_filename(config); - - return PyUnicode_FromString(filename); - -} - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit un accès à une définition de type à diffuser. * -* * -* Retour : Définition d'objet pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyTypeObject *get_python_generic_config_type(void) -{ - static PyMethodDef py_generic_config_methods[] = { - { "read", py_generic_config_read, - METH_NOARGS, - "Read the configuration from its relative XML file." - }, - { "write", py_generic_config_write, - METH_NOARGS, - "Write the configuration to its relative XML file." - }, - { "search", py_generic_config_search, - METH_VARARGS, - "Look for a given configuration parameter." - }, - { "add", py_generic_config_add, - METH_VARARGS, - "Add an existing parameter to a configuration." - }, - { "delete", py_generic_config_delete, - METH_VARARGS, - "Delete an existing parameter from a configuration." - }, - { "params", py_generic_config_list_params, - METH_NOARGS, - "List all registered configuration parameters." - }, - { NULL } - }; - - static PyGetSetDef py_generic_config_getseters[] = { - { - "filename", py_generic_config_get_filename, NULL, - "Show the filename of the loaded binary file.", NULL - }, - { NULL } - }; - - static PyTypeObject py_generic_config_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.glibext.GenConfig", - .tp_basicsize = sizeof(PyGObject), - - .tp_flags = Py_TPFLAGS_DEFAULT, - - .tp_doc = "PyChrysalide generic configuration", - - .tp_methods = py_generic_config_methods, - .tp_getset = py_generic_config_getseters, - .tp_new = (newfunc)py_generic_config_new - - }; - - return &py_generic_config_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.glibext.GenConfig'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_generic_config(PyObject *module) -{ - PyTypeObject *py_generic_config_type; /* Type Python 'GenConfig' */ - PyObject *dict; /* Dictionnaire du module */ - - py_generic_config_type = get_python_generic_config_type(); - - dict = PyModule_GetDict(module); - - if (!register_class_for_pygobject(dict, G_TYPE_GEN_CONFIG, py_generic_config_type, &PyGObject_Type)) - return false; - - return true; - -} diff --git a/plugins/pychrysa/glibext/configuration.h b/plugins/pychrysa/glibext/configuration.h deleted file mode 100644 index ec1a3d7..0000000 --- a/plugins/pychrysa/glibext/configuration.h +++ /dev/null @@ -1,66 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * configuration.h - prototypes pour l'équivalent Python du fichier "glibext/configuration.h" - * - * Copyright (C) 2014-2017 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_PYCHRYSA_GLIBEXT_CONFIGURATION_H -#define _PLUGINS_PYCHRYSA_GLIBEXT_CONFIGURATION_H - - -#include -#include - - - -/* ---------------------------- ELEMENT DE CONFIGURATION ---------------------------- */ - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_config_param_type(void); - -/* Prend en charge l'objet 'pychrysalide.glibext.ConfigParam'. */ -bool register_python_config_param(PyObject *); - - - -/* ----------------------------- PARCOURS DE PARAMETRES ----------------------------- */ - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_config_param_iterator_type(void); - -/* Prend en charge l'objet 'pychrysalide.glibext.ConfigParamIterator'. */ -bool register_python_config_param_iterator(PyObject *); - - -/* ----------------------- GESTION GENERIQUE DE CONFIGURATION ----------------------- */ - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_generic_config_type(void); - -/* Prend en charge l'objet 'pychrysalide.glibext.GenConfig'. */ -bool register_python_generic_config(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSA_GLIBEXT_CONFIGURATION_H */ diff --git a/plugins/pychrysa/glibext/linegen.c b/plugins/pychrysa/glibext/linegen.c deleted file mode 100644 index b6aad6b..0000000 --- a/plugins/pychrysa/glibext/linegen.c +++ /dev/null @@ -1,404 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * linegen.c - équivalent Python du fichier "glibext/linegen.h" - * - * Copyright (C) 2017 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 "linegen.h" - - -#include - - -#include -#include - - -#include "../helpers.h" -#include "../analysis/content.h" -#include "../arch/vmpa.h" -#include "../glibext/bufferline.h" - - - -/* Indique le nombre de ligne prêtes à être générées. */ -static PyObject *py_line_generator_count_lines(PyObject *, PyObject *); - -/* Retrouve l'emplacement correspondant à une position donnée. */ -static PyObject *py_line_generator_compute_addr(PyObject *, PyObject *); - -/* Détermine si le conteneur s'inscrit dans une plage donnée. */ -static PyObject *py_line_generator_contains_addr(PyObject *, PyObject *); - -/* Renseigne sur les propriétés liées à un générateur. */ -static PyObject *py_line_generator_get_flags(PyObject *, PyObject *); - -/* Imprime dans une ligne de rendu le contenu représenté. */ -static PyObject *py_line_generator_print(PyObject *, PyObject *); - - - -/****************************************************************************** -* * -* Paramètres : self = classe représentant un générateur à manipuler. * -* args = arguments fournis à l'appel. * -* * -* Description : Indique le nombre de ligne prêtes à être générées. * -* * -* Retour : Nombre de lignes devant apparaître au final. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_line_generator_count_lines(PyObject *self, PyObject *args) -{ - PyObject *result; /* Décompte à retourner */ - GLineGenerator *generator; /* Version native */ - size_t count; /* Nombre de lignes présentes */ - - generator = G_LINE_GENERATOR(pygobject_get(self)); - - count = g_line_generator_count_lines(generator); - - result = Py_BuildValue("k", count); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = classe représentant un générateur à manipuler. * -* args = arguments fournis à l'appel. * -* * -* Description : Retrouve l'emplacement correspondant à une position donnée. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_line_generator_compute_addr(PyObject *self, PyObject *args) -{ - PyObject *result; /* Localisation à retourner */ - GLineGenerator *generator; /* Version native */ - gint x; /* Position géographique */ - size_t index; /* Indice dans le tampon */ - size_t repeat; /* Utilisations successives */ - int ret; /* Bilan de lecture des args. */ - vmpa2t addr; /* Adresse visée par l'opérat° */ - - generator = G_LINE_GENERATOR(pygobject_get(self)); - - ret = PyArg_ParseTuple(args, "ikk", &x, &index, &repeat); - if (!ret) return NULL; - - g_line_generator_compute_addr(generator, x, &addr, index, repeat); - - result = build_from_internal_vmpa(&addr); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = classe représentant un générateur à manipuler. * -* args = arguments fournis à l'appel. * -* * -* Description : Détermine si le conteneur s'inscrit dans une plage donnée. * -* * -* Retour : Bilan de la détermination, utilisable en comparaisons. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_line_generator_contains_addr(PyObject *self, PyObject *args) -{ - GLineGenerator *generator; /* Version native */ - PyObject *py_vmpa; /* Localisation version Python */ - size_t index; /* Indice dans le tampon */ - size_t repeat; /* Utilisations successives */ - int ret; /* Bilan de lecture des args. */ - vmpa2t *addr; /* Adresse visée par l'opérat° */ - - generator = G_LINE_GENERATOR(pygobject_get(self)); - - ret = PyArg_ParseTuple(args, "O!kk", get_python_vmpa_type(), &py_vmpa, &index, &repeat); - if (!ret) return NULL; - - addr = get_internal_vmpa(py_vmpa); - if (addr == NULL) return NULL; - - g_line_generator_contains_addr(generator, addr, index, repeat); - - Py_RETURN_NONE; - -} - - -/****************************************************************************** -* * -* Paramètres : self = classe représentant un générateur à manipuler. * -* args = arguments fournis à l'appel. * -* * -* Description : Renseigne sur les propriétés liées à un générateur. * -* * -* Retour : Propriétés particulières associées. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_line_generator_get_flags(PyObject *self, PyObject *args) -{ - PyObject *result; /* Propriétés à retourner */ - GLineGenerator *generator; /* Version native */ - size_t index; /* Indice dans le tampon */ - size_t repeat; /* Utilisations successives */ - int ret; /* Bilan de lecture des args. */ - BufferLineFlags flags; /* Propriétés courantes */ - - generator = G_LINE_GENERATOR(pygobject_get(self)); - - ret = PyArg_ParseTuple(args, "kk", &index, &repeat); - if (!ret) return NULL; - - flags = g_line_generator_get_flags(generator, index, repeat); - - result = Py_BuildValue("I", flags); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : self = classe représentant un générateur à manipuler. * -* args = arguments fournis à l'appel. * -* * -* Description : Imprime dans une ligne de rendu le contenu représenté. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_line_generator_print(PyObject *self, PyObject *args) -{ - GLineGenerator *generator; /* Version native */ - PyObject *py_line; /* Ligne version Python */ - size_t index; /* Indice dans le tampon */ - size_t repeat; /* Utilisations successives */ - PyObject *py_content; /* Contenu version Python */ - int ret; /* Bilan de lecture des args. */ - GBufferLine *line; /* Ligne de rendu à compléter */ - GBinContent *content; /* Contenu binaire associé */ - - generator = G_LINE_GENERATOR(pygobject_get(self)); - - ret = PyArg_ParseTuple(args, "O!kkO!", get_python_buffer_line_type(), &py_line, &index, - &repeat, get_python_binary_content_type(), &py_content); - if (!ret) return NULL; - - line = G_BUFFER_LINE(pygobject_get(py_line)); - - content = G_BIN_CONTENT(pygobject_get(py_content)); - - g_line_generator_print(generator, line, index, repeat, content); - - Py_RETURN_NONE; - -} - - - - - - - - - - - - - -#if 0 - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit un accès à une définition de type à diffuser. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void python_line_generator_interface_init(GLineGeneratorIface *iface, PyTypeObject *type) -{ - GLineGeneratorIface *parent; /* Défintion parente */ - size_t i; /* Boucle de parcours */ - PyObject *method; /* Méthode à associer */ - - static const char *meth_names[] = { - "count_lines", - "compute_addr", - "contains_addr", - "get_flags", - "print" - }; - - parent = g_type_interface_peek_parent(iface); - - for (i = 0; i < ARRAY_SIZE(meth_names); i++) - { - method = NULL; - - if (type != NULL) - method = PyObject_GetAttrString((PyObject *)type, meth_names[i]); - - if (method != NULL && PyObject_TypeCheck(method, &PyCFunction_Type) == 0) - /*iface->iface_method = _wrap_TestInterface__proxy_do_iface_method*/; - - else - { - PyErr_Clear(); - - if (parent != NULL) - /*iface->iface_method = parent->iface_method*/; - - } - - Py_XDECREF(method); - - } - -} - - -#endif - - - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit un accès à une définition de type à diffuser. * -* * -* Retour : Définition d'objet pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyTypeObject *get_python_line_generator_type(void) -{ - static PyMethodDef py_line_generator_methods[] = { - { - "count_lines", py_line_generator_count_lines, - METH_NOARGS, - "count_lines($self, /)\n--\n\nCount the number of lines which can be displayed." - }, - { - "compute_addr", py_line_generator_compute_addr, - METH_VARARGS, - "compute_addr($self, x, index, repeat, /)\n--\n\nReturn the position at a given location." - }, - { - "contains_addr", py_line_generator_contains_addr, - METH_VARARGS, - "contains_addr($self, addr, index, repeat, /)\n--\n\nTell if the generator contains an address." - }, - { - "get_flags", py_line_generator_get_flags, - METH_VARARGS, - "get_flags($self, index, repeat, /)\n--\n\nGet the flags of a position from the generator." - }, - { - "print", py_line_generator_print, - METH_VARARGS, - "print($self, line, index, repeat, content, /)\n--\n\nProduce output into a line from content." - }, - { NULL } - }; - - static PyGetSetDef py_line_generator_getseters[] = { - { NULL } - }; - - static PyTypeObject py_line_generator_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.glibext.LineGenerator", - //.tp_basicsize = sizeof(PyGObject), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyChrysalide line content generator", - - .tp_methods = py_line_generator_methods, - .tp_getset = py_line_generator_getseters, - - }; - - return &py_line_generator_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.glibext.LineGenerator'.* -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_line_generator(PyObject *module) -{ - PyTypeObject *py_line_generator_type; /* Type Python 'LineGenerator' */ - PyObject *dict; /* Dictionnaire du module */ - - py_line_generator_type = get_python_line_generator_type(); - - dict = PyModule_GetDict(module); - pyg_register_interface(dict, "LineGenerator", G_TYPE_LINE_GENERATOR, py_line_generator_type); - - return true; - -} diff --git a/plugins/pychrysa/glibext/linegen.h b/plugins/pychrysa/glibext/linegen.h deleted file mode 100644 index 8669bb7..0000000 --- a/plugins/pychrysa/glibext/linegen.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * linegen.h - prototypes pour l'équivalent Python du fichier "glibext/linegen.h" - * - * Copyright (C) 2017 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_PYCHRYSA_GLIBEXT_LINEGEN_H -#define _PLUGINS_PYCHRYSA_GLIBEXT_LINEGEN_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_line_generator_type(void); - -/* Prend en charge l'objet 'pychrysalide.glibext.LineGenerator'. */ -bool register_python_line_generator(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSA_GLIBEXT_LINEGEN_H */ diff --git a/plugins/pychrysa/glibext/loadedpanel.c b/plugins/pychrysa/glibext/loadedpanel.c deleted file mode 100644 index f831607..0000000 --- a/plugins/pychrysa/glibext/loadedpanel.c +++ /dev/null @@ -1,166 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * loadedpanel.c - équivalent Python du fichier "glibext/gloadedpanel.h" - * - * Copyright (C) 2017 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 "loadedpanel.h" - - -#include - - -#include - - - - -/* Retrouve l'emplacement correspondant à une position donnée. */ -//static PyObject *py_loaded_panel_compute_addr(PyObject *, PyObject *); - - - - -#if 0 - - -/****************************************************************************** -* * -* Paramètres : self = classe représentant un générateur à manipuler. * -* args = arguments fournis à l'appel. * -* * -* Description : Retrouve l'emplacement correspondant à une position donnée. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_loaded_panel_compute_addr(PyObject *self, PyObject *args) -{ - PyObject *result; /* Localisation à retourner */ - GLineGenerator *generator; /* Version native */ - gint x; /* Position géographique */ - size_t index; /* Indice dans le tampon */ - size_t repeat; /* Utilisations successives */ - int ret; /* Bilan de lecture des args. */ - vmpa2t addr; /* Adresse visée par l'opérat° */ - - generator = G_LOADED_PANEL(pygobject_get(self)); - - ret = PyArg_ParseTuple(args, "ikk", &x, &index, &repeat); - if (!ret) return NULL; - - g_loaded_panel_compute_addr(generator, x, &addr, index, repeat); - - result = build_from_internal_vmpa(&addr); - - return result; - -} - -#endif - - - - - - - - - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit un accès à une définition de type à diffuser. * -* * -* Retour : Définition d'objet pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyTypeObject *get_python_loaded_panel_type(void) -{ - static PyMethodDef py_loaded_panel_methods[] = { - /* - { - "compute_addr", py_loaded_panel_compute_addr, - METH_VARARGS, - "compute_addr($self, x, index, repeat, /)\n--\n\nReturn the position at a given location." - }, - */ - { NULL } - }; - - static PyGetSetDef py_loaded_panel_getseters[] = { - { NULL } - }; - - static PyTypeObject py_loaded_panel_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.glibext.LoadedPanel", - //.tp_basicsize = sizeof(PyGObject), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyChrysalide loaded panel", - - .tp_methods = py_loaded_panel_methods, - .tp_getset = py_loaded_panel_getseters, - - }; - - return &py_loaded_panel_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.glibext.LoadedPanel'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_loaded_panel(PyObject *module) -{ - PyTypeObject *py_loaded_panel_type; /* Type Python 'LineGenerator' */ - PyObject *dict; /* Dictionnaire du module */ - - py_loaded_panel_type = get_python_loaded_panel_type(); - - dict = PyModule_GetDict(module); - pyg_register_interface(dict, "LoadedPanel", G_TYPE_LOADED_PANEL, py_loaded_panel_type); - - return true; - -} diff --git a/plugins/pychrysa/glibext/loadedpanel.h b/plugins/pychrysa/glibext/loadedpanel.h deleted file mode 100644 index a133983..0000000 --- a/plugins/pychrysa/glibext/loadedpanel.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * loadedpanel.h - prototypes pour l'équivalent Python du fichier "glibext/gloadedpanel.h" - * - * Copyright (C) 2017 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_PYCHRYSA_GLIBEXT_LOADEDPANEL_H -#define _PLUGINS_PYCHRYSA_GLIBEXT_LOADEDPANEL_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_loaded_panel_type(void); - -/* Prend en charge l'objet 'pychrysalide.glibext.LoadedPanel'. */ -bool register_python_loaded_panel(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSA_GLIBEXT_LOADEDPANEL_H */ diff --git a/plugins/pychrysa/glibext/module.c b/plugins/pychrysa/glibext/module.c deleted file mode 100644 index a3b0a25..0000000 --- a/plugins/pychrysa/glibext/module.c +++ /dev/null @@ -1,103 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * module.c - intégration du répertoire glibext en tant que module - * - * Copyright (C) 2012-2017 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 "module.h" - - -#include - - -#include "buffercache.h" -#include "bufferline.h" -#include "configuration.h" -#include "linegen.h" -#include "loadedpanel.h" -#include "../access.h" - - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute le module 'glibext' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool add_glibext_module_to_python_module(PyObject *super) -{ - bool result; /* Bilan à retourner */ - PyObject *module; /* Sous-module mis en place */ - int ret; /* Bilan d'un appel */ - - static PyModuleDef py_chrysalide_glibext_module = { - - .m_base = PyModuleDef_HEAD_INIT, - - .m_name = "pychrysalide.glibext", - .m_doc = "Python module for Chrysalide.glibext", - - .m_size = -1, - - }; - - result = false; - - module = PyModule_Create(&py_chrysalide_glibext_module); - if (module == NULL) return false; - - ret = PyState_AddModule(super, &py_chrysalide_glibext_module); - if (ret != 0) goto agmtpm_exit; - - ret = _PyImport_FixupBuiltin(module, "pychrysalide.glibext"); - if (ret != 0) goto agmtpm_exit; - - Py_INCREF(module); - ret = PyModule_AddObject(super, "glibext", module); - if (ret != 0) goto agmtpm_exit; - - result = true; - - result &= register_python_buffer_cache(module); - result &= register_python_buffer_line(module); - result &= register_python_config_param(module); - result &= register_python_config_param_iterator(module); - result &= register_python_generic_config(module); - result &= register_python_line_generator(module); - result &= register_python_loaded_panel(module); - - if (result) - register_access_to_python_module("pychrysalide.glibext", module); - - agmtpm_exit: - - assert(result); - - return result; - -} diff --git a/plugins/pychrysa/glibext/module.h b/plugins/pychrysa/glibext/module.h deleted file mode 100644 index 5a29cca..0000000 --- a/plugins/pychrysa/glibext/module.h +++ /dev/null @@ -1,39 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * module.h - prototypes pour l'intégration du répertoire glibext en tant que module - * - * Copyright (C) 2012-2017 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_GLIBEXT_MODULE_H -#define _PLUGINS_PYCHRYSALIDE_GLIBEXT_MODULE_H - - -#include -#include - - - -/* Ajoute le module 'glibext' au module Python. */ -bool add_glibext_module_to_python_module(PyObject *); - - - -#endif /* _PLUGINS_PYOIDA_GLIBEXT_MODULE_H */ diff --git a/plugins/pychrysa/gtkext/Makefile.am b/plugins/pychrysa/gtkext/Makefile.am deleted file mode 100644 index 4a36e63..0000000 --- a/plugins/pychrysa/gtkext/Makefile.am +++ /dev/null @@ -1,18 +0,0 @@ - -noinst_LTLIBRARIES = libpychrysagtkext.la - -libpychrysagtkext_la_SOURCES = \ - blockdisplay.h blockdisplay.c \ - bufferdisplay.h bufferdisplay.c \ - displaypanel.h displaypanel.c \ - dockable.h dockable.c \ - module.h module.c - - -libpychrysagtkext_la_LDFLAGS = - - -AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ - -I../../../src - -AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) diff --git a/plugins/pychrysa/gtkext/blockdisplay.c b/plugins/pychrysa/gtkext/blockdisplay.c deleted file mode 100644 index c2ccfbb..0000000 --- a/plugins/pychrysa/gtkext/blockdisplay.c +++ /dev/null @@ -1,115 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * blockdisplay.c - prototypes pour l'équivalent Python du fichier "gtkext/gtkblockdisplay.c" - * - * Copyright (C) 2016-2017 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 "blockdisplay.h" - - -#include -#include - - -#include - - -#include "bufferdisplay.h" -#include "../helpers.h" - - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit un accès à une définition de type à diffuser. * -* * -* Retour : Définition d'objet pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyTypeObject *get_python_block_display_type(void) -{ - static PyMethodDef py_block_display_methods[] = { - { NULL } - }; - - static PyGetSetDef py_block_display_getseters[] = { - { NULL } - }; - - static PyTypeObject py_block_display_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.gtkext.BlockDisplay", - .tp_basicsize = sizeof(PyGObject), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyChrysalide block display.", - - .tp_methods = py_block_display_methods, - .tp_getset = py_block_display_getseters - - }; - - static PyTypeObject *result = NULL; - - if (result == NULL) - result = define_python_dynamic_type(&py_block_display_type); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.gtkext.BlockDisplay'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_block_display(PyObject *module) -{ - bool result; /* Bilan à retourner */ - PyTypeObject *py_block_display_type; /* Type Python 'BlockDisplay' */ - PyObject *dict; /* Dictionnaire du module */ - - py_block_display_type = get_python_block_display_type(); - - dict = PyModule_GetDict(module); - - result = register_class_for_pygobject(dict, GTK_TYPE_BLOCK_DISPLAY, - py_block_display_type, get_python_buffer_display_type()); - - return result; - -} diff --git a/plugins/pychrysa/gtkext/blockdisplay.h b/plugins/pychrysa/gtkext/blockdisplay.h deleted file mode 100644 index e4636a3..0000000 --- a/plugins/pychrysa/gtkext/blockdisplay.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * blockdisplay.h - prototypes pour l'équivalent Python du fichier "gtkext/gtkblockdisplay.h" - * - * Copyright (C) 2016-2017 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_PYCHRYSA_GTKEXT_BLOCKDISPLAY_H -#define _PLUGINS_PYCHRYSA_GTKEXT_BLOCKDISPLAY_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_block_display_type(void); - -/* Prend en charge l'objet 'pychrysalide.gtkext.BlockDisplay'. */ -bool register_python_block_display(PyObject *module); - - - -#endif /* _PLUGINS_PYCHRYSA_GTKEXT_BLOCKDISPLAY_H */ diff --git a/plugins/pychrysa/gtkext/bufferdisplay.c b/plugins/pychrysa/gtkext/bufferdisplay.c deleted file mode 100644 index 9aa1bca..0000000 --- a/plugins/pychrysa/gtkext/bufferdisplay.c +++ /dev/null @@ -1,115 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * bufferdisplay.c - prototypes pour l'équivalent Python du fichier "gtkext/gtkbufferdisplay.c" - * - * Copyright (C) 2016-2017 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 "bufferdisplay.h" - - -#include -#include - - -#include - - -#include "displaypanel.h" -#include "../helpers.h" - - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit un accès à une définition de type à diffuser. * -* * -* Retour : Définition d'objet pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyTypeObject *get_python_buffer_display_type(void) -{ - static PyMethodDef py_buffer_display_methods[] = { - { NULL } - }; - - static PyGetSetDef py_buffer_display_getseters[] = { - { NULL } - }; - - static PyTypeObject py_buffer_display_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.gtkext.BufferDisplay", - .tp_basicsize = sizeof(PyGObject), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyChrysalide buffer display.", - - .tp_methods = py_buffer_display_methods, - .tp_getset = py_buffer_display_getseters - - }; - - static PyTypeObject *result = NULL; - - if (result == NULL) - result = define_python_dynamic_type(&py_buffer_display_type); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.gtkext.Bufferdisplay'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_buffer_display(PyObject *module) -{ - bool result; /* Bilan à retourner */ - PyTypeObject *py_buffer_display_type; /* Type Python 'BufferDisplay' */ - PyObject *dict; /* Dictionnaire du module */ - - py_buffer_display_type = get_python_buffer_display_type(); - - dict = PyModule_GetDict(module); - - result = register_class_for_pygobject(dict, GTK_TYPE_BUFFER_DISPLAY, - py_buffer_display_type, get_python_display_panel_type()); - - return result; - -} diff --git a/plugins/pychrysa/gtkext/bufferdisplay.h b/plugins/pychrysa/gtkext/bufferdisplay.h deleted file mode 100644 index b0cbd6c..0000000 --- a/plugins/pychrysa/gtkext/bufferdisplay.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * bufferdisplay.h - prototypes pour l'équivalent Python du fichier "gtkext/gtkbufferdisplay.h" - * - * Copyright (C) 2016-2017 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_PYCHRYSA_GTKEXT_BUFFERDISPLAY_H -#define _PLUGINS_PYCHRYSA_GTKEXT_BUFFERDISPLAY_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_buffer_display_type(void); - -/* Prend en charge l'objet 'pychrysalide.gtkext.BufferDisplay'. */ -bool register_python_buffer_display(PyObject *module); - - - -#endif /* _PLUGINS_PYCHRYSA_GTKEXT_BUFFERDISPLAY_H */ diff --git a/plugins/pychrysa/gtkext/displaypanel.c b/plugins/pychrysa/gtkext/displaypanel.c deleted file mode 100644 index b75d173..0000000 --- a/plugins/pychrysa/gtkext/displaypanel.c +++ /dev/null @@ -1,269 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * displaypanel.c - prototypes pour l'équivalent Python du fichier "gtkext/gtkdisplaypanel.c" - * - * Copyright (C) 2016-2017 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 "displaypanel.h" - - -#include -#include - - -#include - - -#include "../helpers.h" -#include "../arch/vmpa.h" - - - -/* Crée un nouvel objet Python de type 'DisplayPanel'. */ -#if 0 -static PyObject *py_display_panel_new(PyTypeObject *, PyObject *, PyObject *); -#endif - -/* S'assure qu'une adresse donnée est visible à l'écran. */ -static PyObject *py_display_panel_scroll_to_address(PyObject *, PyObject *); - -/* Définit les constantes pour les panneaux de vue. */ -static bool py_display_panel_define_constants(PyTypeObject *); - - - -/****************************************************************************** -* * -* Paramètres : type = type de l'objet à instancier. * -* args = arguments fournis à l'appel. * -* kwds = arguments de type key=val fournis. * -* * -* Description : Crée un nouvel objet Python de type 'DisplayPanel'. * -* * -* Retour : Instance Python mise en place. * -* * -* Remarques : - * -* * -******************************************************************************/ -#if 0 -static PyObject *py_display_panel_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ -#if 0 - PyObject *result; /* Instance à retourner */ - const char *name; /* Désignation humaine */ - const char *lname; /* Nom version longue */ - PyGObject *widget; /* Composant visuel du panneau */ - const char *path; /* Placement à l'affichage */ - int ret; /* Bilan de lecture des args. */ - GEditorItem *item; /* Version GLib du format */ - - ret = PyArg_ParseTuple(args, "ssOs", &name, &lname, &widget, &path); - if (!ret) Py_RETURN_NONE; - - item = g_view_panel_new(name, lname, - GTK_WIDGET(pygobject_get(widget)), path); - - result = py_display_panel_from_c(G_DISPLAY_PANEL(item)); - g_object_unref(item); - - return (PyObject *)result; -#endif - - /* FIXME */ - - - Py_RETURN_NONE; - -} -#endif - - -/****************************************************************************** -* * -* Paramètres : self = classe représentant un tampon de code. * -* args = arguments fournis à l'appel. * -* * -* Description : S'assure qu'une adresse donnée est visible à l'écran. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_display_panel_scroll_to_address(PyObject *self, PyObject *args) -{ - GtkDisplayPanel *panel; /* Panneau à manipuler */ - PyObject *py_vmpa; /* Localisation version Python */ - int ret; /* Bilan de lecture des args. */ - vmpa2t *addr; /* Adresse visée par l'opérat° */ - - ret = PyArg_ParseTuple(args, "O", &py_vmpa); - if (!ret) return NULL; - - ret = PyObject_IsInstance(py_vmpa, (PyObject *)get_python_vmpa_type()); - if (!ret) return NULL; - - addr = get_internal_vmpa(py_vmpa); - if (addr == NULL) return NULL; - - panel = GTK_DISPLAY_PANEL(pygobject_get(self)); - - // FIXME - //gtk_display_panel_scroll_to_address(panel, addr, SPT_RAW); - - Py_RETURN_NONE; - -} - - -/****************************************************************************** -* * -* Paramètres : obj_type = type dont le dictionnaire est à compléter. * -* * -* Description : Définit les constantes pour les panneaux de vue. * -* * -* Retour : true en cas de succès de l'opération, false sinon. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool py_display_panel_define_constants(PyTypeObject *obj_type) -{ - bool result; /* Bilan à retourner */ - - result = true; - - result &= PyDict_AddIntMacro(obj_type, SPT_RAW); - result &= PyDict_AddIntMacro(obj_type, SPT_TOP); - result &= PyDict_AddIntMacro(obj_type, SPT_CENTER); - result &= PyDict_AddIntMacro(obj_type, SPT_BOTTOM); - - 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_display_panel_type(void) -{ - static PyMethodDef py_display_panel_methods[] = { - { - "scroll_to_address", (PyCFunction)py_display_panel_scroll_to_address, - METH_VARARGS, - "scroll_to_address($self, addr, tweak, /)\n--\n\nEnsure a given address is displayed in the view panel." - }, - { NULL } - }; - - static PyGetSetDef py_display_panel_getseters[] = { - { NULL } - }; - - static PyTypeObject py_display_panel_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.gtkext.DisplayPanel", - .tp_basicsize = sizeof(PyGObject), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyChrysalide view panel.", - - .tp_methods = py_display_panel_methods, - .tp_getset = py_display_panel_getseters, - //.tp_new = (newfunc)py_display_panel_new, - //.tp_init = (initproc)pychrysalide_allow_args_for_gobjects - - }; - - static PyTypeObject *result = NULL; - - if (result == NULL) - result = define_python_dynamic_type(&py_display_panel_type); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.gtkext.DisplayPanel'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_display_panel(PyObject *module) -{ - bool result; /* Bilan à retourner */ - PyTypeObject *py_display_panel_type; /* Type Python 'DisplayPanel' */ - PyObject *parent_mod; /* Module Python Fixed */ - PyObject *fixed; /* Module "GtkFixed" */ - PyObject *dict; /* Dictionnaire du module */ - - result = false; - - py_display_panel_type = get_python_display_panel_type(); - - parent_mod = PyImport_ImportModule("gi.repository.Gtk"); - - if (parent_mod == NULL) - goto rpdp_exit; - - fixed = PyObject_GetAttrString(parent_mod, "Fixed"); - - Py_DECREF(parent_mod); - - dict = PyModule_GetDict(module); - - result = register_class_for_pygobject(dict, GTK_TYPE_DISPLAY_PANEL, - py_display_panel_type, (PyTypeObject *)fixed); - Py_DECREF(fixed); - - if (!result) - goto rpdp_exit; - - result = py_display_panel_define_constants(py_display_panel_type); - - rpdp_exit: - - return result; - -} diff --git a/plugins/pychrysa/gtkext/displaypanel.h b/plugins/pychrysa/gtkext/displaypanel.h deleted file mode 100644 index c6787df..0000000 --- a/plugins/pychrysa/gtkext/displaypanel.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * displaypanel.h - prototypes pour l'équivalent Python du fichier "gtkext/gtkdisplaypanel.h" - * - * Copyright (C) 2016-2017 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_PYCHRYSA_GTKEXT_DISPLAYPANEL_H -#define _PLUGINS_PYCHRYSA_GTKEXT_DISPLAYPANEL_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_display_panel_type(void); - -/* Prend en charge l'objet 'pychrysalide.gtkext.DisplayPanel'. */ -bool register_python_display_panel(PyObject *module); - - - -#endif /* _PLUGINS_PYCHRYSA_GTKEXT_DISPLAYPANEL_H */ diff --git a/plugins/pychrysa/gtkext/dockable.c b/plugins/pychrysa/gtkext/dockable.c deleted file mode 100644 index 9c66159..0000000 --- a/plugins/pychrysa/gtkext/dockable.c +++ /dev/null @@ -1,102 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * dockable.c - équivalent Python du fichier "gtkext/gtkdockable.c" - * - * Copyright (C) 2017 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 "dockable.h" - - -#include - - -#include - - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit un accès à une définition de type à diffuser. * -* * -* Retour : Définition d'objet pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyTypeObject *get_python_gtk_dockable_type(void) -{ - static PyMethodDef py_gtk_dockable_methods[] = { - { NULL } - }; - - static PyGetSetDef py_gtk_dockable_getseters[] = { - { NULL } - }; - - static PyTypeObject py_gtk_dockable_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.gtkext.GtkDockable", - //.tp_basicsize = sizeof(PyGObject), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyChrysalide interface for Gtk dockable widgets", - - .tp_methods = py_gtk_dockable_methods, - .tp_getset = py_gtk_dockable_getseters, - - }; - - return &py_gtk_dockable_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.gtkext.GtkDockable'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_gtk_dockable(PyObject *module) -{ - PyTypeObject *py_gtk_dockable_type; /* Type Python 'LineGenerator' */ - PyObject *dict; /* Dictionnaire du module */ - - py_gtk_dockable_type = get_python_gtk_dockable_type(); - - dict = PyModule_GetDict(module); - pyg_register_interface(dict, "LineGenerator", GTK_TYPE_DOCKABLE, py_gtk_dockable_type); - - return true; - -} diff --git a/plugins/pychrysa/gtkext/dockable.h b/plugins/pychrysa/gtkext/dockable.h deleted file mode 100644 index 1709966..0000000 --- a/plugins/pychrysa/gtkext/dockable.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * dockable.h - prototypes pour l'équivalent Python du fichier "gtkext/gtkdockable.h" - * - * Copyright (C) 2017 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_PYCHRYSA_GTKEXT_DOCKABLE_H -#define _PLUGINS_PYCHRYSA_GTKEXT_DOCKABLE_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_gtk_dockable_type(void); - -/* Prend en charge l'objet 'pychrysalide.gtkext.GtkDockable'. */ -bool register_python_gtk_dockable(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSA_GTKEXT_DOCKABLE_H */ diff --git a/plugins/pychrysa/gtkext/module.c b/plugins/pychrysa/gtkext/module.c deleted file mode 100644 index 8b2cc5e..0000000 --- a/plugins/pychrysa/gtkext/module.c +++ /dev/null @@ -1,95 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * module.c - intégration du répertoire gtkext en tant que module - * - * Copyright (C) 2012-2017 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 "module.h" - - -#include - - -#include "blockdisplay.h" -#include "bufferdisplay.h" -#include "displaypanel.h" -#include "dockable.h" - - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute le module 'gtkext' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool add_gtkext_module_to_python_module(PyObject *super) -{ - bool result; /* Bilan à retourner */ - PyObject *module; /* Sous-module mis en place */ - int ret; /* Bilan d'un appel */ - - static PyModuleDef py_chrysalide_gtkext_module = { - - .m_base = PyModuleDef_HEAD_INIT, - - .m_name = "pychrysalide.gtkext", - .m_doc = "Python module for Chrysalide.gtkext", - - .m_size = -1, - - }; - - result = false; - - module = PyModule_Create(&py_chrysalide_gtkext_module); - if (module == NULL) return false; - - ret = PyState_AddModule(super, &py_chrysalide_gtkext_module); - if (ret != 0) goto agmtpm_exit; - - ret = _PyImport_FixupBuiltin(module, "pychrysalide.gtkext"); - if (ret != 0) goto agmtpm_exit; - - Py_INCREF(module); - ret = PyModule_AddObject(super, "gtkext", module); - if (ret != 0) goto agmtpm_exit; - - result = true; - - result &= register_python_display_panel(module); - result &= register_python_buffer_display(module); - result &= register_python_block_display(module); - result &= register_python_gtk_dockable(module); - - agmtpm_exit: - - assert(result); - - return result; - -} diff --git a/plugins/pychrysa/gtkext/module.h b/plugins/pychrysa/gtkext/module.h deleted file mode 100644 index a58aed0..0000000 --- a/plugins/pychrysa/gtkext/module.h +++ /dev/null @@ -1,39 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * module.h - prototypes pour l'intégration du répertoire gtkext en tant que module - * - * Copyright (C) 2012-2017 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_PYOIDA_GTKEXT_MODULE_H -#define _PLUGINS_PYOIDA_GTKEXT_MODULE_H - - -#include -#include - - - -/* Ajoute le module 'gtkext' au module Python. */ -bool add_gtkext_module_to_python_module(PyObject *); - - - -#endif /* _PLUGINS_PYOIDA_GTKEXT_MODULE_H */ diff --git a/plugins/pychrysa/gui/Makefile.am b/plugins/pychrysa/gui/Makefile.am deleted file mode 100644 index d4a724d..0000000 --- a/plugins/pychrysa/gui/Makefile.am +++ /dev/null @@ -1,19 +0,0 @@ - -noinst_LTLIBRARIES = libpychrysagui.la - -libpychrysagui_la_SOURCES = \ - editem.h editem.c \ - module.h module.c - -libpychrysagui_la_LIBADD = \ - panels/libpychrysaguipanels.la - -libpychrysagui_la_LDFLAGS = - - -AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ - -I../../../src - -AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) - -SUBDIRS = panels diff --git a/plugins/pychrysa/gui/editem.c b/plugins/pychrysa/gui/editem.c deleted file mode 100644 index 91f5246..0000000 --- a/plugins/pychrysa/gui/editem.c +++ /dev/null @@ -1,370 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * editem.c - prototypes pour l'équivalent Python du fichier "gui/editem.c" - * - * Copyright (C) 2012-2017 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 "editem.h" - - -#include - - -#include - - -#include "../helpers.h" - - -#include "../analysis/binary.h" -#include "../gtkext/displaypanel.h" - - - -/* Réagit à un changement du binaire courant. */ -static void _update_editor_item_for_binary_python_wrapper(GEditorItem *, GLoadedBinary *); - -/* Réagit à un changement de vue. */ -static void _update_editor_item_for_view_python_wrapper(GEditorItem *, GtkDisplayPanel *); - -/* Réagit à un changement de contenu. */ -static void _update_editor_item_for_view_content_python_wrapper(GEditorItem *, GtkDisplayPanel *); - -/* Réagit à un changement du binaire courant. */ -static PyObject *py_editor_item_update_for_binary(PyObject *, PyObject *); - -/* Réagit à un changement d'affichage principal de contenu. */ -static PyObject *py_editor_item_update_for_view(PyObject *, PyObject *); - -/* Réagit à un changement d'affichage principal de contenu. */ -static PyObject *py_editor_item_update_for_content(PyObject *, PyObject *); - -/* Procède à l'enregistrement d'un élément reactif de l'éditeur. */ -static PyObject *py_editor_item_register(PyObject *, PyObject *); - - - -/****************************************************************************** -* * -* Paramètres : item = élément à actualiser. * -* binary = nouvelle instance de binaire analysé. * -* * -* Description : Réagit à un changement du binaire courant. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void _update_editor_item_for_binary_python_wrapper(GEditorItem *item, GLoadedBinary *binary) -{ - PyObject *target; /* Version Python de l'élément */ - PyObject *args; /* Arguments pour l'appel */ - PyObject *value; /* Retour obtenu */ - - /** - * Normalement, l'objet Python est enregistré dans la liste de Chrysalide - * des éléments d'éditeur, via py_editor_item_register(), donc son compteur - * de références doit le maintenir en vie. - * - * On peut donc le récupérer directement depuis l'instance GLib, sans passer - * par la procédure de pygobject, qui obligerait à connaître le type précis - * de l'instance GLib manipulée. - */ - target = pygobject_new(G_OBJECT(item)); - - args = PyTuple_New(1); - PyTuple_SetItem(args, 0, pygobject_new(G_OBJECT(binary))); - - value = run_python_method(target, "update_for_binary", args); - - Py_XDECREF(value); - Py_DECREF(args); - Py_DECREF(target); - -} - - -/****************************************************************************** -* * -* Paramètres : item = élément à actualiser. * -* panel = nouveau panneau d'affichage actif. * -* * -* Description : Réagit à un changement de vue. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void _update_editor_item_for_view_python_wrapper(GEditorItem *item, GtkDisplayPanel *panel) -{ - PyObject *target; /* Version Python de l'élément */ - PyObject *args; /* Arguments pour l'appel */ - PyObject *value; /* Retour obtenu */ - - /** - * Normalement, l'objet Python est enregistré dans la liste de Chrysalide - * des éléments d'éditeur, via py_editor_item_register(), donc son compteur - * de références doit le maintenir en vie. - * - * On peut donc le récupérer directement depuis l'instane GLib, sans passer - * par la procédure de pygobject, qui obligerait à connaître le type précis - * de l'instance GLib manipulée. - */ - target = pygobject_new(G_OBJECT(item)); - - args = PyTuple_New(1); - PyTuple_SetItem(args, 0, pygobject_new(G_OBJECT(panel))); - - value = run_python_method(target, "update_for_view", args); - - Py_XDECREF(value); - Py_DECREF(args); - Py_DECREF(target); - -} - - -/****************************************************************************** -* * -* Paramètres : item = élément à actualiser. * -* panel = nouveau panneau d'affichage actif. * -* * -* Description : Réagit à un changement de contenu. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void _update_editor_item_for_view_content_python_wrapper(GEditorItem *item, GtkDisplayPanel *panel) -{ - PyObject *target; /* Version Python de l'élément */ - PyObject *args; /* Arguments pour l'appel */ - PyObject *value; /* Retour obtenu */ - - /** - * Normalement, l'objet Python est enregistré dans la liste de Chrysalide - * des éléments d'éditeur, via py_editor_item_register(), donc son compteur - * de références doit le maintenir en vie. - * - * On peut donc le récupérer directement depuis l'instane GLib, sans passer - * par la procédure de pygobject, qui obligerait à connaître le type précis - * de l'instance GLib manipulée. - */ - target = pygobject_new(G_OBJECT(item)); - - args = PyTuple_New(1); - PyTuple_SetItem(args, 0, pygobject_new(G_OBJECT(panel))); - - value = run_python_method(target, "update_for_content", args); - - Py_XDECREF(value); - Py_DECREF(args); - Py_DECREF(target); - -} - - -/****************************************************************************** -* * -* Paramètres : self = classe représentant un binaire. * -* args = arguments fournis à l'appel. * -* * -* Description : Réagit à un changement du binaire courant. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_editor_item_update_for_binary(PyObject *self, PyObject *args) -{ - Py_RETURN_NONE; - -} - - -/****************************************************************************** -* * -* Paramètres : self = classe représentant un binaire. * -* args = arguments fournis à l'appel. * -* * -* Description : Réagit à un changement d'affichage principal de contenu. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_editor_item_update_for_view(PyObject *self, PyObject *args) -{ - Py_RETURN_NONE; - -} - - -/****************************************************************************** -* * -* Paramètres : self = classe représentant un binaire. * -* args = arguments fournis à l'appel. * -* * -* Description : Réagit à un changement d'affichage principal de contenu. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_editor_item_update_for_content(PyObject *self, PyObject *args) -{ - Py_RETURN_NONE; - -} - - -/****************************************************************************** -* * -* Paramètres : self = classe représentant un binaire. * -* args = arguments fournis à l'appel. * -* * -* Description : Procède à l'enregistrement d'un élément reactif de l'éditeur.* -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_editor_item_register(PyObject *self, PyObject *args) -{ - GEditorItem *item; /* Version GLib de l'élément */ - - item = G_EDITOR_ITEM(pygobject_get(self)); - - //item->update_binary = _update_editor_item_for_binary_python_wrapper; - //item->update_view = _update_editor_item_for_view_python_wrapper; - //item->update_content = _update_editor_item_for_view_content_python_wrapper; - - Py_INCREF(self); - register_editor_item(item); - - Py_RETURN_NONE; - -} - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit un accès à une définition de type à diffuser. * -* * -* Retour : Définition d'objet pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyTypeObject *get_python_editor_item_type(void) -{ - static PyMethodDef py_editor_item_methods[] = { - { - "update_for_binary", (PyCFunction)py_editor_item_update_for_binary, - METH_VARARGS, - "Called by Chrysalide on each binary change, if the item is registered." - }, - { - "update_for_view", (PyCFunction)py_editor_item_update_for_view, - METH_VARARGS, - "Called by Chrysalide on each view change, if the item is registered." - }, - { - "update_for_content", (PyCFunction)py_editor_item_update_for_content, - METH_VARARGS, - "Called by Chrysalide on each view content change, if the item is registered." - }, - { - "register", (PyCFunction)py_editor_item_register, - METH_NOARGS, - "register($self, /)\n--\n\nRegister the item as editor item." - }, - { NULL } - }; - - static PyGetSetDef py_editor_item_getseters[] = { - { NULL } - }; - - static PyTypeObject py_editor_item_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.gui.EditorItem", - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyChrysalide editor item", - - .tp_methods = py_editor_item_methods, - .tp_getset = py_editor_item_getseters, - - }; - - return &py_editor_item_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.gui.EditorItem'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_editor_item(PyObject *module) -{ - PyTypeObject *py_editor_item_type; /* Type Python 'LoadedBinary' */ - PyObject *dict; /* Dictionnaire du module */ - - py_editor_item_type = get_python_editor_item_type(); - - dict = PyModule_GetDict(module); - - if (!register_class_for_pygobject(dict, G_TYPE_EDITOR_ITEM, py_editor_item_type, &PyGObject_Type)) - return false; - - return true; - -} diff --git a/plugins/pychrysa/gui/editem.h b/plugins/pychrysa/gui/editem.h deleted file mode 100644 index b6b3daf..0000000 --- a/plugins/pychrysa/gui/editem.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * editem.h - prototypes pour l'équivalent Python du fichier "gui/editem.h" - * - * Copyright (C) 2012-2017 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_PYCHRYSA_GUI_EDITEM_H -#define _PLUGINS_PYCHRYSA_GUI_EDITEM_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_editor_item_type(void); - -/* Prend en charge l'objet 'pychrysalide.gui.EditorItem'. */ -bool register_python_editor_item(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSA_GUI_EDITEM_H */ diff --git a/plugins/pychrysa/gui/module.c b/plugins/pychrysa/gui/module.c deleted file mode 100644 index 192b1e6..0000000 --- a/plugins/pychrysa/gui/module.c +++ /dev/null @@ -1,97 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * module.c - intégration du répertoire gui en tant que module - * - * Copyright (C) 2012-2017 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 "module.h" - - -#include - - - -#include "editem.h" -#include "panels/module.h" -#include "../access.h" - - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute le module 'gui' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool add_gui_module_to_python_module(PyObject *super) -{ - bool result; /* Bilan à retourner */ - PyObject *module; /* Sous-module mis en place */ - int ret; /* Bilan d'un appel */ - - static PyModuleDef py_chrysalide_gui_module = { - - .m_base = PyModuleDef_HEAD_INIT, - - .m_name = "pychrysalide.gui", - .m_doc = "Python module for the Chrysalide GUI", - - .m_size = -1, - - }; - - result = false; - - module = PyModule_Create(&py_chrysalide_gui_module); - if (module == NULL) return false; - - ret = PyState_AddModule(super, &py_chrysalide_gui_module); - if (ret != 0) goto loading_failed; - - ret = _PyImport_FixupBuiltin(module, "pychrysalide.gui"); - if (ret != 0) goto loading_failed; - - Py_INCREF(module); - ret = PyModule_AddObject(super, "gui", module); - if (ret != 0) goto loading_failed; - - result = true; - - result &= register_python_editor_item(module); - - result &= add_gui_panels_module_to_python_module(module); - - if (result) - register_access_to_python_module("pychrysalide.gui", module); - - loading_failed: - - assert(result); - - return result; - -} diff --git a/plugins/pychrysa/gui/module.h b/plugins/pychrysa/gui/module.h deleted file mode 100644 index 22acc15..0000000 --- a/plugins/pychrysa/gui/module.h +++ /dev/null @@ -1,39 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * module.h - prototypes pour l'intégration du répertoire gui en tant que module - * - * Copyright (C) 2012-2017 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_PYCHRYSA_GUI_MODULE_H -#define _PLUGINS_PYCHRYSA_GUI_MODULE_H - - -#include -#include - - - -/* Ajoute le module 'gui' au module Python. */ -bool add_gui_module_to_python_module(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSA_GUI_MODULE_H */ diff --git a/plugins/pychrysa/gui/panels/Makefile.am b/plugins/pychrysa/gui/panels/Makefile.am deleted file mode 100644 index 99e4c3f..0000000 --- a/plugins/pychrysa/gui/panels/Makefile.am +++ /dev/null @@ -1,15 +0,0 @@ - -noinst_LTLIBRARIES = libpychrysaguipanels.la - -libpychrysaguipanels_la_SOURCES = \ - module.h module.c \ - panel.h panel.c - - -libpychrysaguipanels_la_LDFLAGS = - - -AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ - -I../../../../src - -AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) diff --git a/plugins/pychrysa/gui/panels/module.c b/plugins/pychrysa/gui/panels/module.c deleted file mode 100644 index 21b487e..0000000 --- a/plugins/pychrysa/gui/panels/module.c +++ /dev/null @@ -1,93 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * module.c - intégration du répertoire panels en tant que module - * - * Copyright (C) 2012-2017 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 "module.h" - - -#include - - -#include "panel.h" -#include "../../access.h" - - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Ajoute le module 'gui.panels' au module Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool add_gui_panels_module_to_python_module(PyObject *super) -{ - bool result; /* Bilan à retourner */ - PyObject *module; /* Sous-module mis en place */ - int ret; /* Bilan d'un appel */ - - static PyModuleDef py_chrysalide_panels_module = { - - .m_base = PyModuleDef_HEAD_INIT, - - .m_name = "gui.analysis.panels", - .m_doc = "Python module for Chrysalide.gui.panels", - - .m_size = -1, - - }; - - result = false; - - module = PyModule_Create(&py_chrysalide_panels_module); - if (module == NULL) return false; - - ret = PyState_AddModule(super, &py_chrysalide_panels_module); - if (ret != 0) goto loading_failed; - - ret = _PyImport_FixupBuiltin(module, "pychrysalide.gui.panels"); - if (ret != 0) goto loading_failed; - - Py_INCREF(module); - ret = PyModule_AddObject(super, "panels", module); - if (ret != 0) goto loading_failed; - - result = true; - - result &= register_python_panel_item(module); - - if (result) - register_access_to_python_module("pychrysalide.gui.panels", module); - - loading_failed: - - assert(result); - - return result; - -} diff --git a/plugins/pychrysa/gui/panels/module.h b/plugins/pychrysa/gui/panels/module.h deleted file mode 100644 index 542754b..0000000 --- a/plugins/pychrysa/gui/panels/module.h +++ /dev/null @@ -1,39 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * module.h - prototypes pour l'intégration du répertoire panels en tant que module - * - * Copyright (C) 2012-2017 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_PYCHRYSA_GUI_PANELS_MODULE_H -#define _PLUGINS_PYCHRYSA_GUI_PANELS_MODULE_H - - -#include -#include - - - -/* Ajoute le module 'gui.panels' au module Python. */ -bool add_gui_panels_module_to_python_module(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSA_GUI_PANELS_MODULE_H */ diff --git a/plugins/pychrysa/gui/panels/panel.c b/plugins/pychrysa/gui/panels/panel.c deleted file mode 100644 index 72c9e7e..0000000 --- a/plugins/pychrysa/gui/panels/panel.c +++ /dev/null @@ -1,244 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * panel.c - équivalent Python du fichier "gui/panels/panel.c" - * - * Copyright (C) 2012-2017 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 "panel.h" - - -#include - - -#include -#include -#include - - -#include "../editem.h" -#include "../../helpers.h" -#include "../../gtkext/dockable.h" - - - -/* Initialise une instance sur la base du dérivé de GObject. */ -static int py_panel_item_init(PyObject *self, PyObject *args, PyObject *kwds); - -/* Place un panneau dans l'ensemble affiché. */ -static PyObject *py_panel_item_dock(PyObject *, PyObject *); - -/* Définit les constantes pour les panneaux. */ -static bool py_panel_item_define_constants(PyTypeObject *); - - - -/****************************************************************************** -* * -* Paramètres : self = objet à initialiser (théoriquement). * -* args = arguments fournis à l'appel. * -* kwds = arguments de type key=val fournis. * -* * -* Description : Initialise une instance sur la base du dérivé de GObject. * -* * -* Retour : 0. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static int py_panel_item_init(PyObject *self, PyObject *args, PyObject *kwds) -{ - unsigned long personality; /* Nature du panneau */ - const char *name; /* Désignation humaine */ - const char *lname; /* Nom version longue */ - PyGObject *widget; /* Composant visuel du panneau */ - int startup; /* Recommandation au démarrage */ - const char *path; /* Placement à l'affichage */ - int ret; /* Bilan de lecture des args. */ - GPanelItem *item; /* Elément de l'éditeur */ - - ret = PyArg_ParseTuple(args, "kssOps", &personality, &name, &lname, &widget, &startup, &path); - if (!ret) return -1; - - item = g_panel_item_new(personality, name, lname, - GTK_WIDGET(pygobject_get(widget)), startup, path); - - /* FIXME ? Est-ce à l'utilisateur de s'enregistrer ? */ - register_panel_item(item, get_main_configuration()); - - /** - * Si Python ne voit plus la variable représentant le panneau utilisée, - * il va la supprimer, ce qui va supprimer le composant GTK. - * - * On sera donc en situation de Use-After-Free, dont les conséquences - * arrivent très vite. - */ - g_object_ref(GTK_WIDGET(pygobject_get(widget))); - Py_INCREF(self); - - /* Enregistrement auprès de PyGObject */ - - ((PyGObject *)self)->obj = G_OBJECT(item); - - pygobject_register_wrapper(self); - - return 0; - -} - - -/****************************************************************************** -* * -* Paramètres : self = classe représentant un binaire. * -* args = arguments fournis à l'appel. * -* * -* Description : Place un panneau dans l'ensemble affiché. * -* * -* Retour : Py_None. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_panel_item_dock(PyObject *self, PyObject *args) -{ - GPanelItem *item; /* Panneau à manipuler */ - - item = G_PANEL_ITEM(pygobject_get(self)); - - g_panel_item_dock(item); - - Py_RETURN_NONE; - -} - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Fournit un accès à une définition de type à diffuser. * -* * -* Retour : Définition d'objet pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyTypeObject *get_python_panel_item_type(void) -{ - static PyMethodDef py_panel_item_methods[] = { - { - "dock", (PyCFunction)py_panel_item_dock, - METH_NOARGS, - "dock($self, /)\n--\n\nDisplay the panel item in the right place." - }, - { NULL } - }; - - static PyGetSetDef py_panel_item_getseters[] = { - { NULL } - }; - - static PyTypeObject py_panel_item_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.gui.panels.PanelItem", - .tp_basicsize = sizeof(PyGObject), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyChrysalide panel item.", - - .tp_methods = py_panel_item_methods, - .tp_getset = py_panel_item_getseters, - .tp_init = (initproc)py_panel_item_init - - }; - - return &py_panel_item_type; - -} - - -/****************************************************************************** -* * -* Paramètres : obj_type = type dont le dictionnaire est à compléter. * -* * -* Description : Définit les constantes pour les panneaux. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool py_panel_item_define_constants(PyTypeObject *obj_type) -{ - bool result; /* Bilan à retourner */ - - result = true; - - result &= PyDict_AddIntMacro(obj_type, PIP_INVALID); - - result &= PyDict_AddIntMacro(obj_type, PIP_SINGLETON); - result &= PyDict_AddIntMacro(obj_type, PIP_BINARY_VIEW); - result &= PyDict_AddIntMacro(obj_type, PIP_OTHER); - - result &= PyDict_AddIntMacro(obj_type, PIP_COUNT); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.gui.panels.PanelItem'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_panel_item(PyObject *module) -{ - PyTypeObject *py_panel_item_type; /* Type Python 'LoadedBinary' */ - PyObject *dict; /* Dictionnaire du module */ - - py_panel_item_type = get_python_panel_item_type(); - - dict = PyModule_GetDict(module); - - if (!_register_class_for_pygobject(dict, G_TYPE_PANEL_ITEM, py_panel_item_type, - get_python_editor_item_type(), get_python_gtk_dockable_type(), NULL)) - return false; - - if (!py_panel_item_define_constants(py_panel_item_type)) - return false; - - return true; - -} diff --git a/plugins/pychrysa/gui/panels/panel.h b/plugins/pychrysa/gui/panels/panel.h deleted file mode 100644 index b10928c..0000000 --- a/plugins/pychrysa/gui/panels/panel.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * panel.h - prototypes pour l'équivalent Python du fichier "gui/panels/panel.h" - * - * Copyright (C) 2012-2017 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_PYCHRYSA_GUI_PANELS_PANEL_H -#define _PLUGINS_PYCHRYSA_GUI_PANELS_PANEL_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_panel_item_type(void); - -/* Prend en charge l'objet 'pychrysalide.gui.panels.PanelItem'. */ -bool register_python_panel_item(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSA_GUI_PANELS_PANEL_H */ diff --git a/plugins/pychrysa/helpers.c b/plugins/pychrysa/helpers.c deleted file mode 100644 index 17a396d..0000000 --- a/plugins/pychrysa/helpers.c +++ /dev/null @@ -1,473 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * helpers.c - simplification des interactions de base avec Python - * - * Copyright (C) 2012-2017 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 "helpers.h" - - -#include -#include -#include -#include - - - -/* ---------------------------------------------------------------------------------- */ -/* ACCELERATEURS POUR PYTHON UNIQUEMENT */ -/* ---------------------------------------------------------------------------------- */ - - -/****************************************************************************** -* * -* Paramètres : status = bilan de comparaison à traduire. * -* op = type de comparaison menée. * -* * -* Description : Traduit pour Python le bilan d'une comparaison riche. * -* * -* Retour : Objet Python à référencer. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyObject *status_to_rich_cmp_state(int status, int op) -{ - PyObject *result; /* Bilan àretourner */ - - switch (op) - { - case Py_LT: - result = status < 0 ? Py_True : Py_False; - break; - - case Py_LE: - result = status <= 0 ? Py_True : Py_False; - break; - - case Py_EQ: - result = status == 0 ? Py_True : Py_False; - break; - - case Py_NE: - result = status != 0 ? Py_True : Py_False; - break; - - case Py_GT: - result = status > 0 ? Py_True : Py_False; - break; - - case Py_GE: - result = status >= 0 ? Py_True : Py_False; - break; - - default: - result = Py_NotImplemented; - break; - - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : target = propriétaire de la routine visée. * -* method = désignation de la fonction à appeler. * -* * -* Description : Indique si une routine Python existe ou non. * -* * -* Retour : Bilan de l'analyse. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool has_python_method(PyObject *module, const char *method) -{ - bool result; /* Bilan à retourner */ - PyObject *func; /* Fonction visée */ - - func = PyObject_GetAttrString(module, method); - if (func == NULL) return false; - - result = PyCallable_Check(func); - - Py_DECREF(func); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : func = fonction Python à appeler. * -* args = arguments à associer à l'opération. * -* * -* Description : Appelle une routine Python. * -* * -* Retour : Retour obtenu ou NULL si erreur. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyObject *_run_python_method(PyObject *func, PyObject *args) -{ - PyObject *result; /* Bilan à retourner */ - - result = NULL; - - if (PyCallable_Check(func)) - { - result = PyObject_CallObject(func, args); - if (result == NULL) PyErr_Print(); - } - else if (PyErr_Occurred()) PyErr_Print(); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : target = propriétaire de la routine visée. * -* method = désignation de la fonction à appeler. * -* args = arguments à associer à l'opération. * -* * -* Description : Appelle une routine Python. * -* * -* Retour : Retour obtenu ou NULL si erreur. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyObject *run_python_method(PyObject *module, const char *method, PyObject *args) -{ - PyObject *result; /* Bilan à retourner */ - PyObject *func; /* Fonction visée */ - - result = NULL; - - func = PyObject_GetAttrString(module, method); - if (func == NULL) return NULL; - - result = _run_python_method(func, args); - - Py_DECREF(func); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : obj_type = type dont le dictionnaire est à compléter. * -* key = désignation de la constante à intégrer. * -* value = valeur de la constante à intégrer. * -* * -* Description : Ajoute une constante au dictionnaire d'un type Python donné. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool PyDict_AddIntConstant(PyTypeObject *obj_type, const char *key, long value) -{ - bool result; /* Bilan à retourner */ - PyObject *item; /* Nouvel élément à insérer */ - int ret; /* Bilan d'un ajout */ - - item = PyLong_FromLong(value); - - ret = PyDict_SetItemString(obj_type->tp_dict, key, item); - result = (ret != -1); - - Py_DECREF(item); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : obj_type = type dont le dictionnaire est à compléter. * -* key = désignation de la constante à intégrer. * -* value = valeur de la constante à intégrer. * -* * -* Description : Ajoute une constante au dictionnaire d'un type Python donné. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool PyDict_AddStringConstant(PyTypeObject *obj_type, const char *key, const char *value) -{ - bool result; /* Bilan à retourner */ - PyObject *item; /* Nouvel élément à insérer */ - int ret; /* Bilan d'un ajout */ - - item = PyUnicode_FromString(value); - - ret = PyDict_SetItemString(obj_type->tp_dict, key, item); - result = (ret != -1); - - Py_DECREF(item); - - return result; - -} - - - -/* ---------------------------------------------------------------------------------- */ -/* CONFORTS CIBLANT PYGOBJECT */ -/* ---------------------------------------------------------------------------------- */ - - -/****************************************************************************** -* * -* Paramètres : spec = définition à mettre en place dynamiquement. * -* * -* Description : Définit dans le tas de Python un nouveau type. * -* * -* Retour : Nouveau type prêt à emploi. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyTypeObject *define_python_dynamic_type(const PyTypeObject *spec) -{ - PyTypeObject *result; /* Définition créée à renvoyer */ - PyTypeObject *type; /* Type de tous les types */ - size_t size; /* Taille de la définition */ - char *s; /* Marqueur de début de chaîne */ - PyHeapTypeObject *hobj; /* Version réelle du type créé */ - - /** - * Le cahier des charges est ici d'éviter les erreurs suivantes : - * - * TypeError: type 'XXX' is not dynamically allocated but its base type 'YYY' is dynamically allocated - * Fatal Python error: unexpected exception during garbage collection - * - * L'allocation dynamique est marquée par le fanion Py_TPFLAGS_HEAPTYPE. - * - * Une des rares fonctions qui appliquent ce fanion est PyType_FromSpecWithBases(), - * mais elle appelle ensuite PyType_Ready(), ce qui est incompatible avec des modifications - * utltérieures avant un appel à pygobject_register_class(). - * - * Le code suivant s'inspire fortement des méthodes originales de Python, - * dont les mécanismes employés par PyType_GenericAlloc(). - */ - - type = &PyType_Type; - size = _PyObject_SIZE(type); - - if (PyType_IS_GC(type)) - result = (PyTypeObject *)_PyObject_GC_Malloc(size); - else - result = (PyTypeObject *)PyObject_MALLOC(size); - - if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) - Py_INCREF(type); - - /* Définitions sommaires */ - - memset(result, 0, sizeof(PyHeapTypeObject)); - - memcpy(result, spec, sizeof(PyTypeObject)); - - result->tp_flags |= Py_TPFLAGS_HEAPTYPE; - - /* Définitions des noms */ - - /** - * Pour un type dynamique, les désignations ne s'appuient pas sur la partie réservée - * au type, mais sur les données suivantes (cf. type_name() et type_qualname()). - * - * Les deux fonctions désignées sont par ailleurs facilement accessibles : - * - * #0 0x0000555555689bf0 in type_qualname (...) at Objects/typeobject.c:393 - * #1 0x000055555568b3b4 in type_repr (...) at Objects/typeobject.c:855 - * #2 0x0000555555693574 in object_str (...) at Objects/typeobject.c:3511 - * #3 0x0000555555670d02 in PyObject_Str (...) at Objects/object.c:535 - * ... - * - * On s'inspire donc du contenu de PyType_FromSpecWithBases() pour éviter tout - * plantage du fait de données non initialisées. - */ - - hobj = (PyHeapTypeObject *)result; - - s = strrchr(spec->tp_name, '.'); - - if (s == NULL) - s = (char *)spec->tp_name; - else - s++; - - hobj->ht_name = PyUnicode_FromString(s); - assert(hobj->ht_name != NULL); - - hobj->ht_qualname = hobj->ht_name; - Py_INCREF(hobj->ht_qualname); - - result->tp_as_async = &hobj->as_async; - result->tp_as_number = &hobj->as_number; - result->tp_as_sequence = &hobj->as_sequence; - result->tp_as_mapping = &hobj->as_mapping; - result->tp_as_buffer = &hobj->as_buffer; - - hobj->ht_cached_keys = _PyDict_NewKeysForClass(); - - - - -#if 0 - if (type->tp_itemsize == 0) - (void)PyObject_INIT(result, type); - else - (void) PyObject_INIT_VAR((PyVarObject *)result, type, 0); - - if (PyType_IS_GC(type)) - _PyObject_GC_TRACK(result); -#endif - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module où conserver une référence au type créé. * -* gtype = type dans sa version GLib. * -* type = type dans sa version Python. * -* base = type de base de l'objet. * -* * -* Description : Enregistre correctement une surcouche de conversion GObject. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool _register_class_for_pygobject(PyObject *dict, GType gtype, PyTypeObject *type, PyTypeObject *base, ...) -{ - bool result; /* Bilan à retourner */ - Py_ssize_t size; /* Taille de liste actuelle */ - PyObject *static_bases; /* Base(s) de l'objet */ - va_list ap; /* Parcours des arguments */ - PyTypeObject *static_base; /* Base à rajouter à la liste */ - - /** - * pygobject_register_class() définit type->tp_base à partir des arguments fournis, - * puis fait appel à PyType_Ready(). - * - * PyType_Ready() complète la définition via inherit_special() : - * - * type->tp_basicsize = type->tp_base->tp_basicsize - * - * Cependant, il y a un appel à mro_internal() avant, qui mène à solid_base() - * puis à extra_ivars(). Et là : - * - * size_t t_size = type->tp_basicsize; - * size_t b_size = base->tp_basicsize; - * - * assert(t_size >= b_size); - * - * Si le type de base est spécifié, une taille doit être indiquée. - * - * Et quelqu'un doit se coller à la tâche. PyGObject ne fait rien, donc... - */ - - if (type->tp_basicsize < base->tp_basicsize) - { - assert(type->tp_basicsize == 0); - type->tp_basicsize = base->tp_basicsize; - } - - size = 1; - static_bases = PyTuple_New(size); - - Py_INCREF(base); - PyTuple_SetItem(static_bases, 0, (PyObject *)base); - - va_start(ap, base); - - while (1) - { - static_base = va_arg(ap, PyTypeObject *); - - if (static_base == NULL) break; - - _PyTuple_Resize(&static_bases, ++size); - - Py_INCREF(static_base); - PyTuple_SetItem(static_bases, size - 1, (PyObject *)static_base); - - } - - va_end(ap); - - - - /* -#0 0x000055555565aad4 in insertdict (mp=0x7fffe7c2c8a8, key='GenConfig', hash=262970853803706525, value=) at ../Objects/dictobject.c:801 -#1 0x000055555565bf62 in PyDict_SetItem (op={'__doc__': 'Python module for Chrysalide.glibext', '__name__': 'pychrysalide.glibext', 'BufferLine': , '__spec__': None, 'ConfigParam': , '__package__': None, 'Buffercache': , 'ConfigParamIterator': , '__loader__': None}, key='GenConfig', value=) at ../Objects/dictobject.c:1227 -#2 0x00005555556610b0 in PyDict_SetItemString (v={'__doc__': 'Python module for Chrysalide.glibext', '__name__': 'pychrysalide.glibext', 'BufferLine': , '__spec__': None, 'ConfigParam': , '__package__': None, 'Buffercache': , 'ConfigParamIterator': , '__loader__': None}, key=0x7ffff69cd0bd "GenConfig", item=) at ../Objects/dictobject.c:2870 -#3 0x00007ffff69b3d12 in _register_class_for_pygobject (dict={'__doc__': 'Python module for Chrysalide.glibext', '__name__': 'pychrysalide.glibext', 'BufferLine': , '__spec__': None, 'ConfigParam': , '__package__': None, 'Buffercache': , 'ConfigParamIterator': , '__loader__': None}, gtype=93824998785328, type=0x7ffff6bd9ce0 , base=0x7fffe80e72a0 ) at helpers.c:320 - */ - - - - //type->tp_weaklistoffset = offsetof(PyGObject, weakreflist); - //type->tp_dictoffset = offsetof(PyGObject, inst_dict); - - pygobject_register_class(dict, NULL, gtype, type, static_bases); - - if (PyErr_Occurred() == NULL) - result = true; - - else - { - PyErr_Print(); - result = false; - } - - assert(PyErr_Occurred() == NULL); - - return result; - -} diff --git a/plugins/pychrysa/helpers.h b/plugins/pychrysa/helpers.h deleted file mode 100644 index 295ec28..0000000 --- a/plugins/pychrysa/helpers.h +++ /dev/null @@ -1,93 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * helpers.h - prototypes pour la simplification des interactions de base avec Python - * - * Copyright (C) 2012-2017 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 . - */ - - -#ifndef _PLUGINS_PYCHRYSA_HELPERS_H -#define _PLUGINS_PYCHRYSA_HELPERS_H - - -#include -#include -#include - - - -/* ---------------------- ACCELERATEURS POUR PYTHON UNIQUEMENT ---------------------- */ - - -/* Traduit pour Python le bilan d'une comparaison riche. */ -PyObject *status_to_rich_cmp_state(int, int); - -/* Indique si une routine Python existe ou non. */ -bool has_python_method(PyObject *, const char *); - -/* Appelle une routine Python. */ -PyObject *_run_python_method(PyObject *, PyObject *); - -/* Appelle une routine Python. */ -PyObject *run_python_method(PyObject *, const char *, PyObject *); - -/* Ajoute une constante au dictionnaire d'un type Python donné. */ -bool PyDict_AddIntConstant(PyTypeObject *, const char *, long); - -/* Ajoute une constante au dictionnaire d'un type Python donné. */ -bool PyDict_AddStringConstant(PyTypeObject *, const char *, const char *); - - -#define PyDict_AddIntMacro(tp, c) PyDict_AddIntConstant(tp, #c, c) -#define PyDict_AddStringMacro(tp, c) PyDict_AddStringConstant(tp, #c, c) - - - -/* --------------------------- CONFORTS CIBLANT PYGOBJECT --------------------------- */ - - -/** - * Quelque chose est mal fait au niveau de l'abstraction GObject. - * Du coup, Py_TPFLAGS_IS_ABSTRACT n'est pas pris en compte. - * On force alors la méthode de base pour obtenir un traitement correct. - * - * Cf. http://stackoverflow.com/questions/20432335/can-python-abstract-base-classes-inherit-from-c-extensions - */ -#define APPLY_ABSTRACT_FLAG(tp) tp->tp_new = PyBaseObject_Type.tp_new - - -/* Définit dans le tas de Python un nouveau type. */ -PyTypeObject *define_python_dynamic_type(const PyTypeObject *); - -/* Enregistre correctement une surcouche de conversion GObject. */ -bool _register_class_for_pygobject(PyObject *, GType, PyTypeObject *, PyTypeObject *, ...); - -#define register_class_for_pygobject(dict, gtype, type, base) \ - _register_class_for_pygobject(dict, gtype, type, base, NULL) - - -/** - * Quand on remplace un objet GLib dans le dos de Python, il faut - * le remplacer de la même manière qu'on l'a obtenu ! - */ - -#define pygobject_set(p, v) ((PyGObject *)(p))->obj = (GObject *)v - - - -#endif /* _PLUGINS_PYCHRYSA_HELPERS_H */ diff --git a/plugins/pychrysa/plugin.c b/plugins/pychrysa/plugin.c deleted file mode 100644 index fad0084..0000000 --- a/plugins/pychrysa/plugin.c +++ /dev/null @@ -1,809 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * plugin.c - interactions avec un greffon Python - * - * Copyright (C) 2012-2017 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 "plugin.h" - - -#include -#include - - -#include -#include "../../src/core/formats.h" -//#include -#include - - -#include "helpers.h" - - - -/* --------------------- INTERFACE INTERNE POUR GREFFONS PYTHON --------------------- */ - - -/* Ligne de représentation de code binaire (instance) */ -struct _GPythonPlugin -{ - GPluginModule parent; /* Instance parente */ - - PyObject *module; /* Script Python chargé */ - PyObject *instance; /* Instance Python du greffon */ - -}; - - -/* Ligne de représentation de code binaire (classe) */ -struct _GPythonPluginClass -{ - GPluginModuleClass parent; /* Classe parente */ - -}; - - -/* Initialise la classe des greffons Python. */ -static void g_python_plugin_class_init(GPythonPluginClass *); - -/* Initialise l'instance d'un greffon Python. */ -static void g_python_plugin_init(GPythonPlugin *); - -/* Reconstruit la déclaration d'interface à partir de lectures. */ -static bool g_python_plugin_read_interface(GPythonPlugin *); - -/* Procède à l'initialisation du greffon. */ -static bool g_python_plugin_do_init(GPythonPlugin *); - -/* Procède à l'extinction du greffon. */ -static bool g_python_plugin_do_exit(GPythonPlugin *, GObject *); - -/* Indique si le format peut être pris en charge ici. */ -FormatMatchStatus python_plugin_is_matching(GBinContent *, GExeFormat *, GPythonPlugin *, char **); - -/* Exécute une action pendant un désassemblage de binaire. */ -static void g_python_plugin_process_disass(const GPythonPlugin *, PluginAction, GLoadedBinary *); - - - -/* ------------------------- MODULE PYTHON POUR LES SCRIPTS ------------------------- */ - - -/* Définit les constantes pour les greffons en Python. */ -static bool py_plugin_module_define_constants(PyTypeObject *); - - - -/* ---------------------------------------------------------------------------------- */ -/* INTERFACE INTERNE POUR GREFFONS PYTHON */ -/* ---------------------------------------------------------------------------------- */ - - -/* Indique le type définit par la GLib pour le greffon Python. */ -G_DEFINE_TYPE(GPythonPlugin, g_python_plugin, G_TYPE_PLUGIN_MODULE); - - -/****************************************************************************** -* * -* Paramètres : klass = classe à initialiser. * -* * -* Description : Initialise la classe des greffons Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_python_plugin_class_init(GPythonPluginClass *klass) -{ - -} - - -/****************************************************************************** -* * -* Paramètres : plugin = instance à initialiser. * -* * -* Description : Initialise l'instance d'un greffon Python. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_python_plugin_init(GPythonPlugin *plugin) -{ - -} - - -/****************************************************************************** -* * -* Paramètres : modname = nom du module à charger. * -* filename = chemin d'accès au code Python à charger. * -* * -* Description : Crée un greffon à partir de code Python. * -* * -* Retour : Adresse de la structure mise en place ou NULL si erreur. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GPluginModule *g_python_plugin_new(const char *modname, const char *filename) -{ - GPythonPlugin *result; /* Structure à retourner */ - PyObject *name; /* Chemin d'accès pour Python */ - PyObject *module; /* Script Python chargé */ - PyObject *err_type; /* Type d'erreur Python */ - PyObject *err_value; /* Instance Python d'erreur */ - PyObject *err_traceback; /* Trace Python associée */ - PyObject *err_string; /* Description Python d'erreur */ - const char *err_msg; /* Représentation humaine */ - PyObject *dict; /* Dictionnaire associé */ - PyObject *class; /* Classe à instancier */ - PyObject *instance; /* Instance Python du greffon */ - size_t i; /* Boucle de parcours */ - uint32_t action; /* Identifiant d'une action */ - uint32_t category; /* Catégorie principale */ - uint32_t sub; /* Sous-catégorie visée */ - - name = PyUnicode_FromString(modname); - if (name == NULL) goto gppn_bad_exit; - - module = PyImport_Import(name); - Py_DECREF(name); - - if (PyErr_Occurred()) - { - PyErr_Fetch(&err_type, &err_value, &err_traceback); - - if (err_value == NULL) - log_variadic_message(LMT_ERROR, - _("An unknown error occured when importing '%s'..."), modname); - else - { - err_string = PyObject_Str(err_value); - err_msg = PyUnicode_AsUTF8(err_string); - - log_variadic_message(LMT_ERROR, - _("An error occured when importing '%s': \"%s\""), modname, err_msg); - - Py_DECREF(err_string); - Py_DECREF(err_value); - - } - - Py_XDECREF(err_traceback); - Py_XDECREF(err_type); - - Py_XDECREF(module); - - module = NULL; - - } - - if (module == NULL) goto gppn_bad_exit; - - dict = PyModule_GetDict(module); - class = PyDict_GetItemString(dict, "AutoLoad"); - - if (class == NULL) goto gppn_no_class; - if (!PyType_Check(class->ob_type)) goto gppn_no_class; - - instance = PyObject_CallFunction(class, NULL); - if (instance == NULL) goto gppn_no_instance; - - result = g_object_new(G_TYPE_PYTHON_PLUGIN, NULL); - - G_PLUGIN_MODULE(result)->filename = strdup(filename); - - result->module = module; - result->instance = instance; - - if (!g_python_plugin_read_interface(result)) - { - printf("bad interface------------\n"); - goto gppn_interface_error; - } - - /* Localisation des différents points d'entrée déclarés */ - -#define register_python_binding(inst, sym, binding) \ - ({ \ - bool __result; \ - if (!has_python_method(inst, #sym)) \ - { \ - log_variadic_message(LMT_ERROR, \ - _("No '%s' entry in plugin candidate '%s'"), \ - #sym, G_PLUGIN_MODULE(result)->filename); \ - __result = false; \ - } \ - else \ - { \ - G_PLUGIN_MODULE(result)->sym = binding; \ - __result = true; \ - } \ - __result; \ - }) - - for (i = 0; i < G_PLUGIN_MODULE(result)->interface->actions_count; i++) - { - action = G_PLUGIN_MODULE(result)->interface->actions[i]; - category = MASK_PLUGIN_CATEGORY(action); - sub = MASK_PLUGIN_SUB_CATEGORY(action); - - switch (category) - { - case DPC_BASIC: - - switch (sub) - { - case DPS_NONE: - break; - - case PGA_PLUGIN_INIT: - if (!register_python_binding(instance, init, (pg_management_fc)g_python_plugin_do_init)) - goto gppn_bad_plugin; - break; - - case PGA_PLUGIN_EXIT: - if (!register_python_binding(instance, exit, (pg_management_fc)g_python_plugin_do_exit)) - goto gppn_bad_plugin; - break; - - default: - log_variadic_message(LMT_WARNING, - _("Unknown sub-category '0x%02x' in plugin '%s'..."), sub, filename); - break; - - } - - break; - - case DPC_BINARY_PROCESSING: - - switch (sub) - { - case DPS_FORMAT: - - switch (action) - { - case PGA_FORMAT_MATCHER: - - if (!has_python_method(instance, "is_format_matching")) - { - log_variadic_message(LMT_ERROR, - _("No '%s' entry in plugin candidate '%s'"), - "is_format_matching", - G_PLUGIN_MODULE(result)->filename); - goto gppn_bad_plugin; - } - - if (!register_format_matcher((format_match_fc)python_plugin_is_matching, result)) - goto gppn_bad_plugin; - - break; - - case PGA_FORMAT_LOADER_LAST: - /* TODO */ - break; - - default: - log_variadic_message(LMT_WARNING, - _("Unknown action '0x%02x' in plugin '%s'..."), - action, filename); - break; - - } - - break; - - case DPS_DISASSEMBLY: - if (!register_python_binding(instance, process_disass, - (pg_process_disassembly_fc)g_python_plugin_process_disass)) - goto gppn_bad_plugin; - break; - - default: - log_variadic_message(LMT_WARNING, - _("Unknown sub-category '0x%02x' in plugin '%s'..."), sub, filename); - break; - - } - - break; - - default: - log_variadic_message(LMT_WARNING, - _("Unknown category '0x%02x' in plugin '%s'..."), category, filename); - break; - - } - - } - - /* Conclusion */ - - /* - if (!g_plugin_module_load(G_PLUGIN_MODULE(result))) - goto gppn_bad_plugin; - */ - - return G_PLUGIN_MODULE(result); - - gppn_bad_plugin: - - gppn_interface_error: - - g_object_unref(G_OBJECT(result)); - - //Py_DECREF(instance); - - gppn_no_instance: - - gppn_no_class: - - //Py_DECREF(module); - - gppn_bad_exit: - - printf("bad exit :(\n"); - return NULL; - -} - - -/****************************************************************************** -* * -* Paramètres : plugin = greffon à initialiser. * -* * -* Description : Reconstruit la déclaration d'interface à partir de lectures. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool g_python_plugin_read_interface(GPythonPlugin *plugin) -{ - bool result; /* Bilan à renvoyer */ - plugin_interface interface; /* Recueil des éléments */ - PyObject *desc; /* Tableau de description */ - PyObject *str; /* Chaîne de caractères */ - PyObject *tuple; /* Liste d'éléments à traiter */ - Py_ssize_t count; /* Nombre d'éléments présents */ - Py_ssize_t i; /* Boucle de parcours */ - PyObject *action; /* Identifiant d'une action */ - plugin_interface *final; /* Interface finale conservée */ - - result = true; - - desc = run_python_method(plugin->instance, "get_interface", NULL); - if (!PyDict_Check(desc)) - { - result = false; - goto pgpri_end; - } - - memset(&interface, 0, sizeof(interface)); - - /* Chargements des premières chaînes */ - -#define READ_STR_FIELD(name) \ - str = PyDict_GetItemString(desc, #name); \ - if ((result = PyUnicode_Check(str))) \ - interface.name = strdup(PyUnicode_DATA(str)); \ - - READ_STR_FIELD(name); - READ_STR_FIELD(desc); - READ_STR_FIELD(version); - - /* Chargement des actions supportées */ - - tuple = PyDict_GetItemString(desc, "actions"); - - if (!PyList_Check(tuple)) - { - result = false; - goto pgpri_failed; - } - - count = PyList_GET_SIZE(tuple); - - interface.actions = (plugin_action_t *)calloc(count, sizeof(plugin_action_t)); - interface.actions_count = count; - - for (i = 0; i < count; i++) - { - action = PyList_GET_ITEM(tuple, i); - - interface.actions[i] = PyLong_AsLong(action); - - } - - pgpri_failed: - - if (result) - { - final = (plugin_interface *)calloc(1, sizeof(plugin_interface)); - - memcpy(final, &interface, sizeof(interface)); - - G_PLUGIN_MODULE(plugin)->interface = final; - - } - else - { - if (interface.name != NULL) free((char *)interface.name); - if (interface.desc != NULL) free((char *)interface.desc); - if (interface.version != NULL) free((char *)interface.version); - - if (interface.actions != NULL) free(interface.actions); - - } - - pgpri_end: - - Py_XDECREF(desc); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : plugin = greffon à initialiser. * -* ref = espace de référencement global. * -* * -* Description : Procède à l'initialisation du greffon. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool g_python_plugin_do_init(GPythonPlugin *plugin) -{ - bool result; /* Bilan à retourner */ - PyObject *args; /* Arguments pour l'appel */ - PyObject *value; /* Valeur obtenue */ - - args = Py_None; - Py_INCREF(args); - - value = run_python_method(plugin->instance, "init", args); - - result = (value != NULL && PyObject_IsTrue(value)); - - Py_XDECREF(value); - Py_DECREF(args); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : plugin = greffon à initialiser. * -* ref = espace de référencement global. * -* * -* Description : Procède à l'extinction du greffon. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool g_python_plugin_do_exit(GPythonPlugin *plugin, GObject *ref) -{ - bool result; /* Bilan à retourner */ - PyObject *args; /* Arguments pour l'appel */ - PyObject *value; /* Valeur obtenue */ - - args = PyTuple_New(1); - PyTuple_SetItem(args, 0, pygobject_new(ref)); - - value = run_python_method(plugin->instance, "exit", args); - - result = PyObject_IsTrue(value); - - Py_XDECREF(value); - Py_DECREF(args); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : content = contenu binaire à parcourir. * -* parent = éventuel format exécutable déjà chargé. * -* plugin = grefon C interne représentant le grefon Python. * -* key = identifiant de format trouvé ou NULL. [OUT] * -* * -* Description : Indique si le format peut être pris en charge ici. * -* * -* Retour : Conclusion de haut niveau sur la reconnaissance effectuée. * -* * -* Remarques : - * -* * -******************************************************************************/ - -FormatMatchStatus python_plugin_is_matching(GBinContent *content, GExeFormat *parent, GPythonPlugin *plugin, char **key) -{ - FormatMatchStatus result; /* Bilan à renvoyer */ - PyObject *args; /* Arguments pour l'appel */ - PyObject *value; /* Valeur obtenue */ - PyObject *arg; /* Argument en élément de tuple*/ - - result = FMS_UNKNOWN; - - args = PyTuple_New(2); - PyTuple_SetItem(args, 0, pygobject_new(G_OBJECT(content))); - PyTuple_SetItem(args, 1, pygobject_new(G_OBJECT(parent))); - - value = run_python_method(plugin->instance, "is_format_matching", args); - - if (PyTuple_Check(value)) - { - if (PyTuple_Size(value) > 0) - { - arg = PyTuple_GetItem(value, 0); - - if (PyLong_Check(arg)) - { - result = PyLong_AsLong(arg); - - switch (result) - { - case FMS_MATCHED: - - if (PyTuple_Size(value) != 2) - { - g_plugin_module_log_variadic_message(G_PLUGIN_MODULE(plugin), LMT_ERROR, - _("Expecting only a tuple [ status, key ] " \ - "as result for format matching.")); - result = FMS_UNKNOWN; - break; - } - - arg = PyTuple_GetItem(value, 1); - - if (PyUnicode_Check(arg)) - *key = strdup(PyUnicode_AsUTF8(arg)); - - else - { - g_plugin_module_log_variadic_message(G_PLUGIN_MODULE(plugin), LMT_ERROR, - _("Expecting a key string for format matching.")); - result = FMS_UNKNOWN; - } - - break; - - case FMS_FORWARDED: - case FMS_UNKNOWN: - if (PyTuple_Size(value) != 1) - { - g_plugin_module_log_variadic_message(G_PLUGIN_MODULE(plugin), LMT_WARNING, - _("Unused second item for format matching.")); - } - break; - - default: - g_plugin_module_log_variadic_message(G_PLUGIN_MODULE(plugin), LMT_ERROR, - _("Unexpected result for format matching.")); - result = FMS_UNKNOWN; - break; - - } - - } - - else - { - g_plugin_module_log_variadic_message(G_PLUGIN_MODULE(plugin), LMT_ERROR, - _("Unexpected result status for format matching.")); - result = FMS_UNKNOWN; - } - - } - else - g_plugin_module_log_variadic_message(G_PLUGIN_MODULE(plugin), LMT_WARNING, - _("Interpreting a empty tuple as FMS_UNKNOWN " \ - "for format matching.")); - - } - else - g_plugin_module_log_variadic_message(G_PLUGIN_MODULE(plugin), LMT_ERROR, - _("Expected a tuple containing [ status, key ] as result " \ - "for format matching.")); - - Py_XDECREF(value); - Py_DECREF(args); - - return result; - - - - -} - - -/****************************************************************************** -* * -* Paramètres : plugin = greffon à manipuler. * -* action = type d'action attendue. * -* binary = binaire dont le contenu est en cours de traitement. * -* * -* Description : Exécute une action pendant un désassemblage de binaire. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_python_plugin_process_disass(const GPythonPlugin *plugin, PluginAction action, GLoadedBinary *binary) -{ - PyObject *args; /* Arguments pour l'appel */ - PyObject *value; /* Valeurs obtenues */ - - args = PyTuple_New(2); - - PyTuple_SetItem(args, 0, PyLong_FromLong(action)); - PyTuple_SetItem(args, 1, pygobject_new(G_OBJECT(binary))); - - value = run_python_method(plugin->instance, "process_binary_disassembly", args); - - Py_XDECREF(value); - Py_DECREF(args); - -} - - - -/* ---------------------------------------------------------------------------------- */ -/* MODULE PYTHON POUR LES SCRIPTS */ -/* ---------------------------------------------------------------------------------- */ - - -/****************************************************************************** -* * -* Paramètres : obj_type = type dont le dictionnaire est à compléter. * -* * -* Description : Définit les constantes pour les greffons en Python. * -* * -* Retour : true en cas de succès de l'opération, false sinon. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool py_plugin_module_define_constants(PyTypeObject *obj_type) -{ - bool result; /* Bilan à retourner */ - - result = true; - - result &= PyDict_AddIntMacro(obj_type, PGA_BASIC_NONE); - result &= PyDict_AddIntMacro(obj_type, PGA_PLUGIN_INIT); - result &= PyDict_AddIntMacro(obj_type, PGA_PLUGIN_EXIT); - result &= PyDict_AddIntMacro(obj_type, PGA_FORMAT_MATCHER); - result &= PyDict_AddIntMacro(obj_type, PGA_FORMAT_LOADER_LAST); - result &= PyDict_AddIntMacro(obj_type, PGA_DISASSEMBLY_STARTED); - result &= PyDict_AddIntMacro(obj_type, PGA_DISASSEMBLY_RAW); - result &= PyDict_AddIntMacro(obj_type, PGA_DISASSEMBLY_HOOKED_LINK); - result &= PyDict_AddIntMacro(obj_type, PGA_DISASSEMBLY_HOOKED_POST); - result &= PyDict_AddIntMacro(obj_type, PGA_DISASSEMBLY_LIMITED); - result &= PyDict_AddIntMacro(obj_type, PGA_DISASSEMBLY_LOOPS); - result &= PyDict_AddIntMacro(obj_type, PGA_DISASSEMBLY_LINKED); - result &= PyDict_AddIntMacro(obj_type, PGA_DISASSEMBLY_GROUPED); - result &= PyDict_AddIntMacro(obj_type, PGA_DISASSEMBLY_RANKED); - result &= PyDict_AddIntMacro(obj_type, PGA_DISASSEMBLY_ENDED); - - 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_plugin_module_type(void) -{ - static PyMethodDef py_plugin_module_methods[] = { - { NULL } - }; - - static PyGetSetDef py_plugin_module_getseters[] = { - { NULL } - }; - - static PyTypeObject py_plugin_module_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.PluginModule", - .tp_basicsize = sizeof(PyGObject), - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "Chrysalide plugin for Python.", - - .tp_methods = py_plugin_module_methods, - .tp_getset = py_plugin_module_getseters - - }; - - return &py_plugin_module_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.PluginModule'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_plugin_module(PyObject *module) -{ - PyTypeObject *py_plugin_module_type; /* Type Python 'PluginModule' */ - PyObject *dict; /* Dictionnaire du module */ - - py_plugin_module_type = get_python_plugin_module_type(); - - dict = PyModule_GetDict(module); - - if (!register_class_for_pygobject(dict, G_TYPE_PLUGIN_MODULE, py_plugin_module_type, &PyGObject_Type)) - return false; - - if (!py_plugin_module_define_constants(py_plugin_module_type)) - return false; - - return true; - -} diff --git a/plugins/pychrysa/plugin.h b/plugins/pychrysa/plugin.h deleted file mode 100644 index ca451a8..0000000 --- a/plugins/pychrysa/plugin.h +++ /dev/null @@ -1,75 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * plugin.h - prototypes pour les interactions avec un greffon Python - * - * Copyright (C) 2012-2017 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_PYCHRYSA_PLUGIN_H -#define _PLUGINS_PYCHRYSA_PLUGIN_H - - -#include -#include -#include - - -#include - - - -/* --------------------- INTERFACE INTERNE POUR GREFFONS PYTHON --------------------- */ - - -#define G_TYPE_PYTHON_PLUGIN (g_python_plugin_get_type()) -#define G_PYTHON_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_PYTHON_PLUGIN, GPythonPlugin)) -#define G_IS_PYTHON_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_PYTHON_PLUGIN)) -#define G_PYTHON_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_PYTHON_PLUGIN, GPythonPluginClass)) -#define G_IS_PYTHON_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_PYTHON_PLUGIN)) -#define G_PYTHON_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_PYTHON_PLUGIN, GPythonPluginClass)) - - -/* Ligne de représentation de code binaire (instance) */ -typedef struct _GPythonPlugin GPythonPlugin; - -/* Ligne de représentation de code binaire (classe) */ -typedef struct _GPythonPluginClass GPythonPluginClass; - - -/* Indique le type définit par la GLib pour le greffon Python. */ -GType g_python_plugin_get_type(void); - -/* Crée un greffon à partir de code Python. */ -GPluginModule *g_python_plugin_new(const char *, const char *); - - - -/* ------------------------- MODULE PYTHON POUR LES SCRIPTS ------------------------- */ - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_plugin_module_type(void); - -/* Prend en charge l'objet 'pychrysalide.PluginModule'. */ -bool register_python_plugin_module(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSA_PLUGIN_H */ diff --git a/plugins/pychrysa/pychrysa.c b/plugins/pychrysa/pychrysa.c deleted file mode 100644 index 35d14f4..0000000 --- a/plugins/pychrysa/pychrysa.c +++ /dev/null @@ -1,616 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * pychrysa.c - plugin permettant des extensions en Python - * - * Copyright (C) 2012-2017 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 "pychrysa.h" - - -#include -#include -#include -#include -#include -#include -#include - - -#include -#include -#include -#include -#include -#include -#include -#include - - -#include "helpers.h" -#include "plugin.h" -#include "struct.h" -#include "analysis/module.h" -#include "arch/module.h" -#include "common/module.h" -#include "core/module.h" -#include "debug/module.h" -#include "format/module.h" -#include "glibext/module.h" -#include "gtkext/module.h" -#include "gui/module.h" - - - -DEFINE_CHRYSALIDE_ACTIVE_PLUGIN("PyChrysalide", "Provides bindings to Python", "0.1.0", PGA_PLUGIN_INIT); - - -/* Note la nature du chargement */ -static bool _standalone = true; - -/* Réceptacle pour le chargement forcé */ -static PyObject *_chrysalide_module = NULL; - - -/* Fournit la révision du programme global. */ -static PyObject *py_chrysalide_revision(PyObject *, PyObject *); - -/* Fournit la version du programme global. */ -static PyObject *py_chrysalide_version(PyObject *, PyObject *); - -/* Fournit la version du greffon pour Python. */ -static PyObject *py_chrysalide_mod_version(PyObject *, PyObject *); - -/* Détermine si l'interpréteur lancé est celui pris en compte. */ -static bool is_current_abi_suitable(void); - -/* Définit la version attendue de GTK à charger dans Python. */ -static bool set_version_for_gtk_namespace(const char *); - -/* Charge autant de greffons composés en Python que possible. */ -static bool load_python_plugins(GPluginModule *); - - - -/****************************************************************************** -* * -* Paramètres : self = NULL car méthode statique. * -* args = non utilisé ici. * -* * -* Description : Fournit la révision du programme global. * -* * -* Retour : Numéro de révision. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_chrysalide_revision(PyObject *self, PyObject *args) -{ - return PyUnicode_FromString("r" XSTR(REVISION)); - -} - - -/****************************************************************************** -* * -* Paramètres : self = NULL car méthode statique. * -* args = non utilisé ici. * -* * -* Description : Fournit la version du programme global. * -* * -* Retour : Numéro de version. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_chrysalide_version(PyObject *self, PyObject *args) -{ - char version[16]; - int major; - int minor; - int revision; - - major = REVISION / 1000; - minor = (REVISION - (major * 1000)) / 100; - revision = REVISION % 100; - - snprintf(version, sizeof(version), "%d.%d.%d", major, minor, revision); - - return PyUnicode_FromString(version); - -} - - -/****************************************************************************** -* * -* Paramètres : self = NULL car méthode statique. * -* args = non utilisé ici. * -* * -* Description : Fournit la version du greffon pour Python. * -* * -* Retour : Numéro de version. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_chrysalide_mod_version(PyObject *self, PyObject *args) -{ - char version[16]; - - snprintf(version, sizeof(version), "%s", _chrysalide_plugin.version); - - return PyUnicode_FromString(version); - -} - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Détermine si l'interpréteur lancé est celui pris en compte. * -* * -* Retour : true si l'exécution peut se poursuivre, false sinon. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool is_current_abi_suitable(void) -{ - bool result; - int fds[2]; - int ret; - char cmds[128]; - char content[64]; - ssize_t got; - -#define GRAB_ABI_FLAGS_IN_PYTHON \ - "import sys" "\n" \ - "import os" "\n" \ - "os.write(%d, bytes(sys.abiflags, 'UTF-8'))" "\n" - - result = false; - - ret = pipe(fds); - if (ret == -1) - { - perror("pipe()"); - return false; - } - - snprintf(cmds, sizeof(cmds), GRAB_ABI_FLAGS_IN_PYTHON, fds[1]); - - ret = PyRun_SimpleString(cmds); - if (ret != 0) goto icas_exit; - - got = read(fds[0], content, sizeof(content)); - if (got < 0) - { - perror("read()"); - goto icas_exit; - } - - content[got] = '\0'; - - result = (strcmp(content, LIBPYTHON_ABI_FLAGS) == 0); - - icas_exit: - - if (!result) - PyErr_SetString(PyExc_SystemError, "the ABI flags of the current interpreter do not match " \ - "the ones of the Python library used during the module compilation."); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : version = idenfiant de la version de GTK à stipuler. * -* * -* Description : Définit la version attendue de GTK à charger dans Python. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool set_version_for_gtk_namespace(const char *version) -{ - bool result; /* Bilan à retourner */ - PyObject *gi_mod; /* Module Python-GObject */ - PyObject *args; /* Arguments à fournir */ - - result = false; - - /** - * On cherche ici à éviter le message suivant si on charge 'gi.repository.Gtk' directement : - * - * - * PyGIWarning: Gtk was imported without specifying a version first. \ - * Use gi.require_version('Gtk', '3.0') before import to ensure that the right version gets loaded. - * - */ - - gi_mod = PyImport_ImportModule("gi"); - - if (gi_mod != NULL) - { - args = Py_BuildValue("ss", "Gtk", "3.0"); - - run_python_method(gi_mod, "require_version", args); - - result = (PyErr_Occurred() == NULL); - - Py_DECREF(args); - Py_DECREF(gi_mod); - - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Point d'entrée pour l'initialisation de Python. * -* * -* Retour : ? * -* * -* Remarques : - * -* * -******************************************************************************/ -#include // REMME -#include - -#define PYCHRYSALIDE_DOC \ - "PyChrysalide is a module containing Chrysalide's features and designed for Python users.\n" \ - "\n" \ - "The whole API is defined in a single library named 'pychrysalide.so' and can be used in two ways:\n" \ - "* either from the Chrysalide's GUI, by registering hooks or GLib signals.\n" \ - "* or from a shell command line, by setting PYTHONPATH to point to the directory containing the library.\n" \ - "\n" \ - "In both cases, it is a good start point to have a look at already existing plugins to quickly learn " \ - "how the API works.\n" \ - "\n" \ - "These plugins are located in the 'plugins/python' directory." - -PyMODINIT_FUNC PyInit_pychrysalide(void) -{ - PyObject *result; /* Module Python à retourner */ - bool status; /* Bilan des inclusions */ - GPluginModule *self; /* Représentation interne */ - PluginStatusFlags self_flags; /* Fanions à mettre à jour */ - - static PyMethodDef py_chrysalide_methods[] = { - - { "revision", py_chrysalide_revision, - METH_NOARGS, - "revision(/)\n--\n\nProvide the revision number of Chrysalide." - }, - { "version", py_chrysalide_version, - METH_NOARGS, - "version(/)\n--\n\nProvide the version number of Chrysalide." - }, - { "mod_version", py_chrysalide_mod_version, - METH_NOARGS, - "mod_version(/)\n--\n\nProvide the version number of Chrysalide module for Python." - }, - { NULL } - - }; - - static PyModuleDef py_chrysalide_module = { - - .m_base = PyModuleDef_HEAD_INIT, - - .m_name = "pychrysalide", - .m_doc = PYCHRYSALIDE_DOC, - - .m_size = -1, - - .m_methods = py_chrysalide_methods - - }; - -#if 0 - do - { - int argc = 0; - //char *argv[] = { NULL }; - - /* Initialisation de GTK */ - g_set_prgname("Chrysalide"); - setlocale (LC_ALL, ""); - gtk_init(&argc, NULL/*&argv-*/); - - } while (0); - - add_pixmap_directory(PACKAGE_DATA_DIR); - add_pixmap_directory(PACKAGE_SOURCE_DIR G_DIR_SEPARATOR_S "pixmaps"); - - /** - * On évite d'initialiser deux fois... - */ - if (get_work_queue() != NULL) - init_work_queue(NULL/* !! */); -#endif - - - - - - if (!is_current_abi_suitable()) - return NULL; - - if (pygobject_init(-1, -1, -1) == NULL) - { - PyErr_SetString(PyExc_SystemError, "unable to init GObject in Python."); - return NULL; - } - - if (!set_version_for_gtk_namespace("3.0")) - return NULL; - - if (!load_all_basic_components()) - { - PyErr_SetString(PyExc_SystemError, "unable to load all basic components."); - return NULL; - } - - /* Mise en place des fonctionnalités offertes */ - - result = PyModule_Create(&py_chrysalide_module); - - status = register_python_py_struct(result); - - /* Interface 'LineGenerator' en premier... */ - if (status) status = add_glibext_module_to_python_module(result); - - /* BinRoutine hérite de BinSymbol... */ - if (status) status = add_format_module_to_python_module(result); - - if (status) status = register_python_plugin_module(result); - if (status) status = add_analysis_module_to_python_module(result); - if (status) status = add_arch_module_to_python_module(result); - if (status) status = add_common_module_to_python_module(result); - if (status) status = add_core_module_to_python_module(result); - if (status) status = add_debug_module_to_python_module(result); - if (status) status = add_gtkext_module_to_python_module(result); - if (status) status = add_gui_module_to_python_module(result); - - if (!status) - { - PyErr_SetString(PyExc_SystemError, "fail to load all PyChrysalide components."); - return NULL; - } - - if (_standalone) - { - init_all_plugins(false); - - lock_plugin_list_for_reading(); - - self = get_plugin_by_name("PyChrysalide", NULL); - assert(self != NULL); - - self_flags = g_plugin_module_get_flags(self); - self_flags &= ~(PSF_FAILURE | PSF_LOADED); - self_flags |= (status ? PSF_LOADED : PSF_FAILURE); - - g_plugin_module_override_flags(self, self_flags); - - unlock_plugin_list_for_reading(); - - load_remaning_plugins(); - - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : plugin = instance représentant le greffon Python d'origine. * -* * -* Description : Charge autant de greffons composés en Python que possible. * -* * -* Retour : true. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool load_python_plugins(GPluginModule *plugin) -{ - char *paths; /* Emplacements de greffons */ - char *save; /* Sauvegarde pour ré-entrance */ - char *path; /* Chemin à fouiller */ - DIR *dir; /* Répertoire à parcourir */ - struct dirent *entry; /* Elément trouvé */ - char *modname; /* Nom du module pour Python */ - char *filename; /* Chemin d'accès reconstruit */ - GPluginModule *pyplugin; /* Lien vers un grffon Python */ - - paths = get_env_var("PYTHONPATH"); - - save = NULL; /* gcc... */ - - for (path = strtok_r(paths, ":", &save); - path != NULL; - path = strtok_r(NULL, ":", &save)) - { - dir = opendir(path); - if (dir == NULL) - { - perror("opendir"); - continue; - } - - g_plugin_module_log_variadic_message(plugin, LMT_INFO, - _("Looking for Python plugins in '%s'..."), - path); - - while (1) - { - errno = 0; - - entry = readdir(dir); - - if (entry == NULL) - { - if (errno != 0) - perror("readdir"); - - break; - - } - - if (entry->d_type != DT_DIR) continue; - if (entry->d_name[0] == '.') continue; - - modname = strdup(entry->d_name); - modname = stradd(modname, "."); - modname = stradd(modname, "__init__"); - - filename = strdup(path); - filename = stradd(filename, G_DIR_SEPARATOR_S); - filename = stradd(filename, entry->d_name); - - pyplugin = g_python_plugin_new(modname, filename); - - if (pyplugin == NULL) - g_plugin_module_log_variadic_message(plugin, LMT_ERROR, - _("No suitable Python plugin found in '%s'"), - filename); - else - { - g_plugin_module_log_variadic_message(plugin, LMT_PROCESS, - _("Loaded the Python plugin found in the '%s' directory"), - filename); - _register_plugin(pyplugin); - } - - free(filename); - free(modname); - - } - - closedir(dir); - - } - - return true; - -} - - -/****************************************************************************** -* * -* Paramètres : plugin = greffon à manipuler. * -* * -* Description : Prend acte du chargement du greffon. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -G_MODULE_EXPORT bool chrysalide_plugin_init(GPluginModule *plugin) -{ - bool result; /* Bilan à retourner */ - DIR *dir; /* Répertoire à parcourir */ - int ret; /* Bilan de préparatifs */ - - /* Définition des zones d'influence */ - - dir = opendir(PLUGINS_DIR G_DIR_SEPARATOR_S "python"); - - if (dir != NULL) - { - closedir(dir); - add_to_env_var("PYTHONPATH", PLUGINS_DIR G_DIR_SEPARATOR_S "python", ":"); - } - else - add_to_env_var("PYTHONPATH", PACKAGE_SOURCE_DIR G_DIR_SEPARATOR_S "plugins" \ - G_DIR_SEPARATOR_S "python", ":"); - - g_plugin_module_log_variadic_message(plugin, LMT_INFO, - _("PYTHONPATH environment variable set to '%s'"), - getenv("PYTHONPATH")); - - /* Chargement du module pour Python */ - - _standalone = false; - - ret = PyImport_AppendInittab("pychrysalide", &PyInit_pychrysalide); - - if (ret == -1) - { - g_plugin_module_log_variadic_message(plugin, LMT_ERROR, - _("Can not extend the existing table of Python built-in modules.")); - result = false; - goto cpi_done; - } - - Py_Initialize(); - - PySys_SetArgv(0, (wchar_t *[]) { NULL }); - - _chrysalide_module = PyImport_ImportModule("pychrysalide"); - - result = load_python_plugins(plugin); - - cpi_done: - - return result; - -} - - - -/****************************************************************************** -* * -* Paramètres : plugin = greffon à manipuler. * -* * -* Description : Prend acte du déchargement du greffon. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -G_MODULE_EXPORT void chrysalide_plugin_exit(GPluginModule *plugin) -{ - Py_XDECREF(_chrysalide_module); - -} diff --git a/plugins/pychrysa/pychrysa.h b/plugins/pychrysa/pychrysa.h deleted file mode 100644 index eb8fc5b..0000000 --- a/plugins/pychrysa/pychrysa.h +++ /dev/null @@ -1,99 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * pychrysa.h - prototypes pour le plugin permettant des extensions en Python - * - * Copyright (C) 2012-2017 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 . - */ - - -#ifndef _PLUGINS_PYCHRYSA_H -#define _PLUGINS_PYCHRYSA_H - - -/** - * Note: - * Since Python may define some pre-processor definitions which affect the standard headers - * on some systems, you must include Python.h before any standard headers are included. - * - * cf. https://docs.python.org/3.4/c-api/intro.html - */ -#include - - - - - - -#if 0 - - -#include -#include - - -#include "plugin.h" - - - -/* Précise le nom associé au greffon. */ -char *get_plugin_name(void); - -/* Initialise le greffon permettant l'usage de Python. */ -bool init_plugin(GPluginModule *, GObject *); - -/* Libère le greffon permettant l'usage de Python. */ -void exit_plugin(GPluginModule *); - -/* Indique les opérations offertes par un greffon donné. */ -PluginAction get_plugin_action(const GPluginModule *); - - -#if PY_VERSION_HEX >= 0x03000000 - -/* Point d'entrée pour l'initialisation de Python. */ -//PyMODINIT_FUNC PyInit_pychrysa(void); -PyMODINIT_FUNC initpychrysa(void); - -#else - -/* Point d'entrée pour l'initialisation de Python. */ -PyMODINIT_FUNC initpychrysa(void); - -#endif - -#endif - - - - -#include - - - -/* Point d'entrée pour l'initialisation de Python. */ -PyMODINIT_FUNC PyInit_pychrysalide(void); - -/* Prend acte du chargement du greffon. */ -G_MODULE_EXPORT bool chrysalide_plugin_init(GPluginModule *); - -/* Prend acte du déchargement du greffon. */ -G_MODULE_EXPORT void chrysalide_plugin_exit(GPluginModule *); - - - -#endif /* _PLUGINS_PYCHRYSA_H */ diff --git a/plugins/pychrysa/struct.c b/plugins/pychrysa/struct.c deleted file mode 100644 index 33b58b8..0000000 --- a/plugins/pychrysa/struct.c +++ /dev/null @@ -1,161 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * struct.c - prototypes pour la conversion de structures C en équivalent Python - * - * Copyright (C) 2017 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 "struct.h" - - - -/* Objet à vocation abstraite */ -typedef struct _PyStructObject -{ - PyDictObject base; /* A laisser en premier */ - -} PyStructObject; - - -/* Assure l'encadrement des accès aux champs d'une structure. */ -static PyObject *py_struct_getattr(PyObject *, char *); - - - -/****************************************************************************** -* * -* Paramètres : self = structure C convertie en Python. * -* name = nom du champ auquel un accès est demandé. * -* * -* Description : Assure l'encadrement des accès aux champs d'une structure. * -* * -* Retour : Valeur du champ demandé. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static PyObject *py_struct_getattr(PyObject *self, char *name) -{ - PyObject *result; /* Elément à retourner */ - PyObject *w; /* Conversion du nom de champ */ - PyTypeObject *tp; /* Type de l'objet manipulé */ - - result = PyDict_GetItemString(self, name); - - if (result != NULL) - Py_INCREF(result); - - else - { - w = PyUnicode_InternFromString(name); - if (w == NULL) return NULL; - - tp = Py_TYPE(self); - - if (tp->tp_base->tp_getattro != NULL) - result = tp->tp_base->tp_getattro(self, w); - - Py_DECREF(w); - - } - - 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_py_struct_type(void) -{ - static PyMethodDef py_struct_methods[] = { - { NULL } - }; - - static PyGetSetDef py_struct_getseters[] = { - { NULL } - }; - - static PyTypeObject py_struct_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.PyStructObject", - .tp_basicsize = sizeof(PyStructObject), - - .tp_getattr = py_struct_getattr, - - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - - .tp_doc = "PyChrysalide structure", - - .tp_methods = py_struct_methods, - .tp_getset = py_struct_getseters, - .tp_base = &PyDict_Type, - - }; - - return &py_struct_type; - -} - - -/****************************************************************************** -* * -* Paramètres : module = module dont la définition est à compléter. * -* * -* Description : Prend en charge l'objet 'pychrysalide.PyStructObject'. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_python_py_struct(PyObject *module) -{ - PyTypeObject *py_struct_type; /* Type Python 'PyStructObject'*/ - int ret; /* Bilan des préparatifs */ - - py_struct_type = get_python_py_struct_type(); - - ret = PyType_Ready(py_struct_type); - - if (ret != 0) - return false; - - Py_INCREF(py_struct_type); - - PyModule_AddObject(module, "PyStructObject", (PyObject *)py_struct_type);; - - return true; - -} diff --git a/plugins/pychrysa/struct.h b/plugins/pychrysa/struct.h deleted file mode 100644 index cca00b8..0000000 --- a/plugins/pychrysa/struct.h +++ /dev/null @@ -1,42 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * struct.h - prototypes pour la conversion de structures C en équivalent Python - * - * Copyright (C) 2017 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_PYCHRYSA_STRUCT_H -#define _PLUGINS_PYCHRYSA_STRUCT_H - - -#include -#include - - - -/* Fournit un accès à une définition de type à diffuser. */ -PyTypeObject *get_python_py_struct_type(void); - -/* Prend en charge l'objet 'pychrysalide.PyStructObject'. */ -bool register_python_py_struct(PyObject *); - - - -#endif /* _PLUGINS_PYCHRYSA_STRUCT_H */ diff --git a/plugins/pychrysa/weak.c b/plugins/pychrysa/weak.c deleted file mode 100644 index 59c5666..0000000 --- a/plugins/pychrysa/weak.c +++ /dev/null @@ -1,129 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * weak.c - définition de symboles qui n'ont pas leur place dans la version autonome - * - * Copyright (C) 2016-2017 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 "weak.h" - - - -/****************************************************************************** -* * -* Paramètres : stack = barre de statut à actualiser. * -* msg = nouveau message de statut à copier. * -* max = taille de la plage à parcourir. * -* * -* Description : Démarre le suivi d'une nouvelle activité. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -activity_id_t gtk_status_stack_add_activity(GtkStatusStack *stack, const char *msg, unsigned long max) -{ - return ~0lu; - -} - - -/****************************************************************************** -* * -* Paramètres : stack = barre de statut à actualiser. * -* id = identifiant de l'activité à cibler. * -* extra = nouvelle échéance supplémentaire des traitements. * -* * -* Description : Etend la portée des travaux d'une nouvelle activité. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void gtk_status_stack_extend_activity(GtkStatusStack *stack, activity_id_t id, unsigned long extra) -{ - ; - -} - - -/****************************************************************************** -* * -* Paramètres : stack = barre de statut à actualiser. * -* id = identifiant de l'activité à cibler. * -* msg = nouveau message de statut à copier. * -* * -* Description : Actualise les informations concernant une activité. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void gtk_status_stack_update_activity(GtkStatusStack *stack, activity_id_t id, const char *msg) -{ - ; - -} - - -/****************************************************************************** -* * -* Paramètres : stack = barre de statut à actualiser. * -* id = identifiant de l'activité à cibler. * -* inc = nouvelle valeur pour une progression donnée. * -* * -* Description : Actualise la progression d'une activité. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void gtk_status_stack_update_activity_value(GtkStatusStack *stack, activity_id_t id, unsigned long inc) -{ - ; - -} - - -/****************************************************************************** -* * -* Paramètres : stack = barre de statut à actualiser. * -* * -* Description : Met fin au suivi d'une activité donnée. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void gtk_status_stack_remove_activity(GtkStatusStack *stack, activity_id_t id) -{ - ; - -} diff --git a/plugins/pychrysa/weak.h b/plugins/pychrysa/weak.h deleted file mode 100644 index a0aadbf..0000000 --- a/plugins/pychrysa/weak.h +++ /dev/null @@ -1,50 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * weak.h - prototypes pour la définition de symboles qui n'ont pas leur place dans la version autonome - * - * Copyright (C) 2016-2017 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_PYCHRYSA_WEAK_H -#define _PLUGINS_PYCHRYSA_WEAK_H - - -#include - - - -/* Démarre le suivi d'une nouvelle activité. */ -activity_id_t gtk_status_stack_add_activity(GtkStatusStack *, const char *, unsigned long) __attribute__((weak)); - -/* Etend la portée des travaux d'une nouvelle activité. */ -void gtk_status_stack_extend_activity(GtkStatusStack *, activity_id_t, unsigned long) __attribute__((weak)); - -/* Actualise les informations concernant une activité. */ -void gtk_status_stack_update_activity(GtkStatusStack *, activity_id_t, const char *) __attribute__((weak)); - -/* Actualise la progression d'une activité. */ -void gtk_status_stack_update_activity_value(GtkStatusStack *, activity_id_t, unsigned long) __attribute__((weak)); - -/* Met fin au suivi d'une activité donnée. */ -void gtk_status_stack_remove_activity(GtkStatusStack *, activity_id_t) __attribute__((weak)); - - - -#endif /* _PLUGINS_PYCHRYSA_WEAK_H */ diff --git a/plugins/pychrysalide/Makefile.am b/plugins/pychrysalide/Makefile.am new file mode 100644 index 0000000..0648bb3 --- /dev/null +++ b/plugins/pychrysalide/Makefile.am @@ -0,0 +1,36 @@ + +pkglib_LTLIBRARIES = pychrysalide.la + +libdir = $(pluginsdir) + +pychrysalide_la_SOURCES = \ + access.h access.c \ + helpers.h helpers.c \ + plugin.h plugin.c \ + pychrysa.h pychrysa.c \ + struct.h struct.c \ + weak.h weak.c + +pychrysalide_la_LIBADD = \ + analysis/libpychrysaanalysis.la \ + arch/libpychrysaarch.la \ + common/libpychrysacommon.la \ + core/libpychrysacore.la \ + debug/libpychrysadebug.la \ + format/libpychrysaformat.la \ + glibext/libpychrysaglibext.la \ + gtkext/libpychrysagtkext.la \ + gui/libpychrysagui.la + +pychrysalide_la_LDFLAGS = -module -avoid-version \ + $(LIBPYTHON_LIBS) $(LIBPYGOBJECT_LIBS) \ + -L../../src/.libs -lchrysadisass -lchrysagui -lchrysagtkext -lchrysacore \ + -L../../src/plugins/.libs -lplugins + + +AM_CPPFLAGS = $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) \ + -I../../src + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) + +SUBDIRS = analysis arch common core debug format glibext gtkext gui diff --git a/plugins/pychrysalide/access.c b/plugins/pychrysalide/access.c new file mode 100644 index 0000000..21ff68f --- /dev/null +++ b/plugins/pychrysalide/access.c @@ -0,0 +1,137 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * access.c - accès aux modules Python en cours d'enregistrement + * + * Copyright (C) 2017 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 "access.h" + + +#include +#include + + +#include + + + +/* Lien entre un module et sa désignation */ +typedef struct _module_access +{ + const char *path; /* Chemin d'accès */ + PyObject *mod; /* Module Python en place */ + +} module_access; + + +/* Conservation de tous les accès */ +static module_access *_pychrysalide_modules = NULL; +static size_t _pychrysalide_count = 0; + + +/* Effectue la comparaison entre deux accès à des modules. */ +static int compare_python_module_accesses(const module_access *, const module_access *); + + + +/****************************************************************************** +* * +* Paramètres : a = premier accès à analyser. * +* b = second accès à analyser. * +* * +* Description : Effectue la comparaison entre deux accès à des modules. * +* * +* Retour : Bilan de la comparaison. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int compare_python_module_accesses(const module_access *a, const module_access *b) +{ + int result; /* Bilan à retourner */ + + result = strcmp(a->path, b->path); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : path = chemin d'accès à un module Python. * +* mod = module Python en question. * +* * +* Description : Enregistre une référence à un module Python en chargement. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void register_access_to_python_module(const char *path, PyObject *mod) +{ + module_access access; /* Nouvel enregistrement */ + + access.path = path; + access.mod = mod; + + Py_INCREF(mod); + + _pychrysalide_modules = qinsert(_pychrysalide_modules, &_pychrysalide_count, + sizeof(module_access), (__compar_fn_t)compare_python_module_accesses, + &access); + +} + + +/****************************************************************************** +* * +* Paramètres : path = chemin d'accès à un module Python. * +* * +* Description : Fournit la référence à un module Python défini. * +* * +* Retour : Module Python correspondant, ou NULL si aucun de trouvé. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyObject *get_access_to_python_module(const char *path) +{ + PyObject *result; /* Référence à renvoyer */ + module_access key; /* Définition à retrouver */ + module_access *access; /* Accès trouvé à consulter */ + + key.path = path; + + access = bsearch(&key, _pychrysalide_modules, _pychrysalide_count, + sizeof(module_access), (__compar_fn_t)compare_python_module_accesses); + + if (access != NULL) + result = access->mod; + else + result = NULL; + + return result; + +} diff --git a/plugins/pychrysalide/access.h b/plugins/pychrysalide/access.h new file mode 100644 index 0000000..f5d47ce --- /dev/null +++ b/plugins/pychrysalide/access.h @@ -0,0 +1,40 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * access.h - prototypes pour l'accès aux modules Python en cours d'enregistrement + * + * Copyright (C) 2017 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 . + */ + + +#ifndef _PLUGINS_PYCHRYSALIDE_ACCESS_H +#define _PLUGINS_PYCHRYSALIDE_ACCESS_H + + +#include + + + +/* Enregistre une référence à un module Python en chargement. */ +void register_access_to_python_module(const char *, PyObject *); + +/* Fournit la référence à un module Python défini. */ +PyObject *get_access_to_python_module(const char *path); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_ACCESS_H */ diff --git a/plugins/pychrysalide/analysis/Makefile.am b/plugins/pychrysalide/analysis/Makefile.am new file mode 100644 index 0000000..c1639e7 --- /dev/null +++ b/plugins/pychrysalide/analysis/Makefile.am @@ -0,0 +1,24 @@ + +noinst_LTLIBRARIES = libpychrysaanalysis.la + +libpychrysaanalysis_la_SOURCES = \ + binary.h binary.c \ + block.h block.c \ + content.h content.c \ + loaded.h loaded.c \ + module.h module.c \ + routine.h routine.c + +libpychrysaanalysis_la_LIBADD = \ + contents/libpychrysaanalysiscontents.la \ + db/libpychrysaanalysisdb.la + +libpychrysaanalysis_la_LDFLAGS = + + +AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ + -I../../../src + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) + +SUBDIRS = contents db diff --git a/plugins/pychrysalide/analysis/binary.c b/plugins/pychrysalide/analysis/binary.c new file mode 100644 index 0000000..6be767c --- /dev/null +++ b/plugins/pychrysalide/analysis/binary.c @@ -0,0 +1,381 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * binary.c - équivalent Python du fichier "analysis/binary.h" + * + * Copyright (C) 2012-2017 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 "binary.h" + + +#include + + +#include + + +#include + + +#include "content.h" +#include "../helpers.h" + + + +/* Crée un nouvel objet Python de type 'LoadedBinary'. */ +static PyObject *py_loaded_binary_new(PyTypeObject *, PyObject *, PyObject *); + +/* Fournit le nom associé à l'élément binaire. */ +static PyObject *py_loaded_binary_get_name(PyObject *, void *); + +/* Lance l'analyse d'un élément binaire chargé. */ +static PyObject *py_loaded_binary_analyse(PyObject *, PyObject *); + +/* Lance l'analyse d'un binaire chargé et attend sa conclusion. */ +static PyObject *py_loaded_binary_analyse_and_wait(PyObject *, PyObject *); + +/* Fournit le format de fichier reconnu dans le contenu binaire. */ +static PyObject *py_loaded_binary_get_format(PyObject *, void *); + +/* Fournit le processeur de l'architecture liée au binaire. */ +static PyObject *py_loaded_binary_get_processor(PyObject *, void *); + +/* Fournit le tampon associé au contenu assembleur d'un binaire. */ +static PyObject *py_loaded_binary_get_disassembled_cache(PyObject *, void *); + + + +/****************************************************************************** +* * +* Paramètres : type = type de l'objet à instancier. * +* args = arguments fournis à l'appel. * +* kwds = arguments de type key=val fournis. * +* * +* Description : Crée un nouvel objet Python de type 'LoadedBinary'. * +* * +* Retour : Instance Python mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_loaded_binary_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PyObject *result; /* Instance à retourner */ + PyObject *content_obj; /* Objet pour le contenu */ + int ret; /* Bilan de lecture des args. */ + GBinContent *content; /* Instance GLib correspondante*/ + GLoadedBinary *binary; /* Version GLib du format */ + + ret = PyArg_ParseTuple(args, "O", &content_obj); + if (!ret) return NULL; + + ret = PyObject_IsInstance(content_obj, (PyObject *)get_python_binary_content_type()); + if (ret == 0) + { + PyErr_SetString(PyExc_TypeError, _("Expected a BinContent as argument")); + return NULL; + } + + content = G_BIN_CONTENT(pygobject_get(content_obj)); + binary = g_loaded_binary_new(content); + + result = pygobject_new(G_OBJECT(binary)); + + g_object_unref(binary); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Fournit le nom associé à l'élément binaire. * +* * +* Retour : Nom de fichier avec chemin absolu. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_loaded_binary_get_name(PyObject *self, void *closure) +{ + PyObject *result; /* Trouvailles à retourner */ + GLoadedBinary *binary; /* Version native */ + const char *name; /* Désignation du binaire */ + + binary = G_LOADED_BINARY(pygobject_get(self)); + + name = g_loaded_binary_get_name(binary, true); + + result = PyUnicode_FromString(name); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = contenu binaire à manipuler. * +* args = non utilisé ici. * +* * +* Description : Lance l'analyse d'un élément binaire chargé. * +* * +* Retour : Rien (None). * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_loaded_binary_analyse(PyObject *self, PyObject *args) +{ + GLoadedBinary *binary; /* Version GLib du format */ + + binary = G_LOADED_BINARY(pygobject_get(self)); + + g_loaded_binary_analyse(binary); + + Py_RETURN_NONE; + +} + + +/****************************************************************************** +* * +* Paramètres : self = contenu binaire à manipuler. * +* args = non utilisé ici. * +* * +* Description : Lance l'analyse d'un binaire chargé et attend sa conclusion. * +* * +* Retour : Rien (None). * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_loaded_binary_analyse_and_wait(PyObject *self, PyObject *args) +{ + GLoadedBinary *binary; /* Version GLib du format */ + + binary = G_LOADED_BINARY(pygobject_get(self)); + + g_loaded_binary_analyse_and_wait(binary); + + Py_RETURN_NONE; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Fournit le format de fichier reconnu dans le contenu binaire.* +* * +* Retour : Instance du format reconnu. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_loaded_binary_get_format(PyObject *self, void *closure) +{ + PyObject *result; /* Instance Python à retourner */ + GLoadedBinary *binary; /* Binaire en cours d'analyse */ + GExeFormat *format; /* Format du binaire lié */ + + binary = G_LOADED_BINARY(pygobject_get(self)); + format = g_loaded_binary_get_format(binary); + + result = pygobject_new(G_OBJECT(format)); + + g_object_unref(G_OBJECT(format)); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Fournit le processeur de l'architecture liée au binaire. * +* * +* Retour : Instance du processeur associé. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_loaded_binary_get_processor(PyObject *self, void *closure) +{ + PyObject *result; /* Instance Python à retourner */ + GLoadedBinary *binary; /* Binaire en cours d'analyse */ + GArchProcessor *proc; /* Architecture visée */ + + binary = G_LOADED_BINARY(pygobject_get(self)); + proc = g_loaded_binary_get_processor(binary); + + result = pygobject_new(G_OBJECT(proc)); + + g_object_unref(G_OBJECT(proc)); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant une instruction. * +* closure = adresse non utilisée ici. * +* * +* Description : Fournit le tampon associé au contenu assembleur d'un binaire.* +* * +* Retour : Valeur associée à la propriété consultée. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_loaded_binary_get_disassembled_cache(PyObject *self, void *closure) +{ + PyObject *result; /* Trouvailles à retourner */ + GLoadedBinary *binary; /* Version native */ + GBufferCache *cache; /* Tampon à récupérer */ + + binary = G_LOADED_BINARY(pygobject_get(self)); + cache = g_loaded_binary_get_disassembled_cache(binary); + + result = pygobject_new(G_OBJECT(cache)); + + g_object_unref(G_OBJECT(cache)); + + 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_loaded_binary_type(void) +{ + static PyMethodDef py_loaded_binary_methods[] = { + { + "analyse", py_loaded_binary_analyse, + METH_NOARGS, + "analyse(/)\n--\n\nStart the analysis of the loaded binary and " \ + "send a \"disassembly-done\" signal when done." + }, + { + "analyse_and_wait", py_loaded_binary_analyse_and_wait, + METH_NOARGS, + "analyse_and_wait(/)\n--\n\nRun the analysis of the loaded binary and " \ + "wait for its completion." + }, + { NULL } + }; + + static PyGetSetDef py_loaded_binary_getseters[] = { + { + "name", py_loaded_binary_get_name, NULL, + "Name of the loaded binary.", NULL + }, + { + "format", py_loaded_binary_get_format, NULL, + "File format recognized in the binary content.", NULL + }, + { + "processor", py_loaded_binary_get_processor, NULL, + "Handler for the current binary processor.", NULL + }, + { + "disassembled_cache", py_loaded_binary_get_disassembled_cache, NULL, + "Disassembled buffer cache.", NULL + }, + { NULL } + }; + + static PyTypeObject py_loaded_binary_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.analysis.LoadedBinary", + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + + .tp_doc = "PyChrysalide loaded binary", + + .tp_methods = py_loaded_binary_methods, + .tp_getset = py_loaded_binary_getseters, + .tp_new = (newfunc)py_loaded_binary_new + + }; + + return &py_loaded_binary_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.analysis.LoadedBinary'.* +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_loaded_binary(PyObject *module) +{ + PyTypeObject *py_loaded_binary_type; /* Type Python 'LoadedBinary' */ + PyObject *dict; /* Dictionnaire du module */ + + py_loaded_binary_type = get_python_loaded_binary_type(); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_LOADED_BINARY, py_loaded_binary_type, &PyGObject_Type)) + return false; + + return true; + +} diff --git a/plugins/pychrysalide/analysis/binary.h b/plugins/pychrysalide/analysis/binary.h new file mode 100644 index 0000000..d134111 --- /dev/null +++ b/plugins/pychrysalide/analysis/binary.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * binary.h - prototypes pour l'équivalent Python du fichier "analysis/binary.h" + * + * Copyright (C) 2012-2017 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_PYOIDA_ANALYSIS_BINARY_H +#define _PLUGINS_PYOIDA_ANALYSIS_BINARY_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_loaded_binary_type(void); + +/* Prend en charge l'objet 'pychrysalide.analysis.LoadedBinary'. */ +bool register_python_loaded_binary(PyObject *); + + + +#endif /* _PLUGINS_PYOIDA_ANALYSIS_BINARY_H */ diff --git a/plugins/pychrysalide/analysis/block.c b/plugins/pychrysalide/analysis/block.c new file mode 100644 index 0000000..edd364d --- /dev/null +++ b/plugins/pychrysalide/analysis/block.c @@ -0,0 +1,274 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * block.c - équivalent Python du fichier "analysis/block.c" + * + * Copyright (C) 2013-2017 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 "block.h" + + +#include + + +#include + + +#include "../helpers.h" + + + +/* Permet la jonction entre C et Python lors des visites */ +typedef struct _py_block_vdata +{ + PyObject *func; /* Fonction à appeler */ + PyObject *user; /* Donnée à faire suivre */ + +} py_block_vdata; + + +/* Parcourt le bloc d'instructions dans un ordre donné. */ +static bool py_block_visitor_glue(GInstrBlock *, BlockVisitOrder, py_block_vdata *); + +/* Parcourt tous les blocs d'instructions dans un ordre donné. */ +static PyObject *py_instructions_block_visit(PyObject *, PyObject *); + +/* Fournit l'ensemble contenant les blocs liés. */ +static PyObject *py_instructions_block_get_links_block(PyObject *, PyObject *); + +/* Définit les constantes pour les blocs basiques. */ +static bool py_instructions_block_define_constants(PyTypeObject *); + + + +/****************************************************************************** +* * +* Paramètres : block = bloc d'instructions concerné par la visite. * +* order = indication sur la position dans le parcours. * +* data = donnée utilisateur à associer au parcours. * +* * +* Description : Parcourt le bloc d'instructions dans un ordre donné. * +* * +* Retour : true si le parcours a été jusqu'à son terme, false sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool py_block_visitor_glue(GInstrBlock *block, BlockVisitOrder order, py_block_vdata *data) +{ + bool result; /* Bilan à retourner */ + PyObject *args; /* Arguments pour l'appel */ + PyObject *value; /* Retour obtenu */ + + Py_INCREF(data->user); + + args = PyTuple_New(3); + PyTuple_SetItem(args, 0, pygobject_new(G_OBJECT(block))); + PyTuple_SetItem(args, 1, PyLong_FromLong(order)); + PyTuple_SetItem(args, 2, data->user); + + value = _run_python_method(data->func, args); + result = (value == Py_True); + + Py_XDECREF(value); + Py_DECREF(args); + + return result; + +} + + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant un binaire. * +* args = arguments fournis à l'appel. * +* * +* Description : Parcourt tous les blocs d'instructions dans un ordre donné. * +* * +* Retour : True si le parcours a été jusqu'à son terme, False sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_instructions_block_visit(PyObject *self, PyObject *args) +{ + PyObject *result; /* Conclusion à retourner */ + py_block_vdata data; /* Transition entre C et Python*/ + int ret; /* Bilan de lecture des args. */ + GInstrBlock *block; /* Point de départ des visites */ + bool status; /* Bilan du parcours */ + + ret = PyArg_ParseTuple(args, "OO", &data.func, &data.user); + if (!ret) Py_RETURN_NONE; + + if (PyCallable_Check(data.func) != 1) return NULL; + + block = G_INSTR_BLOCK(pygobject_get(self)); + status = g_instr_block_visit(block, (instr_block_visitor_cb)py_block_visitor_glue, &data); + + result = (status ? Py_True : Py_False); + Py_INCREF(result); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant un binaire. * +* args = arguments fournis à l'appel. * +* * +* Description : Fournit l'ensemble contenant les blocs liés. * +* * +* Retour : Bloc contenant les blocs liés au bloc. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_instructions_block_get_links_block(PyObject *self, PyObject *args) +{ + PyObject *result; /* Conclusion à retourner */ + GInstrBlock *block; /* Point de départ des visites */ + + block = G_INSTR_BLOCK(pygobject_get(self)); + + block = g_instr_block_get_links_block(block); + + result = pygobject_new(G_OBJECT(block)); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : obj_type = type dont le dictionnaire est à compléter. * +* * +* Description : Définit les constantes pour les blocs basiques. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool py_instructions_block_define_constants(PyTypeObject *obj_type) +{ + bool result; /* Bilan à retourner */ + + result = true; + + result &= PyDict_AddIntMacro(obj_type, BVO_IN); + result &= PyDict_AddIntMacro(obj_type, BVO_PENDING); + result &= PyDict_AddIntMacro(obj_type, BVO_OUT); + + 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_instr_block_type(void) +{ + static PyMethodDef py_instr_block_methods[] = { + { + "visit", (PyCFunction)py_instructions_block_visit, + METH_VARARGS, + "visit($self, cb, data, /)\n--\n\nVisit all the basic blocks, starting at the provided one." + }, + { + "get_links_block", (PyCFunction)py_instructions_block_get_links_block, + METH_VARARGS, + "get_links_block($self, /)\n--\n\nGet the block containing all blocks linked to the caller." + }, + { NULL } + }; + + static PyGetSetDef py_instr_block_getseters[] = { + { NULL } + }; + + static PyTypeObject py_instr_block_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.analysis.InstrBlock", + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + + .tp_doc = "PyChrysalide basic block", + + .tp_methods = py_instr_block_methods, + .tp_getset = py_instr_block_getseters, + + }; + + return &py_instr_block_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.analysis.InstrBlock'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_instr_block(PyObject *module) +{ + PyTypeObject *py_instr_block_type; /* Type Python 'InstrBlock' */ + PyObject *dict; /* Dictionnaire du module */ + + py_instr_block_type = get_python_instr_block_type(); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_INSTR_BLOCK, py_instr_block_type, &PyGObject_Type)) + return false; + + if (!py_instructions_block_define_constants(py_instr_block_type)) + return false; + + return true; + +} diff --git a/plugins/pychrysalide/analysis/block.h b/plugins/pychrysalide/analysis/block.h new file mode 100644 index 0000000..1f87445 --- /dev/null +++ b/plugins/pychrysalide/analysis/block.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * block.h - prototypes pour l'équivalent Python du fichier "analysis/block.h" + * + * Copyright (C) 2013-2017 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_PYOIDA_ANALYSIS_BLOCK_H +#define _PLUGINS_PYOIDA_ANALYSIS_BLOCK_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_instr_block_type(void); + +/* Prend en charge l'objet 'pychrysalide.analysis.InstrBlock'. */ +bool register_python_instr_block(PyObject *); + + + +#endif /* _PLUGINS_PYOIDA_ANALYSIS_BLOCK_H */ diff --git a/plugins/pychrysalide/analysis/content.c b/plugins/pychrysalide/analysis/content.c new file mode 100644 index 0000000..1f36eb8 --- /dev/null +++ b/plugins/pychrysalide/analysis/content.c @@ -0,0 +1,460 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * content.c - prototypes pour l'équivalent Python du fichier "analysis/content.c" + * + * Copyright (C) 2015-2017 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 "content.h" + + +#include +#include + + +#include + + +#include +#include + + +#include "../arch/vmpa.h" + + + +/* Fournit une empreinte unique (SHA256) pour les données. */ +static PyObject *py_binary_content_get_checksum(PyObject *, PyObject *); + +/* Détermine le nombre d'octets lisibles. */ +static PyObject *py_binary_content_compute_size(PyObject *, PyObject *); + +/* Fournit une portion des données représentées. */ +static PyObject *py_binary_content_read_raw(PyObject *, PyObject *); + +/* Lit un nombre non signé sur un octet. */ +static PyObject *py_binary_content_read_u8(PyObject *, PyObject *); + +/* Lit un nombre non signé sur deux octets. */ +static PyObject *py_binary_content_read_u16(PyObject *, PyObject *); + +/* Lit un nombre non signé sur quatre octets. */ +static PyObject *py_binary_content_read_u32(PyObject *, PyObject *); + +/* Lit un nombre non signé sur huit octets. */ +static PyObject *py_binary_content_read_u64(PyObject *, PyObject *); + + + +/****************************************************************************** +* * +* Paramètres : self = contenu binaire à manipuler. * +* args = non utilisé ici. * +* * +* Description : Fournit une empreinte unique (SHA256) pour les données. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_content_get_checksum(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GBinContent *content; /* Version GLib du format */ + const gchar *checksum; /* Empreinte fournie */ + + content = G_BIN_CONTENT(pygobject_get(self)); + + checksum = g_binary_content_get_checksum(content); + + result = PyUnicode_FromString(checksum); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = contenu binaire à manipuler. * +* args = non utilisé ici. * +* * +* Description : Détermine le nombre d'octets lisibles. * +* * +* Retour : Quantité représentée. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_content_compute_size(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GBinContent *content; /* Version GLib du format */ + phys_t size; /* Quantité d'octets dispos. */ + + content = G_BIN_CONTENT(pygobject_get(self)); + + size = g_binary_content_compute_size(content); + + result = PyLong_FromUnsignedLongLong(size); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = contenu binaire à manipuler. * +* args = non utilisé ici. * +* * +* Description : Fournit une portion des données représentées. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_content_read_raw(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GBinContent *content; /* Version GLib du format */ + PyObject *addr_obj; /* Objet pour une position */ + vmpa2t *addr; /* Position interne associée */ + unsigned long long length; /* Quantité de données à lire */ + int ret; /* Bilan de lecture des args. */ + const bin_t *val; /* Valeur lue à faire suivre */ + + content = G_BIN_CONTENT(pygobject_get(self)); + assert(content != NULL); + + ret = PyArg_ParseTuple(args, "OK", &addr_obj, &length); + if (!ret) return NULL; + + addr = get_internal_vmpa(addr_obj); + assert(addr != NULL); + + val = g_binary_content_get_raw_access(content, addr, length); + if (val == NULL) + { + PyErr_SetString(PyExc_Exception, _("Invalid read access.")); + return NULL; + } + + result = PyBytes_FromStringAndSize((char *)val, length); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = contenu binaire à manipuler. * +* args = non utilisé ici. * +* * +* Description : Lit un nombre non signé sur un octet. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_content_read_u8(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GBinContent *content; /* Version GLib du format */ + int ret; /* Bilan de lecture des args. */ + PyObject *addr_obj; /* Objet pour une position */ + vmpa2t *addr; /* Position interne associée */ + uint8_t val; /* Valeur lue à faire suivre */ + bool status; /* Bilan de l'opération */ + + content = G_BIN_CONTENT(pygobject_get(self)); + assert(content != NULL); + + ret = PyArg_ParseTuple(args, "O", &addr_obj); + if (!ret) return NULL; + + addr = get_internal_vmpa(addr_obj); + assert(addr != NULL); + + status = g_binary_content_read_u8(content, addr, &val); + if (!status) + { + PyErr_SetString(PyExc_Exception, _("Invalid read access.")); + return NULL; + } + + result = PyLong_FromUnsignedLong(val); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = contenu binaire à manipuler. * +* args = non utilisé ici. * +* * +* Description : Lit un nombre non signé sur deux octets. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_content_read_u16(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GBinContent *content; /* Version GLib du format */ + int ret; /* Bilan de lecture des args. */ + PyObject *addr_obj; /* Objet pour une position */ + unsigned long endianness; /* Boutisme de la lecture */ + vmpa2t *addr; /* Position interne associée */ + uint16_t val; /* Valeur lue à faire suivre */ + bool status; /* Bilan de l'opération */ + + content = G_BIN_CONTENT(pygobject_get(self)); + assert(content != NULL); + + ret = PyArg_ParseTuple(args, "Ok", &addr_obj, &endianness); + if (!ret) return NULL; + + addr = get_internal_vmpa(addr_obj); + assert(addr != NULL); + + status = g_binary_content_read_u16(content, addr, endianness, &val); + if (!status) + { + PyErr_SetString(PyExc_Exception, _("Invalid read access.")); + return NULL; + } + + result = PyLong_FromUnsignedLong(val); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = contenu binaire à manipuler. * +* args = non utilisé ici. * +* * +* Description : Lit un nombre non signé sur quatre octets. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_content_read_u32(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GBinContent *content; /* Version GLib du format */ + int ret; /* Bilan de lecture des args. */ + PyObject *addr_obj; /* Objet pour une position */ + unsigned long endianness; /* Boutisme de la lecture */ + vmpa2t *addr; /* Position interne associée */ + uint32_t val; /* Valeur lue à faire suivre */ + bool status; /* Bilan de l'opération */ + + content = G_BIN_CONTENT(pygobject_get(self)); + assert(content != NULL); + + ret = PyArg_ParseTuple(args, "Ok", &addr_obj, &endianness); + if (!ret) return NULL; + + addr = get_internal_vmpa(addr_obj); + assert(addr != NULL); + + status = g_binary_content_read_u32(content, addr, endianness, &val); + if (!status) + { + PyErr_SetString(PyExc_Exception, _("Invalid read access.")); + return NULL; + } + + result = PyLong_FromUnsignedLong(val); + + return result; + +} + +/****************************************************************************** +* * +* Paramètres : self = contenu binaire à manipuler. * +* args = non utilisé ici. * +* * +* Description : Lit un nombre non signé sur huit octets. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_content_read_u64(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GBinContent *content; /* Version GLib du format */ + int ret; /* Bilan de lecture des args. */ + PyObject *addr_obj; /* Objet pour une position */ + unsigned long endianness; /* Boutisme de la lecture */ + vmpa2t *addr; /* Position interne associée */ + uint64_t val; /* Valeur lue à faire suivre */ + bool status; /* Bilan de l'opération */ + + content = G_BIN_CONTENT(pygobject_get(self)); + assert(content != NULL); + + ret = PyArg_ParseTuple(args, "Ok", &addr_obj, &endianness); + if (!ret) return NULL; + + addr = get_internal_vmpa(addr_obj); + assert(addr != NULL); + + status = g_binary_content_read_u64(content, addr, endianness, &val); + if (!status) + { + PyErr_SetString(PyExc_Exception, _("Invalid read access.")); + return NULL; + } + + result = PyLong_FromUnsignedLongLong(val); + + 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_binary_content_type(void) +{ + static PyMethodDef py_binary_content_methods[] = { + { + "get_checksum", py_binary_content_get_checksum, + METH_NOARGS, + "get_checksum($self, /)\n--\n\nCompute a SHA256 hash as chechsum of handled data." + }, + { + "compute_size", py_binary_content_compute_size, + METH_NOARGS, + "compute_size($self, /)\n--\n\nCompute the quantity of readable bytes." + }, + { + "read_raw", py_binary_content_read_raw, + METH_VARARGS, + "read_raw($self, addr, length, /)\n--\n\nRead bytes from a given position." + }, + { + "read_u8", py_binary_content_read_u8, + METH_VARARGS, + "read_u8($self, addr, /)\n--\n\nRead an unsigned byte from a given position." + }, + { + "read_u16", py_binary_content_read_u16, + METH_VARARGS, + "read_u16($self, addr, endianness, /)\n--\n\nRead two unsigned bytes from a given position." + }, + { + "read_u32", py_binary_content_read_u32, + METH_VARARGS, + "read_u32($self, addr, endianness, /)\n--\n\nRead four unsigned bytes from a given position." + }, + { + "read_u64", py_binary_content_read_u64, + METH_VARARGS, + "read_u64($self, addr, endianness, /)\n--\n\nRead eight unsigned bytes from a given position." + }, + { NULL } + }; + + static PyGetSetDef py_binary_content_getseters[] = { + { NULL } + }; + + static PyTypeObject py_binary_content_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.analysis.BinContent", + .tp_basicsize = sizeof(PyObject), + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + + .tp_doc = "PyChrysalide binary content", + + .tp_methods = py_binary_content_methods, + .tp_getset = py_binary_content_getseters + + }; + + return &py_binary_content_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.analysis.BinContent'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_binary_content(PyObject *module) +{ + PyTypeObject *py_binary_content_type; /* Type Python 'BinContent' */ + PyObject *dict; /* Dictionnaire du module */ + + py_binary_content_type = get_python_binary_content_type(); + + dict = PyModule_GetDict(module); + pyg_register_interface(dict, "BinContent", G_TYPE_BIN_CONTENT, py_binary_content_type); + + return true; + +} diff --git a/plugins/pychrysalide/analysis/content.h b/plugins/pychrysalide/analysis/content.h new file mode 100644 index 0000000..71d8100 --- /dev/null +++ b/plugins/pychrysalide/analysis/content.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * content.h - prototypes pour l'équivalent Python du fichier "analysis/content.h" + * + * Copyright (C) 2015-2017 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_ANALYSIS_CONTENT_H +#define _PLUGINS_PYCHRYSALIDE_ANALYSIS_CONTENT_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_binary_content_type(void); + +/* Prend en charge l'objet 'pychrysalide.analysis.BinContent'. */ +bool register_python_binary_content(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_CONTENT_H */ diff --git a/plugins/pychrysalide/analysis/contents/Makefile.am b/plugins/pychrysalide/analysis/contents/Makefile.am new file mode 100644 index 0000000..3cd00a6 --- /dev/null +++ b/plugins/pychrysalide/analysis/contents/Makefile.am @@ -0,0 +1,15 @@ + +noinst_LTLIBRARIES = libpychrysaanalysiscontents.la + +libpychrysaanalysiscontents_la_SOURCES = \ + file.h file.c \ + module.h module.c \ + restricted.h restricted.c + +libpychrysaanalysiscontents_la_LDFLAGS = + + +AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ + -I../../../../src + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) diff --git a/plugins/pychrysalide/analysis/contents/file.c b/plugins/pychrysalide/analysis/contents/file.c new file mode 100644 index 0000000..b033611 --- /dev/null +++ b/plugins/pychrysalide/analysis/contents/file.c @@ -0,0 +1,149 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * file.c - prototypes pour l'équivalent Python du fichier "analysis/contents/file.c" + * + * Copyright (C) 2015-2017 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 "file.h" + + +#include + + +#include + + +#include "../../helpers.h" + + + +/* Crée un nouvel objet Python de type 'BinContent'. */ +static PyObject *py_file_content_new(PyTypeObject *, PyObject *, PyObject *); + + + +/****************************************************************************** +* * +* Paramètres : type = type de l'objet à instancier. * +* args = arguments fournis à l'appel. * +* kwds = arguments de type key=val fournis. * +* * +* Description : Crée un nouvel objet Python de type 'BinContent'. * +* * +* Retour : Instance Python mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_file_content_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PyObject *result; /* Instance à retourner */ + const char *filename; /* Nom du fichier à charger */ + int ret; /* Bilan de lecture des args. */ + GBinContent *content; /* Version GLib du contenu */ + + ret = PyArg_ParseTuple(args, "s", &filename); + if (!ret) Py_RETURN_NONE; + + content = g_file_content_new(filename); + + result = pygobject_new(G_OBJECT(content)); + + if (content != NULL) + 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_file_content_type(void) +{ + static PyMethodDef py_file_content_methods[] = { + { NULL } + }; + + static PyGetSetDef py_file_content_getseters[] = { + { NULL } + }; + + static PyTypeObject py_file_content_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.analysis.contents.FileContent", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + + .tp_doc = "PyChrysalide binary file content", + + .tp_methods = py_file_content_methods, + .tp_getset = py_file_content_getseters, + .tp_new = (newfunc)py_file_content_new + + }; + + return &py_file_content_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.....FileContent'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_file_content(PyObject *module) +{ + PyTypeObject *py_file_content_type; /* Type Python 'FileContent' */ + PyObject *dict; /* Dictionnaire du module */ + + py_file_content_type = get_python_file_content_type(); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_FILE_CONTENT, py_file_content_type, &PyGObject_Type)) + return false; + + return true; + +} diff --git a/plugins/pychrysalide/analysis/contents/file.h b/plugins/pychrysalide/analysis/contents/file.h new file mode 100644 index 0000000..04f4395 --- /dev/null +++ b/plugins/pychrysalide/analysis/contents/file.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * file.h - prototypes pour l'équivalent Python du fichier "analysis/contents/file.h" + * + * Copyright (C) 2015-2017 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_ANALYSIS_CONTENTS_FILE_H +#define _PLUGINS_PYCHRYSALIDE_ANALYSIS_CONTENTS_FILE_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_file_content_type(void); + +/* Prend en charge l'objet 'pychrysalide.analysis.contents.FileContent'. */ +bool register_python_file_content(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_CONTENTS_FILE_H */ diff --git a/plugins/pychrysalide/analysis/contents/module.c b/plugins/pychrysalide/analysis/contents/module.c new file mode 100644 index 0000000..2daa62c --- /dev/null +++ b/plugins/pychrysalide/analysis/contents/module.c @@ -0,0 +1,97 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.c - intégration du répertoire contents en tant que module + * + * Copyright (C) 2015-2017 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 "module.h" + + +#include + + +#include "file.h" +#include "restricted.h" +#include "../../access.h" + + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Ajoute le module 'contents' au module Python. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ +#include "../content.h" +bool add_analysis_contents_module_to_python_module(PyObject *super) +{ + bool result; /* Bilan à retourner */ + PyObject *module; /* Sous-module mis en place */ + int ret; /* Bilan d'un appel */ + + static PyModuleDef py_chrysalide_contents_module = { + + .m_base = PyModuleDef_HEAD_INIT, + + .m_name = "pychrysalide.analysis.contents", + .m_doc = "Python module for Chrysalide.analysis.contents", + + .m_size = -1, + + }; + + result = false; + + module = PyModule_Create(&py_chrysalide_contents_module); + if (module == NULL) return false; + + ret = PyState_AddModule(super, &py_chrysalide_contents_module); + if (ret != 0) goto loading_failed; + + ret = _PyImport_FixupBuiltin(module, "pychrysalide.analysis.contents"); + if (ret != 0) goto loading_failed; + + Py_INCREF(module); + ret = PyModule_AddObject(super, "contents", module); + if (ret != 0) goto loading_failed; + + result = true; + + result &= register_python_binary_content(module); + + result &= register_python_file_content(module); + result &= register_python_restricted_content(module); + + if (result) + register_access_to_python_module("pychrysalide.analysis.contents", module); + + loading_failed: + + assert(result); + + return result; + +} diff --git a/plugins/pychrysalide/analysis/contents/module.h b/plugins/pychrysalide/analysis/contents/module.h new file mode 100644 index 0000000..1b6adfa --- /dev/null +++ b/plugins/pychrysalide/analysis/contents/module.h @@ -0,0 +1,39 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.h - prototypes pour l'intégration du répertoire contents en tant que module + * + * Copyright (C) 2015-2017 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_PYOIDA_ANALYSIS_CONTENTS_MODULE_H +#define _PLUGINS_PYOIDA_ANALYSIS_CONTENTS_MODULE_H + + +#include +#include + + + +/* Ajoute le module 'contents' au module Python. */ +bool add_analysis_contents_module_to_python_module(PyObject *); + + + +#endif /* _PLUGINS_PYOIDA_ANALYSIS_CONTENTS_MODULE_H */ diff --git a/plugins/pychrysalide/analysis/contents/restricted.c b/plugins/pychrysalide/analysis/contents/restricted.c new file mode 100644 index 0000000..f8b0b98 --- /dev/null +++ b/plugins/pychrysalide/analysis/contents/restricted.c @@ -0,0 +1,173 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * restricted.c - prototypes pour l'équivalent Python du fichier "analysis/contents/restricted.c" + * + * Copyright (C) 2015-2017 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 "restricted.h" + + +#include + + +#include + + +#include + + +#include "../content.h" +#include "../../helpers.h" +#include "../../arch/vmpa.h" + + + +/* Crée un nouvel objet Python de type 'BinContent'. */ +static PyObject *py_restricted_content_new(PyTypeObject *, PyObject *, PyObject *); + + + +/****************************************************************************** +* * +* Paramètres : type = type de l'objet à instancier. * +* args = arguments fournis à l'appel. * +* kwds = arguments de type key=val fournis. * +* * +* Description : Crée un nouvel objet Python de type 'BinContent'. * +* * +* Retour : Instance Python mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_restricted_content_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PyObject *result; /* Instance à retourner */ + PyObject *content_obj; /* Objet pour le contenu */ + PyObject *range_obj; /* Objet pour la restriction */ + int ret; /* Bilan de lecture des args. */ + GBinContent *content; /* Instance GLib correspondante*/ + mrange_t *range; /* Restriction à appliquer */ + GBinContent *restricted; /* Création GLib à transmettre */ + + ret = PyArg_ParseTuple(args, "OO", &content_obj, &range_obj); + if (!ret) return NULL; + + ret = PyObject_IsInstance(content_obj, (PyObject *)get_python_binary_content_type()); + if (!ret) + { + PyErr_SetString(PyExc_TypeError, _("The first argument must be an instance of BinContent.")); + 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; + } + + content = G_BIN_CONTENT(pygobject_get(content_obj)); + + range = get_internal_mrange(range_obj); + + restricted = g_restricted_content_new(content, range); + + result = pygobject_new(G_OBJECT(restricted)); + + 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_restricted_content_type(void) +{ + static PyMethodDef py_restricted_content_methods[] = { + { NULL } + }; + + static PyGetSetDef py_restricted_content_getseters[] = { + { NULL } + }; + + static PyTypeObject py_restricted_content_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.analysis.contents.RestrictedContent", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + + .tp_doc = "PyChrysalide binary restricted content", + + .tp_methods = py_restricted_content_methods, + .tp_getset = py_restricted_content_getseters, + .tp_new = (newfunc)py_restricted_content_new + + }; + + return &py_restricted_content_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.....RestrictedContent'.* +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_restricted_content(PyObject *module) +{ + PyTypeObject *py_restricted_content_type;/* Type Python 'BinContent' */ + PyObject *dict; /* Dictionnaire du module */ + + py_restricted_content_type = get_python_restricted_content_type(); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_RESTRICTED_CONTENT, + py_restricted_content_type, &PyGObject_Type)) + return false; + + return true; + +} diff --git a/plugins/pychrysalide/analysis/contents/restricted.h b/plugins/pychrysalide/analysis/contents/restricted.h new file mode 100644 index 0000000..5b7b910 --- /dev/null +++ b/plugins/pychrysalide/analysis/contents/restricted.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * restricted.h - prototypes pour l'équivalent Python du fichier "analysis/contents/restricted.h" + * + * Copyright (C) 2015-2017 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_ANALYSIS_CONTENTS_RESTRICTED_H +#define _PLUGINS_PYCHRYSALIDE_ANALYSIS_CONTENTS_RESTRICTED_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_restricted_content_type(void); + +/* Prend en charge l'objet 'pychrysalide.analysis.contents.RestrictedContent'. */ +bool register_python_restricted_content(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_CONTENTS_RESTRICTED_H */ diff --git a/plugins/pychrysalide/analysis/db/Makefile.am b/plugins/pychrysalide/analysis/db/Makefile.am new file mode 100644 index 0000000..a6bb701 --- /dev/null +++ b/plugins/pychrysalide/analysis/db/Makefile.am @@ -0,0 +1,19 @@ + +noinst_LTLIBRARIES = libpychrysaanalysisdb.la + +libpychrysaanalysisdb_la_SOURCES = \ + certs.h certs.c \ + collection.h collection.c \ + item.h item.c \ + module.h module.c + +libpychrysaanalysisdb_la_LDFLAGS = \ + items/libpychrysaanalysisdbitems.la + + +AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ + -I../../../../src + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) + +SUBDIRS = items diff --git a/plugins/pychrysalide/analysis/db/certs.c b/plugins/pychrysalide/analysis/db/certs.c new file mode 100644 index 0000000..e0358d1 --- /dev/null +++ b/plugins/pychrysalide/analysis/db/certs.c @@ -0,0 +1,327 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * certs.c - équivalent Python du fichier "analysis/db/certs.c" + * + * Copyright (C) 2017 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 "certs.h" + + +#include +#include + + +#include +#include + + +#include "../../helpers.h" + + + +/* Traduit en version native une identité de certificat. */ +static bool py_certs_fill_x509_entries(PyObject *, x509_entries *); + +/* Crée un certificat de signature racine. */ +static PyObject *py_certs_make_ca(PyObject *, PyObject *); + +/* Crée un certificat pour application. */ +static PyObject *py_certs_make_request(PyObject *, PyObject *); + +/* Signe un certificat pour application. */ +static PyObject *py_certs_sign_cert(PyObject *, PyObject *); + + + +/****************************************************************************** +* * +* Paramètres : dict = ensemble de propriétés renseignées. * +* out = résumé des entrées regroupées. [OUT] * +* * +* Description : Traduit en version native une identité de certificat. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool py_certs_fill_x509_entries(PyObject *dict, x509_entries *out) +{ + bool result; /* Bilan à retourner */ + PyObject *value; /* Valeur au format Python */ + +#define TRANSLATE_ENTRY(name, dest) \ + do \ + { \ + value = PyDict_GetItemString(dict, name); \ + if (value != NULL) \ + { \ + result = PyUnicode_Check(value); \ + if (result) \ + out->dest = strdup((char *)PyUnicode_DATA(value)); \ + else \ + PyErr_Format(PyExc_TypeError, _("The %s property must be a string."), name); \ + } \ + } \ + while (0) + + result = true; + + memset(out, 0, sizeof(x509_entries)); + + TRANSLATE_ENTRY("C", country); + + if (result) + TRANSLATE_ENTRY("ST", state); + + if (result) + TRANSLATE_ENTRY("L", locality); + + if (result) + TRANSLATE_ENTRY("O", organisation); + + if (result) + TRANSLATE_ENTRY("OU", organisational_unit); + + if (result) + TRANSLATE_ENTRY("CN", common_name); + + if (!result) + free_x509_entries(out); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = NULL car méthode statique. * +* args = paramètres à transmettre à l'appel natif. * +* * +* Description : Crée un certificat de signature racine. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_certs_make_ca(PyObject *self, PyObject *args) +{ + PyObject *result; /* Désignation à retourner */ + const char *dir; /* Répertoire de sortie */ + const char *label; /* Nom principal du certificat */ + unsigned long valid; /* Durée de validité en sec. */ + PyObject *dict; /* Détails identitaires */ + int ret; /* Bilan de lecture des args. */ + x509_entries entries; /* Définition d'une identité */ + bool status; /* Bilan d'une constitution */ + + ret = PyArg_ParseTuple(args, "sskO!", &dir, &label, &valid, &PyDict_Type, &dict); + if (!ret) return NULL; + + status = py_certs_fill_x509_entries(dict, &entries); + if (!status) return NULL; + + status = make_ca(dir, label, valid, &entries); + + free_x509_entries(&entries); + + result = status ? Py_True : Py_False; + + Py_INCREF(result); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = NULL car méthode statique. * +* args = paramètres à transmettre à l'appel natif. * +* * +* Description : Crée un certificat pour application. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_certs_make_request(PyObject *self, PyObject *args) +{ + PyObject *result; /* Désignation à retourner */ + const char *dir; /* Répertoire de sortie */ + const char *label; /* Nom principal du certificat */ + PyObject *dict; /* Détails identitaires */ + int ret; /* Bilan de lecture des args. */ + x509_entries entries; /* Définition d'une identité */ + bool status; /* Bilan d'une constitution */ + + ret = PyArg_ParseTuple(args, "ssO!", &dir, &label, &PyDict_Type, &dict); + if (!ret) return NULL; + + status = py_certs_fill_x509_entries(dict, &entries); + if (!status) return NULL; + + status = make_request(dir, label, &entries); + + free_x509_entries(&entries); + + result = status ? Py_True : Py_False; + + Py_INCREF(result); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = NULL car méthode statique. * +* args = paramètres à transmettre à l'appel natif. * +* * +* Description : Signe un certificat pour application. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_certs_sign_cert(PyObject *self, PyObject *args) +{ + PyObject *result; /* Désignation à retourner */ + const char *csr; /* Requête à satisfaire */ + const char *cacert; /* Certificat de confiance */ + const char *cakey; /* Clef de ce certificat */ + const char *cert; /* Certificat en sortie */ + unsigned long valid; /* Durée de validité en sec. */ + int ret; /* Bilan de lecture des args. */ + bool status; /* Bilan de l'opération */ + + ret = PyArg_ParseTuple(args, "ssssk", &csr, &cacert, &cakey, &cert, &valid); + if (!ret) return NULL; + + status = sign_cert(csr, cacert, cakey, cert, valid); + + result = status ? Py_True : Py_False; + + Py_INCREF(result); + + 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_certs_type(void) +{ + static PyMethodDef py_certs_methods[] = { + + { "make_ca", py_certs_make_ca, + METH_VARARGS | METH_STATIC, + "make_ca(dir, label, valid, entries, /)\n--\n\nCreate a certificate authority." + }, + { "make_request", py_certs_make_request, + METH_VARARGS | METH_STATIC, + "make_request(dir, label, entries, /)\n--\n\nCreate a certificate sign request." + }, + { "sign_cert", py_certs_sign_cert, + METH_VARARGS | METH_STATIC, + "sign_cert(csr, cacert, cakey, cert, valid, /)\n--\n\nSign a certificate sign request.." + }, + { NULL } + + }; + + static PyGetSetDef py_certs_getseters[] = { + + { NULL } + + }; + + static PyTypeObject py_certs_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.analysis.db.certs", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + + .tp_doc = "PyChrysalide support for DataBase certicates", + + .tp_methods = py_certs_methods, + .tp_getset = py_certs_getseters, + + }; + + return &py_certs_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide....db.certs'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_certs(PyObject *module) +{ + PyTypeObject *py_certs_type; /* Type Python pour 'certs' */ + int ret; /* Bilan d'un appel */ + + py_certs_type = get_python_certs_type(); + + py_certs_type->tp_new = PyType_GenericNew; + + if (PyType_Ready(py_certs_type) != 0) + return false; + + Py_INCREF(py_certs_type); + ret = PyModule_AddObject(module, "certs", (PyObject *)py_certs_type); + + return (ret == 0); + +} diff --git a/plugins/pychrysalide/analysis/db/certs.h b/plugins/pychrysalide/analysis/db/certs.h new file mode 100644 index 0000000..2e90778 --- /dev/null +++ b/plugins/pychrysalide/analysis/db/certs.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * certs.h - prototypes pour l'équivalent Python du fichier "analysis/db/certs.h" + * + * Copyright (C) 2017 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_ANALYSIS_DB_CERTS_H +#define _PLUGINS_PYCHRYSALIDE_ANALYSIS_DB_CERTS_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_certs_type(void); + +/* Prend en charge l'objet 'pychrysalide.analysis.db.certs'. */ +bool register_python_certs(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_DB_CERTSS_H */ diff --git a/plugins/pychrysalide/analysis/db/collection.c b/plugins/pychrysalide/analysis/db/collection.c new file mode 100644 index 0000000..80fcfc2 --- /dev/null +++ b/plugins/pychrysalide/analysis/db/collection.c @@ -0,0 +1,110 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * collection.c - équivalent Python du fichier "analysis/db/collection.c" + * + * Copyright (C) 2014-2017 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 "collection.h" + + +#include + + +#include +#include + + +#include "../../helpers.h" + + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *get_python_db_collection_type(void) +{ + static PyMethodDef py_db_collection_methods[] = { + { NULL } + }; + + static PyGetSetDef py_db_collection_getseters[] = { + + { NULL } + + }; + + static PyTypeObject py_db_collection_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.analysis.db.DbCollection", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + + .tp_doc = "PyChrysalide collection for DataBase collection", + + .tp_methods = py_db_collection_methods, + .tp_getset = py_db_collection_getseters, + + }; + + return &py_db_collection_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide....db.DbCollection'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_db_collection(PyObject *module) +{ + PyTypeObject *py_db_collection_type; /* Type Python 'DbCollection' */ + PyObject *dict; /* Dictionnaire du module */ + + py_db_collection_type = get_python_db_collection_type(); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_DB_COLLECTION, py_db_collection_type, &PyGObject_Type)) + return false; + + return true; + +} diff --git a/plugins/pychrysalide/analysis/db/collection.h b/plugins/pychrysalide/analysis/db/collection.h new file mode 100644 index 0000000..76256bc --- /dev/null +++ b/plugins/pychrysalide/analysis/db/collection.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * collection.h - prototypes pour l'équivalent Python du fichier "analysis/db/collection.h" + * + * Copyright (C) 2014-2017 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_ANALYSIS_DB_COLLECTION_H +#define _PLUGINS_PYCHRYSALIDE_ANALYSIS_DB_COLLECTION_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_db_collection_type(void); + +/* Prend en charge l'objet 'pychrysalide.analysis.db.DbCollection'. */ +bool register_python_db_collection(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_DB_COLLECTIONS_H */ diff --git a/plugins/pychrysalide/analysis/db/item.c b/plugins/pychrysalide/analysis/db/item.c new file mode 100644 index 0000000..27b5bac --- /dev/null +++ b/plugins/pychrysalide/analysis/db/item.c @@ -0,0 +1,182 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * item.c - équivalent Python du fichier "analysis/db/item.c" + * + * Copyright (C) 2014-2017 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 "item.h" + + +#include + + +#include +#include + + +#include "../../helpers.h" + + + +/* Indique si l'élément contient des données à oublier ou non. */ +static PyObject *py_db_item_get_volatile(PyObject *, void *); + +/* Définit si l'élément contient des données à oublier ou non. */ +static int py_db_item_set_volatile(PyObject *, PyObject *, void *); + + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Indique si l'élément contient des données à oublier ou non. * +* * +* Retour : Etat de la sauegarde de l'élément consulté. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_db_item_get_volatile(PyObject *self, void *closure) +{ + PyObject *result; /* Valeur à retourner */ + GDbItem *item; /* Elément à consulter */ + + item = G_DB_ITEM(pygobject_get(self)); + + result = (g_db_item_is_volatile(item) ? Py_True : Py_False); + Py_INCREF(result); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* value = valeur fournie à intégrer ou prendre en compte. * +* closure = non utilisé ici. * +* * +* Description : Définit si l'élément contient des données à oublier ou non. * +* * +* Retour : Bilan de l'opération pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int py_db_item_set_volatile(PyObject *self, PyObject *value, void *closure) +{ + GDbItem *item; /* Elément à modifier */ + + if (!PyBool_Check(value)) + { + PyErr_SetString(PyExc_TypeError, _("The attribute value must be a boolean.")); + return -1; + } + + item = G_DB_ITEM(pygobject_get(self)); + g_db_item_set_volatile(item, (bool)(value == Py_True)); + + return 0; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *get_python_db_item_type(void) +{ + static PyMethodDef py_db_item_methods[] = { + { NULL } + }; + + static PyGetSetDef py_db_item_getseters[] = { + + { + "volatile", py_db_item_get_volatile, py_db_item_set_volatile, + "Define if a Database item can be forgotten.", NULL + }, + { NULL } + + }; + + static PyTypeObject py_db_item_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.analysis.db.DbItem", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + + .tp_doc = "PyChrysalide item for DataBase collection", + + .tp_methods = py_db_item_methods, + .tp_getset = py_db_item_getseters, + + }; + + return &py_db_item_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide....db.items.DbItem'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_db_item(PyObject *module) +{ + PyTypeObject *py_db_item_type; /* Type Python 'DbItem' */ + PyObject *dict; /* Dictionnaire du module */ + + py_db_item_type = get_python_db_item_type(); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_DB_ITEM, py_db_item_type, &PyGObject_Type)) + return false; + + return true; + +} diff --git a/plugins/pychrysalide/analysis/db/item.h b/plugins/pychrysalide/analysis/db/item.h new file mode 100644 index 0000000..96122e6 --- /dev/null +++ b/plugins/pychrysalide/analysis/db/item.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * item.h - prototypes pour l'équivalent Python du fichier "analysis/db/item.h" + * + * Copyright (C) 2014-2017 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_ANALYSIS_DB_ITEM_H +#define _PLUGINS_PYCHRYSALIDE_ANALYSIS_DB_ITEM_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_db_item_type(void); + +/* Prend en charge l'objet 'pychrysalide.analysis.db.DbItem'. */ +bool register_python_db_item(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_DB_ITEM_H */ diff --git a/plugins/pychrysalide/analysis/db/items/Makefile.am b/plugins/pychrysalide/analysis/db/items/Makefile.am new file mode 100644 index 0000000..b08a558 --- /dev/null +++ b/plugins/pychrysalide/analysis/db/items/Makefile.am @@ -0,0 +1,14 @@ + +noinst_LTLIBRARIES = libpychrysaanalysisdbitems.la + +libpychrysaanalysisdbitems_la_SOURCES = \ + comment.h comment.c \ + module.h module.c + +libpychrysaanalysisdbitems_la_LDFLAGS = + + +AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ + -I../../../../../src + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) diff --git a/plugins/pychrysalide/analysis/db/items/comment.c b/plugins/pychrysalide/analysis/db/items/comment.c new file mode 100644 index 0000000..28886f5 --- /dev/null +++ b/plugins/pychrysalide/analysis/db/items/comment.c @@ -0,0 +1,241 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * comment.c - équivalent Python du fichier "analysis/db/items/comment.c" + * + * Copyright (C) 2014-2017 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 "comment.h" + + +#include +#include + + +#include +#include + + +#include "../item.h" +#include "../../../helpers.h" +#include "../../../arch/vmpa.h" + + + +/* Crée un nouvel objet Python de type 'DbComment'. */ +static PyObject *py_db_comment_new(PyTypeObject *, PyObject *, PyObject *); + +/* Fournit le commentaire associé à un commentaire. */ +static PyObject *py_db_comment_get_text(PyObject *, void *); + +/* Définit le commentaire associé à un commentaire. */ +static int py_db_comment_set_text(PyObject *, PyObject *, void *); + + + +/****************************************************************************** +* * +* Paramètres : type = type de l'objet à instancier. * +* args = arguments fournis à l'appel. * +* kwds = arguments de type key=val fournis. * +* * +* Description : Crée un nouvel objet Python de type 'DbComment'. * +* * +* Retour : Instance Python mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_db_comment_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PyObject *result; /* Instance à retourner */ + PyObject *py_vmpa; /* Localisation version Python */ + const char *text; /* Texte à associer */ + int is_volatile; /* Conservation en mémoire */ + int ret; /* Bilan de lecture des args. */ + vmpa2t *addr; /* Localisation version C */ + GDbComment *comment; /* Version GLib du commentaire */ + + ret = PyArg_ParseTuple(args, "Osp", &py_vmpa, &text, &is_volatile); + if (!ret) Py_RETURN_NONE; + + ret = PyObject_IsInstance(py_vmpa, (PyObject *)get_python_vmpa_type()); + if (!ret) return NULL; + + addr = get_internal_vmpa(py_vmpa); + if (py_vmpa == NULL) Py_RETURN_NONE; + + return NULL;/* FIXME */ + //comment = g_db_comment_new(addr, text, is_volatile); + + result = pygobject_new(G_OBJECT(comment)); + g_object_unref(comment); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Fournit le commentaire associé à un commentaire. * +* * +* Retour : Texte manipulable en Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_db_comment_get_text(PyObject *self, void *closure) +{ + PyObject *result; /* Résultat à retourner */ + GDbComment *comment; /* Commentaire à consulter */ + char *text; /* Contenu textuel associé */ + + comment = G_DB_COMMENT(pygobject_get(self)); + text = g_db_comment_get_text(comment); + + if (text == NULL) + { + result = Py_None; + Py_INCREF(result); + } + else + { + result = PyUnicode_FromString(text); + free(text); + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* value = valeur fournie à intégrer ou prendre en compte. * +* closure = non utilisé ici. * +* * +* Description : Définit le commentaire associé à un commentaire. * +* * +* Retour : Bilan de l'opération pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int py_db_comment_set_text(PyObject *self, PyObject *value, void *closure) +{ + GDbComment *comment; /* Commentaire à consulter */ + + if (!PyUnicode_Check(value)) + { + PyErr_SetString(PyExc_TypeError, _("The attribute value must be a string.")); + return -1; + } + + comment = G_DB_COMMENT(pygobject_get(self)); + //g_db_comment_set_text(comment, PyUnicode_DATA(value)); + + return 0; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *get_python_db_comment_type(void) +{ + static PyMethodDef py_db_comment_methods[] = { + { NULL } + }; + + static PyGetSetDef py_db_comment_getseters[] = { + { + "text", py_db_comment_get_text, py_db_comment_set_text, + "Give access to the content of a given comment.", NULL + }, + { NULL } + }; + + static PyTypeObject py_db_comment_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.analysis.db.items.DbComment", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT, + + .tp_doc = "PyChrysalide comment for edited binary", + + .tp_methods = py_db_comment_methods, + .tp_getset = py_db_comment_getseters, + .tp_new = (newfunc)py_db_comment_new + + }; + + return &py_db_comment_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide....db.items.DbComment'.* +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_db_comment(PyObject *module) +{ + PyTypeObject *py_db_comment_type; /* Type Python 'DbComment' */ + PyObject *dict; /* Dictionnaire du module */ + + py_db_comment_type = get_python_db_comment_type(); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_DB_COMMENT, py_db_comment_type, get_python_db_item_type())) + return false; + + return true; + +} diff --git a/plugins/pychrysalide/analysis/db/items/comment.h b/plugins/pychrysalide/analysis/db/items/comment.h new file mode 100644 index 0000000..2b4f130 --- /dev/null +++ b/plugins/pychrysalide/analysis/db/items/comment.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * comment.h - prototypes pour l'équivalent Python du fichier "analysis/db/items/comment.h" + * + * Copyright (C) 2014-2017 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_ANALYSIS_DB_ITEMS_COMMENT_H +#define _PLUGINS_PYCHRYSALIDE_ANALYSIS_DB_ITEMS_COMMENT_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_db_comment_type(void); + +/* Prend en charge l'objet 'pychrysalide.analysis.db.items.DbComment'. */ +bool register_python_db_comment(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_DB_ITEMS_COMMENT_H */ diff --git a/plugins/pychrysalide/analysis/db/items/module.c b/plugins/pychrysalide/analysis/db/items/module.c new file mode 100644 index 0000000..cf0fe56 --- /dev/null +++ b/plugins/pychrysalide/analysis/db/items/module.c @@ -0,0 +1,93 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.c - intégration du répertoire items en tant que module + * + * Copyright (C) 2014-2017 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 "module.h" + + +#include + + +#include "comment.h" +#include "../../../access.h" + + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Ajoute le module 'items' au module Python. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool add_analysis_db_items_module_to_python_module(PyObject *super) +{ + bool result; /* Bilan à retourner */ + PyObject *module; /* Sous-module mis en place */ + int ret; /* Bilan d'un appel */ + + static PyModuleDef py_chrysalide_items_module = { + + .m_base = PyModuleDef_HEAD_INIT, + + .m_name = "pychrysalide.analysis.db.items", + .m_doc = "Python module for Chrysalide.analysis.db.items", + + .m_size = -1, + + }; + + result = false; + + module = PyModule_Create(&py_chrysalide_items_module); + if (module == NULL) return false; + + ret = PyState_AddModule(super, &py_chrysalide_items_module); + if (ret != 0) goto loading_failed; + + ret = _PyImport_FixupBuiltin(module, "pychrysalide.analysis.db.items"); + if (ret != 0) goto loading_failed; + + Py_INCREF(module); + ret = PyModule_AddObject(super, "items", module); + if (ret != 0) goto loading_failed; + + result = true; + + result &= register_python_db_comment(module); + + if (result) + register_access_to_python_module("pychrysalide.analysis.db.items", module); + + loading_failed: + + assert(result); + + return result; + +} diff --git a/plugins/pychrysalide/analysis/db/items/module.h b/plugins/pychrysalide/analysis/db/items/module.h new file mode 100644 index 0000000..1382226 --- /dev/null +++ b/plugins/pychrysalide/analysis/db/items/module.h @@ -0,0 +1,39 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.h - prototypes pour l'intégration du répertoire items en tant que module + * + * Copyright (C) 2014-2017 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_ANALYSIS_DB_ITEMS_MODULE_H +#define _PLUGINS_PYCHRYSALIDE_ANALYSIS_DB_ITEMS_MODULE_H + + +#include +#include + + + +/* Ajoute le module 'items' au module Python. */ +bool add_analysis_db_items_module_to_python_module(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_DB_ITEMS_MODULE_H */ diff --git a/plugins/pychrysalide/analysis/db/module.c b/plugins/pychrysalide/analysis/db/module.c new file mode 100644 index 0000000..1c4da25 --- /dev/null +++ b/plugins/pychrysalide/analysis/db/module.c @@ -0,0 +1,100 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.c - intégration du répertoire db en tant que module + * + * Copyright (C) 2014-2017 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 "module.h" + + +#include + + +#include "certs.h" +#include "collection.h" +#include "item.h" +#include "items/module.h" +#include "../../access.h" + + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Ajoute le module 'db' au module Python. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool add_analysis_db_module_to_python_module(PyObject *super) +{ + bool result; /* Bilan à retourner */ + PyObject *module; /* Sous-module mis en place */ + int ret; /* Bilan d'un appel */ + + static PyModuleDef py_chrysalide_db_module = { + + .m_base = PyModuleDef_HEAD_INIT, + + .m_name = "pychrysalide.analysis.db", + .m_doc = "Python module for Chrysalide.analysis.db", + + .m_size = -1, + + }; + + result = false; + + module = PyModule_Create(&py_chrysalide_db_module); + if (module == NULL) return false; + + ret = PyState_AddModule(super, &py_chrysalide_db_module); + if (ret != 0) goto loading_failed; + + ret = _PyImport_FixupBuiltin(module, "pychrysalide.analysis.db"); + if (ret != 0) goto loading_failed; + + Py_INCREF(module); + ret = PyModule_AddObject(super, "db", module); + if (ret != 0) goto loading_failed; + + result = true; + + result &= register_python_certs(module); + result &= register_python_db_collection(module); + result &= register_python_db_item(module); + + result &= add_analysis_db_items_module_to_python_module(module); + + if (result) + register_access_to_python_module("pychrysalide.analysis.db", module); + + loading_failed: + + assert(result); + + return result; + +} diff --git a/plugins/pychrysalide/analysis/db/module.h b/plugins/pychrysalide/analysis/db/module.h new file mode 100644 index 0000000..d545ecb --- /dev/null +++ b/plugins/pychrysalide/analysis/db/module.h @@ -0,0 +1,39 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.h - prototypes pour l'intégration du répertoire db en tant que module + * + * Copyright (C) 2014-2017 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_ANALYSIS_DB_MODULE_H +#define _PLUGINS_PYCHRYSALIDE_ANALYSIS_DB_MODULE_H + + +#include +#include + + + +/* Ajoute le module 'db' au module Python. */ +bool add_analysis_db_module_to_python_module(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_DB_MODULE_H */ diff --git a/plugins/pychrysalide/analysis/loaded.c b/plugins/pychrysalide/analysis/loaded.c new file mode 100644 index 0000000..b38025a --- /dev/null +++ b/plugins/pychrysalide/analysis/loaded.c @@ -0,0 +1,146 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * loaded.c - prototypes pour l'équivalent Python du fichier "analysis/loaded.c" + * + * Copyright (C) 2017 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 "loaded.h" + + +#include +#include + + +#include + + +#include + + + +/* Détermine le nombre de vues disponibles pour un contenu. */ +static PyObject *py_loaded_content_count_views(PyObject *, PyObject *); + + + +/****************************************************************************** +* * +* Paramètres : self = contenu chargé à manipuler. * +* args = non utilisé ici. * +* * +* Description : Détermine le nombre de vues disponibles pour un contenu. * +* * +* Retour : Quantité strictement positive. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_loaded_content_count_views(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GLoadedContent *content; /* Version GLib du format */ + size_t count; /* Quantité à retourner */ + + content = G_LOADED_CONTENT(pygobject_get(self)); + + count = g_loaded_content_count_views(content); + + result = PyLong_FromUnsignedLongLong(count); + + 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_loaded_content_type(void) +{ + static PyMethodDef py_loaded_content_methods[] = { + { + "count_views", py_loaded_content_count_views, + METH_NOARGS, + "count_views($self, /)\n--\n\nCompute the quantity of available views." + }, + { NULL } + }; + + static PyGetSetDef py_loaded_content_getseters[] = { + { NULL } + }; + + static PyTypeObject py_loaded_content_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.analysis.LoadedContent", + .tp_basicsize = sizeof(PyObject), + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + + .tp_doc = "PyChrysalide loaded content", + + .tp_methods = py_loaded_content_methods, + .tp_getset = py_loaded_content_getseters + + }; + + return &py_loaded_content_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.....LoadedContent'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_loaded_content(PyObject *module) +{ + PyTypeObject *py_loaded_content_type; /* Type Python 'LoadedContent' */ + PyObject *dict; /* Dictionnaire du module */ + + py_loaded_content_type = get_python_loaded_content_type(); + + dict = PyModule_GetDict(module); + pyg_register_interface(dict, "LoadedContent", G_TYPE_LOADED_CONTENT, py_loaded_content_type); + + return true; + +} diff --git a/plugins/pychrysalide/analysis/loaded.h b/plugins/pychrysalide/analysis/loaded.h new file mode 100644 index 0000000..8f9478b --- /dev/null +++ b/plugins/pychrysalide/analysis/loaded.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * loaded.h - prototypes pour l'équivalent Python du fichier "analysis/loaded.h" + * + * Copyright (C) 2017 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_ANALYSIS_LOADED_H +#define _PLUGINS_PYCHRYSALIDE_ANALYSIS_LOADED_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_loaded_content_type(void); + +/* Prend en charge l'objet 'pychrysalide.analysis.LoadedContent'. */ +bool register_python_loaded_content(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_CONTENT_H */ diff --git a/plugins/pychrysalide/analysis/module.c b/plugins/pychrysalide/analysis/module.c new file mode 100644 index 0000000..f4a0f5b --- /dev/null +++ b/plugins/pychrysalide/analysis/module.c @@ -0,0 +1,107 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.c - intégration du répertoire analysis en tant que module + * + * Copyright (C) 2012-2017 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 "module.h" + + +#include + + +#include "binary.h" +#include "block.h" +#include "content.h" +#include "loaded.h" +#include "routine.h" +#include "contents/module.h" +#include "db/module.h" +#include "../access.h" + + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Ajoute le module 'analysis' au module Python. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool add_analysis_module_to_python_module(PyObject *super) +{ + bool result; /* Bilan à retourner */ + PyObject *module; /* Sous-module mis en place */ + int ret; /* Bilan d'un appel */ + + static PyModuleDef py_chrysalide_analysis_module = { + + .m_base = PyModuleDef_HEAD_INIT, + + .m_name = "pychrysalide.analysis", + .m_doc = "Python module for Chrysalide.analysis", + + .m_size = -1, + + }; + + result = false; + + module = PyModule_Create(&py_chrysalide_analysis_module); + if (module == NULL) return false; + + ret = PyState_AddModule(super, &py_chrysalide_analysis_module); + if (ret != 0) goto loading_failed; + + ret = _PyImport_FixupBuiltin(module, "pychrysalide.analysis"); + if (ret != 0) goto loading_failed; + + Py_INCREF(module); + ret = PyModule_AddObject(super, "analysis", module); + if (ret != 0) goto loading_failed; + + result = true; + + result &= register_python_loaded_content(module); + + result &= register_python_loaded_binary(module); + result &= register_python_instr_block(module); + //result &= register_python_binary_content(module); + result &= register_python_binary_routine(module); + + result &= add_analysis_contents_module_to_python_module(module); + result &= add_analysis_db_module_to_python_module(module); + + if (result) + register_access_to_python_module("pychrysalide.analysis", module); + + loading_failed: + + assert(result); + + return result; + +} diff --git a/plugins/pychrysalide/analysis/module.h b/plugins/pychrysalide/analysis/module.h new file mode 100644 index 0000000..310fc0c --- /dev/null +++ b/plugins/pychrysalide/analysis/module.h @@ -0,0 +1,39 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.h - prototypes pour l'intégration du répertoire analysis en tant que module + * + * Copyright (C) 2012-2017 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_ANALYSIS_MODULE_H +#define _PLUGINS_PYCHRYSALIDE_ANALYSIS_MODULE_H + + +#include +#include + + + +/* Ajoute le module 'analysis' au module Python. */ +bool add_analysis_module_to_python_module(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_ANALYSIS_MODULE_H */ diff --git a/plugins/pychrysalide/analysis/routine.c b/plugins/pychrysalide/analysis/routine.c new file mode 100644 index 0000000..37f36a7 --- /dev/null +++ b/plugins/pychrysalide/analysis/routine.c @@ -0,0 +1,295 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * routine.c - équivalent Python du fichier "analysis/routine.c" + * + * Copyright (C) 2013-2017 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 "routine.h" + + +#include +#include + + +#include + + +#include +#include + + +#include "block.h" +#include "../helpers.h" +#include "../format/symbol.h" + + + +/* Crée un nouvel objet Python de type 'BinRoutine'. */ +static PyObject *py_binary_routine_new(PyTypeObject *, PyObject *, PyObject *); + +/* Fournit le nom humain d'une routine. */ +static PyObject *py_binary_routine_get_name(PyObject *, void *); + +/* Définit le nom humain d'une routine. */ +static int py_binary_routine_set_name(PyObject *, PyObject *, void *); + +/* Fournit les blocs basiques de la routine. */ +static PyObject *py_binary_routine_get_basic_blocks(PyObject *, void *); + + + +/****************************************************************************** +* * +* Paramètres : type = type de l'objet à instancier. * +* args = arguments fournis à l'appel. * +* kwds = arguments de type key=val fournis. * +* * +* Description : Crée un nouvel objet Python de type 'BinaryRoutine'. * +* * +* Retour : Instance Python mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_routine_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PyObject *result; /* Création à retourner */ + + result = pygobject_new(G_OBJECT(g_binary_routine_new())); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Fournit le nom humain d'une routine. * +* * +* Retour : Désignation humainement lisible ou None si non définie. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_routine_get_name(PyObject *self, void *closure) +{ + PyObject *result; /* Valeur à retourner */ + GBinRoutine *routine; /* Elément à consulter */ + const char *name; /* Désignation courante */ + + routine = G_BIN_ROUTINE(pygobject_get(self)); + name = g_binary_routine_get_name(routine); + + if (name != NULL) + result = PyUnicode_FromString(name); + else + { + result = Py_None; + Py_INCREF(result); + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* value = valeur fournie à intégrer ou prendre en compte. * +* closure = non utilisé ici. * +* * +* Description : Définit le nom humain d'une routine. * +* * +* Retour : Bilan de l'opération pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int py_binary_routine_set_name(PyObject *self, PyObject *value, void *closure) +{ + GBinRoutine *routine; /* Elément à consulter */ + + if (!PyUnicode_Check(value) && value != Py_None) + { + PyErr_SetString(PyExc_TypeError, _("The attribute value must be a string.")); + return -1; + } + + routine = G_BIN_ROUTINE(pygobject_get(self)); + + if (!PyUnicode_Check(value)) + g_binary_routine_set_name(routine, strdup(PyUnicode_DATA(value))); + else + g_binary_routine_set_name(routine, NULL); + + return 0; + +} + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant une routine binaire. * +* closure = adresse non utilisée ici. * +* * +* Description : Fournit les blocs basiques de la routine. * +* * +* Retour : Ensemble de blocs déterminés via les instructions. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_routine_get_basic_blocks(PyObject *self, void *closure) +{ + PyObject *result; /* Eléments à retourner */ + GBinRoutine *routine; /* Version native */ + GBlockList *blocks; /* Blocs basiques de routine */ + + routine = G_BIN_ROUTINE(pygobject_get(self)); + blocks = g_binary_routine_get_basic_blocks(routine); + + result = pygobject_new(G_OBJECT(blocks)); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* value = valeur fournie à intégrer ou prendre en compte. * +* closure = non utilisé ici. * +* * +* Description : Définit les blocs basiques de la routine. * +* * +* Retour : Bilan de l'opération pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int py_binary_routine_set_basic_blocks(PyObject *self, PyObject *value, void *closure) +{ + GBinRoutine *routine; /* Elément à consulter */ + int ret; /* Bilan de lecture des args. */ + GBlockList *blocks; /* Blocs basiques à intégrer */ + + ret = PyObject_IsInstance(value, (PyObject *)get_python_instr_block_type()); + if (!ret) return -1; + + routine = G_BIN_ROUTINE(pygobject_get(self)); + blocks = G_BLOCK_LIST(pygobject_get(value)); + + g_binary_routine_set_basic_blocks(routine, blocks); + + return 0; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *get_python_binary_routine_type(void) +{ + static PyMethodDef py_binary_routine_methods[] = { + { NULL } + }; + + static PyGetSetDef py_binary_routine_getseters[] = { + { + "name", py_binary_routine_get_name, py_binary_routine_set_name, + "Name of the current routine.", NULL + }, + { + "basic_blocks", py_binary_routine_get_basic_blocks, py_binary_routine_set_basic_blocks, + "Basic blocks of the binary routine.", NULL + }, + { NULL } + }; + + static PyTypeObject py_binary_routine_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.analysis.BinRoutine", + + .tp_flags = Py_TPFLAGS_DEFAULT, + + .tp_doc = "PyChrysalide binary routine", + + .tp_methods = py_binary_routine_methods, + .tp_getset = py_binary_routine_getseters, + .tp_new = (newfunc)py_binary_routine_new + + }; + + return &py_binary_routine_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.analysis.BinRoutine'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_binary_routine(PyObject *module) +{ + PyTypeObject *py_binary_routine_type; /* Type Python 'BinRoutine' */ + PyObject *dict; /* Dictionnaire du module */ + + py_binary_routine_type = get_python_binary_routine_type(); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_BIN_ROUTINE, + py_binary_routine_type, get_python_binary_symbol_type())) + return false; + + return true; + +} diff --git a/plugins/pychrysalide/analysis/routine.h b/plugins/pychrysalide/analysis/routine.h new file mode 100644 index 0000000..57ad7bc --- /dev/null +++ b/plugins/pychrysalide/analysis/routine.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * routine.h - prototypes pour l'équivalent Python du fichier "analysis/routine.h" + * + * Copyright (C) 2013-2017 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_PYOIDA_ANALYSIS_ROUTINE_H +#define _PLUGINS_PYOIDA_ANALYSIS_ROUTINE_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_binary_routine_type(void); + +/* Prend en charge l'objet 'pychrysalide.analysis.BinRoutine'. */ +bool register_python_binary_routine(PyObject *); + + + +#endif /* _PLUGINS_PYOIDA_ANALYSIS_ROUTINE_H */ diff --git a/plugins/pychrysalide/arch/Makefile.am b/plugins/pychrysalide/arch/Makefile.am new file mode 100644 index 0000000..694c9e0 --- /dev/null +++ b/plugins/pychrysalide/arch/Makefile.am @@ -0,0 +1,25 @@ + +noinst_LTLIBRARIES = libpychrysaarch.la + +libpychrysaarch_la_SOURCES = \ + immediate.h immediate.c \ + instriter.h instriter.c \ + instruction.h instruction.c \ + module.h module.c \ + operand.h operand.c \ + processor.h processor.c \ + raw.h raw.c \ + vmpa.h vmpa.c + +libpychrysaarch_la_LIBADD = + + +libpychrysaarch_la_LDFLAGS = + + +AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ + -I../../../src + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) + +SUBDIRS = diff --git a/plugins/pychrysalide/arch/immediate.c b/plugins/pychrysalide/arch/immediate.c new file mode 100644 index 0000000..f1ec125 --- /dev/null +++ b/plugins/pychrysalide/arch/immediate.c @@ -0,0 +1,700 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * immediate.c - équivalent Python du fichier "arch/immediate.h" + * + * Copyright (C) 2012-2017 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 "immediate.h" + + +#include + + +#include + + +#include + + +#include "operand.h" +#include "../helpers.h" + + + +/* Fournit la valeur portée par une opérande numérique. */ +static PyObject *py_imm_operand_get_value(PyObject *, void *); + +/* Indique si l'affichage est complété avec des zéros. */ +static PyObject *py_imm_operand_get_padding_by_default(PyObject *self, void *); + +/* Précise si des zéro doivent compléter l'affichage ou non. */ +static int py_imm_operand_set_padding_by_default(PyObject *, PyObject *, void *); + +/* Indique si l'affichage est complété avec des zéros. */ +static PyObject *py_imm_operand_get_padding(PyObject *self, void *); + +/* Précise si des zéro doivent compléter l'affichage ou non. */ +static int py_imm_operand_set_padding(PyObject *, PyObject *, void *); + +/* Indique le format textuel par défaut de la valeur. */ +static PyObject *py_imm_operand_get_default_display(PyObject *, void *); + +/* Définit le format textuel par défaut de la valeur. */ +static int py_imm_operand_set_default_display(PyObject *, PyObject *, void *); + +/* Indique la grande ligne du format textuel de la valeur. */ +static PyObject *py_imm_operand_get_display(PyObject *, void *); + +/* Définit la grande ligne du format textuel de la valeur. */ +static int py_imm_operand_set_display(PyObject *, PyObject *, void *); + +/* Construit la chaîne de caractères correspondant à l'opérande. */ +static PyObject *py_imm_operand_to_string(PyObject *, PyObject *); + +/* Crée un nouvel objet Python de type 'ImmOperand'. */ +static PyObject *py_imm_operand_new(PyTypeObject *, PyObject *, PyObject *); + +/* Définit les constantes pour les opérandes d'immédiats. */ +static bool py_imm_operand_define_constants(PyTypeObject *); + + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Renseigne la taille de la valeur indiquée à la construction. * +* * +* Retour : Taille de la valeur représentée en mémoire. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_imm_operand_get_size(PyObject *self, void *closure) +{ + PyObject *result; /* Instance Python à retourner */ + GImmOperand *operand; /* Version GLib de l'opérande */ + MemoryDataSize size; /* Type de donnée représentée */ + + operand = G_IMM_OPERAND(pygobject_get(self)); + assert(operand != NULL); + + size = g_imm_operand_get_size(operand); + + result = Py_BuildValue("I", size); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Fournit la valeur portée par une opérande numérique. * +* * +* Retour : Valeur contenue dans l'opérande, ou None en cas de soucis. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_imm_operand_get_value(PyObject *self, void *closure) +{ + PyObject *result; /* Instance Python à retourner */ + GImmOperand *operand; /* Version GLib de l'opérande */ + MemoryDataSize size; /* Type de donnée représentée */ + uint8_t uval8; /* Valeur sur 8 bits */ + uint16_t uval16; /* Valeur sur 16 bits */ + uint32_t uval32; /* Valeur sur 32 bits */ + uint64_t uval64; /* Valeur sur 64 bits */ + int8_t sval8; /* Valeur sur 8 bits */ + int16_t sval16; /* Valeur sur 16 bits */ + int32_t sval32; /* Valeur sur 32 bits */ + int64_t sval64; /* Valeur sur 64 bits */ + + operand = G_IMM_OPERAND(pygobject_get(self)); + assert(operand != NULL); + + size = g_imm_operand_get_size(operand); + + switch (size) + { + /* Pour GCC... */ + case MDS_UNDEFINED: + result = Py_None; + Py_INCREF(result); + break; + case MDS_4_BITS_UNSIGNED: + case MDS_8_BITS_UNSIGNED: + g_imm_operand_get_value(operand, size, &uval8); + result = PyLong_FromUnsignedLong(uval8); + break; + case MDS_16_BITS_UNSIGNED: + g_imm_operand_get_value(operand, size, &uval16); + result = PyLong_FromUnsignedLong(uval16); + break; + case MDS_32_BITS_UNSIGNED: + g_imm_operand_get_value(operand, size, &uval32); + result = PyLong_FromUnsignedLong(uval32); + break; + case MDS_64_BITS_UNSIGNED: + g_imm_operand_get_value(operand, size, &uval64); + result = PyLong_FromUnsignedLongLong(uval64); + break; + case MDS_4_BITS_SIGNED: + case MDS_8_BITS_SIGNED: + g_imm_operand_get_value(operand, size, &sval8); + result = PyLong_FromLong(sval8); + break; + case MDS_16_BITS_SIGNED: + g_imm_operand_get_value(operand, size, &sval16); + result = PyLong_FromLong(sval16); + break; + case MDS_32_BITS_SIGNED: + g_imm_operand_get_value(operand, size, &sval32); + result = PyLong_FromLong(sval32); + break; + case MDS_64_BITS_SIGNED: + g_imm_operand_get_value(operand, size, &sval64); + result = PyLong_FromLongLong(sval64); + break; + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Indique si l'affichage est complété avec des zéros. * +* * +* Retour : true si des zéro sont ajoutés à l'affichage, false sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_imm_operand_get_padding_by_default(PyObject *self, void *closure) +{ + PyObject *result; /* Instance Python à retourner */ + GImmOperand *operand; /* Version GLib de l'opérande */ + bool padding; /* Bourrage en préfixe ? */ + + operand = G_IMM_OPERAND(pygobject_get(self)); + assert(operand != NULL); + + padding = g_imm_operand_does_padding_by_default(operand); + + result = Py_BuildValue("p", padding); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* value = valeur fournie à intégrer ou prendre en compte. * +* closure = non utilisé ici. * +* * +* Description : Précise si des zéro doivent compléter l'affichage ou non. * +* * +* Retour : Bilan de l'opération pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int py_imm_operand_set_padding_by_default(PyObject *self, PyObject *value, void *closure) +{ + bool padding; /* Bourrage en préfixe ? */ + GImmOperand *operand; /* Version GLib de l'opérande */ + + if (!PyBool_Check(value)) + { + PyErr_SetString(PyExc_TypeError, _("Invalid padding state")); + return -1; + } + + padding = (value == Py_True); + + operand = G_IMM_OPERAND(pygobject_get(self)); + assert(operand != NULL); + + g_imm_operand_pad_by_default(operand, padding); + + return 0; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Indique si l'affichage est complété avec des zéros. * +* * +* Retour : true si des zéro sont ajoutés à l'affichage, false sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_imm_operand_get_padding(PyObject *self, void *closure) +{ + PyObject *result; /* Instance Python à retourner */ + GImmOperand *operand; /* Version GLib de l'opérande */ + bool padding; /* Bourrage en préfixe ? */ + + operand = G_IMM_OPERAND(pygobject_get(self)); + assert(operand != NULL); + + padding = g_imm_operand_does_padding(operand); + + result = Py_BuildValue("p", padding); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* value = valeur fournie à intégrer ou prendre en compte. * +* closure = non utilisé ici. * +* * +* Description : Précise si des zéro doivent compléter l'affichage ou non. * +* * +* Retour : Bilan de l'opération pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int py_imm_operand_set_padding(PyObject *self, PyObject *value, void *closure) +{ + bool padding; /* Bourrage en préfixe ? */ + GImmOperand *operand; /* Version GLib de l'opérande */ + + if (!PyBool_Check(value)) + { + PyErr_SetString(PyExc_TypeError, _("Invalid padding state")); + return -1; + } + + padding = (value == Py_True); + + operand = G_IMM_OPERAND(pygobject_get(self)); + assert(operand != NULL); + + g_imm_operand_pad(operand, padding); + + return 0; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Indique le format textuel par défaut de la valeur. * +* * +* Retour : Format global d'un affichage de valeur. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_imm_operand_get_default_display(PyObject *self, void *closure) +{ + PyObject *result; /* Instance Python à retourner */ + GImmOperand *operand; /* Version GLib de l'opérande */ + ImmOperandDisplay display; /* Type d'affichage courant */ + + operand = G_IMM_OPERAND(pygobject_get(self)); + assert(operand != NULL); + + display = g_imm_operand_get_default_display(operand); + + result = Py_BuildValue("I", display); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* value = valeur fournie à intégrer ou prendre en compte. * +* closure = non utilisé ici. * +* * +* Description : Définit le format textuel par défaut de la valeur. * +* * +* Retour : Bilan de l'opération pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int py_imm_operand_set_default_display(PyObject *self, PyObject *value, void *closure) +{ + ImmOperandDisplay display; /* Type d'affichage demandé */ + GImmOperand *operand; /* Version GLib de l'opérande */ + + if (!PyLong_Check(value)) + { + PyErr_SetString(PyExc_TypeError, _("Invalid display type")); + return -1; + } + + display = PyLong_AsUnsignedLong(value); + + if (!(IOD_BIN <= display && display <= IOD_CHAR)) + { + PyErr_SetString(PyExc_TypeError, _("Invalid display type")); + return -1; + } + + operand = G_IMM_OPERAND(pygobject_get(self)); + assert(operand != NULL); + + g_imm_operand_set_default_display(operand, display); + + return 0; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Indique la grande ligne du format textuel de la valeur. * +* * +* Retour : Format global d'un affichage de valeur. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_imm_operand_get_display(PyObject *self, void *closure) +{ + PyObject *result; /* Instance Python à retourner */ + GImmOperand *operand; /* Version GLib de l'opérande */ + ImmOperandDisplay display; /* Type d'affichage courant */ + + operand = G_IMM_OPERAND(pygobject_get(self)); + assert(operand != NULL); + + display = g_imm_operand_get_display(operand); + + result = Py_BuildValue("I", display); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* value = valeur fournie à intégrer ou prendre en compte. * +* closure = non utilisé ici. * +* * +* Description : Définit la grande ligne du format textuel de la valeur. * +* * +* Retour : Bilan de l'opération pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int py_imm_operand_set_display(PyObject *self, PyObject *value, void *closure) +{ + ImmOperandDisplay display; /* Type d'affichage demandé */ + GImmOperand *operand; /* Version GLib de l'opérande */ + + if (!PyLong_Check(value)) + { + PyErr_SetString(PyExc_TypeError, _("Invalid display type")); + return -1; + } + + display = PyLong_AsUnsignedLong(value); + + if (!(IOD_BIN <= display && display <= IOD_CHAR)) + { + PyErr_SetString(PyExc_TypeError, _("Invalid display type")); + return -1; + } + + operand = G_IMM_OPERAND(pygobject_get(self)); + assert(operand != NULL); + + g_imm_operand_set_display(operand, display); + + return 0; + +} + + +/****************************************************************************** +* * +* Paramètres : self = operande à manipuler. * +* args = arguments accompagnant l'appel. * +* * +* Description : Construit la chaîne de caractères correspondant à l'opérande.* +* * +* Retour : Chaîne de caractères mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_imm_operand_to_string(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GImmOperand *operand; /* Version GLib de l'opérande */ + unsigned int raw_syntax; /* Affichage brut à utiliser */ + int ret; /* Bilan de lecture des args. */ + AsmSyntax syntax; /* Affichage final à utiliser */ + char value[IMM_MAX_SIZE]; /* Valeur humainement lisible */ + + operand = G_IMM_OPERAND(pygobject_get(self)); + assert(operand != NULL); + + ret = PyArg_ParseTuple(args, "I", &raw_syntax); + if (!ret) return NULL; + + syntax = raw_syntax; + + if (syntax != ASX_INTEL && syntax != ASX_ATT) + { + PyErr_SetString(PyExc_ValueError, _("Invalid syntax type")); + return NULL; + } + + g_imm_operand_to_string(operand, syntax, value); + + result = PyUnicode_FromString(value); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : type = type de l'objet à instancier. * +* args = arguments fournis à l'appel. * +* kwds = arguments de type key=val fournis. * +* * +* Description : Crée un nouvel objet Python de type 'ImmOperand'. * +* * +* Retour : Instance Python mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_imm_operand_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PyObject *result; /* Instance à retourner */ + unsigned int raw_size; /* Taille obtenue de Python */ + unsigned long long value; /* Valeur brute à représenter */ + int ret; /* Bilan de lecture des args. */ + MemoryDataSize size; /* Taille des données finale */ + GArchOperand *operand; /* Création GLib à transmettre */ + + ret = PyArg_ParseTuple(args, "IK", &raw_size, &value); + if (!ret) return NULL; + + size = raw_size; + + if (size != MDS_UNDEFINED + && !(MDS_4_BITS_UNSIGNED <= size && size <= MDS_64_BITS_UNSIGNED) + && !(MDS_4_BITS_SIGNED <= size && size <= MDS_64_BITS_SIGNED)) + { + PyErr_SetString(PyExc_ValueError, _("Invalid size to build an immediate operand")); + return NULL; + } + + operand = g_imm_operand_new_from_value(size, value); + + result = pygobject_new(G_OBJECT(operand)); + + g_object_unref(operand); + + return (PyObject *)result; + +} + + +/****************************************************************************** +* * +* Paramètres : obj_type = type dont le dictionnaire est à compléter. * +* * +* Description : Définit les constantes pour les opérandes d'immédiats. * +* * +* Retour : true en cas de succès de l'opération, false sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool py_imm_operand_define_constants(PyTypeObject *obj_type) +{ + bool result; /* Bilan à retourner */ + + result = true; + + result &= PyDict_AddIntMacro(obj_type, IOD_BIN); + result &= PyDict_AddIntMacro(obj_type, IOD_OCT); + result &= PyDict_AddIntMacro(obj_type, IOD_DEC); + result &= PyDict_AddIntMacro(obj_type, IOD_HEX); + result &= PyDict_AddIntMacro(obj_type, IOD_CHAR); + result &= PyDict_AddIntMacro(obj_type, IOD_COUNT); + + 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_imm_operand_type(void) +{ + static PyMethodDef py_imm_operand_methods[] = { + { + "to_string", py_imm_operand_to_string, + METH_VARARGS, + "to_string($self, syntax, /)\n--\n\nConvert the immediate operand to a string." + }, + { NULL } + }; + + static PyGetSetDef py_imm_operand_getseters[] = { + { + "size", py_imm_operand_get_size, NULL, + "Size of the value contained in the operand.", NULL + }, + { + "value", py_imm_operand_get_value, NULL, + "Value of the immediate operand.", NULL + }, + { + "padding", py_imm_operand_get_padding, py_imm_operand_set_padding, + "Status of padding with zeros in front of the textual representation.", NULL + }, + { + "default_padding", py_imm_operand_get_padding_by_default, py_imm_operand_set_padding_by_default, + "Status of default padding with zeros in front of the textual representation.", NULL + }, + { + "default_display", py_imm_operand_get_default_display, py_imm_operand_set_default_display, + "Definition of the immediate operand default textual representation.", NULL + }, + { + "display", py_imm_operand_get_display, py_imm_operand_set_display, + "Definition of the immediate operand current textual representation.", NULL + }, + { NULL } + }; + + static PyTypeObject py_imm_operand_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.arch.ImmOperand", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_BASETYPE, + + .tp_doc = "PyChrysalide immediate operand.", + + .tp_methods = py_imm_operand_methods, + .tp_getset = py_imm_operand_getseters, + .tp_new = py_imm_operand_new + + }; + + return &py_imm_operand_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.arch.ImmOperand'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_imm_operand(PyObject *module) +{ + PyTypeObject *py_imm_operand_type; /* Type Python 'BinContent' */ + PyObject *dict; /* Dictionnaire du module */ + + py_imm_operand_type = get_python_imm_operand_type(); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_IMM_OPERAND, + py_imm_operand_type, get_python_arch_operand_type())) + return false; + + if (!py_imm_operand_define_constants(py_imm_operand_type)) + return false; + + return true; + +} diff --git a/plugins/pychrysalide/arch/immediate.h b/plugins/pychrysalide/arch/immediate.h new file mode 100644 index 0000000..d6e5eba --- /dev/null +++ b/plugins/pychrysalide/arch/immediate.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * immediate.h - prototypes pour l'équivalent Python du fichier "arch/immediate.h" + * + * Copyright (C) 2017 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_PYOIDA_ARCH_IMMEDIATE_H +#define _PLUGINS_PYOIDA_ARCH_IMMEDIATE_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_imm_operand_type(void); + +/* Prend en charge l'objet 'pychrysalide.arch.ImmOperand'. */ +bool register_python_imm_operand(PyObject *); + + + +#endif /* _PLUGINS_PYOIDA_ARCH_IMMEDIATE_H */ diff --git a/plugins/pychrysalide/arch/instriter.c b/plugins/pychrysalide/arch/instriter.c new file mode 100644 index 0000000..244a825 --- /dev/null +++ b/plugins/pychrysalide/arch/instriter.c @@ -0,0 +1,276 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * instriter.c - équivalent Python du fichier "arch/instriter.c" + * + * Copyright (C) 2016-2017 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 "instriter.h" + + +#include + + +#include + + +#include "processor.h" + + + +/* Transcription d'un itérateur en Python */ +typedef struct _PyInstrIterator +{ + PyObject_HEAD; /* A laisser en premier */ + + instr_iter_t *native; /* Version native de l'objet */ + bool first_time; /* Premier élément retourné ? */ + +} PyInstrIterator; + + +/* Libère de la mémoire un itérateur sur des instructions. */ +static void py_instr_iterator_dealloc(PyInstrIterator *); + +/* Fournit l'instruction qui en suit une autre. */ +static PyObject *py_instr_iterator_next(PyInstrIterator *); + +/* Initialise un nouvel itérateur. */ +static int py_instr_iterator_init(PyInstrIterator *, PyObject *, PyObject *); + +/* Construit un nouvel itérateur. */ +static PyObject *py_instr_iterator_new(PyTypeObject *, PyObject *, PyObject *); + + + +/****************************************************************************** +* * +* Paramètres : self = itérateur à supprimer. * +* * +* Description : Libère de la mémoire un itérateur sur des instructions. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void py_instr_iterator_dealloc(PyInstrIterator *self) +{ + delete_instruction_iterator(self->native); + + Py_TYPE(self)->tp_free((PyObject *)self); + +} + + +/****************************************************************************** +* * +* Paramètres : self = itérateur à manipuler. * +* * +* Description : Fournit l'instruction qui en suit une autre. * +* * +* Retour : Instruction suivante trouvée, ou NULL. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_instr_iterator_next(PyInstrIterator *self) +{ + PyObject *result; /* Résultat à retourner */ + GArchInstruction *next; /* Instruction suivante */ + + if (self->first_time) + { + next = get_instruction_iterator_current(self->native); + self->first_time = false; + } + + else + next = get_instruction_iterator_next(self->native); + + if (next != NULL) + { + result = pygobject_new(G_OBJECT(next)); + g_object_unref(G_OBJECT(next)); + } + + else + { + PyErr_SetNone(PyExc_StopIteration); + result = NULL; + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = instance d'objet à initialiser. * +* args = arguments passés pour l'appel. * +* kwds = mots clefs éventuellement fournis en complément. * +* * +* Description : Initialise un nouvel itérateur. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int py_instr_iterator_init(PyInstrIterator *self, PyObject *args, PyObject *kwds) +{ + int result; /* Bilan à retourner */ + PyObject *proc_obj; /* Processeur version Python */ + unsigned long index; /* Indice de première instruc. */ + int ret; /* Bilan de lecture des args. */ + GArchProcessor *proc; /* Version native du processeur*/ + + result = -1; + + ret = PyArg_ParseTuple(args, "Ok", &proc_obj, &index); + if (ret == 0) goto piii_exit; + + ret = PyObject_IsInstance(proc_obj, (PyObject *)get_python_arch_processor_type()); + if (!ret) goto piii_exit; + + proc = G_ARCH_PROCESSOR(pygobject_get(proc_obj)); + + self->native = create_instruction_iterator(proc, index); + self->first_time = true; + + result = 0; + + piii_exit: + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : type = type d'objet à mettre en place. * +* args = arguments passés pour l'appel. * +* kwds = mots clefs éventuellement fournis en complément. * +* * +* Description : Construit un nouvel itérateur. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_instr_iterator_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PyInstrIterator *result; /* Nouvelle instance à renvoyer*/ + int ret; /* Bilan de l'initialisation */ + + result = (PyInstrIterator *)type->tp_alloc(type, 0); + + if (result != NULL) + { + ret = py_instr_iterator_init(result, args, kwds); + + if (ret != 0) + { + Py_DECREF(result); + result = NULL; + } + + } + + return (PyObject *)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_instr_iterator_type(void) +{ + static PyTypeObject py_instr_iterator_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.arch.InstrIterator", + .tp_basicsize = sizeof(PyInstrIterator), + + .tp_dealloc = (destructor)py_instr_iterator_dealloc, + + .tp_flags = Py_TPFLAGS_DEFAULT, + + .tp_doc = "Iterator for Chrysalide instructions loaded in a given processor.", + + .tp_iter = PyObject_SelfIter, + .tp_iternext = (iternextfunc)py_instr_iterator_next, + + .tp_init = (initproc)py_instr_iterator_init, + .tp_new = py_instr_iterator_new, + + }; + + return &py_instr_iterator_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.arch.InstrIterator'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_instr_iterator(PyObject *module) +{ + PyTypeObject *py_instr_iterator_type; /* Type Python 'BinContent' */ + int ret; /* Bilan d'un appel */ + + py_instr_iterator_type = get_python_instr_iterator_type(); + + if (PyType_Ready(py_instr_iterator_type) < 0) + return false; + + Py_INCREF(py_instr_iterator_type); + ret = PyModule_AddObject(module, "InstrIterator", (PyObject *)py_instr_iterator_type); + + return (ret == 0); + +} diff --git a/plugins/pychrysalide/arch/instriter.h b/plugins/pychrysalide/arch/instriter.h new file mode 100644 index 0000000..3cb0e38 --- /dev/null +++ b/plugins/pychrysalide/arch/instriter.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * instriter.h - prototypes pour l'équivalent Python du fichier "arch/instriter.h" + * + * Copyright (C) 2016-2017 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_ARCH_INSTRITER_H +#define _PLUGINS_PYCHRYSALIDE_ARCH_INSTRITER_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_instr_iterator_type(void); + +/* Prend en charge l'objet 'pychrysalide.arch.InstrIterator'. */ +bool register_python_instr_iterator(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_ARCH_INSTRITER_H */ diff --git a/plugins/pychrysalide/arch/instruction.c b/plugins/pychrysalide/arch/instruction.c new file mode 100644 index 0000000..bb977ce --- /dev/null +++ b/plugins/pychrysalide/arch/instruction.c @@ -0,0 +1,462 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * instruction.c - équivalent Python du fichier "arch/instruction.h" + * + * Copyright (C) 2012-2017 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 "instruction.h" + + +#include +#include + + +#include + + +#include "vmpa.h" +#include "../helpers.h" +#include "../glibext/linegen.h" + + + + +/* ------------------- DEFINITION DES LIAISONS ENTRE INSTRUCTIONS ------------------- */ + + + + + +/* --------------------- INSTRUCTIONS D'ARCHITECTURES EN PYTHON --------------------- */ + + + +/* Fournit la place mémoire d'une instruction. */ +static PyObject *py_arch_instruction_get_range(PyObject *, void *); + +/* Définit la localisation d'une instruction. */ +static int py_arch_instruction_set_range(PyObject *, PyObject *, void *); + + + +/* Fournit le nom humain de l'instruction manipulée. */ +static PyObject *py_arch_instruction_get_keyword(PyObject *, void *); + + + +/* Fournit tous les opérandes d'une instruction. */ +static PyObject *py_arch_instruction_get_operands(PyObject *, void *); + + + + + + + + + + +/* ---------------------------------------------------------------------------------- */ +/* DEFINITION DES LIAISONS ENTRE INSTRUCTIONS */ +/* ---------------------------------------------------------------------------------- */ + + + + +/* Fournit les origines d'une instruction donnée. */ +static PyObject *py_arch_instruction_get_sources(PyObject *, void *); + +/* Fournit les destinations d'une instruction donnée. */ +static PyObject *py_arch_instruction_get_destinations(PyObject *, void *); + + + + +/****************************************************************************** +* * +* Paramètres : self = instruction d'architecture à manipuler. * +* unused = adresse non utilisée ici. * +* * +* Description : Fournit les origines d'une instruction donnée. * +* * +* Retour : Nombre de ces origines. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_arch_instruction_get_sources(PyObject *self, void *unused) +{ + PyObject *result; /* Instance à retourner */ + GArchInstruction *instr; /* Version native */ + instr_link_t *source; /* Origine des liens */ + size_t count; /* Nombre de liens présents */ + size_t i; /* Boucle de parcours */ + PyObject *linked; /* Source de lien Python */ + PyObject *type; /* Nature du lien en Python */ + int ret; /* Bilan d'une écriture d'arg. */ + + instr = G_ARCH_INSTRUCTION(pygobject_get(self)); + + g_arch_instruction_lock_src(instr); + + count = g_arch_instruction_count_sources(instr); + + result = PyTuple_New(count); + + for (i = 0; i < count; i++) + { + source = g_arch_instruction_get_source(instr, i); + + linked = pygobject_new(G_OBJECT(source->linked)); + type = PyLong_FromLong(source->type); + + ret = PyTuple_SetItem(result, i, Py_BuildValue("(OO)", linked, type)); + assert(ret == 0); + + } + + g_arch_instruction_unlock_src(instr); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = instruction d'architecture à manipuler. * +* unused = adresse non utilisée ici. * +* * +* Description : Fournit les destinations d'une instruction donnée. * +* * +* Retour : Nombre de ces destinations. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_arch_instruction_get_destinations(PyObject *self, void *unused) +{ + PyObject *result; /* Instance à retourner */ + GArchInstruction *instr; /* Version native */ + instr_link_t *dest; /* Destination des liens */ + size_t count; /* Nombre de liens présents */ + size_t i; /* Boucle de parcours */ + PyObject *linked; /* Destination de lien Python */ + PyObject *type; /* Nature du lien en Python */ + int ret; /* Bilan d'une écriture d'arg. */ + + instr = G_ARCH_INSTRUCTION(pygobject_get(self)); + + g_arch_instruction_lock_dest(instr); + + count = g_arch_instruction_count_destinations(instr); + + result = PyTuple_New(count); + + for (i = 0; i < count; i++) + { + dest = g_arch_instruction_get_destination(instr, i); + + linked = pygobject_new(G_OBJECT(dest->linked)); + type = PyLong_FromLong(dest->type); + + ret = PyTuple_SetItem(result, i, Py_BuildValue("(OO)", linked, type)); + assert(ret == 0); + + } + + g_arch_instruction_unlock_dest(instr); + + return result; + +} + + + + + + + + + + + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant une instruction. * +* closure = adresse non utilisée ici. * +* * +* Description : Fournit la place mémoire d'une instruction. * +* * +* Retour : Valeur associée à la propriété consultée. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_arch_instruction_get_range(PyObject *self, void *closure) +{ + PyObject *result; /* Conversion à retourner */ + GArchInstruction *instr; /* Version native */ + const mrange_t *range; /* Espace mémoire à exporter */ + + instr = G_ARCH_INSTRUCTION(pygobject_get(self)); + range = g_arch_instruction_get_range(instr); + + result = build_from_internal_mrange(range); + + return result; + +} + + +/****************************************************************************** +* * +* 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 localisation d'une instruction. * +* * +* Retour : Bilan de l'opération pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int py_arch_instruction_set_range(PyObject *self, PyObject *value, void *closure) +{ + int ret; /* Bilan d'analyse */ + mrange_t *range; /* Espace mémoire à manipuler */ + GArchInstruction *instr; /* Version native */ + + ret = PyObject_IsInstance(value, (PyObject *)get_python_mrange_type()); + if (!ret) return -1; + + range = get_internal_mrange(value); + + instr = G_ARCH_INSTRUCTION(pygobject_get(self)); + g_arch_instruction_set_range(instr, range); + + return 0; + +} + + + + + + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant une instruction. * +* unused = adresse non utilisée ici. * +* * +* Description : Fournit le nom humain de l'instruction manipulée. * +* * +* Retour : Valeur associée à la propriété consultée. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_arch_instruction_get_keyword(PyObject *self, void *unused) +{ + PyObject *result; /* Trouvailles à retourner */ + GArchInstruction *instr; /* Version native */ + const char *kw; /* Valeur récupérée */ + + instr = G_ARCH_INSTRUCTION(pygobject_get(self)); + kw = g_arch_instruction_get_keyword(instr, 0/* FIXME*/); + + result = PyUnicode_FromString(kw); + + return result; + +} + + + + + +/****************************************************************************** +* * +* Paramètres : self = objet représentant une instruction. * +* unused = adresse non utilisée ici. * +* * +* Description : Fournit tous les opérandes d'une instruction. * +* * +* Retour : Valeur associée à la propriété consultée. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_arch_instruction_get_operands(PyObject *self, void *unused) +{ + PyObject *result; /* Instance à retourner */ + GArchInstruction *instr; /* Version native */ + size_t count; /* Nombre d'opérandes présents */ + size_t i; /* Boucle de parcours */ + GArchOperand *operand; /* Opérande à manipuler */ + PyObject *opobj; /* Version Python */ + int ret; /* Bilan d'une écriture d'arg. */ + + instr = G_ARCH_INSTRUCTION(pygobject_get(self)); + + g_arch_instruction_lock_operands(instr); + + count = _g_arch_instruction_count_operands(instr); + + result = PyTuple_New(count); + + for (i = 0; i < count; i++) + { + operand = _g_arch_instruction_get_operand(instr, i); + + opobj = pygobject_new(G_OBJECT(operand)); + + ret = PyTuple_SetItem(result, i, Py_BuildValue("O", opobj)); + assert(ret == 0); + + g_object_unref(G_OBJECT(operand)); + + } + + g_arch_instruction_unlock_operands(instr); + + 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_arch_instruction_type(void) +{ + static PyMethodDef py_arch_instruction_methods[] = { + { NULL } + }; + + static PyGetSetDef py_arch_instruction_getseters[] = { + { + "range", py_arch_instruction_get_range, py_arch_instruction_set_range, + "Give access to the memory range covered by the current instruction.", NULL + }, + { + "keyword", (getter)py_arch_instruction_get_keyword, (setter)NULL, + "Give le name of the assembly instruction.", NULL + }, + { + "operands", (getter)py_arch_instruction_get_operands, (setter)NULL, + "Provide the list of instruction attached operands.", NULL + }, + { + "sources", (getter)py_arch_instruction_get_sources, (setter)NULL, + "Provide the instructions list driving to the current instruction." + }, + { + "destinations", (getter)py_arch_instruction_get_destinations, (setter)NULL, + "Provide the instructions list following the current instruction." + }, + { NULL } + }; + + static PyTypeObject py_arch_instruction_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.arch.ArchInstruction", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_BASETYPE, + + .tp_doc = "PyChrysalide instruction for a given architecture.", + + .tp_methods = py_arch_instruction_methods, + .tp_getset = py_arch_instruction_getseters, + + }; + + return &py_arch_instruction_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.arch.ArchInstruction'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_arch_instruction(PyObject *module) +{ + PyTypeObject *py_arch_instruction_type; /* Type Python 'ArchInstruc...'*/ + PyObject *dict; /* Dictionnaire du module */ + PyTypeObject *py_line_generator_type; /* Type Python 'LineGenerator' */ + + py_arch_instruction_type = get_python_arch_instruction_type(); + + APPLY_ABSTRACT_FLAG(py_arch_instruction_type); + + dict = PyModule_GetDict(module); + + py_line_generator_type = get_python_line_generator_type(); + + if (!_register_class_for_pygobject(dict, G_TYPE_ARCH_INSTRUCTION, py_arch_instruction_type, + &PyGObject_Type, py_line_generator_type, NULL)) + return false; + + return true; + +} diff --git a/plugins/pychrysalide/arch/instruction.h b/plugins/pychrysalide/arch/instruction.h new file mode 100644 index 0000000..85a1552 --- /dev/null +++ b/plugins/pychrysalide/arch/instruction.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * instruction.h - prototypes pour l'équivalent Python du fichier "arch/instruction.h" + * + * Copyright (C) 2012-2017 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_PYOIDA_ARCH_INSTRUCTION_H +#define _PLUGINS_PYOIDA_ARCH_INSTRUCTION_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_arch_instruction_type(void); + +/* Prend en charge l'objet 'pychrysalide.arch.ArchInstruction'. */ +bool register_python_arch_instruction(PyObject *); + + + +#endif /* _PLUGINS_PYOIDA_ARCH_INSTRUCTION_H */ diff --git a/plugins/pychrysalide/arch/module.c b/plugins/pychrysalide/arch/module.c new file mode 100644 index 0000000..54b470c --- /dev/null +++ b/plugins/pychrysalide/arch/module.c @@ -0,0 +1,165 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.c - intégration du répertoire arch en tant que module + * + * Copyright (C) 2012-2017 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 "module.h" + + +#include + + +#include + + +#include "immediate.h" +#include "instriter.h" +#include "instruction.h" +#include "operand.h" +#include "processor.h" +#include "raw.h" +#include "vmpa.h" +#include "../access.h" +#include "../helpers.h" + + + +/* Définit les constantes de base pour une architecture. */ +static bool py_base_define_constants(PyTypeObject *); + + + +/****************************************************************************** +* * +* Paramètres : obj_type = type dont le dictionnaire est à compléter. * +* * +* Description : Définit les constantes de base pour une architecture. * +* * +* Retour : true en cas de succès de l'opération, false sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool py_base_define_constants(PyTypeObject *obj_type) +{ + bool result; /* Bilan à retourner */ + + result = true; + + result &= PyDict_AddIntMacro(obj_type, MDS_UNDEFINED); + + result &= PyDict_AddIntMacro(obj_type, MDS_4_BITS_UNSIGNED); + result &= PyDict_AddIntMacro(obj_type, MDS_8_BITS_UNSIGNED); + result &= PyDict_AddIntMacro(obj_type, MDS_16_BITS_UNSIGNED); + result &= PyDict_AddIntMacro(obj_type, MDS_32_BITS_UNSIGNED); + result &= PyDict_AddIntMacro(obj_type, MDS_64_BITS_UNSIGNED); + + result &= PyDict_AddIntMacro(obj_type, MDS_4_BITS_SIGNED); + result &= PyDict_AddIntMacro(obj_type, MDS_8_BITS_SIGNED); + result &= PyDict_AddIntMacro(obj_type, MDS_16_BITS_SIGNED); + result &= PyDict_AddIntMacro(obj_type, MDS_32_BITS_SIGNED); + result &= PyDict_AddIntMacro(obj_type, MDS_64_BITS_SIGNED); + + result &= PyDict_AddIntMacro(obj_type, MDS_4_BITS); + result &= PyDict_AddIntMacro(obj_type, MDS_8_BITS); + result &= PyDict_AddIntMacro(obj_type, MDS_16_BITS); + result &= PyDict_AddIntMacro(obj_type, MDS_32_BITS); + result &= PyDict_AddIntMacro(obj_type, MDS_64_BITS); + + result &= PyDict_AddIntMacro(obj_type, ASX_INTEL); + result &= PyDict_AddIntMacro(obj_type, ASX_ATT); + result &= PyDict_AddIntMacro(obj_type, ASX_COUNT); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Ajoute le module 'arch' au module Python. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool add_arch_module_to_python_module(PyObject *super) +{ + bool result; /* Bilan à retourner */ + PyObject *module; /* Sous-module mis en place */ + int ret; /* Bilan d'un appel */ + + static PyModuleDef py_chrysalide_arch_module = { + + .m_base = PyModuleDef_HEAD_INIT, + + .m_name = "pychrysalide.arch", + .m_doc = "Python module for Chrysalide.arch", + + .m_size = -1, + + }; + + result = false; + + module = PyModule_Create(&py_chrysalide_arch_module); + if (module == NULL) return false; + + ret = PyState_AddModule(super, &py_chrysalide_arch_module); + if (ret != 0) goto loading_failed; + + ret = _PyImport_FixupBuiltin(module, "pychrysalide.arch"); + if (ret != 0) goto loading_failed; + + Py_INCREF(module); + ret = PyModule_AddObject(super, "arch", module); + if (ret != 0) goto loading_failed; + + result = true; + + result &= py_base_define_constants(Py_TYPE(module)); + + result &= register_python_arch_instruction(module); + result &= register_python_arch_operand(module); + result &= register_python_arch_processor(module); + result &= register_python_instr_iterator(module); + result &= register_python_raw_instruction(module); + result &= register_python_vmpa(module); + result &= register_python_mrange(module); + + result &= register_python_imm_operand(module); + + if (result) + register_access_to_python_module("pychrysalide.arch", module); + + loading_failed: + + assert(result); + + return result; + +} diff --git a/plugins/pychrysalide/arch/module.h b/plugins/pychrysalide/arch/module.h new file mode 100644 index 0000000..07d3575 --- /dev/null +++ b/plugins/pychrysalide/arch/module.h @@ -0,0 +1,39 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.h - prototypes pour l'intégration du répertoire arch en tant que module + * + * Copyright (C) 2012-2017 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_ARCH_MODULE_H +#define _PLUGINS_PYCHRYSALIDE_ARCH_MODULE_H + + +#include +#include + + + +/* Ajoute le module 'arch' au module Python. */ +bool add_arch_module_to_python_module(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_ARCH_MODULE_H */ diff --git a/plugins/pychrysalide/arch/operand.c b/plugins/pychrysalide/arch/operand.c new file mode 100644 index 0000000..427f92b --- /dev/null +++ b/plugins/pychrysalide/arch/operand.c @@ -0,0 +1,109 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * operand.c - équivalent Python du fichier "arch/operand.h" + * + * Copyright (C) 2012-2017 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 "operand.h" + + +#include + + +#include + + +#include "../helpers.h" + + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *get_python_arch_operand_type(void) +{ + static PyMethodDef py_arch_operand_methods[] = { + { NULL } + }; + + static PyGetSetDef py_arch_operand_getseters[] = { + { NULL } + }; + + static PyTypeObject py_arch_operand_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.arch.ArchOperand", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_BASETYPE, + + .tp_doc = "PyChrysalide instruction operand.", + + .tp_methods = py_arch_operand_methods, + .tp_getset = py_arch_operand_getseters, + + }; + + return &py_arch_operand_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.arch.ArchOperand'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_arch_operand(PyObject *module) +{ + PyTypeObject *py_arch_operand_type; /* Type Python 'BinContent' */ + PyObject *dict; /* Dictionnaire du module */ + + py_arch_operand_type = get_python_arch_operand_type(); + + APPLY_ABSTRACT_FLAG(py_arch_operand_type); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_ARCH_OPERAND, py_arch_operand_type, &PyGObject_Type)) + return false; + + return true; + +} diff --git a/plugins/pychrysalide/arch/operand.h b/plugins/pychrysalide/arch/operand.h new file mode 100644 index 0000000..3c5ef6a --- /dev/null +++ b/plugins/pychrysalide/arch/operand.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * operand.h - prototypes pour l'équivalent Python du fichier "arch/operand.h" + * + * Copyright (C) 2017 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_PYOIDA_ARCH_OPERAND_H +#define _PLUGINS_PYOIDA_ARCH_OPERAND_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_arch_operand_type(void); + +/* Prend en charge l'objet 'pychrysalide.arch.ArchOperand'. */ +bool register_python_arch_operand(PyObject *); + + + +#endif /* _PLUGINS_PYOIDA_ARCH_OPERAND_H */ diff --git a/plugins/pychrysalide/arch/processor.c b/plugins/pychrysalide/arch/processor.c new file mode 100644 index 0000000..65431af --- /dev/null +++ b/plugins/pychrysalide/arch/processor.c @@ -0,0 +1,459 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * processor.c - équivalent Python du fichier "arch/processor.c" + * + * Copyright (C) 2012-2017 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 "processor.h" + + +#include +#include + + +#include + + +#include + + +#include "instriter.h" +#include "instruction.h" +#include "vmpa.h" +#include "../helpers.h" + + + + + + + + + + + + + + + + +/* ------------------ CONSERVATION DES SOUCIS DURANT LE CHARGEMENT ------------------ */ + + +/* Etend la liste des soucis détectés avec de nouvelles infos. */ +static PyObject *py_arch_processor_add_error(PyObject *, PyObject *); + +/* Fournit les éléments concernant tous les soucis détectés. */ +static PyObject *py_arch_processor_get_errors(PyObject *, void *); + + + +/* ------------------ MANIPULATIONS DES INSTRUCTIONS DESASSEMBLEES ------------------ */ + + +/* Fournit les instructions désassemblées pour une architecture. */ +static PyObject *py_arch_processor_get_instrs(PyObject *, void *); + +/* Note les instructions désassemblées avec une architecture. */ +static int py_arch_processor_set_instrs(PyObject *, PyObject *, void *); + +/* Recherche une instruction d'après son adresse. */ +static PyObject *py_arch_processor_find_instr_by_addr(PyObject *, PyObject *); + + + + + +/* Définit les constantes pour les types d'erreurs. */ +static bool define_python_arch_processor_constants(PyTypeObject *); + + + +/* ---------------------------------------------------------------------------------- */ +/* CONSERVATION DES SOUCIS DURANT LE CHARGEMENT */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : self = architecture concernée par la procédure. * +* args = instruction représentant le point de départ. * +* * +* Description : Etend la liste des soucis détectés avec de nouvelles infos. * +* * +* Retour : None. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_arch_processor_add_error(PyObject *self, PyObject *args) +{ + ArchProcessingError type; /* Type d'erreur détectée */ + vmpa2t addr; /* Position d'une erreur */ + const char *desc; /* Description d'une erreur */ + int ret; /* Bilan de lecture des args. */ + GArchProcessor *proc; /* Processeur manipulé */ + + ret = PyArg_ParseTuple(args, "IO&s", &type, convert_any_to_vmpa, &addr, &desc); + if (!ret) return NULL; + + proc = G_ARCH_PROCESSOR(pygobject_get(self)); + + g_arch_processor_add_error(proc, type, &addr, desc); + + Py_RETURN_NONE; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Fournit les éléments concernant tous les soucis détectés. * +* * +* Retour : Liste des erreurs relevées au niveau de l'assembleur. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_arch_processor_get_errors(PyObject *self, void *closure) +{ + PyObject *result; /* Instance Python à retourner */ + GArchProcessor *proc; /* Architecture visée */ + size_t count; /* Nombre d'éléments à traiter */ + size_t i; /* Boucle de parcours */ +#ifndef NDEBUG + bool status; /* Bilan d'un appel */ +#endif + ArchProcessingError type; /* Type d'erreur détectée */ + vmpa2t addr; /* Position d'une erreur */ + char *desc; /* Description d'une erreur */ + PyObject *error; /* Nouvelle erreur à rajouter */ + + proc = G_ARCH_PROCESSOR(pygobject_get(self)); + + g_arch_processor_lock_errors(proc); + + count = g_arch_processor_count_errors(proc); + + result = PyTuple_New(count); + + for (i = 0; i < count; i++) + { +#ifndef NDEBUG + status = g_arch_processor_get_error(proc, i, &type, &addr, &desc); + assert(status); +#else + g_arch_processor_get_error(proc, i, &type, &addr, &desc); +#endif + + error = Py_BuildValue("IO&s", type, build_from_internal_vmpa, &addr, desc); + + PyTuple_SetItem(result, i, error); + + } + + g_arch_processor_unlock_errors(proc); + + return result; + +} + + + +/* ---------------------------------------------------------------------------------- */ +/* MANIPULATIONS DES INSTRUCTIONS DESASSEMBLEES */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Fournit les instructions désassemblées pour une architecture.* +* * +* Retour : Liste des instructions désassemblées ou None si aucune. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_arch_processor_get_instrs(PyObject *self, void *closure) +{ + PyObject *result; /* Instance Python à retourner */ + PyTypeObject *iterator_type; /* Type Python de l'itérateur */ + PyObject *args; /* Liste des arguments d'appel */ + + iterator_type = get_python_instr_iterator_type(); + + args = Py_BuildValue("On", self, 0); + + result = PyObject_CallObject((PyObject *)iterator_type, args); + + Py_DECREF(args); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* value = valeur fournie à intégrer ou prendre en compte. * +* closure = non utilisé ici. * +* * +* Description : Note les instructions désassemblées avec une architecture. * +* * +* Retour : Bilan de l'opération pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int py_arch_processor_set_instrs(PyObject *self, PyObject *value, void *closure) +{ + size_t count; /* Nombre d'instructions */ + GArchInstruction **list; /* Liste d'instructions */ + size_t i; /* Boucle de parcours */ + PyObject *instr; /* Instruction en Python */ + GArchProcessor *proc; /* Architecture visée */ + + if (!PyTuple_Check(value)) + { + PyErr_SetString(PyExc_TypeError, _("The attribute value must be a tuple of instructions.")); + return -1; + } + + count = PyTuple_Size(value); + + list = (GArchInstruction **)calloc(count, sizeof(GArchInstruction *)); + + for (i = 0; i < count; i++) + { + instr = PyTuple_GetItem(value, i); + + if (!PyObject_TypeCheck(value, get_python_arch_instruction_type())) + { + PyErr_SetString(PyExc_TypeError, _("The attribute value must be a tuple of instructions.")); + count = i; + goto papsi_error; + } + + list[i] = G_ARCH_INSTRUCTION(pygobject_get(instr)); + g_object_ref(G_OBJECT(list[i])); + + } + + proc = G_ARCH_PROCESSOR(pygobject_get(self)); + + g_arch_processor_set_instructions(proc, list, count); + + return 0; + + papsi_error: + + for (i = 0; i < count; i++) + g_object_unref(G_OBJECT(list[i])); + + free(list); + + return -1; + +} + + +/****************************************************************************** +* * +* Paramètres : self = processeur d'architecture à manipuler. * +* args = instruction représentant le point de départ. * +* * +* Description : Recherche une instruction d'après son adresse. * +* * +* Retour : Instruction trouvée à l'adresse donnée, None si aucune. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_arch_processor_find_instr_by_addr(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + PyObject *addr_obj; /* Objet pour une localisation */ + int ret; /* Bilan de lecture des args. */ + GArchProcessor *proc; /* Processeur manipulé */ + vmpa2t *addr; /* Localisation à retrouver */ + GArchInstruction *found; /* Instruction liée trouvée */ + + ret = PyArg_ParseTuple(args, "O", &addr_obj); + if (!ret) return NULL; + + ret = PyObject_IsInstance(addr_obj, (PyObject *)get_python_vmpa_type()); + if (!ret) return NULL; + + proc = G_ARCH_PROCESSOR(pygobject_get(self)); + addr = get_internal_vmpa(addr_obj); + + found = g_arch_processor_find_instr_by_address(proc, addr); + + if (found != NULL) + { + result = pygobject_new(G_OBJECT(found)); + g_object_unref(G_OBJECT(found)); + } + + else + { + result = Py_None; + Py_INCREF(result); + } + + return result; + +} + + + + + + +/****************************************************************************** +* * +* Paramètres : obj_type = type dont le dictionnaire est à compléter. * +* * +* Description : Définit les constantes pour les types d'erreurs. * +* * +* Retour : true en cas de succès de l'opération, false sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool define_python_arch_processor_constants(PyTypeObject *obj_type) +{ + bool result; /* Bilan à retourner */ + + result = true; + + result &= PyDict_AddIntMacro(obj_type, APE_DISASSEMBLY); + result &= PyDict_AddIntMacro(obj_type, APE_LABEL); + + 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_arch_processor_type(void) +{ + static PyMethodDef py_arch_processor_methods[] = { + { + "add_error", py_arch_processor_add_error, + METH_VARARGS, + "add_error($self, type, addr, desc, /)\n--\n\nExtend the list of detected disassembling errors." + }, + { + "find_instr_by_addr", py_arch_processor_find_instr_by_addr, + METH_VARARGS, + "find_instr_by_addr($self, addr, /)\n--\n\nLook for an instruction located at a given address." + }, + { NULL } + }; + + static PyGetSetDef py_arch_processor_getseters[] = { + { + "errors", py_arch_processor_get_errors, NULL, + "List of all detected errors which occurred during the disassembling process.", NULL + }, + { + "instrs", py_arch_processor_get_instrs, py_arch_processor_set_instrs, + "Give access to the disassembled instructions run by the current processor.", NULL + }, + { NULL } + }; + + static PyTypeObject py_arch_processor_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.arch.ArchProcessor", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_BASETYPE, + + .tp_doc = "PyChrysalide processor for a given architecture.", + + .tp_methods = py_arch_processor_methods, + .tp_getset = py_arch_processor_getseters, + + }; + + return &py_arch_processor_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.arch.ArchProcessor'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_arch_processor(PyObject *module) +{ + PyTypeObject *py_arch_processor_type; /* Type Python 'BinContent' */ + PyObject *dict; /* Dictionnaire du module */ + + py_arch_processor_type = get_python_arch_processor_type(); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_ARCH_PROCESSOR, py_arch_processor_type, &PyGObject_Type)) + return false; + + if (!define_python_arch_processor_constants(py_arch_processor_type)) + return false; + + return true; + +} diff --git a/plugins/pychrysalide/arch/processor.h b/plugins/pychrysalide/arch/processor.h new file mode 100644 index 0000000..ff6ccb3 --- /dev/null +++ b/plugins/pychrysalide/arch/processor.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * processor.h - prototypes pour l'équivalent Python du fichier "arch/processor.h" + * + * Copyright (C) 2012-2017 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_ARCH_PROCESSOR_H +#define _PLUGINS_PYCHRYSALIDE_ARCH_PROCESSOR_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_arch_processor_type(void); + +/* Prend en charge l'objet 'pychrysalide.arch.ArchProcessor'. */ +bool register_python_arch_processor(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_ARCH_PROCESSOR_H */ diff --git a/plugins/pychrysalide/arch/raw.c b/plugins/pychrysalide/arch/raw.c new file mode 100644 index 0000000..39b5fe7 --- /dev/null +++ b/plugins/pychrysalide/arch/raw.c @@ -0,0 +1,263 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * raw.c - équivalent Python du fichier "arch/raw.h" + * + * Copyright (C) 2017 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 "raw.h" + + +#include + + +#include + + +#include "instruction.h" +#include "../helpers.h" + + + +/* Indique si le contenu de l'instruction est du bourrage. */ +static PyObject *py_arch_instruction_is_padding(PyObject *, void *); + +/* Marque l'instruction comme ne contenant que du bourrage. */ +static int py_arch_instruction_mark_as_padding(PyObject *, PyObject *, void *); + +/* Indique si le contenu de l'instruction est un texte. */ +static PyObject *py_arch_instruction_is_string(PyObject *, void *); + +/* Marque l'instruction comme contenant une chaîne de texte. */ +static int py_arch_instruction_mark_as_string(PyObject *, PyObject *, void *); + + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant une instruction. * +* closure = adresse non utilisée ici. * +* * +* Description : Indique si le contenu de l'instruction est du bourrage. * +* * +* Retour : Valeur associée à la propriété consultée. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_arch_instruction_is_padding(PyObject *self, void *closure) +{ + PyObject *result; /* Conversion à retourner */ + GRawInstruction *instr; /* Version native */ + bool state; /* Etat courant à consulter */ + + instr = G_RAW_INSTRUCTION(pygobject_get(self)); + + state = g_raw_instruction_is_padding(instr); + + result = state ? Py_True : Py_False; + Py_INCREF(result); + + + return result; + +} + + +/****************************************************************************** +* * +* 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 : Marque l'instruction comme ne contenant que du bourrage. * +* * +* Retour : Bilan de l'opération pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int py_arch_instruction_mark_as_padding(PyObject *self, PyObject *value, void *closure) +{ + bool state; /* Nouvel état à définir */ + GRawInstruction *instr; /* Version native */ + + if (value != Py_True && value != Py_False) + return -1; + + state = (value == Py_True); + + instr = G_RAW_INSTRUCTION(pygobject_get(self)); + + g_raw_instruction_mark_as_padding(instr, state); + + return 0; + +} + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant une instruction. * +* closure = adresse non utilisée ici. * +* * +* Description : Indique si le contenu de l'instruction est un texte. * +* * +* Retour : Valeur associée à la propriété consultée. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_arch_instruction_is_string(PyObject *self, void *closure) +{ + PyObject *result; /* Conversion à retourner */ + GRawInstruction *instr; /* Version native */ + bool state; /* Etat courant à consulter */ + + instr = G_RAW_INSTRUCTION(pygobject_get(self)); + + state = g_raw_instruction_is_string(instr); + + result = state ? Py_True : Py_False; + Py_INCREF(result); + + + return result; + +} + + +/****************************************************************************** +* * +* 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 : Marque l'instruction comme contenant une chaîne de texte. * +* * +* Retour : Bilan de l'opération pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int py_arch_instruction_mark_as_string(PyObject *self, PyObject *value, void *closure) +{ + bool state; /* Nouvel état à définir */ + GRawInstruction *instr; /* Version native */ + + if (value != Py_True && value != Py_False) + return -1; + + state = (value == Py_True); + + instr = G_RAW_INSTRUCTION(pygobject_get(self)); + + g_raw_instruction_mark_as_string(instr, state); + + return 0; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *get_python_raw_instruction_type(void) +{ + static PyMethodDef py_raw_instruction_methods[] = { + { NULL } + }; + + static PyGetSetDef py_raw_instruction_getseters[] = { + { + "is_padding", py_arch_instruction_is_padding, py_arch_instruction_mark_as_padding, + "Report if the instruction is seen as padding.", NULL + }, + { + "is_string", py_arch_instruction_is_string, py_arch_instruction_mark_as_string, + "Report if the instruction is seen as a string.", NULL + }, + { NULL } + }; + + static PyTypeObject py_raw_instruction_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.arch.RawInstruction", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT, + + .tp_doc = "PyChrysalide raw instruction for a all architectures.", + + .tp_methods = py_raw_instruction_methods, + .tp_getset = py_raw_instruction_getseters, + + }; + + return &py_raw_instruction_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.arch.ArchInstruction'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_raw_instruction(PyObject *module) +{ + PyTypeObject *py_raw_instruction_type; /* Type Python 'RawInstruction'*/ + PyObject *dict; /* Dictionnaire du module */ + PyTypeObject *base; /* Base parente pour héritage */ + + py_raw_instruction_type = get_python_raw_instruction_type(); + + dict = PyModule_GetDict(module); + + base = get_python_arch_instruction_type(); + + if (!register_class_for_pygobject(dict, G_TYPE_RAW_INSTRUCTION, py_raw_instruction_type, base)) + return false; + + return true; + +} diff --git a/plugins/pychrysalide/arch/raw.h b/plugins/pychrysalide/arch/raw.h new file mode 100644 index 0000000..32c4e2d --- /dev/null +++ b/plugins/pychrysalide/arch/raw.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * raw.h - prototypes pour l'équivalent Python du fichier "arch/raw.h" + * + * Copyright (C) 2017 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_ARCH_RAW_H +#define _PLUGINS_PYCHRYSALIDE_ARCH_RAW_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_raw_instruction_type(void); + +/* Prend en charge l'objet 'pychrysalide.arch.RawInstruction'. */ +bool register_python_raw_instruction(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_ARCH_RAW_H */ diff --git a/plugins/pychrysalide/arch/vmpa.c b/plugins/pychrysalide/arch/vmpa.c new file mode 100644 index 0000000..413d67b --- /dev/null +++ b/plugins/pychrysalide/arch/vmpa.c @@ -0,0 +1,1303 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * vmpa.c - équivalent Python du fichier "arch/vmpa.c" + * + * Copyright (C) 2014-2017 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 "vmpa.h" + + +#include +#include + + +#include + + +#include "../helpers.h" + + + + + +#include /* TODO : à bouger vers base ? */ + + + + +/* ---------------------- DEFINITION D'UNE POSITION EN MEMOIRE ---------------------- */ + + + +typedef struct _py_vmpa_t +{ + PyObject_HEAD + + vmpa2t addr; + +} py_vmpa_t; + + + + +/* Fournit une représentation d'une variable 'vmpa_t'. */ +static PyObject *py_vmpa_to_str(PyObject *); + +/* Effectue une comparaison avec un objet Python 'vmpa_t'. */ +static PyObject *py_vmpa_richcompare(PyObject *, PyObject *, int); + +/* Fournit une partie du contenu de la position représentée. */ +static PyObject *py_vmpa_get_value(PyObject *, void *); + +/* Définit une partie du contenu de la position représentée. */ +static int py_vmpa_set_value(PyObject *, PyObject *, void *); + +/* Crée un nouvel objet Python de type 'vmpa2t'. */ +static PyObject *py_vmpa_new(PyTypeObject *, PyObject *, PyObject *); + +/* Effectue une conversion d'un objet Python en type 'vmpa_t'. */ +static bool convert_pyobj_to_vmpa(PyObject *, vmpa2t *); + +/* Effectue une opération de type 'add' avec le type 'vmpa'. */ +static PyObject *py_vmpa_nb_add(PyObject *, PyObject *); + +/* Définit les constantes pour les localisations. */ +static bool py_vmpa_define_constants(PyTypeObject *); + + + +/* ------------------------ DEFINITION D'UNE ZONE EN MEMOIRE ------------------------ */ + + +/* Couverture mémoire */ +typedef struct _py_mrange_t +{ + PyObject_HEAD /* Préambule Python */ + + mrange_t range; /* Informations internes */ + +} py_mrange_t; + + +/* Fournit une représentation d'une variable 'mrange_t'. */ +static PyObject *py_mrange_to_str(PyObject *); + + + +/* Effectue une comparaison avec un objet Python 'mrange_t'. */ +static PyObject *py_mrange_richcompare(PyObject *, PyObject *, int); + + + +/* Indique si une zone en contient une autre ou non. */ +static PyObject *py_mrange_contains(PyObject *, PyObject *); + + + + +/* Fournit la position de départ de la zone mémoire représentée. */ +static PyObject *py_mrange_get_addr(PyObject *, void *); + +/* Définit la position de départ de la zone mémoire représentée. */ +static int py_mrange_set_addr(PyObject *, PyObject *, void *); + +/* Fournit la taille de la zone mémoire représentée. */ +static PyObject *py_mrange_get_length(PyObject *, void *); + +/* Définit la taille de la zone mémoire représentée. */ +static int py_mrange_set_length(PyObject *, PyObject *, void *); + +/* Calcule la position extérieure finale d'une couverture. */ +static PyObject *py_mrange_get_end_addr(PyObject *, void *); + + + + +/* Crée un nouvel objet Python de type 'mrange'. */ +static PyObject *py_mrange_new(PyTypeObject *, PyObject *, PyObject *); + + + + + + + +/* ---------------------------------------------------------------------------------- */ +/* DEFINITION D'UNE POSITION EN MEMOIRE */ +/* ---------------------------------------------------------------------------------- */ + + + + +/****************************************************************************** +* * +* Paramètres : obj = objet Python à traiter. * +* * +* Description : Fournit une représentation d'une variable 'vmpa_t'. * +* * +* Retour : Chaîne de caractère pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_vmpa_to_str(PyObject *obj) +{ + PyObject *result; /* Chaîne à retourner */ + vmpa2t *addr; /* Véritable adresse manipulée */ + 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(""); + + else if (physical != VMPA_NO_PHYSICAL && virtual == VMPA_NO_VIRTUAL) + result = PyUnicode_FromFormat("", phys_str); + + else if (physical == VMPA_NO_PHYSICAL && virtual != VMPA_NO_VIRTUAL) + result = PyUnicode_FromFormat("", virt_str); + + else + result = PyUnicode_FromFormat("", phys_str, virt_str); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : a = premier object Python à consulter. * +* b = second object Python à consulter. * +* op = type de comparaison menée. * +* * +* Description : Effectue une comparaison avec un objet Python 'vmpa_t'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_vmpa_richcompare(PyObject *a, PyObject *b, int op) +{ + PyObject *result; /* Bilan à retourner */ + vmpa2t *addr_a; /* Première adresse à traiter */ + vmpa2t addr_b; /* Seconde adresse à traiter */ + int comp; /* Résultat d'une comparaison */ + + addr_a = &((py_vmpa_t *)a)->addr; + + if (!convert_pyobj_to_vmpa(b, &addr_b)) + return NULL; + + comp = cmp_vmpa(addr_a, &addr_b); + + switch (op) + { + case Py_LT: + result = comp < 0 ? Py_True : Py_False; + break; + + case Py_LE: + result = comp <= 0 ? Py_True : Py_False; + break; + + case Py_EQ: + result = comp == 0 ? Py_True : Py_False; + break; + + case Py_NE: + result = comp != 0 ? Py_True : Py_False; + break; + + case Py_GT: + result = comp > 0 ? Py_True : Py_False; + break; + + case Py_GE: + result = comp >= 0 ? Py_True : Py_False; + break; + + default: + assert(false); + result = Py_NotImplemented; + break; + + } + + Py_INCREF(result); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = définition d'adresse visée par la procédure. * +* closure = sélection de la valeur à traiter. * +* * +* Description : Fournit une partie du contenu de la position représentée. * +* * +* Retour : Nombre positif ou nul ou None. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_vmpa_get_value(PyObject *self, void *closure) +{ + PyObject *result; /* Valeur à retourner */ + py_vmpa_t *vmpa; /* Véritable objet Python */ + char *key; /* Contenu à cibler précisément*/ + + vmpa = (py_vmpa_t *)self; + + key = (char *)closure; + + if (strcmp(key, "phys") == 0) + { + if (get_phy_addr(&vmpa->addr) == VMPA_NO_PHYSICAL) + { + result = Py_None; + Py_INCREF(result); + } + else result = Py_BuildValue("K", get_phy_addr(&vmpa->addr)); + } + else + { + if (get_virt_addr(&vmpa->addr) == VMPA_NO_VIRTUAL) + { + result = Py_None; + Py_INCREF(result); + } + else result = Py_BuildValue("K", get_virt_addr(&vmpa->addr)); + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = définition d'adresse visée par la procédure. * +* value = valeur fournie à intégrer ou prendre en compte. * +* closure = sélection de la valeur à traiter. * +* * +* Description : Définit une partie du contenu de la position représentée. * +* * +* Retour : Bilan de l'opération pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int py_vmpa_set_value(PyObject *self, PyObject *value, void *closure) +{ + int result; /* Bilan à faire remonter */ + py_vmpa_t *vmpa; /* Véritable objet Python */ + char *key; /* Contenu à cibler précisément*/ + PY_LONG_LONG val; /* Valeur traduite génériquemt */ + int overflow; /* Détection d'une grosse val. */ + + result = 0; + + vmpa = (py_vmpa_t *)self; + + key = (char *)closure; + + if (strcmp(key, "phys") == 0) + { + if (value == Py_None) + init_vmpa(&vmpa->addr, VMPA_NO_PHYSICAL, get_virt_addr(&vmpa->addr)); + + else + { + val = PyLong_AsLongLongAndOverflow(value, &overflow); + + if (val == -1 && (overflow == 1 || PyErr_Occurred())) + { + result = -1; + PyErr_Clear(); + } + else init_vmpa(&vmpa->addr, val, get_virt_addr(&vmpa->addr)); + + } + + } + else + { + if (value == Py_None) + init_vmpa(&vmpa->addr, get_phy_addr(&vmpa->addr), VMPA_NO_VIRTUAL); + + else + { + val = PyLong_AsLongLongAndOverflow(value, &overflow); + + if (val == -1 && (overflow == 1 || PyErr_Occurred())) + { + result = -1; + PyErr_Clear(); + } + else init_vmpa(&vmpa->addr, get_phy_addr(&vmpa->addr), val); + + } + + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : type = type de l'objet à instancier. * +* args = arguments fournis à l'appel. * +* kwds = arguments de type key=val fournis. * +* * +* Description : Crée un nouvel objet Python de type 'vmpa2t'. * +* * +* Retour : Instance Python mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_vmpa_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + py_vmpa_t *result; /* Instance à retourner */ + unsigned long long phy; /* Position physique */ + unsigned long long virt; /* Adresse en mémoire virtuelle*/ + int ret; /* Bilan de lecture des args. */ + + phy = VMPA_NO_PHYSICAL; + virt = VMPA_NO_VIRTUAL; + + ret = PyArg_ParseTuple(args, "|KK", &phy, &virt); + if (!ret) Py_RETURN_NONE; + + result = (py_vmpa_t *)type->tp_alloc(type, 0); + + init_vmpa(&result->addr, phy, virt); + + return (PyObject *)result; + +} + + + + + + +/****************************************************************************** +* * +* Paramètres : obj = objet Python à tenter de convertir. * +* addr = structure équivalente pour Chrysalide. * +* * +* Description : Effectue une conversion d'un objet Python en type 'vmpa_t'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool convert_pyobj_to_vmpa(PyObject *obj, vmpa2t *addr) +{ + bool result; /* Résulats à retourner */ + PyTypeObject *py_vmpa_type; /* Type Python pour 'vmpa' */ + int ret; /* Bilan d'un appel */ + PY_LONG_LONG value; /* Valeur de type générique */ + int overflow; /* Détection d'une grosse val. */ + + result = false; + + py_vmpa_type = get_python_vmpa_type(); + + ret = PyObject_IsInstance(obj, (PyObject *)py_vmpa_type); + + /* S'il n'y a rien à faire... */ + if (ret == 1) + { + *addr = ((py_vmpa_t *)obj)->addr; + result = true; + } + + /* Sinon on demande à Python... */ + else + { + value = PyLong_AsLongLongAndOverflow(obj, &overflow); + + if (value == -1 && (overflow == 1 || PyErr_Occurred())) + { + PyErr_Clear(); + PyErr_SetString(PyExc_TypeError, _("Unable to cast object as VMPA.")); + } + + else + { + init_vmpa(addr, value, value); + result = true; + } + + } + + return result; + +} + + + + +/****************************************************************************** +* * +* Paramètres : o1 = premier élément concerné par l'opération. * +* o2 = second élément concerné par l'opération. * +* * +* Description : Effectue une opération de type 'add' avec le type 'vmpa'. * +* * +* Retour : Résultat de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_vmpa_nb_add(PyObject *o1, PyObject *o2) +{ + PyObject *result; /* Résultat à retourner */ + vmpa2t addr1; /* Première adresse à traiter */ + vmpa2t addr2; /* Seconde adresse à traiter */ + PyTypeObject *py_vmpa_type; /* Type Python pour 'vmpa' */ + + if (!convert_pyobj_to_vmpa(o1, &addr1)) + return NULL; + + if (!convert_pyobj_to_vmpa(o2, &addr2)) + return NULL; + + py_vmpa_type = get_python_vmpa_type(); + + result = PyObject_CallObject((PyObject *)py_vmpa_type, NULL); + + init_vmpa(&((py_vmpa_t *)result)->addr, + addr1.physical + addr2.physical, + addr1.virtual + addr2.virtual); + + return result; + +} + + + + + +void change_editor_items_current_view_content(void/*GtkDisplayPanel*/ *view) +{ + /* FIXME */ + +} + + + + +/****************************************************************************** +* * +* Paramètres : obj_type = type dont le dictionnaire est à compléter. * +* * +* Description : Définit les constantes pour les localisations. * +* * +* Retour : true en cas de succès de l'opération, false sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool py_vmpa_define_constants(PyTypeObject *obj_type) +{ + bool result; /* Bilan à retourner */ + + result = true; + + result &= PyDict_AddIntMacro(obj_type, VMPA_NO_PHYSICAL); + result &= PyDict_AddIntMacro(obj_type, VMPA_NO_VIRTUAL); + + /* TODO : à bouger vers base ? */ + result &= PyDict_AddIntMacro(obj_type, SRE_LITTLE); + result &= PyDict_AddIntMacro(obj_type, SRE_MIDDLE); + result &= PyDict_AddIntMacro(obj_type, SRE_BIG); + + 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_vmpa_type(void) +{ + static PyNumberMethods py_vmpa_nb_proto = { + + .nb_add = py_vmpa_nb_add, + + /* + binaryfunc nb_add; + binaryfunc nb_subtract; + binaryfunc nb_multiply; + binaryfunc nb_remainder; + binaryfunc nb_divmod; + ternaryfunc nb_power; + unaryfunc nb_negative; + unaryfunc nb_positive; + unaryfunc nb_absolute; + inquiry nb_bool; + unaryfunc nb_invert; + binaryfunc nb_lshift; + binaryfunc nb_rshift; + binaryfunc nb_and; + binaryfunc nb_xor; + binaryfunc nb_or; + unaryfunc nb_int; + void *nb_reserved; + unaryfunc nb_float; + + binaryfunc nb_inplace_add; + binaryfunc nb_inplace_subtract; + binaryfunc nb_inplace_multiply; + binaryfunc nb_inplace_remainder; + ternaryfunc nb_inplace_power; + binaryfunc nb_inplace_lshift; + binaryfunc nb_inplace_rshift; + binaryfunc nb_inplace_and; + binaryfunc nb_inplace_xor; + binaryfunc nb_inplace_or; + + binaryfunc nb_floor_divide; + binaryfunc nb_true_divide; + binaryfunc nb_inplace_floor_divide; + binaryfunc nb_inplace_true_divide; + + unaryfunc nb_index; + + */ + + }; + + static PyGetSetDef py_vmpa_getseters[] = { + + { + "phys", py_vmpa_get_value, py_vmpa_set_value, + "Give access to the physical offset of the location.", "phys" + }, + + { + "virt", py_vmpa_get_value, py_vmpa_set_value, + "Give access to the virtual address of the location.", "virt" + }, + { NULL } + + }; + + static PyTypeObject py_vmpa_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.arch.vmpa", + .tp_basicsize = sizeof(py_vmpa_t), + + .tp_as_number = &py_vmpa_nb_proto, + + .tp_str = py_vmpa_to_str, + + .tp_flags = Py_TPFLAGS_DEFAULT, + + .tp_doc = "Python object for vmpa_t.", + + .tp_richcompare = py_vmpa_richcompare, + + .tp_getset = py_vmpa_getseters, + .tp_new = (newfunc)py_vmpa_new + + }; + + return &py_vmpa_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.arch.vmpa'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_vmpa(PyObject *module) +{ + PyTypeObject *py_vmpa_type; /* Type Python pour 'vmpa' */ + int ret; /* Bilan d'un appel */ + + py_vmpa_type = get_python_vmpa_type(); + + if (PyType_Ready(py_vmpa_type) != 0) + return false; + + if (!py_vmpa_define_constants(py_vmpa_type)) + return false; + + Py_INCREF(py_vmpa_type); + ret = PyModule_AddObject(module, "vmpa", (PyObject *)py_vmpa_type); + + return (ret == 0); + +} + + +/****************************************************************************** +* * +* Paramètres : obj = objet Python à traiter. * +* * +* Description : Donne accès au coeur d'un objet 'pychrysalide.arch.vmpa'. * +* * +* Retour : Localistion réelle ou NULL en cas de mauvaise conversion. * +* * +* Remarques : - * +* * +******************************************************************************/ + +vmpa2t *get_internal_vmpa(PyObject *obj) +{ + int ret; /* Bilan d'analyse */ + + ret = PyObject_IsInstance(obj, (PyObject *)get_python_vmpa_type()); + if (!ret) return NULL; + + return &((py_vmpa_t *)obj)->addr; + +} + + +/****************************************************************************** +* * +* Paramètres : addr = structure interne à copier en objet Python. * +* * +* Description : Convertit une structure de type 'vmpa2t' en objet Python. * +* * +* Retour : Object Python résultant de la conversion opérée. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyObject *build_from_internal_vmpa(const vmpa2t *addr) +{ + py_vmpa_t *result; /* Instance à retourner */ + PyTypeObject *type; /* Type à instancier */ + + type = get_python_vmpa_type(); + + result = (py_vmpa_t *)type->tp_alloc(type, 0); + + copy_vmpa(&result->addr, addr); + + return (PyObject *)result; + +} + + +/****************************************************************************** +* * +* Paramètres : arg = argument quelconque à tenter de convertir. * +* dst = destination des valeurs récupérées en cas de succès. * +* * +* Description : Tente de convertir en adresse n'importe quoi. * +* * +* Retour : Bilan de l'opération, voire indications supplémentaires. * +* * +* Remarques : - * +* * +******************************************************************************/ + +int convert_any_to_vmpa(PyObject *arg, void *dst) +{ + int result; /* Bilan à retourner */ + int ret; /* Test intermédiaire */ + vmpa2t *src; /* Modèle de données à copier */ + PY_LONG_LONG value; /* Valeur de type générique */ + int overflow; /* Détection d'une grosse val. */ + + result = 0; + + /* Si l'objet est au bon format, rien à faire ! */ + + ret = PyObject_IsInstance(arg, (PyObject *)get_python_vmpa_type()); + + if (ret == 1) + { + src = get_internal_vmpa(arg); + copy_vmpa((vmpa2t *)dst, src); + + result = 1; + goto catv_done; + + } + + /* Sinon on demande à Python... */ + + value = PyLong_AsLongLongAndOverflow(arg, &overflow); + + if (value == -1 && (overflow == 1 || PyErr_Occurred())) + PyErr_Clear(); + + else + { + init_vmpa((vmpa2t *)dst, VMPA_NO_PHYSICAL, value); + + result = 1; + goto catv_done; + + } + + PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to vmpa"); + + catv_done: + + return result; + +} + + + +/* ---------------------------------------------------------------------------------- */ +/* DEFINITION D'UNE ZONE EN MEMOIRE */ +/* ---------------------------------------------------------------------------------- */ + + + + + + + +/****************************************************************************** +* * +* Paramètres : obj = objet Python à traiter. * +* * +* Description : Fournit une représentation d'une variable 'mrange_t'. * +* * +* Retour : Chaîne de caractère pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_mrange_to_str(PyObject *obj) +{ + PyObject *result; /* Chaîne à retourner */ + + result = PyUnicode_FromFormat(""); + + return result; + +} + + + + +/****************************************************************************** +* * +* Paramètres : a = premier object Python à consulter. * +* b = second object Python à consulter. * +* op = type de comparaison menée. * +* * +* Description : Effectue une comparaison avec un objet Python 'mrange_t'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_mrange_richcompare(PyObject *a, PyObject *b, int op) +{ + PyObject *result; /* Bilan à retourner */ + mrange_t *range_a; /* Premier espace à traiter */ + mrange_t *range_b; /* Second espace à traiter */ + int status; /* Résultat d'une comparaison */ + + range_a = get_internal_mrange(a); + + range_b = get_internal_mrange(b); + if (range_b == NULL) return NULL; + + status = cmp_mrange(range_a, range_b); + + result = status_to_rich_cmp_state(status, op); + + Py_INCREF(result); + + return result; + +} + + + + + + + + + +/****************************************************************************** +* * +* Paramètres : self = contenu binaire à manipuler. * +* args = non utilisé ici. * +* * +* Description : Indique si une zone en contient une autre ou non. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_mrange_contains(PyObject *self, PyObject *args) +{ + PyObject *result; /* Bilan à faire remonter */ + int ret; /* Bilan de lecture des args. */ + PyObject *range_obj; /* Objet pour un intervale */ + mrange_t *range; /* Région mémoire de contenance*/ + mrange_t *sub; /* Région mémoire contenue ? */ + + ret = PyArg_ParseTuple(args, "O", &range_obj); + if (!ret) return NULL; + + ret = PyObject_IsInstance(range_obj, (PyObject *)get_python_mrange_type()); + if (!ret) return NULL; + + range = get_internal_mrange(self); + sub = get_internal_mrange(range_obj); + + result = (mrange_contains_mrange(range, sub) ? Py_True : Py_False); + + Py_INCREF(result); + + return result; + +} + + + + + +/****************************************************************************** +* * +* Paramètres : self = définition de l'espace visé par la procédure. * +* closure = élément non utilisé ici. * +* * +* Description : Fournit la position de départ de la zone mémoire représentée.* +* * +* Retour : Nouvelle objet mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_mrange_get_addr(PyObject *self, void *closure) +{ + PyObject *result; /* Valeur à retourner */ + mrange_t *range; /* Espace mémoire à manipuler */ + + range = get_internal_mrange(self); + + result = build_from_internal_vmpa(get_mrange_addr(range)); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = définition de l'espace visé par la procédure. * +* value = valeur fournie à intégrer ou prendre en compte. * +* closure = élément non utilisé ici. * +* * +* Description : Définit la position de départ de la zone mémoire représentée.* +* * +* Retour : Bilan de l'opération pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int py_mrange_set_addr(PyObject *self, PyObject *value, void *closure) +{ + int result; /* Bilan à faire remonter */ + vmpa2t *addr; /* Localisation version C */ + mrange_t *range; /* Espace mémoire à manipuler */ + + result = 0; + + addr = get_internal_vmpa(value); + if (addr == NULL) return -1; + + range = get_internal_mrange(self); + + init_mrange(range, addr, get_mrange_length(range)); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = définition de l'espace visé par la procédure. * +* closure = élément non utilisé ici. * +* * +* Description : Fournit la taille de la zone mémoire représentée. * +* * +* Retour : Nouvelle objet mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_mrange_get_length(PyObject *self, void *closure) +{ + PyObject *result; /* Valeur à retourner */ + mrange_t *range; /* Espace mémoire à manipuler */ + + range = get_internal_mrange(self); + + result = Py_BuildValue("K", get_mrange_length(range)); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = définition de l'espace visé par la procédure. * +* value = valeur fournie à intégrer ou prendre en compte. * +* closure = élément non utilisé ici. * +* * +* Description : Définit la taille de la zone mémoire représentée. * +* * +* Retour : Bilan de l'opération pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int py_mrange_set_length(PyObject *self, PyObject *value, void *closure) +{ + int result; /* Bilan à faire remonter */ + mrange_t *range; /* Espace mémoire à manipuler */ + PY_LONG_LONG val; /* Valeur traduite génériquemt */ + int overflow; /* Détection d'une grosse val. */ + vmpa2t tmp; /* Copie pour recopie */ + + result = 0; + + range = get_internal_mrange(self); + + val = PyLong_AsLongLongAndOverflow(value, &overflow); + + if (val == -1 && (overflow == 1 || PyErr_Occurred())) + { + result = -1; + PyErr_Clear(); + } + else + { + copy_vmpa(&tmp, get_mrange_addr(range)); + init_mrange(range, &tmp, val); + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = définition de l'espace visé par la procédure. * +* closure = élément non utilisé ici. * +* * +* Description : Calcule la position extérieure finale d'une couverture. * +* * +* Retour : Nouvelle objet mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_mrange_get_end_addr(PyObject *self, void *closure) +{ + PyObject *result; /* Valeur à retourner */ + mrange_t *range; /* Espace mémoire à manipuler */ + vmpa2t end; /* Adresse à reproduire */ + + range = get_internal_mrange(self); + compute_mrange_end_addr(range, &end); + + result = build_from_internal_vmpa(&end); + + return result; + +} + + + + + + + + + +/****************************************************************************** +* * +* Paramètres : type = type de l'objet à instancier. * +* args = arguments fournis à l'appel. * +* kwds = arguments de type key=val fournis. * +* * +* Description : Crée un nouvel objet Python de type 'mrange'. * +* * +* Retour : Instance Python mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_mrange_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + py_mrange_t *result; /* Instance à retourner */ + PyObject *py_vmpa; /* Localisation version Python */ + unsigned long long length; /* Taille physique */ + int ret; /* Bilan de lecture des args. */ + vmpa2t *addr; /* Localisation version C */ + + ret = PyArg_ParseTuple(args, "OK", &py_vmpa, &length); + if (!ret) return NULL; + + ret = PyObject_IsInstance(py_vmpa, (PyObject *)get_python_vmpa_type()); + if (!ret) return NULL; + + addr = get_internal_vmpa(py_vmpa); + if (addr == NULL) return NULL; + + result = (py_mrange_t *)type->tp_alloc(type, 0); + + init_mrange(&result->range, addr, length); + + return (PyObject *)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_mrange_type(void) +{ + static PyMethodDef py_mrange_methods[] = { + { "contains", py_mrange_contains, + METH_VARARGS, + "contains($self, other, /)\n--\nTell if the current range contains another given range or address." + }, +#if 0 + { "read_u8", py_arch_instruction_read_u8, + METH_VARARGS, + "read_u8($self, addr, /)\n--\n\nRead an unsigned byte from a given position." + }, +#endif + { NULL } + }; + + static PyGetSetDef py_mrange_getseters[] = { + { + "addr", py_mrange_get_addr, py_mrange_set_addr, + "Give access to the start location of the memory range.", NULL + }, + { + "length", py_mrange_get_length, py_mrange_set_length, + "Give access to the length of the memory range.", NULL + }, + { + "end", py_mrange_get_end_addr, NULL, + "Provide the final external point of the memory range.", NULL + }, + { NULL } + }; + + static PyTypeObject py_mrange_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.arch.mrange", + .tp_basicsize = sizeof(py_mrange_t), + + .tp_str = py_mrange_to_str, + + .tp_flags = Py_TPFLAGS_DEFAULT, + + .tp_doc = "Python object for mrange_t.", + + .tp_richcompare = py_mrange_richcompare, + + .tp_methods = py_mrange_methods, + .tp_getset = py_mrange_getseters, + .tp_new = (newfunc)py_mrange_new + + }; + + return &py_mrange_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.arch.mrange'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_mrange(PyObject *module) +{ + PyTypeObject *py_mrange_type; /* Type Python pour 'mrange' */ + int ret; /* Bilan d'un appel */ + + py_mrange_type = get_python_mrange_type(); + + if (PyType_Ready(py_mrange_type) != 0) + return false; + + Py_INCREF(py_mrange_type); + ret = PyModule_AddObject(module, "mrange", (PyObject *)py_mrange_type); + + return (ret == 0); + +} + + +/****************************************************************************** +* * +* Paramètres : obj = objet Python à traiter. * +* * +* Description : Donne accès au coeur d'un objet 'pychrysalide.arch.mrange'. * +* * +* Retour : Localistion réelle ou NULL en cas de mauvaise conversion. * +* * +* Remarques : - * +* * +******************************************************************************/ + +mrange_t *get_internal_mrange(PyObject *obj) +{ + int ret; /* Bilan d'analyse */ + + ret = PyObject_IsInstance(obj, (PyObject *)get_python_mrange_type()); + if (!ret) return NULL; + + return &((py_mrange_t *)obj)->range; + +} + + +/****************************************************************************** +* * +* Paramètres : range = structure interne à copier en objet Python. * +* * +* Description : Convertit une structure de type 'mrange_t' en objet Python. * +* * +* Retour : Object Python résultant de la conversion opérée. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyObject *build_from_internal_mrange(const mrange_t *range) +{ + py_mrange_t *result; /* Instance à retourner */ + PyTypeObject *type; /* Type à instancier */ + + type = get_python_mrange_type(); + + result = (py_mrange_t *)type->tp_alloc(type, 0); + + copy_mrange(&result->range, range); + + return (PyObject *)result; + +} diff --git a/plugins/pychrysalide/arch/vmpa.h b/plugins/pychrysalide/arch/vmpa.h new file mode 100644 index 0000000..46828f5 --- /dev/null +++ b/plugins/pychrysalide/arch/vmpa.h @@ -0,0 +1,71 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * vmpa.h - prototypes pour l'équivalent Python du fichier "arch/vmpa.h" + * + * Copyright (C) 2014-2017 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_ARCH_VMPA_H +#define _PLUGINS_PYCHRYSALIDE_ARCH_VMPA_H + + +#include +#include + + +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_vmpa_type(void); + +/* Prend en charge l'objet 'pychrysalide.arch.vmpa'. */ +bool register_python_vmpa(PyObject *); + +/* Donne accès au coeur d'un objet 'pychrysalide.arch.vmpa'. */ +vmpa2t *get_internal_vmpa(PyObject *); + +/* Convertit une structure de type 'vmpa2t' en objet Python. */ +PyObject *build_from_internal_vmpa(const vmpa2t *); + +/* Tente de convertir en adresse n'importe quoi. */ +int convert_any_to_vmpa(PyObject *, void *); + + + +/* ------------------------ DEFINITION D'UNE ZONE EN MEMOIRE ------------------------ */ + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_mrange_type(void); + +/* Prend en charge l'objet 'pychrysalide.arch.mrange'. */ +bool register_python_mrange(PyObject *); + +/* Donne accès au coeur d'un objet 'pychrysalide.arch.mrange'. */ +mrange_t *get_internal_mrange(PyObject *); + +/* Convertit une structure de type 'mrange_t' en objet Python. */ +PyObject *build_from_internal_mrange(const mrange_t *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_ARCH_VMPA_H */ diff --git a/plugins/pychrysalide/common/Makefile.am b/plugins/pychrysalide/common/Makefile.am new file mode 100644 index 0000000..0637229 --- /dev/null +++ b/plugins/pychrysalide/common/Makefile.am @@ -0,0 +1,17 @@ + +noinst_LTLIBRARIES = libpychrysacommon.la + +libpychrysacommon_la_SOURCES = \ + bits.h bits.c \ + fnv1a.h fnv1a.c \ + module.h module.c \ + pathname.h pathname.c + + +libpychrysacommon_la_LDFLAGS = + + +AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ + -I../../../src + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) diff --git a/plugins/pychrysalide/common/bits.c b/plugins/pychrysalide/common/bits.c new file mode 100644 index 0000000..33f81c3 --- /dev/null +++ b/plugins/pychrysalide/common/bits.c @@ -0,0 +1,653 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * bits.c - équivalent Python du fichier "common/bits.c" + * + * Copyright (C) 2017 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 "bits.h" + + +#include "../helpers.h" + + + +/* Encapsulation d'un champ de bits */ +typedef struct _py_bitfield_t +{ + PyObject_HEAD /* A laisser en premier */ + + bitfield_t *native; /* Champ de bits représenté */ + +} py_bitfield_t; + + + +/* Crée un nouvel objet Python de type 'bitfield_t'. */ +static PyObject *py_bitfield_new(PyTypeObject *, PyObject *, PyObject *); + +/* Crée une copie d'un champ de bits classique. */ +static PyObject *py_bitfield_dup(PyObject *, PyObject *); + +/* Effectue une opération de type 'and' avec le type 'bitfield'. */ +static PyObject *py_bitfield_nb_and(PyObject *, PyObject *); + +/* Effectue une opération de type 'or' avec le type 'bitfield'. */ +static PyObject *py_bitfield_nb_or(PyObject *, PyObject *); + +/* Effectue une comparaison avec un objet Python 'bitfield'. */ +static PyObject *py_bitfield_richcompare(PyObject *, PyObject *, int); + +/* Bascule à 0 un champ de bits dans son intégralité. */ +static PyObject *py_bitfield_reset_all(PyObject *, PyObject *); + +/* Bascule à 1 un champ de bits dans son intégralité. */ +static PyObject *py_bitfield_set_all(PyObject *, PyObject *); + +/* Bascule à 0 une partie d'un champ de bits. */ +static PyObject *py_bitfield_reset(PyObject *, PyObject *); + +/* Bascule à 1 une partie d'un champ de bits. */ +static PyObject *py_bitfield_set(PyObject *, PyObject *); + +/* Détermine si un bit est à 1 dans un champ de bits. */ +static PyObject *py_bitfield_test(PyObject *, PyObject *); + +/* Détermine si un ensemble de bits est à 0 dans un champ. */ +static PyObject *py_bitfield_test_none(PyObject *, PyObject *); + +/* Détermine si un ensemble de bits est à 1 dans un champ. */ +static PyObject *py_bitfield_test_all(PyObject *, PyObject *); + + + +/****************************************************************************** +* * +* Paramètres : type = type de l'objet à instancier. * +* args = arguments fournis à l'appel. * +* kwds = arguments de type key=val fournis. * +* * +* Description : Crée un nouvel objet Python de type 'bitfield_t'. * +* * +* Retour : Instance Python mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_bitfield_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + py_bitfield_t *result; /* Instance à retourner */ + unsigned long length; /* Taille du champ à créer */ + int state; /* Initialisation par défaut */ + int ret; /* Bilan de lecture des args. */ + + ret = PyArg_ParseTuple(args, "kp", &length, &state); + if (!ret) return NULL; + + result = (py_bitfield_t *)type->tp_alloc(type, 0); + + result->native = create_bit_field(length, state); + + return (PyObject *)result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = champ de bits à dupliquer. * +* args = non utilisé ici. * +* * +* Description : Crée une copie d'un champ de bits classique. * +* * +* Retour : Champ de bits mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_bitfield_dup(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + py_bitfield_t *bf; /* Instance à manipuler */ + + bf = (py_bitfield_t *)self; + + result = build_from_internal_bitfield(bf->native);; + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : o1 = premier élément concerné par l'opération. * +* o2 = second élément concerné par l'opération. * +* * +* Description : Effectue une opération de type 'and' avec le type 'bitfield'.* +* * +* Retour : Résultat de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_bitfield_nb_and(PyObject *o1, PyObject *o2) +{ + PyObject *result; /* Résultat à retourner */ + int ret; /* Bilan de compatibilité */ + py_bitfield_t *bf_1; /* Instance à manipuler #1 */ + py_bitfield_t *bf_2; /* Instance à manipuler #2 */ + py_bitfield_t *new; /* Nouvelle version en place */ + + ret = PyObject_IsInstance(o2, (PyObject *)get_python_bitfield_type()); + if (!ret) + { + result = NULL; + goto pbna_done; + } + + bf_1 = (py_bitfield_t *)o1; + bf_2 = (py_bitfield_t *)o2; + + result = build_from_internal_bitfield(bf_1->native); + + new = (py_bitfield_t *)result; + + and_bit_field(new->native, bf_2->native); + + pbna_done: + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : o1 = premier élément concerné par l'opération. * +* o2 = second élément concerné par l'opération. * +* * +* Description : Effectue une opération de type 'or' avec le type 'bitfield'. * +* * +* Retour : Résultat de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_bitfield_nb_or(PyObject *o1, PyObject *o2) +{ + PyObject *result; /* Résultat à retourner */ + int ret; /* Bilan de compatibilité */ + py_bitfield_t *bf_1; /* Instance à manipuler #1 */ + py_bitfield_t *bf_2; /* Instance à manipuler #2 */ + py_bitfield_t *new; /* Nouvelle version en place */ + + ret = PyObject_IsInstance(o2, (PyObject *)get_python_bitfield_type()); + if (!ret) + { + result = NULL; + goto pbna_done; + } + + bf_1 = (py_bitfield_t *)o1; + bf_2 = (py_bitfield_t *)o2; + + result = build_from_internal_bitfield(bf_1->native); + + new = (py_bitfield_t *)result; + + or_bit_field(new->native, bf_2->native); + + pbna_done: + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : a = premier object Python à consulter. * +* b = second object Python à consulter. * +* op = type de comparaison menée. * +* * +* Description : Effectue une comparaison avec un objet Python 'bitfield'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_bitfield_richcompare(PyObject *a, PyObject *b, int op) +{ + PyObject *result; /* Bilan à retourner */ + int ret; /* Bilan de lecture des args. */ + py_bitfield_t *bf_a; /* Instance à manipuler #1 */ + py_bitfield_t *bf_b; /* Instance à manipuler #2 */ + int status; /* Résultat d'une comparaison */ + + ret = PyObject_IsInstance(b, (PyObject *)get_python_bitfield_type()); + if (!ret) + { + result = Py_NotImplemented; + goto cmp_done; + } + + bf_a = (py_bitfield_t *)a; + bf_b = (py_bitfield_t *)b; + + status = compare_bit_fields(bf_a->native, bf_b->native); + + result = status_to_rich_cmp_state(status, op); + + cmp_done: + + Py_INCREF(result); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = champ de bits à modifier. * +* args = non utilisé ici. * +* * +* Description : Bascule à 0 un champ de bits dans son intégralité. * +* * +* Retour : Rien (None). * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_bitfield_reset_all(PyObject *self, PyObject *args) +{ + py_bitfield_t *bf; /* Instance à manipuler */ + + bf = (py_bitfield_t *)self; + + reset_all_in_bit_field(bf->native); + + Py_RETURN_NONE; + +} + + +/****************************************************************************** +* * +* Paramètres : self = champ de bits à modifier. * +* args = non utilisé ici. * +* * +* Description : Bascule à 1 un champ de bits dans son intégralité. * +* * +* Retour : Rien (None). * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_bitfield_set_all(PyObject *self, PyObject *args) +{ + py_bitfield_t *bf; /* Instance à manipuler */ + + bf = (py_bitfield_t *)self; + + set_all_in_bit_field(bf->native); + + Py_RETURN_NONE; + +} + + +/****************************************************************************** +* * +* Paramètres : self = champ de bits à consulter. * +* args = arguments fournis pour la conduite de l'opération. * +* * +* Description : Bascule à 0 une partie d'un champ de bits. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_bitfield_reset(PyObject *self, PyObject *args) +{ + unsigned long first; /* Indice du premier bit testé */ + unsigned long count; /* Nombre de bits à analyser */ + int ret; /* Bilan de lecture des args. */ + py_bitfield_t *bf; /* Instance à manipuler */ + + ret = PyArg_ParseTuple(args, "kk", &first, &count); + if (!ret) return NULL; + + bf = (py_bitfield_t *)self; + + reset_in_bit_field(bf->native, first, count); + + Py_RETURN_NONE; + +} + + +/****************************************************************************** +* * +* Paramètres : self = champ de bits à consulter. * +* args = arguments fournis pour la conduite de l'opération. * +* * +* Description : Bascule à 1 une partie d'un champ de bits. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_bitfield_set(PyObject *self, PyObject *args) +{ + unsigned long first; /* Indice du premier bit testé */ + unsigned long count; /* Nombre de bits à analyser */ + int ret; /* Bilan de lecture des args. */ + py_bitfield_t *bf; /* Instance à manipuler */ + + ret = PyArg_ParseTuple(args, "kk", &first, &count); + if (!ret) return NULL; + + bf = (py_bitfield_t *)self; + + set_in_bit_field(bf->native, first, count); + + Py_RETURN_NONE; + +} + + +/****************************************************************************** +* * +* Paramètres : self = champ de bits à consulter. * +* args = arguments fournis pour la conduite de l'opération. * +* * +* Description : Détermine si un bit est à 1 dans un champ de bits. * +* * +* Retour : true si le bit correspondant est à l'état haut. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_bitfield_test(PyObject *self, PyObject *args) +{ + PyObject *result; /* Bilan à faire remonter */ + unsigned long n; /* Indice du bit à traiter */ + int ret; /* Bilan de lecture des args. */ + py_bitfield_t *bf; /* Instance à manipuler */ + bool status; /* Bilan d'analyse */ + + ret = PyArg_ParseTuple(args, "k", &n); + if (!ret) return NULL; + + bf = (py_bitfield_t *)self; + + status = test_in_bit_field(bf->native, n); + + result = status ? Py_True : Py_False; + + Py_INCREF(result); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = champ de bits à consulter. * +* args = arguments fournis pour la conduite de l'opération. * +* * +* Description : Détermine si un ensemble de bits est à 0 dans un champ. * +* * +* Retour : True si les bits correspondants sont à l'état bas. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_bitfield_test_none(PyObject *self, PyObject *args) +{ + PyObject *result; /* Bilan à faire remonter */ + unsigned long first; /* Indice du premier bit testé */ + unsigned long count; /* Nombre de bits à analyser */ + int ret; /* Bilan de lecture des args. */ + py_bitfield_t *bf; /* Instance à manipuler */ + bool status; /* Bilan d'analyse */ + + ret = PyArg_ParseTuple(args, "kk", &first, &count); + if (!ret) return NULL; + + bf = (py_bitfield_t *)self; + + status = test_none_in_bit_field(bf->native, first, count); + + result = status ? Py_True : Py_False; + + Py_INCREF(result); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = champ de bits à consulter. * +* args = arguments fournis pour la conduite de l'opération. * +* * +* Description : Détermine si un ensemble de bits est à 1 dans un champ. * +* * +* Retour : True si les bits correspondants sont à l'état haut. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_bitfield_test_all(PyObject *self, PyObject *args) +{ + PyObject *result; /* Bilan à faire remonter */ + unsigned long first; /* Indice du premier bit testé */ + unsigned long count; /* Nombre de bits à analyser */ + int ret; /* Bilan de lecture des args. */ + py_bitfield_t *bf; /* Instance à manipuler */ + bool status; /* Bilan d'analyse */ + + ret = PyArg_ParseTuple(args, "kk", &first, &count); + if (!ret) return NULL; + + bf = (py_bitfield_t *)self; + + status = test_all_in_bit_field(bf->native, first, count); + + result = status ? Py_True : Py_False; + + Py_INCREF(result); + + 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_bitfield_type(void) +{ + static PyNumberMethods py_bitfield_nb_proto = { + + .nb_and = py_bitfield_nb_and, + .nb_or = py_bitfield_nb_or + + }; + + static PyMethodDef py_bitfield_methods[] = { + { + "dup", py_bitfield_dup, + METH_NOARGS, + "dup(self, /)\n--\n\nDuplicate a bitfield." + }, + { + "reset_all", py_bitfield_reset_all, + METH_NOARGS, + "reset_all(self, /)\n--\n\nSwitch to 0 all bits in a bitfield." + }, + { + "set_all", py_bitfield_set_all, + METH_NOARGS, + "set_all(self, /)\n--\n\nSwitch to 1 all bits in a bitfield." + }, + { + "reset", py_bitfield_reset, + METH_VARARGS, + "reset(self, first, count, /)\n--\n\nSwitch to 0 a part of bits in a bitfield." + }, + { + "set", py_bitfield_set, + METH_VARARGS, + "set(self, first, count, /)\n--\n\nSwitch to 1 a part of bits in a bitfield." + }, + { + "test", py_bitfield_test, + METH_VARARGS, + "test(self, n, /)\n--\n\nTest if a given bit is set in a bitfield." + }, + { + "test_none", py_bitfield_test_none, + METH_VARARGS, + "test_none(self, first, count, /)\n--\n\nTest a range of bits to 0." + }, + { + "test_all", py_bitfield_test_all, + METH_VARARGS, + "test_all(self, first, count, /)\n--\n\nTest a range of bits to 1." + }, + { NULL } + }; + + static PyGetSetDef py_bitfield_getseters[] = { + { NULL } + }; + + static PyTypeObject py_bitfield_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.common.bitfield", + .tp_basicsize = sizeof(py_bitfield_t), + + .tp_as_number = &py_bitfield_nb_proto, + + .tp_flags = Py_TPFLAGS_DEFAULT, + + .tp_doc = "Python object for bitfield_t.", + + .tp_richcompare = py_bitfield_richcompare, + + .tp_methods = py_bitfield_methods, + .tp_getset = py_bitfield_getseters, + .tp_new = (newfunc)py_bitfield_new + + }; + + return &py_bitfield_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.common.bitfield'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_bitfield(PyObject *module) +{ + PyTypeObject *py_bitfield_type; /* Type Python pour 'bitfield' */ + int ret; /* Bilan d'un appel */ + + py_bitfield_type = get_python_bitfield_type(); + + if (PyType_Ready(py_bitfield_type) != 0) + return false; + + Py_INCREF(py_bitfield_type); + ret = PyModule_AddObject(module, "bitfield", (PyObject *)py_bitfield_type); + + return (ret == 0); + +} + + +/****************************************************************************** +* * +* Paramètres : field = structure interne à copier en objet Python. * +* * +* Description : Convertit une structure de type 'bitfield' en objet Python. * +* * +* Retour : Object Python résultant de la conversion opérée. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyObject *build_from_internal_bitfield(const bitfield_t *field) +{ + py_bitfield_t *result; /* Instance à retourner */ + PyTypeObject *type; /* Type à instancier */ + + type = get_python_bitfield_type(); + + result = (py_bitfield_t *)type->tp_alloc(type, 0); + + result->native = dup_bit_field(field); + + return (PyObject *)result; + +} diff --git a/plugins/pychrysalide/common/bits.h b/plugins/pychrysalide/common/bits.h new file mode 100644 index 0000000..3e2af73 --- /dev/null +++ b/plugins/pychrysalide/common/bits.h @@ -0,0 +1,48 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * bits.h - prototypes pour l'équivalent Python du fichier "common/bits.h" + * + * Copyright (C) 2017 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_COMMON_BITS_H +#define _PLUGINS_PYCHRYSALIDE_COMMON_BITS_H + + +#include +#include + + +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_bitfield_type(void); + +/* Prend en charge l'objet 'pychrysalide.common.bitfield'. */ +bool register_python_bitfield(PyObject *); + +/* Convertit une structure de type 'bitfield' en objet Python. */ +PyObject *build_from_internal_bitfield(const bitfield_t *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_COMMON_BITS_H */ diff --git a/plugins/pychrysalide/common/fnv1a.c b/plugins/pychrysalide/common/fnv1a.c new file mode 100644 index 0000000..cc2c342 --- /dev/null +++ b/plugins/pychrysalide/common/fnv1a.c @@ -0,0 +1,145 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * fnv1a.c - équivalent Python du fichier "common/fnv1a.c" + * + * Copyright (C) 2015-2017 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 "fnv1a.h" + + +#include + + +#include + + + +/* Détermine l'empreinte FNV1a d'une chaîne de caractères. */ +static PyObject *py_fnv1a_hash(PyObject *, PyObject *); + + + +/****************************************************************************** +* * +* Paramètres : self = NULL car méthode statique. * +* args = arguments fournis lors de l'appel à la fonction. * +* * +* Description : Détermine l'empreinte FNV1a d'une chaîne de caractères. * +* * +* Retour : Numéro de révision. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_fnv1a_hash(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + const char *str; /* Chaîne à traiter. */ + int ret; /* Bilan de lecture des args. */ + fnv64_t value; /* Empreinte calculée */ + + ret = PyArg_ParseTuple(args, "s", &str); + if (!ret) Py_RETURN_NONE; + + value = fnv_64a_hash(str); + + result = Py_BuildValue("K", (unsigned long long)value); + + 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_fnv1a_type(void) +{ + static PyMethodDef py_fnv1a_methods[] = { + + { "hash", py_fnv1a_hash, + METH_VARARGS | METH_STATIC, + "hash(str, /)\n--\n\nCompute the FNV-1a hash from a given string." + }, + { NULL } + + }; + + static PyTypeObject py_fnv1a_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.core.fnv1a", + .tp_basicsize = sizeof(PyObject), + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IS_ABSTRACT, + + .tp_doc = "Python version for Chrysalide of the Fowler-Noll-Vo hash function.", + + .tp_methods = py_fnv1a_methods + + }; + + return &py_fnv1a_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.core.fnv1a'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_fnv1a(PyObject *module) +{ + PyTypeObject *py_fnv1a_type; /* Type Python pour 'fnv1a' */ + int ret; /* Bilan d'un appel */ + + py_fnv1a_type = get_python_fnv1a_type(); + + //py_fnv1a_type->tp_new = PyType_GenericNew; + + if (PyType_Ready(py_fnv1a_type) != 0) + return false; + + Py_INCREF(py_fnv1a_type); + ret = PyModule_AddObject(module, "fnv1a", (PyObject *)py_fnv1a_type); + + return (ret == 0); + +} diff --git a/plugins/pychrysalide/common/fnv1a.h b/plugins/pychrysalide/common/fnv1a.h new file mode 100644 index 0000000..0a40770 --- /dev/null +++ b/plugins/pychrysalide/common/fnv1a.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * fnv1a.h - prototypes pour l'équivalent Python du fichier "common/fnv1a.c" + * + * Copyright (C) 2015-2017 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_COMMON_FNV1A_H +#define _PLUGINS_PYCHRYSALIDE_COMMON_FNV1A_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_fnv1a_type(void); + +/* Prend en charge l'objet 'pychrysalide.common.fnv1a'. */ +bool register_python_fnv1a(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_COMMON_FNV1A_H */ diff --git a/plugins/pychrysalide/common/module.c b/plugins/pychrysalide/common/module.c new file mode 100644 index 0000000..7ff7528 --- /dev/null +++ b/plugins/pychrysalide/common/module.c @@ -0,0 +1,99 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.c - intégration du répertoire common en tant que module + * + * Copyright (C) 2015-2017 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 "module.h" + + +#include "bits.h" +#include "fnv1a.h" +#include "pathname.h" +#include "../access.h" + + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Ajoute le module 'common' au module Python. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool add_common_module_to_python_module(PyObject *super) +{ + bool result; /* Bilan à retourner */ + PyObject *module; /* Sous-module mis en place */ + int ret; /* Bilan d'un appel */ + + static PyModuleDef py_chrysalide_common_module = { + + .m_base = PyModuleDef_HEAD_INIT, + + .m_name = "pychrysalide.common", + .m_doc = "Python module for Chrysalide.common", + + .m_size = -1, + + }; + + result = false; + + module = PyModule_Create(&py_chrysalide_common_module); + if (module == NULL) return false; + + ret = PyState_AddModule(super, &py_chrysalide_common_module); + if (ret != 0) goto acmtpm_exit; + + ret = _PyImport_FixupBuiltin(module, "pychrysalide.common"); + if (ret != 0) goto acmtpm_exit; + + Py_INCREF(module); + ret = PyModule_AddObject(super, "common", module); + if (ret != 0) goto acmtpm_exit; + + result = true; + + result &= register_python_bitfield(module); + result &= register_python_fnv1a(module); + result &= register_python_pathname(module); + + if (result) + register_access_to_python_module("pychrysalide.common", module); + + acmtpm_exit: + + if (!result) + { + printf("something went wrong in %s...\n", __FUNCTION__); + /* ... */ + + } + + return result; + +} diff --git a/plugins/pychrysalide/common/module.h b/plugins/pychrysalide/common/module.h new file mode 100644 index 0000000..446f6fe --- /dev/null +++ b/plugins/pychrysalide/common/module.h @@ -0,0 +1,39 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.h - prototypes pour l'intégration du répertoire common en tant que module + * + * Copyright (C) 2015-2017 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_COMMON_MODULE_H +#define _PLUGINS_PYCHRYSALIDE_COMMON_MODULE_H + + +#include +#include + + + +/* Ajoute le module 'common' au module Python. */ +bool add_common_module_to_python_module(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_COMMON_MODULE_H */ diff --git a/plugins/pychrysalide/common/pathname.c b/plugins/pychrysalide/common/pathname.c new file mode 100644 index 0000000..40977df --- /dev/null +++ b/plugins/pychrysalide/common/pathname.c @@ -0,0 +1,203 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * pathname.c - équivalent Python du fichier "common/pathname.c" + * + * Copyright (C) 2015-2017 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 "pathname.h" + + +#include +#include + + +#include + + +#include + + + +/* Calcule le chemin relatif entre deux fichiers donnés. */ +static PyObject *py_build_relative_filename(PyObject *, PyObject *); + +/* Calcule le chemin absolu d'un fichier par rapport à un autre. */ +static PyObject *py_build_absolute_filename(PyObject *, PyObject *); + + + +/****************************************************************************** +* * +* Paramètres : self = NULL car méthode statique. * +* args = arguments fournis lors de l'appel à la fonction. * +* * +* Description : Calcule le chemin relatif entre deux fichiers donnés. * +* * +* Retour : Chemin relatif obtenu. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_build_relative_filename(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + const char *ref; /* Fichier de référence */ + const char *target; /* Fichier à cibler */ + int ret; /* Bilan de lecture des args. */ + char *relative; /* Chemin d'accès construit */ + + ret = PyArg_ParseTuple(args, "ss", &ref, &target); + if (!ret) Py_RETURN_NONE; + + relative = build_relative_filename(ref, target); + + result = PyUnicode_FromString(relative); + + free(relative); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = NULL car méthode statique. * +* args = arguments fournis lors de l'appel à la fonction. * +* * +* Description : Calcule le chemin absolu d'un fichier par rapport à un autre.* +* * +* Retour : Chemin absolu obtenu. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_build_absolute_filename(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + const char *ref; /* Fichier de référence */ + const char *target; /* Fichier à cibler */ + int ret; /* Bilan de lecture des args. */ + char *relative; /* Chemin d'accès construit */ + + ret = PyArg_ParseTuple(args, "ss", &ref, &target); + if (!ret) Py_RETURN_NONE; + + relative = build_absolute_filename(ref, target); + + if (relative == NULL) + { + PyErr_SetString(PyExc_ValueError, _("Relative path is too deep.")); + result = NULL; + } + else + { + result = PyUnicode_FromString(relative); + + free(relative); + + } + + 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_pathname_type(void) +{ + static PyMethodDef py_pathname_methods[] = { + + { "build_relative_filename", py_build_relative_filename, + METH_VARARGS | METH_STATIC, + "build_relative_filename(ref, target, /)\n--\n\nCompute the relative path between two files." + }, + { "build_absolute_filename", py_build_absolute_filename, + METH_VARARGS | METH_STATIC, + "build_absolute_filename(ref, target, /)\n--\n\nCompute the absolute path for a file." + }, + { NULL } + + }; + + static PyTypeObject py_pathname_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.core.pathname", + .tp_basicsize = sizeof(PyObject), + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IS_ABSTRACT, + + .tp_doc = "Path manipulations in Python for Chrysalide.", + + .tp_methods = py_pathname_methods + + }; + + return &py_pathname_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.core.pathname'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_pathname(PyObject *module) +{ + PyTypeObject *py_pathname_type; /* Type Python pour 'pathname' */ + int ret; /* Bilan d'un appel */ + + py_pathname_type = get_python_pathname_type(); + + //py_pathname_type->tp_new = PyType_GenericNew; + + if (PyType_Ready(py_pathname_type) != 0) + return false; + + Py_INCREF(py_pathname_type); + ret = PyModule_AddObject(module, "pathname", (PyObject *)py_pathname_type); + + return (ret == 0); + +} diff --git a/plugins/pychrysalide/common/pathname.h b/plugins/pychrysalide/common/pathname.h new file mode 100644 index 0000000..a3940c9 --- /dev/null +++ b/plugins/pychrysalide/common/pathname.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * pathname.h - prototypes pour l'équivalent Python du fichier "common/pathname.c" + * + * Copyright (C) 2015-2017 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_COMMON_PATHNAME_H +#define _PLUGINS_PYCHRYSALIDE_COMMON_PATHNAME_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_pathname_type(void); + +/* Prend en charge l'objet 'pychrysalide.common.pathname'. */ +bool register_python_pathname(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_COMMON_PATHNAME_H */ diff --git a/plugins/pychrysalide/core/Makefile.am b/plugins/pychrysalide/core/Makefile.am new file mode 100644 index 0000000..71abfa4 --- /dev/null +++ b/plugins/pychrysalide/core/Makefile.am @@ -0,0 +1,17 @@ + +noinst_LTLIBRARIES = libpychrysacore.la + +libpychrysacore_la_SOURCES = \ + formats.h formats.c \ + logs.h logs.c \ + module.h module.c \ + params.h params.c + + +libpychrysacore_la_LDFLAGS = + + +AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ + -I../../../src + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) diff --git a/plugins/pychrysalide/core/formats.c b/plugins/pychrysalide/core/formats.c new file mode 100644 index 0000000..621277a --- /dev/null +++ b/plugins/pychrysalide/core/formats.c @@ -0,0 +1,190 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * formats.c - équivalent Python du fichier "core/formats.c" + * + * Copyright (C) 2015-2017 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 "formats.h" + + +#include + + +#include + + +#include "../helpers.h" + + + +/* Fournit le nom humain du format binaire visé. */ +static PyObject *py_formats_get_binary_format_name(PyObject *, PyObject *); + +/* Définit les constantes pour les paramètres. */ +static bool py_formats_define_constants(PyTypeObject *); + + + +/****************************************************************************** +* * +* Paramètres : self = NULL car méthode statique. * +* args = non utilisé ici. * +* * +* Description : Fournit le nom humain du format binaire visé. * +* * +* Retour : Désignation humaine trouvée ou None. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_formats_get_binary_format_name(PyObject *self, PyObject *args) +{ + PyObject *result; /* Désignation à retourner */ + const char *key; /* Nom court du format */ + int ret; /* Bilan de lecture des args. */ + const char *name; /* Désignation humaine */ + + ret = PyArg_ParseTuple(args, "s", &key); + if (!ret) return NULL; + + name = get_binary_format_name(key); + + if (name != NULL) + result = PyUnicode_FromString(name); + + else + { + result = Py_None; + Py_INCREF(result); + } + + 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_formats_type(void) +{ + static PyMethodDef py_formats_methods[] = { + + { "get_binary_format_name", py_formats_get_binary_format_name, + METH_VARARGS | METH_STATIC, + "get_binary_format_name(key, /)\n--\n\nGive access to the main configuration of Chrysalide." + }, + { NULL } + + }; + + static PyTypeObject py_formats_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.core.formats", + .tp_basicsize = sizeof(PyObject), + + .tp_flags = Py_TPFLAGS_DEFAULT, + + .tp_doc = "Python object for parameters", + + .tp_methods = py_formats_methods + + }; + + return &py_formats_type; + +} + + +/****************************************************************************** +* * +* Paramètres : obj_type = type dont le dictionnaire est à compléter. * +* * +* Description : Définit les constantes pour les paramètres. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool py_formats_define_constants(PyTypeObject *obj_type) +{ + bool result; /* Bilan à retourner */ + + result = true; + + result &= PyDict_AddIntMacro(obj_type, FMS_MATCHED); + result &= PyDict_AddIntMacro(obj_type, FMS_FORWARDED); + result &= PyDict_AddIntMacro(obj_type, FMS_UNKNOWN); + + result &= PyDict_AddIntMacro(obj_type, FMS_COUNT); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.core.formats'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_formats(PyObject *module) +{ + PyTypeObject *py_formats_type; /* Type Python pour 'formats' */ + int ret; /* Bilan d'un appel */ + + py_formats_type = get_python_formats_type(); + + py_formats_type->tp_new = PyType_GenericNew; + + if (PyType_Ready(py_formats_type) != 0) + return false; + + if (!py_formats_define_constants(py_formats_type)) + return false; + + Py_INCREF(py_formats_type); + ret = PyModule_AddObject(module, "formats", (PyObject *)py_formats_type); + + return (ret == 0); + +} diff --git a/plugins/pychrysalide/core/formats.h b/plugins/pychrysalide/core/formats.h new file mode 100644 index 0000000..ca12c3e --- /dev/null +++ b/plugins/pychrysalide/core/formats.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * formats.h - prototypes pour l'équivalent Python du fichier "core/formats.h" + * + * Copyright (C) 2015-2017 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_FORMATS_H +#define _PLUGINS_PYCHRYSALIDE_CORE_FORMATS_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_formats_type(void); + +/* Prend en charge l'objet 'pychrysalide.core.formats'. */ +bool register_python_formats(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_CORE_FORMATS_H */ diff --git a/plugins/pychrysalide/core/logs.c b/plugins/pychrysalide/core/logs.c new file mode 100644 index 0000000..8a922c1 --- /dev/null +++ b/plugins/pychrysalide/core/logs.c @@ -0,0 +1,278 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * logs.c - équivalent Python du fichier "gui/panels/logs.c" + * + * Copyright (C) 2017 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 "logs.h" + + +#include + + +#include + + +#include "../helpers.h" + + + +/* Fournit la verbosité des messages système. */ +static PyObject *py_logs_get_verbosity(PyObject *, PyObject *); + +/* Définit la verbosité des messages système. */ +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(PyTypeObject *); + + + +/****************************************************************************** +* * +* Paramètres : self = classe assurant le lien avec l'éditeur de messages. * +* args = arguments fournis à l'appel. * +* * +* Description : Fournit la verbosité des messages système. * +* * +* Retour : Plus faible niveau des types de message affichés. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_logs_get_verbosity(PyObject *self, PyObject *args) +{ + PyObject *result; /* Conversion à retourner */ + LogMessageType verbosity; /* Niveau de filtre de message */ + + verbosity = get_log_verbosity(); + + result = PyLong_FromUnsignedLong(verbosity); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = classe assurant le lien avec l'éditeur de messages. * +* args = arguments fournis à l'appel. * +* * +* Description : Définit la verbosité des messages système. * +* * +* Retour : Rien en équivalent Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_logs_set_verbosity(PyObject *self, PyObject *args) +{ + PyObject *result; /* Bilan à retourner */ + unsigned long verbosity; /* Niveau de filtre de message */ + + if (!PyArg_ParseTuple(args, "k", &verbosity)) + return NULL; + + set_log_verbosity(verbosity); + + result = Py_None; + Py_INCREF(result); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = classe assurant le lien avec l'éditeur de messages. * +* args = arguments fournis à l'appel. * +* * +* Description : Affiche un message dans le journal des messages système. * +* * +* Retour : Rien en équivalent Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_logs_log_message(PyObject *self, PyObject *args) +{ + PyObject *result; /* Bilan à retourner */ + unsigned long type; /* Espèce du message */ + const char *msg; /* Contenu du message */ + + if (!PyArg_ParseTuple(args, "ks", &type, &msg)) + return NULL; + + switch (type) + { + case LMT_INFO: + case LMT_PROCESS: + case LMT_WARNING: + case LMT_ERROR: + case LMT_BAD_BINARY: + log_simple_message(type, msg); + result = Py_None; + Py_INCREF(result); + break; + + default: + PyErr_SetString(PyExc_ValueError, + _("Invalid type of message")); + result = NULL; + break; + + } + + 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_logs_type(void) +{ + static PyMethodDef py_logs_methods[] = { + { + "get_verbosity", (PyCFunction)py_logs_get_verbosity, + METH_NOARGS | METH_STATIC, + "get_verbosity(, /)\n--\n\nGet the log verbosity." + }, + { + "set_verbosity", (PyCFunction)py_logs_set_verbosity, + METH_VARARGS | METH_STATIC, + "set_verbosity(, /)\n--\n\nSet the log verbosity." + }, + { + "log_message", (PyCFunction)py_logs_log_message, + METH_VARARGS | METH_STATIC, + "log_message(type, msg, /)\n--\n\nDisplay a message in the log window, if any." + }, + { NULL } + + }; + + static PyGetSetDef py_logs_getseters[] = { + { NULL } + }; + + static PyTypeObject py_logs_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.core.logs", + .tp_basicsize = sizeof(PyObject) + 80, + + .tp_flags = Py_TPFLAGS_DEFAULT, + + .tp_doc = "Python object for logs", + + .tp_methods = py_logs_methods, + .tp_getset = py_logs_getseters + + }; + + return &py_logs_type; + +} + + +/****************************************************************************** +* * +* Paramètres : obj_type = type dont le dictionnaire est à 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(PyTypeObject *obj_type) +{ + bool result; /* Bilan à retourner */ + + result = true; + + result &= PyDict_AddIntMacro(obj_type, LMT_INFO); + result &= PyDict_AddIntMacro(obj_type, LMT_PROCESS); + result &= PyDict_AddIntMacro(obj_type, LMT_WARNING); + result &= PyDict_AddIntMacro(obj_type, LMT_ERROR); + result &= PyDict_AddIntMacro(obj_type, LMT_BAD_BINARY); + result &= PyDict_AddIntMacro(obj_type, LMT_COUNT); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.gui.panels.LogPanel'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_logs(PyObject *module) +{ + PyTypeObject *py_logs_type; /* Type Python pour 'logs' */ + int ret; /* Bilan d'un appel */ + + py_logs_type = get_python_logs_type(); + + py_logs_type->tp_new = PyType_GenericNew; + + if (PyType_Ready(py_logs_type) != 0) + return false; + + if (!define_python_log_constants(py_logs_type)) + return false; + + Py_INCREF(py_logs_type); + ret = PyModule_AddObject(module, "logs", (PyObject *)py_logs_type); + + return (ret == 0); + +} diff --git a/plugins/pychrysalide/core/logs.h b/plugins/pychrysalide/core/logs.h new file mode 100644 index 0000000..a43d9ca --- /dev/null +++ b/plugins/pychrysalide/core/logs.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * logs.h - prototypes pour l'équivalent Python du fichier "core/logs.h" + * + * Copyright (C) 2017 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_LOGS_H +#define _PLUGINS_PYCHRYSALIDE_CORE_LOGS_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_logs_type(void); + +/* Prend en charge l'objet 'pychrysalide.core.logs'. */ +bool register_python_logs(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_CORE_LOGS_H */ diff --git a/plugins/pychrysalide/core/module.c b/plugins/pychrysalide/core/module.c new file mode 100644 index 0000000..ff7f828 --- /dev/null +++ b/plugins/pychrysalide/core/module.c @@ -0,0 +1,97 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.c - intégration du répertoire core en tant que module + * + * Copyright (C) 2014-2017 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 "module.h" + + +#include + + +#include "formats.h" +#include "logs.h" +#include "params.h" +#include "../access.h" + + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Ajoute le module 'core' au module Python. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool add_core_module_to_python_module(PyObject *super) +{ + bool result; /* Bilan à retourner */ + PyObject *module; /* Sous-module mis en place */ + int ret; /* Bilan d'un appel */ + + static PyModuleDef py_chrysalide_core_module = { + + .m_base = PyModuleDef_HEAD_INIT, + + .m_name = "pychrysalide.core", + .m_doc = "Python module for Chrysalide.core", + + .m_size = -1, + + }; + + result = false; + + module = PyModule_Create(&py_chrysalide_core_module); + if (module == NULL) return false; + + ret = PyState_AddModule(super, &py_chrysalide_core_module); + if (ret != 0) goto loading_failed; + + ret = _PyImport_FixupBuiltin(module, "pychrysalide.core"); + if (ret != 0) goto loading_failed; + + Py_INCREF(module); + ret = PyModule_AddObject(super, "core", module); + if (ret != 0) goto loading_failed; + + result = true; + + result &= register_python_formats(module); + result &= register_python_logs(module); + result &= register_python_params(module); + + if (result) + register_access_to_python_module("pychrysalide.core", module); + + loading_failed: + + assert(result); + + return result; + +} diff --git a/plugins/pychrysalide/core/module.h b/plugins/pychrysalide/core/module.h new file mode 100644 index 0000000..8581425 --- /dev/null +++ b/plugins/pychrysalide/core/module.h @@ -0,0 +1,39 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.h - prototypes pour l'intégration du répertoire core en tant que module + * + * Copyright (C) 2014-2017 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_MODULE_H +#define _PLUGINS_PYCHRYSALIDE_CORE_MODULE_H + + +#include +#include + + + +/* Ajoute le module 'core' au module Python. */ +bool add_core_module_to_python_module(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_CORE_MODULE_H */ diff --git a/plugins/pychrysalide/core/params.c b/plugins/pychrysalide/core/params.c new file mode 100644 index 0000000..df71a88 --- /dev/null +++ b/plugins/pychrysalide/core/params.c @@ -0,0 +1,179 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * params.c - équivalent Python du fichier "core/params.c" + * + * Copyright (C) 2014-2017 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 "params.h" + + +#include + + +#include + + +#include "../helpers.h" + + + +/* Fournit la version du programme global. */ +static PyObject *py_params_get_main_configuration(PyObject *, PyObject *); + +/* Définit les constantes pour les paramètres. */ +static bool py_params_define_constants(PyTypeObject *); + + + +/****************************************************************************** +* * +* Paramètres : self = NULL car méthode statique. * +* args = non utilisé ici. * +* * +* Description : Fournit la version du programme global. * +* * +* Retour : Numéro de révision. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_params_get_main_configuration(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance GLib à retourner */ + GGenConfig *config; /* Configuration à convertir */ + + config = get_main_configuration(); + + result = pygobject_new(G_OBJECT(config)); + Py_XINCREF(result); + + 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_params_type(void) +{ + static PyMethodDef py_params_methods[] = { + + { "get_main_configuration", py_params_get_main_configuration, + METH_NOARGS | METH_STATIC, + "Give access to the main configuration of Chrysalide." + }, + { NULL } + + }; + + static PyTypeObject py_params_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.core.params", + .tp_basicsize = sizeof(PyObject), + + .tp_flags = Py_TPFLAGS_DEFAULT, + + .tp_doc = "Python object for parameters", + + .tp_methods = py_params_methods + + }; + + return &py_params_type; + +} + + +/****************************************************************************** +* * +* Paramètres : obj_type = type dont le dictionnaire est à compléter. * +* * +* Description : Définit les constantes pour les paramètres. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool py_params_define_constants(PyTypeObject *obj_type) +{ + bool result; /* Bilan à retourner */ + + result = true; + + result &= PyDict_AddStringMacro(obj_type, MPK_LAST_PROJECT); + result &= PyDict_AddStringMacro(obj_type, MPK_ELLIPSIS_HEADER); + result &= PyDict_AddStringMacro(obj_type, MPK_ELLIPSIS_TAB); + result &= PyDict_AddStringMacro(obj_type, MPK_KEYBINDINGS_EDIT); + result &= PyDict_AddStringMacro(obj_type, MPK_AUTO_SAVE); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.core.params'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_params(PyObject *module) +{ + PyTypeObject *py_params_type; /* Type Python pour 'params' */ + int ret; /* Bilan d'un appel */ + + py_params_type = get_python_params_type(); + + py_params_type->tp_new = PyType_GenericNew; + + if (PyType_Ready(py_params_type) != 0) + return false; + + if (!py_params_define_constants(py_params_type)) + return false; + + Py_INCREF(py_params_type); + ret = PyModule_AddObject(module, "params", (PyObject *)py_params_type); + + return (ret == 0); + +} diff --git a/plugins/pychrysalide/core/params.h b/plugins/pychrysalide/core/params.h new file mode 100644 index 0000000..e7297b3 --- /dev/null +++ b/plugins/pychrysalide/core/params.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * params.h - prototypes pour l'équivalent Python du fichier "core/params.h" + * + * Copyright (C) 2014-2017 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_PARAMS_H +#define _PLUGINS_PYCHRYSALIDE_CORE_PARAMS_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_params_type(void); + +/* Prend en charge l'objet 'pychrysalide.core.params'. */ +bool register_python_params(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_CORE_PARAMS_H */ diff --git a/plugins/pychrysalide/debug/Makefile.am b/plugins/pychrysalide/debug/Makefile.am new file mode 100644 index 0000000..8011c49 --- /dev/null +++ b/plugins/pychrysalide/debug/Makefile.am @@ -0,0 +1,19 @@ + +noinst_LTLIBRARIES = libpychrysadebug.la + +libpychrysadebug_la_SOURCES = \ + debugger.h debugger.c \ + module.h module.c + +libpychrysadebug_la_LIBADD = \ + gdbrsp/libpychrysadebuggdbrsp.la + +libpychrysadebug_la_LDFLAGS = + + +AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ + -I../../../src + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) + +SUBDIRS = gdbrsp diff --git a/plugins/pychrysalide/debug/debugger.c b/plugins/pychrysalide/debug/debugger.c new file mode 100644 index 0000000..20b94c7 --- /dev/null +++ b/plugins/pychrysalide/debug/debugger.c @@ -0,0 +1,1185 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * debugger.c - instances Python de débogueurs + * + * Copyright (C) 2012-2017 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 "debugger.h" + + +#include +#include +#include + + +#include + + +#include "../helpers.h" +#include "../arch/vmpa.h" + + + + + +/* Fournit les identifiants de tous les threads actifs. */ +static PyObject *py_binary_debugger_list_all_threads(PyObject *, PyObject *); + + + +/* Lit une valeur de 8 bits à une adresse arbitraire. */ +static PyObject *py_binary_debugger_read_memory_u8(PyObject *, PyObject *); + +/* Lit une valeur de 16 bits à une adresse arbitraire. */ +static PyObject *py_binary_debugger_read_memory_u16(PyObject *, PyObject *); + +/* Lit une valeur de 32 bits à une adresse arbitraire. */ +static PyObject *py_binary_debugger_read_memory_u32(PyObject *, PyObject *); + +/* Lit une valeur de 64 bits à une adresse arbitraire. */ +static PyObject *py_binary_debugger_read_memory_u64(PyObject *, PyObject *); + +/* Liste l'ensemble des registres appartenant à un groupe. */ +static PyObject *py_binary_debugger_get_register_names(PyObject *, PyObject *); + +/* Indique la taille associée à un registre donné. */ +static PyObject *py_binary_debugger_get_register_size(PyObject *, PyObject *); + +/* Lit une valeur de 8 bits à partir d'un registre. */ +static PyObject *py_binary_debugger_read_register_u8(PyObject *, PyObject *); + +/* Lit une valeur de 16 bits à partir d'un registre. */ +static PyObject *py_binary_debugger_read_register_u16(PyObject *, PyObject *); + +/* Lit une valeur de 32 bits à partir d'un registre. */ +static PyObject *py_binary_debugger_read_register_u32(PyObject *, PyObject *); + +/* Lit une valeur de 64 bits à partir d'un registre. */ +static PyObject *py_binary_debugger_read_register_u64(PyObject *, PyObject *); + +/* Ecrit une valeur de 8 bits dans un registre. */ +static PyObject *py_binary_debugger_write_register_u8(PyObject *, PyObject *); + +/* Ecrit une valeur de 16 bits dans un registre. */ +static PyObject *py_binary_debugger_write_register_u16(PyObject *, PyObject *); + +/* Ecrit une valeur de 32 bits dans un registre. */ +static PyObject *py_binary_debugger_write_register_u32(PyObject *, PyObject *); + +/* Ecrit une valeur de 64 bits dans un registre. */ +static PyObject *py_binary_debugger_write_register_u64(PyObject *, PyObject *); + + + +/* Remonte la pile d'appels jusqu'au point courant. */ +static PyObject *py_binary_debugger_get_call_stack(PyObject *, PyObject *); + + + +/* Ajoute un point d'arrêt basique en mémoire. */ +static PyObject *py_binary_debugger_add_mem_bp(PyObject *, PyObject *); + +/* Retire un point d'arrêt basique en mémoire. */ +static PyObject *py_binary_debugger_delete_mem_bp(PyObject *, PyObject *); + + + +/* Redémarre le processus de débogage. */ +static PyObject *py_binary_debugger_restart(PyObject *, PyObject *); + +/* Remet en marche le débogueur courant. */ +static PyObject *py_binary_debugger_resume(PyObject *, PyObject *); + +/* Relance l'exécution pour une seule instruction. */ +static PyObject *py_binary_debugger_stepi(PyObject *, PyObject *); + + + + + + + + + + + + + + + + +/****************************************************************************** +* * +* Paramètres : self = contenu binaire à manipuler. * +* args = arguments non utilisés ici. * +* * +* Description : Fournit les identifiants de tous les threads actifs. * +* * +* Retour : Liste contenant identifiants et désignations de threads. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_debugger_list_all_threads(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GBinaryDebugger *debugger; /* Version GLib du format */ + size_t count; /* Quantité de threads actifs */ + dbg_thread_desc *threads; /* Liste des threads actifs */ + size_t i; /* Boucle de parcours */ + PyObject *thread; /* Détails sur un thread donné */ + + debugger = G_BINARY_DEBUGGER(pygobject_get(self)); + assert(debugger != NULL); + + threads = g_binary_debugger_list_all_threads(debugger, &count); + + result = PyTuple_New(count); + + for (i = 0; i < count; i++) + { + thread = PyTuple_New(2); + PyTuple_SetItem(result, i, thread); + + PyTuple_SetItem(thread, 0, PyLong_FromLong(threads[i].id)); + PyTuple_SetItem(thread, 1, PyUnicode_FromString(threads[i].name)); + + } + + delete_dbg_thread_desc(threads, count); + + return result; + +} + + + + + + + +/****************************************************************************** +* * +* Paramètres : self = contenu binaire à manipuler. * +* args = arguments accompagnant l'appel. * +* * +* Description : Lit une valeur de 8 bits à une adresse arbitraire. * +* * +* Retour : Valeur lue ou None. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_debugger_read_memory_u8(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GBinaryDebugger *debugger; /* Version GLib du format */ + int ret; /* Bilan de lecture des args. */ + vmpa2t addr; /* Position interne associée */ + uint8_t value; /* Valeur lue en mémoire */ + bool status; /* Bilan de l'opération */ + + debugger = G_BINARY_DEBUGGER(pygobject_get(self)); + assert(debugger != NULL); + + ret = PyArg_ParseTuple(args, "O&", convert_any_to_vmpa, &addr); + if (!ret) return NULL; + + status = g_binary_debugger_read_memory_u8(debugger, get_virt_addr(&addr), &value); + + if (status) + result = PyLong_FromUnsignedLongLong(value); + + else + { + result = Py_None; + Py_INCREF(result); + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = contenu binaire à manipuler. * +* args = arguments accompagnant l'appel. * +* * +* Description : Lit une valeur de 16 bits à une adresse arbitraire. * +* * +* Retour : Valeur lue ou None. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_debugger_read_memory_u16(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GBinaryDebugger *debugger; /* Version GLib du format */ + int ret; /* Bilan de lecture des args. */ + vmpa2t addr; /* Position interne associée */ + uint16_t value; /* Valeur lue en mémoire */ + bool status; /* Bilan de l'opération */ + + debugger = G_BINARY_DEBUGGER(pygobject_get(self)); + assert(debugger != NULL); + + ret = PyArg_ParseTuple(args, "O&", convert_any_to_vmpa, &addr); + if (!ret) return NULL; + + status = g_binary_debugger_read_memory_u16(debugger, get_virt_addr(&addr), &value); + + if (status) + result = PyLong_FromUnsignedLongLong(value); + + else + { + result = Py_None; + Py_INCREF(result); + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = contenu binaire à manipuler. * +* args = arguments accompagnant l'appel. * +* * +* Description : Lit une valeur de 32 bits à une adresse arbitraire. * +* * +* Retour : Valeur lue ou None. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_debugger_read_memory_u32(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GBinaryDebugger *debugger; /* Version GLib du format */ + int ret; /* Bilan de lecture des args. */ + vmpa2t addr; /* Position interne associée */ + uint32_t value; /* Valeur lue en mémoire */ + bool status; /* Bilan de l'opération */ + + debugger = G_BINARY_DEBUGGER(pygobject_get(self)); + assert(debugger != NULL); + + ret = PyArg_ParseTuple(args, "O&", convert_any_to_vmpa, &addr); + if (!ret) return NULL; + + status = g_binary_debugger_read_memory_u32(debugger, get_virt_addr(&addr), &value); + + if (status) + result = PyLong_FromUnsignedLongLong(value); + + else + { + result = Py_None; + Py_INCREF(result); + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = contenu binaire à manipuler. * +* args = arguments accompagnant l'appel. * +* * +* Description : Lit une valeur de 64 bits à une adresse arbitraire. * +* * +* Retour : Valeur lue ou None. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_debugger_read_memory_u64(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GBinaryDebugger *debugger; /* Version GLib du format */ + int ret; /* Bilan de lecture des args. */ + vmpa2t addr; /* Position interne associée */ + uint64_t value; /* Valeur lue en mémoire */ + bool status; /* Bilan de l'opération */ + + debugger = G_BINARY_DEBUGGER(pygobject_get(self)); + assert(debugger != NULL); + + ret = PyArg_ParseTuple(args, "O&", convert_any_to_vmpa, &addr); + if (!ret) return NULL; + + status = g_binary_debugger_read_memory_u64(debugger, get_virt_addr(&addr), &value); + + if (status) + result = PyLong_FromUnsignedLongLong(value); + + else + { + result = Py_None; + Py_INCREF(result); + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = instance de débogueur à consulter. * +* args = arguments accompagnant l'appel. * +* * +* Description : Liste l'ensemble des registres appartenant à un groupe. * +* * +* Retour : Liste de noms à libérer de la mémoire après utilisation. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_debugger_get_register_names(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GBinaryDebugger *debugger; /* Version GLib du format */ + const char *group; /* Nom du registre à manipuler */ + int ret; /* Bilan de lecture des args. */ + char **list; /* Liste de noms de registre */ + size_t count; /* Taille de cette liste */ + size_t i; /* Boucle de parcours */ + + debugger = G_BINARY_DEBUGGER(pygobject_get(self)); + assert(debugger != NULL); + + ret = PyArg_ParseTuple(args, "|s", &group); + if (!ret) return NULL; + + list = g_binary_debugger_get_register_names(debugger, group, &count); + + result = PyTuple_New(count); + + for (i = 0; i < count; i++) + { + PyTuple_SetItem(result, i, PyUnicode_FromString(list[i])); + free(list[i]); + } + + if (list != NULL) + free(list); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = instance de débogueur à consulter. * +* args = arguments accompagnant l'appel. * +* * +* Description : Indique la taille associée à un registre donné. * +* * +* Retour : Taille en bits, ou 0 si le registre n'a pas été trouvé. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_debugger_get_register_size(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GBinaryDebugger *debugger; /* Version GLib du format */ + const char *reg; /* Nom du registre à manipuler */ + int ret; /* Bilan de lecture des args. */ + unsigned int size; /* Taille associée au registre */ + + debugger = G_BINARY_DEBUGGER(pygobject_get(self)); + assert(debugger != NULL); + + ret = PyArg_ParseTuple(args, "s", ®); + if (!ret) return NULL; + + size = g_binary_debugger_get_register_size(debugger, reg); + + result = PyLong_FromUnsignedLong(size); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = contenu binaire à manipuler. * +* args = arguments accompagnant l'appel. * +* * +* Description : Lit une valeur de 8 bits à partir d'un registre. * +* * +* Retour : Valeur lue ou None. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_debugger_read_register_u8(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GBinaryDebugger *debugger; /* Version GLib du format */ + const char *reg; /* Nom du registre à manipuler */ + int ret; /* Bilan de lecture des args. */ + uint8_t value; /* Valeur lue en mémoire */ + bool status; /* Bilan de l'opération */ + + debugger = G_BINARY_DEBUGGER(pygobject_get(self)); + assert(debugger != NULL); + + ret = PyArg_ParseTuple(args, "s", ®); + if (!ret) return NULL; + + status = g_binary_debugger_read_register_u8(debugger, reg, &value); + + if (status) + result = PyLong_FromUnsignedLongLong(value); + + else + { + result = Py_None; + Py_INCREF(result); + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = contenu binaire à manipuler. * +* args = arguments accompagnant l'appel. * +* * +* Description : Lit une valeur de 16 bits à partir d'un registre. * +* * +* Retour : Valeur lue ou None. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_debugger_read_register_u16(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GBinaryDebugger *debugger; /* Version GLib du format */ + const char *reg; /* Nom du registre à manipuler */ + int ret; /* Bilan de lecture des args. */ + uint16_t value; /* Valeur lue en mémoire */ + bool status; /* Bilan de l'opération */ + + debugger = G_BINARY_DEBUGGER(pygobject_get(self)); + assert(debugger != NULL); + + ret = PyArg_ParseTuple(args, "s", ®); + if (!ret) return NULL; + + status = g_binary_debugger_read_register_u16(debugger, reg, &value); + + if (status) + result = PyLong_FromUnsignedLongLong(value); + + else + { + result = Py_None; + Py_INCREF(result); + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = contenu binaire à manipuler. * +* args = arguments accompagnant l'appel. * +* * +* Description : Lit une valeur de 32 bits à partir d'un registre. * +* * +* Retour : Valeur lue ou None. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_debugger_read_register_u32(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GBinaryDebugger *debugger; /* Version GLib du format */ + const char *reg; /* Nom du registre à manipuler */ + int ret; /* Bilan de lecture des args. */ + uint32_t value; /* Valeur lue en mémoire */ + bool status; /* Bilan de l'opération */ + + debugger = G_BINARY_DEBUGGER(pygobject_get(self)); + assert(debugger != NULL); + + ret = PyArg_ParseTuple(args, "s", ®); + if (!ret) return NULL; + + status = g_binary_debugger_read_register_u32(debugger, reg, &value); + + if (status) + result = PyLong_FromUnsignedLongLong(value); + + else + { + result = Py_None; + Py_INCREF(result); + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = contenu binaire à manipuler. * +* args = arguments accompagnant l'appel. * +* * +* Description : Lit une valeur de 64 bits à partir d'un registre. * +* * +* Retour : Valeur lue ou None. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_debugger_read_register_u64(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GBinaryDebugger *debugger; /* Version GLib du format */ + const char *reg; /* Nom du registre à manipuler */ + int ret; /* Bilan de lecture des args. */ + uint64_t value; /* Valeur lue en mémoire */ + bool status; /* Bilan de l'opération */ + + debugger = G_BINARY_DEBUGGER(pygobject_get(self)); + assert(debugger != NULL); + + ret = PyArg_ParseTuple(args, "s", ®); + if (!ret) return NULL; + + status = g_binary_debugger_read_register_u64(debugger, reg, &value); + + if (status) + result = PyLong_FromUnsignedLongLong(value); + + else + { + result = Py_None; + Py_INCREF(result); + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = contenu binaire à manipuler. * +* args = arguments accompagnant l'appel. * +* * +* Description : Ecrit une valeur de 8 bits dans un registre. * +* * +* Retour : Valeur lue ou None. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_debugger_write_register_u8(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GBinaryDebugger *debugger; /* Version GLib du format */ + const char *reg; /* Nom du registre à manipuler */ + int ret; /* Bilan de lecture des args. */ + uint8_t value; /* Valeur lue en mémoire */ + bool status; /* Bilan de l'opération */ + + debugger = G_BINARY_DEBUGGER(pygobject_get(self)); + assert(debugger != NULL); + + ret = PyArg_ParseTuple(args, "sB", ®, &value); + if (!ret) return NULL; + + status = g_binary_debugger_write_register_u8(debugger, reg, &value); + + result = status ? Py_True : Py_False; + Py_INCREF(result); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = contenu binaire à manipuler. * +* args = arguments accompagnant l'appel. * +* * +* Description : Ecrit une valeur de 16 bits dans un registre. * +* * +* Retour : Valeur lue ou None. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_debugger_write_register_u16(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GBinaryDebugger *debugger; /* Version GLib du format */ + const char *reg; /* Nom du registre à manipuler */ + int ret; /* Bilan de lecture des args. */ + uint16_t value; /* Valeur lue en mémoire */ + bool status; /* Bilan de l'opération */ + + debugger = G_BINARY_DEBUGGER(pygobject_get(self)); + assert(debugger != NULL); + + ret = PyArg_ParseTuple(args, "sH", ®, &value); + if (!ret) return NULL; + + status = g_binary_debugger_write_register_u16(debugger, reg, &value); + + result = status ? Py_True : Py_False; + Py_INCREF(result); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = contenu binaire à manipuler. * +* args = arguments accompagnant l'appel. * +* * +* Description : Ecrit une valeur de 32 bits dans un registre. * +* * +* Retour : Valeur lue ou None. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_debugger_write_register_u32(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GBinaryDebugger *debugger; /* Version GLib du format */ + const char *reg; /* Nom du registre à manipuler */ + int ret; /* Bilan de lecture des args. */ + uint32_t value; /* Valeur lue en mémoire */ + bool status; /* Bilan de l'opération */ + + debugger = G_BINARY_DEBUGGER(pygobject_get(self)); + assert(debugger != NULL); + + ret = PyArg_ParseTuple(args, "sI", ®, &value); + if (!ret) return NULL; + + status = g_binary_debugger_write_register_u32(debugger, reg, &value); + + result = status ? Py_True : Py_False; + Py_INCREF(result); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = contenu binaire à manipuler. * +* args = arguments accompagnant l'appel. * +* * +* Description : Ecrit une valeur de 64 bits dans un registre. * +* * +* Retour : Valeur lue ou None. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_debugger_write_register_u64(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GBinaryDebugger *debugger; /* Version GLib du format */ + const char *reg; /* Nom du registre à manipuler */ + int ret; /* Bilan de lecture des args. */ + uint64_t value; /* Valeur lue en mémoire */ + bool status; /* Bilan de l'opération */ + + debugger = G_BINARY_DEBUGGER(pygobject_get(self)); + assert(debugger != NULL); + + ret = PyArg_ParseTuple(args, "sK", ®, &value); + if (!ret) return NULL; + + status = g_binary_debugger_write_register_u64(debugger, reg, &value); + + result = status ? Py_True : Py_False; + Py_INCREF(result); + + return result; + +} + + + + + + + + +/****************************************************************************** +* * +* Paramètres : self = contenu binaire à manipuler. * +* args = arguments accompagnant l'appel. * +* * +* Description : Remonte la pile d'appels jusqu'au point courant. * +* * +* Retour : Pile d'appels sous forme de liste ou None en cas d'erreur. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_debugger_get_call_stack(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GBinaryDebugger *debugger; /* Version GLib du format */ + virt_t *callstack; /* Pile d'appels obtenue */ + size_t size; /* Hauteur de cette pile */ + bool status; /* Bilan de l'opération */ + size_t i; /* Boucle de parcours */ + + debugger = G_BINARY_DEBUGGER(pygobject_get(self)); + assert(debugger != NULL); + + status = g_binary_debugger_get_call_stack(debugger, &callstack, &size); + + if (!status) + { + result = Py_None; + Py_INCREF(result); + } + + else + { + result = PyTuple_New(size); + + for (i = 0; i < size; i++) + PyTuple_SetItem(result, i, PyLong_FromUnsignedLongLong(callstack[i])); + + if (callstack != NULL) + free(callstack); + + } + + return result; + +} + + + + + + + + +/****************************************************************************** +* * +* Paramètres : self = contenu binaire à manipuler. * +* args = arguments accompagnant l'appel. * +* * +* Description : Ajoute un point d'arrêt basique en mémoire. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_debugger_add_mem_bp(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GBinaryDebugger *debugger; /* Version GLib du format */ + vmpa2t addr; /* Position interne associée */ + int ret; /* Bilan de lecture des args. */ + bool status; /* Bilan de l'opération */ + + debugger = G_BINARY_DEBUGGER(pygobject_get(self)); + assert(debugger != NULL); + + ret = PyArg_ParseTuple(args, "O&", convert_any_to_vmpa, &addr); + if (!ret) return NULL; + + status = g_binary_debugger_add_memory_breakpoint(debugger, get_virt_addr(&addr)); + + result = status ? Py_True : Py_False; + Py_INCREF(result); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = contenu binaire à manipuler. * +* args = arguments accompagnant l'appel. * +* * +* Description : Retire un point d'arrêt basique en mémoire. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_debugger_delete_mem_bp(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GBinaryDebugger *debugger; /* Version GLib du format */ + vmpa2t addr; /* Position interne associée */ + int ret; /* Bilan de lecture des args. */ + bool status; /* Bilan de l'opération */ + + debugger = G_BINARY_DEBUGGER(pygobject_get(self)); + assert(debugger != NULL); + + ret = PyArg_ParseTuple(args, "O&", convert_any_to_vmpa, &addr); + if (!ret) return NULL; + + status = g_binary_debugger_delete_memory_breakpoint(debugger, get_virt_addr(&addr)); + + result = status ? Py_True : Py_False; + Py_INCREF(result); + + return result; + +} + + + + + + + + +/****************************************************************************** +* * +* Paramètres : self = contenu binaire à manipuler. * +* args = arguments non utilisés ici. * +* * +* Description : Redémarre le processus de débogage. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_debugger_restart(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GBinaryDebugger *debugger; /* Version GLib du format */ + bool status; /* Bilan de l'opération */ + + debugger = G_BINARY_DEBUGGER(pygobject_get(self)); + assert(debugger != NULL); + + status = g_binary_debugger_restart(debugger); + + result = status ? Py_True : Py_False; + Py_INCREF(result); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = contenu binaire à manipuler. * +* args = arguments non utilisés ici. * +* * +* Description : Remet en marche le débogueur courant. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_debugger_resume(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GBinaryDebugger *debugger; /* Version GLib du format */ + bool status; /* Bilan de l'opération */ + + debugger = G_BINARY_DEBUGGER(pygobject_get(self)); + assert(debugger != NULL); + + status = g_binary_debugger_resume(debugger); + + result = status ? Py_True : Py_False; + Py_INCREF(result); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = contenu binaire à manipuler. * +* args = arguments non utilisés ici. * +* * +* Description : Relance l'exécution pour une seule instruction. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_debugger_stepi(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GBinaryDebugger *debugger; /* Version GLib du format */ + bool status; /* Bilan de l'opération */ + + debugger = G_BINARY_DEBUGGER(pygobject_get(self)); + assert(debugger != NULL); + + status = g_binary_debugger_stepi(debugger, false); + + result = status ? Py_True : Py_False; + Py_INCREF(result); + + 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_binary_debugger_type(void) +{ + static PyMethodDef py_binary_debugger_methods[] = { + { + "list_all_threads", py_binary_debugger_list_all_threads, + METH_NOARGS, + "list_all_threads($self, /)\n--\n\nList all current active threads." + }, + { + "read_mem_u8", py_binary_debugger_read_memory_u8, + METH_VARARGS, + "read_mem_u8($self, addr, /)\n--\n\nRead a 8-bit value from a given address." + }, + { + "read_mem_u16", py_binary_debugger_read_memory_u16, + METH_VARARGS, + "read_mem_u16($self, addr, /)\n--\n\nRead a 16-bit value from a given address." + }, + { + "read_mem_u32", py_binary_debugger_read_memory_u32, + METH_VARARGS, + "read_mem_u32($self, addr, /)\n--\n\nRead a 32-bit value from a given address." + }, + { + "read_mem_u64", py_binary_debugger_read_memory_u64, + METH_VARARGS, + "read_mem_u64($self, addr, /)\n--\n\nRead a 64-bit value from a given address." + }, + { + "get_reg_names", py_binary_debugger_get_register_names, + METH_VARARGS, + "get_reg_names($self, [grp]/)\n--\n\nGet the names of all registers belonging to an optional group." + }, + { + "get_reg_size", py_binary_debugger_get_register_size, + METH_VARARGS, + "get_reg_size($self, name, /)\n--\n\nGet the size of a given register." + }, + { + "read_reg_u8", py_binary_debugger_read_register_u8, + METH_VARARGS, + "read_reg_u8($self, reg, /)\n--\n\nRead a 8-bit value from a named register." + }, + { + "read_reg_u16", py_binary_debugger_read_register_u16, + METH_VARARGS, + "read_reg_u16($self, reg, /)\n--\n\nRead a 16-bit value from a named register." + }, + { + "read_reg_u32", py_binary_debugger_read_register_u32, + METH_VARARGS, + "read_reg_u32($self, reg, /)\n--\n\nRead a 32-bit value from a named register." + }, + { + "read_reg_u64", py_binary_debugger_read_register_u64, + METH_VARARGS, + "read_reg_u64($self, reg, /)\n--\n\nRead a 64-bit value from a named register." + }, + { + "write_reg_u8", py_binary_debugger_write_register_u8, + METH_VARARGS, + "write_reg_u8($self, reg, val, /)\n--\n\nWrite a 8-bit value into a named register." + }, + { + "write_reg_u16", py_binary_debugger_write_register_u16, + METH_VARARGS, + "write_reg_u16($self, reg, val, /)\n--\n\nWrite a 16-bit value into a named register." + }, + { + "write_reg_u32", py_binary_debugger_write_register_u32, + METH_VARARGS, + "write_reg_u32($self, reg, val, /)\n--\n\nWrite a 32-bit value into a named register." + }, + { + "write_reg_u64", py_binary_debugger_write_register_u64, + METH_VARARGS, + "write_reg_u64($self, reg, val, /)\n--\n\nWrite a 64-bit value into a named register." + }, + { + "get_call_stack", py_binary_debugger_get_call_stack, + METH_NOARGS, + "get_call_stack($self, /)\n--\n\nGet the current call stack." + }, + { + "add_mem_bp", py_binary_debugger_add_mem_bp, + METH_VARARGS, + "add_mem_bp($self, addr, /)\n--\n\nInsert a memory breakpoint at a given address." + }, + { + "delete_mem_bp", py_binary_debugger_delete_mem_bp, + METH_VARARGS, + "delete_mem_bp($self, addr, /)\n--\n\nRemove a memory breakpoint at a given address." + }, + { + "restart", py_binary_debugger_restart, + METH_NOARGS, + "restart($self, /)\n--\n\nRestart the current debugging session." + }, + { + "resume", py_binary_debugger_resume, + METH_NOARGS, + "resume($self, /)\n--\n\nResume the current debugging session." + }, + { + "stepi", py_binary_debugger_stepi, + METH_NOARGS, + "stepi($self, /)\n--\n\nExecute one machine instruction, then stop and return to the debugger." + }, + { NULL } + }; + + static PyGetSetDef py_binary_debugger_getseters[] = { + { NULL } + }; + + static PyTypeObject py_binary_debugger_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.analysis.BinaryDebugger", + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + + .tp_doc = "PyChrysalide loaded binary", + + .tp_methods = py_binary_debugger_methods, + .tp_getset = py_binary_debugger_getseters + + }; + + return &py_binary_debugger_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.....BinaryDebugger'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_binary_debugger(PyObject *module) +{ + PyTypeObject *py_binary_debugger_type; /* Type Python 'BinaryDebugger'*/ + PyObject *dict; /* Dictionnaire du module */ + + py_binary_debugger_type = get_python_binary_debugger_type(); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_BINARY_DEBUGGER, py_binary_debugger_type, &PyGObject_Type)) + return false; + + return true; + +} diff --git a/plugins/pychrysalide/debug/debugger.h b/plugins/pychrysalide/debug/debugger.h new file mode 100644 index 0000000..97f91ac --- /dev/null +++ b/plugins/pychrysalide/debug/debugger.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * debugger.h - prototypes pour les instances Python de débogueurs + * + * Copyright (C) 2012-2017 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_DEBUG_DEBUGGER_H +#define _PLUGINS_PYCHRYSALIDE_DEBUG_DEBUGGER_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_binary_debugger_type(void); + +/* Prend en charge l'objet 'pychrysalide.debug.BinaryDebugger'. */ +bool register_python_binary_debugger(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_DEBUG_DEBUGGER_H */ diff --git a/plugins/pychrysalide/debug/gdbrsp/Makefile.am b/plugins/pychrysalide/debug/gdbrsp/Makefile.am new file mode 100644 index 0000000..cf7b78a --- /dev/null +++ b/plugins/pychrysalide/debug/gdbrsp/Makefile.am @@ -0,0 +1,15 @@ + +noinst_LTLIBRARIES = libpychrysadebuggdbrsp.la + +libpychrysadebuggdbrsp_la_SOURCES = \ + gdb.h gdb.c \ + module.h module.c + + +libpychrysadebuggdbrsp_la_LDFLAGS = + + +AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ + -I../../../../src + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) diff --git a/plugins/pychrysalide/debug/gdbrsp/gdb.c b/plugins/pychrysalide/debug/gdbrsp/gdb.c new file mode 100644 index 0000000..a4cde20 --- /dev/null +++ b/plugins/pychrysalide/debug/gdbrsp/gdb.c @@ -0,0 +1,166 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * gdb.c - équivalent Python du fichier "debug/gdbrsp/gdb.c" + * + * Copyright (C) 2016 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 "gdb.h" + + +#include + + +#include + + +#include + + +#include "../debugger.h" +#include "../../helpers.h" +#include "../../analysis/binary.h" + + + +/* Crée un nouvel objet Python de type 'GdbDebugger'. */ +static PyObject *py_gdb_debugger_new(PyTypeObject *, PyObject *, PyObject *); + + + +/****************************************************************************** +* * +* Paramètres : type = type de l'objet à instancier. * +* args = arguments fournis à l'appel. * +* kwds = arguments de type key=val fournis. * +* * +* Description : Crée un nouvel objet Python de type 'GdbDebugger'. * +* * +* Retour : Instance Python mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_gdb_debugger_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PyObject *result; /* Instance à retourner */ + PyObject *binary_obj; /* Objet pour le binaire lié */ + const char *server; /* Nom du serveur à contacter */ + unsigned short port; /* Port de connexion */ + int ret; /* Bilan de lecture des args. */ + GLoadedBinary *binary; /* Binaire chargé en mémoire */ + GBinaryDebugger *debugger; /* Création GLib à transmettre */ + + ret = PyArg_ParseTuple(args, "OsH", &binary_obj, &server, &port); + if (!ret) return NULL; + + ret = PyObject_IsInstance(binary_obj, (PyObject *)get_python_loaded_binary_type()); + if (!ret) + { + PyErr_SetString(PyExc_TypeError, _("The first argument must be an instance of LoadedBinary.")); + return NULL; + } + + binary = G_LOADED_BINARY(pygobject_get(binary_obj)); + + debugger = g_gdb_debugger_new(binary, server, port); + + result = pygobject_new(G_OBJECT(debugger)); + + g_object_unref(debugger); + + return (PyObject *)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_gdb_debugger_type(void) +{ + static PyMethodDef py_gdb_debugger_methods[] = { + { NULL } + }; + + static PyGetSetDef py_gdb_debugger_getseters[] = { + { NULL } + }; + + static PyTypeObject py_gdb_debugger_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.debug.gdbrsp.GdbDebugger", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT, + + .tp_doc = "PyChrysalide GDB debugger", + + .tp_methods = py_gdb_debugger_methods, + .tp_getset = py_gdb_debugger_getseters, + .tp_new = (newfunc)py_gdb_debugger_new + + }; + + return &py_gdb_debugger_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide....gdbrsp.GdbDebugger'.* +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_gdb_debugger(PyObject *module) +{ + PyTypeObject *py_gdb_debugger_type; /* Type Python 'GdbDebugger' */ + PyObject *dict; /* Dictionnaire du module */ + + py_gdb_debugger_type = get_python_gdb_debugger_type(); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_GDB_DEBUGGER, + py_gdb_debugger_type, get_python_binary_debugger_type())) + return false; + + return true; + +} diff --git a/plugins/pychrysalide/debug/gdbrsp/gdb.h b/plugins/pychrysalide/debug/gdbrsp/gdb.h new file mode 100644 index 0000000..00afab5 --- /dev/null +++ b/plugins/pychrysalide/debug/gdbrsp/gdb.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * gdb.h - prototypes pour l'équivalent Python du fichier "debug/gdbrsp/gdb.h" + * + * Copyright (C) 2016 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_DEBUG_GDBRSP_DEBUGGER_H +#define _PLUGINS_PYCHRYSALIDE_DEBUG_GDBRSP_DEBUGGER_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_gdb_debugger_type(void); + +/* Prend en charge l'objet 'pychrysalide.debug.gdbrsp.GdbDebugger'. */ +bool register_python_gdb_debugger(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_DEBUG_GDBRSP_DEBUGGER_H */ diff --git a/plugins/pychrysalide/debug/gdbrsp/module.c b/plugins/pychrysalide/debug/gdbrsp/module.c new file mode 100644 index 0000000..6e7896c --- /dev/null +++ b/plugins/pychrysalide/debug/gdbrsp/module.c @@ -0,0 +1,86 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.c - intégration du répertoire gdbrsp en tant que module + * + * Copyright (C) 2012 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 "module.h" + + +#include "gdb.h" + + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Ajoute le module 'debug.gdbrsp' au module Python. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool add_debug_gdbrsp_module_to_python_module(PyObject *super) +{ + bool result; /* Bilan à retourner */ + PyObject *module; /* Sous-module mis en place */ + int ret; /* Bilan d'un appel */ + + static PyModuleDef py_chrysalide_gdbrsp_module = { + + .m_base = PyModuleDef_HEAD_INIT, + + .m_name = "pychrysalide.debug.gdbrsp", + .m_doc = "Python module for Chrysalide.debug.gdbrsp", + + .m_size = -1, + + }; + + result = false; + + module = PyModule_Create(&py_chrysalide_gdbrsp_module); + if (module == NULL) return false; + + ret = PyState_AddModule(super, &py_chrysalide_gdbrsp_module); + if (ret != 0) goto loading_failed; + + ret = _PyImport_FixupBuiltin(module, "pychrysalide.debug.gdbrsp"); + if (ret != 0) goto loading_failed; + + Py_INCREF(module); + ret = PyModule_AddObject(super, "gdbrsp", module); + if (ret != 0) goto loading_failed; + + result = true; + + result &= register_python_gdb_debugger(module); + + loading_failed: + + assert(result); + + return result; + +} diff --git a/plugins/pychrysalide/debug/gdbrsp/module.h b/plugins/pychrysalide/debug/gdbrsp/module.h new file mode 100644 index 0000000..edc2b11 --- /dev/null +++ b/plugins/pychrysalide/debug/gdbrsp/module.h @@ -0,0 +1,39 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.h - prototypes pour l'intégration du répertoire gdbrsp en tant que module + * + * Copyright (C) 2012-2016 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_DEBUG_GDBRSP_MODULE_H +#define _PLUGINS_PYCHRYSALIDE_DEBUG_GDBRSP_MODULE_H + + +#include +#include + + + +/* Ajoute le module 'debug.gdbrsp' au module Python. */ +bool add_debug_gdbrsp_module_to_python_module(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_DEBUG_GDBRSP_MODULE_H */ diff --git a/plugins/pychrysalide/debug/module.c b/plugins/pychrysalide/debug/module.c new file mode 100644 index 0000000..ea586be --- /dev/null +++ b/plugins/pychrysalide/debug/module.c @@ -0,0 +1,93 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.c - intégration du répertoire debug en tant que module + * + * Copyright (C) 2012-2017 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 "module.h" + + +#include "debugger.h" +#include "gdbrsp/module.h" +#include "../access.h" + + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Ajoute le module 'debug' au module Python. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool add_debug_module_to_python_module(PyObject *super) +{ + bool result; /* Bilan à retourner */ + PyObject *module; /* Sous-module mis en place */ + int ret; /* Bilan d'un appel */ + + static PyModuleDef py_chrysalide_debug_module = { + + .m_base = PyModuleDef_HEAD_INIT, + + .m_name = "pychrysalide.debug", + .m_doc = "Python module for Chrysalide.debug", + + .m_size = -1, + + }; + + result = false; + + module = PyModule_Create(&py_chrysalide_debug_module); + if (module == NULL) return false; + + ret = PyState_AddModule(super, &py_chrysalide_debug_module); + if (ret != 0) goto loading_failed; + + ret = _PyImport_FixupBuiltin(module, "pychrysalide.debug"); + if (ret != 0) goto loading_failed; + + Py_INCREF(module); + ret = PyModule_AddObject(super, "debug", module); + if (ret != 0) goto loading_failed; + + result = true; + + result &= register_python_binary_debugger(module); + + result &= add_debug_gdbrsp_module_to_python_module(module); + + if (result) + register_access_to_python_module("pychrysalide.debug", module); + + loading_failed: + + assert(result); + + return result; + +} diff --git a/plugins/pychrysalide/debug/module.h b/plugins/pychrysalide/debug/module.h new file mode 100644 index 0000000..b723ab8 --- /dev/null +++ b/plugins/pychrysalide/debug/module.h @@ -0,0 +1,39 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.h - prototypes pour l'intégration du répertoire debug en tant que module + * + * Copyright (C) 2012-2017 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_DEBUG_MODULE_H +#define _PLUGINS_PYCHRYSALIDE_DEBUG_MODULE_H + + +#include +#include + + + +/* Ajoute le module 'debug' au module Python. */ +bool add_debug_module_to_python_module(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_DEBUG_MODULE_H */ diff --git a/plugins/pychrysalide/format/Makefile.am b/plugins/pychrysalide/format/Makefile.am new file mode 100644 index 0000000..325206c --- /dev/null +++ b/plugins/pychrysalide/format/Makefile.am @@ -0,0 +1,21 @@ + +noinst_LTLIBRARIES = libpychrysaformat.la + +libpychrysaformat_la_SOURCES = \ + executable.h executable.c \ + format.h format.c \ + module.h module.c \ + symbol.h symbol.c \ + symiter.h symiter.c + +libpychrysaformat_la_LIBADD = + +libpychrysaformat_la_LDFLAGS = + + +AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ + -I../../../src + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) + +SUBDIRS = diff --git a/plugins/pychrysalide/format/executable.c b/plugins/pychrysalide/format/executable.c new file mode 100644 index 0000000..1b1bfe8 --- /dev/null +++ b/plugins/pychrysalide/format/executable.c @@ -0,0 +1,215 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * executable.c - équivalent Python du fichier "format/executable.h" + * + * Copyright (C) 2012-2017 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 "executable.h" + + +#include + + +#include + + +#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 : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +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 } + }; + + static PyGetSetDef py_exe_format_getseters[] = { + { NULL } + }; + + static PyTypeObject py_exe_format_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.format.ExeFormat", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + + .tp_doc = "PyChrysalide executable format", + + .tp_methods = py_exe_format_methods, + .tp_getset = py_exe_format_getseters, + + }; + + return &py_exe_format_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.format.ExeFormat'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_executable_format(PyObject *module) +{ + PyTypeObject *py_exe_format_type; /* Type Python 'ExeFormat' */ + PyObject *dict; /* Dictionnaire du module */ + + py_exe_format_type = get_python_executable_format_type(); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_EXE_FORMAT, py_exe_format_type, get_python_binary_format_type())) + return false; + + return true; + +} diff --git a/plugins/pychrysalide/format/executable.h b/plugins/pychrysalide/format/executable.h new file mode 100644 index 0000000..2157b93 --- /dev/null +++ b/plugins/pychrysalide/format/executable.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * executable.h - prototypes pour l'équivalent Python du fichier "format/executable.h" + * + * Copyright (C) 2012-2017 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_EXECUTABLE_H +#define _PLUGINS_PYCHRYSALIDE_FORMAT_EXECUTABLE_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_executable_format_type(void); + +/* Prend en charge l'objet 'pychrysalide.format.ExeFormat'. */ +bool register_python_executable_format(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_FORMAT_EXECUTABLE_H */ diff --git a/plugins/pychrysalide/format/format.c b/plugins/pychrysalide/format/format.c new file mode 100644 index 0000000..3bfc705 --- /dev/null +++ b/plugins/pychrysalide/format/format.c @@ -0,0 +1,680 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * format.c - équivalent Python du fichier "format/format.c" + * + * Copyright (C) 2012-2017 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 "format.h" + + +#include + + +#include + + +#include "symbol.h" +#include "symiter.h" +#include "../helpers.h" +#include "../arch/vmpa.h" + + + +/* ---------------------------- FORMAT BINAIRE GENERIQUE ---------------------------- */ + + + +/* Ajoute un symbole à la collection du format binaire. */ +static PyObject *py_binary_format_add_symbol(PyObject *, PyObject *); + +/* Retire un symbole de la collection du format binaire. */ +static PyObject *py_binary_format_remove_symbol(PyObject *, PyObject *); + +/* Recherche le symbole correspondant à une étiquette. */ +static PyObject *py_binary_format_find_symbol_by_label(PyObject *, PyObject *); + +/* Recherche le symbole suivant celui lié à une adresse. */ +static PyObject *py_binary_format_find_symbol_at(PyObject *, PyObject *); + +/* Recherche le symbole suivant celui lié à une adresse. */ +static PyObject *py_binary_format_find_next_symbol_at(PyObject *, PyObject *); + +/* Recherche le symbole correspondant à une adresse. */ +static PyObject *py_binary_format_resolve_symbol(PyObject *, PyObject *); + +/* Fournit une référence vers le contenu binaire analysé. */ +static PyObject *py_binary_format_get_content(PyObject *, void *); + +/* Fournit la liste de tous les symboles détectés. */ +static PyObject *py_binary_format_get_symbols(PyObject *, void *); + + + +/* ------------------ CONSERVATION DES SOUCIS DURANT LE CHARGEMENT ------------------ */ + + +/* Etend la liste des soucis détectés avec de nouvelles infos. */ +static PyObject *py_binary_format_add_error(PyObject *, PyObject *); + +/* Fournit les éléments concernant tous les soucis détectés. */ +static PyObject *py_binary_format_get_errors(PyObject *, void *); + + + + + + +/* Définit les constantes pour les types d'erreurs. */ +static bool define_python_binary_format_constants(PyTypeObject *); + + + +/* ---------------------------------------------------------------------------------- */ +/* FORMAT BINAIRE GENERIQUE */ +/* ---------------------------------------------------------------------------------- */ + + + + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant un format. * +* args = arguments fournis à l'appel. * +* * +* Description : Ajoute un symbole à la collection du format binaire. * +* * +* Retour : True si le symbole était bien localisé et a été inséré. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_format_add_symbol(PyObject *self, PyObject *args) +{ + PyObject *result; /* Valeur à retourner */ + PyObject *symbol_obj; /* Version Python d'un symbole */ + int ret; /* Bilan de lecture des args. */ + GBinFormat *format; /* Format de binaire manipulé */ + GBinSymbol *symbol; /* Enventuel symbole trouvé */ + bool added; /* Bilan de l'appel interne */ + + ret = PyArg_ParseTuple(args, "O!", get_python_binary_symbol_type(), &symbol_obj); + if (!ret) return NULL; + + format = G_BIN_FORMAT(pygobject_get(self)); + symbol = G_BIN_SYMBOL(pygobject_get(symbol_obj)); + + added = g_binary_format_add_symbol(format, symbol); + + result = added ? Py_True : Py_False; + Py_INCREF(result); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant un format. * +* args = arguments fournis à l'appel. * +* * +* Description : Retire un symbole de la collection du format binaire. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_format_remove_symbol(PyObject *self, PyObject *args) +{ + PyObject *result; /* Valeur à retourner */ + PyObject *symbol_obj; /* Version Python d'un symbole */ + int ret; /* Bilan de lecture des args. */ + GBinFormat *format; /* Format de binaire manipulé */ + GBinSymbol *symbol; /* Enventuel symbole trouvé */ + + ret = PyArg_ParseTuple(args, "O!", get_python_binary_symbol_type(), &symbol_obj); + if (!ret) return NULL; + + format = G_BIN_FORMAT(pygobject_get(self)); + symbol = G_BIN_SYMBOL(pygobject_get(symbol_obj)); + + g_binary_format_remove_symbol(format, symbol); + + result = Py_None; + Py_INCREF(result); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant un binaire. * +* args = arguments fournis à l'appel. * +* * +* Description : Recherche le symbole correspondant à une étiquette. * +* * +* Retour : Symbol trouvé si l'opération a été un succès, None sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_format_find_symbol_by_label(PyObject *self, PyObject *args) +{ + PyObject *result; /* Valeur à retourner */ + PyObject *label; /* Etiquette à retrouver */ + int ret; /* Bilan de lecture des args. */ + GBinFormat *format; /* Format de binaire manipulé */ + GBinSymbol *symbol; /* Enventuel symbole trouvé */ + bool found; /* Bilan de la recherche */ + + ret = PyArg_ParseTuple(args, "O", &label); + if (!ret) return NULL; + + ret = PyUnicode_Check(label); + if (!ret) return NULL; + + format = G_BIN_FORMAT(pygobject_get(self)); + + found = g_binary_format_find_symbol_by_label(format, PyUnicode_DATA(label), &symbol); + + if (found) + result = pygobject_new(G_OBJECT(symbol)); + else + { + result = Py_None; + Py_INCREF(result); + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant un binaire. * +* args = arguments fournis à l'appel. * +* * +* Description : Recherche le symbole suivant celui lié à une adresse. * +* * +* Retour : Symbol trouvé si l'opération a été un succès, None sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_format_find_symbol_at(PyObject *self, PyObject *args) +{ + PyObject *result; /* Valeur à retourner */ + PyObject *py_vmpa; /* Localisation version Python */ + int ret; /* Bilan de lecture des args. */ + GBinFormat *format; /* Format de binaire manipulé */ + GBinSymbol *symbol; /* Enventuel symbole trouvé */ + bool found; /* Bilan de la recherche */ + + ret = PyArg_ParseTuple(args, "O", &py_vmpa); + if (!ret) return NULL; + + ret = PyObject_IsInstance(py_vmpa, (PyObject *)get_python_vmpa_type()); + if (!ret) return NULL; + + format = G_BIN_FORMAT(pygobject_get(self)); + + found = g_binary_format_find_symbol_at(format, get_internal_vmpa(py_vmpa), &symbol); + + if (found) + { + result = pygobject_new(G_OBJECT(symbol)); + g_object_unref(G_OBJECT(symbol)); + } + else + { + result = Py_None; + Py_INCREF(result); + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant un binaire. * +* args = arguments fournis à l'appel. * +* * +* Description : Recherche le symbole suivant celui lié à une adresse. * +* * +* Retour : Symbol trouvé si l'opération a été un succès, None sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_format_find_next_symbol_at(PyObject *self, PyObject *args) +{ + PyObject *result; /* Valeur à retourner */ + PyObject *py_vmpa; /* Localisation version Python */ + int ret; /* Bilan de lecture des args. */ + GBinFormat *format; /* Format de binaire manipulé */ + GBinSymbol *symbol; /* Enventuel symbole trouvé */ + bool found; /* Bilan de la recherche */ + + ret = PyArg_ParseTuple(args, "O", &py_vmpa); + if (!ret) return NULL; + + ret = PyObject_IsInstance(py_vmpa, (PyObject *)get_python_vmpa_type()); + if (!ret) return NULL; + + format = G_BIN_FORMAT(pygobject_get(self)); + + found = g_binary_format_find_next_symbol_at(format, get_internal_vmpa(py_vmpa), &symbol); + + if (found) + { + result = pygobject_new(G_OBJECT(symbol)); + g_object_unref(G_OBJECT(symbol)); + } + else + { + result = Py_None; + Py_INCREF(result); + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant un format binaire. * +* args = arguments fournis à l'appel. * +* * +* Description : Recherche le symbole correspondant à une adresse. * +* * +* Retour : Tuple (nom, décallage) ou Py_None. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_format_resolve_symbol(PyObject *self, PyObject *args) +{ + PyObject *result; /* Valeur à retourner */ + PyObject *py_vmpa; /* Localisation version Python */ + int strict; /* Tolérance acceptée */ + int ret; /* Bilan de lecture des args. */ + GBinFormat *format; /* Format de binaire manipulé */ + GBinSymbol *symbol; /* Enventuel symbole trouvé */ + phys_t diff; /* Décallage éventuel mesuré */ + bool found; /* Bilan de la recherche */ + + ret = PyArg_ParseTuple(args, "Op", &py_vmpa, &strict); + if (!ret) return NULL; + + ret = PyObject_IsInstance(py_vmpa, (PyObject *)get_python_vmpa_type()); + if (!ret) return NULL; + + format = G_BIN_FORMAT(pygobject_get(self)); + + found = g_binary_format_resolve_symbol(format, get_internal_vmpa(py_vmpa), strict, &symbol, &diff); + + if (found) + { + result = PyTuple_New(2); + PyTuple_SetItem(result, 0, pygobject_new(G_OBJECT(symbol))); + PyTuple_SetItem(result, 1, PyLong_FromUnsignedLongLong(diff)); + + g_object_unref(G_OBJECT(symbol)); + + } + else + { + result = Py_None; + Py_INCREF(result); + } + + 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_binary_format_get_content(PyObject *self, void *closure) +{ + PyObject *result; /* Trouvailles à retourner */ + GBinFormat *format; /* Format de binaire manipulé */ + GBinContent *content; /* Instance GLib correspondante*/ + + format = G_BIN_FORMAT(pygobject_get(self)); + + content = g_binary_format_get_content(format); + + result = pygobject_new(G_OBJECT(content)); + + g_object_unref(content); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant un format binaire. * +* closure = adresse non utilisée ici. * +* * +* Description : Fournit la liste de tous les symboles détectés. * +* * +* Retour : Tableau créé ou NULL si aucun symbole trouvé. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_format_get_symbols(PyObject *self, void *closure) +{ + PyObject *result; /* Instance Python à retourner */ + PyTypeObject *iterator_type; /* Type Python de l'itérateur */ + PyObject *args; /* Liste des arguments d'appel */ + + iterator_type = get_python_sym_iterator_type(); + + args = Py_BuildValue("On", self, 0); + + result = PyObject_CallObject((PyObject *)iterator_type, args); + + Py_DECREF(args); + + return result; + +} + + + +/* ---------------------------------------------------------------------------------- */ +/* CONSERVATION DES SOUCIS DURANT LE CHARGEMENT */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : self = architecture concernée par la procédure. * +* args = instruction représentant le point de départ. * +* * +* Description : Etend la liste des soucis détectés avec de nouvelles infos. * +* * +* Retour : None. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_format_add_error(PyObject *self, PyObject *args) +{ + BinaryFormatError type; /* Type d'erreur détectée */ + vmpa2t addr; /* Position d'une erreur */ + const char *desc; /* Description d'une erreur */ + int ret; /* Bilan de lecture des args. */ + GBinFormat *format; /* Format binaire manipulé */ + + ret = PyArg_ParseTuple(args, "IO&s", &type, convert_any_to_vmpa, &addr, &desc); + if (!ret) return NULL; + + format = G_BIN_FORMAT(pygobject_get(self)); + + g_binary_format_add_error(format, type, &addr, desc); + + Py_RETURN_NONE; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Fournit les éléments concernant tous les soucis détectés. * +* * +* Retour : Liste des erreurs relevées au niveau de l'assembleur. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_format_get_errors(PyObject *self, void *closure) +{ + PyObject *result; /* Instance Python à retourner */ + GBinFormat *format; /* Format binaire manipulé */ + size_t count; /* Nombre d'éléments à traiter */ + size_t i; /* Boucle de parcours */ +#ifndef NDEBUG + bool status; /* Bilan d'un appel */ +#endif + BinaryFormatError type; /* Type d'erreur détectée */ + vmpa2t addr; /* Position d'une erreur */ + char *desc; /* Description d'une erreur */ + PyObject *error; /* Nouvelle erreur à rajouter */ + + format = G_BIN_FORMAT(pygobject_get(self)); + + g_binary_format_lock_errors(format); + + count = g_binary_format_count_errors(format); + + result = PyTuple_New(count); + + for (i = 0; i < count; i++) + { +#ifndef NDEBUG + status = g_binary_format_get_error(format, i, &type, &addr, &desc); + assert(status); +#else + g_binary_format_get_error(format, i, &type, &addr, &desc); +#endif + + error = Py_BuildValue("IO&s", type, build_from_internal_vmpa, &addr, desc); + + PyTuple_SetItem(result, i, error); + + } + + g_binary_format_unlock_errors(format); + + return result; + +} + + + + + + + +/****************************************************************************** +* * +* Paramètres : obj_type = type dont le dictionnaire est à compléter. * +* * +* Description : Définit les constantes pour les types d'erreurs. * +* * +* Retour : true en cas de succès de l'opération, false sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool define_python_binary_format_constants(PyTypeObject *obj_type) +{ + bool result; /* Bilan à retourner */ + + result = true; + + result &= PyDict_AddIntMacro(obj_type, BFE_SPECIFICATION); + result &= PyDict_AddIntMacro(obj_type, BFE_STRUCTURE); + + 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_binary_format_type(void) +{ + static PyMethodDef py_bin_format_methods[] = { + { + "add_symbol", py_binary_format_add_symbol, + METH_VARARGS, + "add_symbol($self, symbol, /)\n--\n\nRegister a new symbol for the format." + }, + { + "remove_symbol", py_binary_format_remove_symbol, + METH_VARARGS, + "remove_symbol($self, symbol, /)\n--\n\nUnregister a symbol from the format." + }, + { + "find_symbol_by_label", py_binary_format_find_symbol_by_label, + METH_VARARGS, + "find_symbol_by_label($self, label, /)\n--\n\nFind a symbol by its label." + }, + { + "find_symbol_at", py_binary_format_find_symbol_at, + METH_VARARGS, + "find_symbol_at($self, addr, /)\n--\n\nFind a symbol at a given address." + }, + { + "find_next_symbol_at", py_binary_format_find_next_symbol_at, + METH_VARARGS, + "find_next_symbol_at($self, addr, /)\n--\n\nFind the symbol next to the one found at a given address." + }, + { + "resolve_symbol", py_binary_format_resolve_symbol, + METH_VARARGS, + "resolve_symbol($self, addr, strict, /)\n--\n\nSearch a position inside a routine by a given address." + }, + { + "add_error", py_binary_format_add_error, + METH_VARARGS, + "add_error($self, type, addr, desc, /)\n--\n\nExtend the list of detected disassembling errors." + }, + { NULL } + }; + + static PyGetSetDef py_bin_format_getseters[] = { + { + "content", py_binary_format_get_content, NULL, + "Content of the binary format.", NULL + }, + { + "symbols", py_binary_format_get_symbols, NULL, + "Iterable list of all symbols found in the binary format.", NULL + }, + { + "errors", py_binary_format_get_errors, NULL, + "List of all detected errors which occurred while loading the binary.", NULL + }, + { NULL } + }; + + static PyTypeObject py_bin_format_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.format.BinFormat", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_BASETYPE, + + .tp_doc = "PyChrysalide binary format", + + .tp_methods = py_bin_format_methods, + .tp_getset = py_bin_format_getseters + + }; + + return &py_bin_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 register_python_binary_format(PyObject *module) +{ + PyTypeObject *py_bin_format_type; /* Type Python 'BinFormat' */ + PyObject *dict; /* Dictionnaire du module */ + + py_bin_format_type = get_python_binary_format_type(); + + APPLY_ABSTRACT_FLAG(py_bin_format_type); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_BIN_FORMAT, py_bin_format_type, &PyGObject_Type)) + return false; + + if (!define_python_binary_format_constants(py_bin_format_type)) + return false; + + return true; + +} diff --git a/plugins/pychrysalide/format/format.h b/plugins/pychrysalide/format/format.h new file mode 100644 index 0000000..a8dfbf0 --- /dev/null +++ b/plugins/pychrysalide/format/format.h @@ -0,0 +1,56 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * format.h - prototypes pour l'équivalent Python du fichier "format/format.h" + * + * Copyright (C) 2012-2017 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_FORMAT_H +#define _PLUGINS_PYCHRYSALIDE_FORMAT_FORMAT_H + + +#include +#include + + + +/* ------------------------ PARCOURS DE SYMBOLES DE BINAIRES ------------------------ */ + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_binary_symbol_iterator_type(void); + +/* Prend en charge l'objet 'pychrysalide...BinSymbolIterator'. */ +bool register_python_binary_symbol_iterator(PyObject *); + + + +/* ---------------------------- FORMAT BINAIRE GENERIQUE ---------------------------- */ + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_binary_format_type(void); + +/* Prend en charge l'objet 'pychrysalide.format.BinFormat'. */ +bool register_python_binary_format(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_FORMAT_FORMAT_H */ diff --git a/plugins/pychrysalide/format/module.c b/plugins/pychrysalide/format/module.c new file mode 100644 index 0000000..1daeb3f --- /dev/null +++ b/plugins/pychrysalide/format/module.c @@ -0,0 +1,99 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.c - intégration du répertoire format en tant que module + * + * Copyright (C) 2012-2017 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 "module.h" + + +#include + + +#include "executable.h" +#include "format.h" +#include "symbol.h" +#include "symiter.h" +#include "../access.h" + + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Ajoute le module 'format' au module Python. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool add_format_module_to_python_module(PyObject *super) +{ + bool result; /* Bilan à retourner */ + PyObject *module; /* Sous-module mis en place */ + int ret; /* Bilan d'un appel */ + + static PyModuleDef py_chrysalide_format_module = { + + .m_base = PyModuleDef_HEAD_INIT, + + .m_name = "pychrysalide.format", + .m_doc = "Python module for Chrysalide.format", + + .m_size = -1, + + }; + + result = false; + + module = PyModule_Create(&py_chrysalide_format_module); + if (module == NULL) return false; + + ret = PyState_AddModule(super, &py_chrysalide_format_module); + if (ret != 0) goto loading_failed; + + ret = _PyImport_FixupBuiltin(module, "pychrysalide.format"); + if (ret != 0) goto loading_failed; + + Py_INCREF(module); + ret = PyModule_AddObject(super, "format", module); + if (ret != 0) goto loading_failed; + + result = true; + + result &= register_python_binary_format(module); + result &= register_python_executable_format(module); + result &= register_python_binary_symbol(module); + result &= register_python_sym_iterator(module); + + if (result) + register_access_to_python_module("pychrysalide.format", module); + + loading_failed: + + assert(result); + + return result; + +} diff --git a/plugins/pychrysalide/format/module.h b/plugins/pychrysalide/format/module.h new file mode 100644 index 0000000..0557722 --- /dev/null +++ b/plugins/pychrysalide/format/module.h @@ -0,0 +1,39 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.h - prototypes pour l'intégration du répertoire format en tant que module + * + * Copyright (C) 2012-2017 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_PYOIDA_FORMAT_MODULE_H +#define _PLUGINS_PYOIDA_FORMAT_MODULE_H + + +#include +#include + + + +/* Ajoute le module 'format' au module Python. */ +bool add_format_module_to_python_module(PyObject *); + + + +#endif /* _PLUGINS_PYOIDA_FORMAT_MODULE_H */ diff --git a/plugins/pychrysalide/format/symbol.c b/plugins/pychrysalide/format/symbol.c new file mode 100644 index 0000000..5ddaca2 --- /dev/null +++ b/plugins/pychrysalide/format/symbol.c @@ -0,0 +1,446 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * symbol.c - équivalent Python du fichier "format/symbol.h" + * + * Copyright (C) 2015-2017 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 "symbol.h" + + +#include + + +#include + + +#include + + +#include "../helpers.h" +#include "../analysis/routine.h" +#include "../analysis/db/items/comment.h" +#include "../arch/instruction.h" +#include "../arch/vmpa.h" + + + +/* 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 *); + +/* Fournit l'emplacement où se situe un symbole. */ +static PyObject *py_binary_symbol_get_range(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 *); + + + +/****************************************************************************** +* * +* Paramètres : a = premier object Python à consulter. * +* b = second object Python à consulter. * +* op = type de comparaison menée. * +* * +* Description : Effectue une comparaison avec un objet Python 'BinSymbol'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_symbol_richcompare(PyObject *a, PyObject *b, int op) +{ + PyObject *result; /* Bilan à retourner */ + int ret; /* Bilan de lecture des args. */ + const GBinSymbol *sym_a; /* Premier élément à traiter */ + const GBinSymbol *sym_b; /* Second élément à traiter */ + int status; /* Résultat d'une comparaison */ + + ret = PyObject_IsInstance(b, (PyObject *)get_python_binary_symbol_type()); + if (!ret) + { + result = Py_NotImplemented; + goto cmp_done; + } + + sym_a = G_BIN_SYMBOL(pygobject_get(a)); + sym_a = G_BIN_SYMBOL(pygobject_get(b)); + + status = g_binary_symbol_cmp(&sym_a, &sym_b); + + result = status_to_rich_cmp_state(status, op); + + cmp_done: + + Py_INCREF(result); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : type = type de l'objet à instancier. * +* args = arguments fournis à l'appel. * +* kwds = arguments de type key=val fournis. * +* * +* Description : Crée un nouvel objet Python de type 'DbComment'. * +* * +* Retour : Instance Python mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_symbol_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PyObject *result; /* Bilan à retourner */ + SymbolType stype; /* Type prévu pour le symbole */ + PyObject *range_obj; /* Objet pour la couverture */ + 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); + if (!ret) return NULL; + + if (stype >= STP_COUNT) + { + PyErr_SetString(PyExc_ValueError, _("Invalid type of symbol.")); + 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); + + result = pygobject_new(G_OBJECT(symbol)); + g_object_unref(symbol); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant un binaire. * +* args = arguments fournis à l'appel. * +* * +* Description : Définit un autre nom pour le symbole. * +* * +* Retour : None. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_symbol_set_alt_label(PyObject *self, PyObject *args) +{ + const char *alt; /* Etiquette alternative */ + int ret; /* Bilan de lecture des args. */ + GBinSymbol *symbol; /* Elément à consulter */ + + ret = PyArg_ParseTuple(args, "s", &alt); + if (!ret) return NULL; + + symbol = G_BIN_SYMBOL(pygobject_get(self)); + + g_binary_symbol_set_alt_label(symbol, alt); + + Py_RETURN_NONE; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Fournit le type du symbole. * +* * +* Retour : Type de symbole représenté. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_symbol_get_target_type(PyObject *self, void *closure) +{ + PyObject *result; /* Valeur à retourner */ + GBinSymbol *symbol; /* Elément à consulter */ + SymbolType type; /* Type de symbole représenté */ + + symbol = G_BIN_SYMBOL(pygobject_get(self)); + type = g_binary_symbol_get_target_type(symbol); + + result = PyLong_FromLong(type); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Fournit un étiquette pour viser un symbole. * +* * +* Retour : Chaîne de caractères renvoyant au symbole. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_symbol_get_label(PyObject *self, void *closure) +{ + PyObject *result; /* Valeur à retourner */ + GBinSymbol *symbol; /* Elément à consulter */ + const char *label; /* Désignation courante */ + + symbol = G_BIN_SYMBOL(pygobject_get(self)); + label = g_binary_symbol_get_label(symbol); + + if (label != NULL) + result = PyUnicode_FromString(label); + + else + { + result = Py_None; + Py_INCREF(result); + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Fournit l'emplacement où se situe un symbole. * +* * +* Retour : Zone mémoire couverte par le symbole. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_symbol_get_range(PyObject *self, void *closure) +{ + PyObject *result; /* Valeur à retourner */ + GBinSymbol *symbol; /* Elément à consulter */ + const mrange_t *range; /* Couverture courante */ + + symbol = G_BIN_SYMBOL(pygobject_get(self)); + range = g_binary_symbol_get_range(symbol); + + result = build_from_internal_mrange(range); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Fournit la visibilité du symbole. * +* * +* Retour : Etat de la visibilité du symbole représenté. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_binary_symbol_get_status(PyObject *self, void *closure) +{ + PyObject *result; /* Valeur à retourner */ + GBinSymbol *symbol; /* Elément à consulter */ + SymbolStatus status; /* Visibilité du symbole fourni*/ + + symbol = G_BIN_SYMBOL(pygobject_get(self)); + status = g_binary_symbol_get_status(symbol); + + result = PyLong_FromLong(status); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : obj_type = type dont le dictionnaire est à compléter. * +* * +* Description : Définit les constantes pour les symboles binaires. * +* * +* Retour : true en cas de succès de l'opération, false sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool py_binary_symbol_define_constants(PyTypeObject *obj_type) +{ + bool result; /* Bilan à retourner */ + + result = true; + + result &= PyDict_AddIntMacro(obj_type, STP_DATA); + result &= PyDict_AddIntMacro(obj_type, STP_ROUTINE); + result &= PyDict_AddIntMacro(obj_type, STP_CODE_LABEL); + result &= PyDict_AddIntMacro(obj_type, STP_OBJECT); + result &= PyDict_AddIntMacro(obj_type, STP_ENTRY_POINT); + result &= PyDict_AddIntMacro(obj_type, STP_STRING); + result &= PyDict_AddIntMacro(obj_type, STP_RO_STRING); + result &= PyDict_AddIntMacro(obj_type, STP_COUNT); + + 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_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, NULL, + "Range covered by the symbol.", NULL + }, + { + "status", py_binary_symbol_get_status, NULL, + "Status of the symbol's visibility.", NULL + }, + { NULL } + }; + + static PyTypeObject py_bin_symbol_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.format.BinSymbol", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + + .tp_doc = "PyChrysalide binary symbol", + + .tp_richcompare = py_binary_symbol_richcompare, + + .tp_methods = py_bin_symbol_methods, + .tp_getset = py_bin_symbol_getseters, + .tp_new = (newfunc)py_binary_symbol_new + + }; + + return &py_bin_symbol_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.format.BinSymbol'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_binary_symbol(PyObject *module) +{ + PyTypeObject *py_bin_symbol_type; /* Type Python 'BinSymbol' */ + PyObject *dict; /* Dictionnaire du module */ + + py_bin_symbol_type = get_python_binary_symbol_type(); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_BIN_SYMBOL, py_bin_symbol_type, &PyGObject_Type)) + return false; + + if (!py_binary_symbol_define_constants(py_bin_symbol_type)) + return false; + + return true; + +} diff --git a/plugins/pychrysalide/format/symbol.h b/plugins/pychrysalide/format/symbol.h new file mode 100644 index 0000000..913da74 --- /dev/null +++ b/plugins/pychrysalide/format/symbol.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * symbol.h - prototypes pour l'équivalent Python du fichier "format/symbol.h" + * + * Copyright (C) 2015-2017 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_SYMBOL_H +#define _PLUGINS_PYCHRYSALIDE_FORMAT_SYMBOL_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_binary_symbol_type(void); + +/* Prend en charge l'objet 'pychrysalide.format.BinSymbol'. */ +bool register_python_binary_symbol(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_FORMAT_EXECUTABLE_H */ diff --git a/plugins/pychrysalide/format/symiter.c b/plugins/pychrysalide/format/symiter.c new file mode 100644 index 0000000..db0b744 --- /dev/null +++ b/plugins/pychrysalide/format/symiter.c @@ -0,0 +1,276 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * symiter.c - équivalent Python du fichier "format/symiter.c" + * + * Copyright (C) 2017 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 "symiter.h" + + +#include + + +#include + + +#include "format.h" + + + +/* Transcription d'un itérateur en Python */ +typedef struct _PySymIterator +{ + PyObject_HEAD; /* A laisser en premier */ + + sym_iter_t *native; /* Version native de l'objet */ + bool first_time; /* Premier élément retourné ? */ + +} PySymIterator; + + +/* Libère de la mémoire un itérateur sur des symboles. */ +static void py_sym_iterator_dealloc(PySymIterator *); + +/* Fournit le symbole qui en suit un autr. */ +static PyObject *py_sym_iterator_next(PySymIterator *); + +/* Initialise un nouvel itérateur. */ +static int py_sym_iterator_init(PySymIterator *, PyObject *, PyObject *); + +/* Construit un nouvel itérateur. */ +static PyObject *py_sym_iterator_new(PyTypeObject *, PyObject *, PyObject *); + + + +/****************************************************************************** +* * +* Paramètres : self = itérateur à supprimer. * +* * +* Description : Libère de la mémoire un itérateur sur des symboles. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void py_sym_iterator_dealloc(PySymIterator *self) +{ + delete_symbol_iterator(self->native); + + Py_TYPE(self)->tp_free((PyObject *)self); + +} + + +/****************************************************************************** +* * +* Paramètres : self = itérateur à manipuler. * +* * +* Description : Fournit le symbole qui en suit un autre. * +* * +* Retour : Symbole suivant trouvé, ou NULL. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_sym_iterator_next(PySymIterator *self) +{ + PyObject *result; /* Résultat à retourner */ + GBinSymbol *next; /* Symbole suivant */ + + if (self->first_time) + { + next = get_symbol_iterator_current(self->native); + self->first_time = false; + } + + else + next = get_symbol_iterator_next(self->native); + + if (next != NULL) + { + result = pygobject_new(G_OBJECT(next)); + g_object_unref(G_OBJECT(next)); + } + + else + { + PyErr_SetNone(PyExc_StopIteration); + result = NULL; + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = instance d'objet à initialiser. * +* args = arguments passés pour l'appel. * +* kwds = mots clefs éventuellement fournis en complément. * +* * +* Description : Initialise un nouvel itérateur. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int py_sym_iterator_init(PySymIterator *self, PyObject *args, PyObject *kwds) +{ + int result; /* Bilan à retourner */ + PyObject *fmt_obj; /* Format version Python */ + unsigned long index; /* Indice de premier symbole */ + int ret; /* Bilan de lecture des args. */ + GBinFormat *format; /* Version native du format */ + + result = -1; + + ret = PyArg_ParseTuple(args, "Ok", &fmt_obj, &index); + if (ret == 0) goto psii_exit; + + ret = PyObject_IsInstance(fmt_obj, (PyObject *)get_python_binary_format_type()); + if (!ret) goto psii_exit; + + format = G_BIN_FORMAT(pygobject_get(fmt_obj)); + + self->native = create_symbol_iterator(format, index); + self->first_time = true; + + result = 0; + + psii_exit: + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : type = type d'objet à mettre en place. * +* args = arguments passés pour l'appel. * +* kwds = mots clefs éventuellement fournis en complément. * +* * +* Description : Construit un nouvel itérateur. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_sym_iterator_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PySymIterator *result; /* Nouvelle instance à renvoyer*/ + int ret; /* Bilan de l'initialisation */ + + result = (PySymIterator *)type->tp_alloc(type, 0); + + if (result != NULL) + { + ret = py_sym_iterator_init(result, args, kwds); + + if (ret != 0) + { + Py_DECREF(result); + result = NULL; + } + + } + + return (PyObject *)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_sym_iterator_type(void) +{ + static PyTypeObject py_sym_iterator_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.format.SymIterator", + .tp_basicsize = sizeof(PySymIterator), + + .tp_dealloc = (destructor)py_sym_iterator_dealloc, + + .tp_flags = Py_TPFLAGS_DEFAULT, + + .tp_doc = "Iterator for Chrysalide symbols registered in a given format.", + + .tp_iter = PyObject_SelfIter, + .tp_iternext = (iternextfunc)py_sym_iterator_next, + + .tp_init = (initproc)py_sym_iterator_init, + .tp_new = py_sym_iterator_new, + + }; + + return &py_sym_iterator_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.format.SymIterator'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_sym_iterator(PyObject *module) +{ + PyTypeObject *py_sym_iterator_type; /* Type Python 'BinContent' */ + int ret; /* Bilan d'un appel */ + + py_sym_iterator_type = get_python_sym_iterator_type(); + + if (PyType_Ready(py_sym_iterator_type) < 0) + return false; + + Py_INCREF(py_sym_iterator_type); + ret = PyModule_AddObject(module, "SymIterator", (PyObject *)py_sym_iterator_type); + + return (ret == 0); + +} diff --git a/plugins/pychrysalide/format/symiter.h b/plugins/pychrysalide/format/symiter.h new file mode 100644 index 0000000..6cc1d29 --- /dev/null +++ b/plugins/pychrysalide/format/symiter.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * symiter.h - prototypes pour l'équivalent Python du fichier "format/symiter.h" + * + * Copyright (C) 2017 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_SYMITER_H +#define _PLUGINS_PYCHRYSALIDE_FORMAT_SYMITER_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_sym_iterator_type(void); + +/* Prend en charge l'objet 'pychrysalide.format.SymIterator'. */ +bool register_python_sym_iterator(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_FORMAT_SYMITER_H */ diff --git a/plugins/pychrysalide/glibext/Makefile.am b/plugins/pychrysalide/glibext/Makefile.am new file mode 100644 index 0000000..e4d5243 --- /dev/null +++ b/plugins/pychrysalide/glibext/Makefile.am @@ -0,0 +1,19 @@ + +noinst_LTLIBRARIES = libpychrysaglibext.la + +libpychrysaglibext_la_SOURCES = \ + buffercache.h buffercache.c \ + bufferline.h bufferline.c \ + configuration.h configuration.c \ + linegen.h linegen.c \ + loadedpanel.h loadedpanel.c \ + module.h module.c + + +libpychrysaglibext_la_LDFLAGS = + + +AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ + -I../../../src + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) diff --git a/plugins/pychrysalide/glibext/buffercache.c b/plugins/pychrysalide/glibext/buffercache.c new file mode 100644 index 0000000..f61d34f --- /dev/null +++ b/plugins/pychrysalide/glibext/buffercache.c @@ -0,0 +1,165 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * buffercache.c - équivalent Python du fichier "glibext/gbuffercache.h" + * + * Copyright (C) 2016-2017 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 "buffercache.h" + + +#include + + +#include + + +#include "../arch/vmpa.h" +#include "../helpers.h" + + + +#if 0 +/* Retrouve une ligne au sein d'un tampon avec une adresse. */ +static PyObject *py_code_buffer_find_line_by_addr(PyObject *, PyObject *); + + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant un tampon de code. * +* args = arguments fournis à l'appel. * +* * +* Description : Retrouve une ligne au sein d'un tampon avec une adresse. * +* * +* Retour : Instance de la ligne trouvée. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_code_buffer_find_line_by_addr(PyObject *self, PyObject *args) +{ + PyObject *result; /* Trouvailles à retourner */ + PyObject *py_vmpa; /* Localisation version Python */ + int ret; /* Bilan de lecture des args. */ + vmpa2t *addr; /* Adresse visée par l'opérat° */ + GBuffercache *buffer; /* Version native */ + GBufferLine *line; /* Ligne trouvée */ + + ret = PyArg_ParseTuple(args, "O", &py_vmpa); + if (!ret) return NULL; + + ret = PyObject_IsInstance(py_vmpa, (PyObject *)get_python_vmpa_type()); + if (!ret) return NULL; + + addr = get_internal_vmpa(py_vmpa); + if (addr == NULL) return NULL; + + buffer = G_CODE_BUFFER(pygobject_get(self)); + + line = g_code_buffer_find_line_by_addr(buffer, addr, 0, NULL); + if (line == NULL) Py_RETURN_NONE; + + result = pygobject_new(G_OBJECT(line)); + + return result; + +} +#endif + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *get_python_buffer_cache_type(void) +{ + static PyMethodDef py_buffer_cache_methods[] = { +#if 0 + { + "find_line_by_addr", (PyCFunction)py_buffer_cache_find_line_by_addr, + METH_VARARGS, + "find_line_by_addr($self, addr, /)\n--\n\nFind a buffer line with a given address." + }, +#endif + { NULL } + }; + + static PyGetSetDef py_buffer_cache_getseters[] = { + { NULL } + }; + + static PyTypeObject py_buffer_cache_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.glibext.Buffercache", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT, + + .tp_doc = "PyChrysalide code buffer", + + .tp_methods = py_buffer_cache_methods, + .tp_getset = py_buffer_cache_getseters, + + }; + + return &py_buffer_cache_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.glibext.BufferCache'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_buffer_cache(PyObject *module) +{ + PyTypeObject *py_buffer_cache_type; /* Type Python 'BufferCache' */ + PyObject *dict; /* Dictionnaire du module */ + + py_buffer_cache_type = get_python_buffer_cache_type(); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_BUFFER_CACHE, py_buffer_cache_type, &PyGObject_Type)) + return false; + + return true; + +} diff --git a/plugins/pychrysalide/glibext/buffercache.h b/plugins/pychrysalide/glibext/buffercache.h new file mode 100644 index 0000000..dd41cfe --- /dev/null +++ b/plugins/pychrysalide/glibext/buffercache.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * buffercache.h - prototypes pour l'équivalent Python du fichier "glibext/buffercache.h" + * + * Copyright (C) 2016-2017 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_GLIBEXT_BUFFERCACHE_H +#define _PLUGINS_PYCHRYSALIDE_GLIBEXT_BUFFERCACHE_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_buffer_cache_type(void); + +/* Prend en charge l'objet 'pychrysalide.glibext.CodeBuffer'. */ +bool register_python_buffer_cache(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_GLIBEXT_BUFFERCACHE_H */ diff --git a/plugins/pychrysalide/glibext/bufferline.c b/plugins/pychrysalide/glibext/bufferline.c new file mode 100644 index 0000000..bfb894b --- /dev/null +++ b/plugins/pychrysalide/glibext/bufferline.c @@ -0,0 +1,373 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * bufferline.c - équivalent Python du fichier "glibext/gbufferline.h" + * + * Copyright (C) 2012-2017 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 "bufferline.h" + + +#include +#include + + +#include + + +#include + + +#include "../helpers.h" +#include "../arch/vmpa.h" + + + +/* Reconstruit et fournit le texte présent sur une ligne tampon. */ +static PyObject *py_buffer_line_get_text(PyObject *, PyObject *); + +/* Ajoute une propriété particulière à une ligne donnée. */ +static PyObject *py_buffer_line_add_flag(PyObject *, PyObject *); + +/* Retire une propriété particulière à une ligne donnée. */ +static PyObject *py_buffer_line_remove_flag(PyObject *, PyObject *); + +/* Fournit l'emplacement où se situe un symbole. */ +static PyObject *py_buffer_line_get_range(PyObject *, void *); + +/* Renseigne sur les propriétés particulières liées à une ligne. */ +static PyObject *py_buffer_line_get_flags(PyObject *, void *); + +/* Définit les constantes pour les lignes de tampon. */ +static bool py_buffer_line_define_constants(PyTypeObject *); + + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant une ligne de tampon. * +* args = arguments fournis à l'appel. * +* * +* Description : Reconstruit et fournit le texte présent sur une ligne tampon.* +* * +* Retour : Texte reconstruit pour l'occasion. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_buffer_line_get_text(PyObject *self, PyObject *args) +{ + PyObject *result; /* Trouvailles à retourner */ + BufferLineColumn first; /* Première colonne à parcourir*/ + BufferLineColumn end; /* Dernière colonne à parcourir*/ + int markup; /* Besoin de décorations ? */ + int ret; /* Bilan de lecture des args. */ + GBufferLine *line; /* Version native */ + char *text; /* Texte reconstruit à libérer */ + + ret = PyArg_ParseTuple(args, "IIp", &first, &end, &markup); + if (!ret) return NULL; + + if (first >= BLC_COUNT || end >= BLC_COUNT) + { + PyErr_SetString(PyExc_ValueError, _("Invalid range in arguments")); + return NULL; + } + + line = G_BUFFER_LINE(pygobject_get(self)); + text = g_buffer_line_get_text(line, first, end, markup); + + result = PyUnicode_FromString(text); + + free(text); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant une ligne de tampon. * +* args = arguments fournis à l'appel. * +* * +* Description : Ajoute une propriété particulière à une ligne donnée. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_buffer_line_add_flag(PyObject *self, PyObject *args) +{ + BufferLineFlags flag; /* Drapeau à considérer */ + int ret; /* Bilan de lecture des args. */ + GBufferLine *line; /* Version native */ + + ret = PyArg_ParseTuple(args, "I", &flag); + if (!ret) return NULL; + + if ((flag & ~BLF_ALL) != 0) + { + PyErr_SetString(PyExc_ValueError, _("Invalid flag")); + return NULL; + } + + line = G_BUFFER_LINE(pygobject_get(self)); + g_buffer_line_add_flag(line, flag); + + Py_RETURN_NONE; + +} + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant une ligne de tampon. * +* args = arguments fournis à l'appel. * +* * +* Description : Retire une propriété particulière à une ligne donnée. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_buffer_line_remove_flag(PyObject *self, PyObject *args) +{ + BufferLineFlags flag; /* Drapeau à considérer */ + int ret; /* Bilan de lecture des args. */ + GBufferLine *line; /* Version native */ + + ret = PyArg_ParseTuple(args, "I", &flag); + if (!ret) return NULL; + + if ((flag & ~BLF_ALL) != 0) + { + PyErr_SetString(PyExc_ValueError, _("Invalid flag")); + return NULL; + } + + line = G_BUFFER_LINE(pygobject_get(self)); + g_buffer_line_remove_flag(line, flag); + + Py_RETURN_NONE; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Indique la zone mémoire où se situe la ligne. * +* * +* Retour : Emplacement mémoire virtuel ou physique. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_buffer_line_get_range(PyObject *self, void *closure) +{ + PyObject *result; /* Valeur à retourner */ + GBufferLine *line; /* Elément à consulter */ + const mrange_t *range; /* Couverture courante */ + + line = G_BUFFER_LINE(pygobject_get(self)); + range = g_buffer_line_get_range(line); + + result = build_from_internal_mrange(range); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet Python concerné par l'appel. * +* closure = non utilisé ici. * +* * +* Description : Renseigne sur les propriétés particulières liées à une ligne.* +* * +* Retour : Propriétés intégrées. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_buffer_line_get_flags(PyObject *self, void *closure) +{ + PyObject *result; /* Valeur à retourner */ + GBufferLine *line; /* Elément à consulter */ + BufferLineFlags flags; /* Drapeaux à exporter */ + + line = G_BUFFER_LINE(pygobject_get(self)); + flags = g_buffer_line_get_flags(line); + + result = PyLong_FromLong(flags); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : obj_type = type dont le dictionnaire est à compléter. * +* * +* Description : Définit les constantes pour les lignes de tampon. * +* * +* Retour : true en cas de succès de l'opération, false sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool py_buffer_line_define_constants(PyTypeObject *obj_type) +{ + bool result; /* Bilan à retourner */ + + result = true; + + result &= PyDict_AddIntMacro(obj_type, BLC_PHYSICAL); + result &= PyDict_AddIntMacro(obj_type, BLC_VIRTUAL); + result &= PyDict_AddIntMacro(obj_type, BLC_BINARY); + result &= PyDict_AddIntMacro(obj_type, BLC_ASSEMBLY_HEAD); + result &= PyDict_AddIntMacro(obj_type, BLC_ASSEMBLY); + result &= PyDict_AddIntMacro(obj_type, BLC_COMMENTS); + result &= PyDict_AddIntMacro(obj_type, BLC_COUNT); + result &= PyDict_AddIntMacro(obj_type, BLC_LAST_USED); + result &= PyDict_AddIntMacro(obj_type, BLC_INVALID); + result &= PyDict_AddIntMacro(obj_type, BLC_MAIN); + result &= PyDict_AddIntMacro(obj_type, BLC_FIRST); + result &= PyDict_AddIntMacro(obj_type, BLC_DISPLAY); + + result &= PyDict_AddIntMacro(obj_type, BLF_NONE); + result &= PyDict_AddIntMacro(obj_type, BLF_HAS_CODE); + result &= PyDict_AddIntMacro(obj_type, BLF_ENTRYPOINT); + result &= PyDict_AddIntMacro(obj_type, BLF_BOOKMARK); + + 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_buffer_line_type(void) +{ + static PyMethodDef py_buffer_line_methods[] = { + { + "get_text", py_buffer_line_get_text, + METH_VARARGS, + "get_text($self, first_col, last_col, markup, /)\n--\n\nProvide the text of a buffer line." + }, + { + "add_flag", py_buffer_line_add_flag, + METH_VARARGS, + "add_flag($self, flag, /)\n--\n\nAdd a flag to the buffer line." + }, + { + "remove_flag", py_buffer_line_remove_flag, + METH_VARARGS, + "remove_flag($self, flag, /)\n--\n\nRemove a flag from the buffer line." + }, + { NULL } + }; + + static PyGetSetDef py_buffer_line_getseters[] = { + { + "range", py_buffer_line_get_range, NULL, + "Range covered by the line.", NULL + }, + { + "flags", py_buffer_line_get_flags, NULL, + "Current flags of the buffer line.", NULL + }, + { NULL } + }; + + static PyTypeObject py_buffer_line_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.glibext.BufferLine", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT, + + .tp_doc = "PyChrysalide buffer line", + + .tp_methods = py_buffer_line_methods, + .tp_getset = py_buffer_line_getseters, + + }; + + return &py_buffer_line_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.glibext.BufferLine'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_buffer_line(PyObject *module) +{ + PyTypeObject *py_buffer_line_type; /* Type Python 'BufferLine' */ + PyObject *dict; /* Dictionnaire du module */ + + py_buffer_line_type = get_python_buffer_line_type(); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_BUFFER_LINE, py_buffer_line_type, &PyGObject_Type)) + return false; + + if (!py_buffer_line_define_constants(py_buffer_line_type)) + return false; + + return true; + +} diff --git a/plugins/pychrysalide/glibext/bufferline.h b/plugins/pychrysalide/glibext/bufferline.h new file mode 100644 index 0000000..d905de3 --- /dev/null +++ b/plugins/pychrysalide/glibext/bufferline.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * bufferline.h - prototypes pour l'équivalent Python du fichier "glibext/bufferline.h" + * + * Copyright (C) 2012-2017 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_GLIBEXT_BUFFERLINE_H +#define _PLUGINS_PYCHRYSALIDE_GLIBEXT_BUFFERLINE_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_buffer_line_type(void); + +/* Prend en charge l'objet 'pychrysalide.glibext.BufferLine'. */ +bool register_python_buffer_line(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_GLIBEXT_BUFFERLINE_H */ diff --git a/plugins/pychrysalide/glibext/configuration.c b/plugins/pychrysalide/glibext/configuration.c new file mode 100644 index 0000000..a780f73 --- /dev/null +++ b/plugins/pychrysalide/glibext/configuration.c @@ -0,0 +1,1165 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * configuration.c - prototypes pour l'équivalent Python du fichier "glibext/configuration.c" + * + * Copyright (C) 2014-2017 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 "configuration.h" + + +#include + + +#include + + +#include "../helpers.h" + + + +/* ---------------------------- ELEMENT DE CONFIGURATION ---------------------------- */ + + +/* Crée un nouvel objet Python de type 'ConfigParam'. */ +static PyObject *py_config_param_new(PyTypeObject *, PyObject *, PyObject *); + +/* Efface toute valeur courante d'un paramètre de configuration. */ +static PyObject *py_config_param_make_empty(PyObject *, PyObject *); + +/* Réinitialise la valeur d'un paramètre de configuration. */ +static PyObject *py_config_param_reset(PyObject *, PyObject *); + +/* Indique le chemin d'accès utilisé pour un paramètre. */ +static PyObject *py_config_param_get_path(PyObject *, void *); + +/* Indique le type de valeur utilisée par un paramètre. */ +static PyObject *py_config_param_get_type(PyObject *, void *); + +/* Indique le statut d'une valeur utilisée par un paramètre. */ +static PyObject *py_config_param_get_state(PyObject *, void *); + +/* Indique la valeur courante d'un paramètre de configuration. */ +static PyObject *py_config_param_get_value(PyObject *, void *); + +/* Modifie la valeur courante d'un paramètre de configuration. */ +static int py_config_param_set_value(PyObject *, PyObject *, void *); + +/* Définit les constantes pour les paramètres. */ +static bool py_config_param_define_constants(PyObject *); + + + +/* ----------------------------- PARCOURS DE PARAMETRES ----------------------------- */ + + +/* Parcours des éléments de configuration */ +typedef struct _pyConfigParamIterator +{ + PyObject_HEAD /* A laisser en premier */ + + GGenConfig *config; /* Configuration à parcourir */ + GList *params; /* Liste de paramètres */ + + GList *last; /* Dernier élément retourné */ + +} pyConfigParamIterator; + + +/* Prend acte d'un compteur de référence à 0. */ +static void py_config_param_iterator_dealloc(PyObject *); + +/* Fournit un itérateur pour paramètres de configuration. */ +static PyObject *py_config_param_iterator_next(PyObject *); + +/* Initialise un objet Python de type 'ConfigParamIterator'. */ +static int py_config_param_iterator_init(PyObject *, PyObject *, PyObject *); + + + +/* ----------------------- GESTION GENERIQUE DE CONFIGURATION ----------------------- */ + + +/* Crée un nouvel objet Python de type 'GenConfig'. */ +static PyObject *py_generic_config_new(PyTypeObject *, PyObject *, PyObject *); + +/* Lit la configuration depuis un fichier. */ +static PyObject *py_generic_config_read(PyObject *, PyObject *); + +/* Ecrit la configuration dans un fichier. */ +static PyObject *py_generic_config_write(PyObject *, PyObject *); + +/* Retrouve un élément de configuration par son chemin. */ +static PyObject *py_generic_config_search(PyObject *, PyObject *); + +/* Ajoute un paramètre à une configuration. */ +static PyObject *py_generic_config_add(PyObject *, PyObject *); + +/* Retire un paramètre d'une configuration. */ +static PyObject *py_generic_config_delete(PyObject *, PyObject *); + +/* Fournit le chemin d'accès au binaire représenté. */ +static PyObject *py_generic_config_get_filename(PyObject *, void *); + + + +/* ---------------------------------------------------------------------------------- */ +/* ELEMENT DE CONFIGURATION */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : type = type de l'objet à instancier. * +* args = arguments fournis à l'appel. * +* kwds = arguments de type key=val fournis. * +* * +* Description : Crée un nouvel objet Python de type 'ConfigParam'. * +* * +* Retour : Instance Python mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_config_param_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PyObject *result; /* Instance à retourner */ + const char *path; /* Accès au paramètre */ + unsigned int ptype; /* Type de paramètre */ + PyObject *value; /* Valeur par défaut éventuelle*/ + int ret; /* Bilan de lecture des args. */ + GCfgParam *param; /* Paramètre mis en place */ + + value = NULL; + + ret = PyArg_ParseTuple(args, "sI|O", &path, &ptype, &value); + if (!ret) Py_RETURN_NONE; + + if (value == NULL || value == Py_None) + param = g_config_param_new_empty(path, ptype); + + else + switch (ptype) + { + case CPT_BOOLEAN: + if (PyBool_Check(value)) + param = g_config_param_new(path, CPT_BOOLEAN, (bool)(value == Py_True)); + else + param = NULL; + break; + + case CPT_INTEGER: + if (PyLong_Check(value)) + param = g_config_param_new(path, CPT_INTEGER, (int)PyLong_AsLong(value)); + else + param = NULL; + break; + + case CPT_STRING: + if (PyUnicode_Check(value)) + param = g_config_param_new(path, CPT_STRING, PyUnicode_DATA(value)); + else + param = NULL; + break; + + default: + param = NULL; + break; + + } + + if (param != NULL) + { + result = pygobject_new(G_OBJECT(param)); + g_object_unref(param); + } + else result = NULL; + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = paramètre de configuration à manipuler. * +* args = non utilisé ici. * +* * +* Description : Efface toute valeur courante d'un paramètre de configuration.* +* * +* Retour : None. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_config_param_make_empty(PyObject *self, PyObject *args) +{ + GCfgParam *param; /* Paramètre visé par l'opérat°*/ + + param = G_CFG_PARAM(pygobject_get(self)); + + g_config_param_make_empty(param); + + Py_RETURN_NONE; + +} + + +/****************************************************************************** +* * +* Paramètres : self = paramètre de configuration à manipuler. * +* args = non utilisé ici. * +* * +* Description : Réinitialise la valeur d'un paramètre de configuration. * +* * +* Retour : None. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_config_param_reset(PyObject *self, PyObject *args) +{ + GCfgParam *param; /* Paramètre visé par l'opérat°*/ + + param = G_CFG_PARAM(pygobject_get(self)); + + g_config_param_reset(param); + + Py_RETURN_NONE; + +} + + +/****************************************************************************** +* * +* Paramètres : self = paramètre de configuration à manipuler. * +* closure = non utilisé ici. * +* * +* Description : Indique le chemin d'accès utilisé pour un paramètre. * +* * +* Retour : Chemin d'accès en Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_config_param_get_path(PyObject *self, void *closure) +{ + GCfgParam *param; /* Paramètre visé par l'opérat°*/ + const char *path; /* Chemin d'accès à diffuser */ + + param = G_CFG_PARAM(pygobject_get(self)); + path = g_config_param_get_path(param); + + return PyUnicode_FromString(path); + +} + + +/****************************************************************************** +* * +* Paramètres : self = paramètre de configuration à manipuler. * +* closure = non utilisé ici. * +* * +* Description : Indique le type de valeur utilisée par un paramètre. * +* * +* Retour : Type en Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_config_param_get_type(PyObject *self, void *closure) +{ + GCfgParam *param; /* Paramètre visé par l'opérat°*/ + ConfigParamType type; /* Type de paramètre */ + + param = G_CFG_PARAM(pygobject_get(self)); + type = g_config_param_get_ptype(param); + + return PyLong_FromLong(type); + +} + + +/****************************************************************************** +* * +* Paramètres : self = paramètre de configuration à manipuler. * +* closure = non utilisé ici. * +* * +* Description : Indique le statut d'une valeur utilisée par un paramètre. * +* * +* Retour : Etat en Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_config_param_get_state(PyObject *self, void *closure) +{ + GCfgParam *param; /* Paramètre visé par l'opérat°*/ + ConfigParamState state; /* Statut de paramètre */ + + param = G_CFG_PARAM(pygobject_get(self)); + state = g_config_param_get_state(param); + + return PyLong_FromLong(state); + +} + + +/****************************************************************************** +* * +* Paramètres : self = paramètre de configuration à manipuler. * +* closure = non utilisé ici. * +* * +* Description : Indique la valeur courante d'un paramètre de configuration. * +* * +* Retour : Etat en Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_config_param_get_value(PyObject *self, void *closure) +{ + PyObject *result; /* Valeur à retourner */ + GCfgParam *param; /* Paramètre visé par l'opérat°*/ + ConfigParamType type; /* Type de paramètre manipulé */ + bool boolean; /* Valeur booléenne */ + int integer; /* Valeur entière */ + char *string; /* Chaîne de caractères */ + + param = G_CFG_PARAM(pygobject_get(self)); + type = g_config_param_get_ptype(param); + + switch (type) + { + case CPT_BOOLEAN: + g_config_param_get_value(param, &boolean); + result = (boolean ? Py_True : Py_False); + Py_INCREF(result); + break; + + case CPT_INTEGER: + g_config_param_get_value(param, &integer); + result = PyLong_FromLong(integer); + break; + + case CPT_STRING: + g_config_param_get_value(param, &string); + if (string != NULL) + result = PyUnicode_FromString(string); + else + { + result = Py_None; + Py_INCREF(result); + } + break; + + default: + result = NULL; + break; + + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = paramètre de configuration à manipuler. * +* value = nouvelle valeur à convertir et définir. * +* closure = non utilisé ici. * +* * +* Description : Modifie la valeur courante d'un paramètre de configuration. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int py_config_param_set_value(PyObject *self, PyObject *value, void *closure) +{ + int result; /* Conclusion à remonter */ + GCfgParam *param; /* Paramètre visé par l'opérat°*/ + ConfigParamType type; /* Type de paramètre manipulé */ + + result = -1; + + param = G_CFG_PARAM(pygobject_get(self)); + + if (value == Py_None) + { + g_config_param_make_empty(param); + result = 0; + } + + else + { + type = g_config_param_get_ptype(param); + + switch (type) + { + case CPT_BOOLEAN: + if (PyBool_Check(value)) + { + g_config_param_set_value(param, (bool)(value == Py_True)); + result = 0; + } + break; + + case CPT_INTEGER: + if (PyLong_Check(value)) + { + g_config_param_set_value(param, (int)PyLong_AsLong(value)); + result = 0; + } + break; + + case CPT_STRING: + if (PyUnicode_Check(value)) + { + g_config_param_set_value(param, PyUnicode_DATA(value)); + result = 0; + } + break; + + default: + break; + + } + + } + + 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_config_param_type(void) +{ + static PyMethodDef py_config_param_methods[] = { + { "make_empty", py_config_param_make_empty, + METH_NOARGS, + "Unset the value of the current parameter." + }, + { "reset", py_config_param_reset, + METH_NOARGS, + "Reset the content of the current parameter." + }, + { NULL } + }; + + static PyGetSetDef py_config_param_getseters[] = { + { + "path", py_config_param_get_path, NULL, + "Show the path used as key for a configuration parameter.", NULL + }, + { + "type", py_config_param_get_type, NULL, + "Show the type of value provided by a configuration parameter.", NULL + }, + { + "state", py_config_param_get_state, NULL, + "Show the state of a configuration parameter.", NULL + }, + { + "value", py_config_param_get_value, py_config_param_set_value, + "Handle the value of a configuration parameter.", NULL + }, + { NULL } + }; + + static PyTypeObject py_config_param_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.glibext.ConfigParam", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT, + + .tp_doc = "PyChrysalide generic configuration", + + .tp_methods = py_config_param_methods, + .tp_getset = py_config_param_getseters, + .tp_new = (newfunc)py_config_param_new + + }; + + return &py_config_param_type; + +} + + +/****************************************************************************** +* * +* Paramètres : dict = dictionnaire à compléter. * +* * +* Description : Définit les constantes pour les paramètres. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool py_config_param_define_constants(PyObject *dict) +{ + int ret; /* Bilan d'un ajout */ + +#define DEF_ULONG_CONST(name) \ + ret = PyDict_SetItemString(dict, #name, PyLong_FromUnsignedLong(name)); \ + if (ret == -1) return false; + + DEF_ULONG_CONST(CPT_BOOLEAN); + DEF_ULONG_CONST(CPT_INTEGER); + DEF_ULONG_CONST(CPT_STRING); + DEF_ULONG_CONST(CPT_COUNT); + + DEF_ULONG_CONST(CPS_UNDEFINED); + DEF_ULONG_CONST(CPS_CHANGED); + DEF_ULONG_CONST(CPS_DEFAULT); + DEF_ULONG_CONST(CPS_EMPTY); + + return true; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.glibext.ConfigParam'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_config_param(PyObject *module) +{ + PyTypeObject *py_config_param_type; /* Type Python 'ConfigParam' */ + PyObject *dict; /* Dictionnaire du module */ + + py_config_param_type = get_python_config_param_type(); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_CFG_PARAM, py_config_param_type, &PyGObject_Type)) + return false; + + if (!py_config_param_define_constants(py_config_param_type->tp_dict)) + return false; + + return true; + +} + + + +/* ---------------------------------------------------------------------------------- */ +/* PARCOURS DE PARAMETRES */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : self = instance Python à libérer de la mémoire. * +* * +* Description : Prend acte d'un compteur de référence à 0. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void py_config_param_iterator_dealloc(PyObject *self) +{ + pyConfigParamIterator *iterator; /* Références pour le parcours */ + + /** + * Il aurait été sans doute mieux de reposer ici sur .tp_finalize, + * mais cela semble impliquer de mettre en place tous les mécanismes de GC... + * + * cf. https://docs.python.org/3/extending/newtypes.html#finalization-and-de-allocation + */ + + iterator = (pyConfigParamIterator *)self; + + g_generic_config_runlock(iterator->config); + g_object_unref(G_OBJECT(iterator->config)); + + Py_TYPE(self)->tp_free((PyObject *)self); + +} + + +/****************************************************************************** +* * +* Paramètres : self = itérateur à manipuler. * +* * +* Description : Fournit un itérateur pour paramètres de configuration. * +* * +* Retour : Instance Python prête à emploi. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_config_param_iterator_next(PyObject *self) +{ + PyObject *result; /* Instance à retourner */ + pyConfigParamIterator *iterator; /* Références pour le parcours */ + GList *item; /* Nouvel élément courant */ + + iterator = (pyConfigParamIterator *)self; + + if (iterator->last == NULL) item = iterator->params; + else item = g_list_next(iterator->last); + + iterator->last = item; + + if (item != NULL) + { + result = pygobject_new(G_OBJECT(item->data)); + Py_INCREF(result); + } + else + { + PyErr_SetNone(PyExc_StopIteration); + result = NULL; + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = objet instancié à initialiser. * +* args = arguments fournis à l'appel. * +* kwds = arguments de type key=val fournis. * +* * +* Description : Initialise un objet Python de type 'ConfigParamIterator'. * +* * +* Retour : Instance Python mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int py_config_param_iterator_init(PyObject *self, PyObject *args, PyObject *kwds) +{ + pyConfigParamIterator *iterator; /* Références pour le parcours */ + PyObject *config; /* Configuration format Python */ + int ret; /* Bilan de lecture des args. */ + + ret = PyArg_ParseTuple(args, "O", &config); + if (!ret) return -1; + + ret = PyObject_IsInstance(config, (PyObject *)get_python_generic_config_type()); + if (!ret) return -1; + + iterator = (pyConfigParamIterator *)self; + + iterator->config = G_GEN_CONFIG(pygobject_get(config)); + g_object_ref(G_OBJECT(iterator->config)); + + g_generic_config_rlock(iterator->config); + + iterator->params = g_generic_config_list_params(iterator->config); + + iterator->last = NULL; + + return 0; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *get_python_config_param_iterator_type(void) +{ + static PyTypeObject py_config_param_iterator_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.glibext.ConfigParamIterator", + .tp_basicsize = sizeof(pyConfigParamIterator), + + .tp_dealloc = py_config_param_iterator_dealloc, + + .tp_flags = Py_TPFLAGS_DEFAULT, + + .tp_doc = "Iterator for configuration parameters", + + .tp_iter = PyObject_SelfIter, + .tp_iternext = py_config_param_iterator_next, + + .tp_init = py_config_param_iterator_init, + + .tp_new = PyType_GenericNew, + + }; + + return &py_config_param_iterator_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide...ConfigParamIterator'.* +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_config_param_iterator(PyObject *module) +{ + PyTypeObject *py_config_param_iterator_type;/* Type Python 'Cnf...Iter'*/ + int ret; /* Bilan d'un appel */ + + py_config_param_iterator_type = get_python_config_param_iterator_type(); + + py_config_param_iterator_type->tp_base = &PyBaseObject_Type; + + if (PyType_Ready(py_config_param_iterator_type) != 0) + return false; + + Py_INCREF(py_config_param_iterator_type); + ret = PyModule_AddObject(module, "ConfigParamIterator", (PyObject *)py_config_param_iterator_type); + if (ret != 0) return false; + + return true; + +} + + + +/* ---------------------------------------------------------------------------------- */ +/* GESTION GENERIQUE DE CONFIGURATION */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : type = type de l'objet à instancier. * +* args = arguments fournis à l'appel. * +* kwds = arguments de type key=val fournis. * +* * +* Description : Crée un nouvel objet Python de type 'GenConfig'. * +* * +* Retour : Instance Python mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_generic_config_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + PyObject *result; /* Instance à retourner */ + const char *name; /* Nom du fichier à charger */ + int ret; /* Bilan de lecture des args. */ + GGenConfig *config; /* Version GLib du format */ + + ret = PyArg_ParseTuple(args, "s", &name); + if (!ret) Py_RETURN_NONE; + + config = g_generic_config_new(name); + + result = pygobject_new(G_OBJECT(config)); + g_object_unref(config); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = configuration à manipuler. * +* args = non utilisé ici. * +* * +* Description : Lit la configuration depuis un fichier. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_generic_config_read(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GGenConfig *config; /* Version GLib du format */ + bool status; /* Bilan de l'opération */ + + config = G_GEN_CONFIG(pygobject_get(self)); + + status = g_generic_config_read(config); + + result = status ? Py_True : Py_False; + Py_INCREF(result); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = configuration à manipuler. * +* args = non utilisé ici. * +* * +* Description : Ecrit la configuration dans un fichier. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_generic_config_write(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GGenConfig *config; /* Version GLib du format */ + bool status; /* Bilan de l'opération */ + + config = G_GEN_CONFIG(pygobject_get(self)); + + status = g_generic_config_write(config); + + result = status ? Py_True : Py_False; + Py_INCREF(result); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = configuration à manipuler. * +* args = indication sur l'élément à retrouver. * +* * +* Description : Retrouve un élément de configuration par son chemin. * +* * +* Retour : Elément trouvé ou NULL en cas d'échec. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_generic_config_search(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GGenConfig *config; /* Version GLib du format */ + const char *path; /* Chemin d'accès du paramètre */ + int ret; /* Bilan de lecture des args. */ + GCfgParam *param; /* Paramètre trouvé ou NULL */ + + config = G_GEN_CONFIG(pygobject_get(self)); + + ret = PyArg_ParseTuple(args, "s", &path); + if (!ret) Py_RETURN_NONE; + + param = g_generic_config_search(config, path); + + result = pygobject_new(G_OBJECT(param)); + Py_XINCREF(result); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = configuration à manipuler. * +* args = indication sur l'élément à retrouver. * +* * +* Description : Ajoute un paramètre à une configuration. * +* * +* Retour : Elément ajouté ou NULL en cas d'échec. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_generic_config_add(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + GGenConfig *config; /* Version GLib du format */ + PyObject *param; /* Paramètre transmis */ + int ret; /* Bilan de lecture des args. */ + GCfgParam *added; /* Elément ajouté ou NULL */ + + config = G_GEN_CONFIG(pygobject_get(self)); + + ret = PyArg_ParseTuple(args, "O", ¶m); + if (!ret) Py_RETURN_NONE; + + ret = PyObject_IsInstance(param, (PyObject *)get_python_config_param_type()); + if (!ret) Py_RETURN_NONE; + + added = g_generic_config_add_param(config, G_CFG_PARAM(pygobject_get(param))); + + if (added != NULL) + { + result = pygobject_new(G_OBJECT(added)); + Py_XINCREF(result); + } + else + result = NULL; + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = configuration à manipuler. * +* args = indication sur l'élément à retrouver. * +* * +* Description : Retire un paramètre d'une configuration. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_generic_config_delete(PyObject *self, PyObject *args) +{ + GGenConfig *config; /* Version GLib du format */ + const char *path; /* Chemin d'accès du paramètre */ + int ret; /* Bilan de lecture des args. */ + + config = G_GEN_CONFIG(pygobject_get(self)); + + ret = PyArg_ParseTuple(args, "s", &path); + if (!ret) Py_RETURN_NONE; + + g_generic_config_delete_param(config, path); + + Py_RETURN_NONE; + +} + + +/****************************************************************************** +* * +* Paramètres : self = configuration à manipuler. * +* args = non utilisé ici. * +* * +* Description : Renvoie la liste des paramètres de configuration. * +* * +* Retour : Itérateur pour la liste des paramètres. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_generic_config_list_params(PyObject *self, PyObject *args) +{ + PyObject *result; /* Instance à retourner */ + PyTypeObject *iterator_type; /* Type Python de l'itérateur */ + PyObject *args_list; /* Arguments de mise en place */ + + iterator_type = get_python_config_param_iterator_type(); + + Py_INCREF(self); + + args_list = Py_BuildValue("(O)", self); + result = PyObject_CallObject((PyObject *)iterator_type, args_list); + + Py_DECREF(args_list); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = NULL car méthode statique. * +* closure = non utilisé ici. * +* * +* Description : Fournit le chemin d'accès au binaire représenté. * +* * +* Retour : Chemin d'accès en Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_generic_config_get_filename(PyObject *self, void *closure) +{ + GGenConfig *config; /* Version GLib du format */ + const char *filename; /* Chemin d'accès au fichier */ + + config = G_GEN_CONFIG(pygobject_get(self)); + + filename = g_generic_config_get_filename(config); + + return PyUnicode_FromString(filename); + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *get_python_generic_config_type(void) +{ + static PyMethodDef py_generic_config_methods[] = { + { "read", py_generic_config_read, + METH_NOARGS, + "Read the configuration from its relative XML file." + }, + { "write", py_generic_config_write, + METH_NOARGS, + "Write the configuration to its relative XML file." + }, + { "search", py_generic_config_search, + METH_VARARGS, + "Look for a given configuration parameter." + }, + { "add", py_generic_config_add, + METH_VARARGS, + "Add an existing parameter to a configuration." + }, + { "delete", py_generic_config_delete, + METH_VARARGS, + "Delete an existing parameter from a configuration." + }, + { "params", py_generic_config_list_params, + METH_NOARGS, + "List all registered configuration parameters." + }, + { NULL } + }; + + static PyGetSetDef py_generic_config_getseters[] = { + { + "filename", py_generic_config_get_filename, NULL, + "Show the filename of the loaded binary file.", NULL + }, + { NULL } + }; + + static PyTypeObject py_generic_config_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.glibext.GenConfig", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT, + + .tp_doc = "PyChrysalide generic configuration", + + .tp_methods = py_generic_config_methods, + .tp_getset = py_generic_config_getseters, + .tp_new = (newfunc)py_generic_config_new + + }; + + return &py_generic_config_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.glibext.GenConfig'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_generic_config(PyObject *module) +{ + PyTypeObject *py_generic_config_type; /* Type Python 'GenConfig' */ + PyObject *dict; /* Dictionnaire du module */ + + py_generic_config_type = get_python_generic_config_type(); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_GEN_CONFIG, py_generic_config_type, &PyGObject_Type)) + return false; + + return true; + +} diff --git a/plugins/pychrysalide/glibext/configuration.h b/plugins/pychrysalide/glibext/configuration.h new file mode 100644 index 0000000..a34d8c2 --- /dev/null +++ b/plugins/pychrysalide/glibext/configuration.h @@ -0,0 +1,66 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * configuration.h - prototypes pour l'équivalent Python du fichier "glibext/configuration.h" + * + * Copyright (C) 2014-2017 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_GLIBEXT_CONFIGURATION_H +#define _PLUGINS_PYCHRYSALIDE_GLIBEXT_CONFIGURATION_H + + +#include +#include + + + +/* ---------------------------- ELEMENT DE CONFIGURATION ---------------------------- */ + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_config_param_type(void); + +/* Prend en charge l'objet 'pychrysalide.glibext.ConfigParam'. */ +bool register_python_config_param(PyObject *); + + + +/* ----------------------------- PARCOURS DE PARAMETRES ----------------------------- */ + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_config_param_iterator_type(void); + +/* Prend en charge l'objet 'pychrysalide.glibext.ConfigParamIterator'. */ +bool register_python_config_param_iterator(PyObject *); + + +/* ----------------------- GESTION GENERIQUE DE CONFIGURATION ----------------------- */ + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_generic_config_type(void); + +/* Prend en charge l'objet 'pychrysalide.glibext.GenConfig'. */ +bool register_python_generic_config(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_GLIBEXT_CONFIGURATION_H */ diff --git a/plugins/pychrysalide/glibext/linegen.c b/plugins/pychrysalide/glibext/linegen.c new file mode 100644 index 0000000..b6aad6b --- /dev/null +++ b/plugins/pychrysalide/glibext/linegen.c @@ -0,0 +1,404 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * linegen.c - équivalent Python du fichier "glibext/linegen.h" + * + * Copyright (C) 2017 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 "linegen.h" + + +#include + + +#include +#include + + +#include "../helpers.h" +#include "../analysis/content.h" +#include "../arch/vmpa.h" +#include "../glibext/bufferline.h" + + + +/* Indique le nombre de ligne prêtes à être générées. */ +static PyObject *py_line_generator_count_lines(PyObject *, PyObject *); + +/* Retrouve l'emplacement correspondant à une position donnée. */ +static PyObject *py_line_generator_compute_addr(PyObject *, PyObject *); + +/* Détermine si le conteneur s'inscrit dans une plage donnée. */ +static PyObject *py_line_generator_contains_addr(PyObject *, PyObject *); + +/* Renseigne sur les propriétés liées à un générateur. */ +static PyObject *py_line_generator_get_flags(PyObject *, PyObject *); + +/* Imprime dans une ligne de rendu le contenu représenté. */ +static PyObject *py_line_generator_print(PyObject *, PyObject *); + + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant un générateur à manipuler. * +* args = arguments fournis à l'appel. * +* * +* Description : Indique le nombre de ligne prêtes à être générées. * +* * +* Retour : Nombre de lignes devant apparaître au final. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_line_generator_count_lines(PyObject *self, PyObject *args) +{ + PyObject *result; /* Décompte à retourner */ + GLineGenerator *generator; /* Version native */ + size_t count; /* Nombre de lignes présentes */ + + generator = G_LINE_GENERATOR(pygobject_get(self)); + + count = g_line_generator_count_lines(generator); + + result = Py_BuildValue("k", count); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant un générateur à manipuler. * +* args = arguments fournis à l'appel. * +* * +* Description : Retrouve l'emplacement correspondant à une position donnée. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_line_generator_compute_addr(PyObject *self, PyObject *args) +{ + PyObject *result; /* Localisation à retourner */ + GLineGenerator *generator; /* Version native */ + gint x; /* Position géographique */ + size_t index; /* Indice dans le tampon */ + size_t repeat; /* Utilisations successives */ + int ret; /* Bilan de lecture des args. */ + vmpa2t addr; /* Adresse visée par l'opérat° */ + + generator = G_LINE_GENERATOR(pygobject_get(self)); + + ret = PyArg_ParseTuple(args, "ikk", &x, &index, &repeat); + if (!ret) return NULL; + + g_line_generator_compute_addr(generator, x, &addr, index, repeat); + + result = build_from_internal_vmpa(&addr); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant un générateur à manipuler. * +* args = arguments fournis à l'appel. * +* * +* Description : Détermine si le conteneur s'inscrit dans une plage donnée. * +* * +* Retour : Bilan de la détermination, utilisable en comparaisons. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_line_generator_contains_addr(PyObject *self, PyObject *args) +{ + GLineGenerator *generator; /* Version native */ + PyObject *py_vmpa; /* Localisation version Python */ + size_t index; /* Indice dans le tampon */ + size_t repeat; /* Utilisations successives */ + int ret; /* Bilan de lecture des args. */ + vmpa2t *addr; /* Adresse visée par l'opérat° */ + + generator = G_LINE_GENERATOR(pygobject_get(self)); + + ret = PyArg_ParseTuple(args, "O!kk", get_python_vmpa_type(), &py_vmpa, &index, &repeat); + if (!ret) return NULL; + + addr = get_internal_vmpa(py_vmpa); + if (addr == NULL) return NULL; + + g_line_generator_contains_addr(generator, addr, index, repeat); + + Py_RETURN_NONE; + +} + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant un générateur à manipuler. * +* args = arguments fournis à l'appel. * +* * +* Description : Renseigne sur les propriétés liées à un générateur. * +* * +* Retour : Propriétés particulières associées. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_line_generator_get_flags(PyObject *self, PyObject *args) +{ + PyObject *result; /* Propriétés à retourner */ + GLineGenerator *generator; /* Version native */ + size_t index; /* Indice dans le tampon */ + size_t repeat; /* Utilisations successives */ + int ret; /* Bilan de lecture des args. */ + BufferLineFlags flags; /* Propriétés courantes */ + + generator = G_LINE_GENERATOR(pygobject_get(self)); + + ret = PyArg_ParseTuple(args, "kk", &index, &repeat); + if (!ret) return NULL; + + flags = g_line_generator_get_flags(generator, index, repeat); + + result = Py_BuildValue("I", flags); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant un générateur à manipuler. * +* args = arguments fournis à l'appel. * +* * +* Description : Imprime dans une ligne de rendu le contenu représenté. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_line_generator_print(PyObject *self, PyObject *args) +{ + GLineGenerator *generator; /* Version native */ + PyObject *py_line; /* Ligne version Python */ + size_t index; /* Indice dans le tampon */ + size_t repeat; /* Utilisations successives */ + PyObject *py_content; /* Contenu version Python */ + int ret; /* Bilan de lecture des args. */ + GBufferLine *line; /* Ligne de rendu à compléter */ + GBinContent *content; /* Contenu binaire associé */ + + generator = G_LINE_GENERATOR(pygobject_get(self)); + + ret = PyArg_ParseTuple(args, "O!kkO!", get_python_buffer_line_type(), &py_line, &index, + &repeat, get_python_binary_content_type(), &py_content); + if (!ret) return NULL; + + line = G_BUFFER_LINE(pygobject_get(py_line)); + + content = G_BIN_CONTENT(pygobject_get(py_content)); + + g_line_generator_print(generator, line, index, repeat, content); + + Py_RETURN_NONE; + +} + + + + + + + + + + + + + +#if 0 + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void python_line_generator_interface_init(GLineGeneratorIface *iface, PyTypeObject *type) +{ + GLineGeneratorIface *parent; /* Défintion parente */ + size_t i; /* Boucle de parcours */ + PyObject *method; /* Méthode à associer */ + + static const char *meth_names[] = { + "count_lines", + "compute_addr", + "contains_addr", + "get_flags", + "print" + }; + + parent = g_type_interface_peek_parent(iface); + + for (i = 0; i < ARRAY_SIZE(meth_names); i++) + { + method = NULL; + + if (type != NULL) + method = PyObject_GetAttrString((PyObject *)type, meth_names[i]); + + if (method != NULL && PyObject_TypeCheck(method, &PyCFunction_Type) == 0) + /*iface->iface_method = _wrap_TestInterface__proxy_do_iface_method*/; + + else + { + PyErr_Clear(); + + if (parent != NULL) + /*iface->iface_method = parent->iface_method*/; + + } + + Py_XDECREF(method); + + } + +} + + +#endif + + + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *get_python_line_generator_type(void) +{ + static PyMethodDef py_line_generator_methods[] = { + { + "count_lines", py_line_generator_count_lines, + METH_NOARGS, + "count_lines($self, /)\n--\n\nCount the number of lines which can be displayed." + }, + { + "compute_addr", py_line_generator_compute_addr, + METH_VARARGS, + "compute_addr($self, x, index, repeat, /)\n--\n\nReturn the position at a given location." + }, + { + "contains_addr", py_line_generator_contains_addr, + METH_VARARGS, + "contains_addr($self, addr, index, repeat, /)\n--\n\nTell if the generator contains an address." + }, + { + "get_flags", py_line_generator_get_flags, + METH_VARARGS, + "get_flags($self, index, repeat, /)\n--\n\nGet the flags of a position from the generator." + }, + { + "print", py_line_generator_print, + METH_VARARGS, + "print($self, line, index, repeat, content, /)\n--\n\nProduce output into a line from content." + }, + { NULL } + }; + + static PyGetSetDef py_line_generator_getseters[] = { + { NULL } + }; + + static PyTypeObject py_line_generator_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.glibext.LineGenerator", + //.tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + + .tp_doc = "PyChrysalide line content generator", + + .tp_methods = py_line_generator_methods, + .tp_getset = py_line_generator_getseters, + + }; + + return &py_line_generator_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.glibext.LineGenerator'.* +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_line_generator(PyObject *module) +{ + PyTypeObject *py_line_generator_type; /* Type Python 'LineGenerator' */ + PyObject *dict; /* Dictionnaire du module */ + + py_line_generator_type = get_python_line_generator_type(); + + dict = PyModule_GetDict(module); + pyg_register_interface(dict, "LineGenerator", G_TYPE_LINE_GENERATOR, py_line_generator_type); + + return true; + +} diff --git a/plugins/pychrysalide/glibext/linegen.h b/plugins/pychrysalide/glibext/linegen.h new file mode 100644 index 0000000..6c2d161 --- /dev/null +++ b/plugins/pychrysalide/glibext/linegen.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * linegen.h - prototypes pour l'équivalent Python du fichier "glibext/linegen.h" + * + * Copyright (C) 2017 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_GLIBEXT_LINEGEN_H +#define _PLUGINS_PYCHRYSALIDE_GLIBEXT_LINEGEN_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_line_generator_type(void); + +/* Prend en charge l'objet 'pychrysalide.glibext.LineGenerator'. */ +bool register_python_line_generator(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_GLIBEXT_LINEGEN_H */ diff --git a/plugins/pychrysalide/glibext/loadedpanel.c b/plugins/pychrysalide/glibext/loadedpanel.c new file mode 100644 index 0000000..f831607 --- /dev/null +++ b/plugins/pychrysalide/glibext/loadedpanel.c @@ -0,0 +1,166 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * loadedpanel.c - équivalent Python du fichier "glibext/gloadedpanel.h" + * + * Copyright (C) 2017 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 "loadedpanel.h" + + +#include + + +#include + + + + +/* Retrouve l'emplacement correspondant à une position donnée. */ +//static PyObject *py_loaded_panel_compute_addr(PyObject *, PyObject *); + + + + +#if 0 + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant un générateur à manipuler. * +* args = arguments fournis à l'appel. * +* * +* Description : Retrouve l'emplacement correspondant à une position donnée. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_loaded_panel_compute_addr(PyObject *self, PyObject *args) +{ + PyObject *result; /* Localisation à retourner */ + GLineGenerator *generator; /* Version native */ + gint x; /* Position géographique */ + size_t index; /* Indice dans le tampon */ + size_t repeat; /* Utilisations successives */ + int ret; /* Bilan de lecture des args. */ + vmpa2t addr; /* Adresse visée par l'opérat° */ + + generator = G_LOADED_PANEL(pygobject_get(self)); + + ret = PyArg_ParseTuple(args, "ikk", &x, &index, &repeat); + if (!ret) return NULL; + + g_loaded_panel_compute_addr(generator, x, &addr, index, repeat); + + result = build_from_internal_vmpa(&addr); + + return result; + +} + +#endif + + + + + + + + + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *get_python_loaded_panel_type(void) +{ + static PyMethodDef py_loaded_panel_methods[] = { + /* + { + "compute_addr", py_loaded_panel_compute_addr, + METH_VARARGS, + "compute_addr($self, x, index, repeat, /)\n--\n\nReturn the position at a given location." + }, + */ + { NULL } + }; + + static PyGetSetDef py_loaded_panel_getseters[] = { + { NULL } + }; + + static PyTypeObject py_loaded_panel_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.glibext.LoadedPanel", + //.tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + + .tp_doc = "PyChrysalide loaded panel", + + .tp_methods = py_loaded_panel_methods, + .tp_getset = py_loaded_panel_getseters, + + }; + + return &py_loaded_panel_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.glibext.LoadedPanel'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_loaded_panel(PyObject *module) +{ + PyTypeObject *py_loaded_panel_type; /* Type Python 'LineGenerator' */ + PyObject *dict; /* Dictionnaire du module */ + + py_loaded_panel_type = get_python_loaded_panel_type(); + + dict = PyModule_GetDict(module); + pyg_register_interface(dict, "LoadedPanel", G_TYPE_LOADED_PANEL, py_loaded_panel_type); + + return true; + +} diff --git a/plugins/pychrysalide/glibext/loadedpanel.h b/plugins/pychrysalide/glibext/loadedpanel.h new file mode 100644 index 0000000..84f1741 --- /dev/null +++ b/plugins/pychrysalide/glibext/loadedpanel.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * loadedpanel.h - prototypes pour l'équivalent Python du fichier "glibext/gloadedpanel.h" + * + * Copyright (C) 2017 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_GLIBEXT_LOADEDPANEL_H +#define _PLUGINS_PYCHRYSALIDE_GLIBEXT_LOADEDPANEL_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_loaded_panel_type(void); + +/* Prend en charge l'objet 'pychrysalide.glibext.LoadedPanel'. */ +bool register_python_loaded_panel(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_GLIBEXT_LOADEDPANEL_H */ diff --git a/plugins/pychrysalide/glibext/module.c b/plugins/pychrysalide/glibext/module.c new file mode 100644 index 0000000..a3b0a25 --- /dev/null +++ b/plugins/pychrysalide/glibext/module.c @@ -0,0 +1,103 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.c - intégration du répertoire glibext en tant que module + * + * Copyright (C) 2012-2017 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 "module.h" + + +#include + + +#include "buffercache.h" +#include "bufferline.h" +#include "configuration.h" +#include "linegen.h" +#include "loadedpanel.h" +#include "../access.h" + + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Ajoute le module 'glibext' au module Python. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool add_glibext_module_to_python_module(PyObject *super) +{ + bool result; /* Bilan à retourner */ + PyObject *module; /* Sous-module mis en place */ + int ret; /* Bilan d'un appel */ + + static PyModuleDef py_chrysalide_glibext_module = { + + .m_base = PyModuleDef_HEAD_INIT, + + .m_name = "pychrysalide.glibext", + .m_doc = "Python module for Chrysalide.glibext", + + .m_size = -1, + + }; + + result = false; + + module = PyModule_Create(&py_chrysalide_glibext_module); + if (module == NULL) return false; + + ret = PyState_AddModule(super, &py_chrysalide_glibext_module); + if (ret != 0) goto agmtpm_exit; + + ret = _PyImport_FixupBuiltin(module, "pychrysalide.glibext"); + if (ret != 0) goto agmtpm_exit; + + Py_INCREF(module); + ret = PyModule_AddObject(super, "glibext", module); + if (ret != 0) goto agmtpm_exit; + + result = true; + + result &= register_python_buffer_cache(module); + result &= register_python_buffer_line(module); + result &= register_python_config_param(module); + result &= register_python_config_param_iterator(module); + result &= register_python_generic_config(module); + result &= register_python_line_generator(module); + result &= register_python_loaded_panel(module); + + if (result) + register_access_to_python_module("pychrysalide.glibext", module); + + agmtpm_exit: + + assert(result); + + return result; + +} diff --git a/plugins/pychrysalide/glibext/module.h b/plugins/pychrysalide/glibext/module.h new file mode 100644 index 0000000..5a29cca --- /dev/null +++ b/plugins/pychrysalide/glibext/module.h @@ -0,0 +1,39 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.h - prototypes pour l'intégration du répertoire glibext en tant que module + * + * Copyright (C) 2012-2017 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_GLIBEXT_MODULE_H +#define _PLUGINS_PYCHRYSALIDE_GLIBEXT_MODULE_H + + +#include +#include + + + +/* Ajoute le module 'glibext' au module Python. */ +bool add_glibext_module_to_python_module(PyObject *); + + + +#endif /* _PLUGINS_PYOIDA_GLIBEXT_MODULE_H */ diff --git a/plugins/pychrysalide/gtkext/Makefile.am b/plugins/pychrysalide/gtkext/Makefile.am new file mode 100644 index 0000000..4a36e63 --- /dev/null +++ b/plugins/pychrysalide/gtkext/Makefile.am @@ -0,0 +1,18 @@ + +noinst_LTLIBRARIES = libpychrysagtkext.la + +libpychrysagtkext_la_SOURCES = \ + blockdisplay.h blockdisplay.c \ + bufferdisplay.h bufferdisplay.c \ + displaypanel.h displaypanel.c \ + dockable.h dockable.c \ + module.h module.c + + +libpychrysagtkext_la_LDFLAGS = + + +AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ + -I../../../src + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) diff --git a/plugins/pychrysalide/gtkext/blockdisplay.c b/plugins/pychrysalide/gtkext/blockdisplay.c new file mode 100644 index 0000000..c2ccfbb --- /dev/null +++ b/plugins/pychrysalide/gtkext/blockdisplay.c @@ -0,0 +1,115 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * blockdisplay.c - prototypes pour l'équivalent Python du fichier "gtkext/gtkblockdisplay.c" + * + * Copyright (C) 2016-2017 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 "blockdisplay.h" + + +#include +#include + + +#include + + +#include "bufferdisplay.h" +#include "../helpers.h" + + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *get_python_block_display_type(void) +{ + static PyMethodDef py_block_display_methods[] = { + { NULL } + }; + + static PyGetSetDef py_block_display_getseters[] = { + { NULL } + }; + + static PyTypeObject py_block_display_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.gtkext.BlockDisplay", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + + .tp_doc = "PyChrysalide block display.", + + .tp_methods = py_block_display_methods, + .tp_getset = py_block_display_getseters + + }; + + static PyTypeObject *result = NULL; + + if (result == NULL) + result = define_python_dynamic_type(&py_block_display_type); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.gtkext.BlockDisplay'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_block_display(PyObject *module) +{ + bool result; /* Bilan à retourner */ + PyTypeObject *py_block_display_type; /* Type Python 'BlockDisplay' */ + PyObject *dict; /* Dictionnaire du module */ + + py_block_display_type = get_python_block_display_type(); + + dict = PyModule_GetDict(module); + + result = register_class_for_pygobject(dict, GTK_TYPE_BLOCK_DISPLAY, + py_block_display_type, get_python_buffer_display_type()); + + return result; + +} diff --git a/plugins/pychrysalide/gtkext/blockdisplay.h b/plugins/pychrysalide/gtkext/blockdisplay.h new file mode 100644 index 0000000..ab15ac5 --- /dev/null +++ b/plugins/pychrysalide/gtkext/blockdisplay.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * blockdisplay.h - prototypes pour l'équivalent Python du fichier "gtkext/gtkblockdisplay.h" + * + * Copyright (C) 2016-2017 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_GTKEXT_BLOCKDISPLAY_H +#define _PLUGINS_PYCHRYSALIDE_GTKEXT_BLOCKDISPLAY_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_block_display_type(void); + +/* Prend en charge l'objet 'pychrysalide.gtkext.BlockDisplay'. */ +bool register_python_block_display(PyObject *module); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_GTKEXT_BLOCKDISPLAY_H */ diff --git a/plugins/pychrysalide/gtkext/bufferdisplay.c b/plugins/pychrysalide/gtkext/bufferdisplay.c new file mode 100644 index 0000000..9aa1bca --- /dev/null +++ b/plugins/pychrysalide/gtkext/bufferdisplay.c @@ -0,0 +1,115 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * bufferdisplay.c - prototypes pour l'équivalent Python du fichier "gtkext/gtkbufferdisplay.c" + * + * Copyright (C) 2016-2017 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 "bufferdisplay.h" + + +#include +#include + + +#include + + +#include "displaypanel.h" +#include "../helpers.h" + + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *get_python_buffer_display_type(void) +{ + static PyMethodDef py_buffer_display_methods[] = { + { NULL } + }; + + static PyGetSetDef py_buffer_display_getseters[] = { + { NULL } + }; + + static PyTypeObject py_buffer_display_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.gtkext.BufferDisplay", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + + .tp_doc = "PyChrysalide buffer display.", + + .tp_methods = py_buffer_display_methods, + .tp_getset = py_buffer_display_getseters + + }; + + static PyTypeObject *result = NULL; + + if (result == NULL) + result = define_python_dynamic_type(&py_buffer_display_type); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.gtkext.Bufferdisplay'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_buffer_display(PyObject *module) +{ + bool result; /* Bilan à retourner */ + PyTypeObject *py_buffer_display_type; /* Type Python 'BufferDisplay' */ + PyObject *dict; /* Dictionnaire du module */ + + py_buffer_display_type = get_python_buffer_display_type(); + + dict = PyModule_GetDict(module); + + result = register_class_for_pygobject(dict, GTK_TYPE_BUFFER_DISPLAY, + py_buffer_display_type, get_python_display_panel_type()); + + return result; + +} diff --git a/plugins/pychrysalide/gtkext/bufferdisplay.h b/plugins/pychrysalide/gtkext/bufferdisplay.h new file mode 100644 index 0000000..4a21fb9 --- /dev/null +++ b/plugins/pychrysalide/gtkext/bufferdisplay.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * bufferdisplay.h - prototypes pour l'équivalent Python du fichier "gtkext/gtkbufferdisplay.h" + * + * Copyright (C) 2016-2017 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_GTKEXT_BUFFERDISPLAY_H +#define _PLUGINS_PYCHRYSALIDE_GTKEXT_BUFFERDISPLAY_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_buffer_display_type(void); + +/* Prend en charge l'objet 'pychrysalide.gtkext.BufferDisplay'. */ +bool register_python_buffer_display(PyObject *module); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_GTKEXT_BUFFERDISPLAY_H */ diff --git a/plugins/pychrysalide/gtkext/displaypanel.c b/plugins/pychrysalide/gtkext/displaypanel.c new file mode 100644 index 0000000..b75d173 --- /dev/null +++ b/plugins/pychrysalide/gtkext/displaypanel.c @@ -0,0 +1,269 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * displaypanel.c - prototypes pour l'équivalent Python du fichier "gtkext/gtkdisplaypanel.c" + * + * Copyright (C) 2016-2017 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 "displaypanel.h" + + +#include +#include + + +#include + + +#include "../helpers.h" +#include "../arch/vmpa.h" + + + +/* Crée un nouvel objet Python de type 'DisplayPanel'. */ +#if 0 +static PyObject *py_display_panel_new(PyTypeObject *, PyObject *, PyObject *); +#endif + +/* S'assure qu'une adresse donnée est visible à l'écran. */ +static PyObject *py_display_panel_scroll_to_address(PyObject *, PyObject *); + +/* Définit les constantes pour les panneaux de vue. */ +static bool py_display_panel_define_constants(PyTypeObject *); + + + +/****************************************************************************** +* * +* Paramètres : type = type de l'objet à instancier. * +* args = arguments fournis à l'appel. * +* kwds = arguments de type key=val fournis. * +* * +* Description : Crée un nouvel objet Python de type 'DisplayPanel'. * +* * +* Retour : Instance Python mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ +#if 0 +static PyObject *py_display_panel_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ +#if 0 + PyObject *result; /* Instance à retourner */ + const char *name; /* Désignation humaine */ + const char *lname; /* Nom version longue */ + PyGObject *widget; /* Composant visuel du panneau */ + const char *path; /* Placement à l'affichage */ + int ret; /* Bilan de lecture des args. */ + GEditorItem *item; /* Version GLib du format */ + + ret = PyArg_ParseTuple(args, "ssOs", &name, &lname, &widget, &path); + if (!ret) Py_RETURN_NONE; + + item = g_view_panel_new(name, lname, + GTK_WIDGET(pygobject_get(widget)), path); + + result = py_display_panel_from_c(G_DISPLAY_PANEL(item)); + g_object_unref(item); + + return (PyObject *)result; +#endif + + /* FIXME */ + + + Py_RETURN_NONE; + +} +#endif + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant un tampon de code. * +* args = arguments fournis à l'appel. * +* * +* Description : S'assure qu'une adresse donnée est visible à l'écran. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_display_panel_scroll_to_address(PyObject *self, PyObject *args) +{ + GtkDisplayPanel *panel; /* Panneau à manipuler */ + PyObject *py_vmpa; /* Localisation version Python */ + int ret; /* Bilan de lecture des args. */ + vmpa2t *addr; /* Adresse visée par l'opérat° */ + + ret = PyArg_ParseTuple(args, "O", &py_vmpa); + if (!ret) return NULL; + + ret = PyObject_IsInstance(py_vmpa, (PyObject *)get_python_vmpa_type()); + if (!ret) return NULL; + + addr = get_internal_vmpa(py_vmpa); + if (addr == NULL) return NULL; + + panel = GTK_DISPLAY_PANEL(pygobject_get(self)); + + // FIXME + //gtk_display_panel_scroll_to_address(panel, addr, SPT_RAW); + + Py_RETURN_NONE; + +} + + +/****************************************************************************** +* * +* Paramètres : obj_type = type dont le dictionnaire est à compléter. * +* * +* Description : Définit les constantes pour les panneaux de vue. * +* * +* Retour : true en cas de succès de l'opération, false sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool py_display_panel_define_constants(PyTypeObject *obj_type) +{ + bool result; /* Bilan à retourner */ + + result = true; + + result &= PyDict_AddIntMacro(obj_type, SPT_RAW); + result &= PyDict_AddIntMacro(obj_type, SPT_TOP); + result &= PyDict_AddIntMacro(obj_type, SPT_CENTER); + result &= PyDict_AddIntMacro(obj_type, SPT_BOTTOM); + + 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_display_panel_type(void) +{ + static PyMethodDef py_display_panel_methods[] = { + { + "scroll_to_address", (PyCFunction)py_display_panel_scroll_to_address, + METH_VARARGS, + "scroll_to_address($self, addr, tweak, /)\n--\n\nEnsure a given address is displayed in the view panel." + }, + { NULL } + }; + + static PyGetSetDef py_display_panel_getseters[] = { + { NULL } + }; + + static PyTypeObject py_display_panel_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.gtkext.DisplayPanel", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + + .tp_doc = "PyChrysalide view panel.", + + .tp_methods = py_display_panel_methods, + .tp_getset = py_display_panel_getseters, + //.tp_new = (newfunc)py_display_panel_new, + //.tp_init = (initproc)pychrysalide_allow_args_for_gobjects + + }; + + static PyTypeObject *result = NULL; + + if (result == NULL) + result = define_python_dynamic_type(&py_display_panel_type); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.gtkext.DisplayPanel'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_display_panel(PyObject *module) +{ + bool result; /* Bilan à retourner */ + PyTypeObject *py_display_panel_type; /* Type Python 'DisplayPanel' */ + PyObject *parent_mod; /* Module Python Fixed */ + PyObject *fixed; /* Module "GtkFixed" */ + PyObject *dict; /* Dictionnaire du module */ + + result = false; + + py_display_panel_type = get_python_display_panel_type(); + + parent_mod = PyImport_ImportModule("gi.repository.Gtk"); + + if (parent_mod == NULL) + goto rpdp_exit; + + fixed = PyObject_GetAttrString(parent_mod, "Fixed"); + + Py_DECREF(parent_mod); + + dict = PyModule_GetDict(module); + + result = register_class_for_pygobject(dict, GTK_TYPE_DISPLAY_PANEL, + py_display_panel_type, (PyTypeObject *)fixed); + Py_DECREF(fixed); + + if (!result) + goto rpdp_exit; + + result = py_display_panel_define_constants(py_display_panel_type); + + rpdp_exit: + + return result; + +} diff --git a/plugins/pychrysalide/gtkext/displaypanel.h b/plugins/pychrysalide/gtkext/displaypanel.h new file mode 100644 index 0000000..318a9f6 --- /dev/null +++ b/plugins/pychrysalide/gtkext/displaypanel.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * displaypanel.h - prototypes pour l'équivalent Python du fichier "gtkext/gtkdisplaypanel.h" + * + * Copyright (C) 2016-2017 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_GTKEXT_DISPLAYPANEL_H +#define _PLUGINS_PYCHRYSALIDE_GTKEXT_DISPLAYPANEL_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_display_panel_type(void); + +/* Prend en charge l'objet 'pychrysalide.gtkext.DisplayPanel'. */ +bool register_python_display_panel(PyObject *module); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_GTKEXT_DISPLAYPANEL_H */ diff --git a/plugins/pychrysalide/gtkext/dockable.c b/plugins/pychrysalide/gtkext/dockable.c new file mode 100644 index 0000000..9c66159 --- /dev/null +++ b/plugins/pychrysalide/gtkext/dockable.c @@ -0,0 +1,102 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * dockable.c - équivalent Python du fichier "gtkext/gtkdockable.c" + * + * Copyright (C) 2017 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 "dockable.h" + + +#include + + +#include + + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *get_python_gtk_dockable_type(void) +{ + static PyMethodDef py_gtk_dockable_methods[] = { + { NULL } + }; + + static PyGetSetDef py_gtk_dockable_getseters[] = { + { NULL } + }; + + static PyTypeObject py_gtk_dockable_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.gtkext.GtkDockable", + //.tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + + .tp_doc = "PyChrysalide interface for Gtk dockable widgets", + + .tp_methods = py_gtk_dockable_methods, + .tp_getset = py_gtk_dockable_getseters, + + }; + + return &py_gtk_dockable_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.gtkext.GtkDockable'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_gtk_dockable(PyObject *module) +{ + PyTypeObject *py_gtk_dockable_type; /* Type Python 'LineGenerator' */ + PyObject *dict; /* Dictionnaire du module */ + + py_gtk_dockable_type = get_python_gtk_dockable_type(); + + dict = PyModule_GetDict(module); + pyg_register_interface(dict, "LineGenerator", GTK_TYPE_DOCKABLE, py_gtk_dockable_type); + + return true; + +} diff --git a/plugins/pychrysalide/gtkext/dockable.h b/plugins/pychrysalide/gtkext/dockable.h new file mode 100644 index 0000000..dfec74d --- /dev/null +++ b/plugins/pychrysalide/gtkext/dockable.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * dockable.h - prototypes pour l'équivalent Python du fichier "gtkext/gtkdockable.h" + * + * Copyright (C) 2017 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_GTKEXT_DOCKABLE_H +#define _PLUGINS_PYCHRYSALIDE_GTKEXT_DOCKABLE_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_gtk_dockable_type(void); + +/* Prend en charge l'objet 'pychrysalide.gtkext.GtkDockable'. */ +bool register_python_gtk_dockable(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_GTKEXT_DOCKABLE_H */ diff --git a/plugins/pychrysalide/gtkext/module.c b/plugins/pychrysalide/gtkext/module.c new file mode 100644 index 0000000..8b2cc5e --- /dev/null +++ b/plugins/pychrysalide/gtkext/module.c @@ -0,0 +1,95 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.c - intégration du répertoire gtkext en tant que module + * + * Copyright (C) 2012-2017 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 "module.h" + + +#include + + +#include "blockdisplay.h" +#include "bufferdisplay.h" +#include "displaypanel.h" +#include "dockable.h" + + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Ajoute le module 'gtkext' au module Python. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool add_gtkext_module_to_python_module(PyObject *super) +{ + bool result; /* Bilan à retourner */ + PyObject *module; /* Sous-module mis en place */ + int ret; /* Bilan d'un appel */ + + static PyModuleDef py_chrysalide_gtkext_module = { + + .m_base = PyModuleDef_HEAD_INIT, + + .m_name = "pychrysalide.gtkext", + .m_doc = "Python module for Chrysalide.gtkext", + + .m_size = -1, + + }; + + result = false; + + module = PyModule_Create(&py_chrysalide_gtkext_module); + if (module == NULL) return false; + + ret = PyState_AddModule(super, &py_chrysalide_gtkext_module); + if (ret != 0) goto agmtpm_exit; + + ret = _PyImport_FixupBuiltin(module, "pychrysalide.gtkext"); + if (ret != 0) goto agmtpm_exit; + + Py_INCREF(module); + ret = PyModule_AddObject(super, "gtkext", module); + if (ret != 0) goto agmtpm_exit; + + result = true; + + result &= register_python_display_panel(module); + result &= register_python_buffer_display(module); + result &= register_python_block_display(module); + result &= register_python_gtk_dockable(module); + + agmtpm_exit: + + assert(result); + + return result; + +} diff --git a/plugins/pychrysalide/gtkext/module.h b/plugins/pychrysalide/gtkext/module.h new file mode 100644 index 0000000..a58aed0 --- /dev/null +++ b/plugins/pychrysalide/gtkext/module.h @@ -0,0 +1,39 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.h - prototypes pour l'intégration du répertoire gtkext en tant que module + * + * Copyright (C) 2012-2017 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_PYOIDA_GTKEXT_MODULE_H +#define _PLUGINS_PYOIDA_GTKEXT_MODULE_H + + +#include +#include + + + +/* Ajoute le module 'gtkext' au module Python. */ +bool add_gtkext_module_to_python_module(PyObject *); + + + +#endif /* _PLUGINS_PYOIDA_GTKEXT_MODULE_H */ diff --git a/plugins/pychrysalide/gui/Makefile.am b/plugins/pychrysalide/gui/Makefile.am new file mode 100644 index 0000000..d4a724d --- /dev/null +++ b/plugins/pychrysalide/gui/Makefile.am @@ -0,0 +1,19 @@ + +noinst_LTLIBRARIES = libpychrysagui.la + +libpychrysagui_la_SOURCES = \ + editem.h editem.c \ + module.h module.c + +libpychrysagui_la_LIBADD = \ + panels/libpychrysaguipanels.la + +libpychrysagui_la_LDFLAGS = + + +AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ + -I../../../src + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) + +SUBDIRS = panels diff --git a/plugins/pychrysalide/gui/editem.c b/plugins/pychrysalide/gui/editem.c new file mode 100644 index 0000000..91f5246 --- /dev/null +++ b/plugins/pychrysalide/gui/editem.c @@ -0,0 +1,370 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * editem.c - prototypes pour l'équivalent Python du fichier "gui/editem.c" + * + * Copyright (C) 2012-2017 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 "editem.h" + + +#include + + +#include + + +#include "../helpers.h" + + +#include "../analysis/binary.h" +#include "../gtkext/displaypanel.h" + + + +/* Réagit à un changement du binaire courant. */ +static void _update_editor_item_for_binary_python_wrapper(GEditorItem *, GLoadedBinary *); + +/* Réagit à un changement de vue. */ +static void _update_editor_item_for_view_python_wrapper(GEditorItem *, GtkDisplayPanel *); + +/* Réagit à un changement de contenu. */ +static void _update_editor_item_for_view_content_python_wrapper(GEditorItem *, GtkDisplayPanel *); + +/* Réagit à un changement du binaire courant. */ +static PyObject *py_editor_item_update_for_binary(PyObject *, PyObject *); + +/* Réagit à un changement d'affichage principal de contenu. */ +static PyObject *py_editor_item_update_for_view(PyObject *, PyObject *); + +/* Réagit à un changement d'affichage principal de contenu. */ +static PyObject *py_editor_item_update_for_content(PyObject *, PyObject *); + +/* Procède à l'enregistrement d'un élément reactif de l'éditeur. */ +static PyObject *py_editor_item_register(PyObject *, PyObject *); + + + +/****************************************************************************** +* * +* Paramètres : item = élément à actualiser. * +* binary = nouvelle instance de binaire analysé. * +* * +* Description : Réagit à un changement du binaire courant. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void _update_editor_item_for_binary_python_wrapper(GEditorItem *item, GLoadedBinary *binary) +{ + PyObject *target; /* Version Python de l'élément */ + PyObject *args; /* Arguments pour l'appel */ + PyObject *value; /* Retour obtenu */ + + /** + * Normalement, l'objet Python est enregistré dans la liste de Chrysalide + * des éléments d'éditeur, via py_editor_item_register(), donc son compteur + * de références doit le maintenir en vie. + * + * On peut donc le récupérer directement depuis l'instance GLib, sans passer + * par la procédure de pygobject, qui obligerait à connaître le type précis + * de l'instance GLib manipulée. + */ + target = pygobject_new(G_OBJECT(item)); + + args = PyTuple_New(1); + PyTuple_SetItem(args, 0, pygobject_new(G_OBJECT(binary))); + + value = run_python_method(target, "update_for_binary", args); + + Py_XDECREF(value); + Py_DECREF(args); + Py_DECREF(target); + +} + + +/****************************************************************************** +* * +* Paramètres : item = élément à actualiser. * +* panel = nouveau panneau d'affichage actif. * +* * +* Description : Réagit à un changement de vue. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void _update_editor_item_for_view_python_wrapper(GEditorItem *item, GtkDisplayPanel *panel) +{ + PyObject *target; /* Version Python de l'élément */ + PyObject *args; /* Arguments pour l'appel */ + PyObject *value; /* Retour obtenu */ + + /** + * Normalement, l'objet Python est enregistré dans la liste de Chrysalide + * des éléments d'éditeur, via py_editor_item_register(), donc son compteur + * de références doit le maintenir en vie. + * + * On peut donc le récupérer directement depuis l'instane GLib, sans passer + * par la procédure de pygobject, qui obligerait à connaître le type précis + * de l'instance GLib manipulée. + */ + target = pygobject_new(G_OBJECT(item)); + + args = PyTuple_New(1); + PyTuple_SetItem(args, 0, pygobject_new(G_OBJECT(panel))); + + value = run_python_method(target, "update_for_view", args); + + Py_XDECREF(value); + Py_DECREF(args); + Py_DECREF(target); + +} + + +/****************************************************************************** +* * +* Paramètres : item = élément à actualiser. * +* panel = nouveau panneau d'affichage actif. * +* * +* Description : Réagit à un changement de contenu. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void _update_editor_item_for_view_content_python_wrapper(GEditorItem *item, GtkDisplayPanel *panel) +{ + PyObject *target; /* Version Python de l'élément */ + PyObject *args; /* Arguments pour l'appel */ + PyObject *value; /* Retour obtenu */ + + /** + * Normalement, l'objet Python est enregistré dans la liste de Chrysalide + * des éléments d'éditeur, via py_editor_item_register(), donc son compteur + * de références doit le maintenir en vie. + * + * On peut donc le récupérer directement depuis l'instane GLib, sans passer + * par la procédure de pygobject, qui obligerait à connaître le type précis + * de l'instance GLib manipulée. + */ + target = pygobject_new(G_OBJECT(item)); + + args = PyTuple_New(1); + PyTuple_SetItem(args, 0, pygobject_new(G_OBJECT(panel))); + + value = run_python_method(target, "update_for_content", args); + + Py_XDECREF(value); + Py_DECREF(args); + Py_DECREF(target); + +} + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant un binaire. * +* args = arguments fournis à l'appel. * +* * +* Description : Réagit à un changement du binaire courant. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_editor_item_update_for_binary(PyObject *self, PyObject *args) +{ + Py_RETURN_NONE; + +} + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant un binaire. * +* args = arguments fournis à l'appel. * +* * +* Description : Réagit à un changement d'affichage principal de contenu. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_editor_item_update_for_view(PyObject *self, PyObject *args) +{ + Py_RETURN_NONE; + +} + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant un binaire. * +* args = arguments fournis à l'appel. * +* * +* Description : Réagit à un changement d'affichage principal de contenu. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_editor_item_update_for_content(PyObject *self, PyObject *args) +{ + Py_RETURN_NONE; + +} + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant un binaire. * +* args = arguments fournis à l'appel. * +* * +* Description : Procède à l'enregistrement d'un élément reactif de l'éditeur.* +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_editor_item_register(PyObject *self, PyObject *args) +{ + GEditorItem *item; /* Version GLib de l'élément */ + + item = G_EDITOR_ITEM(pygobject_get(self)); + + //item->update_binary = _update_editor_item_for_binary_python_wrapper; + //item->update_view = _update_editor_item_for_view_python_wrapper; + //item->update_content = _update_editor_item_for_view_content_python_wrapper; + + Py_INCREF(self); + register_editor_item(item); + + Py_RETURN_NONE; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *get_python_editor_item_type(void) +{ + static PyMethodDef py_editor_item_methods[] = { + { + "update_for_binary", (PyCFunction)py_editor_item_update_for_binary, + METH_VARARGS, + "Called by Chrysalide on each binary change, if the item is registered." + }, + { + "update_for_view", (PyCFunction)py_editor_item_update_for_view, + METH_VARARGS, + "Called by Chrysalide on each view change, if the item is registered." + }, + { + "update_for_content", (PyCFunction)py_editor_item_update_for_content, + METH_VARARGS, + "Called by Chrysalide on each view content change, if the item is registered." + }, + { + "register", (PyCFunction)py_editor_item_register, + METH_NOARGS, + "register($self, /)\n--\n\nRegister the item as editor item." + }, + { NULL } + }; + + static PyGetSetDef py_editor_item_getseters[] = { + { NULL } + }; + + static PyTypeObject py_editor_item_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.gui.EditorItem", + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + + .tp_doc = "PyChrysalide editor item", + + .tp_methods = py_editor_item_methods, + .tp_getset = py_editor_item_getseters, + + }; + + return &py_editor_item_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.gui.EditorItem'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_editor_item(PyObject *module) +{ + PyTypeObject *py_editor_item_type; /* Type Python 'LoadedBinary' */ + PyObject *dict; /* Dictionnaire du module */ + + py_editor_item_type = get_python_editor_item_type(); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_EDITOR_ITEM, py_editor_item_type, &PyGObject_Type)) + return false; + + return true; + +} diff --git a/plugins/pychrysalide/gui/editem.h b/plugins/pychrysalide/gui/editem.h new file mode 100644 index 0000000..e34690c --- /dev/null +++ b/plugins/pychrysalide/gui/editem.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * editem.h - prototypes pour l'équivalent Python du fichier "gui/editem.h" + * + * Copyright (C) 2012-2017 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_GUI_EDITEM_H +#define _PLUGINS_PYCHRYSALIDE_GUI_EDITEM_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_editor_item_type(void); + +/* Prend en charge l'objet 'pychrysalide.gui.EditorItem'. */ +bool register_python_editor_item(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_GUI_EDITEM_H */ diff --git a/plugins/pychrysalide/gui/module.c b/plugins/pychrysalide/gui/module.c new file mode 100644 index 0000000..192b1e6 --- /dev/null +++ b/plugins/pychrysalide/gui/module.c @@ -0,0 +1,97 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.c - intégration du répertoire gui en tant que module + * + * Copyright (C) 2012-2017 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 "module.h" + + +#include + + + +#include "editem.h" +#include "panels/module.h" +#include "../access.h" + + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Ajoute le module 'gui' au module Python. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool add_gui_module_to_python_module(PyObject *super) +{ + bool result; /* Bilan à retourner */ + PyObject *module; /* Sous-module mis en place */ + int ret; /* Bilan d'un appel */ + + static PyModuleDef py_chrysalide_gui_module = { + + .m_base = PyModuleDef_HEAD_INIT, + + .m_name = "pychrysalide.gui", + .m_doc = "Python module for the Chrysalide GUI", + + .m_size = -1, + + }; + + result = false; + + module = PyModule_Create(&py_chrysalide_gui_module); + if (module == NULL) return false; + + ret = PyState_AddModule(super, &py_chrysalide_gui_module); + if (ret != 0) goto loading_failed; + + ret = _PyImport_FixupBuiltin(module, "pychrysalide.gui"); + if (ret != 0) goto loading_failed; + + Py_INCREF(module); + ret = PyModule_AddObject(super, "gui", module); + if (ret != 0) goto loading_failed; + + result = true; + + result &= register_python_editor_item(module); + + result &= add_gui_panels_module_to_python_module(module); + + if (result) + register_access_to_python_module("pychrysalide.gui", module); + + loading_failed: + + assert(result); + + return result; + +} diff --git a/plugins/pychrysalide/gui/module.h b/plugins/pychrysalide/gui/module.h new file mode 100644 index 0000000..8609d66 --- /dev/null +++ b/plugins/pychrysalide/gui/module.h @@ -0,0 +1,39 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.h - prototypes pour l'intégration du répertoire gui en tant que module + * + * Copyright (C) 2012-2017 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_GUI_MODULE_H +#define _PLUGINS_PYCHRYSALIDE_GUI_MODULE_H + + +#include +#include + + + +/* Ajoute le module 'gui' au module Python. */ +bool add_gui_module_to_python_module(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_GUI_MODULE_H */ diff --git a/plugins/pychrysalide/gui/panels/Makefile.am b/plugins/pychrysalide/gui/panels/Makefile.am new file mode 100644 index 0000000..99e4c3f --- /dev/null +++ b/plugins/pychrysalide/gui/panels/Makefile.am @@ -0,0 +1,15 @@ + +noinst_LTLIBRARIES = libpychrysaguipanels.la + +libpychrysaguipanels_la_SOURCES = \ + module.h module.c \ + panel.h panel.c + + +libpychrysaguipanels_la_LDFLAGS = + + +AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) $(LIBPYTHON_CFLAGS) $(LIBPYGOBJECT_CFLAGS) \ + -I../../../../src + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) diff --git a/plugins/pychrysalide/gui/panels/module.c b/plugins/pychrysalide/gui/panels/module.c new file mode 100644 index 0000000..21b487e --- /dev/null +++ b/plugins/pychrysalide/gui/panels/module.c @@ -0,0 +1,93 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.c - intégration du répertoire panels en tant que module + * + * Copyright (C) 2012-2017 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 "module.h" + + +#include + + +#include "panel.h" +#include "../../access.h" + + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Ajoute le module 'gui.panels' au module Python. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool add_gui_panels_module_to_python_module(PyObject *super) +{ + bool result; /* Bilan à retourner */ + PyObject *module; /* Sous-module mis en place */ + int ret; /* Bilan d'un appel */ + + static PyModuleDef py_chrysalide_panels_module = { + + .m_base = PyModuleDef_HEAD_INIT, + + .m_name = "gui.analysis.panels", + .m_doc = "Python module for Chrysalide.gui.panels", + + .m_size = -1, + + }; + + result = false; + + module = PyModule_Create(&py_chrysalide_panels_module); + if (module == NULL) return false; + + ret = PyState_AddModule(super, &py_chrysalide_panels_module); + if (ret != 0) goto loading_failed; + + ret = _PyImport_FixupBuiltin(module, "pychrysalide.gui.panels"); + if (ret != 0) goto loading_failed; + + Py_INCREF(module); + ret = PyModule_AddObject(super, "panels", module); + if (ret != 0) goto loading_failed; + + result = true; + + result &= register_python_panel_item(module); + + if (result) + register_access_to_python_module("pychrysalide.gui.panels", module); + + loading_failed: + + assert(result); + + return result; + +} diff --git a/plugins/pychrysalide/gui/panels/module.h b/plugins/pychrysalide/gui/panels/module.h new file mode 100644 index 0000000..34fac70 --- /dev/null +++ b/plugins/pychrysalide/gui/panels/module.h @@ -0,0 +1,39 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * module.h - prototypes pour l'intégration du répertoire panels en tant que module + * + * Copyright (C) 2012-2017 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_GUI_PANELS_MODULE_H +#define _PLUGINS_PYCHRYSALIDE_GUI_PANELS_MODULE_H + + +#include +#include + + + +/* Ajoute le module 'gui.panels' au module Python. */ +bool add_gui_panels_module_to_python_module(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_GUI_PANELS_MODULE_H */ diff --git a/plugins/pychrysalide/gui/panels/panel.c b/plugins/pychrysalide/gui/panels/panel.c new file mode 100644 index 0000000..72c9e7e --- /dev/null +++ b/plugins/pychrysalide/gui/panels/panel.c @@ -0,0 +1,244 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * panel.c - équivalent Python du fichier "gui/panels/panel.c" + * + * Copyright (C) 2012-2017 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 "panel.h" + + +#include + + +#include +#include +#include + + +#include "../editem.h" +#include "../../helpers.h" +#include "../../gtkext/dockable.h" + + + +/* Initialise une instance sur la base du dérivé de GObject. */ +static int py_panel_item_init(PyObject *self, PyObject *args, PyObject *kwds); + +/* Place un panneau dans l'ensemble affiché. */ +static PyObject *py_panel_item_dock(PyObject *, PyObject *); + +/* Définit les constantes pour les panneaux. */ +static bool py_panel_item_define_constants(PyTypeObject *); + + + +/****************************************************************************** +* * +* Paramètres : self = objet à initialiser (théoriquement). * +* args = arguments fournis à l'appel. * +* kwds = arguments de type key=val fournis. * +* * +* Description : Initialise une instance sur la base du dérivé de GObject. * +* * +* Retour : 0. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int py_panel_item_init(PyObject *self, PyObject *args, PyObject *kwds) +{ + unsigned long personality; /* Nature du panneau */ + const char *name; /* Désignation humaine */ + const char *lname; /* Nom version longue */ + PyGObject *widget; /* Composant visuel du panneau */ + int startup; /* Recommandation au démarrage */ + const char *path; /* Placement à l'affichage */ + int ret; /* Bilan de lecture des args. */ + GPanelItem *item; /* Elément de l'éditeur */ + + ret = PyArg_ParseTuple(args, "kssOps", &personality, &name, &lname, &widget, &startup, &path); + if (!ret) return -1; + + item = g_panel_item_new(personality, name, lname, + GTK_WIDGET(pygobject_get(widget)), startup, path); + + /* FIXME ? Est-ce à l'utilisateur de s'enregistrer ? */ + register_panel_item(item, get_main_configuration()); + + /** + * Si Python ne voit plus la variable représentant le panneau utilisée, + * il va la supprimer, ce qui va supprimer le composant GTK. + * + * On sera donc en situation de Use-After-Free, dont les conséquences + * arrivent très vite. + */ + g_object_ref(GTK_WIDGET(pygobject_get(widget))); + Py_INCREF(self); + + /* Enregistrement auprès de PyGObject */ + + ((PyGObject *)self)->obj = G_OBJECT(item); + + pygobject_register_wrapper(self); + + return 0; + +} + + +/****************************************************************************** +* * +* Paramètres : self = classe représentant un binaire. * +* args = arguments fournis à l'appel. * +* * +* Description : Place un panneau dans l'ensemble affiché. * +* * +* Retour : Py_None. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_panel_item_dock(PyObject *self, PyObject *args) +{ + GPanelItem *item; /* Panneau à manipuler */ + + item = G_PANEL_ITEM(pygobject_get(self)); + + g_panel_item_dock(item); + + Py_RETURN_NONE; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit un accès à une définition de type à diffuser. * +* * +* Retour : Définition d'objet pour Python. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *get_python_panel_item_type(void) +{ + static PyMethodDef py_panel_item_methods[] = { + { + "dock", (PyCFunction)py_panel_item_dock, + METH_NOARGS, + "dock($self, /)\n--\n\nDisplay the panel item in the right place." + }, + { NULL } + }; + + static PyGetSetDef py_panel_item_getseters[] = { + { NULL } + }; + + static PyTypeObject py_panel_item_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.gui.panels.PanelItem", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + + .tp_doc = "PyChrysalide panel item.", + + .tp_methods = py_panel_item_methods, + .tp_getset = py_panel_item_getseters, + .tp_init = (initproc)py_panel_item_init + + }; + + return &py_panel_item_type; + +} + + +/****************************************************************************** +* * +* Paramètres : obj_type = type dont le dictionnaire est à compléter. * +* * +* Description : Définit les constantes pour les panneaux. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool py_panel_item_define_constants(PyTypeObject *obj_type) +{ + bool result; /* Bilan à retourner */ + + result = true; + + result &= PyDict_AddIntMacro(obj_type, PIP_INVALID); + + result &= PyDict_AddIntMacro(obj_type, PIP_SINGLETON); + result &= PyDict_AddIntMacro(obj_type, PIP_BINARY_VIEW); + result &= PyDict_AddIntMacro(obj_type, PIP_OTHER); + + result &= PyDict_AddIntMacro(obj_type, PIP_COUNT); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.gui.panels.PanelItem'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_panel_item(PyObject *module) +{ + PyTypeObject *py_panel_item_type; /* Type Python 'LoadedBinary' */ + PyObject *dict; /* Dictionnaire du module */ + + py_panel_item_type = get_python_panel_item_type(); + + dict = PyModule_GetDict(module); + + if (!_register_class_for_pygobject(dict, G_TYPE_PANEL_ITEM, py_panel_item_type, + get_python_editor_item_type(), get_python_gtk_dockable_type(), NULL)) + return false; + + if (!py_panel_item_define_constants(py_panel_item_type)) + return false; + + return true; + +} diff --git a/plugins/pychrysalide/gui/panels/panel.h b/plugins/pychrysalide/gui/panels/panel.h new file mode 100644 index 0000000..f0406d5 --- /dev/null +++ b/plugins/pychrysalide/gui/panels/panel.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * panel.h - prototypes pour l'équivalent Python du fichier "gui/panels/panel.h" + * + * Copyright (C) 2012-2017 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_GUI_PANELS_PANEL_H +#define _PLUGINS_PYCHRYSALIDE_GUI_PANELS_PANEL_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_panel_item_type(void); + +/* Prend en charge l'objet 'pychrysalide.gui.panels.PanelItem'. */ +bool register_python_panel_item(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_GUI_PANELS_PANEL_H */ diff --git a/plugins/pychrysalide/helpers.c b/plugins/pychrysalide/helpers.c new file mode 100644 index 0000000..17a396d --- /dev/null +++ b/plugins/pychrysalide/helpers.c @@ -0,0 +1,473 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * helpers.c - simplification des interactions de base avec Python + * + * Copyright (C) 2012-2017 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 "helpers.h" + + +#include +#include +#include +#include + + + +/* ---------------------------------------------------------------------------------- */ +/* ACCELERATEURS POUR PYTHON UNIQUEMENT */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : status = bilan de comparaison à traduire. * +* op = type de comparaison menée. * +* * +* Description : Traduit pour Python le bilan d'une comparaison riche. * +* * +* Retour : Objet Python à référencer. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyObject *status_to_rich_cmp_state(int status, int op) +{ + PyObject *result; /* Bilan àretourner */ + + switch (op) + { + case Py_LT: + result = status < 0 ? Py_True : Py_False; + break; + + case Py_LE: + result = status <= 0 ? Py_True : Py_False; + break; + + case Py_EQ: + result = status == 0 ? Py_True : Py_False; + break; + + case Py_NE: + result = status != 0 ? Py_True : Py_False; + break; + + case Py_GT: + result = status > 0 ? Py_True : Py_False; + break; + + case Py_GE: + result = status >= 0 ? Py_True : Py_False; + break; + + default: + result = Py_NotImplemented; + break; + + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : target = propriétaire de la routine visée. * +* method = désignation de la fonction à appeler. * +* * +* Description : Indique si une routine Python existe ou non. * +* * +* Retour : Bilan de l'analyse. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool has_python_method(PyObject *module, const char *method) +{ + bool result; /* Bilan à retourner */ + PyObject *func; /* Fonction visée */ + + func = PyObject_GetAttrString(module, method); + if (func == NULL) return false; + + result = PyCallable_Check(func); + + Py_DECREF(func); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : func = fonction Python à appeler. * +* args = arguments à associer à l'opération. * +* * +* Description : Appelle une routine Python. * +* * +* Retour : Retour obtenu ou NULL si erreur. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyObject *_run_python_method(PyObject *func, PyObject *args) +{ + PyObject *result; /* Bilan à retourner */ + + result = NULL; + + if (PyCallable_Check(func)) + { + result = PyObject_CallObject(func, args); + if (result == NULL) PyErr_Print(); + } + else if (PyErr_Occurred()) PyErr_Print(); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : target = propriétaire de la routine visée. * +* method = désignation de la fonction à appeler. * +* args = arguments à associer à l'opération. * +* * +* Description : Appelle une routine Python. * +* * +* Retour : Retour obtenu ou NULL si erreur. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyObject *run_python_method(PyObject *module, const char *method, PyObject *args) +{ + PyObject *result; /* Bilan à retourner */ + PyObject *func; /* Fonction visée */ + + result = NULL; + + func = PyObject_GetAttrString(module, method); + if (func == NULL) return NULL; + + result = _run_python_method(func, args); + + Py_DECREF(func); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : obj_type = type dont le dictionnaire est à compléter. * +* key = désignation de la constante à intégrer. * +* value = valeur de la constante à intégrer. * +* * +* Description : Ajoute une constante au dictionnaire d'un type Python donné. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool PyDict_AddIntConstant(PyTypeObject *obj_type, const char *key, long value) +{ + bool result; /* Bilan à retourner */ + PyObject *item; /* Nouvel élément à insérer */ + int ret; /* Bilan d'un ajout */ + + item = PyLong_FromLong(value); + + ret = PyDict_SetItemString(obj_type->tp_dict, key, item); + result = (ret != -1); + + Py_DECREF(item); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : obj_type = type dont le dictionnaire est à compléter. * +* key = désignation de la constante à intégrer. * +* value = valeur de la constante à intégrer. * +* * +* Description : Ajoute une constante au dictionnaire d'un type Python donné. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool PyDict_AddStringConstant(PyTypeObject *obj_type, const char *key, const char *value) +{ + bool result; /* Bilan à retourner */ + PyObject *item; /* Nouvel élément à insérer */ + int ret; /* Bilan d'un ajout */ + + item = PyUnicode_FromString(value); + + ret = PyDict_SetItemString(obj_type->tp_dict, key, item); + result = (ret != -1); + + Py_DECREF(item); + + return result; + +} + + + +/* ---------------------------------------------------------------------------------- */ +/* CONFORTS CIBLANT PYGOBJECT */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : spec = définition à mettre en place dynamiquement. * +* * +* Description : Définit dans le tas de Python un nouveau type. * +* * +* Retour : Nouveau type prêt à emploi. * +* * +* Remarques : - * +* * +******************************************************************************/ + +PyTypeObject *define_python_dynamic_type(const PyTypeObject *spec) +{ + PyTypeObject *result; /* Définition créée à renvoyer */ + PyTypeObject *type; /* Type de tous les types */ + size_t size; /* Taille de la définition */ + char *s; /* Marqueur de début de chaîne */ + PyHeapTypeObject *hobj; /* Version réelle du type créé */ + + /** + * Le cahier des charges est ici d'éviter les erreurs suivantes : + * + * TypeError: type 'XXX' is not dynamically allocated but its base type 'YYY' is dynamically allocated + * Fatal Python error: unexpected exception during garbage collection + * + * L'allocation dynamique est marquée par le fanion Py_TPFLAGS_HEAPTYPE. + * + * Une des rares fonctions qui appliquent ce fanion est PyType_FromSpecWithBases(), + * mais elle appelle ensuite PyType_Ready(), ce qui est incompatible avec des modifications + * utltérieures avant un appel à pygobject_register_class(). + * + * Le code suivant s'inspire fortement des méthodes originales de Python, + * dont les mécanismes employés par PyType_GenericAlloc(). + */ + + type = &PyType_Type; + size = _PyObject_SIZE(type); + + if (PyType_IS_GC(type)) + result = (PyTypeObject *)_PyObject_GC_Malloc(size); + else + result = (PyTypeObject *)PyObject_MALLOC(size); + + if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) + Py_INCREF(type); + + /* Définitions sommaires */ + + memset(result, 0, sizeof(PyHeapTypeObject)); + + memcpy(result, spec, sizeof(PyTypeObject)); + + result->tp_flags |= Py_TPFLAGS_HEAPTYPE; + + /* Définitions des noms */ + + /** + * Pour un type dynamique, les désignations ne s'appuient pas sur la partie réservée + * au type, mais sur les données suivantes (cf. type_name() et type_qualname()). + * + * Les deux fonctions désignées sont par ailleurs facilement accessibles : + * + * #0 0x0000555555689bf0 in type_qualname (...) at Objects/typeobject.c:393 + * #1 0x000055555568b3b4 in type_repr (...) at Objects/typeobject.c:855 + * #2 0x0000555555693574 in object_str (...) at Objects/typeobject.c:3511 + * #3 0x0000555555670d02 in PyObject_Str (...) at Objects/object.c:535 + * ... + * + * On s'inspire donc du contenu de PyType_FromSpecWithBases() pour éviter tout + * plantage du fait de données non initialisées. + */ + + hobj = (PyHeapTypeObject *)result; + + s = strrchr(spec->tp_name, '.'); + + if (s == NULL) + s = (char *)spec->tp_name; + else + s++; + + hobj->ht_name = PyUnicode_FromString(s); + assert(hobj->ht_name != NULL); + + hobj->ht_qualname = hobj->ht_name; + Py_INCREF(hobj->ht_qualname); + + result->tp_as_async = &hobj->as_async; + result->tp_as_number = &hobj->as_number; + result->tp_as_sequence = &hobj->as_sequence; + result->tp_as_mapping = &hobj->as_mapping; + result->tp_as_buffer = &hobj->as_buffer; + + hobj->ht_cached_keys = _PyDict_NewKeysForClass(); + + + + +#if 0 + if (type->tp_itemsize == 0) + (void)PyObject_INIT(result, type); + else + (void) PyObject_INIT_VAR((PyVarObject *)result, type, 0); + + if (PyType_IS_GC(type)) + _PyObject_GC_TRACK(result); +#endif + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module où conserver une référence au type créé. * +* gtype = type dans sa version GLib. * +* type = type dans sa version Python. * +* base = type de base de l'objet. * +* * +* Description : Enregistre correctement une surcouche de conversion GObject. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool _register_class_for_pygobject(PyObject *dict, GType gtype, PyTypeObject *type, PyTypeObject *base, ...) +{ + bool result; /* Bilan à retourner */ + Py_ssize_t size; /* Taille de liste actuelle */ + PyObject *static_bases; /* Base(s) de l'objet */ + va_list ap; /* Parcours des arguments */ + PyTypeObject *static_base; /* Base à rajouter à la liste */ + + /** + * pygobject_register_class() définit type->tp_base à partir des arguments fournis, + * puis fait appel à PyType_Ready(). + * + * PyType_Ready() complète la définition via inherit_special() : + * + * type->tp_basicsize = type->tp_base->tp_basicsize + * + * Cependant, il y a un appel à mro_internal() avant, qui mène à solid_base() + * puis à extra_ivars(). Et là : + * + * size_t t_size = type->tp_basicsize; + * size_t b_size = base->tp_basicsize; + * + * assert(t_size >= b_size); + * + * Si le type de base est spécifié, une taille doit être indiquée. + * + * Et quelqu'un doit se coller à la tâche. PyGObject ne fait rien, donc... + */ + + if (type->tp_basicsize < base->tp_basicsize) + { + assert(type->tp_basicsize == 0); + type->tp_basicsize = base->tp_basicsize; + } + + size = 1; + static_bases = PyTuple_New(size); + + Py_INCREF(base); + PyTuple_SetItem(static_bases, 0, (PyObject *)base); + + va_start(ap, base); + + while (1) + { + static_base = va_arg(ap, PyTypeObject *); + + if (static_base == NULL) break; + + _PyTuple_Resize(&static_bases, ++size); + + Py_INCREF(static_base); + PyTuple_SetItem(static_bases, size - 1, (PyObject *)static_base); + + } + + va_end(ap); + + + + /* +#0 0x000055555565aad4 in insertdict (mp=0x7fffe7c2c8a8, key='GenConfig', hash=262970853803706525, value=) at ../Objects/dictobject.c:801 +#1 0x000055555565bf62 in PyDict_SetItem (op={'__doc__': 'Python module for Chrysalide.glibext', '__name__': 'pychrysalide.glibext', 'BufferLine': , '__spec__': None, 'ConfigParam': , '__package__': None, 'Buffercache': , 'ConfigParamIterator': , '__loader__': None}, key='GenConfig', value=) at ../Objects/dictobject.c:1227 +#2 0x00005555556610b0 in PyDict_SetItemString (v={'__doc__': 'Python module for Chrysalide.glibext', '__name__': 'pychrysalide.glibext', 'BufferLine': , '__spec__': None, 'ConfigParam': , '__package__': None, 'Buffercache': , 'ConfigParamIterator': , '__loader__': None}, key=0x7ffff69cd0bd "GenConfig", item=) at ../Objects/dictobject.c:2870 +#3 0x00007ffff69b3d12 in _register_class_for_pygobject (dict={'__doc__': 'Python module for Chrysalide.glibext', '__name__': 'pychrysalide.glibext', 'BufferLine': , '__spec__': None, 'ConfigParam': , '__package__': None, 'Buffercache': , 'ConfigParamIterator': , '__loader__': None}, gtype=93824998785328, type=0x7ffff6bd9ce0 , base=0x7fffe80e72a0 ) at helpers.c:320 + */ + + + + //type->tp_weaklistoffset = offsetof(PyGObject, weakreflist); + //type->tp_dictoffset = offsetof(PyGObject, inst_dict); + + pygobject_register_class(dict, NULL, gtype, type, static_bases); + + if (PyErr_Occurred() == NULL) + result = true; + + else + { + PyErr_Print(); + result = false; + } + + assert(PyErr_Occurred() == NULL); + + return result; + +} diff --git a/plugins/pychrysalide/helpers.h b/plugins/pychrysalide/helpers.h new file mode 100644 index 0000000..9c914e5 --- /dev/null +++ b/plugins/pychrysalide/helpers.h @@ -0,0 +1,93 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * helpers.h - prototypes pour la simplification des interactions de base avec Python + * + * Copyright (C) 2012-2017 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 . + */ + + +#ifndef _PLUGINS_PYCHRYSALIDE_HELPERS_H +#define _PLUGINS_PYCHRYSALIDE_HELPERS_H + + +#include +#include +#include + + + +/* ---------------------- ACCELERATEURS POUR PYTHON UNIQUEMENT ---------------------- */ + + +/* Traduit pour Python le bilan d'une comparaison riche. */ +PyObject *status_to_rich_cmp_state(int, int); + +/* Indique si une routine Python existe ou non. */ +bool has_python_method(PyObject *, const char *); + +/* Appelle une routine Python. */ +PyObject *_run_python_method(PyObject *, PyObject *); + +/* Appelle une routine Python. */ +PyObject *run_python_method(PyObject *, const char *, PyObject *); + +/* Ajoute une constante au dictionnaire d'un type Python donné. */ +bool PyDict_AddIntConstant(PyTypeObject *, const char *, long); + +/* Ajoute une constante au dictionnaire d'un type Python donné. */ +bool PyDict_AddStringConstant(PyTypeObject *, const char *, const char *); + + +#define PyDict_AddIntMacro(tp, c) PyDict_AddIntConstant(tp, #c, c) +#define PyDict_AddStringMacro(tp, c) PyDict_AddStringConstant(tp, #c, c) + + + +/* --------------------------- CONFORTS CIBLANT PYGOBJECT --------------------------- */ + + +/** + * Quelque chose est mal fait au niveau de l'abstraction GObject. + * Du coup, Py_TPFLAGS_IS_ABSTRACT n'est pas pris en compte. + * On force alors la méthode de base pour obtenir un traitement correct. + * + * Cf. http://stackoverflow.com/questions/20432335/can-python-abstract-base-classes-inherit-from-c-extensions + */ +#define APPLY_ABSTRACT_FLAG(tp) tp->tp_new = PyBaseObject_Type.tp_new + + +/* Définit dans le tas de Python un nouveau type. */ +PyTypeObject *define_python_dynamic_type(const PyTypeObject *); + +/* Enregistre correctement une surcouche de conversion GObject. */ +bool _register_class_for_pygobject(PyObject *, GType, PyTypeObject *, PyTypeObject *, ...); + +#define register_class_for_pygobject(dict, gtype, type, base) \ + _register_class_for_pygobject(dict, gtype, type, base, NULL) + + +/** + * Quand on remplace un objet GLib dans le dos de Python, il faut + * le remplacer de la même manière qu'on l'a obtenu ! + */ + +#define pygobject_set(p, v) ((PyGObject *)(p))->obj = (GObject *)v + + + +#endif /* _PLUGINS_PYCHRYSALIDE_HELPERS_H */ diff --git a/plugins/pychrysalide/plugin.c b/plugins/pychrysalide/plugin.c new file mode 100644 index 0000000..fad0084 --- /dev/null +++ b/plugins/pychrysalide/plugin.c @@ -0,0 +1,809 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * plugin.c - interactions avec un greffon Python + * + * Copyright (C) 2012-2017 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 "plugin.h" + + +#include +#include + + +#include +#include "../../src/core/formats.h" +//#include +#include + + +#include "helpers.h" + + + +/* --------------------- INTERFACE INTERNE POUR GREFFONS PYTHON --------------------- */ + + +/* Ligne de représentation de code binaire (instance) */ +struct _GPythonPlugin +{ + GPluginModule parent; /* Instance parente */ + + PyObject *module; /* Script Python chargé */ + PyObject *instance; /* Instance Python du greffon */ + +}; + + +/* Ligne de représentation de code binaire (classe) */ +struct _GPythonPluginClass +{ + GPluginModuleClass parent; /* Classe parente */ + +}; + + +/* Initialise la classe des greffons Python. */ +static void g_python_plugin_class_init(GPythonPluginClass *); + +/* Initialise l'instance d'un greffon Python. */ +static void g_python_plugin_init(GPythonPlugin *); + +/* Reconstruit la déclaration d'interface à partir de lectures. */ +static bool g_python_plugin_read_interface(GPythonPlugin *); + +/* Procède à l'initialisation du greffon. */ +static bool g_python_plugin_do_init(GPythonPlugin *); + +/* Procède à l'extinction du greffon. */ +static bool g_python_plugin_do_exit(GPythonPlugin *, GObject *); + +/* Indique si le format peut être pris en charge ici. */ +FormatMatchStatus python_plugin_is_matching(GBinContent *, GExeFormat *, GPythonPlugin *, char **); + +/* Exécute une action pendant un désassemblage de binaire. */ +static void g_python_plugin_process_disass(const GPythonPlugin *, PluginAction, GLoadedBinary *); + + + +/* ------------------------- MODULE PYTHON POUR LES SCRIPTS ------------------------- */ + + +/* Définit les constantes pour les greffons en Python. */ +static bool py_plugin_module_define_constants(PyTypeObject *); + + + +/* ---------------------------------------------------------------------------------- */ +/* INTERFACE INTERNE POUR GREFFONS PYTHON */ +/* ---------------------------------------------------------------------------------- */ + + +/* Indique le type définit par la GLib pour le greffon Python. */ +G_DEFINE_TYPE(GPythonPlugin, g_python_plugin, G_TYPE_PLUGIN_MODULE); + + +/****************************************************************************** +* * +* Paramètres : klass = classe à initialiser. * +* * +* Description : Initialise la classe des greffons Python. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_python_plugin_class_init(GPythonPluginClass *klass) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : plugin = instance à initialiser. * +* * +* Description : Initialise l'instance d'un greffon Python. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_python_plugin_init(GPythonPlugin *plugin) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : modname = nom du module à charger. * +* filename = chemin d'accès au code Python à charger. * +* * +* Description : Crée un greffon à partir de code Python. * +* * +* Retour : Adresse de la structure mise en place ou NULL si erreur. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GPluginModule *g_python_plugin_new(const char *modname, const char *filename) +{ + GPythonPlugin *result; /* Structure à retourner */ + PyObject *name; /* Chemin d'accès pour Python */ + PyObject *module; /* Script Python chargé */ + PyObject *err_type; /* Type d'erreur Python */ + PyObject *err_value; /* Instance Python d'erreur */ + PyObject *err_traceback; /* Trace Python associée */ + PyObject *err_string; /* Description Python d'erreur */ + const char *err_msg; /* Représentation humaine */ + PyObject *dict; /* Dictionnaire associé */ + PyObject *class; /* Classe à instancier */ + PyObject *instance; /* Instance Python du greffon */ + size_t i; /* Boucle de parcours */ + uint32_t action; /* Identifiant d'une action */ + uint32_t category; /* Catégorie principale */ + uint32_t sub; /* Sous-catégorie visée */ + + name = PyUnicode_FromString(modname); + if (name == NULL) goto gppn_bad_exit; + + module = PyImport_Import(name); + Py_DECREF(name); + + if (PyErr_Occurred()) + { + PyErr_Fetch(&err_type, &err_value, &err_traceback); + + if (err_value == NULL) + log_variadic_message(LMT_ERROR, + _("An unknown error occured when importing '%s'..."), modname); + else + { + err_string = PyObject_Str(err_value); + err_msg = PyUnicode_AsUTF8(err_string); + + log_variadic_message(LMT_ERROR, + _("An error occured when importing '%s': \"%s\""), modname, err_msg); + + Py_DECREF(err_string); + Py_DECREF(err_value); + + } + + Py_XDECREF(err_traceback); + Py_XDECREF(err_type); + + Py_XDECREF(module); + + module = NULL; + + } + + if (module == NULL) goto gppn_bad_exit; + + dict = PyModule_GetDict(module); + class = PyDict_GetItemString(dict, "AutoLoad"); + + if (class == NULL) goto gppn_no_class; + if (!PyType_Check(class->ob_type)) goto gppn_no_class; + + instance = PyObject_CallFunction(class, NULL); + if (instance == NULL) goto gppn_no_instance; + + result = g_object_new(G_TYPE_PYTHON_PLUGIN, NULL); + + G_PLUGIN_MODULE(result)->filename = strdup(filename); + + result->module = module; + result->instance = instance; + + if (!g_python_plugin_read_interface(result)) + { + printf("bad interface------------\n"); + goto gppn_interface_error; + } + + /* Localisation des différents points d'entrée déclarés */ + +#define register_python_binding(inst, sym, binding) \ + ({ \ + bool __result; \ + if (!has_python_method(inst, #sym)) \ + { \ + log_variadic_message(LMT_ERROR, \ + _("No '%s' entry in plugin candidate '%s'"), \ + #sym, G_PLUGIN_MODULE(result)->filename); \ + __result = false; \ + } \ + else \ + { \ + G_PLUGIN_MODULE(result)->sym = binding; \ + __result = true; \ + } \ + __result; \ + }) + + for (i = 0; i < G_PLUGIN_MODULE(result)->interface->actions_count; i++) + { + action = G_PLUGIN_MODULE(result)->interface->actions[i]; + category = MASK_PLUGIN_CATEGORY(action); + sub = MASK_PLUGIN_SUB_CATEGORY(action); + + switch (category) + { + case DPC_BASIC: + + switch (sub) + { + case DPS_NONE: + break; + + case PGA_PLUGIN_INIT: + if (!register_python_binding(instance, init, (pg_management_fc)g_python_plugin_do_init)) + goto gppn_bad_plugin; + break; + + case PGA_PLUGIN_EXIT: + if (!register_python_binding(instance, exit, (pg_management_fc)g_python_plugin_do_exit)) + goto gppn_bad_plugin; + break; + + default: + log_variadic_message(LMT_WARNING, + _("Unknown sub-category '0x%02x' in plugin '%s'..."), sub, filename); + break; + + } + + break; + + case DPC_BINARY_PROCESSING: + + switch (sub) + { + case DPS_FORMAT: + + switch (action) + { + case PGA_FORMAT_MATCHER: + + if (!has_python_method(instance, "is_format_matching")) + { + log_variadic_message(LMT_ERROR, + _("No '%s' entry in plugin candidate '%s'"), + "is_format_matching", + G_PLUGIN_MODULE(result)->filename); + goto gppn_bad_plugin; + } + + if (!register_format_matcher((format_match_fc)python_plugin_is_matching, result)) + goto gppn_bad_plugin; + + break; + + case PGA_FORMAT_LOADER_LAST: + /* TODO */ + break; + + default: + log_variadic_message(LMT_WARNING, + _("Unknown action '0x%02x' in plugin '%s'..."), + action, filename); + break; + + } + + break; + + case DPS_DISASSEMBLY: + if (!register_python_binding(instance, process_disass, + (pg_process_disassembly_fc)g_python_plugin_process_disass)) + goto gppn_bad_plugin; + break; + + default: + log_variadic_message(LMT_WARNING, + _("Unknown sub-category '0x%02x' in plugin '%s'..."), sub, filename); + break; + + } + + break; + + default: + log_variadic_message(LMT_WARNING, + _("Unknown category '0x%02x' in plugin '%s'..."), category, filename); + break; + + } + + } + + /* Conclusion */ + + /* + if (!g_plugin_module_load(G_PLUGIN_MODULE(result))) + goto gppn_bad_plugin; + */ + + return G_PLUGIN_MODULE(result); + + gppn_bad_plugin: + + gppn_interface_error: + + g_object_unref(G_OBJECT(result)); + + //Py_DECREF(instance); + + gppn_no_instance: + + gppn_no_class: + + //Py_DECREF(module); + + gppn_bad_exit: + + printf("bad exit :(\n"); + return NULL; + +} + + +/****************************************************************************** +* * +* Paramètres : plugin = greffon à initialiser. * +* * +* Description : Reconstruit la déclaration d'interface à partir de lectures. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool g_python_plugin_read_interface(GPythonPlugin *plugin) +{ + bool result; /* Bilan à renvoyer */ + plugin_interface interface; /* Recueil des éléments */ + PyObject *desc; /* Tableau de description */ + PyObject *str; /* Chaîne de caractères */ + PyObject *tuple; /* Liste d'éléments à traiter */ + Py_ssize_t count; /* Nombre d'éléments présents */ + Py_ssize_t i; /* Boucle de parcours */ + PyObject *action; /* Identifiant d'une action */ + plugin_interface *final; /* Interface finale conservée */ + + result = true; + + desc = run_python_method(plugin->instance, "get_interface", NULL); + if (!PyDict_Check(desc)) + { + result = false; + goto pgpri_end; + } + + memset(&interface, 0, sizeof(interface)); + + /* Chargements des premières chaînes */ + +#define READ_STR_FIELD(name) \ + str = PyDict_GetItemString(desc, #name); \ + if ((result = PyUnicode_Check(str))) \ + interface.name = strdup(PyUnicode_DATA(str)); \ + + READ_STR_FIELD(name); + READ_STR_FIELD(desc); + READ_STR_FIELD(version); + + /* Chargement des actions supportées */ + + tuple = PyDict_GetItemString(desc, "actions"); + + if (!PyList_Check(tuple)) + { + result = false; + goto pgpri_failed; + } + + count = PyList_GET_SIZE(tuple); + + interface.actions = (plugin_action_t *)calloc(count, sizeof(plugin_action_t)); + interface.actions_count = count; + + for (i = 0; i < count; i++) + { + action = PyList_GET_ITEM(tuple, i); + + interface.actions[i] = PyLong_AsLong(action); + + } + + pgpri_failed: + + if (result) + { + final = (plugin_interface *)calloc(1, sizeof(plugin_interface)); + + memcpy(final, &interface, sizeof(interface)); + + G_PLUGIN_MODULE(plugin)->interface = final; + + } + else + { + if (interface.name != NULL) free((char *)interface.name); + if (interface.desc != NULL) free((char *)interface.desc); + if (interface.version != NULL) free((char *)interface.version); + + if (interface.actions != NULL) free(interface.actions); + + } + + pgpri_end: + + Py_XDECREF(desc); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : plugin = greffon à initialiser. * +* ref = espace de référencement global. * +* * +* Description : Procède à l'initialisation du greffon. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool g_python_plugin_do_init(GPythonPlugin *plugin) +{ + bool result; /* Bilan à retourner */ + PyObject *args; /* Arguments pour l'appel */ + PyObject *value; /* Valeur obtenue */ + + args = Py_None; + Py_INCREF(args); + + value = run_python_method(plugin->instance, "init", args); + + result = (value != NULL && PyObject_IsTrue(value)); + + Py_XDECREF(value); + Py_DECREF(args); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : plugin = greffon à initialiser. * +* ref = espace de référencement global. * +* * +* Description : Procède à l'extinction du greffon. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool g_python_plugin_do_exit(GPythonPlugin *plugin, GObject *ref) +{ + bool result; /* Bilan à retourner */ + PyObject *args; /* Arguments pour l'appel */ + PyObject *value; /* Valeur obtenue */ + + args = PyTuple_New(1); + PyTuple_SetItem(args, 0, pygobject_new(ref)); + + value = run_python_method(plugin->instance, "exit", args); + + result = PyObject_IsTrue(value); + + Py_XDECREF(value); + Py_DECREF(args); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : content = contenu binaire à parcourir. * +* parent = éventuel format exécutable déjà chargé. * +* plugin = grefon C interne représentant le grefon Python. * +* key = identifiant de format trouvé ou NULL. [OUT] * +* * +* Description : Indique si le format peut être pris en charge ici. * +* * +* Retour : Conclusion de haut niveau sur la reconnaissance effectuée. * +* * +* Remarques : - * +* * +******************************************************************************/ + +FormatMatchStatus python_plugin_is_matching(GBinContent *content, GExeFormat *parent, GPythonPlugin *plugin, char **key) +{ + FormatMatchStatus result; /* Bilan à renvoyer */ + PyObject *args; /* Arguments pour l'appel */ + PyObject *value; /* Valeur obtenue */ + PyObject *arg; /* Argument en élément de tuple*/ + + result = FMS_UNKNOWN; + + args = PyTuple_New(2); + PyTuple_SetItem(args, 0, pygobject_new(G_OBJECT(content))); + PyTuple_SetItem(args, 1, pygobject_new(G_OBJECT(parent))); + + value = run_python_method(plugin->instance, "is_format_matching", args); + + if (PyTuple_Check(value)) + { + if (PyTuple_Size(value) > 0) + { + arg = PyTuple_GetItem(value, 0); + + if (PyLong_Check(arg)) + { + result = PyLong_AsLong(arg); + + switch (result) + { + case FMS_MATCHED: + + if (PyTuple_Size(value) != 2) + { + g_plugin_module_log_variadic_message(G_PLUGIN_MODULE(plugin), LMT_ERROR, + _("Expecting only a tuple [ status, key ] " \ + "as result for format matching.")); + result = FMS_UNKNOWN; + break; + } + + arg = PyTuple_GetItem(value, 1); + + if (PyUnicode_Check(arg)) + *key = strdup(PyUnicode_AsUTF8(arg)); + + else + { + g_plugin_module_log_variadic_message(G_PLUGIN_MODULE(plugin), LMT_ERROR, + _("Expecting a key string for format matching.")); + result = FMS_UNKNOWN; + } + + break; + + case FMS_FORWARDED: + case FMS_UNKNOWN: + if (PyTuple_Size(value) != 1) + { + g_plugin_module_log_variadic_message(G_PLUGIN_MODULE(plugin), LMT_WARNING, + _("Unused second item for format matching.")); + } + break; + + default: + g_plugin_module_log_variadic_message(G_PLUGIN_MODULE(plugin), LMT_ERROR, + _("Unexpected result for format matching.")); + result = FMS_UNKNOWN; + break; + + } + + } + + else + { + g_plugin_module_log_variadic_message(G_PLUGIN_MODULE(plugin), LMT_ERROR, + _("Unexpected result status for format matching.")); + result = FMS_UNKNOWN; + } + + } + else + g_plugin_module_log_variadic_message(G_PLUGIN_MODULE(plugin), LMT_WARNING, + _("Interpreting a empty tuple as FMS_UNKNOWN " \ + "for format matching.")); + + } + else + g_plugin_module_log_variadic_message(G_PLUGIN_MODULE(plugin), LMT_ERROR, + _("Expected a tuple containing [ status, key ] as result " \ + "for format matching.")); + + Py_XDECREF(value); + Py_DECREF(args); + + return result; + + + + +} + + +/****************************************************************************** +* * +* Paramètres : plugin = greffon à manipuler. * +* action = type d'action attendue. * +* binary = binaire dont le contenu est en cours de traitement. * +* * +* Description : Exécute une action pendant un désassemblage de binaire. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_python_plugin_process_disass(const GPythonPlugin *plugin, PluginAction action, GLoadedBinary *binary) +{ + PyObject *args; /* Arguments pour l'appel */ + PyObject *value; /* Valeurs obtenues */ + + args = PyTuple_New(2); + + PyTuple_SetItem(args, 0, PyLong_FromLong(action)); + PyTuple_SetItem(args, 1, pygobject_new(G_OBJECT(binary))); + + value = run_python_method(plugin->instance, "process_binary_disassembly", args); + + Py_XDECREF(value); + Py_DECREF(args); + +} + + + +/* ---------------------------------------------------------------------------------- */ +/* MODULE PYTHON POUR LES SCRIPTS */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : obj_type = type dont le dictionnaire est à compléter. * +* * +* Description : Définit les constantes pour les greffons en Python. * +* * +* Retour : true en cas de succès de l'opération, false sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool py_plugin_module_define_constants(PyTypeObject *obj_type) +{ + bool result; /* Bilan à retourner */ + + result = true; + + result &= PyDict_AddIntMacro(obj_type, PGA_BASIC_NONE); + result &= PyDict_AddIntMacro(obj_type, PGA_PLUGIN_INIT); + result &= PyDict_AddIntMacro(obj_type, PGA_PLUGIN_EXIT); + result &= PyDict_AddIntMacro(obj_type, PGA_FORMAT_MATCHER); + result &= PyDict_AddIntMacro(obj_type, PGA_FORMAT_LOADER_LAST); + result &= PyDict_AddIntMacro(obj_type, PGA_DISASSEMBLY_STARTED); + result &= PyDict_AddIntMacro(obj_type, PGA_DISASSEMBLY_RAW); + result &= PyDict_AddIntMacro(obj_type, PGA_DISASSEMBLY_HOOKED_LINK); + result &= PyDict_AddIntMacro(obj_type, PGA_DISASSEMBLY_HOOKED_POST); + result &= PyDict_AddIntMacro(obj_type, PGA_DISASSEMBLY_LIMITED); + result &= PyDict_AddIntMacro(obj_type, PGA_DISASSEMBLY_LOOPS); + result &= PyDict_AddIntMacro(obj_type, PGA_DISASSEMBLY_LINKED); + result &= PyDict_AddIntMacro(obj_type, PGA_DISASSEMBLY_GROUPED); + result &= PyDict_AddIntMacro(obj_type, PGA_DISASSEMBLY_RANKED); + result &= PyDict_AddIntMacro(obj_type, PGA_DISASSEMBLY_ENDED); + + 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_plugin_module_type(void) +{ + static PyMethodDef py_plugin_module_methods[] = { + { NULL } + }; + + static PyGetSetDef py_plugin_module_getseters[] = { + { NULL } + }; + + static PyTypeObject py_plugin_module_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.PluginModule", + .tp_basicsize = sizeof(PyGObject), + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + + .tp_doc = "Chrysalide plugin for Python.", + + .tp_methods = py_plugin_module_methods, + .tp_getset = py_plugin_module_getseters + + }; + + return &py_plugin_module_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.PluginModule'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_plugin_module(PyObject *module) +{ + PyTypeObject *py_plugin_module_type; /* Type Python 'PluginModule' */ + PyObject *dict; /* Dictionnaire du module */ + + py_plugin_module_type = get_python_plugin_module_type(); + + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_PLUGIN_MODULE, py_plugin_module_type, &PyGObject_Type)) + return false; + + if (!py_plugin_module_define_constants(py_plugin_module_type)) + return false; + + return true; + +} diff --git a/plugins/pychrysalide/plugin.h b/plugins/pychrysalide/plugin.h new file mode 100644 index 0000000..1b7f7ba --- /dev/null +++ b/plugins/pychrysalide/plugin.h @@ -0,0 +1,75 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * plugin.h - prototypes pour les interactions avec un greffon Python + * + * Copyright (C) 2012-2017 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_PLUGIN_H +#define _PLUGINS_PYCHRYSALIDE_PLUGIN_H + + +#include +#include +#include + + +#include + + + +/* --------------------- INTERFACE INTERNE POUR GREFFONS PYTHON --------------------- */ + + +#define G_TYPE_PYTHON_PLUGIN (g_python_plugin_get_type()) +#define G_PYTHON_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_PYTHON_PLUGIN, GPythonPlugin)) +#define G_IS_PYTHON_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_PYTHON_PLUGIN)) +#define G_PYTHON_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_PYTHON_PLUGIN, GPythonPluginClass)) +#define G_IS_PYTHON_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_PYTHON_PLUGIN)) +#define G_PYTHON_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_PYTHON_PLUGIN, GPythonPluginClass)) + + +/* Ligne de représentation de code binaire (instance) */ +typedef struct _GPythonPlugin GPythonPlugin; + +/* Ligne de représentation de code binaire (classe) */ +typedef struct _GPythonPluginClass GPythonPluginClass; + + +/* Indique le type définit par la GLib pour le greffon Python. */ +GType g_python_plugin_get_type(void); + +/* Crée un greffon à partir de code Python. */ +GPluginModule *g_python_plugin_new(const char *, const char *); + + + +/* ------------------------- MODULE PYTHON POUR LES SCRIPTS ------------------------- */ + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_plugin_module_type(void); + +/* Prend en charge l'objet 'pychrysalide.PluginModule'. */ +bool register_python_plugin_module(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_PLUGIN_H */ diff --git a/plugins/pychrysalide/pychrysa.c b/plugins/pychrysalide/pychrysa.c new file mode 100644 index 0000000..35d14f4 --- /dev/null +++ b/plugins/pychrysalide/pychrysa.c @@ -0,0 +1,616 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * pychrysa.c - plugin permettant des extensions en Python + * + * Copyright (C) 2012-2017 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 "pychrysa.h" + + +#include +#include +#include +#include +#include +#include +#include + + +#include +#include +#include +#include +#include +#include +#include +#include + + +#include "helpers.h" +#include "plugin.h" +#include "struct.h" +#include "analysis/module.h" +#include "arch/module.h" +#include "common/module.h" +#include "core/module.h" +#include "debug/module.h" +#include "format/module.h" +#include "glibext/module.h" +#include "gtkext/module.h" +#include "gui/module.h" + + + +DEFINE_CHRYSALIDE_ACTIVE_PLUGIN("PyChrysalide", "Provides bindings to Python", "0.1.0", PGA_PLUGIN_INIT); + + +/* Note la nature du chargement */ +static bool _standalone = true; + +/* Réceptacle pour le chargement forcé */ +static PyObject *_chrysalide_module = NULL; + + +/* Fournit la révision du programme global. */ +static PyObject *py_chrysalide_revision(PyObject *, PyObject *); + +/* Fournit la version du programme global. */ +static PyObject *py_chrysalide_version(PyObject *, PyObject *); + +/* Fournit la version du greffon pour Python. */ +static PyObject *py_chrysalide_mod_version(PyObject *, PyObject *); + +/* Détermine si l'interpréteur lancé est celui pris en compte. */ +static bool is_current_abi_suitable(void); + +/* Définit la version attendue de GTK à charger dans Python. */ +static bool set_version_for_gtk_namespace(const char *); + +/* Charge autant de greffons composés en Python que possible. */ +static bool load_python_plugins(GPluginModule *); + + + +/****************************************************************************** +* * +* Paramètres : self = NULL car méthode statique. * +* args = non utilisé ici. * +* * +* Description : Fournit la révision du programme global. * +* * +* Retour : Numéro de révision. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_chrysalide_revision(PyObject *self, PyObject *args) +{ + return PyUnicode_FromString("r" XSTR(REVISION)); + +} + + +/****************************************************************************** +* * +* Paramètres : self = NULL car méthode statique. * +* args = non utilisé ici. * +* * +* Description : Fournit la version du programme global. * +* * +* Retour : Numéro de version. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_chrysalide_version(PyObject *self, PyObject *args) +{ + char version[16]; + int major; + int minor; + int revision; + + major = REVISION / 1000; + minor = (REVISION - (major * 1000)) / 100; + revision = REVISION % 100; + + snprintf(version, sizeof(version), "%d.%d.%d", major, minor, revision); + + return PyUnicode_FromString(version); + +} + + +/****************************************************************************** +* * +* Paramètres : self = NULL car méthode statique. * +* args = non utilisé ici. * +* * +* Description : Fournit la version du greffon pour Python. * +* * +* Retour : Numéro de version. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_chrysalide_mod_version(PyObject *self, PyObject *args) +{ + char version[16]; + + snprintf(version, sizeof(version), "%s", _chrysalide_plugin.version); + + return PyUnicode_FromString(version); + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Détermine si l'interpréteur lancé est celui pris en compte. * +* * +* Retour : true si l'exécution peut se poursuivre, false sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool is_current_abi_suitable(void) +{ + bool result; + int fds[2]; + int ret; + char cmds[128]; + char content[64]; + ssize_t got; + +#define GRAB_ABI_FLAGS_IN_PYTHON \ + "import sys" "\n" \ + "import os" "\n" \ + "os.write(%d, bytes(sys.abiflags, 'UTF-8'))" "\n" + + result = false; + + ret = pipe(fds); + if (ret == -1) + { + perror("pipe()"); + return false; + } + + snprintf(cmds, sizeof(cmds), GRAB_ABI_FLAGS_IN_PYTHON, fds[1]); + + ret = PyRun_SimpleString(cmds); + if (ret != 0) goto icas_exit; + + got = read(fds[0], content, sizeof(content)); + if (got < 0) + { + perror("read()"); + goto icas_exit; + } + + content[got] = '\0'; + + result = (strcmp(content, LIBPYTHON_ABI_FLAGS) == 0); + + icas_exit: + + if (!result) + PyErr_SetString(PyExc_SystemError, "the ABI flags of the current interpreter do not match " \ + "the ones of the Python library used during the module compilation."); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : version = idenfiant de la version de GTK à stipuler. * +* * +* Description : Définit la version attendue de GTK à charger dans Python. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool set_version_for_gtk_namespace(const char *version) +{ + bool result; /* Bilan à retourner */ + PyObject *gi_mod; /* Module Python-GObject */ + PyObject *args; /* Arguments à fournir */ + + result = false; + + /** + * On cherche ici à éviter le message suivant si on charge 'gi.repository.Gtk' directement : + * + * + * PyGIWarning: Gtk was imported without specifying a version first. \ + * Use gi.require_version('Gtk', '3.0') before import to ensure that the right version gets loaded. + * + */ + + gi_mod = PyImport_ImportModule("gi"); + + if (gi_mod != NULL) + { + args = Py_BuildValue("ss", "Gtk", "3.0"); + + run_python_method(gi_mod, "require_version", args); + + result = (PyErr_Occurred() == NULL); + + Py_DECREF(args); + Py_DECREF(gi_mod); + + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Point d'entrée pour l'initialisation de Python. * +* * +* Retour : ? * +* * +* Remarques : - * +* * +******************************************************************************/ +#include // REMME +#include + +#define PYCHRYSALIDE_DOC \ + "PyChrysalide is a module containing Chrysalide's features and designed for Python users.\n" \ + "\n" \ + "The whole API is defined in a single library named 'pychrysalide.so' and can be used in two ways:\n" \ + "* either from the Chrysalide's GUI, by registering hooks or GLib signals.\n" \ + "* or from a shell command line, by setting PYTHONPATH to point to the directory containing the library.\n" \ + "\n" \ + "In both cases, it is a good start point to have a look at already existing plugins to quickly learn " \ + "how the API works.\n" \ + "\n" \ + "These plugins are located in the 'plugins/python' directory." + +PyMODINIT_FUNC PyInit_pychrysalide(void) +{ + PyObject *result; /* Module Python à retourner */ + bool status; /* Bilan des inclusions */ + GPluginModule *self; /* Représentation interne */ + PluginStatusFlags self_flags; /* Fanions à mettre à jour */ + + static PyMethodDef py_chrysalide_methods[] = { + + { "revision", py_chrysalide_revision, + METH_NOARGS, + "revision(/)\n--\n\nProvide the revision number of Chrysalide." + }, + { "version", py_chrysalide_version, + METH_NOARGS, + "version(/)\n--\n\nProvide the version number of Chrysalide." + }, + { "mod_version", py_chrysalide_mod_version, + METH_NOARGS, + "mod_version(/)\n--\n\nProvide the version number of Chrysalide module for Python." + }, + { NULL } + + }; + + static PyModuleDef py_chrysalide_module = { + + .m_base = PyModuleDef_HEAD_INIT, + + .m_name = "pychrysalide", + .m_doc = PYCHRYSALIDE_DOC, + + .m_size = -1, + + .m_methods = py_chrysalide_methods + + }; + +#if 0 + do + { + int argc = 0; + //char *argv[] = { NULL }; + + /* Initialisation de GTK */ + g_set_prgname("Chrysalide"); + setlocale (LC_ALL, ""); + gtk_init(&argc, NULL/*&argv-*/); + + } while (0); + + add_pixmap_directory(PACKAGE_DATA_DIR); + add_pixmap_directory(PACKAGE_SOURCE_DIR G_DIR_SEPARATOR_S "pixmaps"); + + /** + * On évite d'initialiser deux fois... + */ + if (get_work_queue() != NULL) + init_work_queue(NULL/* !! */); +#endif + + + + + + if (!is_current_abi_suitable()) + return NULL; + + if (pygobject_init(-1, -1, -1) == NULL) + { + PyErr_SetString(PyExc_SystemError, "unable to init GObject in Python."); + return NULL; + } + + if (!set_version_for_gtk_namespace("3.0")) + return NULL; + + if (!load_all_basic_components()) + { + PyErr_SetString(PyExc_SystemError, "unable to load all basic components."); + return NULL; + } + + /* Mise en place des fonctionnalités offertes */ + + result = PyModule_Create(&py_chrysalide_module); + + status = register_python_py_struct(result); + + /* Interface 'LineGenerator' en premier... */ + if (status) status = add_glibext_module_to_python_module(result); + + /* BinRoutine hérite de BinSymbol... */ + if (status) status = add_format_module_to_python_module(result); + + if (status) status = register_python_plugin_module(result); + if (status) status = add_analysis_module_to_python_module(result); + if (status) status = add_arch_module_to_python_module(result); + if (status) status = add_common_module_to_python_module(result); + if (status) status = add_core_module_to_python_module(result); + if (status) status = add_debug_module_to_python_module(result); + if (status) status = add_gtkext_module_to_python_module(result); + if (status) status = add_gui_module_to_python_module(result); + + if (!status) + { + PyErr_SetString(PyExc_SystemError, "fail to load all PyChrysalide components."); + return NULL; + } + + if (_standalone) + { + init_all_plugins(false); + + lock_plugin_list_for_reading(); + + self = get_plugin_by_name("PyChrysalide", NULL); + assert(self != NULL); + + self_flags = g_plugin_module_get_flags(self); + self_flags &= ~(PSF_FAILURE | PSF_LOADED); + self_flags |= (status ? PSF_LOADED : PSF_FAILURE); + + g_plugin_module_override_flags(self, self_flags); + + unlock_plugin_list_for_reading(); + + load_remaning_plugins(); + + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : plugin = instance représentant le greffon Python d'origine. * +* * +* Description : Charge autant de greffons composés en Python que possible. * +* * +* Retour : true. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool load_python_plugins(GPluginModule *plugin) +{ + char *paths; /* Emplacements de greffons */ + char *save; /* Sauvegarde pour ré-entrance */ + char *path; /* Chemin à fouiller */ + DIR *dir; /* Répertoire à parcourir */ + struct dirent *entry; /* Elément trouvé */ + char *modname; /* Nom du module pour Python */ + char *filename; /* Chemin d'accès reconstruit */ + GPluginModule *pyplugin; /* Lien vers un grffon Python */ + + paths = get_env_var("PYTHONPATH"); + + save = NULL; /* gcc... */ + + for (path = strtok_r(paths, ":", &save); + path != NULL; + path = strtok_r(NULL, ":", &save)) + { + dir = opendir(path); + if (dir == NULL) + { + perror("opendir"); + continue; + } + + g_plugin_module_log_variadic_message(plugin, LMT_INFO, + _("Looking for Python plugins in '%s'..."), + path); + + while (1) + { + errno = 0; + + entry = readdir(dir); + + if (entry == NULL) + { + if (errno != 0) + perror("readdir"); + + break; + + } + + if (entry->d_type != DT_DIR) continue; + if (entry->d_name[0] == '.') continue; + + modname = strdup(entry->d_name); + modname = stradd(modname, "."); + modname = stradd(modname, "__init__"); + + filename = strdup(path); + filename = stradd(filename, G_DIR_SEPARATOR_S); + filename = stradd(filename, entry->d_name); + + pyplugin = g_python_plugin_new(modname, filename); + + if (pyplugin == NULL) + g_plugin_module_log_variadic_message(plugin, LMT_ERROR, + _("No suitable Python plugin found in '%s'"), + filename); + else + { + g_plugin_module_log_variadic_message(plugin, LMT_PROCESS, + _("Loaded the Python plugin found in the '%s' directory"), + filename); + _register_plugin(pyplugin); + } + + free(filename); + free(modname); + + } + + closedir(dir); + + } + + return true; + +} + + +/****************************************************************************** +* * +* Paramètres : plugin = greffon à manipuler. * +* * +* Description : Prend acte du chargement du greffon. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +G_MODULE_EXPORT bool chrysalide_plugin_init(GPluginModule *plugin) +{ + bool result; /* Bilan à retourner */ + DIR *dir; /* Répertoire à parcourir */ + int ret; /* Bilan de préparatifs */ + + /* Définition des zones d'influence */ + + dir = opendir(PLUGINS_DIR G_DIR_SEPARATOR_S "python"); + + if (dir != NULL) + { + closedir(dir); + add_to_env_var("PYTHONPATH", PLUGINS_DIR G_DIR_SEPARATOR_S "python", ":"); + } + else + add_to_env_var("PYTHONPATH", PACKAGE_SOURCE_DIR G_DIR_SEPARATOR_S "plugins" \ + G_DIR_SEPARATOR_S "python", ":"); + + g_plugin_module_log_variadic_message(plugin, LMT_INFO, + _("PYTHONPATH environment variable set to '%s'"), + getenv("PYTHONPATH")); + + /* Chargement du module pour Python */ + + _standalone = false; + + ret = PyImport_AppendInittab("pychrysalide", &PyInit_pychrysalide); + + if (ret == -1) + { + g_plugin_module_log_variadic_message(plugin, LMT_ERROR, + _("Can not extend the existing table of Python built-in modules.")); + result = false; + goto cpi_done; + } + + Py_Initialize(); + + PySys_SetArgv(0, (wchar_t *[]) { NULL }); + + _chrysalide_module = PyImport_ImportModule("pychrysalide"); + + result = load_python_plugins(plugin); + + cpi_done: + + return result; + +} + + + +/****************************************************************************** +* * +* Paramètres : plugin = greffon à manipuler. * +* * +* Description : Prend acte du déchargement du greffon. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +G_MODULE_EXPORT void chrysalide_plugin_exit(GPluginModule *plugin) +{ + Py_XDECREF(_chrysalide_module); + +} diff --git a/plugins/pychrysalide/pychrysa.h b/plugins/pychrysalide/pychrysa.h new file mode 100644 index 0000000..070345b --- /dev/null +++ b/plugins/pychrysalide/pychrysa.h @@ -0,0 +1,99 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * pychrysa.h - prototypes pour le plugin permettant des extensions en Python + * + * Copyright (C) 2012-2017 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 . + */ + + +#ifndef _PLUGINS_PYCHRYSALIDE_H +#define _PLUGINS_PYCHRYSALIDE_H + + +/** + * Note: + * Since Python may define some pre-processor definitions which affect the standard headers + * on some systems, you must include Python.h before any standard headers are included. + * + * cf. https://docs.python.org/3.4/c-api/intro.html + */ +#include + + + + + + +#if 0 + + +#include +#include + + +#include "plugin.h" + + + +/* Précise le nom associé au greffon. */ +char *get_plugin_name(void); + +/* Initialise le greffon permettant l'usage de Python. */ +bool init_plugin(GPluginModule *, GObject *); + +/* Libère le greffon permettant l'usage de Python. */ +void exit_plugin(GPluginModule *); + +/* Indique les opérations offertes par un greffon donné. */ +PluginAction get_plugin_action(const GPluginModule *); + + +#if PY_VERSION_HEX >= 0x03000000 + +/* Point d'entrée pour l'initialisation de Python. */ +//PyMODINIT_FUNC PyInit_pychrysa(void); +PyMODINIT_FUNC initpychrysa(void); + +#else + +/* Point d'entrée pour l'initialisation de Python. */ +PyMODINIT_FUNC initpychrysa(void); + +#endif + +#endif + + + + +#include + + + +/* Point d'entrée pour l'initialisation de Python. */ +PyMODINIT_FUNC PyInit_pychrysalide(void); + +/* Prend acte du chargement du greffon. */ +G_MODULE_EXPORT bool chrysalide_plugin_init(GPluginModule *); + +/* Prend acte du déchargement du greffon. */ +G_MODULE_EXPORT void chrysalide_plugin_exit(GPluginModule *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_H */ diff --git a/plugins/pychrysalide/struct.c b/plugins/pychrysalide/struct.c new file mode 100644 index 0000000..33b58b8 --- /dev/null +++ b/plugins/pychrysalide/struct.c @@ -0,0 +1,161 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * struct.c - prototypes pour la conversion de structures C en équivalent Python + * + * Copyright (C) 2017 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 "struct.h" + + + +/* Objet à vocation abstraite */ +typedef struct _PyStructObject +{ + PyDictObject base; /* A laisser en premier */ + +} PyStructObject; + + +/* Assure l'encadrement des accès aux champs d'une structure. */ +static PyObject *py_struct_getattr(PyObject *, char *); + + + +/****************************************************************************** +* * +* Paramètres : self = structure C convertie en Python. * +* name = nom du champ auquel un accès est demandé. * +* * +* Description : Assure l'encadrement des accès aux champs d'une structure. * +* * +* Retour : Valeur du champ demandé. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static PyObject *py_struct_getattr(PyObject *self, char *name) +{ + PyObject *result; /* Elément à retourner */ + PyObject *w; /* Conversion du nom de champ */ + PyTypeObject *tp; /* Type de l'objet manipulé */ + + result = PyDict_GetItemString(self, name); + + if (result != NULL) + Py_INCREF(result); + + else + { + w = PyUnicode_InternFromString(name); + if (w == NULL) return NULL; + + tp = Py_TYPE(self); + + if (tp->tp_base->tp_getattro != NULL) + result = tp->tp_base->tp_getattro(self, w); + + Py_DECREF(w); + + } + + 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_py_struct_type(void) +{ + static PyMethodDef py_struct_methods[] = { + { NULL } + }; + + static PyGetSetDef py_struct_getseters[] = { + { NULL } + }; + + static PyTypeObject py_struct_type = { + + PyVarObject_HEAD_INIT(NULL, 0) + + .tp_name = "pychrysalide.PyStructObject", + .tp_basicsize = sizeof(PyStructObject), + + .tp_getattr = py_struct_getattr, + + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + + .tp_doc = "PyChrysalide structure", + + .tp_methods = py_struct_methods, + .tp_getset = py_struct_getseters, + .tp_base = &PyDict_Type, + + }; + + return &py_struct_type; + +} + + +/****************************************************************************** +* * +* Paramètres : module = module dont la définition est à compléter. * +* * +* Description : Prend en charge l'objet 'pychrysalide.PyStructObject'. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool register_python_py_struct(PyObject *module) +{ + PyTypeObject *py_struct_type; /* Type Python 'PyStructObject'*/ + int ret; /* Bilan des préparatifs */ + + py_struct_type = get_python_py_struct_type(); + + ret = PyType_Ready(py_struct_type); + + if (ret != 0) + return false; + + Py_INCREF(py_struct_type); + + PyModule_AddObject(module, "PyStructObject", (PyObject *)py_struct_type);; + + return true; + +} diff --git a/plugins/pychrysalide/struct.h b/plugins/pychrysalide/struct.h new file mode 100644 index 0000000..7c5391c --- /dev/null +++ b/plugins/pychrysalide/struct.h @@ -0,0 +1,42 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * struct.h - prototypes pour la conversion de structures C en équivalent Python + * + * Copyright (C) 2017 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_STRUCT_H +#define _PLUGINS_PYCHRYSALIDE_STRUCT_H + + +#include +#include + + + +/* Fournit un accès à une définition de type à diffuser. */ +PyTypeObject *get_python_py_struct_type(void); + +/* Prend en charge l'objet 'pychrysalide.PyStructObject'. */ +bool register_python_py_struct(PyObject *); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_STRUCT_H */ diff --git a/plugins/pychrysalide/weak.c b/plugins/pychrysalide/weak.c new file mode 100644 index 0000000..59c5666 --- /dev/null +++ b/plugins/pychrysalide/weak.c @@ -0,0 +1,129 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * weak.c - définition de symboles qui n'ont pas leur place dans la version autonome + * + * Copyright (C) 2016-2017 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 "weak.h" + + + +/****************************************************************************** +* * +* Paramètres : stack = barre de statut à actualiser. * +* msg = nouveau message de statut à copier. * +* max = taille de la plage à parcourir. * +* * +* Description : Démarre le suivi d'une nouvelle activité. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +activity_id_t gtk_status_stack_add_activity(GtkStatusStack *stack, const char *msg, unsigned long max) +{ + return ~0lu; + +} + + +/****************************************************************************** +* * +* Paramètres : stack = barre de statut à actualiser. * +* id = identifiant de l'activité à cibler. * +* extra = nouvelle échéance supplémentaire des traitements. * +* * +* Description : Etend la portée des travaux d'une nouvelle activité. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void gtk_status_stack_extend_activity(GtkStatusStack *stack, activity_id_t id, unsigned long extra) +{ + ; + +} + + +/****************************************************************************** +* * +* Paramètres : stack = barre de statut à actualiser. * +* id = identifiant de l'activité à cibler. * +* msg = nouveau message de statut à copier. * +* * +* Description : Actualise les informations concernant une activité. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void gtk_status_stack_update_activity(GtkStatusStack *stack, activity_id_t id, const char *msg) +{ + ; + +} + + +/****************************************************************************** +* * +* Paramètres : stack = barre de statut à actualiser. * +* id = identifiant de l'activité à cibler. * +* inc = nouvelle valeur pour une progression donnée. * +* * +* Description : Actualise la progression d'une activité. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void gtk_status_stack_update_activity_value(GtkStatusStack *stack, activity_id_t id, unsigned long inc) +{ + ; + +} + + +/****************************************************************************** +* * +* Paramètres : stack = barre de statut à actualiser. * +* * +* Description : Met fin au suivi d'une activité donnée. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void gtk_status_stack_remove_activity(GtkStatusStack *stack, activity_id_t id) +{ + ; + +} diff --git a/plugins/pychrysalide/weak.h b/plugins/pychrysalide/weak.h new file mode 100644 index 0000000..e5e7d39 --- /dev/null +++ b/plugins/pychrysalide/weak.h @@ -0,0 +1,50 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * weak.h - prototypes pour la définition de symboles qui n'ont pas leur place dans la version autonome + * + * Copyright (C) 2016-2017 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_WEAK_H +#define _PLUGINS_PYCHRYSALIDE_WEAK_H + + +#include + + + +/* Démarre le suivi d'une nouvelle activité. */ +activity_id_t gtk_status_stack_add_activity(GtkStatusStack *, const char *, unsigned long) __attribute__((weak)); + +/* Etend la portée des travaux d'une nouvelle activité. */ +void gtk_status_stack_extend_activity(GtkStatusStack *, activity_id_t, unsigned long) __attribute__((weak)); + +/* Actualise les informations concernant une activité. */ +void gtk_status_stack_update_activity(GtkStatusStack *, activity_id_t, const char *) __attribute__((weak)); + +/* Actualise la progression d'une activité. */ +void gtk_status_stack_update_activity_value(GtkStatusStack *, activity_id_t, unsigned long) __attribute__((weak)); + +/* Met fin au suivi d'une activité donnée. */ +void gtk_status_stack_remove_activity(GtkStatusStack *, activity_id_t) __attribute__((weak)); + + + +#endif /* _PLUGINS_PYCHRYSALIDE_WEAK_H */ -- cgit v0.11.2-87-g4458