From 11e76cece91707f1910d3b1fa56464e261757a52 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Sun, 7 May 2017 20:42:18 +0200 Subject: Fixed the registered coverage of LEB128 raw instructions. --- ChangeLog | 8 ++++++++ src/arch/archbase.h | 3 ++- src/arch/raw.c | 48 +++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 49 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index e677156..dbced06 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +17-05-07 Cyrille Bagard + + * src/arch/archbase.h: + Create a macro for memory data signs. + + * src/arch/raw.c: + Fix the registered coverage of LEB128 raw instructions. + 17-05-05 Cyrille Bagard * plugins/fmtp/parser.c: diff --git a/src/arch/archbase.h b/src/arch/archbase.h index 824bebc..634efc3 100644 --- a/src/arch/archbase.h +++ b/src/arch/archbase.h @@ -71,7 +71,8 @@ typedef enum _MemoryDataSize #define MDS_RANGE(mds) ((mds & 0xf) - 1) -#define MDS_IS_SIGNED(mds) (mds & 0x80) +#define MDS_SIGN 0x80 +#define MDS_IS_SIGNED(mds) (mds & MDS_SIGN) #define MDS_FROM_BYTES(sz) \ diff --git a/src/arch/raw.c b/src/arch/raw.c index b84d9f7..da9ee88 100644 --- a/src/arch/raw.c +++ b/src/arch/raw.c @@ -267,17 +267,32 @@ GArchInstruction *g_raw_instruction_new_uleb128(const GBinContent *content, vmpa GArchInstruction *result; /* Instruction à retourner */ vmpa2t start; /* Départ original de lecture */ uleb128_t value; /* Valeur uleb128 à représenter*/ + phys_t diff; /* Couverture de la lecture */ MemoryDataSize leb_size; /* Taille de la valeur */ + GImmOperand *operand; /* Octet non décodé à afficher */ + mrange_t range; /* Couverture de l'instruction */ copy_vmpa(&start, addr); if (!g_binary_content_read_uleb128(content, addr, &value)) goto grinu_error; - leb_size = MDS_FROM_BYTES(compute_vmpa_diff(&start, addr)); + diff = compute_vmpa_diff(&start, addr); + + leb_size = MDS_FROM_BYTES(diff); assert(leb_size != MDS_UNDEFINED); - result = g_raw_instruction_new_from_value(&start, leb_size, (uint64_t)value); + result = g_object_new(G_TYPE_RAW_INSTRUCTION, NULL); + + init_mrange(&range, &start, diff); + g_arch_instruction_set_range(result, &range); + + operand = G_IMM_OPERAND(g_imm_operand_new_from_value(leb_size, (uint64_t)value)); + if (operand == NULL) goto grinu_error; + + g_imm_operand_pad(&operand, true, NULL); + + g_arch_instruction_attach_extra_operand(result, G_ARCH_OPERAND(operand)); return result; @@ -305,22 +320,37 @@ GArchInstruction *g_raw_instruction_new_sleb128(const GBinContent *content, vmpa { GArchInstruction *result; /* Instruction à retourner */ vmpa2t start; /* Départ original de lecture */ - leb128_t value; /* Valeur sleb128 à représenter*/ + uleb128_t value; /* Valeur uleb128 à représenter*/ + phys_t diff; /* Couverture de la lecture */ MemoryDataSize leb_size; /* Taille de la valeur */ + GImmOperand *operand; /* Octet non décodé à afficher */ + mrange_t range; /* Couverture de l'instruction */ copy_vmpa(&start, addr); - if (!g_binary_content_read_leb128(content, addr, &value)) - goto grinu_error; + if (!g_binary_content_read_uleb128(content, addr, &value)) + goto grins_error; - leb_size = MDS_FROM_BYTES(compute_vmpa_diff(&start, addr)); - assert(leb_size != MDS_UNDEFINED); + diff = compute_vmpa_diff(&start, addr); + + leb_size = MDS_FROM_BYTES(diff) | MDS_SIGN; + assert(leb_size != MDS_SIGN); - result = g_raw_instruction_new_from_value(&start, leb_size, (uint64_t)value); + result = g_object_new(G_TYPE_RAW_INSTRUCTION, NULL); + + init_mrange(&range, &start, diff); + g_arch_instruction_set_range(result, &range); + + operand = G_IMM_OPERAND(g_imm_operand_new_from_value(leb_size, (uint64_t)value)); + if (operand == NULL) goto grins_error; + + g_imm_operand_pad(&operand, true, NULL); + + g_arch_instruction_attach_extra_operand(result, G_ARCH_OPERAND(operand)); return result; - grinu_error: + grins_error: return NULL; -- cgit v0.11.2-87-g4458