From b33a52031c0d44a79604bc8d9036c30bffd020cb Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Thu, 11 Nov 2010 01:22:43 +0000 Subject: Built some expressions for the decompilation tree. git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@190 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a --- ChangeLog | 102 +++++++++++++++++++ configure.ac | 2 + plugins/dexresolver/context.c | 1 + src/Makefile.am | 4 +- src/analysis/binary.c | 16 +++ src/analysis/decomp/decompiler.c | 66 +++++++++++++ src/analysis/routine.c | 87 ++++++++++++++++ src/analysis/routine.h | 15 ++- src/arch/Makefile.am | 3 +- src/arch/dalvik/Makefile.am | 9 +- src/arch/dalvik/dop_aget.c | 68 +++++++++++++ src/arch/dalvik/dop_aput.c | 68 +++++++++++++ src/arch/dalvik/dop_arithm.c | 175 ++++++++++++++++++++++++++++++++ src/arch/dalvik/dop_array.c | 74 ++++++++++++++ src/arch/dalvik/dop_const.c | 72 ++++++++++++++ src/arch/dalvik/dop_invoke.c | 158 +++++++++++++++++++++++++++++ src/arch/dalvik/instruction.c | 110 +++++++++++++++------ src/arch/dalvik/instruction.h | 3 + src/arch/dalvik/translate.h | 56 +++++++++++ src/arch/immediate.c | 87 +++++++++++++++- src/arch/instruction-int.h | 4 +- src/arch/instruction.c | 31 +++++- src/arch/instruction.h | 7 +- src/arch/operand-int.h | 3 + src/arch/operand.c | 21 ++++ src/arch/operand.h | 6 +- src/arch/translate.h | 39 ++++++++ src/decomp/Makefile.am | 8 +- src/decomp/context.c | 153 ++++++++++++++++++++++++++++ src/decomp/context.h | 66 +++++++++++++ src/decomp/expr/Makefile.am | 24 +++++ src/decomp/expr/arithm.c | 197 +++++++++++++++++++++++++++++++++++++ src/decomp/expr/arithm.h | 76 ++++++++++++++ src/decomp/expr/array.c | 161 ++++++++++++++++++++++++++++++ src/decomp/expr/array.h | 61 ++++++++++++ src/decomp/expr/assign.c | 159 ++++++++++++++++++++++++++++++ src/decomp/expr/assign.h | 60 +++++++++++ src/decomp/expr/block.c | 185 ++++++++++++++++++++++++++++++++++ src/decomp/expr/block.h | 62 ++++++++++++ src/decomp/expr/call.c | 163 ++++++++++++++++++++++++++++++ src/decomp/expr/call.h | 61 ++++++++++++ src/decomp/expr/dalvik/Makefile.am | 14 +++ src/decomp/expr/dalvik/array.c | 155 +++++++++++++++++++++++++++++ src/decomp/expr/dalvik/array.h | 61 ++++++++++++ src/decomp/expr/immediate.c | 150 ++++++++++++++++++++++++++++ src/decomp/expr/immediate.h | 61 ++++++++++++ src/decomp/expr/pseudo.c | 148 ++++++++++++++++++++++++++++ src/decomp/expr/pseudo.h | 59 +++++++++++ src/decomp/expression-int.h | 50 ++++++++++ src/decomp/expression.c | 76 ++++++++++++++ src/decomp/expression.h | 53 ++++++++++ src/decomp/instruction-int.h | 58 +++++++++++ src/decomp/instruction.c | 101 +++++++++++++++++++ src/decomp/instruction.h | 59 +++++++++++ src/decomp/output.h | 3 + src/format/format.c | 119 ++++++++++++++++++++++ src/format/format.h | 8 +- src/glibext/gbufferline.c | 10 ++ src/glibext/gbufferline.h | 1 + 59 files changed, 3866 insertions(+), 43 deletions(-) create mode 100644 src/arch/dalvik/dop_aget.c create mode 100644 src/arch/dalvik/dop_aput.c create mode 100644 src/arch/dalvik/dop_arithm.c create mode 100644 src/arch/dalvik/dop_array.c create mode 100644 src/arch/dalvik/dop_const.c create mode 100644 src/arch/dalvik/dop_invoke.c create mode 100644 src/arch/dalvik/translate.h create mode 100644 src/arch/translate.h create mode 100644 src/decomp/context.c create mode 100644 src/decomp/context.h create mode 100644 src/decomp/expr/Makefile.am create mode 100644 src/decomp/expr/arithm.c create mode 100644 src/decomp/expr/arithm.h create mode 100644 src/decomp/expr/array.c create mode 100644 src/decomp/expr/array.h create mode 100644 src/decomp/expr/assign.c create mode 100644 src/decomp/expr/assign.h create mode 100644 src/decomp/expr/block.c create mode 100644 src/decomp/expr/block.h create mode 100644 src/decomp/expr/call.c create mode 100644 src/decomp/expr/call.h create mode 100644 src/decomp/expr/dalvik/Makefile.am create mode 100644 src/decomp/expr/dalvik/array.c create mode 100644 src/decomp/expr/dalvik/array.h create mode 100644 src/decomp/expr/immediate.c create mode 100644 src/decomp/expr/immediate.h create mode 100644 src/decomp/expr/pseudo.c create mode 100644 src/decomp/expr/pseudo.h create mode 100644 src/decomp/expression-int.h create mode 100644 src/decomp/expression.c create mode 100644 src/decomp/expression.h create mode 100644 src/decomp/instruction-int.h create mode 100644 src/decomp/instruction.c create mode 100644 src/decomp/instruction.h diff --git a/ChangeLog b/ChangeLog index 52191ec..c45262b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,105 @@ +10-11-11 Cyrille Bagard + + * configure.ac: + Add the new Makefiles from the 'src/decomp/expr' and + 'src/decomp/expr/dalvik' directories to AC_CONFIG_FILES. + + * plugins/dexresolver/context.c: + Add a reminder for improving the code later. + + * src/analysis/binary.c: + Attach instructions to disassembled routines. + + * src/analysis/decomp/decompiler.c: + Improve the decompilation process. + + * src/analysis/routine.c: + * src/analysis/routine.h: + Define ways to get/set disassembled/decompiled instructions. + + * src/arch/dalvik/dop_aget.c: + * src/arch/dalvik/dop_aput.c: + * src/arch/dalvik/dop_arithm.c: + * src/arch/dalvik/dop_array.c: + * src/arch/dalvik/dop_const.c: + * src/arch/dalvik/dop_invoke.c: + New entries: translate some Dalvik opcodes into decompilation expressions. + + * src/arch/dalvik/instruction.c: + * src/arch/dalvik/instruction.h: + * src/arch/dalvik/Makefile.am: + Add the dop*c and translate.h files to libarchdalvik_la_SOURCES. + + * src/arch/dalvik/translate.h: + New entry: register all Dalvik decompilation routines. + + * src/arch/immediate.c: + Print values as human-friendly text in a simple way. + + * src/arch/instruction.c: + * src/arch/instruction.h: + * src/arch/instruction-int.h: + Add a function to decompile instructions. + + * src/arch/Makefile.am: + Add the translate.h file to libarch_la_SOURCES. + + * src/arch/operand.c: + * src/arch/operand.h: + * src/arch/operand-int.h: + Print operands in a simple way. + + * src/arch/translate.h: + New entry: define only one prototype. + + * src/decomp/context.c: + * src/decomp/context.h: + New entries: prepare a context for the decompilation process. + + * src/decomp/expr/arithm.c: + * src/decomp/expr/arithm.h: + * src/decomp/expr/array.c: + * src/decomp/expr/array.h: + * src/decomp/expr/assign.c: + * src/decomp/expr/assign.h: + * src/decomp/expr/block.c: + * src/decomp/expr/block.h: + * src/decomp/expr/call.c: + * src/decomp/expr/call.h: + * src/decomp/expr/dalvik/array.c: + * src/decomp/expr/dalvik/array.h: + * src/decomp/expr/dalvik/Makefile.am: + * src/decomp/expression.c: + * src/decomp/expression.h: + * src/decomp/expression-int.h: + * src/decomp/expr/immediate.c: + * src/decomp/expr/immediate.h: + * src/decomp/expr/Makefile.am: + * src/decomp/expr/pseudo.c: + * src/decomp/expr/pseudo.h: + * src/decomp/instruction.c: + * src/decomp/instruction.h: + * src/decomp/instruction-int.h: + New entries: build some expressions for the decompilation tree. + + * src/decomp/Makefile.am: + Add the context.[ch], expression*[ch] and instruction*[ch] files to + libdecomp_la_SOURCES. Add expr/libdecompexpr.la to libdecomp_la_LIBADD. + + * src/decomp/output.h: + Define lang_t as identifier for languages. + + * src/format/format.c: + * src/format/format.h: + Run the decompilation process and print the results for a given routine. + + * src/glibext/gbufferline.c: + * src/glibext/gbufferline.h: + Create a new attribute: RTT_PUNCT. + + * src/Makefile.am: + Fix the compilation order and the final link. + 10-11-06 Cyrille Bagard * configure.ac: diff --git a/configure.ac b/configure.ac index a9f0420..9b0d4ca 100644 --- a/configure.ac +++ b/configure.ac @@ -254,6 +254,8 @@ AC_CONFIG_FILES([Makefile src/debug/ptrace/Makefile src/debug/remgdb/Makefile src/decomp/Makefile + src/decomp/expr/Makefile + src/decomp/expr/dalvik/Makefile src/decomp/lang/Makefile src/dialogs/Makefile src/format/Makefile diff --git a/plugins/dexresolver/context.c b/plugins/dexresolver/context.c index 0b863e9..19be9c0 100644 --- a/plugins/dexresolver/context.c +++ b/plugins/dexresolver/context.c @@ -223,6 +223,7 @@ static void g_dex_resolver_work_process(GDexResolverWork *work, GtkExtStatusBar instr = g_code_line_get_instruction(G_CODE_LINE(iter)); count = g_arch_instruction_count_operands(instr); + /* FIXME : l'opérande recherchée est à position fixe ! */ for (i = 0; i < count; i++) { op = g_arch_instruction_get_operand(instr, i); diff --git a/src/Makefile.am b/src/Makefile.am index f1fce92..7ef9192 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -41,7 +41,7 @@ liboidaglibext_la_LIBADD = \ liboidagtkext_la_SOURCES = liboidagtkext_la_LDFLAGS = $(LIBGTK_LIBS) $(LIBGRAPH_LIBS) \ - -L.libs -loidadisass + -L.libs -loidadisass liboidagtkext_la_LIBADD = \ graph/libgraph.la \ @@ -93,7 +93,7 @@ AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) openida_LDFLAGS = $(LIBGTK_LIBS) -L/usr/X11R6/lib -ldl -lm $(LIBXML_LIBS) `pkg-config --libs gthread-2.0` $(LIBPYTHON_LIBS) $(LIBVTE_LIBS) \ - -L.libs -loidadisass -loidagtkext \ + -L.libs -loidaglibext -loidadisass -loidagtkext \ -Lcommon/.libs -lcommon \ -Lpanels/.libs -lpanels \ -Lplugins/.libs -lplugins diff --git a/src/analysis/binary.c b/src/analysis/binary.c index 949bb31..0159b29 100644 --- a/src/analysis/binary.c +++ b/src/analysis/binary.c @@ -593,6 +593,22 @@ static void limit_all_routines(GRenderingLine *lines, GBinRoutine **routines, si for (i = 0; i < count; i++) { + /* Instruction de départ */ + + /* FIXME : faire mieux ! */ + + line = g_rendering_line_find_by_address(lines, NULL, starts[i]); + if (line != NULL) line = g_rendering_line_loop_for_code(line, NULL); + + if (line != NULL) + { + instr = g_code_line_get_instruction(G_CODE_LINE(line)); + + g_binary_routine_set_instructions(routines[i], instr); + + } + + if (lengths[i] > 0) continue; start = g_binary_routine_get_address(routines[i]); diff --git a/src/analysis/decomp/decompiler.c b/src/analysis/decomp/decompiler.c index 284d3e1..9e8ec38 100644 --- a/src/analysis/decomp/decompiler.c +++ b/src/analysis/decomp/decompiler.c @@ -34,12 +34,16 @@ #include "../../decomp/output.h" #include "../../decomp/lang/java.h" /* FIXME : remme ! */ +#include "../../format/format.h" /* Construit la description d'introduction de la décompilation. */ static void build_decomp_prologue(GCodeBuffer *, const char *); +/* S'assure de la transcription de routines en expressions. */ +static void prepare_all_routines_for_decomp(const GOpenidaBinary *, const char *); + /****************************************************************************** @@ -108,6 +112,59 @@ static void build_decomp_prologue(GCodeBuffer *buffer, const char *filename) * Paramètres : binary = représentation de binaire chargé. * * filename = nom du fichier source à cibler. * * * +* Description : S'assure de la transcription de routines en expressions. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void prepare_all_routines_for_decomp(const GOpenidaBinary *binary, const char *filename) +{ + GExeFormat *format; /* Format du binaire fourni */ + + GBinRoutine **routines; + size_t count; + + size_t i; + + GDecInstruction *instr; + + format = g_openida_binary_get_format(binary); + + + routines = g_binary_format_get_routines(G_BIN_FORMAT(format), &count); + + + + for (i = 0; i < count; i++) + { + //printf(" -- %s --\n", g_binary_routine_get_name(routines[i])); + + if (strcmp("cryptself", g_binary_routine_get_name(routines[i])) == 0) + { + + printf("...\n"); + + instr = g_binary_format_decompile_routine(G_BIN_FORMAT(format), routines[i]); + + } + + + } + + + + +} + + +/****************************************************************************** +* * +* Paramètres : binary = représentation de binaire chargé. * +* filename = nom du fichier source à cibler. * +* * * Description : Procède à la décompilation des routines d'un fichier donné. * * * * Retour : Tampon de code mis en place. * @@ -119,6 +176,7 @@ static void build_decomp_prologue(GCodeBuffer *buffer, const char *filename) GCodeBuffer *decompile_all_from_file(const GOpenidaBinary *binary, const char *filename) { GCodeBuffer *result; /* Tampon constitué à renvoyer */ + GExeFormat *format; /* Format du binaire fourni */ result = g_code_buffer_new(); @@ -126,6 +184,14 @@ GCodeBuffer *decompile_all_from_file(const GOpenidaBinary *binary, const char *f build_decomp_prologue(result, filename); + prepare_all_routines_for_decomp(binary, filename); + + + + + format = g_openida_binary_get_format(binary); + g_binary_format_decompile(G_BIN_FORMAT(format), result); + return result; } diff --git a/src/analysis/routine.c b/src/analysis/routine.c index 0c8d83a..ad82407 100644 --- a/src/analysis/routine.c +++ b/src/analysis/routine.c @@ -55,6 +55,9 @@ struct _GBinRoutine GBinVariable **locals; /* Variables locales du code */ size_t locals_count; /* Nombre de variables locales */ + GArchInstruction *instr; /* Instructions natives */ + GDecInstruction *dinstr; /* Instructions décompilées */ + }; @@ -770,3 +773,87 @@ char *_g_binary_routine_to_string(const GBinRoutine *routine, Routine2StringOpti return result; } + + +/****************************************************************************** +* * +* Paramètres : routine = routine à consulter. * +* * +* Description : Fournit les instructions natives correspondantes. * +* * +* Retour : Ensemble d'instructions décompilées ou NULL. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GArchInstruction *g_binary_routine_get_instructions(const GBinRoutine *routine) +{ + return routine->instr; + +} + + +/****************************************************************************** +* * +* Paramètres : routine = routine à mettre à jour. * +* instr = série d'instructions à conserver. * +* * +* Description : Définit les instructions natives de la routine. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_binary_routine_set_instructions(GBinRoutine *routine, GArchInstruction *instr) +{ + if (routine->instr != NULL) + g_object_unref(G_OBJECT(routine->instr)); + + routine->instr = instr; + +} + + +/****************************************************************************** +* * +* Paramètres : routine = routine à consulter. * +* * +* Description : Fournit les instructions décompilées correspondantes. * +* * +* Retour : Ensemble d'instructions décompilées ou NULL. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GDecInstruction *g_binary_routine_get_decomp_instructions(const GBinRoutine *routine) +{ + return routine->dinstr; + +} + + +/****************************************************************************** +* * +* Paramètres : routine = routine à mettre à jour. * +* instr = série d'instructions à conserver. * +* * +* Description : Définit les instructions décompilées de la routine. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_binary_routine_set_decomp_instructions(GBinRoutine *routine, GDecInstruction *instr) +{ + if (routine->dinstr != NULL) + g_object_unref(G_OBJECT(routine->dinstr)); + + routine->dinstr = instr; + +} diff --git a/src/analysis/routine.h b/src/analysis/routine.h index e2ea1cc..47de5bd 100644 --- a/src/analysis/routine.h +++ b/src/analysis/routine.h @@ -31,7 +31,8 @@ #include "variable.h" -#include "../arch/archbase.h" +#include "../arch/instruction.h" +#include "../decomp/instruction.h" @@ -143,6 +144,18 @@ char *_g_binary_routine_to_string(const GBinRoutine *, Routine2StringOptions); #define g_binary_routine_to_string(r) _g_binary_routine_to_string((r), RSO_ALL) +/* Fournit les instructions natives correspondantes. */ +GArchInstruction *g_binary_routine_get_instructions(const GBinRoutine *); + +/* Définit les instructions natives de la routine. */ +void g_binary_routine_set_instructions(GBinRoutine *, GArchInstruction *); + +/* Fournit les instructions décompilées correspondantes. */ +GDecInstruction *g_binary_routine_get_decomp_instructions(const GBinRoutine *); + +/* Définit les instructions décompilées de la routine. */ +void g_binary_routine_set_decomp_instructions(GBinRoutine *, GDecInstruction *); + #endif /* _ANALYSIS_ROUTINE_H */ diff --git a/src/arch/Makefile.am b/src/arch/Makefile.am index 8f1c1ff..1a02c07 100644 --- a/src/arch/Makefile.am +++ b/src/arch/Makefile.am @@ -10,7 +10,8 @@ libarch_la_SOURCES = \ operand-int.h \ operand.h operand.c \ processor-int.h \ - processor.h processor.c + processor.h processor.c \ + translate.h libarch_la_LIBADD = \ arm/libarcharm.la \ diff --git a/src/arch/dalvik/Makefile.am b/src/arch/dalvik/Makefile.am index a7e099f..8dc93ae 100644 --- a/src/arch/dalvik/Makefile.am +++ b/src/arch/dalvik/Makefile.am @@ -3,6 +3,12 @@ noinst_LTLIBRARIES = libarchdalvik.la libarchdalvik_la_SOURCES = \ instruction.h instruction.c \ + dop_aget.c \ + dop_aput.c \ + dop_arithm.c \ + dop_array.c \ + dop_const.c \ + dop_invoke.c \ op_add.c \ op_aget.c \ op_and.c \ @@ -33,7 +39,8 @@ libarchdalvik_la_SOURCES = \ opcodes.h \ operand.h operand.c \ processor.h processor.c \ - register.h register.c + register.h register.c \ + translate.h libarchdalvik_la_CFLAGS = $(AM_CFLAGS) diff --git a/src/arch/dalvik/dop_aget.c b/src/arch/dalvik/dop_aget.c new file mode 100644 index 0000000..77e6ef2 --- /dev/null +++ b/src/arch/dalvik/dop_aget.c @@ -0,0 +1,68 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * dop_aget.c - décompilation des instructions manipulant des tableaux (chargement) + * + * Copyright (C) 2010 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 "translate.h" + + +#include "../../decomp/expr/array.h" +#include "../../decomp/expr/assign.h" + + + +/****************************************************************************** +* * +* Paramètres : instr = instruction d'origine à convertir. * +* ctx = contexte de la phase de décompilation. * +* * +* Description : Décompile une instruction de type 'aget'. * +* * +* Retour : Instruction mise en place ou NULL. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GDecInstruction *dalvik_decomp_instr_aget(const GArchInstruction *instr, GDecContext *ctx) +{ + GDecInstruction *result; /* Instruction à retourner */ + GArchOperand *operand; /* Opérande de l'instruction */ + GDecInstruction *content; /* Contenu de cellule visé */ + GDecInstruction *array; /* Tableau accédé */ + GDecInstruction *index; /* Indice de cellule considérée*/ + GDecInstruction *access; /* Représentation de l'accès */ + + operand = g_arch_instruction_get_operand(instr, 0); + content = g_pseudo_register_new(); + + operand = g_arch_instruction_get_operand(instr, 1); + array = g_pseudo_register_new(); + + operand = g_arch_instruction_get_operand(instr, 2); + index = g_pseudo_register_new(); + + access = g_array_access_new(G_DEC_EXPRESSION(array), G_DEC_EXPRESSION(index)); + result = g_assign_expression_new(G_DEC_EXPRESSION(content), G_DEC_EXPRESSION(access)); + + return result; + +} diff --git a/src/arch/dalvik/dop_aput.c b/src/arch/dalvik/dop_aput.c new file mode 100644 index 0000000..2e4527e --- /dev/null +++ b/src/arch/dalvik/dop_aput.c @@ -0,0 +1,68 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * dop_aput.c - décompilation des instructions manipulant des tableaux (enregistrement) + * + * Copyright (C) 2010 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 "translate.h" + + +#include "../../decomp/expr/array.h" +#include "../../decomp/expr/assign.h" + + + +/****************************************************************************** +* * +* Paramètres : instr = instruction d'origine à convertir. * +* ctx = contexte de la phase de décompilation. * +* * +* Description : Décompile une instruction de type 'aput'. * +* * +* Retour : Instruction mise en place ou NULL. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GDecInstruction *dalvik_decomp_instr_aput(const GArchInstruction *instr, GDecContext *ctx) +{ + GDecInstruction *result; /* Instruction à retourner */ + GArchOperand *operand; /* Opérande de l'instruction */ + GDecInstruction *content; /* Contenu de cellule visé */ + GDecInstruction *array; /* Tableau accédé */ + GDecInstruction *index; /* Indice de cellule considérée*/ + GDecInstruction *access; /* Représentation de l'accès */ + + operand = g_arch_instruction_get_operand(instr, 0); + content = g_pseudo_register_new(); + + operand = g_arch_instruction_get_operand(instr, 1); + array = g_pseudo_register_new(); + + operand = g_arch_instruction_get_operand(instr, 2); + index = g_pseudo_register_new(); + + access = g_array_access_new(G_DEC_EXPRESSION(array), G_DEC_EXPRESSION(index)); + result = g_assign_expression_new(G_DEC_EXPRESSION(access), G_DEC_EXPRESSION(content)); + + return result; + +} diff --git a/src/arch/dalvik/dop_arithm.c b/src/arch/dalvik/dop_arithm.c new file mode 100644 index 0000000..388f906 --- /dev/null +++ b/src/arch/dalvik/dop_arithm.c @@ -0,0 +1,175 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * dop_arithm.c - décompilation des opérations arithmétiques + * + * Copyright (C) 2010 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 "translate.h" + + +#include "instruction.h" +#include "../../decomp/expr/arithm.h" +#include "../../decomp/expr/assign.h" +#include "../../decomp/expr/immediate.h" + + + +/****************************************************************************** +* * +* Paramètres : instr = instruction d'origine à convertir. * +* ctx = contexte de la phase de décompilation. * +* * +* Description : Décompile une instruction de type 'opérations arithmétiques'.* +* * +* Retour : Instruction mise en place ou NULL. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GDecInstruction *dalvik_decomp_instr_arithm_2addr(const GArchInstruction *instr, GDecContext *ctx) +{ + GDecInstruction *result; /* Instruction à retourner */ + ArithmOperationType type; /* Type d'opération menée */ + GArchOperand *operand; /* Opérande de l'instruction */ + GDecInstruction *dest; /* Enregistrement du résultat */ + GDecInstruction *op1; /* Premier opérande utilisé */ + GDecInstruction *op2; /* Second opérande utilisé */ + GDecInstruction *arithm; /* Opération arithmétique */ + + switch (g_dalvik_instruction_get_opcode(G_DALVIK_INSTRUCTION(instr))) + { + case DOP_ADD_INT_2ADDR: + type = AOT_ADD; + break; + case DOP_MUL_INT_2ADDR: + case DOP_MUL_DOUBLE_2ADDR: + type = AOT_MUL; + break; + case DOP_DIV_INT_2ADDR: + type = AOT_DIV; + break; + case DOP_REM_INT_2ADDR: + type = AOT_REM; + break; + case DOP_AND_INT_2ADDR: + type = AOT_AND; + break; + case DOP_OR_INT_2ADDR: + type = AOT_OR; + break; + case DOP_XOR_INT_2ADDR: + type = AOT_XOR; + break; + default: + type = AOT_COUNT; + break; + } + + operand = g_arch_instruction_get_operand(instr, 0); + dest = g_pseudo_register_new(); + + operand = g_arch_instruction_get_operand(instr, 1); + op1 = g_pseudo_register_new(); + + operand = g_arch_instruction_get_operand(instr, 2); + op2 = g_pseudo_register_new(); + + arithm = g_arithm_expression_new(G_DEC_EXPRESSION(op1), type, G_DEC_EXPRESSION(op2)); + result = g_assign_expression_new(G_DEC_EXPRESSION(dest), G_DEC_EXPRESSION(arithm)); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : instr = instruction d'origine à convertir. * +* ctx = contexte de la phase de décompilation. * +* * +* Description : Décompile une instruction de type 'opérations arithmétiques'.* +* * +* Retour : Instruction mise en place ou NULL. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GDecInstruction *dalvik_decomp_instr_arithm_lit(const GArchInstruction *instr, GDecContext *ctx) +{ + GDecInstruction *result; /* Instruction à retourner */ + ArithmOperationType type; /* Type d'opération menée */ + GArchOperand *operand; /* Opérande de l'instruction */ + GDecInstruction *dest; /* Enregistrement du résultat */ + GDecInstruction *op1; /* Premier opérande utilisé */ + GDecInstruction *op2; /* Second opérande utilisé */ + GDecInstruction *arithm; /* Opération arithmétique */ + + switch (g_dalvik_instruction_get_opcode(G_DALVIK_INSTRUCTION(instr))) + { + case DOP_ADD_INT_LIT8: + case DOP_ADD_INT_LIT16: + type = AOT_ADD; + break; + case DOP_MUL_INT_LIT8: + case DOP_MUL_INT_LIT16: + type = AOT_MUL; + break; + case DOP_DIV_INT_LIT8: + case DOP_DIV_INT_LIT16: + type = AOT_DIV; + break; + case DOP_REM_INT_LIT8: + case DOP_REM_INT_LIT16: + type = AOT_REM; + break; + case DOP_AND_INT_LIT8: + case DOP_AND_INT_LIT16: + type = AOT_AND; + break; + case DOP_OR_INT_LIT8: + case DOP_OR_INT_LIT16: + type = AOT_OR; + break; + case DOP_XOR_INT_LIT8: + case DOP_XOR_INT_LIT16: + type = AOT_XOR; + break; + default: + type = AOT_COUNT; + break; + } + + operand = g_arch_instruction_get_operand(instr, 0); + dest = g_pseudo_register_new(); + + operand = g_arch_instruction_get_operand(instr, 1); + op1 = g_pseudo_register_new(); + + operand = g_arch_instruction_get_operand(instr, 2); + op2 = g_imm_expression_new(G_IMM_OPERAND(operand)); + + arithm = g_arithm_expression_new(G_DEC_EXPRESSION(op1), type, G_DEC_EXPRESSION(op2)); + result = g_assign_expression_new(G_DEC_EXPRESSION(dest), G_DEC_EXPRESSION(arithm)); + + return result; + +} diff --git a/src/arch/dalvik/dop_array.c b/src/arch/dalvik/dop_array.c new file mode 100644 index 0000000..035b3eb --- /dev/null +++ b/src/arch/dalvik/dop_array.c @@ -0,0 +1,74 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * dop_array.c - décompilation de l'opération récupérant la longueur d'un tableau + * + * Copyright (C) 2010 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 "translate.h" + + +#include "../../decomp/expr/assign.h" +#include "../../decomp/expr/dalvik/array.h" + + + +/****************************************************************************** +* * +* Paramètres : instr = instruction d'origine à convertir. * +* ctx = contexte de la phase de décompilation. * +* * +* Description : Décompile une instruction de type 'array-length'. * +* * +* Retour : Instruction mise en place ou NULL. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GDecInstruction *dalvik_decomp_instr_array_length(const GArchInstruction *instr, GDecContext *ctx) +{ + GDecInstruction *result; /* Instruction à retourner */ + + + GArchOperand *operand; /* Opérande de l'instruction */ + GDecInstruction *reg; /* Pseudo-registre redéfini */ + GDecInstruction *len; /* Enregistrement de taille */ + + + result = NULL; + + + printf("PAssaage !\n"); + + + + operand = g_arch_instruction_get_operand(instr, 1); + reg = g_pseudo_register_new(); + len = g_dalvik_alength_new(G_DEC_EXPRESSION(reg)); + + operand = g_arch_instruction_get_operand(instr, 0); + reg = g_pseudo_register_new(); + + + result = g_assign_expression_new(G_DEC_EXPRESSION(reg), G_DEC_EXPRESSION(len)); + + return result; + +} diff --git a/src/arch/dalvik/dop_const.c b/src/arch/dalvik/dop_const.c new file mode 100644 index 0000000..eab7acd --- /dev/null +++ b/src/arch/dalvik/dop_const.c @@ -0,0 +1,72 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * dop_const.c - décompilation des chargements de constantes + * + * Copyright (C) 2010 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 "translate.h" + + +#include "../../decomp/expr/assign.h" +#include "../../decomp/expr/immediate.h" + + + +/****************************************************************************** +* * +* Paramètres : instr = instruction d'origine à convertir. * +* ctx = contexte de la phase de décompilation. * +* * +* Description : Décompile une instruction de type 'const'. * +* * +* Retour : Instruction mise en place ou NULL. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GDecInstruction *dalvik_decomp_instr_const(const GArchInstruction *instr, GDecContext *ctx) +{ + GDecInstruction *result; /* Instruction à retourner */ + + + GArchOperand *operand; /* Opérande de l'instruction */ + GDecInstruction *reg; /* Pseudo-registre redéfini */ + GDecInstruction *imm; /* Valeur immédiate décompilée */ + + + result = NULL; + + + printf("PAssaage !\n"); + + + + operand = g_arch_instruction_get_operand(instr, 1); + reg = g_pseudo_register_new(); + + operand = g_arch_instruction_get_operand(instr, 1); + imm = g_imm_expression_new(G_IMM_OPERAND(operand)); + + result = g_assign_expression_new(G_DEC_EXPRESSION(reg), G_DEC_EXPRESSION(imm)); + + return result; + +} diff --git a/src/arch/dalvik/dop_invoke.c b/src/arch/dalvik/dop_invoke.c new file mode 100644 index 0000000..e4fa1fb --- /dev/null +++ b/src/arch/dalvik/dop_invoke.c @@ -0,0 +1,158 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * dop_invoke.c - décompilation des appels de méthode + * + * Copyright (C) 2010 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 "translate.h" + + +#include "instruction.h" +#include "operand.h" +#include "../../decomp/expr/assign.h" +#include "../../decomp/expr/call.h" +#include "../../format/dex/pool.h" + + + + +/****************************************************************************** +* * +* Paramètres : instr = instruction d'origine à convertir. * +* ctx = contexte de la phase de décompilation. * +* * +* Description : Décompile une instruction de type 'invoke-virtual'. * +* * +* Retour : Instruction mise en place ou NULL. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GDecInstruction *dalvik_decomp_instr_invoke_virtual(const GArchInstruction *instr, GDecContext *ctx) +{ + GDecInstruction *result; /* Instruction à retourner */ + + + size_t count; /* Quantité d'opérandes */ + GArchOperand *op; /* Opérande de l'instruction */ + uint32_t index; /* Indice de l'élément visé */ + GDexFormat *format; /* Accès aux constantes */ + GBinRoutine *routine; /* Routine visée par l'appel */ + + const char *string; /* Chaîne à afficher */ + GOpenidaType *type; /* Type quelconque */ + char *tmp; /* Chaîne à afficher & libérer */ + + + + GArchOperand *operand; /* Opérande de l'instruction */ + GDecInstruction *reg; /* Pseudo-registre redéfini */ + GDecInstruction *imm; /* Valeur immédiate décompilée */ + + GArchInstruction *iter; /* Boucle de parcours */ + vmpa_t max; /* Limite à ne pas dépasser */ + + + result = NULL; + + + printf("PAssaage !\n"); + + + + + + + /* Récupération de la méthode */ + + count = g_arch_instruction_count_operands(instr); + op = g_arch_instruction_get_operand(instr, count - 1); + + index = g_dalvik_pool_operand_get_index(G_DALVIK_POOL_OPERAND(op)); + + printf("POOL ?? %d -> %d\n", G_IS_DALVIK_POOL_OPERAND(op), index); + + format = G_DEX_FORMAT(g_object_get_data(G_OBJECT(ctx), "format")); + routine = get_routine_from_dex_pool(format, index); + if (routine == NULL) return NULL; + + +#if 0 + if (operand->cache.method == NULL) + g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, + "", 18, RTT_VAR_NAME); + + else + { + tmp = g_binary_routine_to_string(operand->cache.method); + + g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, + tmp, strlen(tmp), RTT_VAR_NAME); + + free(tmp); + + +#endif + + result = g_routine_call_new(routine, true); + + //GDecInstruction *g_routine_call_new(GBinRoutine *routine, bool is_object) + /* + operand = g_arch_instruction_get_operand(instr, 1); + reg = g_pseudo_register_new(); + + operand = g_arch_instruction_get_operand(instr, 1); + imm = g_imm_expression_new(G_IMM_OPERAND(operand)); + + result = g_assign_expression_new(G_DEC_EXPRESSION(reg), G_DEC_EXPRESSION(imm)); + */ + + + + + + /* Récupération d'un résultat ? */ + + iter = instr; + max = g_dec_context_get_max_address(ctx); + + iter = g_arch_instruction_get_next_iter(instr, iter, max); + + if (iter != NULL) + switch (g_dalvik_instruction_get_opcode(G_DALVIK_INSTRUCTION(iter))) + { + case DOP_MOVE_RESULT: + + operand = g_arch_instruction_get_operand(instr, 0); + reg = g_pseudo_register_new(); + + result = g_assign_expression_new(G_DEC_EXPRESSION(reg), G_DEC_EXPRESSION(result)); + + break; + + default: + break; + + } + + return result; + +} diff --git a/src/arch/dalvik/instruction.c b/src/arch/dalvik/instruction.c index 13c8e83..e8059d6 100644 --- a/src/arch/dalvik/instruction.c +++ b/src/arch/dalvik/instruction.c @@ -24,7 +24,8 @@ #include "instruction.h" -#include "../instruction-int.h" +#include "translate.h" +#include "../instruction-int.h" @@ -63,6 +64,8 @@ typedef struct _dalvik_instruction const char *keyword; /* Mot clef de la commande */ + decomp_instr_fc decomp; /* Procédure de décompilation */ + } dalvik_instruction; @@ -81,7 +84,7 @@ static dalvik_instruction _instructions[DOP_COUNT] = { [DOP_RETURN] = { 0x0f, "return" }, [DOP_RETURN_WIDE] = { 0x10, "return-wide" }, [DOP_RETURN_OBJECT] = { 0x11, "return-object" }, - [DOP_CONST_4] = { 0x12, "const/4" }, + [DOP_CONST_4] = { 0x12, "const/4", dalvik_decomp_instr_const }, [DOP_CONST_16] = { 0x13, "const/16" }, [DOP_CONST] = { 0x14, "const" }, [DOP_CONST_HIGH16] = { 0x15, "const/high16" }, @@ -94,7 +97,7 @@ static dalvik_instruction _instructions[DOP_COUNT] = { [DOP_CHECK_CAST] = { 0x1f, "check-cast" }, - [DOP_ARRAY_LENGTH] = { 0x21, "array-length" }, + [DOP_ARRAY_LENGTH] = { 0x21, "array-length", dalvik_decomp_instr_array_length }, [DOP_NEW_INSTANCE] = { 0x22, "new-instance" }, [DOP_NEW_ARRAY] = { 0x23, "new-array" }, @@ -126,14 +129,14 @@ static dalvik_instruction _instructions[DOP_COUNT] = { [DOP_AGET_WIDE] = { 0x45, "aget-wide" }, [DOP_AGET_OBJECT] = { 0x46, "aget-object" }, [DOP_AGET_BOOLEAN] = { 0x47, "aget-boolean" }, - [DOP_AGET_BYTE] = { 0x48, "aget-byte" }, + [DOP_AGET_BYTE] = { 0x48, "aget-byte", dalvik_decomp_instr_aget }, [DOP_AGET_CHAR] = { 0x49, "aget-char" }, [DOP_AGET_SHORT] = { 0x4a, "aget-short" }, [DOP_APUT] = { 0x4b, "aput" }, [DOP_APUT_WIDE] = { 0x4c, "aput-wide" }, [DOP_APUT_OBJECT] = { 0x4d, "aput-object" }, [DOP_APUT_BOOLEAN] = { 0x4e, "aput-boolean" }, - [DOP_APUT_BYTE] = { 0x4f, "aput-byte" }, + [DOP_APUT_BYTE] = { 0x4f, "aput-byte", dalvik_decomp_instr_aput }, [DOP_APUT_CHAR] = { 0x50, "aput-char" }, [DOP_APUT_SHORT] = { 0x51, "aput-short" }, [DOP_IGET] = { 0x52, "iget" }, @@ -164,7 +167,7 @@ static dalvik_instruction _instructions[DOP_COUNT] = { [DOP_SPUT_BYTE] = { 0x6b, "sput-byte" }, [DOP_SPUT_CHAR] = { 0x6c, "sput-char" }, [DOP_SPUT_SHORT] = { 0x6d, "sput-short" }, - [DOP_INVOKE_VIRTUAL] = { 0x6e, "invoke-virtual" }, + [DOP_INVOKE_VIRTUAL] = { 0x6e, "invoke-virtual", dalvik_decomp_instr_invoke_virtual }, [DOP_INVOKE_SUPER] = { 0x6f, "invoke-static" }, [DOP_INVOKE_DIRECT] = { 0x70, "invoke-direct" }, [DOP_INVOKE_STATIC] = { 0x71, "invoke-static" }, @@ -195,34 +198,34 @@ static dalvik_instruction _instructions[DOP_COUNT] = { [DOP_XOR_INT] = { 0x97, "xor-int" }, - [DOP_ADD_INT_2ADDR] = { 0xb0, "add-int/2addr" }, + [DOP_ADD_INT_2ADDR] = { 0xb0, "add-int/2addr", dalvik_decomp_instr_arithm_2addr }, - [DOP_MUL_INT_2ADDR] = { 0xb2, "mul-int/2addr" }, - [DOP_DIV_INT_2ADDR] = { 0xb3, "div-int/2addr" }, - [DOP_REM_INT_2ADDR] = { 0xb4, "rem-int/2addr" }, - [DOP_AND_INT_2ADDR] = { 0xb5, "and-int/2addr" }, - [DOP_OR_INT_2ADDR] = { 0xb6, "or-int/2addr" }, - [DOP_XOR_INT_2ADDR] = { 0xb7, "xor-int/2addr" }, + [DOP_MUL_INT_2ADDR] = { 0xb2, "mul-int/2addr", dalvik_decomp_instr_arithm_2addr }, + [DOP_DIV_INT_2ADDR] = { 0xb3, "div-int/2addr", dalvik_decomp_instr_arithm_2addr }, + [DOP_REM_INT_2ADDR] = { 0xb4, "rem-int/2addr", dalvik_decomp_instr_arithm_2addr }, + [DOP_AND_INT_2ADDR] = { 0xb5, "and-int/2addr", dalvik_decomp_instr_arithm_2addr }, + [DOP_OR_INT_2ADDR] = { 0xb6, "or-int/2addr", dalvik_decomp_instr_arithm_2addr }, + [DOP_XOR_INT_2ADDR] = { 0xb7, "xor-int/2addr", dalvik_decomp_instr_arithm_2addr }, - [DOP_MUL_DOUBLE_2ADDR] = { 0xcd, "mul-double/2addr" }, + [DOP_MUL_DOUBLE_2ADDR] = { 0xcd, "mul-double/2addr", dalvik_decomp_instr_arithm_2addr }, - [DOP_ADD_INT_LIT16] = { 0xd0, "add-int/lit16" }, + [DOP_ADD_INT_LIT16] = { 0xd0, "add-int/lit16", dalvik_decomp_instr_arithm_lit }, [DOP_RSUB_INT] = { 0xd1, "rsub-int" }, - [DOP_MUL_INT_LIT16] = { 0xd2, "mul-int/lit16" }, - [DOP_DIV_INT_LIT16] = { 0xd3, "div-int/lit16" }, - [DOP_REM_INT_LIT16] = { 0xd4, "rem-int/lit16" }, - [DOP_AND_INT_LIT16] = { 0xd5, "and-int/lit16" }, - [DOP_OR_INT_LIT16] = { 0xd6, "or-int/lit16" }, - [DOP_XOR_INT_LIT16] = { 0xd7, "xor-int/lit16" }, - [DOP_ADD_INT_LIT8] = { 0xd8, "add-int/lit8" }, + [DOP_MUL_INT_LIT16] = { 0xd2, "mul-int/lit16", dalvik_decomp_instr_arithm_lit }, + [DOP_DIV_INT_LIT16] = { 0xd3, "div-int/lit16", dalvik_decomp_instr_arithm_lit }, + [DOP_REM_INT_LIT16] = { 0xd4, "rem-int/lit16", dalvik_decomp_instr_arithm_lit }, + [DOP_AND_INT_LIT16] = { 0xd5, "and-int/lit16", dalvik_decomp_instr_arithm_lit }, + [DOP_OR_INT_LIT16] = { 0xd6, "or-int/lit16", dalvik_decomp_instr_arithm_lit }, + [DOP_XOR_INT_LIT16] = { 0xd7, "xor-int/lit16", dalvik_decomp_instr_arithm_lit }, + [DOP_ADD_INT_LIT8] = { 0xd8, "add-int/lit8", dalvik_decomp_instr_arithm_lit }, [DOP_RSUB_INT_LIT8] = { 0xd9, "rsub-int/lit8" }, - [DOP_MUL_INT_LIT8] = { 0xda, "mul-int/lit8" }, - [DOP_DIV_INT_LIT8] = { 0xdb, "div-int/lit8" }, - [DOP_REM_INT_LIT8] = { 0xdc, "rem-int/lit8" }, - [DOP_AND_INT_LIT8] = { 0xdd, "and-int/lit8" }, - [DOP_OR_INT_LIT8] = { 0xde, "or-int/lit8" }, - [DOP_XOR_INT_LIT8] = { 0xdf, "xor-int/lit8" } + [DOP_MUL_INT_LIT8] = { 0xda, "mul-int/lit8", dalvik_decomp_instr_arithm_lit }, + [DOP_DIV_INT_LIT8] = { 0xdb, "div-int/lit8", dalvik_decomp_instr_arithm_lit }, + [DOP_REM_INT_LIT8] = { 0xdc, "rem-int/lit8", dalvik_decomp_instr_arithm_lit }, + [DOP_AND_INT_LIT8] = { 0xdd, "and-int/lit8", dalvik_decomp_instr_arithm_lit }, + [DOP_OR_INT_LIT8] = { 0xde, "or-int/lit8", dalvik_decomp_instr_arithm_lit }, + [DOP_XOR_INT_LIT8] = { 0xdf, "xor-int/lit8", dalvik_decomp_instr_arithm_lit } }; @@ -237,6 +240,9 @@ static InstructionLinkType dalvik_get_instruction_link(const GDalvikInstruction /* Indique si l'instruction correspond à un retour de fonction. */ static bool dalvik_instruction_is_return(const GDalvikInstruction *); +/* Décompile une instruction de la machine virtuelle Dalvik. */ +GDecInstruction *dalvik_instruction_decompile(const GDalvikInstruction *, GDecContext *); + /* Indique le type défini pour une instruction d'architecture Dalvik. */ @@ -283,6 +289,7 @@ static void g_dalvik_instruction_init(GDalvikInstruction *instr) parent->get_text = (get_instruction_text_fc)dalvik_get_instruction_text; parent->get_link = (get_instruction_link_fc)dalvik_get_instruction_link; parent->is_return = (is_instruction_return_fc)dalvik_instruction_is_return; + parent->decomp = (decomp_instr_fc)dalvik_instruction_decompile; } @@ -312,6 +319,25 @@ GArchInstruction *g_dalvik_instruction_new(DalvikOpcodes type) } +/****************************************************************************** +* * +* Paramètres : instr = instruction Dalvik à consulter. * +* * +* Description : Indique l'opcode associé à une instruction Dalvik. * +* * +* Retour : Identifiant de l'instruction en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +DalvikOpcodes g_dalvik_instruction_get_opcode(const GDalvikInstruction *instr) +{ + return instr->type; + +} + + /* ---------------------------------------------------------------------------------- */ /* AIDE A LA MISE EN PLACE D'INSTRUCTIONS */ @@ -409,3 +435,31 @@ static bool dalvik_instruction_is_return(const GDalvikInstruction *instr) return (instr->type == DOP_RETURN_VOID); } + + +/****************************************************************************** +* * +* Paramètres : instr = instruction d'origine à convertir. * +* ctx = contexte de la phase de décompilation. * +* * +* Description : Décompile une instruction de la machine virtuelle Dalvik. * +* * +* Retour : Instruction mise en place ou NULL. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GDecInstruction *dalvik_instruction_decompile(const GDalvikInstruction *instr, GDecContext *ctx) +{ + GDecInstruction *result; /* Instruction à retourner */ + + if (_instructions[instr->type].decomp != NULL) + result = _instructions[instr->type].decomp(G_ARCH_INSTRUCTION(instr), ctx); + + else + result = NULL; + + return result; + +} diff --git a/src/arch/dalvik/instruction.h b/src/arch/dalvik/instruction.h index cc7f845..8eaed17 100644 --- a/src/arch/dalvik/instruction.h +++ b/src/arch/dalvik/instruction.h @@ -214,6 +214,9 @@ GType g_dalvik_instruction_get_type(void); /* Crée une instruction pour l'architecture Dalvik. */ GArchInstruction *g_dalvik_instruction_new(DalvikOpcodes); +/* Indique l'opcode associé à une instruction Dalvik. */ +DalvikOpcodes g_dalvik_instruction_get_opcode(const GDalvikInstruction *); + /* --------------------- AIDE A LA MISE EN PLACE D'INSTRUCTIONS --------------------- */ diff --git a/src/arch/dalvik/translate.h b/src/arch/dalvik/translate.h new file mode 100644 index 0000000..779c133 --- /dev/null +++ b/src/arch/dalvik/translate.h @@ -0,0 +1,56 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * translate.h - prototypes pour les environnements de traduction d'instructions Dalvik + * + * Copyright (C) 2010 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 _ANALYSIS_DECOMP_RTL_DALVIK_TRANSLATE_H +#define _ANALYSIS_DECOMP_RTL_DALVIK_TRANSLATE_H + + +#include "../translate.h" + + + +/* Décompile une instruction de type 'aget'. */ +GDecInstruction *dalvik_decomp_instr_aget(const GArchInstruction *, GDecContext *); + +/* Décompile une instruction de type 'aput'. */ +GDecInstruction *dalvik_decomp_instr_aput(const GArchInstruction *, GDecContext *); + +/* Décompile une instruction de type 'array-length'. */ +GDecInstruction *dalvik_decomp_instr_array_length(const GArchInstruction *, GDecContext *); + +/* Décompile une instruction de type 'const'. */ +GDecInstruction *dalvik_decomp_instr_const(const GArchInstruction *, GDecContext *); + +/* Décompile une instruction de type 'invoke-virtual'. */ +GDecInstruction *dalvik_decomp_instr_invoke_virtual(const GArchInstruction *, GDecContext *); + + +/* Décompile une instruction de type 'opérations arithmétiques'. */ +GDecInstruction *dalvik_decomp_instr_arithm_2addr(const GArchInstruction *, GDecContext *); + +/* Décompile une instruction de type 'opérations arithmétiques'. */ +GDecInstruction *dalvik_decomp_instr_arithm_lit(const GArchInstruction *, GDecContext *); + + + +#endif /* _ANALYSIS_DECOMP_RTL_DALVIK_TRANSLATE_H */ diff --git a/src/arch/immediate.c b/src/arch/immediate.c index 3018b6b..ec689b8 100644 --- a/src/arch/immediate.c +++ b/src/arch/immediate.c @@ -95,6 +95,9 @@ static void g_imm_operand_add_text(const GImmOperand *, GRenderingOptions *, Mai /* Ajoute à un tampon GLib le contenu de l'instance spécifiée. */ static void g_imm_operand_to_buffer(const GImmOperand *, GBufferLine *, GRenderingOptions *); +/* Traduit un opérande en version humainement lisible. */ +static void g_imm_operand_print(const GImmOperand *, GBufferLine *, AsmSyntax); + /* Indique le type défini pour un opérande de valeur numérique. */ @@ -134,13 +137,18 @@ static void g_imm_operand_class_init(GImmOperandClass *klass) static void g_imm_operand_init(GImmOperand *operand) { - GContentExporter *parent; /* Instance parente */ + GContentExporter *parent; /* Instance parente #1 */ + GArchOperand *arch; /* Instance parente #2 */ parent = G_CONTENT_EXPORTER(operand); parent->add_text = (add_text_fc)g_imm_operand_add_text; parent->export_buffer = (export_buffer_fc)g_imm_operand_to_buffer; + arch = G_ARCH_OPERAND(operand); + + arch->print = (operand_print_fc)g_imm_operand_print; + operand->zpad = false; } @@ -653,7 +661,52 @@ static size_t g_imm_operand_to_string(const GImmOperand *operand, AsmSyntax synt } break; - default: + case ASX_COUNT: + switch (operand->size) + { + case MDS_UNDEFINED: + result = snprintf(value, VMPA_MAX_SIZE, "0x???"); + break; + + case MDS_4_BITS_UNSIGNED: + result = snprintf(value, VMPA_MAX_SIZE, "%hhu", operand->unsigned_imm.val8); + + case MDS_8_BITS_UNSIGNED: + result = snprintf(value, VMPA_MAX_SIZE, "%hhu", operand->unsigned_imm.val8); + break; + + case MDS_16_BITS_UNSIGNED: + result = snprintf(value, VMPA_MAX_SIZE, "%hu", operand->unsigned_imm.val16); + break; + + case MDS_32_BITS_UNSIGNED: + result = snprintf(value, VMPA_MAX_SIZE, "%u", operand->unsigned_imm.val32); + break; + + case MDS_64_BITS_UNSIGNED: + result = snprintf(value, VMPA_MAX_SIZE, "%llu", operand->unsigned_imm.val64); + break; + + case MDS_4_BITS_SIGNED: + result = snprintf(value, VMPA_MAX_SIZE, "%hhd", operand->signed_imm.val8); + break; + + case MDS_8_BITS_SIGNED: + result = snprintf(value, VMPA_MAX_SIZE, "%hhd", operand->signed_imm.val8); + break; + + case MDS_16_BITS_SIGNED: + result = snprintf(value, VMPA_MAX_SIZE, "%hd", operand->signed_imm.val16); + break; + + case MDS_32_BITS_SIGNED: + result = snprintf(value, VMPA_MAX_SIZE, "%d", operand->signed_imm.val32); + break; + + case MDS_64_BITS_SIGNED: + result = snprintf(value, VMPA_MAX_SIZE, "%lld", operand->signed_imm.val64); + break; + } break; } @@ -706,10 +759,12 @@ static void g_imm_operand_add_text(const GImmOperand *operand, GRenderingOptions static void g_imm_operand_to_buffer(const GImmOperand *operand, GBufferLine *buffer, GRenderingOptions *options) { + AsmSyntax syntax; /* Choix de l'exportation */ char value[VMPA_MAX_SIZE]; /* Chaîne à imprimer */ size_t len; /* Taille de l'élément inséré */ - len = g_imm_operand_to_string(operand, g_rendering_options_get_syntax(options), value); + syntax = (options == NULL ? ASX_COUNT : g_rendering_options_get_syntax(options)); + len = g_imm_operand_to_string(operand, syntax, value); g_content_exporter_insert_into_buffer(G_CONTENT_EXPORTER(operand), buffer, BLC_ASSEMBLY, value, len, RTT_IMMEDIATE); @@ -720,6 +775,32 @@ static void g_imm_operand_to_buffer(const GImmOperand *operand, GBufferLine *buf /****************************************************************************** * * * Paramètres : operand = opérande à traiter. * +* line = ligne tampon où imprimer l'opérande donné. * +* syntax = type de représentation demandée. * +* * +* Description : Traduit un opérande en version humainement lisible. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_imm_operand_print(const GImmOperand *operand, GBufferLine *line, AsmSyntax syntax) +{ + char value[VMPA_MAX_SIZE]; /* Chaîne à imprimer */ + size_t len; /* Taille de l'élément inséré */ + + len = g_imm_operand_to_string(operand, syntax, value); + + g_buffer_line_insert_text(line, BLC_ASSEMBLY, value, len, RTT_IMMEDIATE); + +} + + +/****************************************************************************** +* * +* Paramètres : operand = opérande à traiter. * * addr = valeur résultante. [OUT] * * * * Description : Convertit une valeur immédiate en adresse de type vmpa_t. * diff --git a/src/arch/instruction-int.h b/src/arch/instruction-int.h index 45a8b2d..2a92bad 100644 --- a/src/arch/instruction-int.h +++ b/src/arch/instruction-int.h @@ -1,6 +1,6 @@ /* OpenIDA - Outil d'analyse de fichiers binaires - * instruction.h - prototypes pour la définition générique interne des instructions + * instruction-int.h - prototypes pour la définition générique interne des instructions * * Copyright (C) 2008 Cyrille Bagard * @@ -27,6 +27,7 @@ #include "archbase.h" #include "instruction.h" +#include "translate.h" #include "../analysis/exporter-int.h" #include "../common/dllist.h" @@ -60,6 +61,7 @@ struct _GArchInstruction get_instruction_text_fc get_text; /* Texte humain équivalent */ get_instruction_link_fc get_link; /* Référence à une instruction */ is_instruction_return_fc is_return; /* Retour de fonction ou pas ? */ + decomp_instr_fc decomp; /* Procédure de décompilation */ }; diff --git a/src/arch/instruction.c b/src/arch/instruction.c index b642219..dd43e14 100644 --- a/src/arch/instruction.c +++ b/src/arch/instruction.c @@ -306,9 +306,9 @@ size_t g_arch_instruction_count_operands(const GArchInstruction *instr) * * ******************************************************************************/ -const GArchOperand *g_arch_instruction_get_operand(GArchInstruction *instr, size_t index) +GArchOperand *g_arch_instruction_get_operand(const GArchInstruction *instr, size_t index) { - const GArchOperand *result; /* Opérande à retourner */ + GArchOperand *result; /* Opérande à retourner */ if (index >= instr->operands_count) result = NULL; else result = instr->operands[index]; @@ -463,6 +463,33 @@ bool g_arch_instruction_is_return(const GArchInstruction *instr) } +/****************************************************************************** +* * +* Paramètres : instr = instruction d'origine à convertir. * +* ctx = contexte de la phase de décompilation. * +* * +* Description : Décompile une instruction de façon générique. * +* * +* Retour : Instruction mise en place ou NULL. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GDecInstruction *g_arch_instruction_decompile(const GArchInstruction *instr, GDecContext *ctx) +{ + GDecInstruction *result; /* Instruction à retourner */ + + if (instr->decomp != NULL) + result = instr->decomp(instr, ctx); + + else + result = NULL; + + return result; + +} + /* ---------------------------------------------------------------------------------- */ /* TRAITEMENT DES INSTRUCTIONS PAR ENSEMBLE */ diff --git a/src/arch/instruction.h b/src/arch/instruction.h index a9e2bd2..4dcba44 100644 --- a/src/arch/instruction.h +++ b/src/arch/instruction.h @@ -32,6 +32,8 @@ #include "archbase.h" #include "operand.h" +#include "../decomp/context.h" +#include "../decomp/instruction.h" #include "../format/executable.h" @@ -77,7 +79,7 @@ void g_arch_instruction_attach_extra_operand(GArchInstruction *, GArchOperand *) size_t g_arch_instruction_count_operands(const GArchInstruction *); /* Fournit un opérande donné d'une instruction. */ -const GArchOperand *g_arch_instruction_get_operand(GArchInstruction *, size_t); +GArchOperand *g_arch_instruction_get_operand(const GArchInstruction *, size_t); /* Remplace un opérande d'une instruction par un autre. */ void g_arch_instruction_replace_operand(GArchInstruction *, GArchOperand *, const GArchOperand *); @@ -94,6 +96,9 @@ InstructionLinkType g_arch_instruction_get_link(const GArchInstruction *, vmpa_t /* Indique si l'instruction correspond à un retour de fonction. */ bool g_arch_instruction_is_return(const GArchInstruction *instr); +/* Décompile une instruction de façon générique. */ +GDecInstruction *g_arch_instruction_decompile(const GArchInstruction *, GDecContext *); + /* -------------------- TRAITEMENT DES INSTRUCTIONS PAR ENSEMBLE -------------------- */ diff --git a/src/arch/operand-int.h b/src/arch/operand-int.h index 258a60e..f21b995 100644 --- a/src/arch/operand-int.h +++ b/src/arch/operand-int.h @@ -33,6 +33,8 @@ /* Traduit un opérande en version humainement lisible. */ typedef char * (* get_operand_text_fc) (const GArchOperand *, const GExeFormat *, AsmSyntax); +/* Traduit un opérande en version humainement lisible. */ +typedef void (* operand_print_fc) (const GArchOperand *, GBufferLine *, AsmSyntax); /* Définition générique d'un opérande d'architecture (instance) */ struct _GArchOperand @@ -40,6 +42,7 @@ struct _GArchOperand GContentExporter parent; /* A laisser en premier */ get_operand_text_fc get_text; /* Texte humain équivalent */ + operand_print_fc print; /* Texte humain équivalent */ }; diff --git a/src/arch/operand.c b/src/arch/operand.c index d4f6b56..16fc073 100644 --- a/src/arch/operand.c +++ b/src/arch/operand.c @@ -96,3 +96,24 @@ char *g_arch_operand_get_text(const GArchOperand *operand, const GExeFormat *for return operand->get_text(operand, format, syntax); } + + +/****************************************************************************** +* * +* Paramètres : operand = opérande à traiter. * +* line = ligne tampon où imprimer l'opérande donné. * +* syntax = type de représentation demandée. * +* * +* Description : Traduit un opérande en version humainement lisible. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_arch_operand_print(const GArchOperand *operand, GBufferLine *line, AsmSyntax syntax) +{ + return operand->print(operand, line, syntax); + +} diff --git a/src/arch/operand.h b/src/arch/operand.h index 6d0dc48..3745a80 100644 --- a/src/arch/operand.h +++ b/src/arch/operand.h @@ -28,7 +28,8 @@ #include -#include "../format/executable.h" +#include "../format/executable.h" /* FIXME : remme ! */ +#include "../glibext/gbufferline.h" @@ -51,6 +52,9 @@ GType g_arch_operand_get_type(void); /* Traduit un opérande en version humainement lisible. */ char *g_arch_operand_get_text(const GArchOperand *, const GExeFormat *, AsmSyntax); +/* Traduit un opérande en version humainement lisible. */ +void g_arch_operand_print(const GArchOperand *, GBufferLine *, AsmSyntax); + #endif /* _ARCH_OPERAND_H */ diff --git a/src/arch/translate.h b/src/arch/translate.h new file mode 100644 index 0000000..6811bc3 --- /dev/null +++ b/src/arch/translate.h @@ -0,0 +1,39 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * translate.h - prototypes pour les environnements de traduction d'instructions + * + * Copyright (C) 2010 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 _ARCH_TRANSLATE_H +#define _ARCH_TRANSLATE_H + + +#include "instruction.h" +#include "../decomp/context.h" +#include "../decomp/instruction.h" + + + +/* Décompile une instruction quelconque. */ +typedef GDecInstruction * (* decomp_instr_fc) (const GArchInstruction *, GDecContext *); + + + +#endif /* _ANALYSIS_DECOMP_RTL_TRANSLATE_H */ diff --git a/src/decomp/Makefile.am b/src/decomp/Makefile.am index d77ad29..20694d0 100755 --- a/src/decomp/Makefile.am +++ b/src/decomp/Makefile.am @@ -2,10 +2,16 @@ noinst_LTLIBRARIES = libdecomp.la libdecomp_la_SOURCES = \ + context.h context.c \ + expression-int.h \ + expression.h expression.c \ + instruction-int.h \ + instruction.h instruction.c \ output-int.h \ output.h output.c libdecomp_la_LIBADD = \ + expr/libdecompexpr.la \ lang/libdecomplang.la libdecomp_la_LDFLAGS = @@ -17,4 +23,4 @@ AM_CPPFLAGS = AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) -SUBDIRS = lang +SUBDIRS = expr lang diff --git a/src/decomp/context.c b/src/decomp/context.c new file mode 100644 index 0000000..7fe6937 --- /dev/null +++ b/src/decomp/context.c @@ -0,0 +1,153 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * context.c - mise en place d'un contexte de décompilation + * + * Copyright (C) 2010 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 "context.h" + + + +/* Définition d'une context décompilée (instance) */ +struct _GDecContext +{ + GObject parent; /* A laisser en premier */ + + vmpa_t max; /* Première adresse à écarter */ + +}; + + +/* Définition d'une context décompilée (classe) */ +struct _GDecContextClass +{ + GObjectClass parent; /* A laisser en premier */ + +}; + + +/* Initialise la classe des contextes de décompilation. */ +static void g_dec_context_class_init(GDecContextClass *); + +/* Initialise une instance de contexte de décompilation. */ +static void g_dec_context_init(GDecContext *); + + + +/* Indique le type défini pour un contexte de décompilation. */ +G_DEFINE_TYPE(GDecContext, g_dec_context, G_TYPE_OBJECT); + + +/****************************************************************************** +* * +* Paramètres : klass = classe à initialiser. * +* * +* Description : Initialise la classe des contextes de décompilation. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_dec_context_class_init(GDecContextClass *klass) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : ctx = instance à initialiser. * +* * +* Description : Initialise une instance de contexte de décompilation. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_dec_context_init(GDecContext *ctx) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Met en place un nouveau contexte de décompilation. * +* * +* Retour : Contexte de décompilation prêt à emploi. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GDecContext *g_dec_context_new(void) +{ + GDecContext *result; /* Instance à retourner */ + + result = g_object_new(G_TYPE_DEC_CONTEXT, NULL); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : ctx = instance à consulter. * +* * +* Description : Indique l'adresse où la décompilation n'est plus souhaitée. * +* * +* Retour : Adresse mémoire ou physique. * +* * +* Remarques : - * +* * +******************************************************************************/ + +vmpa_t g_dec_context_get_max_address(const GDecContext *ctx) +{ + return ctx->max; + +} + + +/****************************************************************************** +* * +* Paramètres : ctx = instance à consulter. * +* max = adresse mémoire ou physique. * +* * +* Description : Définit l'adresse où la décompilation n'est plus souhaitée. * +* * +* Retour : - . * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_dec_context_set_max_address(GDecContext *ctx, vmpa_t max) +{ + ctx->max = max; + +} diff --git a/src/decomp/context.h b/src/decomp/context.h new file mode 100644 index 0000000..76105e6 --- /dev/null +++ b/src/decomp/context.h @@ -0,0 +1,66 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * context.h - prototypes pour la mise en place d'un contexte de décompilation + * + * Copyright (C) 2010 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 _DECOMP_CONTEXT_H +#define _DECOMP_CONTEXT_H + + +#include + + +#include "expr/pseudo.h" +#include "../arch/archbase.h" + + + +#define G_TYPE_DEC_CONTEXT g_dec_context_get_type() +#define G_DEC_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_dec_context_get_type(), GDecContext)) +#define G_IS_DEC_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_dec_context_get_type())) +#define G_DEC_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_DEC_CONTEXT, GDecContextClass)) +#define G_IS_DEC_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_DEC_CONTEXT)) +#define G_DEC_CONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DEC_CONTEXT, GDecContextClass)) + + + +/* Définition d'un contexte de décompilation (instance) */ +typedef struct _GDecContext GDecContext; + +/* Définition d'un contexte de décompilation (classe) */ +typedef struct _GDecContextClass GDecContextClass; + + +/* Indique le type défini pour un contexte de décompilation. */ +GType g_dec_context_get_type(void); + +/* Met en place un nouveau contexte de décompilation. */ +GDecContext *g_dec_context_new(void); + +/* Indique l'adresse où la décompilation n'est plus souhaitée. */ +vmpa_t g_dec_context_get_max_address(const GDecContext *); + +/* Définit l'adresse où la décompilation n'est plus souhaitée. */ +void g_dec_context_set_max_address(GDecContext *, vmpa_t); + + + +#endif /* _DECOMP_CONTEXT_H */ diff --git a/src/decomp/expr/Makefile.am b/src/decomp/expr/Makefile.am new file mode 100644 index 0000000..3c15758 --- /dev/null +++ b/src/decomp/expr/Makefile.am @@ -0,0 +1,24 @@ + +noinst_LTLIBRARIES = libdecompexpr.la + +libdecompexpr_la_SOURCES = \ + arithm.h arithm.c \ + array.h array.c \ + assign.h assign.c \ + block.h block.c \ + call.h call.c \ + immediate.h immediate.c \ + pseudo.h pseudo.c + +libdecompexpr_la_LDFLAGS = + +libdecompexpr_la_LIBADD = \ + dalvik/libdecompexprdalvik.la + +INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) + +AM_CPPFLAGS = + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) + +SUBDIRS = dalvik diff --git a/src/decomp/expr/arithm.c b/src/decomp/expr/arithm.c new file mode 100644 index 0000000..605830d --- /dev/null +++ b/src/decomp/expr/arithm.c @@ -0,0 +1,197 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * arithm.c - représentation des opérations arithmétiques + * + * Copyright (C) 2010 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 "arithm.h" + + +#include "../expression-int.h" + + + +/* Définition d'une opération arithmétique définie (instance) */ +struct _GArithmExpression +{ + GDecExpression parent; /* A laisser en premier */ + + GDecExpression *op1; /* Premier opérande manipulé */ + GDecExpression *op2; /* Second opérande manipulé */ + + ArithmOperationType type; /* Opération à représenter */ + +}; + + +/* Définition d'une opération arithmétique définie (classe) */ +struct _GArithmExpressionClass +{ + GDecExpressionClass parent; /* A laisser en premier */ + +}; + + + +/* Initialise la classe des opérations arithmétiques définies. */ +static void g_arithm_expression_class_init(GArithmExpressionClass *); + +/* Initialise une instance d'opération arithmétique définie. */ +static void g_arithm_expression_init(GArithmExpression *); + +/* Imprime pour l'écran un version humaine d'une expression. */ +static void g_arithm_expression_print(const GArithmExpression *, GCodeBuffer *, GBufferLine *, GLangOutput *); + + + +/* Indique le type défini pour une opération arithmétique définie. */ +G_DEFINE_TYPE(GArithmExpression, g_arithm_expression, G_TYPE_DEC_EXPRESSION); + + +/****************************************************************************** +* * +* Paramètres : klass = classe à initialiser. * +* * +* Description : Initialise la classe des opérations arithmétiques définies. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_arithm_expression_class_init(GArithmExpressionClass *klass) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : expr = instance à initialiser. * +* * +* Description : Initialise une instance d'opération arithmétique définie. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_arithm_expression_init(GArithmExpression *expr) +{ + GDecInstruction *instr; /* Autre version de l'objet */ + + instr = G_DEC_INSTRUCTION(expr); + + instr->print = (dec_instr_print_fc)g_arithm_expression_print; + +} + + +/****************************************************************************** +* * +* Paramètres : op1 = premier opérande à manipuler. * +* type = type d'opération à mener ici. * +* op2 = seconde opérande à manipuler. * +* * +* Description : Représente une opération arithmétique entre deux opérandes. * +* * +* Retour : Expression mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GDecInstruction *g_arithm_expression_new(GDecExpression *op1, ArithmOperationType type, GDecExpression *op2) +{ + GArithmExpression *result; /* Expression à retourner */ + + result = g_object_new(G_TYPE_ARITHM_EXPRESSION, NULL); + + result->op1 = op1; + result->op2 = op2; + + result->type = type; + + return G_DEC_INSTRUCTION(result); + +} + + +/****************************************************************************** +* * +* Paramètres : expr = expression à transcrire en version humaine. * +* buffer = tampon où doit se réaliser l'insertion. * +* line = ligne d'impression prête à emploi ou NULL. * +* output = langage de programmation de sortie. * +* * +* Description : Imprime pour l'écran un version humaine d'une expression. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_arithm_expression_print(const GArithmExpression *expr, GCodeBuffer *buffer, GBufferLine *line, GLangOutput *output) +{ + const char *sign; /* Symbole de l'opération */ + + g_dec_instruction_print(G_DEC_INSTRUCTION(expr->op1), + buffer, line, output); + + switch (expr->type) + { + case AOT_ADD: + sign = " + "; + break; + case AOT_SUB: + sign = " - "; + break; + case AOT_MUL: + sign = " * "; + break; + case AOT_DIV: + sign = " / "; + break; + case AOT_REM: + sign = " % "; + break; + case AOT_AND: + sign = " & "; + break; + case AOT_OR: + sign = " | "; + break; + case AOT_XOR: + sign = " ^ "; + break; + default: /* AOT_COUNT */ + sign = " ? "; + break; + } + + g_buffer_line_insert_text(line, BLC_ASSEMBLY, sign, 3, RTT_SIGNS); + + g_dec_instruction_print(G_DEC_INSTRUCTION(expr->op2), + buffer, line, output); + +} diff --git a/src/decomp/expr/arithm.h b/src/decomp/expr/arithm.h new file mode 100644 index 0000000..1de9865 --- /dev/null +++ b/src/decomp/expr/arithm.h @@ -0,0 +1,76 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * arithm.h - prototypes pour la représentation des opérations arithmétiques + * + * Copyright (C) 2010 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 _ANALYSIS_DECOMP_COMMON_ARITHM_H +#define _ANALYSIS_DECOMP_COMMON_ARITHM_H + + +#include + + +#include "../expression.h" +#include "../instruction.h" + + + +#define G_TYPE_ARITHM_EXPRESSION g_arithm_expression_get_type() +#define G_ARITHM_EXPRESSION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_arithm_expression_get_type(), GArithmExpression)) +#define G_IS_ARITHM_EXPRESSION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_arithm_expression_get_type())) +#define G_ARITHM_EXPRESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_ARITHM_EXPRESSION, GArithmExpressionClass)) +#define G_IS_ARITHM_EXPRESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_ARITHM_EXPRESSION)) +#define G_ARITHM_EXPRESSION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_ARITHM_EXPRESSION, GArithmExpressionClass)) + + +/* Définition d'une opération arithmétique définie (instance) */ +typedef struct _GArithmExpression GArithmExpression; + +/* Définition d'une opération arithmétique définie (classe) */ +typedef struct _GArithmExpressionClass GArithmExpressionClass; + + +/* Types d'opérations menables */ +typedef enum _ArithmOperationType +{ + AOT_ADD, /* Addition */ + AOT_SUB, /* Soustraction */ + AOT_MUL, /* Multiplication */ + AOT_DIV, /* Division */ + AOT_REM, /* Modulo */ + AOT_AND, /* Et logique */ + AOT_OR, /* Ou logique */ + AOT_XOR, /* Ou exclusif */ + + AOT_COUNT + +} ArithmOperationType; + + +/* Indique le type défini pour une opération arithmétique définie. */ +GType g_arithm_expression_get_type(void); + +/* Représente une opération arithmétique entre deux opérandes. */ +GDecInstruction *g_arithm_expression_new(GDecExpression *, ArithmOperationType, GDecExpression *); + + + +#endif /* _ANALYSIS_DECOMP_COMMON_ARITHM_H */ diff --git a/src/decomp/expr/array.c b/src/decomp/expr/array.c new file mode 100644 index 0000000..497e47a --- /dev/null +++ b/src/decomp/expr/array.c @@ -0,0 +1,161 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * array.c - manipulations de tableaux génériques + * + * Copyright (C) 2010 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 "array.h" + + +#include "../expression-int.h" + + + +/* Définition d'un accès à une cellule de tableau (instance) */ +struct _GArrayAccess +{ + GDecExpression parent; /* A laisser en premier */ + + GDecExpression *array; /* Elément auquel accéder */ + GDecExpression *index; /* Position de la cellule */ + +}; + + +/* Définition d'un accès à une cellule de tableau (classe) */ +struct _GArrayAccessClass +{ + GDecExpressionClass parent; /* A laisser en premier */ + +}; + + + +/* Initialise la classe des accès aux cellules de tableau. */ +static void g_array_access_class_init(GArrayAccessClass *); + +/* Initialise une instance d'accès à une cellule de tableau. */ +static void g_array_access_init(GArrayAccess *); + +/* Imprime pour l'écran un version humaine d'une expression. */ +static void g_array_access_print(const GArrayAccess *, GCodeBuffer *, GBufferLine *, GLangOutput *); + + + +/* Indique le type défini pour un accès à une cellule de tableau. */ +G_DEFINE_TYPE(GArrayAccess, g_array_access, G_TYPE_DEC_EXPRESSION); + + +/****************************************************************************** +* * +* Paramètres : klass = classe à initialiser. * +* * +* Description : Initialise la classe des accès aux cellules de tableau. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_array_access_class_init(GArrayAccessClass *klass) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : expr = instance à initialiser. * +* * +* Description : Initialise une instance d'accès à une cellule de tableau. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_array_access_init(GArrayAccess *expr) +{ + GDecInstruction *instr; /* Autre version de l'objet */ + + instr = G_DEC_INSTRUCTION(expr); + + instr->print = (dec_instr_print_fc)g_array_access_print; + +} + + +/****************************************************************************** +* * +* Paramètres : array = tableau auquel on doit accéder. * +* index = indice de la cellule concernée. * +* * +* Description : Construit un accès à une cellule de tableau comme expression.* +* * +* Retour : Expression mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GDecInstruction *g_array_access_new(GDecExpression *array, GDecExpression *index) +{ + GArrayAccess *result; /* Expression à retourner */ + + result = g_object_new(G_TYPE_ARRAY_ACCESS, NULL); + + result->array = array; + result->index = index; + + return G_DEC_INSTRUCTION(result); + +} + + +/****************************************************************************** +* * +* Paramètres : expr = expression à transcrire en version humaine. * +* buffer = tampon où doit se réaliser l'insertion. * +* line = ligne d'impression prête à emploi ou NULL. * +* output = langage de programmation de sortie. * +* * +* Description : Imprime pour l'écran un version humaine d'une expression. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_array_access_print(const GArrayAccess *expr, GCodeBuffer *buffer, GBufferLine *line, GLangOutput *output) +{ + g_dec_instruction_print(G_DEC_INSTRUCTION(expr->array), + buffer, line, output); + + g_buffer_line_insert_text(line, BLC_ASSEMBLY, "[", 1, RTT_RAW); + + g_dec_instruction_print(G_DEC_INSTRUCTION(expr->index), + buffer, line, output); + + g_buffer_line_insert_text(line, BLC_ASSEMBLY, "]", 1, RTT_RAW); + +} diff --git a/src/decomp/expr/array.h b/src/decomp/expr/array.h new file mode 100644 index 0000000..0007a8e --- /dev/null +++ b/src/decomp/expr/array.h @@ -0,0 +1,61 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * array.h - prototypes pour les manipulations de tableaux génériques + * + * Copyright (C) 2010 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 _DECOMP_EXPR_ARRAY_H +#define _DECOMP_EXPR_ARRAY_H + + +#include + + +#include "../expression.h" +#include "../instruction.h" + + + +#define G_TYPE_ARRAY_ACCESS g_array_access_get_type() +#define G_ARRAY_ACCESS(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_array_access_get_type(), GArrayAccess)) +#define G_IS_ARRAY_ACCESS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_array_access_get_type())) +#define G_ARRAY_ACCESS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_ARRAY_ACCESS, GArrayAccessClass)) +#define G_IS_ARRAY_ACCESS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_ARRAY_ACCESS)) +#define G_ARRAY_ACCESS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_ARRAY_ACCESS, GArrayAccessClass)) + + + +/* Définition d'un accès à une cellule de tableau (instance) */ +typedef struct _GArrayAccess GArrayAccess; + +/* Définition d'un accès à une cellule de tableau (classe) */ +typedef struct _GArrayAccessClass GArrayAccessClass; + + + +/* Indique le type défini pour un accès à une cellule de tableau. */ +GType g_array_access_get_type(void); + +/* Construit un accès à une cellule de tableau comme expression. */ +GDecInstruction *g_array_access_new(GDecExpression *, GDecExpression *); + + + +#endif /* _DECOMP_EXPR_ARRAY_H */ diff --git a/src/decomp/expr/assign.c b/src/decomp/expr/assign.c new file mode 100644 index 0000000..561fb0f --- /dev/null +++ b/src/decomp/expr/assign.c @@ -0,0 +1,159 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * assign.c - représentation des assignations + * + * Copyright (C) 2010 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 "assign.h" + + +#include "../expression-int.h" + + + +/* Définition d'une assignation quelconque (instance) */ +struct _GAssignExpression +{ + GDecExpression parent; /* A laisser en premier */ + + GDecExpression *dest; /* Destination de l'assignat° */ + GDecExpression *src; /* Source de l'assignation */ + +}; + + +/* Définition d'une assignation quelconque (classe) */ +struct _GAssignExpressionClass +{ + GDecExpressionClass parent; /* A laisser en premier */ + +}; + + + +/* Initialise la classe des assignations quelconques. */ +static void g_assign_expression_class_init(GAssignExpressionClass *); + +/* Initialise une instance d'assignation quelconque. */ +static void g_assign_expression_init(GAssignExpression *); + +/* Imprime pour l'écran un version humaine d'une expression. */ +static void g_assign_expression_print(const GAssignExpression *, GCodeBuffer *, GBufferLine *, GLangOutput *); + + + +/* Indique le type défini pour une assignation quelconque. */ +G_DEFINE_TYPE(GAssignExpression, g_assign_expression, G_TYPE_DEC_EXPRESSION); + + +/****************************************************************************** +* * +* Paramètres : klass = classe à initialiser. * +* * +* Description : Initialise la classe des assignations quelconques. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_assign_expression_class_init(GAssignExpressionClass *klass) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : expr = instance à initialiser. * +* * +* Description : Initialise une instance d'assignation quelconque. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_assign_expression_init(GAssignExpression *expr) +{ + GDecInstruction *instr; /* Autre version de l'objet */ + + instr = G_DEC_INSTRUCTION(expr); + + instr->print = (dec_instr_print_fc)g_assign_expression_print; + +} + + +/****************************************************************************** +* * +* Paramètres : dest = expression servant de destination. * +* src = source de l'expression à transférer. * +* * +* Description : Assigne le contenu d'une expression dans une autre. * +* * +* Retour : Expression mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GDecInstruction *g_assign_expression_new(GDecExpression *dest, GDecExpression *src) +{ + GAssignExpression *result; /* Expression à retourner */ + + result = g_object_new(G_TYPE_ASSIGN_EXPRESSION, NULL); + + result->dest = dest; + result->src = src; + + return G_DEC_INSTRUCTION(result); + +} + + +/****************************************************************************** +* * +* Paramètres : expr = expression à transcrire en version humaine. * +* buffer = tampon où doit se réaliser l'insertion. * +* line = ligne d'impression prête à emploi ou NULL. * +* output = langage de programmation de sortie. * +* * +* Description : Imprime pour l'écran un version humaine d'une expression. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_assign_expression_print(const GAssignExpression *expr, GCodeBuffer *buffer, GBufferLine *line, GLangOutput *output) +{ + g_dec_instruction_print(G_DEC_INSTRUCTION(expr->dest), + buffer, line, output); + + g_buffer_line_insert_text(line, BLC_ASSEMBLY, " = ", 3, RTT_SIGNS); + + g_dec_instruction_print(G_DEC_INSTRUCTION(expr->src), + buffer, line, output); + +} diff --git a/src/decomp/expr/assign.h b/src/decomp/expr/assign.h new file mode 100644 index 0000000..87d167e --- /dev/null +++ b/src/decomp/expr/assign.h @@ -0,0 +1,60 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * assign.h - prototypes pour la représentation des assignations + * + * Copyright (C) 2010 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 _DECOMP_EXPR_ASSIGN_H +#define _DECOMP_EXPR_ASSIGN_H + + +#include + + +#include "../expression.h" +#include "../instruction.h" + + + +#define G_TYPE_ASSIGN_EXPRESSION g_assign_expression_get_type() +#define G_ASSIGN_EXPRESSION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_assign_expression_get_type(), GAssignExpression)) +#define G_IS_ASSIGN_EXPRESSION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_assign_expression_get_type())) +#define G_ASSIGN_EXPRESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_ASSIGN_EXPRESSION, GAssignExpressionClass)) +#define G_IS_ASSIGN_EXPRESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_ASSIGN_EXPRESSION)) +#define G_ASSIGN_EXPRESSION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_ASSIGN_EXPRESSION, GAssignExpressionClass)) + + + +/* Définition d'une assignation quelconque (instance) */ +typedef struct _GAssignExpression GAssignExpression; + +/* Définition d'une assignation quelconque (classe) */ +typedef struct _GAssignExpressionClass GAssignExpressionClass; + + +/* Indique le type défini pour une assignation quelconque. */ +GType g_assign_expression_get_type(void); + +/* Assigne le contenu d'une expression dans une autre. */ +GDecInstruction *g_assign_expression_new(GDecExpression *, GDecExpression *); + + + +#endif /* _DECOMP_EXPR_ASSIGN_H */ diff --git a/src/decomp/expr/block.c b/src/decomp/expr/block.c new file mode 100644 index 0000000..c14e169 --- /dev/null +++ b/src/decomp/expr/block.c @@ -0,0 +1,185 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * block.c - regroupement d'un lot d'instructions + * + * Copyright (C) 2010 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 "block.h" + + +#include + + +#include "../expression-int.h" + + + +/* Définition d'un ensemble d'instructions décompilées (instance) */ +struct _GExprBlock +{ + GDecExpression parent; /* A laisser en premier */ + + GDecInstruction **list; /* Instructions contenues */ + size_t count; /* Taille de cette liste */ + +}; + + +/* Définition d'un ensemble d'instructions décompilées (classe) */ +struct _GExprBlockClass +{ + GDecExpressionClass parent; /* A laisser en premier */ + +}; + + + +/* Initialise la classe des ensembles d'instructions. */ +static void g_expr_block_class_init(GExprBlockClass *); + +/* Initialise une instance d'ensemble d'instructions. */ +static void g_expr_block_init(GExprBlock *); + +/* Imprime pour l'écran un version humaine d'une expression. */ +static void g_expr_block_print(const GExprBlock *, GCodeBuffer *, GBufferLine *, GLangOutput *); + + + +/* Indique le type défini pour un ensemble d'instructions décompilées. */ +G_DEFINE_TYPE(GExprBlock, g_expr_block, G_TYPE_DEC_EXPRESSION); + + +/****************************************************************************** +* * +* Paramètres : klass = classe à initialiser. * +* * +* Description : Initialise la classe des ensembles d'instructions. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_expr_block_class_init(GExprBlockClass *klass) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : block = instance à initialiser. * +* * +* Description : Initialise une instance d'ensemble d'instructions. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_expr_block_init(GExprBlock *block) +{ + GDecInstruction *instr; /* Autre version de l'objet */ + + instr = G_DEC_INSTRUCTION(block); + + instr->print = (dec_instr_print_fc)g_expr_block_print; + +} + + +/****************************************************************************** +* * +* Paramètres : item = premier élément du nouvel ensemble. * +* * +* Description : Constuit un conteneur pour diverses instructions décompilées.* +* * +* Retour : Conteneur d'instructions mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GDecInstruction *g_expr_block_new(GDecInstruction *item) +{ + GExprBlock *result; /* Groupe d'instructions à renvoyer */ + + result = g_object_new(G_TYPE_EXPR_BLOCK, NULL); + + g_expr_block_add_item(result, item); + + return G_DEC_INSTRUCTION(result); + +} + + +/****************************************************************************** +* * +* Paramètres : block = expression à transcrire en version humaine. * +* buffer = tampon où doit se réaliser l'insertion. * +* line = ligne d'impression prête à emploi ou NULL. * +* output = langage de programmation de sortie. * +* * +* Description : Imprime pour l'écran un version humaine d'une expression. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_expr_block_print(const GExprBlock *block, GCodeBuffer *buffer, GBufferLine *line, GLangOutput *output) +{ + size_t i; /* Boucle de parcours */ + + for (i = 0; i < block->count; i++) + { + if (i > 0) + line = g_code_buffer_append_new_line(buffer); /* FIXME : n° de ligne */ + + g_dec_instruction_print(block->list[i], buffer, line, output); + + } + +} + + +/****************************************************************************** +* * +* Paramètres : block = ensemble à faire évoluer. * +* item = nouvel élément à placer dans l'ensemble. * +* * +* Description : Ajoute une instruction décompilée au conteneur existant. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_expr_block_add_item(GExprBlock *block, GDecInstruction *item) +{ + block->list = (GDecInstruction **)realloc(block->list, + ++block->count * sizeof(GDecInstruction *)); + block->list[block->count - 1] = item; + +} diff --git a/src/decomp/expr/block.h b/src/decomp/expr/block.h new file mode 100644 index 0000000..4ae4ff1 --- /dev/null +++ b/src/decomp/expr/block.h @@ -0,0 +1,62 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * block.h - prototypes pour le regroupement d'un lot d'instructions + * + * Copyright (C) 2010 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 _DECOMP_EXPR_BLOCK_H +#define _DECOMP_EXPR_BLOCK_H + + +#include + + +#include "../instruction.h" + + + +#define G_TYPE_EXPR_BLOCK g_expr_block_get_type() +#define G_EXPR_BLOCK(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_expr_block_get_type(), GExprBlock)) +#define G_IS_EXPR_BLOCK(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_expr_block_get_type())) +#define G_EXPR_BLOCK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_EXPR_BLOCK, GExprBlockClass)) +#define G_IS_EXPR_BLOCK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_EXPR_BLOCK)) +#define G_EXPR_BLOCK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_EXPR_BLOCK, GExprBlockClass)) + + + +/* Définition d'un ensemble d'instructions décompilées (instance) */ +typedef struct _GExprBlock GExprBlock; + +/* Définition d'un ensemble d'instructions décompilées (classe) */ +typedef struct _GExprBlockClass GExprBlockClass; + + +/* Indique le type défini pour un ensemble d'instructions décompilées. */ +GType g_expr_block_get_type(void); + +/* Constuit un conteneur pour diverses instructions décompilées. */ +GDecInstruction *g_expr_block_new(GDecInstruction *); + +/* Ajoute une instruction décompilée au conteneur existant. */ +void g_expr_block_add_item(GExprBlock *, GDecInstruction *); + + + +#endif /* _DECOMP_EXPR_BLOCK_H */ diff --git a/src/decomp/expr/call.c b/src/decomp/expr/call.c new file mode 100644 index 0000000..8f73c4f --- /dev/null +++ b/src/decomp/expr/call.c @@ -0,0 +1,163 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * call.c - encadrement des appels de routine + * + * Copyright (C) 2010 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 "call.h" + + +#include + + +#include "../expression-int.h" + + + +/* Définition d'un appel à une routine quelconque (instance) */ +struct _GRoutineCall +{ + GDecExpression parent; /* A laisser en premier */ + + GBinRoutine *routine; /* Routine sollicitée */ + bool is_object; /* Nature de l'argument n°1 */ + +}; + + +/* Définition d'un appel à une routine quelconque (classe) */ +struct _GRoutineCallClass +{ + GDecExpressionClass parent; /* A laisser en premier */ + +}; + + + +/* Initialise la classe des appels à une routine quelconque. */ +static void g_routine_call_class_init(GRoutineCallClass *); + +/* Initialise une instance d'appel à une routine quelconque. */ +static void g_routine_call_init(GRoutineCall *); + +/* Imprime pour l'écran un version humaine d'une expression. */ +static void g_routine_call_print(const GRoutineCall *, GCodeBuffer *, GBufferLine *, GLangOutput *); + + + +/* Indique le type défini pour un appel à une routine quelconque. */ +G_DEFINE_TYPE(GRoutineCall, g_routine_call, G_TYPE_DEC_EXPRESSION); + + +/****************************************************************************** +* * +* Paramètres : klass = classe à initialiser. * +* * +* Description : Initialise la classe des appels à une routine quelconque. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_routine_call_class_init(GRoutineCallClass *klass) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : expr = instance à initialiser. * +* * +* Description : Initialise une instance d'appel à une routine quelconque. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_routine_call_init(GRoutineCall *expr) +{ + GDecInstruction *instr; /* Autre version de l'objet */ + + instr = G_DEC_INSTRUCTION(expr); + + instr->print = (dec_instr_print_fc)g_routine_call_print; + +} + + +/****************************************************************************** +* * +* Paramètres : routine = routine dont il est fait appel. * +* is_object = indique la nature du premier argument. * +* * +* Description : Exprime un appel à une routine quelconque. * +* * +* Retour : Expression mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GDecInstruction *g_routine_call_new(GBinRoutine *routine, bool is_object) +{ + GRoutineCall *result; /* Expression à retourner */ + + result = g_object_new(G_TYPE_ROUTINE_CALL, NULL); + + result->routine = routine; + result->is_object = is_object; + + return G_DEC_INSTRUCTION(result); + +} + + +/****************************************************************************** +* * +* Paramètres : expr = expression à transcrire en version humaine. * +* buffer = tampon où doit se réaliser l'insertion. * +* line = ligne d'impression prête à emploi ou NULL. * +* output = langage de programmation de sortie. * +* * +* Description : Imprime pour l'écran un version humaine d'une expression. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_routine_call_print(const GRoutineCall *expr, GCodeBuffer *buffer, GBufferLine *line, GLangOutput *output) +{ + const char *name; /* Désignation de la routine */ + + name = g_binary_routine_get_name(expr->routine); + g_buffer_line_insert_text(line, BLC_ASSEMBLY, name, strlen(name), RTT_RAW); + + g_buffer_line_insert_text(line, BLC_ASSEMBLY, "(", 1, RTT_PUNCT); + + g_buffer_line_insert_text(line, BLC_ASSEMBLY, ")", 1, RTT_PUNCT); + +} diff --git a/src/decomp/expr/call.h b/src/decomp/expr/call.h new file mode 100644 index 0000000..7515261 --- /dev/null +++ b/src/decomp/expr/call.h @@ -0,0 +1,61 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * call.h - prototypes pour l'encadrement des appels de routine + * + * Copyright (C) 2010 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 _DECOMP_EXPR_CALL_H +#define _DECOMP_EXPR_CALL_H + + +#include + + +#include "../expression.h" +#include "../instruction.h" +#include "../../analysis/routine.h" + + + +#define G_TYPE_ROUTINE_CALL g_routine_call_get_type() +#define G_ROUTINE_CALL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_routine_call_get_type(), GRoutineCall)) +#define G_IS_ROUTINE_CALL(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_routine_call_get_type())) +#define G_ROUTINE_CALL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_ROUTINE_CALL, GRoutineCallClass)) +#define G_IS_ROUTINE_CALL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_ROUTINE_CALL)) +#define G_ROUTINE_CALL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_ROUTINE_CALL, GRoutineCallClass)) + + + +/* Définition d'un appel à une routine quelconque (instance) */ +typedef struct _GRoutineCall GRoutineCall; + +/* Définition d'un appel à une routine quelconque (classe) */ +typedef struct _GRoutineCallClass GRoutineCallClass; + + +/* Indique le type défini pour un appel à une routine quelconque. */ +GType g_routine_call_get_type(void); + +/* Exprime un appel à une routine quelconque. */ +GDecInstruction *g_routine_call_new(GBinRoutine *, bool); + + + +#endif /* _DECOMP_EXPR_CALL_H */ diff --git a/src/decomp/expr/dalvik/Makefile.am b/src/decomp/expr/dalvik/Makefile.am new file mode 100644 index 0000000..a14b9dd --- /dev/null +++ b/src/decomp/expr/dalvik/Makefile.am @@ -0,0 +1,14 @@ + +noinst_LTLIBRARIES = libdecompexprdalvik.la + +libdecompexprdalvik_la_SOURCES = \ + array.h array.c + +libdecompexprdalvik_la_LDFLAGS = + + +INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) + +AM_CPPFLAGS = + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) diff --git a/src/decomp/expr/dalvik/array.c b/src/decomp/expr/dalvik/array.c new file mode 100644 index 0000000..55b9d07 --- /dev/null +++ b/src/decomp/expr/dalvik/array.c @@ -0,0 +1,155 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * array.c - manipulations de tableaux propres à Dalvik + * + * Copyright (C) 2010 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 "array.h" + + +#include "../../expression-int.h" + + + +/* Définition d'une expression de mesure de tableau (instance) */ +struct _GDalvikALength +{ + GDecExpression parent; /* A laisser en premier */ + + GDecExpression *array; /* Elément auquel accéder */ + +}; + + +/* Définition d'une expression de mesure de tableau (classe) */ +struct _GDalvikALengthClass +{ + GDecExpressionClass parent; /* A laisser en premier */ + +}; + + + +/* Initialise la classe des expressions de mesure de tableau. */ +static void g_dalvik_alength_class_init(GDalvikALengthClass *); + +/* Initialise une instance d'expression de mesure de tableau. */ +static void g_dalvik_alength_init(GDalvikALength *); + +/* Imprime pour l'écran un version humaine d'une expression. */ +static void g_dalvik_alength_print(const GDalvikALength *, GCodeBuffer *, GBufferLine *, GLangOutput *); + + + +/* Indique le type défini pour une expression de mesure de tableau. */ +G_DEFINE_TYPE(GDalvikALength, g_dalvik_alength, G_TYPE_DEC_EXPRESSION); + + +/****************************************************************************** +* * +* Paramètres : klass = classe à initialiser. * +* * +* Description : Initialise la classe des expressions de mesure de tableau. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_dalvik_alength_class_init(GDalvikALengthClass *klass) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : expr = instance à initialiser. * +* * +* Description : Initialise une instance d'expression de mesure de tableau. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_dalvik_alength_init(GDalvikALength *expr) +{ + GDecInstruction *instr; /* Autre version de l'objet */ + + instr = G_DEC_INSTRUCTION(expr); + + instr->print = (dec_instr_print_fc)g_dalvik_alength_print; + +} + + +/****************************************************************************** +* * +* Paramètres : array = tableau dont on doit mesurer la taille. * +* * +* Description : Construit une expression à partir d'une mesure de tableau. * +* * +* Retour : Expression mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GDecInstruction *g_dalvik_alength_new(GDecExpression *array) +{ + GDalvikALength *result; /* Expression à retourner */ + + result = g_object_new(G_TYPE_DALVIK_ALENGTH, NULL); + + result->array = array; + + return G_DEC_INSTRUCTION(result); + +} + + +/****************************************************************************** +* * +* Paramètres : expr = expression à transcrire en version humaine. * +* buffer = tampon où doit se réaliser l'insertion. * +* line = ligne d'impression prête à emploi ou NULL. * +* output = langage de programmation de sortie. * +* * +* Description : Imprime pour l'écran un version humaine d'une expression. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_dalvik_alength_print(const GDalvikALength *expr, GCodeBuffer *buffer, GBufferLine *line, GLangOutput *output) +{ + g_dec_instruction_print(G_DEC_INSTRUCTION(expr->array), + buffer, line, output); + + g_buffer_line_insert_text(line, BLC_ASSEMBLY, ".", 1, RTT_RAW); + + g_buffer_line_insert_text(line, BLC_ASSEMBLY, "length", 6, RTT_RAW); + +} diff --git a/src/decomp/expr/dalvik/array.h b/src/decomp/expr/dalvik/array.h new file mode 100644 index 0000000..15670ab --- /dev/null +++ b/src/decomp/expr/dalvik/array.h @@ -0,0 +1,61 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * array.h - prototypes pour les manipulations de tableaux propres à Dalvik + * + * Copyright (C) 2010 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 _DECOMP_EXPR_DALVIK_ARRAY_H +#define _DECOMP_EXPR_DALVIK_ARRAY_H + + +#include + + +#include "../../expression.h" +#include "../../instruction.h" + + + +#define G_TYPE_DALVIK_ALENGTH g_dalvik_alength_get_type() +#define G_DALVIK_ALENGTH(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_dalvik_alength_get_type(), GDalvikALength)) +#define G_IS_DALVIK_ALENGTH(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_dalvik_alength_get_type())) +#define G_DALVIK_ALENGTH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_DALVIK_ALENGTH, GDalvikALengthClass)) +#define G_IS_DALVIK_ALENGTH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_DALVIK_ALENGTH)) +#define G_DALVIK_ALENGTH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DALVIK_ALENGTH, GDalvikALengthClass)) + + + +/* Définition d'une expression de mesure de tableau (instance) */ +typedef struct _GDalvikALength GDalvikALength; + +/* Définition d'une expression de mesure de tableau (classe) */ +typedef struct _GDalvikALengthClass GDalvikALengthClass; + + + +/* Indique le type défini pour une expression de mesure de tableau. */ +GType g_dalvik_alength_get_type(void); + +/* Construit une expression à partir d'une mesure de tableau. */ +GDecInstruction *g_dalvik_alength_new(GDecExpression *); + + + +#endif /* _DECOMP_EXPR_DALVIK_ARRAY_H */ diff --git a/src/decomp/expr/immediate.c b/src/decomp/expr/immediate.c new file mode 100644 index 0000000..a97c8bd --- /dev/null +++ b/src/decomp/expr/immediate.c @@ -0,0 +1,150 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * immediate.c - raccord avec les opérandes de valeur immédiate + * + * Copyright (C) 2010 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 "immediate.h" + + +#include "../expression-int.h" + + + +/* Définition d'une expression de valeur immédiate (instance) */ +struct _GImmExpression +{ + GDecExpression parent; /* A laisser en premier */ + + GImmOperand *operand; /* Conteneur d'origine */ + +}; + + +/* Définition d'une expression de valeur immédiate (classe) */ +struct _GImmExpressionClass +{ + GDecExpressionClass parent; /* A laisser en premier */ + +}; + + + +/* Initialise la classe des expressions de valeur immédiate. */ +static void g_imm_expression_class_init(GImmExpressionClass *); + +/* Initialise une instance d'expression de valeur immédiate. */ +static void g_imm_expression_init(GImmExpression *); + +/* Imprime pour l'écran un version humaine d'une expression. */ +static void g_imm_expression_print(const GImmExpression *, GCodeBuffer *, GBufferLine *, GLangOutput *); + + + +/* Indique le type défini pour une expression de valeur immédiate. */ +G_DEFINE_TYPE(GImmExpression, g_imm_expression, G_TYPE_DEC_EXPRESSION); + + +/****************************************************************************** +* * +* Paramètres : klass = classe à initialiser. * +* * +* Description : Initialise la classe des expressions de valeur immédiate. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_imm_expression_class_init(GImmExpressionClass *klass) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : expr = instance à initialiser. * +* * +* Description : Initialise une instance d'expression de valeur immédiate. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_imm_expression_init(GImmExpression *expr) +{ + GDecInstruction *instr; /* Autre version de l'objet */ + + instr = G_DEC_INSTRUCTION(expr); + + instr->print = (dec_instr_print_fc)g_imm_expression_print; + +} + + +/****************************************************************************** +* * +* Paramètres : operand = conteneur d'origie de la valeur immédiate. * +* * +* Description : Construit une expression à partir d'une valeur immédiate. * +* * +* Retour : Expression mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GDecInstruction *g_imm_expression_new(GImmOperand *operand) +{ + GImmExpression *result; /* Expression à retourner */ + + result = g_object_new(G_TYPE_IMM_EXPRESSION, NULL); + + result->operand = operand; + + return G_DEC_INSTRUCTION(result); + +} + + +/****************************************************************************** +* * +* Paramètres : expr = expression à transcrire en version humaine. * +* buffer = tampon où doit se réaliser l'insertion. * +* line = ligne d'impression prête à emploi ou NULL. * +* output = langage de programmation de sortie. * +* * +* Description : Imprime pour l'écran un version humaine d'une expression. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_imm_expression_print(const GImmExpression *expr, GCodeBuffer *buffer, GBufferLine *line, GLangOutput *output) +{ + g_arch_operand_print(G_ARCH_OPERAND(expr->operand), line, ASX_COUNT); + +} diff --git a/src/decomp/expr/immediate.h b/src/decomp/expr/immediate.h new file mode 100644 index 0000000..c86a15c --- /dev/null +++ b/src/decomp/expr/immediate.h @@ -0,0 +1,61 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * immediate.h - prototypes pour le raccord avec les opérandes de valeur immédiate + * + * Copyright (C) 2010 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 _DECOMP_EXPR_IMMEDIATE_H +#define _DECOMP_EXPR_IMMEDIATE_H + + +#include + + +#include "../instruction.h" +#include "../../arch/immediate.h" + + + +#define G_TYPE_IMM_EXPRESSION g_imm_expression_get_type() +#define G_IMM_EXPRESSION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_imm_expression_get_type(), GImmExpression)) +#define G_IS_IMM_EXPRESSION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_imm_expression_get_type())) +#define G_IMM_EXPRESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_IMM_EXPRESSION, GImmExpressionClass)) +#define G_IS_IMM_EXPRESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_IMM_EXPRESSION)) +#define G_IMM_EXPRESSION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_IMM_EXPRESSION, GImmExpressionClass)) + + + +/* Définition d'une expression de valeur immédiate (instance) */ +typedef struct _GImmExpression GImmExpression; + +/* Définition d'une expression de valeur immédiate (classe) */ +typedef struct _GImmExpressionClass GImmExpressionClass; + + + +/* Indique le type défini pour une expression de valeur immédiate. */ +GType g_imm_expression_get_type(void); + +/*Construit une expression à partir d'une valeur immédiate. */ +GDecInstruction *g_imm_expression_new(GImmOperand *); + + + +#endif /* _DECOMP_EXPR_IMMEDIATE_H */ diff --git a/src/decomp/expr/pseudo.c b/src/decomp/expr/pseudo.c new file mode 100644 index 0000000..393f32c --- /dev/null +++ b/src/decomp/expr/pseudo.c @@ -0,0 +1,148 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * pseudo.c - définition des pseudo-registres + * + * Copyright (C) 2010 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 "pseudo.h" + + +#include "../expression-int.h" + + + +/* Définition d'un pseudo-registre (instance) */ +struct _GPseudoRegister +{ + GDecExpression parent; /* A laisser en premier */ + +}; + + +/* Définition d'un pseudo-registre (classe) */ +struct _GPseudoRegisterClass +{ + GDecExpressionClass parent; /* A laisser en premier */ + +}; + + + +/* Initialise la classe des pseudo-registres. */ +static void g_pseudo_register_class_init(GPseudoRegisterClass *); + +/* Initialise une instance de pseudo-registre. */ +static void g_pseudo_register_init(GPseudoRegister *); + +/* Imprime pour l'écran un version humaine d'une expression. */ +static void g_pseudo_register_print(const GPseudoRegister *, GCodeBuffer *, GBufferLine *, GLangOutput *); + + + +/* Indique le type défini pour un pseudo-registre. */ +G_DEFINE_TYPE(GPseudoRegister, g_pseudo_register, G_TYPE_DEC_EXPRESSION); + + +/****************************************************************************** +* * +* Paramètres : klass = classe à initialiser. * +* * +* Description : Initialise la classe des pseudo-registres. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_pseudo_register_class_init(GPseudoRegisterClass *klass) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : reg = instance à initialiser. * +* * +* Description : Initialise une instance de pseudo-registre. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_pseudo_register_init(GPseudoRegister *reg) +{ + GDecInstruction *instr; /* Autre version de l'objet */ + + instr = G_DEC_INSTRUCTION(reg); + + instr->print = (dec_instr_print_fc)g_pseudo_register_print; + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Assigne le contenu d'une expression dans une autre. * +* * +* Retour : Pseudo-registre mis en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GDecInstruction *g_pseudo_register_new(void) +{ + GPseudoRegister *result; /* Pseudo-registre à renvoyer */ + + result = g_object_new(G_TYPE_PSEUDO_REGISTER, NULL); + + return G_DEC_INSTRUCTION(result); + +} + + +/****************************************************************************** +* * +* Paramètres : reg = expression à transcrire en version humaine. * +* buffer = tampon où doit se réaliser l'insertion. * +* line = ligne d'impression prête à emploi ou NULL. * +* output = langage de programmation de sortie. * +* * +* Description : Imprime pour l'écran un version humaine d'une expression. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_pseudo_register_print(const GPseudoRegister *reg, GCodeBuffer *buffer, GBufferLine *line, GLangOutput *output) +{ + + g_buffer_line_insert_text(line, BLC_ASSEMBLY, "varX", 4, RTT_RAW); + + +} diff --git a/src/decomp/expr/pseudo.h b/src/decomp/expr/pseudo.h new file mode 100644 index 0000000..9734625 --- /dev/null +++ b/src/decomp/expr/pseudo.h @@ -0,0 +1,59 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * pseudo.h - prototypes pour la définition des pseudo-registres + * + * Copyright (C) 2010 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 _DECOMP_EXPR_PSEUDO_H +#define _DECOMP_EXPR_PSEUDO_H + + +#include + + +#include "../instruction.h" + + + +#define G_TYPE_PSEUDO_REGISTER g_pseudo_register_get_type() +#define G_PSEUDO_REGISTER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_pseudo_register_get_type(), GPseudoRegister)) +#define G_IS_PSEUDO_REGISTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_pseudo_register_get_type())) +#define G_PSEUDO_REGISTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_PSEUDO_REGISTER, GPseudoRegisterClass)) +#define G_IS_PSEUDO_REGISTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_PSEUDO_REGISTER)) +#define G_PSEUDO_REGISTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_PSEUDO_REGISTER, GPseudoRegisterClass)) + + + +/* Définition d'un pseudo-registre (instance) */ +typedef struct _GPseudoRegister GPseudoRegister; + +/* Définition d'un pseudo-registre (classe) */ +typedef struct _GPseudoRegisterClass GPseudoRegisterClass; + + +/* Indique le type défini pour un pseudo-registre. */ +GType g_pseudo_register_get_type(void); + +/* Assigne le contenu d'une expression dans une autre. */ +GDecInstruction *g_pseudo_register_new(void); + + + +#endif /* _DECOMP_EXPR_PSEUDO_H */ diff --git a/src/decomp/expression-int.h b/src/decomp/expression-int.h new file mode 100644 index 0000000..dacd9b8 --- /dev/null +++ b/src/decomp/expression-int.h @@ -0,0 +1,50 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * expression-int.h - prototypes pour la définition interne des expressions décompilées + * + * Copyright (C) 2010 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 _DECOMP_EXPRESSION_INT_H +#define _DECOMP_EXPRESSION_INT_H + + +#include "expression.h" +#include "instruction-int.h" + + + +/* Définition d'une expression décompilée (instance) */ +struct _GDecExpression +{ + GDecInstruction parent; /* A laisser en premier */ + +}; + + +/* Définition d'une expression décompilée (classe) */ +struct _GDecExpressionClass +{ + GDecInstructionClass parent; /* A laisser en premier */ + +}; + + + +#endif /* _DECOMP_EXPRESSION_INT_H */ diff --git a/src/decomp/expression.c b/src/decomp/expression.c new file mode 100644 index 0000000..82a2b4a --- /dev/null +++ b/src/decomp/expression.c @@ -0,0 +1,76 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * expression.c - gestion des expressions décompilées + * + * Copyright (C) 2010 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 "expression.h" + + +#include "expression-int.h" + + + +/* Initialise la classe des expressions décompilées. */ +static void g_dec_expression_class_init(GDecExpressionClass *); + +/* Initialise une instance d'expression décompilée. */ +static void g_dec_expression_init(GDecExpression *); + + + +/* Indique le type défini pour une expression décompilée. */ +G_DEFINE_TYPE(GDecExpression, g_dec_expression, G_TYPE_DEC_INSTRUCTION); + + +/****************************************************************************** +* * +* Paramètres : klass = classe à initialiser. * +* * +* Description : Initialise la classe des expressions décompilées. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_dec_expression_class_init(GDecExpressionClass *klass) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : expr = instance à initialiser. * +* * +* Description : Initialise une instance d'expression décompilée. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_dec_expression_init(GDecExpression *expr) +{ + +} diff --git a/src/decomp/expression.h b/src/decomp/expression.h new file mode 100644 index 0000000..4a56c24 --- /dev/null +++ b/src/decomp/expression.h @@ -0,0 +1,53 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * expression.h - prototypes pour la gestion des expressions décompilées + * + * Copyright (C) 2010 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 _DECOMP_EXPRESSION_H +#define _DECOMP_EXPRESSION_H + + +#include + + + +#define G_TYPE_DEC_EXPRESSION g_dec_expression_get_type() +#define G_DEC_EXPRESSION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_dec_expression_get_type(), GDecExpression)) +#define G_IS_DEC_EXPRESSION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_dec_expression_get_type())) +#define G_DEC_EXPRESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_DEC_EXPRESSION, GDecExpressionClass)) +#define G_IS_DEC_EXPRESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_DEC_EXPRESSION)) +#define G_DEC_EXPRESSION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DEC_EXPRESSION, GDecExpressionClass)) + + + +/* Définition d'une expression décompilée (instance) */ +typedef struct _GDecExpression GDecExpression; + +/* Définition d'une expression décompilée (classe) */ +typedef struct _GDecExpressionClass GDecExpressionClass; + + +/* Indique le type défini pour une expression décompilée. */ +GType g_dec_expression_get_type(void); + + + +#endif /* _DECOMP_EXPRESSION_H */ diff --git a/src/decomp/instruction-int.h b/src/decomp/instruction-int.h new file mode 100644 index 0000000..49a68fc --- /dev/null +++ b/src/decomp/instruction-int.h @@ -0,0 +1,58 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * instruction-int.h - prototypes pour la définition interne des instructions décompilées + * + * Copyright (C) 2010 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 _DECOMP_INSTRUCTION_INT_H +#define _DECOMP_INSTRUCTION_INT_H + + +#include "instruction.h" +#include "../arch/archbase.h" + + + +/* Imprime pour l'écran un version humaine d'une instruction. */ +typedef void (* dec_instr_print_fc) (GDecInstruction *, GCodeBuffer *, GBufferLine *, GLangOutput *); + + +/* Définition d'une instruction décompilée (instance) */ +struct _GDecInstruction +{ + GObject parent; /* A laisser en premier */ + + vmpa_t address; /* Position associée */ + + dec_instr_print_fc print; /* Impression pour à l'écran */ + +}; + + +/* Définition d'une instruction décompilée (classe) */ +struct _GDecInstructionClass +{ + GObjectClass parent; /* A laisser en premier */ + +}; + + + +#endif /* _DECOMP_INSTRUCTION_INT_H */ diff --git a/src/decomp/instruction.c b/src/decomp/instruction.c new file mode 100644 index 0000000..96411f5 --- /dev/null +++ b/src/decomp/instruction.c @@ -0,0 +1,101 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * instruction.c - gestion des instructions décompilées + * + * Copyright (C) 2010 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 "instruction.h" + + +#include "instruction-int.h" + + + +/* Initialise la classe des instructions décompilées. */ +static void g_dec_instruction_class_init(GDecInstructionClass *); + +/* Initialise une instance d'instruction décompilée. */ +static void g_dec_instruction_init(GDecInstruction *); + + + +/* Indique le type défini pour une instruction décompilée. */ +G_DEFINE_TYPE(GDecInstruction, g_dec_instruction, G_TYPE_OBJECT); + + +/****************************************************************************** +* * +* Paramètres : klass = classe à initialiser. * +* * +* Description : Initialise la classe des instructions décompilées. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_dec_instruction_class_init(GDecInstructionClass *klass) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : instr = instance à initialiser. * +* * +* Description : Initialise une instance d'instruction décompilée. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_dec_instruction_init(GDecInstruction *instr) +{ + +} + + +/****************************************************************************** +* * +* Paramètres : instr = instruction à transcrire en version humaine. * +* buffer = tampon où doit se réaliser l'insertion. * +* line = ligne d'impression prête à emploi ou NULL. * +* output = langage de programmation de sortie. * +* * +* Description : Imprime pour l'écran un version humaine d'une instruction. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_dec_instruction_print(const GDecInstruction *instr, GCodeBuffer *buffer, GBufferLine *line, GLangOutput *output) +{ + if (line == NULL) + line = g_code_buffer_append_new_line(buffer); /* FIXME : n° de ligne */ + + instr->print(instr, buffer, line, output); + +} diff --git a/src/decomp/instruction.h b/src/decomp/instruction.h new file mode 100644 index 0000000..9c8a935 --- /dev/null +++ b/src/decomp/instruction.h @@ -0,0 +1,59 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * instruction.h - prototypes pour la gestion des instructions décompilées + * + * Copyright (C) 2010 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA 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. + * + * OpenIDA 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 _DECOMP_INSTRUCTION_H +#define _DECOMP_INSTRUCTION_H + + +#include + + +#include "output.h" + + + +#define G_TYPE_DEC_INSTRUCTION g_dec_instruction_get_type() +#define G_DEC_INSTRUCTION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_dec_instruction_get_type(), GDecInstruction)) +#define G_IS_DEC_INSTRUCTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_dec_instruction_get_type())) +#define G_DEC_INSTRUCTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_DEC_INSTRUCTION, GDecInstructionClass)) +#define G_IS_DEC_INSTRUCTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_DEC_INSTRUCTION)) +#define G_DEC_INSTRUCTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DEC_INSTRUCTION, GDecInstructionClass)) + + + +/* Définition d'une instruction décompilée (instance) */ +typedef struct _GDecInstruction GDecInstruction; + +/* Définition d'une instruction décompilée (classe) */ +typedef struct _GDecInstructionClass GDecInstructionClass; + + +/* Indique le type défini pour une instruction décompilée. */ +GType g_dec_instruction_get_type(void); + +/* Imprime pour l'écran un version humaine d'une expression. */ +void g_dec_instruction_print(const GDecInstruction *, GCodeBuffer *, GBufferLine *, GLangOutput *); + + + +#endif /* _DECOMP_INSTRUCTION_H */ diff --git a/src/decomp/output.h b/src/decomp/output.h index 402a73a..63be0f5 100644 --- a/src/decomp/output.h +++ b/src/decomp/output.h @@ -53,6 +53,9 @@ GBufferLine *g_lang_output_write_comments(GLangOutput *, GCodeBuffer *, const ch +typedef unsigned int lang_t; + + #endif /* _DECOMP_OUTPUT_H */ diff --git a/src/format/format.c b/src/format/format.c index c53e7aa..73f23bd 100644 --- a/src/format/format.c +++ b/src/format/format.c @@ -33,6 +33,7 @@ #include "elf/elf.h" #include "java/java.h" #include "pe/pe.h" +#include "../decomp/expr/block.h" #include "../panels/log.h" @@ -269,6 +270,124 @@ GBinRoutine **g_binary_format_get_routines(const GBinFormat *format, size_t *cou /****************************************************************************** * * * Paramètres : format = informations chargées à consulter. * +* routine = routine à traiter. * +* * +* Description : Procède à la décompilation basique d'une routine donnée. * +* * +* Retour : Instructions créées et enregistrées, ou NULL si erreur. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GDecInstruction *g_binary_format_decompile_routine(const GBinFormat *format, GBinRoutine *routine) +{ + GDecInstruction *result; /* Instructions décompilées */ + GArchInstruction *instr; /* Instructions natives */ + vmpa_t max; /* Première adresse à écarter */ + GDecContext *ctx; /* Contexte de décompilation */ + GArchInstruction *iter; /* Boucle de parcours */ + GDecInstruction *dinstr; /* Nouvelle décompilation */ + + result = NULL; + + instr = g_binary_routine_get_instructions(routine); + max = g_binary_routine_get_address(routine) + + g_binary_routine_get_size(routine); + + printf("max :: 0x%08llx\n", max); + + max = 0x00000a98ll; /* FIXME !!!! */ + + ctx = g_dec_context_new(); + g_object_set_data(G_OBJECT(ctx), "format", format); + g_dec_context_set_max_address(ctx, max); + + for (iter = instr; + iter != NULL; + iter = g_arch_instruction_get_next_iter(instr, iter, max)) + { + + + printf("DECOMP isntr :: %p\n", iter); + + + dinstr = g_arch_instruction_decompile(iter, ctx); + if (dinstr == NULL) continue; + + printf(" -> done :: %p\n", dinstr); + + if (result == NULL) result = g_expr_block_new(dinstr); + else g_expr_block_add_item(G_EXPR_BLOCK(result), dinstr); + + } + + + + + + g_binary_routine_set_decomp_instructions(routine, result); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : format = informations chargées à consulter. * +* buffer = tampon mis à disposition pour la sortie. * +* * +* Description : Procède à la décompilation complète du format. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_binary_format_decompile(const GBinFormat *format, GCodeBuffer *buffer) +{ + + + GBinRoutine **routines; + size_t count; + + size_t i; + + GDecInstruction *instr; + + + routines = g_binary_format_get_routines(format, &count); + + + + for (i = 0; i < count; i++) + { + //printf(" -- %s --\n", g_binary_routine_get_name(routines[i])); + + if (strcmp("cryptself", g_binary_routine_get_name(routines[i])) == 0) + { + + printf("...\n"); + + instr = g_binary_routine_get_decomp_instructions(routines[i]); + + g_dec_instruction_print(instr, buffer, NULL, g_java_output_new()); + + + + } + + + } + +} + + +/****************************************************************************** +* * +* Paramètres : format = informations chargées à consulter. * * label = étiquette du symbole si trouvé. [OUT] * * type = type du symbole trouvé. [OUT] * * address = adresse à cibler, puis décallage final. [OUT] * diff --git a/src/format/format.h b/src/format/format.h index 0223525..073fae3 100644 --- a/src/format/format.h +++ b/src/format/format.h @@ -32,7 +32,7 @@ #include "symbol.h" #include "../analysis/routine.h" - +#include "../decomp/instruction.h" /* ------------------------ TRAITEMENT INDIVIDUEL DE FORMATS ------------------------ */ @@ -70,6 +70,12 @@ void g_binary_format_add_routine(GBinFormat *, GBinRoutine *); /* Fournit le prototype de toutes les routines détectées. */ GBinRoutine **g_binary_format_get_routines(const GBinFormat *, size_t *); +/* Procède à la décompilation basique d'une routine donnée. */ +GDecInstruction *g_binary_format_decompile_routine(const GBinFormat *, GBinRoutine *); + +/* Procède à la décompilation complète du format. */ +void g_binary_format_decompile(const GBinFormat *, GCodeBuffer *); + /* Recherche le symbole correspondant à une adresse. */ bool g_binary_format_resolve_symbol(const GBinFormat *, const char **, SymbolType *, vmpa_t *); diff --git a/src/glibext/gbufferline.c b/src/glibext/gbufferline.c index 701cb4b..2527124 100644 --- a/src/glibext/gbufferline.c +++ b/src/glibext/gbufferline.c @@ -296,6 +296,16 @@ static void g_buffer_line_class_init(GBufferLineClass *class) attrib = pango_attr_foreground_new(16895, 16895, 53759); pango_attr_list_insert(class->attribs[RTT_REGISTER], attrib); + /* RTT_PUNCT */ + + class->attribs[RTT_PUNCT] = pango_attr_list_new(); + + attrib = pango_attr_foreground_new(0, 0, 0); + pango_attr_list_insert(class->attribs[RTT_PUNCT], attrib); + + attrib = pango_attr_weight_new(PANGO_WEIGHT_BOLD); + pango_attr_list_insert(class->attribs[RTT_PUNCT], attrib); + /* RTT_HOOK */ class->attribs[RTT_HOOK] = pango_attr_list_new(); diff --git a/src/glibext/gbufferline.h b/src/glibext/gbufferline.h index 504f0a3..7ee3361 100644 --- a/src/glibext/gbufferline.h +++ b/src/glibext/gbufferline.h @@ -75,6 +75,7 @@ typedef enum _RenderingTagType RTT_REGISTER, /* Registre */ + RTT_PUNCT, /* Signes de ponctuation */ RTT_HOOK, /* Crochets '[' et ']' */ RTT_SIGNS, /* Signes '+', '-' et '*' */ RTT_LTGT, /* Caractères '<' et '>' */ -- cgit v0.11.2-87-g4458