diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2014-07-31 05:53:06 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2014-07-31 05:53:06 (GMT) |
commit | a5d8e3fc30cda2e13d30f099e93ab1b182fdc0bd (patch) | |
tree | cf183906b2301cd3c726af820292fd0f2458bfa1 /src/arch/dalvik/operand.c | |
parent | dc436357ff29158dddd836d368d152d42d5b086b (diff) |
Improved the way code is decoded by avoiding to propagate the base address everywhere.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@385 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/arch/dalvik/operand.c')
-rw-r--r-- | src/arch/dalvik/operand.c | 70 |
1 files changed, 36 insertions, 34 deletions
diff --git a/src/arch/dalvik/operand.c b/src/arch/dalvik/operand.c index a2d04b0..ee033e7 100644 --- a/src/arch/dalvik/operand.c +++ b/src/arch/dalvik/operand.c @@ -72,7 +72,7 @@ static bool dalvik_read_variatic_operands(GArchInstruction *, const GDexFormat * * format = format du fichier contenant le code. * * data = flux de données à analyser. * * pos = position courante dans ce flux. [OUT] * -* len = taille totale des données à analyser. * +* 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. * @@ -86,7 +86,7 @@ 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 len, bool *low, SourceEndian endian, DalvikOperandType model, va_list ap) +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) { bool result; /* Bilan à retourner */ DalvikOperandID *types; /* Liste des chargements */ @@ -281,64 +281,66 @@ static bool dalvik_read_basic_operands(GArchInstruction *instr, const GDexFormat for (iter = types; *iter != G_TYPE_INVALID && result; iter++) { + op = NULL; /* Nul de GCC */ + switch (*iter) { case DOI_REGISTER_4: - op = g_dalvik_register_operand_new(data, pos, len, low, MDS_4_BITS, endian); + op = g_dalvik_register_operand_new(data, pos, end, low, MDS_4_BITS, endian); break; case DOI_REGISTER_8: - op = g_dalvik_register_operand_new(data, pos, len, NULL, MDS_8_BITS, endian); + op = g_dalvik_register_operand_new(data, pos, end, NULL, MDS_8_BITS, endian); break; case DOI_REGISTER_16: - op = g_dalvik_register_operand_new(data, pos, len, NULL, MDS_16_BITS, endian); + op = g_dalvik_register_operand_new(data, pos, end, NULL, MDS_16_BITS, endian); break; case DOI_IMMEDIATE_4: - op = _g_imm_operand_new_from_data(MDS_4_BITS, data, pos, len, low, endian); + op = _g_imm_operand_new_from_data(MDS_4_BITS, data, pos, end, low, endian); break; case DOI_IMMEDIATE_8: - op = g_imm_operand_new_from_data(MDS_8_BITS, data, pos, len, endian); + op = g_imm_operand_new_from_data(MDS_8_BITS, data, pos, end, endian); break; case DOI_IMMEDIATE_16: - op = g_imm_operand_new_from_data(MDS_16_BITS, data, pos, len, endian); + op = g_imm_operand_new_from_data(MDS_16_BITS, data, pos, end, endian); break; case DOI_IMMEDIATE_32: - op = g_imm_operand_new_from_data(MDS_32_BITS, data, pos, len, endian); + op = g_imm_operand_new_from_data(MDS_32_BITS, data, pos, end, endian); break; case DOI_IMMEDIATE_64: - op = g_imm_operand_new_from_data(MDS_64_BITS, data, pos, len, endian); + op = g_imm_operand_new_from_data(MDS_64_BITS, data, pos, end, endian); break; case DOI_IMMEDIATE_H16: - result = read_u16(&value16, data, pos, len, endian); + result = read_u16(&value16, data, pos, end, endian); 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, len, MDS_16_BITS, endian); + op = g_dalvik_pool_operand_new(format, DALVIK_OP_GET_POOL(model), data, pos, end, MDS_16_BITS, endian); break; case DOI_POOL_CONST_WIDE: - op = g_dalvik_pool_operand_new(format, DALVIK_OP_GET_POOL(model), data, pos, len, MDS_32_BITS, endian); + op = g_dalvik_pool_operand_new(format, DALVIK_OP_GET_POOL(model), data, pos, end, MDS_32_BITS, endian); break; case DOI_TARGET_8: - op = g_dalvik_target_operand_new(data, pos, len, MDS_8_BITS_SIGNED, endian, va_arg(ap, vmpa_t)); + op = g_dalvik_target_operand_new(data, pos, end, MDS_8_BITS_SIGNED, endian, va_arg(ap, vmpa_t)); break; case DOI_TARGET_16: - op = g_dalvik_target_operand_new(data, pos, len, MDS_16_BITS_SIGNED, endian, va_arg(ap, vmpa_t)); + op = g_dalvik_target_operand_new(data, pos, end, MDS_16_BITS_SIGNED, endian, va_arg(ap, vmpa_t)); break; case DOI_TARGET_32: - op = g_dalvik_target_operand_new(data, pos, len, MDS_32_BITS_SIGNED, endian, va_arg(ap, vmpa_t)); + op = g_dalvik_target_operand_new(data, pos, end, MDS_32_BITS_SIGNED, endian, va_arg(ap, vmpa_t)); break; default: @@ -363,7 +365,7 @@ static bool dalvik_read_basic_operands(GArchInstruction *instr, const GDexFormat * format = format du fichier contenant le code. * * data = flux de données à analyser. * * pos = position courante dans ce flux. [OUT] * -* len = taille totale des données à analyser. * +* 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. * @@ -376,7 +378,7 @@ 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 len, bool *low, SourceEndian endian, DalvikOperandType model) +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) { GArchOperand *opa; /* Opérande vA décodé */ uint8_t b; /* Nbre. de registres utilisés */ @@ -388,13 +390,13 @@ static bool dalvik_read_fixed_operands(GArchInstruction *instr, const GDexFormat - opa = g_dalvik_register_operand_new(data, pos, len, 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, len, low, endian)) + if (!read_u4(&b, data, pos, end, low, endian)) goto err_va; - target1 = g_dalvik_pool_operand_new(format, DALVIK_OP_GET_POOL(model), data, pos, len, MDS_16_BITS, endian); + 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; @@ -416,7 +418,7 @@ static bool dalvik_read_fixed_operands(GArchInstruction *instr, const GDexFormat for (i = 0; i < MIN(b, 4); i++) { - op = g_dalvik_register_operand_new(data, pos, len, low, MDS_4_BITS, endian); + op = g_dalvik_register_operand_new(data, pos, end, low, MDS_4_BITS, endian); if (op == NULL) goto err_registers; g_dalvik_args_operand_add(G_DALVIK_ARGS_OPERAND(args), op); @@ -461,7 +463,7 @@ static bool dalvik_read_fixed_operands(GArchInstruction *instr, const GDexFormat * format = format du fichier contenant le code. * * data = flux de données à analyser. * * pos = position courante dans ce flux. [OUT] * -* len = taille totale des données à analyser. * +* 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. * @@ -474,7 +476,7 @@ 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 len, bool *low, SourceEndian endian, DalvikOperandType model) +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) { uint8_t a; /* Nbre. de registres utilisés */ uint16_t b; /* Indice dans la table const. */ @@ -484,13 +486,13 @@ static bool dalvik_read_variatic_operands(GArchInstruction *instr, const GDexFor uint16_t c; /* Indice de registre */ GArchOperand *op; /* Opérande unique décodé */ - if (!read_u8(&a, data, pos, len, endian)) + if (!read_u8(&a, data, pos, end, endian)) return false; - if (!read_u16(&b, data, pos, len, endian)) + if (!read_u16(&b, data, pos, end, endian)) return false; - target = g_dalvik_pool_operand_new(format, DALVIK_OP_GET_POOL(model), data, pos, len, MDS_16_BITS, endian); + target = g_dalvik_pool_operand_new(format, DALVIK_OP_GET_POOL(model), data, pos, end, MDS_16_BITS, endian); if (target == NULL) return false; /* Mise en place des arguments */ @@ -500,7 +502,7 @@ static bool dalvik_read_variatic_operands(GArchInstruction *instr, const GDexFor for (i = 0; i < a; i++) { - if (i == 0 && !read_u16(&c, data, pos, len, endian)) + 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)); @@ -542,7 +544,7 @@ static bool dalvik_read_variatic_operands(GArchInstruction *instr, const GDexFor * format = format du fichier contenant le code. * * data = flux de données à analyser. * * pos = position courante dans ce flux. [OUT] * -* len = taille totale des données à analyser. * +* end = limite des données à analyser. * * endian = boutisme lié au binaire accompagnant. * * model = type d'opérandes attendues. * * ... = éventuelles données complémentaires. * @@ -555,7 +557,7 @@ 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 len, SourceEndian endian, DalvikOperandType model, ...) +bool dalvik_read_operands(GArchInstruction *instr, const GDexFormat *format, const bin_t *data, off_t *pos, off_t end, SourceEndian endian, DalvikOperandType model, ...) { bool result; /* Bilan à retourner */ @@ -602,18 +604,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, len, &low, endian, model, ap); + result = dalvik_read_basic_operands(instr, format, data, pos, end, &low, endian, model, ap); va_end(ap); break; case DALVIK_OPT_35C: - result = dalvik_read_fixed_operands(instr, format, data, pos, len, &low, endian, model); + result = dalvik_read_fixed_operands(instr, format, data, pos, end, &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, len, &low, endian, model); + result = dalvik_read_variatic_operands(instr, format, data, pos, end, &low, endian, model); break; default: @@ -627,7 +629,7 @@ bool dalvik_read_operands(GArchInstruction *instr, const GDexFormat *format, con - if (*pos < len) + if (*pos < end) { (*pos)++; |