summaryrefslogtreecommitdiff
path: root/src/arch/dalvik/operand.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2016-01-30 00:21:08 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2016-01-30 00:21:08 (GMT)
commitc922b6b9c841a97dd948755658cff07b2c6762ff (patch)
tree7236b03fde56edde625e406085862381cde6e955 /src/arch/dalvik/operand.c
parent16e0fd9d89ef433848678dfc8dd20426844a2868 (diff)
Updated some parts of the code dealing with Dalvik.
Diffstat (limited to 'src/arch/dalvik/operand.c')
-rw-r--r--src/arch/dalvik/operand.c243
1 files changed, 91 insertions, 152 deletions
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 <assert.h> // REMME (assert(0))
#include <malloc.h>
#include <stdarg.h>
@@ -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;
}