diff options
Diffstat (limited to 'src/arch/dalvik/instruction.c')
-rw-r--r-- | src/arch/dalvik/instruction.c | 110 |
1 files changed, 82 insertions, 28 deletions
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; + +} |