diff options
Diffstat (limited to 'src/arch')
-rw-r--r-- | src/arch/arm/v7/processor.c | 2 | ||||
-rw-r--r-- | src/arch/artificial.c | 2 | ||||
-rw-r--r-- | src/arch/dalvik/operand.c | 10 | ||||
-rw-r--r-- | src/arch/immediate.c | 113 | ||||
-rw-r--r-- | src/arch/immediate.h | 13 | ||||
-rw-r--r-- | src/arch/instruction.h | 1 | ||||
-rw-r--r-- | src/arch/raw.c | 60 | ||||
-rw-r--r-- | src/arch/raw.h | 5 | ||||
-rw-r--r-- | src/arch/x86/operand.c | 6 | ||||
-rw-r--r-- | src/arch/x86/operands/modrm.c | 8 | ||||
-rw-r--r-- | src/arch/x86/operands/moffs.c | 2 |
11 files changed, 200 insertions, 22 deletions
diff --git a/src/arch/arm/v7/processor.c b/src/arch/arm/v7/processor.c index 3464214..9117861 100644 --- a/src/arch/arm/v7/processor.c +++ b/src/arch/arm/v7/processor.c @@ -298,7 +298,7 @@ static GArchInstruction *g_armv7_processor_disassemble(const GArmV7Processor *pr advance_vmpa(pos, diff); /* else - result = g_raw_instruction_new_array(data, MDS_32_BITS, 1, pos, end, + result = g_raw_instruction_new_array_old(data, MDS_32_BITS, 1, pos, end, G_ARCH_PROCESSOR(proc)->endianness); */ return result; diff --git a/src/arch/artificial.c b/src/arch/artificial.c index d2b2117..a6fea56 100644 --- a/src/arch/artificial.c +++ b/src/arch/artificial.c @@ -201,7 +201,7 @@ GArchInstruction *g_db_instruction_new_from_data(const bin_t *data, vmpa2t *addr pos = get_phy_addr(address); old = pos; - operand = g_imm_operand_new_from_data(g_arch_processor_get_instruction_size(proc), + operand = g_imm_operand_new_from_data_old(g_arch_processor_get_instruction_size(proc), data, &pos, end, g_arch_processor_get_endianness(proc)); diff --git a/src/arch/dalvik/operand.c b/src/arch/dalvik/operand.c index a63369c..fca7956 100644 --- a/src/arch/dalvik/operand.c +++ b/src/arch/dalvik/operand.c @@ -300,27 +300,27 @@ static bool dalvik_read_basic_operands(GArchInstruction *instr, const GDexFormat case DOI_IMMEDIATE_4: assert(0); - //op = _g_imm_operand_new_from_data(MDS_4_BITS, data, pos, end, low, endian); + //op = _g_imm_operand_new_from_data_old(MDS_4_BITS, data, pos, end, low, endian); break; case DOI_IMMEDIATE_8: assert(0); - //op = g_imm_operand_new_from_data(MDS_8_BITS, data, pos, end, endian); + //op = g_imm_operand_new_from_data_old(MDS_8_BITS, data, pos, end, endian); break; case DOI_IMMEDIATE_16: assert(0); - //op = g_imm_operand_new_from_data(MDS_16_BITS, data, pos, end, endian); + //op = g_imm_operand_new_from_data_old(MDS_16_BITS, data, pos, end, endian); break; case DOI_IMMEDIATE_32: assert(0); - //op = g_imm_operand_new_from_data(MDS_32_BITS, data, pos, end, endian); + //op = g_imm_operand_new_from_data_old(MDS_32_BITS, data, pos, end, endian); break; case DOI_IMMEDIATE_64: assert(0); - //op = g_imm_operand_new_from_data(MDS_64_BITS, data, pos, end, endian); + //op = g_imm_operand_new_from_data_old(MDS_64_BITS, data, pos, end, endian); break; case DOI_IMMEDIATE_H16: diff --git a/src/arch/immediate.c b/src/arch/immediate.c index 4d0c0b8..3a3e64c 100644 --- a/src/arch/immediate.c +++ b/src/arch/immediate.c @@ -211,7 +211,7 @@ static void g_imm_operand_finalize(GImmOperand *operand) * * ******************************************************************************/ -GArchOperand *_g_imm_operand_new_from_data(MemoryDataSize size, const bin_t *data, vmpa2t *addr, off_t end, bool *low, SourceEndian endian) +GArchOperand *_g_imm_operand_new_from_data_old(MemoryDataSize size, const bin_t *data, vmpa2t *addr, off_t end, bool *low, SourceEndian endian) { GImmOperand *result; /* Opérande à retourner */ off_t old; /* Ancienne tête de lecture */ @@ -315,6 +315,117 @@ GArchOperand *_g_imm_operand_new_from_data(MemoryDataSize size, const bin_t *dat /****************************************************************************** * * +* Paramètres : size = taille de l'opérande souhaitée. * +* content = flux de données à analyser. * +* addr = position courante dans ce flux. [OUT] * +* low = position éventuelle des 4 bits visés. [OUT] * +* endian = ordre des bits dans la source. * +* * +* Description : Crée un opérande réprésentant une valeur numérique. * +* * +* Retour : Instruction mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GArchOperand *_g_imm_operand_new_from_data(MemoryDataSize size, const GBinContent *content, vmpa2t *addr, bool *low, SourceEndian endian) +{ + GImmOperand *result; /* Opérande à retourner */ + uint8_t uval8; /* Valeur sur 8 bits */ + uint16_t uval16; /* Valeur sur 16 bits */ + uint32_t uval32; /* Valeur sur 32 bits */ + uint64_t uval64; /* Valeur sur 64 bits */ + int8_t sval8; /* Valeur sur 8 bits */ + int16_t sval16; /* Valeur sur 16 bits */ + int32_t sval32; /* Valeur sur 32 bits */ + int64_t sval64; /* Valeur sur 64 bits */ + + result = g_object_new(G_TYPE_IMM_OPERAND, NULL); + + result->size = size; + + switch (size) + { + case MDS_4_BITS_UNSIGNED: + if (!g_binary_content_read_u4(content, addr, low, endian, &uval8)) + goto gionfd_error; + result->raw = uval8; + break; + + case MDS_8_BITS_UNSIGNED: + if (!g_binary_content_read_u8(content, addr, endian, &uval8)) + goto gionfd_error; + result->raw = uval8; + break; + + case MDS_16_BITS_UNSIGNED: + if (!g_binary_content_read_u16(content, addr, endian, &uval16)) + goto gionfd_error; + result->raw = uval16; + break; + + case MDS_32_BITS_UNSIGNED: + if (!g_binary_content_read_u32(content, addr, endian, &uval32)) + goto gionfd_error; + result->raw = uval32; + break; + + case MDS_64_BITS_UNSIGNED: + if (!g_binary_content_read_u64(content, addr, endian, &uval64)) + goto gionfd_error; + result->raw = uval64; + break; + + case MDS_4_BITS_SIGNED: + if (!g_binary_content_read_s4(content, addr, low, endian, &sval8)) + goto gionfd_error; + result->raw = sval8; + break; + + case MDS_8_BITS_SIGNED: + if (!g_binary_content_read_s8(content, addr, endian, &sval8)) + goto gionfd_error; + result->raw = sval8; + break; + + case MDS_16_BITS_SIGNED: + if (!g_binary_content_read_s16(content, addr, endian, &sval16)) + goto gionfd_error; + result->raw = sval16; + break; + + case MDS_32_BITS_SIGNED: + if (!g_binary_content_read_s32(content, addr, endian, &sval32)) + goto gionfd_error; + result->raw = sval32; + break; + + case MDS_64_BITS_SIGNED: + if (!g_binary_content_read_s64(content, addr, endian, &sval64)) + goto gionfd_error; + result->raw = sval64; + break; + + case MDS_UNDEFINED: + goto gionfd_error; + break; + + } + + return G_ARCH_OPERAND(result); + + gionfd_error: + + g_object_unref(G_OBJECT(result)); + + return NULL; + +} + + +/****************************************************************************** +* * * Paramètres : size = taille de l'opérande souhaitée. * * value = valeur sur x bits à venir récupérer. * * * diff --git a/src/arch/immediate.h b/src/arch/immediate.h index a218c16..a0721b2 100644 --- a/src/arch/immediate.h +++ b/src/arch/immediate.h @@ -33,6 +33,7 @@ #include "archbase.h" #include "operand.h" #include "../common/endianness.h" +#include "../glibext/gbincontent.h" @@ -66,10 +67,16 @@ typedef struct _GImmOperandClass GImmOperandClass; GType g_imm_operand_get_type(void); /* Crée un opérande réprésentant une valeur numérique. */ -GArchOperand *_g_imm_operand_new_from_data(MemoryDataSize, const bin_t *, vmpa2t *, off_t, bool *, SourceEndian); +GArchOperand *_g_imm_operand_new_from_data_old(MemoryDataSize, const bin_t *, vmpa2t *, off_t, bool *, SourceEndian) __attribute__ ((deprecated)); -#define g_imm_operand_new_from_data(size, data, pos, len, endian) \ - _g_imm_operand_new_from_data(size, data, pos, len, NULL, endian) +#define g_imm_operand_new_from_data_old(size, data, pos, len, endian) \ + _g_imm_operand_new_from_data_old(size, data, pos, len, NULL, endian) + +/* Crée un opérande réprésentant une valeur numérique. */ +GArchOperand *_g_imm_operand_new_from_data(MemoryDataSize, const GBinContent *, vmpa2t *, bool *, SourceEndian); + +#define g_imm_operand_new_from_data(size, content, addr, endian) \ + _g_imm_operand_new_from_data(size, content, addr, NULL, endian) /* Crée un opérande réprésentant une valeur numérique. */ GArchOperand *g_imm_operand_new_from_value(MemoryDataSize, uint64_t); diff --git a/src/arch/instruction.h b/src/arch/instruction.h index 02bb9b7..f1ce67f 100644 --- a/src/arch/instruction.h +++ b/src/arch/instruction.h @@ -35,6 +35,7 @@ #include "../analysis/type.h" #include "../decomp/context.h" #include "../decomp/instruction.h" +#include "../glibext/gbincontent.h" //#include "../format/executable.h" //#include "../format/format.h" diff --git a/src/arch/raw.c b/src/arch/raw.c index 62c88c1..808d973 100644 --- a/src/arch/raw.c +++ b/src/arch/raw.c @@ -254,7 +254,7 @@ GArchInstruction *g_raw_instruction_new_from_value(const vmpa2t *addr, MemoryDat * * ******************************************************************************/ -GArchInstruction *g_raw_instruction_new_array(const bin_t *data, MemoryDataSize size, size_t count, vmpa2t *addr, off_t end, SourceEndian endian) +GArchInstruction *g_raw_instruction_new_array_old(const bin_t *data, MemoryDataSize size, size_t count, vmpa2t *addr, off_t end, SourceEndian endian) { GArchInstruction *result; /* Instruction à retourner */ vmpa2t old; /* Sauvegarde de la position */ @@ -271,7 +271,63 @@ GArchInstruction *g_raw_instruction_new_array(const bin_t *data, MemoryDataSize for (i = 0; i < count; i++) { - operand = g_imm_operand_new_from_data(size, data, addr, end, endian); + operand = g_imm_operand_new_from_data_old(size, data, addr, end, endian); + if (operand == NULL) goto grina_error; + + g_imm_operand_pad(G_IMM_OPERAND(operand), true); + + g_arch_instruction_attach_extra_operand(result, operand); + } + + init_mrange(&range, &old, compute_vmpa_diff(addr, &old)); + + g_arch_instruction_set_range(result, &range); + + return result; + + grina_error: + + g_object_unref(G_OBJECT(result)); + + return NULL; + +} + + +/****************************************************************************** +* * +* Paramètres : content = flux de données à analyser. * +* size = taille de chacun des éléments à représenter. * +* count = nombre de ces éléments. * +* addr = position courante dans ce flux. [OUT] * +* endian = ordre des bits dans la source. * +* * +* Description : Crée une instruction de type 'db/dw/etc' étendue. * +* * +* Retour : Instruction mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GArchInstruction *g_raw_instruction_new_array(const GBinContent *content, MemoryDataSize size, size_t count, vmpa2t *addr, SourceEndian endian) +{ + GArchInstruction *result; /* Instruction à retourner */ + vmpa2t old; /* Sauvegarde de la position */ + size_t i; /* Boucle de parcours */ + GArchOperand *operand; /* Octet non décodé à afficher */ + mrange_t range; /* Couverture de l'instruction */ + + /* Par soucis de cohérence */ + if (count == 0) return NULL; + + result = g_object_new(G_TYPE_RAW_INSTRUCTION, NULL); + + copy_vmpa(&old, addr); + + for (i = 0; i < count; i++) + { + operand = g_imm_operand_new_from_data(size, content, addr, endian); if (operand == NULL) goto grina_error; g_imm_operand_pad(G_IMM_OPERAND(operand), true); diff --git a/src/arch/raw.h b/src/arch/raw.h index 8ae9a74..f7e1715 100644 --- a/src/arch/raw.h +++ b/src/arch/raw.h @@ -56,7 +56,10 @@ GType g_raw_instruction_get_type(void); GArchInstruction *g_raw_instruction_new_from_value(const vmpa2t *, MemoryDataSize, uint64_t); /* Crée une instruction de type 'db/dw/etc' étendue. */ -GArchInstruction *g_raw_instruction_new_array(const bin_t *, MemoryDataSize, size_t, vmpa2t *, off_t, SourceEndian); +GArchInstruction *g_raw_instruction_new_array_old(const bin_t *, MemoryDataSize, size_t, vmpa2t *, off_t, SourceEndian); + +/* Crée une instruction de type 'db/dw/etc' étendue. */ +GArchInstruction *g_raw_instruction_new_array(const GBinContent *, MemoryDataSize, size_t, vmpa2t *, SourceEndian); /* Marque l'instruction comme ne contenant que du bourrage. */ void g_raw_instruction_mark_as_padding(GRawInstruction *, bool); diff --git a/src/arch/x86/operand.c b/src/arch/x86/operand.c index 8eb79dc..cab2570 100644 --- a/src/arch/x86/operand.c +++ b/src/arch/x86/operand.c @@ -118,18 +118,18 @@ bool _x86_read_operands(GArchInstruction *instr, const bin_t *data, off_t *pos, { case X86_OTP_IMM8: assert(0); - //op = g_imm_operand_new_from_data(MDS_8_BITS, data, &op_pos[i], len, SRE_LITTLE /* FIXME */); + //op = g_imm_operand_new_from_data_old(MDS_8_BITS, data, &op_pos[i], len, SRE_LITTLE /* FIXME */); break; case X86_OTP_IMM16: assert(0); - //op = g_imm_operand_new_from_data(MDS_16_BITS, data, &op_pos[i], len, SRE_LITTLE /* FIXME */); + //op = g_imm_operand_new_from_data_old(MDS_16_BITS, data, &op_pos[i], len, SRE_LITTLE /* FIXME */); break; case X86_OTP_IMM1632: if (oprsize == MDS_UNDEFINED) oprsize = va_arg(ap, MemoryDataSize); assert(0); - //op = g_imm_operand_new_from_data(oprsize == MDS_32_BITS ? MDS_32_BITS : MDS_16_BITS, data, &op_pos[i], len, SRE_LITTLE /* FIXME */); + //op = g_imm_operand_new_from_data_old(oprsize == MDS_32_BITS ? MDS_32_BITS : MDS_16_BITS, data, &op_pos[i], len, SRE_LITTLE /* FIXME */); break; case X86_OTP_MOFFS8: diff --git a/src/arch/x86/operands/modrm.c b/src/arch/x86/operands/modrm.c index 1da734f..030b401 100644 --- a/src/arch/x86/operands/modrm.c +++ b/src/arch/x86/operands/modrm.c @@ -138,7 +138,7 @@ GArchOperand *g_x86_mod_rm_operand_new(const bin_t *data, off_t *pos, off_t len, /* FIXME *///free_x86_register(reg); assert(0); return NULL; - //return g_imm_operand_new_from_data(MDS_32_BITS/* FIXME */, data, pos, len, SRE_LITTLE /*FIXME*/); + //return g_imm_operand_new_from_data_old(MDS_32_BITS/* FIXME */, data, pos, len, SRE_LITTLE /*FIXME*/); } result = g_object_new(G_TYPE_X86_MOD_RM_OPERAND, NULL); @@ -179,7 +179,7 @@ GArchOperand *g_x86_mod_rm_operand_new(const bin_t *data, off_t *pos, off_t len, result->base = NULL; assert(0); - //result->displacement = g_imm_operand_new_from_data(size/* FIXME : !convert mds/aos */, data, pos, len, SRE_LITTLE /* FIXME */); + //result->displacement = g_imm_operand_new_from_data_old(size/* FIXME : !convert mds/aos */, data, pos, len, SRE_LITTLE /* FIXME */); if (result->displacement == NULL) goto gxmron_error; } @@ -187,13 +187,13 @@ GArchOperand *g_x86_mod_rm_operand_new(const bin_t *data, off_t *pos, off_t len, case 0x40: assert(0); - //result->displacement = g_imm_operand_new_from_data(MDS_8_BITS_SIGNED, data, pos, len, SRE_LITTLE /* FIXME */); + //result->displacement = g_imm_operand_new_from_data_old(MDS_8_BITS_SIGNED, data, pos, len, SRE_LITTLE /* FIXME */); if (result->displacement == NULL) goto gxmron_error; break; case 0x80: assert(0); - //result->displacement = g_imm_operand_new_from_data(MDS_32_BITS_SIGNED/* FIXME ! 16/32 */, data, pos, len, SRE_LITTLE /* FIXME */); + //result->displacement = g_imm_operand_new_from_data_old(MDS_32_BITS_SIGNED/* FIXME ! 16/32 */, data, pos, len, SRE_LITTLE /* FIXME */); if (result->displacement == NULL) goto gxmron_error; break; diff --git a/src/arch/x86/operands/moffs.c b/src/arch/x86/operands/moffs.c index 689a400..1bdc1f8 100644 --- a/src/arch/x86/operands/moffs.c +++ b/src/arch/x86/operands/moffs.c @@ -117,7 +117,7 @@ GArchOperand *g_x86_moffs_operand_new(const bin_t *data, off_t *pos, off_t len, result = NULL; assert(0); - //offset = g_imm_operand_new_from_data(size, data, pos, len, SRE_LITTLE /* FIXME */); + //offset = g_imm_operand_new_from_data_old(size, data, pos, len, SRE_LITTLE /* FIXME */); if (offset != NULL) { |