From c922b6b9c841a97dd948755658cff07b2c6762ff Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Sat, 30 Jan 2016 01:21:08 +0100 Subject: Updated some parts of the code dealing with Dalvik. --- ChangeLog | 15 +++ src/arch/dalvik/instruction-int.h | 2 + src/arch/dalvik/instruction.c | 6 +- src/arch/dalvik/instruction.h | 2 +- src/arch/dalvik/operand.c | 243 ++++++++++++++---------------------- src/arch/dalvik/operand.h | 2 +- src/arch/dalvik/operands/pool.c | 21 ++-- src/arch/dalvik/operands/pool.h | 2 +- src/arch/dalvik/operands/register.c | 19 ++- src/arch/dalvik/operands/register.h | 4 +- src/arch/dalvik/operands/target.c | 23 ++-- src/arch/dalvik/operands/target.h | 2 +- 12 files changed, 149 insertions(+), 192 deletions(-) diff --git a/ChangeLog b/ChangeLog index ad88de4..b50d117 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +16-01-30 Cyrille Bagard + + * src/arch/dalvik/instruction-int.h: + * src/arch/dalvik/instruction.c: + * src/arch/dalvik/instruction.h: + * src/arch/dalvik/operand.c: + * src/arch/dalvik/operand.h: + * src/arch/dalvik/operands/pool.c: + * src/arch/dalvik/operands/pool.h: + * src/arch/dalvik/operands/register.c: + * src/arch/dalvik/operands/register.h: + * src/arch/dalvik/operands/target.c: + * src/arch/dalvik/operands/target.h: + Update some parts of the code dealing with Dalvik. + 16-01-29 Cyrille Bagard * .gitignore: diff --git a/src/arch/dalvik/instruction-int.h b/src/arch/dalvik/instruction-int.h index ee09d48..bc0d381 100644 --- a/src/arch/dalvik/instruction-int.h +++ b/src/arch/dalvik/instruction-int.h @@ -35,6 +35,8 @@ struct _GDalvikInstruction { GArchInstruction parent; /* A laisser en premier */ + const char *keyword; /* Nom clef de l'instruction */ + DalvikOpcodes type; /* Position dans la liste */ DalvikPseudoOpcodes ptype; /* Position dans la liste #2 */ diff --git a/src/arch/dalvik/instruction.c b/src/arch/dalvik/instruction.c index ac1efdc..a8e8676 100644 --- a/src/arch/dalvik/instruction.c +++ b/src/arch/dalvik/instruction.c @@ -444,7 +444,7 @@ static void g_dalvik_instruction_finalize(GDalvikInstruction *instr) /****************************************************************************** * * -* Paramètres : type = type d'instruction à représenter. * +* Paramètres : keyword = définition du nom humaine de l'instruction. * * * * Description : Crée une instruction pour l'architecture Dalvik. * * * @@ -454,13 +454,13 @@ static void g_dalvik_instruction_finalize(GDalvikInstruction *instr) * * ******************************************************************************/ -GArchInstruction *g_dalvik_instruction_new(DalvikOpcodes type) +GArchInstruction *g_dalvik_instruction_new(const char *keyword) { GArchInstruction *result; /* Structure à retourner */ result = g_object_new(G_TYPE_DALVIK_INSTRUCTION, NULL); - G_DALVIK_INSTRUCTION(result)->type = type; + G_DALVIK_INSTRUCTION(result)->keyword = keyword; return result; diff --git a/src/arch/dalvik/instruction.h b/src/arch/dalvik/instruction.h index 29e4c0d..185eabe 100644 --- a/src/arch/dalvik/instruction.h +++ b/src/arch/dalvik/instruction.h @@ -47,7 +47,7 @@ typedef struct _GDalvikInstructionClass GDalvikInstructionClass; GType g_dalvik_instruction_get_type(void); /* Crée une instruction pour l'architecture Dalvik. */ -GArchInstruction *g_dalvik_instruction_new(DalvikOpcodes); +GArchInstruction *g_dalvik_instruction_new(const char *); /* Indique l'opcode associé à une instruction Dalvik. */ DalvikOpcodes g_dalvik_instruction_get_opcode(const struct _GDalvikInstruction *); diff --git a/src/arch/dalvik/operand.c b/src/arch/dalvik/operand.c index 838d953..f8f7b39 100644 --- a/src/arch/dalvik/operand.c +++ b/src/arch/dalvik/operand.c @@ -24,7 +24,6 @@ #include "operand.h" -#include // REMME (assert(0)) #include #include @@ -57,27 +56,26 @@ typedef enum _DalvikOperandID /* Procède à la lecture d'opérandes pour une instruction. */ -static bool dalvik_read_basic_operands(GArchInstruction *, const GDexFormat *, const bin_t *, off_t *, off_t, bool *, SourceEndian, DalvikOperandType, va_list); +static bool dalvik_read_basic_operands(GArchInstruction *, GDexFormat *, const GBinContent *, vmpa2t *, bool *, SourceEndian, DalvikOperandType, va_list); /* Procède à la lecture d'opérandes pour une instruction. */ -static bool dalvik_read_fixed_operands(GArchInstruction *, const GDexFormat *, const bin_t *, off_t *, off_t, bool *, SourceEndian, DalvikOperandType); +static bool dalvik_read_fixed_operands(GArchInstruction *, GDexFormat *, const GBinContent *, vmpa2t *, bool *, SourceEndian, DalvikOperandType); /* Procède à la lecture d'opérandes pour une instruction. */ -static bool dalvik_read_variatic_operands(GArchInstruction *, const GDexFormat *, const bin_t *, off_t *, off_t, bool *, SourceEndian, DalvikOperandType); +static bool dalvik_read_variatic_operands(GArchInstruction *, GDexFormat *, const GBinContent *, vmpa2t *, bool *, SourceEndian, DalvikOperandType); /****************************************************************************** * * -* Paramètres : instr = instruction dont la définition est incomplète. [OUT]* -* format = format du fichier contenant le code. * -* data = flux de données à analyser. * -* pos = position courante dans ce flux. [OUT] * -* end = limite des données à analyser. * -* low = position éventuelle des 4 bits visés. [OUT] * -* endian = boutisme lié au binaire accompagnant. * -* model = type d'opérandes attendues. * -* ap = éventuels arguments complémentaires. * +* Paramètres : instr = instruction dont la définition est incomplète.[OUT]* +* format = format du fichier contenant le code. * +* content = flux de données à analyser. * +* pos = position courante dans ce flux. [OUT] * +* low = position éventuelle des 4 bits visés. [OUT] * +* endian = boutisme lié au binaire accompagnant. * +* model = type d'opérandes attendues. * +* ap = éventuels arguments complémentaires. * * * * Description : Procède à la lecture d'opérandes pour une instruction. * * * @@ -87,13 +85,14 @@ static bool dalvik_read_variatic_operands(GArchInstruction *, const GDexFormat * * * ******************************************************************************/ -static bool dalvik_read_basic_operands(GArchInstruction *instr, const GDexFormat *format, const bin_t *data, off_t *pos, off_t end, bool *low, SourceEndian endian, DalvikOperandType model, va_list ap) +static bool dalvik_read_basic_operands(GArchInstruction *instr, GDexFormat *format, const GBinContent *content, vmpa2t *pos, bool *low, SourceEndian endian, DalvikOperandType model, va_list ap) { bool result; /* Bilan à retourner */ DalvikOperandID *types; /* Liste des chargements */ DalvikOperandID *iter; /* Boucle de parcours */ GArchOperand *op; /* Opérande unique décodé */ uint16_t value16; /* Valeur sur 16 bits */ + DalvikPoolType pool_type; /* Type de table à manipuler */ result = true; @@ -287,66 +286,63 @@ static bool dalvik_read_basic_operands(GArchInstruction *instr, const GDexFormat switch (*iter) { case DOI_REGISTER_4: - op = g_dalvik_register_operand_new(data, pos, end, low, MDS_4_BITS, endian); + op = g_dalvik_register_operand_new(content, pos, low, MDS_4_BITS, endian); break; case DOI_REGISTER_8: - op = g_dalvik_register_operand_new(data, pos, end, NULL, MDS_8_BITS, endian); + op = g_dalvik_register_operand_new(content, pos, NULL, MDS_8_BITS, endian); break; case DOI_REGISTER_16: - op = g_dalvik_register_operand_new(data, pos, end, NULL, MDS_16_BITS, endian); + op = g_dalvik_register_operand_new(content, pos, NULL, MDS_16_BITS, endian); break; case DOI_IMMEDIATE_4: - assert(0); - //op = _g_imm_operand_new_from_data_old(MDS_4_BITS, data, pos, end, low, endian); + op = _g_imm_operand_new_from_data(MDS_4_BITS, content, pos, low, endian); break; case DOI_IMMEDIATE_8: - assert(0); - //op = g_imm_operand_new_from_data_old(MDS_8_BITS, data, pos, end, endian); + op = g_imm_operand_new_from_data(MDS_8_BITS, content, pos, endian); break; case DOI_IMMEDIATE_16: - assert(0); - //op = g_imm_operand_new_from_data_old(MDS_16_BITS, data, pos, end, endian); + op = g_imm_operand_new_from_data(MDS_16_BITS, content, pos, endian); break; case DOI_IMMEDIATE_32: - assert(0); - //op = g_imm_operand_new_from_data_old(MDS_32_BITS, data, pos, end, endian); + op = g_imm_operand_new_from_data(MDS_32_BITS, content, pos, endian); break; case DOI_IMMEDIATE_64: - assert(0); - //op = g_imm_operand_new_from_data_old(MDS_64_BITS, data, pos, end, endian); + op = g_imm_operand_new_from_data(MDS_64_BITS, content, pos, endian); break; case DOI_IMMEDIATE_H16: - result = read_u16(&value16, data, pos, end, endian); + result = g_binary_content_read_u16(content, pos, endian, &value16); if (result) op = g_imm_operand_new_from_value(MDS_32_BITS_SIGNED, ((uint32_t)value16) << 16); break; case DOI_POOL_CONST: - op = g_dalvik_pool_operand_new(format, DALVIK_OP_GET_POOL(model), data, pos, end, MDS_16_BITS, endian); + pool_type = DALVIK_OP_GET_POOL(model); + op = g_dalvik_pool_operand_new(format, pool_type, content, pos, MDS_16_BITS, endian); break; case DOI_POOL_CONST_WIDE: - op = g_dalvik_pool_operand_new(format, DALVIK_OP_GET_POOL(model), data, pos, end, MDS_32_BITS, endian); + pool_type = DALVIK_OP_GET_POOL(model); + op = g_dalvik_pool_operand_new(format, pool_type, content, pos, MDS_32_BITS, endian); break; case DOI_TARGET_8: - op = g_dalvik_target_operand_new(data, pos, end, MDS_8_BITS_SIGNED, endian, va_arg(ap, vmpa_t)); + op = g_dalvik_target_operand_new(content, pos, MDS_8_BITS_SIGNED, endian, va_arg(ap, vmpa_t)); break; case DOI_TARGET_16: - op = g_dalvik_target_operand_new(data, pos, end, MDS_16_BITS_SIGNED, endian, va_arg(ap, vmpa_t)); + op = g_dalvik_target_operand_new(content, pos, MDS_16_BITS_SIGNED, endian, va_arg(ap, vmpa_t)); break; case DOI_TARGET_32: - op = g_dalvik_target_operand_new(data, pos, end, MDS_32_BITS_SIGNED, endian, va_arg(ap, vmpa_t)); + op = g_dalvik_target_operand_new(content, pos, MDS_32_BITS_SIGNED, endian, va_arg(ap, vmpa_t)); break; default: @@ -367,14 +363,13 @@ static bool dalvik_read_basic_operands(GArchInstruction *instr, const GDexFormat /****************************************************************************** * * -* Paramètres : instr = instruction dont la définition est incomplète. [OUT]* -* format = format du fichier contenant le code. * -* data = flux de données à analyser. * -* pos = position courante dans ce flux. [OUT] * -* end = limite des données à analyser. * -* low = position éventuelle des 4 bits visés. [OUT] * -* endian = boutisme lié au binaire accompagnant. * -* model = type d'opérandes attendues. * +* Paramètres : instr = instruction dont la définition est incomplète.[OUT]* +* format = format du fichier contenant le code. * +* content = flux de données à analyser. * +* pos = position courante dans ce flux. [OUT] * +* low = position éventuelle des 4 bits visés. [OUT] * +* endian = boutisme lié au binaire accompagnant. * +* model = type d'opérandes attendues. * * * * Description : Procède à la lecture d'opérandes pour une instruction. * * * @@ -384,47 +379,34 @@ static bool dalvik_read_basic_operands(GArchInstruction *instr, const GDexFormat * * ******************************************************************************/ -static bool dalvik_read_fixed_operands(GArchInstruction *instr, const GDexFormat *format, const bin_t *data, off_t *pos, off_t end, bool *low, SourceEndian endian, DalvikOperandType model) +static bool dalvik_read_fixed_operands(GArchInstruction *instr, GDexFormat *format, const GBinContent *content, vmpa2t *pos, bool *low, SourceEndian endian, DalvikOperandType model) { - GArchOperand *opa; /* Opérande vA décodé */ - uint8_t b; /* Nbre. de registres utilisés */ - GArchOperand *target1; /* Opérande visant la table #1 */ - GArchOperand *target2; /* Opérande visant la table #2 */ + GArchOperand *opg; /* Opérande G décodé */ + uint8_t a; /* Nbre. de registres utilisés */ + GArchOperand *target; /* Opérande visant la table #1 */ GArchOperand *args; /* Liste des opérandes */ uint8_t i; /* Boucle de parcours */ GArchOperand *op; /* Opérande unique décodé */ + opg = g_dalvik_register_operand_new(content, pos, low, MDS_4_BITS, endian); - - opa = g_dalvik_register_operand_new(data, pos, end, low, MDS_4_BITS, endian); - - if (!read_u4(&b, data, pos, end, low)) + if (!g_binary_content_read_u4(content, pos, low, &a)) goto err_va; + if (a == 5 && opg == NULL) + goto err_no_opg; - target1 = g_dalvik_pool_operand_new(format, DALVIK_OP_GET_POOL(model), data, pos, end, MDS_16_BITS, endian); - if (target1 == NULL) goto err_target1; - - - - target2 = NULL; - - if (0) - { - /* FIXME */ - if (target2 == NULL) goto err_target2; - } + target = g_dalvik_pool_operand_new(format, DALVIK_OP_GET_POOL(model), content, pos, MDS_16_BITS, endian); + if (target == NULL) goto err_target; + /* Mise en place des arguments */ args = g_dalvik_args_operand_new(); g_arch_instruction_attach_extra_operand(instr, args); - - /* Mise en place des arguments */ - - for (i = 0; i < MIN(b, 4); i++) + for (i = 0; i < MIN(a, 4); i++) { - op = g_dalvik_register_operand_new(data, pos, end, low, MDS_4_BITS, endian); + op = g_dalvik_register_operand_new(content, pos, low, MDS_4_BITS, endian); if (op == NULL) goto err_registers; g_dalvik_args_operand_add(G_DALVIK_ARGS_OPERAND(args), op); @@ -433,29 +415,29 @@ static bool dalvik_read_fixed_operands(GArchInstruction *instr, const GDexFormat /* Rajout des éléments finaux déjà chargés */ - if (b < 5) g_object_unref(G_OBJECT(opa)); - else g_dalvik_args_operand_add(G_DALVIK_ARGS_OPERAND(args), opa); + if (a == 5) + g_dalvik_args_operand_add(G_DALVIK_ARGS_OPERAND(args), opg); - g_arch_instruction_attach_extra_operand(instr, target1); + else + { + if (opg != NULL) + g_object_unref(G_OBJECT(opg)); + } - if (target2 != NULL) - g_arch_instruction_attach_extra_operand(instr, target2); + g_arch_instruction_attach_extra_operand(instr, target); return true; err_registers: - if (target2 != NULL) - g_object_unref(G_OBJECT(target2)); - - err_target2: - - g_object_unref(G_OBJECT(target1)); + g_object_unref(G_OBJECT(target)); - err_target1: + err_target: - g_object_unref(G_OBJECT(opa)); + if (opg != NULL) + g_object_unref(G_OBJECT(opg)); + err_no_opg: err_va: return false; @@ -465,14 +447,13 @@ static bool dalvik_read_fixed_operands(GArchInstruction *instr, const GDexFormat /****************************************************************************** * * -* Paramètres : instr = instruction dont la définition est incomplète. [OUT]* -* format = format du fichier contenant le code. * -* data = flux de données à analyser. * -* pos = position courante dans ce flux. [OUT] * -* end = limite des données à analyser. * -* low = position éventuelle des 4 bits visés. [OUT] * -* endian = boutisme lié au binaire accompagnant. * -* model = type d'opérandes attendues. * +* Paramètres : instr = instruction dont la définition est incomplète.[OUT]* +* format = format du fichier contenant le code. * +* content = flux de données à analyser. * +* pos = position courante dans ce flux. [OUT] * +* low = position éventuelle des 4 bits visés. [OUT] * +* endian = boutisme lié au binaire accompagnant. * +* model = type d'opérandes attendues. * * * * Description : Procède à la lecture d'opérandes pour une instruction. * * * @@ -482,23 +463,26 @@ static bool dalvik_read_fixed_operands(GArchInstruction *instr, const GDexFormat * * ******************************************************************************/ -static bool dalvik_read_variatic_operands(GArchInstruction *instr, const GDexFormat *format, const bin_t *data, off_t *pos, off_t end, bool *low, SourceEndian endian, DalvikOperandType model) +static bool dalvik_read_variatic_operands(GArchInstruction *instr, GDexFormat *format, const GBinContent *content, vmpa2t *pos, bool *low, SourceEndian endian, DalvikOperandType model) { uint8_t a; /* Nbre. de registres utilisés */ uint16_t b; /* Indice dans la table const. */ + uint16_t c; /* Indice de registre */ GArchOperand *target; /* Opérande visant la table */ GArchOperand *args; /* Liste des opérandes */ uint8_t i; /* Boucle de parcours */ - uint16_t c; /* Indice de registre */ GArchOperand *op; /* Opérande unique décodé */ - if (!read_u8(&a, data, pos, end)) + if (!g_binary_content_read_u8(content, pos, &a)) + return false; + + if (!g_binary_content_read_u16(content, pos, endian, &b)) return false; - if (!read_u16(&b, data, pos, end, endian)) + if (!g_binary_content_read_u16(content, pos, endian, &c)) return false; - target = g_dalvik_pool_operand_new(format, DALVIK_OP_GET_POOL(model), data, pos, end, MDS_16_BITS, endian); + target = g_dalvik_pool_operand_new(format, DALVIK_OP_GET_POOL(model), content, pos, MDS_16_BITS, endian); if (target == NULL) return false; /* Mise en place des arguments */ @@ -508,9 +492,6 @@ static bool dalvik_read_variatic_operands(GArchInstruction *instr, const GDexFor for (i = 0; i < a; i++) { - if (i == 0 && !read_u16(&c, data, pos, end, endian)) - goto drvo_registers; - op = g_dalvik_register_operand_new_from_existing(g_dalvik_register_new(c + i)); if (op == NULL) goto drvo_registers; @@ -526,8 +507,6 @@ static bool dalvik_read_variatic_operands(GArchInstruction *instr, const GDexFor drvo_registers: - g_object_unref(G_OBJECT(args)); - g_object_unref(G_OBJECT(target)); return false; @@ -535,25 +514,15 @@ static bool dalvik_read_variatic_operands(GArchInstruction *instr, const GDexFor } - - - - - - - - - /****************************************************************************** * * -* Paramètres : instr = instruction dont la définition est incomplète. [OUT]* -* format = format du fichier contenant le code. * -* data = flux de données à analyser. * -* pos = position courante dans ce flux. [OUT] * -* end = limite des données à analyser. * -* endian = boutisme lié au binaire accompagnant. * -* model = type d'opérandes attendues. * -* ... = éventuelles données complémentaires. * +* Paramètres : instr = instruction dont la définition est incomplète.[OUT]* +* format = format du fichier contenant le code. * +* content = flux de données à analyser. * +* pos = position courante dans ce flux. [OUT] * +* endian = boutisme lié au binaire accompagnant. * +* model = type d'opérandes attendues. * +* ... = éventuelles données complémentaires. * * * * Description : Procède à la lecture d'opérandes pour une instruction. * * * @@ -563,29 +532,19 @@ static bool dalvik_read_variatic_operands(GArchInstruction *instr, const GDexFor * * ******************************************************************************/ -bool dalvik_read_operands(GArchInstruction *instr, const GDexFormat *format, const bin_t *data, off_t *pos, off_t end, SourceEndian endian, DalvikOperandType model, ...) +bool dalvik_read_operands(GArchInstruction *instr, GExeFormat *format, const GBinContent *content, vmpa2t *pos, SourceEndian endian, DalvikOperandType model, ...) { bool result; /* Bilan à retourner */ - - - bool low; - - off_t old_pos; - + GDexFormat *dformat; /* Autre version du format */ + bool low; /* Partie d'octets à lire */ va_list ap; /* Arguments complémentaires */ - off_t length; - result = true; - - old_pos = *pos; - + dformat = G_DEX_FORMAT(format); low = true; - - switch (model & ~DALVIK_OP_EXTRA_MASK) { case DALVIK_OPT_10T: @@ -610,18 +569,18 @@ bool dalvik_read_operands(GArchInstruction *instr, const GDexFormat *format, con case DALVIK_OPT_32X: case DALVIK_OPT_51L: va_start(ap, model); - result = dalvik_read_basic_operands(instr, format, data, pos, end, &low, endian, model, ap); + result = dalvik_read_basic_operands(instr, dformat, content, pos, &low, endian, model, ap); va_end(ap); break; case DALVIK_OPT_35C: - result = dalvik_read_fixed_operands(instr, format, data, pos, end, &low, endian, model); + result = dalvik_read_fixed_operands(instr, dformat, content, pos, &low, endian, model); break; case DALVIK_OPT_3RC: case DALVIK_OPT_3RMS: case DALVIK_OPT_3RFS: - result = dalvik_read_variatic_operands(instr, format, data, pos, end, &low, endian, model); + result = dalvik_read_variatic_operands(instr, dformat, content, pos, &low, endian, model); break; default: @@ -629,26 +588,6 @@ bool dalvik_read_operands(GArchInstruction *instr, const GDexFormat *format, con } - - - *pos = old_pos; - - - - if (*pos < end) - { - (*pos)++; - - length = DALVIK_OP_GET_LEN(model); - - if (length > 1) - *pos += (length - 1) * sizeof(uint16_t); - - } - - - - return result; } diff --git a/src/arch/dalvik/operand.h b/src/arch/dalvik/operand.h index 6f63f25..27901be 100644 --- a/src/arch/dalvik/operand.h +++ b/src/arch/dalvik/operand.h @@ -112,7 +112,7 @@ typedef enum _DalvikOperandType /* Procède à la lecture d'opérandes pour une instruction. */ -bool dalvik_read_operands(GArchInstruction *, const GDexFormat *, const bin_t *, off_t *, off_t, SourceEndian, DalvikOperandType, ...); +bool dalvik_read_operands(GArchInstruction *, GExeFormat *, const GBinContent *, vmpa2t *, SourceEndian, DalvikOperandType, ...); /* Procède à la lecture d'opérandes pour une instruction. */ void dalvik_mark_first_operand_as_written(GArchInstruction *); diff --git a/src/arch/dalvik/operands/pool.c b/src/arch/dalvik/operands/pool.c index 2f5c4a0..0d88242 100644 --- a/src/arch/dalvik/operands/pool.c +++ b/src/arch/dalvik/operands/pool.c @@ -41,7 +41,7 @@ struct _GDalvikPoolOperand { GArchOperand parent; /* Instance parente */ - const GDexFormat *format; /* Lien vers le contenu réel */ + GDexFormat *format; /* Lien vers le contenu réel */ DalvikPoolType type; /* Type de table visée */ uint32_t index; /* Indice de l'élément visé */ @@ -165,13 +165,12 @@ static void g_dalvik_pool_operand_finalize(GDalvikPoolOperand *operand) /****************************************************************************** * * -* Paramètres : format = format du fichier contenant le code. * -* type = type de table visée avec la référence. * -* data = flux de données à analyser. * -* pos = position courante dans ce flux. [OUT] * -* end = limite des données à analyser. * -* size = taille de l'opérande, et donc du registre. * -* endian = ordre des bits dans la source. * +* Paramètres : format = format du fichier contenant le code. * +* type = type de table visée avec la référence. * +* content = flux de données à analyser. * +* pos = position courante dans ce flux. [OUT] * +* size = taille de l'opérande, et donc du registre. * +* endian = ordre des bits dans la source. * * * * Description : Crée un opérande visant un élément constant Dalvik. * * * @@ -181,7 +180,7 @@ static void g_dalvik_pool_operand_finalize(GDalvikPoolOperand *operand) * * ******************************************************************************/ -GArchOperand *g_dalvik_pool_operand_new(const GDexFormat *format, DalvikPoolType type, const bin_t *data, off_t *pos, off_t end, MemoryDataSize size, SourceEndian endian) +GArchOperand *g_dalvik_pool_operand_new(GDexFormat *format, DalvikPoolType type, const GBinContent *content, vmpa2t *pos, MemoryDataSize size, SourceEndian endian) { GDalvikPoolOperand *result; /* Structure à retourner */ uint8_t index8; /* Indice sur 8 bits */ @@ -191,10 +190,10 @@ GArchOperand *g_dalvik_pool_operand_new(const GDexFormat *format, DalvikPoolType switch (size) { case MDS_8_BITS: - test = read_u8(&index8, data, pos, end); + test = g_binary_content_read_u8(content, pos, &index8); break; case MDS_16_BITS: - test = read_u16(&index16, data, pos, end, endian); + test = g_binary_content_read_u16(content, pos, endian, &index16); break; default: test = false; diff --git a/src/arch/dalvik/operands/pool.h b/src/arch/dalvik/operands/pool.h index 604302d..3d75142 100644 --- a/src/arch/dalvik/operands/pool.h +++ b/src/arch/dalvik/operands/pool.h @@ -67,7 +67,7 @@ typedef enum _DalvikPoolType GType g_dalvik_pool_operand_get_type(void); /* Crée un opérande visant un élément constant Dalvik. */ -GArchOperand *g_dalvik_pool_operand_new(const GDexFormat *, DalvikPoolType, const bin_t *, off_t *, off_t, MemoryDataSize, SourceEndian); +GArchOperand *g_dalvik_pool_operand_new(GDexFormat *, DalvikPoolType, const GBinContent *, vmpa2t *, MemoryDataSize, SourceEndian); /* Indique la nature de la table de constantes visée ici. */ DalvikPoolType g_dalvik_pool_operand_get_pool_type(const GDalvikPoolOperand *); diff --git a/src/arch/dalvik/operands/register.c b/src/arch/dalvik/operands/register.c index 1b789f2..7f243ad 100644 --- a/src/arch/dalvik/operands/register.c +++ b/src/arch/dalvik/operands/register.c @@ -159,12 +159,11 @@ static void g_dalvik_register_operand_finalize(GDalvikRegisterOperand *operand) /****************************************************************************** * * -* Paramètres : data = flux de données à analyser. * -* pos = position courante dans ce flux. [OUT] * -* end = limite des données à analyser. * -* low = position éventuelle des 4 bits visés. [OUT] * -* size = taille de l'opérande, et donc du registre. * -* endian = ordre des bits dans la source. * +* Paramètres : content = flux de données à analyser. * +* pos = position courante dans ce flux. [OUT] * +* low = position éventuelle des 4 bits visés. [OUT] * +* size = taille de l'opérande, et donc du registre. * +* endian = ordre des bits dans la source. * * * * Description : Crée un opérande visant un registre Dalvik. * * * @@ -174,7 +173,7 @@ static void g_dalvik_register_operand_finalize(GDalvikRegisterOperand *operand) * * ******************************************************************************/ -GArchOperand *g_dalvik_register_operand_new(const bin_t *data, off_t *pos, off_t end, bool *low, MemoryDataSize size, SourceEndian endian) +GArchOperand *g_dalvik_register_operand_new(const GBinContent *content, vmpa2t *pos, bool *low, MemoryDataSize size, SourceEndian endian) { GDalvikRegisterOperand *result; /* Structure à retourner */ uint8_t index8; /* Indice sur 8 bits */ @@ -184,13 +183,13 @@ GArchOperand *g_dalvik_register_operand_new(const bin_t *data, off_t *pos, off_t switch (size) { case MDS_4_BITS: - test = read_u4(&index8, data, pos, end, low); + test = g_binary_content_read_u4(content, pos, low, &index8); break; case MDS_8_BITS: - test = read_u8(&index8, data, pos, end); + test = g_binary_content_read_u8(content, pos, &index8); break; case MDS_16_BITS: - test = read_u16(&index16, data, pos, end, endian); + test = g_binary_content_read_u16(content, pos, endian, &index16); break; default: test = false; diff --git a/src/arch/dalvik/operands/register.h b/src/arch/dalvik/operands/register.h index cd341b4..d70f410 100644 --- a/src/arch/dalvik/operands/register.h +++ b/src/arch/dalvik/operands/register.h @@ -30,7 +30,7 @@ #include "../register.h" #include "../../operand.h" -#include "../../../common/endianness.h" +#include "../../../analysis/content.h" @@ -53,7 +53,7 @@ typedef struct _GDalvikRegisterOperandClass GDalvikRegisterOperandClass; GType g_dalvik_register_operand_get_type(void); /* Crée un opérande visant un registre Dalvik. */ -GArchOperand *g_dalvik_register_operand_new(const bin_t *, off_t *, off_t, bool *, MemoryDataSize, SourceEndian); +GArchOperand *g_dalvik_register_operand_new(const GBinContent *, vmpa2t *, bool *, MemoryDataSize, SourceEndian); /* Crée un opérande visant un registre Dalvik. */ GArchOperand *g_dalvik_register_operand_new_from_existing(GDalvikRegister *); diff --git a/src/arch/dalvik/operands/target.c b/src/arch/dalvik/operands/target.c index 690858b..42d09cf 100644 --- a/src/arch/dalvik/operands/target.c +++ b/src/arch/dalvik/operands/target.c @@ -155,12 +155,11 @@ static void g_dalvik_target_operand_finalize(GDalvikTargetOperand *operand) /****************************************************************************** * * -* Paramètres : data = flux de données à analyser. * -* pos = position courante dans ce flux. [OUT] * -* end = limite des données à analyser. * -* size = taille de l'opérande. * -* endian = ordre des bits dans la source. * -* base = adresse de référence pour le calcul. * +* Paramètres : content = flux de données à analyser. * +* pos = position courante dans ce flux. [OUT] * +* size = taille de l'opérande. * +* endian = ordre des bits dans la source. * +* base = adresse de référence pour le calcul. * * * * Description : Crée un opérande visant un instruction Dalvik. * * * @@ -170,26 +169,27 @@ static void g_dalvik_target_operand_finalize(GDalvikTargetOperand *operand) * * ******************************************************************************/ -GArchOperand *g_dalvik_target_operand_new(const bin_t *data, off_t *pos, off_t end, MemoryDataSize size, SourceEndian endian, vmpa_t base) +GArchOperand *g_dalvik_target_operand_new(const GBinContent *content, vmpa2t *pos, MemoryDataSize size, SourceEndian endian, vmpa_t base) { GDalvikTargetOperand *result; /* Structure à retourner */ int8_t val8; /* Valeur sur 8 bits */ int16_t val16; /* Valeur sur 16 bits */ int32_t val32; /* Valeur sur 32 bits */ + bool test; /* Bilan de lecture */ vmpa_t address; /* Adresse finale visée */ switch (size) { case MDS_8_BITS_SIGNED: - read_s8(&val8, data, pos, end); + test = g_binary_content_read_s8(content, pos, &val8); address = base + val8 * sizeof(uint16_t); break; case MDS_16_BITS_SIGNED: - read_s16(&val16, data, pos, end, endian); + test = g_binary_content_read_s16(content, pos, endian, &val16); address = base + val16 * sizeof(uint16_t); break; case MDS_32_BITS_SIGNED: - read_s32(&val32, data, pos, end, endian); + test = g_binary_content_read_s32(content, pos, endian, &val32); address = base + val32 * sizeof(uint16_t); break; default: @@ -197,6 +197,9 @@ GArchOperand *g_dalvik_target_operand_new(const bin_t *data, off_t *pos, off_t e break; } + if (!test) + return NULL; + result = g_object_new(G_TYPE_DALVIK_TARGET_OPERAND, NULL); result->immediate = G_IMM_OPERAND(g_imm_operand_new_from_value(MDS_32_BITS/*FIXME*/, (uint32_t)address/* FIXME */)); diff --git a/src/arch/dalvik/operands/target.h b/src/arch/dalvik/operands/target.h index e15b167..cb0e9f1 100644 --- a/src/arch/dalvik/operands/target.h +++ b/src/arch/dalvik/operands/target.h @@ -51,7 +51,7 @@ typedef struct _GDalvikTargetOperandClass GDalvikTargetOperandClass; GType g_dalvik_target_operand_get_type(void); /* Crée un opérande visant un instruction Dalvik. */ -GArchOperand *g_dalvik_target_operand_new(const bin_t *, off_t *, off_t, MemoryDataSize, SourceEndian, vmpa_t); +GArchOperand *g_dalvik_target_operand_new(const GBinContent *, vmpa2t *, MemoryDataSize, SourceEndian, vmpa_t); /* Fournit l'adresse représentée par une opérande Dalvik. */ const GImmOperand *g_dalvik_target_operand_get_value(const GDalvikTargetOperand *); -- cgit v0.11.2-87-g4458