summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2017-05-07 18:42:18 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2017-05-07 18:42:18 (GMT)
commit11e76cece91707f1910d3b1fa56464e261757a52 (patch)
tree461db8648bef6bad06c532979a80b6c1858e8839 /src
parenta66f854ce4e19dc0f772fc55a3899643252afa3d (diff)
Fixed the registered coverage of LEB128 raw instructions.
Diffstat (limited to 'src')
-rw-r--r--src/arch/archbase.h3
-rw-r--r--src/arch/raw.c48
2 files changed, 41 insertions, 10 deletions
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;