summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2015-02-16 07:07:15 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2015-02-16 07:07:15 (GMT)
commit635640a32fecbb9b8a5ddf239b819c022c4b9977 (patch)
treef8fc69a2c2db411000996146536ca5cc4f54d417 /src
parentbf879f2562545ab7de23f9d38364b7bd4b43fb2c (diff)
Added a basic support for Mobicore truslets.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@472 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src')
-rw-r--r--src/analysis/binary.c3
-rw-r--r--src/analysis/disass/area.c10
-rw-r--r--src/arch/arm/v7/processor.c2
-rw-r--r--src/arch/artificial.c2
-rw-r--r--src/arch/dalvik/operand.c10
-rw-r--r--src/arch/immediate.c113
-rw-r--r--src/arch/immediate.h13
-rw-r--r--src/arch/instruction.h1
-rw-r--r--src/arch/raw.c60
-rw-r--r--src/arch/raw.h5
-rw-r--r--src/arch/x86/operand.c6
-rw-r--r--src/arch/x86/operands/modrm.c8
-rw-r--r--src/arch/x86/operands/moffs.c2
-rw-r--r--src/core/formats.c7
-rw-r--r--src/core/processors.c7
-rw-r--r--src/format/elf/elf-int.c6
-rw-r--r--src/format/elf/symbols.c108
-rw-r--r--src/format/format-int.h1
-rw-r--r--src/format/format.c1
-rw-r--r--src/glibext/gbincontent.c392
-rw-r--r--src/glibext/gbincontent.h25
-rw-r--r--src/plugins/plugin-def.h21
-rw-r--r--src/plugins/plugin-int.h10
-rw-r--r--src/plugins/plugin.c40
24 files changed, 735 insertions, 118 deletions
diff --git a/src/analysis/binary.c b/src/analysis/binary.c
index 96e774c..d27e761 100644
--- a/src/analysis/binary.c
+++ b/src/analysis/binary.c
@@ -210,9 +210,6 @@ static void g_loaded_binary_finalize(GLoadedBinary *binary)
{
free(binary->username);
- if (binary->bin_data != NULL)
- free(binary->bin_data);
-
/* TODO... */
G_OBJECT_CLASS(g_loaded_binary_parent_class)->finalize(G_OBJECT(binary));
diff --git a/src/analysis/disass/area.c b/src/analysis/disass/area.c
index a6e58cd..974a223 100644
--- a/src/analysis/disass/area.c
+++ b/src/analysis/disass/area.c
@@ -359,13 +359,13 @@ static bool mark_range_in_mem_area_as_processed(mem_area *area, phys_t start, ph
index = i / (sizeof(unsigned long) * 8);
remaining = i % (sizeof(unsigned long) * 8);
- assert((area->processed[index] & (1ul << remaining)) == 0);
+ //assert((area->processed[index] & (1ul << remaining)) == 0);
area->processed[index] |= (1ul << remaining);
}
- assert(area->instructions[start] == NULL);
+ //assert(area->instructions[start] == NULL);
area->instructions[start] = instr;
@@ -666,7 +666,7 @@ static void load_data_from_mem_area(mem_area *area, mem_area *list, size_t count
init_mrange(&range, &pos, 4);
if (is_range_blank_in_mem_areas(list, count, &range))
- instr = g_raw_instruction_new_array(bin_data, MDS_32_BITS, 1, &pos, bin_length, endianness);
+ instr = g_raw_instruction_new_array_old(bin_data, MDS_32_BITS, 1, &pos, bin_length, endianness);
}
*/
@@ -676,7 +676,7 @@ static void load_data_from_mem_area(mem_area *area, mem_area *list, size_t count
init_mrange(&range, &pos, 2);
if (is_range_blank_in_mem_areas(list, count, &range))
- instr = g_raw_instruction_new_array(bin_data, MDS_16_BITS, 1, &pos, bin_length, endianness);
+ instr = g_raw_instruction_new_array_old(bin_data, MDS_16_BITS, 1, &pos, bin_length, endianness);
}
@@ -686,7 +686,7 @@ static void load_data_from_mem_area(mem_area *area, mem_area *list, size_t count
init_mrange(&range, &pos, 1);
if (is_range_blank_in_mem_areas(list, count, &range))
- instr = g_raw_instruction_new_array(bin_data, MDS_8_BITS, 1, &pos, bin_length, endianness);
+ instr = g_raw_instruction_new_array_old(bin_data, MDS_8_BITS, 1, &pos, bin_length, endianness);
else
{
/**
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)
{
diff --git a/src/core/formats.c b/src/core/formats.c
index b528e62..9ff31b2 100644
--- a/src/core/formats.c
+++ b/src/core/formats.c
@@ -178,9 +178,10 @@ static format_t *find_format_by_key(const char *key)
result = NULL;
- for (i = 0; i < _formats_definitions_count; i++)
- if (strcmp(_formats_definitions[i].key, key) == 0)
- result = &_formats_definitions[i];
+ if (key != NULL)
+ for (i = 0; i < _formats_definitions_count; i++)
+ if (strcmp(_formats_definitions[i].key, key) == 0)
+ result = &_formats_definitions[i];
return result;
diff --git a/src/core/processors.c b/src/core/processors.c
index 7489614..715cd88 100644
--- a/src/core/processors.c
+++ b/src/core/processors.c
@@ -179,9 +179,10 @@ static proc_t *find_processor_by_key(const char *key)
result = NULL;
- for (i = 0; i < _processors_definitions_count; i++)
- if (strcmp(_processors_definitions[i].key, key) == 0)
- result = &_processors_definitions[i];
+ if (key != NULL)
+ for (i = 0; i < _processors_definitions_count; i++)
+ if (strcmp(_processors_definitions[i].key, key) == 0)
+ result = &_processors_definitions[i];
return result;
diff --git a/src/format/elf/elf-int.c b/src/format/elf/elf-int.c
index a2ef9b2..4fd65df 100644
--- a/src/format/elf/elf-int.c
+++ b/src/format/elf/elf-int.c
@@ -31,9 +31,9 @@
/******************************************************************************
* *
* Paramètres : format = informations chargées à consulter. *
-* header = en-tête à déterminer. [OUT] *
-* is_32b = indique si le format est en 32 ou 64 bits. [OUT] *
-* endian = boutisme reconnu dans le format. [OUT] *
+* header = en-tête à déterminer. [OUT] *
+* is_32b = indique si le format est en 32 ou 64 bits. [OUT] *
+* endian = boutisme reconnu dans le format. [OUT] *
* *
* Description : Procède à la lecture de l'en-tête d'un contenu binaire ELF. *
* *
diff --git a/src/format/elf/symbols.c b/src/format/elf/symbols.c
index c09c429..1c3da14 100644
--- a/src/format/elf/symbols.c
+++ b/src/format/elf/symbols.c
@@ -544,7 +544,7 @@ static bool annotate_elf_header(GElfFormat *format)
/* ELFMAG (0) */
- instr = g_raw_instruction_new_array(content, MDS_8_BITS, 4, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_8_BITS, 4, pos, length, format->endian);
SET_IMM_DISPLAY(instr, operand, 1, IOD_CHAR);
SET_IMM_DISPLAY(instr, operand, 2, IOD_CHAR);
@@ -570,7 +570,7 @@ static bool annotate_elf_header(GElfFormat *format)
break;
}
- instr = g_raw_instruction_new_array(content, MDS_8_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_8_BITS, 1, pos, length, format->endian);
SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
@@ -594,7 +594,7 @@ static bool annotate_elf_header(GElfFormat *format)
break;
}
- instr = g_raw_instruction_new_array(content, MDS_8_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_8_BITS, 1, pos, length, format->endian);
SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
@@ -615,7 +615,7 @@ static bool annotate_elf_header(GElfFormat *format)
break;
}
- instr = g_raw_instruction_new_array(content, MDS_8_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_8_BITS, 1, pos, length, format->endian);
SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
@@ -672,7 +672,7 @@ static bool annotate_elf_header(GElfFormat *format)
break;
}
- instr = g_raw_instruction_new_array(content, MDS_8_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_8_BITS, 1, pos, length, format->endian);
SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
@@ -680,7 +680,7 @@ static bool annotate_elf_header(GElfFormat *format)
/* EI_ABIVERSION (8) */
- instr = g_raw_instruction_new_array(content, MDS_8_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_8_BITS, 1, pos, length, format->endian);
SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
@@ -688,7 +688,7 @@ static bool annotate_elf_header(GElfFormat *format)
/* Padding */
- instr = g_raw_instruction_new_array(content, MDS_8_BITS, 7, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_8_BITS, 7, pos, length, format->endian);
g_raw_instruction_mark_as_padding(G_RAW_INSTRUCTION(instr), true);
@@ -724,7 +724,7 @@ static bool annotate_elf_header(GElfFormat *format)
break;
}
- instr = g_raw_instruction_new_array(content, MDS_16_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_16_BITS, 1, pos, length, format->endian);
SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
@@ -815,7 +815,7 @@ static bool annotate_elf_header(GElfFormat *format)
default: text = _("Architecture: unknown"); break;
}
- instr = g_raw_instruction_new_array(content, MDS_16_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_16_BITS, 1, pos, length, format->endian);
SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
@@ -823,7 +823,7 @@ static bool annotate_elf_header(GElfFormat *format)
/* Champ "e_version" */
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_32_BITS, 1, pos, length, format->endian);
SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
@@ -833,19 +833,19 @@ static bool annotate_elf_header(GElfFormat *format)
{
/* Champ "e_entry" */
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_32_BITS, 1, pos, length, format->endian);
ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Entry point virtual address"));
/* Champ "e_phoff" */
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_32_BITS, 1, pos, length, format->endian);
ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Program header table file offset"));
/* Champ "e_shoff" */
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_32_BITS, 1, pos, length, format->endian);
ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Section header table file offset"));
@@ -855,19 +855,19 @@ static bool annotate_elf_header(GElfFormat *format)
{
/* Champ "e_entry" */
- instr = g_raw_instruction_new_array(content, MDS_64_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_64_BITS, 1, pos, length, format->endian);
ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Entry point virtual address"));
/* Champ "e_phoff" */
- instr = g_raw_instruction_new_array(content, MDS_64_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_64_BITS, 1, pos, length, format->endian);
ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Program header table file offset"));
/* Champ "e_shoff" */
- instr = g_raw_instruction_new_array(content, MDS_64_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_64_BITS, 1, pos, length, format->endian);
ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Section header table file offset"));
@@ -877,7 +877,7 @@ static bool annotate_elf_header(GElfFormat *format)
/* Champ "e_flags" */
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_32_BITS, 1, pos, length, format->endian);
//SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
@@ -885,7 +885,7 @@ static bool annotate_elf_header(GElfFormat *format)
/* Champ "e_ehsize" */
- instr = g_raw_instruction_new_array(content, MDS_16_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_16_BITS, 1, pos, length, format->endian);
SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
@@ -893,7 +893,7 @@ static bool annotate_elf_header(GElfFormat *format)
/* Champ "e_phentsize" */
- instr = g_raw_instruction_new_array(content, MDS_16_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_16_BITS, 1, pos, length, format->endian);
SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
@@ -901,7 +901,7 @@ static bool annotate_elf_header(GElfFormat *format)
/* Champ "e_phnum" */
- instr = g_raw_instruction_new_array(content, MDS_16_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_16_BITS, 1, pos, length, format->endian);
SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
@@ -909,7 +909,7 @@ static bool annotate_elf_header(GElfFormat *format)
/* Champ "e_shentsize" */
- instr = g_raw_instruction_new_array(content, MDS_16_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_16_BITS, 1, pos, length, format->endian);
SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
@@ -917,7 +917,7 @@ static bool annotate_elf_header(GElfFormat *format)
/* Champ "e_shnum" */
- instr = g_raw_instruction_new_array(content, MDS_16_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_16_BITS, 1, pos, length, format->endian);
SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
@@ -925,7 +925,7 @@ static bool annotate_elf_header(GElfFormat *format)
/* Champ "e_shstrndx" */
- instr = g_raw_instruction_new_array(content, MDS_16_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_16_BITS, 1, pos, length, format->endian);
SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
@@ -1049,7 +1049,7 @@ static bool annotate_elf_program_header_table(GElfFormat *format)
break;
}
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_32_BITS, 1, pos, length, format->endian);
SET_IMM_DISPLAY(instr, operand, 0, disp);
@@ -1059,31 +1059,31 @@ static bool annotate_elf_program_header_table(GElfFormat *format)
{
/* Champ "p_offset" */
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_32_BITS, 1, pos, length, format->endian);
ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Segment file offset"));
/* Champ "p_vaddr" */
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_32_BITS, 1, pos, length, format->endian);
ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Segment virtual address"));
/* Champ "p_paddr" */
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_32_BITS, 1, pos, length, format->endian);
ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Segment physical address"));
/* Champ "p_filesz" */
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_32_BITS, 1, pos, length, format->endian);
ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Segment size in file"));
/* Champ "p_memsz" */
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_32_BITS, 1, pos, length, format->endian);
ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Segment size in memory"));
@@ -1119,7 +1119,7 @@ static bool annotate_elf_program_header_table(GElfFormat *format)
if (!filled)
dtext = stradd(dtext, _("none"));
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_32_BITS, 1, pos, length, format->endian);
ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, dtext);
@@ -1127,7 +1127,7 @@ static bool annotate_elf_program_header_table(GElfFormat *format)
/* Champ "p_align" */
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_32_BITS, 1, pos, length, format->endian);
ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Segment alignment"));
@@ -1166,7 +1166,7 @@ static bool annotate_elf_program_header_table(GElfFormat *format)
if (!filled)
dtext = stradd(dtext, _("none"));
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_32_BITS, 1, pos, length, format->endian);
ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, dtext);
@@ -1174,37 +1174,37 @@ static bool annotate_elf_program_header_table(GElfFormat *format)
/* Champ "p_offset" */
- instr = g_raw_instruction_new_array(content, MDS_64_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_64_BITS, 1, pos, length, format->endian);
ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Segment file offset"));
/* Champ "p_vaddr" */
- instr = g_raw_instruction_new_array(content, MDS_64_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_64_BITS, 1, pos, length, format->endian);
ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Segment virtual address"));
/* Champ "p_paddr" */
- instr = g_raw_instruction_new_array(content, MDS_64_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_64_BITS, 1, pos, length, format->endian);
ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Segment physical address"));
/* Champ "p_filesz" */
- instr = g_raw_instruction_new_array(content, MDS_64_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_64_BITS, 1, pos, length, format->endian);
ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Segment size in file"));
/* Champ "p_memsz" */
- instr = g_raw_instruction_new_array(content, MDS_64_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_64_BITS, 1, pos, length, format->endian);
ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Segment size in memory"));
/* Champ "p_align" */
- instr = g_raw_instruction_new_array(content, MDS_64_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_64_BITS, 1, pos, length, format->endian);
ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Segment alignment"));
@@ -1280,7 +1280,7 @@ static bool annotate_elf_section_header_table(GElfFormat *format)
dtext = stradd(dtext, "'");
}
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_32_BITS, 1, pos, length, format->endian);
SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
@@ -1406,7 +1406,7 @@ static bool annotate_elf_section_header_table(GElfFormat *format)
break;
}
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_32_BITS, 1, pos, length, format->endian);
SET_IMM_DISPLAY(instr, operand, 0, disp);
@@ -1460,7 +1460,7 @@ static bool annotate_elf_section_header_table(GElfFormat *format)
{
/* Champ "sh_flags" (suite) */
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_32_BITS, 1, pos, length, format->endian);
ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, dtext);
@@ -1468,19 +1468,19 @@ static bool annotate_elf_section_header_table(GElfFormat *format)
/* Champ "sh_addr" */
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_32_BITS, 1, pos, length, format->endian);
ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Section virtual addr at execution"));
/* Champ "sh_offset" */
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_32_BITS, 1, pos, length, format->endian);
ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Section file offset"));
/* Champ "sh_size" */
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_32_BITS, 1, pos, length, format->endian);
SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
@@ -1491,7 +1491,7 @@ static bool annotate_elf_section_header_table(GElfFormat *format)
{
/* Champ "sh_flags" (suite) */
- instr = g_raw_instruction_new_array(content, MDS_64_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_64_BITS, 1, pos, length, format->endian);
ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, dtext);
@@ -1499,19 +1499,19 @@ static bool annotate_elf_section_header_table(GElfFormat *format)
/* Champ "sh_addr" */
- instr = g_raw_instruction_new_array(content, MDS_64_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_64_BITS, 1, pos, length, format->endian);
ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Section virtual addr at execution"));
/* Champ "sh_offset" */
- instr = g_raw_instruction_new_array(content, MDS_64_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_64_BITS, 1, pos, length, format->endian);
ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Section file offset"));
/* Champ "sh_size" */
- instr = g_raw_instruction_new_array(content, MDS_64_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_64_BITS, 1, pos, length, format->endian);
SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
@@ -1521,13 +1521,13 @@ static bool annotate_elf_section_header_table(GElfFormat *format)
/* Champ "sh_link" */
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_32_BITS, 1, pos, length, format->endian);
ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Link to another section"));
/* Champ "sh_info" */
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_32_BITS, 1, pos, length, format->endian);
ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Additional section information"));
@@ -1535,13 +1535,13 @@ static bool annotate_elf_section_header_table(GElfFormat *format)
{
/* Champ "sh_addralign" */
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_32_BITS, 1, pos, length, format->endian);
ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Section alignment"));
/* Champ "sh_entsize" */
- instr = g_raw_instruction_new_array(content, MDS_32_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_32_BITS, 1, pos, length, format->endian);
SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
@@ -1552,13 +1552,13 @@ static bool annotate_elf_section_header_table(GElfFormat *format)
{
/* Champ "sh_addralign" */
- instr = g_raw_instruction_new_array(content, MDS_64_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_64_BITS, 1, pos, length, format->endian);
ADD_RAW_AS_SYM(format, symbol, pos, instr, comment, _("Section alignment"));
/* Champ "sh_entsize" */
- instr = g_raw_instruction_new_array(content, MDS_64_BITS, 1, pos, length, format->endian);
+ instr = g_raw_instruction_new_array_old(content, MDS_64_BITS, 1, pos, length, format->endian);
SET_IMM_DISPLAY(instr, operand, 0, IOD_DEC);
diff --git a/src/format/format-int.h b/src/format/format-int.h
index 22b0c0f..96ff081 100644
--- a/src/format/format-int.h
+++ b/src/format/format-int.h
@@ -41,6 +41,7 @@ struct _GBinFormat
{
GObject parent; /* A laisser en premier */
+ GBinContent *conten_; /* Contenu binaire à étudier */
const bin_t *content; /* Contenu binaire à étudier */
off_t length; /* Taille de ce contenu */
diff --git a/src/format/format.c b/src/format/format.c
index c779947..fa00856 100644
--- a/src/format/format.c
+++ b/src/format/format.c
@@ -105,6 +105,7 @@ static void g_binary_format_init(GBinFormat *format)
void g_binary_format_set_content(GBinFormat *format, GBinContent *content)
{
+ format->conten_ = content;
format->content = g_binary_content_get(content, &format->length);
diff --git a/src/glibext/gbincontent.c b/src/glibext/gbincontent.c
index c72ac15..e0c64d4 100644
--- a/src/glibext/gbincontent.c
+++ b/src/glibext/gbincontent.c
@@ -24,6 +24,7 @@
#include "gbincontent.h"
+#include <assert.h>
#include <fcntl.h>
#include <malloc.h>
#include <stdio.h>
@@ -33,6 +34,9 @@
#include <sys/stat.h>
+#include "../common/endianness.h"
+
+
/* Aire de contenu binaire */
typedef struct _binary_part
@@ -73,6 +77,9 @@ static void g_binary_content_dispose(GBinContent *);
/* Procède à la libération totale de la mémoire. */
static void g_binary_content_finalize(GBinContent *);
+/* Retrouve la zone adaptée pour une localisation de données. */
+static const binary_part *g_binary_content_find_part(const GBinContent *, const vmpa2t *, phys_t *);
+
/* Indique le type défini par la GLib pour les contenus de données. */
@@ -239,10 +246,43 @@ GBinContent *g_binary_content_new_from_file(const char *filename)
}
+/******************************************************************************
+* *
+* Paramètres : content = contenu binaire à venir lire. *
+* addr = position de la tête de lecture globale demandée. *
+* start = position de la tête de lecture dans la zone. [OUT] *
+* *
+* Description : Retrouve la zone adaptée pour une localisation de données. *
+* *
+* Retour : Partie trouvée ou NULL en cas d'échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+static const binary_part *g_binary_content_find_part(const GBinContent *content, const vmpa2t *addr, phys_t *start)
+{
+ const binary_part *result; /* Trouvaille à retourner */
+ size_t i; /* Boucle de parcours */
+ binary_part *part; /* Zone mémoire manipulée */
+ result = NULL;
+ for (i = 0; i < content->count && result == NULL; i++)
+ {
+ part = &content->parts[i];
+
+ if (mrange_contains_addr(&part->range, addr))
+ result = part;
+
+ }
+ if (result != NULL)
+ *start = compute_vmpa_diff(get_mrange_addr(&result->range), addr);
+
+ return result;
+
+}
/******************************************************************************
@@ -260,19 +300,367 @@ GBinContent *g_binary_content_new_from_file(const char *filename)
* *
******************************************************************************/
-bool g_binary_content_get_raw(const GBinContent *content, const vmpa2t *addr, phys_t length, bin_t *out)
+bool g_binary_content_get_raw(const GBinContent *content, vmpa2t *addr, phys_t length, bin_t *out)
{
+ bool result;
+ phys_t offset;
+
/* FIXME */
- memcpy(out, &content->parts[0].data[get_phy_addr(addr)], length);
+ offset = get_phy_addr(addr);
+
+ memcpy(out, &content->parts[0].data[offset], length);
+
+ advance_vmpa(addr, length);
+
+ return true;
+
+}
+
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : content = contenu binaire à venir lire. *
+* addr = position de la tête de lecture. *
+* low = position éventuelle des 4 bits visés. [OUT] *
+* endian = ordre des bits dans la source. *
+* val = lieu d'enregistrement de la lecture. [OUT] *
+* *
+* Description : Lit un nombre non signé sur quatre bits. *
+* *
+* Retour : Bilan de l'opération : true en cas de succès, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_binary_content_read_u4(const GBinContent *content, vmpa2t *addr, bool *low, SourceEndian endian, uint8_t *val)
+{
+ phys_t start; /* Tête de lecture relative */
+ const binary_part *part; /* Zone de mémoire effective */
+ bin_t *data; /* Contenu binaire représenté */
+
+ part = g_binary_content_find_part(content, addr, &start);
+ if (part == NULL) return false;
+
+ if ((get_mrange_length(&part->range) - start) < 1) return false;
+
+ data = part->data;
+
+ if (*low)
+ {
+ *val = data[start] & 0x0f;
+ *low = false;
+ }
+ else
+ {
+ *val = (data[start] & 0xf0) >> 4;
+ *low = true;
+ advance_vmpa(addr, 4);
+ }
+
+ return true;
+
+}
+
+
+
+/******************************************************************************
+* *
+* Paramètres : content = contenu binaire à venir lire. *
+* addr = position de la tête de lecture. *
+* endian = ordre des bits dans la source. *
+* val = lieu d'enregistrement de la lecture. [OUT] *
+* *
+* Description : Lit un nombre non signé sur un octet. *
+* *
+* Retour : Bilan de l'opération : true en cas de succès, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_binary_content_read_u8(const GBinContent *content, vmpa2t *addr, SourceEndian endian, uint8_t *val)
+{
+ phys_t start; /* Tête de lecture relative */
+ const binary_part *part; /* Zone de mémoire effective */
+ bin_t *data; /* Contenu binaire représenté */
+
+ part = g_binary_content_find_part(content, addr, &start);
+ if (part == NULL) return false;
+
+ if ((get_mrange_length(&part->range) - start) < 1) return false;
+
+ data = part->data;
+
+ *val = data[start];
+
+ advance_vmpa(addr, 1);
+
+ return true;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : content = contenu binaire à venir lire. *
+* addr = position de la tête de lecture. *
+* endian = ordre des bits dans la source. *
+* val = lieu d'enregistrement de la lecture. [OUT] *
+* *
+* Description : Lit un nombre non signé sur deux octets. *
+* *
+* Retour : Bilan de l'opération : true en cas de succès, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_binary_content_read_u16(const GBinContent *content, vmpa2t *addr, SourceEndian endian, uint16_t *val)
+{
+ phys_t start; /* Tête de lecture relative */
+ const binary_part *part; /* Zone de mémoire effective */
+ bin_t *data; /* Contenu binaire représenté */
+
+ part = g_binary_content_find_part(content, addr, &start);
+ if (part == NULL) return false;
+
+ if ((get_mrange_length(&part->range) - start) < 2) return false;
+
+ data = part->data;
+
+ switch (endian)
+ {
+ case SRE_LITTLE:
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+
+ *val = data[start] | (uint16_t)data[start + 1] << 8;
+
+#elif __BYTE_ORDER == __BIG_ENDIAN
+
+ *val = data[start + 1] | (uint16_t)data[start] << 8;
+
+#else
+
+# error "TODO : extra byte order !"
+
+#endif
+
+ break;
+
+ case SRE_MIDDLE:
+ assert(false); /* TODO */
+ break;
+
+ case SRE_BIG:
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+
+ *val = data[start + 1] | (uint16_t)data[start] << 8;
+
+#elif __BYTE_ORDER == __BIG_ENDIAN
+
+ *val = data[start] | (uint16_t)data[start + 1] << 8;
+
+#else
+
+# error "TODO : extra byte order !"
+
+#endif
+
+ break;
+
+
+ }
+
+ advance_vmpa(addr, 2);
+
+ return true;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : content = contenu binaire à venir lire. *
+* addr = position de la tête de lecture. *
+* endian = ordre des bits dans la source. *
+* val = lieu d'enregistrement de la lecture. [OUT] *
+* *
+* Description : Lit un nombre non signé sur quatre octets. *
+* *
+* Retour : Bilan de l'opération : true en cas de succès, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_binary_content_read_u32(const GBinContent *content, vmpa2t *addr, SourceEndian endian, uint32_t *val)
+{
+ phys_t start; /* Tête de lecture relative */
+ const binary_part *part; /* Zone de mémoire effective */
+ bin_t *data; /* Contenu binaire représenté */
+
+ part = g_binary_content_find_part(content, addr, &start);
+ if (part == NULL) return false;
+
+ if ((get_mrange_length(&part->range) - start) < 4) return false;
+
+ data = part->data;
+
+ switch (endian)
+ {
+ case SRE_LITTLE:
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+
+ *val = data[start] | (uint32_t)data[start + 1] << 8;
+ *val |= data[start + 2] << 16 | (uint32_t)data[start + 3] << 24;
+
+#elif __BYTE_ORDER == __BIG_ENDIAN
+
+ *val = data[start + 3] | (uint32_t)data[start + 2] << 8;
+ *val |= data[start + 1] << 16 | (uint32_t)data[start] << 24;
+
+#else
+
+# error "TODO : extra byte order !"
+
+#endif
+
+ break;
+
+ case SRE_MIDDLE:
+ assert(false); /* TODO */
+ break;
+
+ case SRE_BIG:
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+
+ *val = data[start + 3] | (uint32_t)data[start + 2] << 8;
+ *val |= data[start + 1] << 16 | (uint32_t)data[start] << 24;
+
+#elif __BYTE_ORDER == __BIG_ENDIAN
+
+ *val = data[start] | (uint32_t)data[start + 1] << 8;
+ *val |= data[start + 2] << 16 | (uint32_t)data[start + 3] << 24;
+
+#else
+
+# error "TODO : extra byte order !"
+
+#endif
+
+ break;
+
+
+ }
+
+ advance_vmpa(addr, 4);
return true;
}
+/******************************************************************************
+* *
+* Paramètres : content = contenu binaire à venir lire. *
+* addr = position de la tête de lecture. *
+* endian = ordre des bits dans la source. *
+* val = lieu d'enregistrement de la lecture. [OUT] *
+* *
+* Description : Lit un nombre non signé sur huit octets. *
+* *
+* Retour : Bilan de l'opération : true en cas de succès, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool g_binary_content_read_u64(const GBinContent *content, vmpa2t *addr, SourceEndian endian, uint64_t *val)
+{
+ phys_t start; /* Tête de lecture relative */
+ const binary_part *part; /* Zone de mémoire effective */
+ bin_t *data; /* Contenu binaire représenté */
+
+ part = g_binary_content_find_part(content, addr, &start);
+ if (part == NULL) return false;
+
+ if ((get_mrange_length(&part->range) - start) < 8) return false;
+ data = part->data;
+ switch (endian)
+ {
+ case SRE_LITTLE:
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+
+ *val = (uint64_t)data[start] | (uint64_t)data[start + 1] << 8;
+ *val |= (uint64_t)data[start + 2] << 16 | (uint64_t)data[start + 3] << 24;
+ *val |= (uint64_t)data[start + 4] << 32 | (uint64_t)data[start + 5] << 40;
+ *val |= (uint64_t)data[start + 6] << 48 | (uint64_t)data[start + 7] << 56;
+
+#elif __BYTE_ORDER == __BIG_ENDIAN
+
+ *val = (uint64_t)data[start + 7] | (uint64_t)data[start + 6] << 8;
+ *val |= (uint64_t)data[start + 5] << 16 | (uint64_t)data[start + 4] << 24;
+ *val |= (uint64_t)data[start + 3] << 32 | (uint64_t)data[start + 2] << 40;
+ *val |= (uint64_t)data[start + 1] << 48 | (uint64_t)data[start] << 56;
+
+#else
+
+# error "TODO : extra byte order !"
+
+#endif
+
+ break;
+
+ case SRE_MIDDLE:
+ assert(false); /* TODO */
+ break;
+
+ case SRE_BIG:
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+
+ *val = (uint64_t)data[start + 7] | (uint64_t)data[start + 6] << 8;
+ *val |= (uint64_t)data[start + 5] << 16 | (uint64_t)data[start + 4] << 24;
+ *val |= (uint64_t)data[start + 3] << 32 | (uint64_t)data[start + 2] << 40;
+ *val |= (uint64_t)data[start + 1] << 48 | (uint64_t)data[start] << 56;
+
+#elif __BYTE_ORDER == __BIG_ENDIAN
+
+ *val = (uint64_t)data[start] | (uint64_t)data[start + 1] << 8;
+ *val |= (uint64_t)data[start + 2] << 16 | (uint64_t)data[start + 3] << 24;
+ *val |= (uint64_t)data[start + 4] << 32 | (uint64_t)data[start + 5] << 40;
+ *val |= (uint64_t)data[start + 6] << 48 | (uint64_t)data[start + 7] << 56;
+
+#else
+
+# error "TODO : extra byte order !"
+
+#endif
+
+ break;
+
+
+ }
+
+ advance_vmpa(addr, 8);
+
+ return true;
+
+}
diff --git a/src/glibext/gbincontent.h b/src/glibext/gbincontent.h
index 1bfcfa5..e2f5933 100644
--- a/src/glibext/gbincontent.h
+++ b/src/glibext/gbincontent.h
@@ -59,10 +59,33 @@ GBinContent *g_binary_content_new_from_file(const char *);
/* Fournit une portion des données représentées. */
-bool g_binary_content_get_raw(const GBinContent *, const vmpa2t *, phys_t, bin_t *);
+bool g_binary_content_get_raw(const GBinContent *, vmpa2t *, phys_t, bin_t *);
+/* Lit un nombre non signé sur quatre bits. */
+bool g_binary_content_read_u4(const GBinContent *, vmpa2t *, bool *, SourceEndian, uint8_t *);
+
+/* Lit un nombre non signé sur un octet. */
+bool g_binary_content_read_u8(const GBinContent *, vmpa2t *, SourceEndian, uint8_t *);
+
+/* Lit un nombre non signé sur deux octets. */
+bool g_binary_content_read_u16(const GBinContent *, vmpa2t *, SourceEndian, uint16_t *);
+
+/* Lit un nombre non signé sur quatre octets. */
+bool g_binary_content_read_u32(const GBinContent *, vmpa2t *, SourceEndian, uint32_t *);
+
+/* Lit un nombre non signé sur huit octets. */
+bool g_binary_content_read_u64(const GBinContent *, vmpa2t *, SourceEndian, uint64_t *);
+
+
+#define g_binary_content_read_s4(c, a, l, e, v) g_binary_content_read_u4(c, a, l, e, (uint8_t *)v)
+#define g_binary_content_read_s8(c, a, e, v) g_binary_content_read_u8(c, a, e, (uint8_t *)v)
+#define g_binary_content_read_s16(c, a, e, v) g_binary_content_read_u16(c, a, e, (uint16_t *)v)
+#define g_binary_content_read_s32(c, a, e, v) g_binary_content_read_u32(c, a, e, (uint32_t *)v)
+#define g_binary_content_read_s64(c, a, e, v) g_binary_content_read_u64(c, a, e, (uint64_t *)v)
+
+
const bin_t *g_binary_content_get(GBinContent *content, off_t *length);
diff --git a/src/plugins/plugin-def.h b/src/plugins/plugin-def.h
index d1a13b7..edab3a5 100644
--- a/src/plugins/plugin-def.h
+++ b/src/plugins/plugin-def.h
@@ -69,14 +69,15 @@ typedef uint32_t plugin_action_t;
#define MASK_PLUGIN_SUB_CATEGORY(val) (val & (0xff << 16))
-#define DPC_NONE DEFINE_PLUGIN_CATEGORY(0)
+#define DPC_BASIC DEFINE_PLUGIN_CATEGORY(0)
#define DPC_BINARY_PROCESSING DEFINE_PLUGIN_CATEGORY(1)
// GUI
-/* DPC_NONE */
+/* DPC_BASIC */
#define DPS_NONE DEFINE_PLUGIN_SUB_CATEGORY(0)
+#define DPS_PG_MANAGEMENT DEFINE_PLUGIN_SUB_CATEGORY(1)
/* DPC_BINARY_PROCESSING */
@@ -94,8 +95,22 @@ typedef uint32_t plugin_action_t;
/* Action(s) menée(s) par un greffon */
typedef enum _PluginAction
{
+ /**
+ * DPC_BASIC | DPS_NONE
+ */
+
/* Aucun intérêt */
- PGA_NONE = DPC_NONE | DPS_NONE | DEFINE_PLUGIN_ACTION(0),
+ PGA_BASIC_NONE = DPC_BASIC | DPS_NONE | DEFINE_PLUGIN_ACTION(0),
+
+ /**
+ * DPC_BASIC | DPS_NONE
+ */
+
+ /* Chargement */
+ PGA_PLUGIN_INIT = DPC_BASIC | DPS_PG_MANAGEMENT | DEFINE_PLUGIN_ACTION(0),
+
+ /* Déchargement */
+ PGA_PLUGIN_EXIT = DPC_BASIC | DPS_PG_MANAGEMENT | DEFINE_PLUGIN_ACTION(1),
/**
* DPC_BINARY_PROCESSING | DPS_FORMAT
diff --git a/src/plugins/plugin-int.h b/src/plugins/plugin-int.h
index 7a3fb3e..1bf459c 100644
--- a/src/plugins/plugin-int.h
+++ b/src/plugins/plugin-int.h
@@ -26,14 +26,18 @@
#include <glib-object.h>
+#include <stdbool.h>
#include "plugin.h"
#include "plugin-def.h"
+#include "../glibext/gbincontent.h"
#include "../gui/panels/log.h"
+/* Prend acte du [dé]chargement du greffon. */
+typedef bool (* pg_management_fc) (GPluginModule *);
/* Indique si le format peut être pris en charge ici. */
typedef bool (* pg_format_is_matching) (const GPluginModule *, GBinContent **);
@@ -78,14 +82,16 @@ struct _GPluginModule
const plugin_interface *interface; /* Déclaration d'interfaçage */
+ pg_management_fc init; /* Procédure d'initialisation */
+ pg_management_fc exit; /* Procédure d'extinction */
//char *name; /* Nom associé au greffon */
//PluginType type; /* Type(s) du greffon */
- init_plugin_fc init; /* Procédure d'initialisation */
- exit_plugin_fc exit; /* Procédure d'extinction */
+ //init_plugin_fc init; /* Procédure d'initialisation */
+ //exit_plugin_fc exit; /* Procédure d'extinction */
get_plugin_action_fc get_action; /* Opération(s) menée(s) */
//is_matching_fc is_matching; /* Recherche de correspondance */
diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c
index fd55f8c..0ca19e4 100644
--- a/src/plugins/plugin.c
+++ b/src/plugins/plugin.c
@@ -222,13 +222,25 @@ GPluginModule *g_plugin_module_new(const gchar *filename)
switch (category)
{
- case DPC_NONE:
+ case DPC_BASIC:
switch (sub)
{
case DPS_NONE:
break;
+ case PGA_PLUGIN_INIT:
+ if (!load_plugin_symbol(result->module,
+ "chrysalide_plugin_init", &result->init))
+ goto bad_plugin;
+ break;
+
+ case PGA_PLUGIN_EXIT:
+ if (!load_plugin_symbol(result->module,
+ "chrysalide_plugin_exit", &result->exit))
+ goto bad_plugin;
+ break;
+
default:
log_variadic_message(LMT_WARNING,
_("Unknown sub-category '0x%02x' in plugin '%s'..."), sub, filename);
@@ -269,27 +281,21 @@ GPluginModule *g_plugin_module_new(const gchar *filename)
}
-
-
-
-
- /*
- if (!g_module_symbol(result->module, "init_plugin", (gpointer *)&result->init))
- result->init = NULL;
-
- if (!g_module_symbol(result->module, "exit_plugin", (gpointer *)&result->exit))
- result->exit = NULL;
- */
-
-
-
-
-
/* Conclusion */
dir = strdup(filename);
dir = dirname(dir);
+ if (result->init != NULL)
+ {
+ if (!result->init(result))
+ {
+ log_variadic_message(LMT_ERROR,
+ _("Plugin '%s' failed to load itself..."), filename);
+ goto bad_plugin;
+ }
+ }
+
log_variadic_message(LMT_PROCESS, _("Loaded the '<b>%s</b>' from the '<b>%s</b>' directory"),
strrchr(filename, G_DIR_SEPARATOR) + 1, dir);