summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/analysis/disass/disassembler.c7
-rw-r--r--src/analysis/disass/fetch.c128
-rw-r--r--src/analysis/disass/fetch.h6
-rw-r--r--src/arch/Makefile.am1
-rw-r--r--src/arch/archbase.h26
-rw-r--r--src/arch/immediate.c544
-rw-r--r--src/arch/immediate.h25
-rw-r--r--src/arch/instruction-int.h1
-rw-r--r--src/arch/instruction.c30
-rw-r--r--src/arch/instruction.h9
-rw-r--r--src/arch/raw.c246
-rw-r--r--src/arch/raw.h60
-rw-r--r--src/editor.c2
-rw-r--r--src/format/elf/elf-int.c56
-rw-r--r--src/format/elf/elf-int.h2
-rw-r--r--src/format/elf/elf.c2
-rw-r--r--src/format/elf/helper_x86.c4
-rw-r--r--src/format/elf/strings.c2
-rw-r--r--src/format/elf/symbols.c4
-rw-r--r--src/format/format.c3
-rw-r--r--src/format/symbol.c64
-rw-r--r--src/format/symbol.h12
22 files changed, 926 insertions, 308 deletions
diff --git a/src/analysis/disass/disassembler.c b/src/analysis/disass/disassembler.c
index 9344089..e20429c 100644
--- a/src/analysis/disass/disassembler.c
+++ b/src/analysis/disass/disassembler.c
@@ -243,7 +243,12 @@ static void g_delayed_disassembly_process(GDelayedDisassembly *disass, GtkExtSta
ustart += usage.ru_stime.tv_sec * 1000000 + usage.ru_stime.tv_usec;
- *disass->instrs = load_raw_binary(disass->binary, &base, 100, statusbar, id);
+ //*disass->instrs = load_raw_binary(disass->binary, &base, 314744/*100*/, statusbar, id);
+
+
+ *disass->instrs = disassemble_binary_content(disass->binary, statusbar, id);
+
+
/*
*disass->instrs = disassemble_binary_parts(disass->binary, disass->parts, disass->count,
diff --git a/src/analysis/disass/fetch.c b/src/analysis/disass/fetch.c
index 1f93465..9ef6f29 100644
--- a/src/analysis/disass/fetch.c
+++ b/src/analysis/disass/fetch.c
@@ -29,6 +29,15 @@
+#include "../../arch/raw.h"
+#include "../../arch/instruction-int.h"
+
+
+
+
+
+
+
@@ -77,7 +86,9 @@ GArchInstruction *load_raw_binary(const GLoadedBinary *binary, const vmpa2t *bas
while (old_phy < end)
{
- instr = g_db_instruction_new_from_data(bin_data, &pos, end, proc);
+ instr = g_raw_instruction_new_array(bin_data, MDS_32_BITS, 1, &pos, end,
+ g_arch_processor_get_endianness(proc));
+ if (instr == NULL) printf(" Break !!!\n");
if (instr == NULL) break;
new_phy = get_phy_addr(&pos);
@@ -102,26 +113,141 @@ GArchInstruction *load_raw_binary(const GLoadedBinary *binary, const vmpa2t *bas
+/******************************************************************************
+* *
+* Paramètres : binary = représentation de binaire chargé. *
+* statusbar = barre de statut avec progression à mettre à jour.*
+* id = identifiant du message affiché à l'utilisateur. *
+* *
+* Description : Procède au désassemblage basique d'un contenu binaire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+GArchInstruction *disassemble_binary_content(const GLoadedBinary *binary, GtkExtStatusBar *statusbar, bstatus_id_t id)
+{
+ GArchInstruction *result; /* Instruction désassemblées */
+ GBinFormat *format; /* Format du fichier binaire */
+
+
+
+ GBinSymbol **symbols; /* Symboles à représenter */
+ size_t sym_count; /* Qté de symboles présents */
+
+
+ size_t i; /* Boucle de parcours */
+
+ GArchInstruction *instr; /* Instruction à insérer */
+
+
+ vmpa2t *last; /* Dernière bordure rencontrée */
+
+ const vmpa2t *border; /* Nouvelle bordure rencontrée */
+ off_t length; /* Taille d'une partie traitée */
+ GArchInstruction *joint; /* Jointure entre deux lots */
+ off_t max_length; /* Taille des données à lire */
+ result = NULL;
+
+
+
+ format = G_BIN_FORMAT(g_loaded_binary_get_format(binary));
+ last = make_vmpa(0, VMPA_NO_VIRTUAL);
+ symbols = g_binary_format_get_symbols(format, &sym_count);
+
+
+ //sym_count = 0;
+
+
+ for (i = 0; i < sym_count; i++)
+ {
+ switch (g_binary_symbol_get_target_type(symbols[i]))
+ {
+ case STP_DATA:
+ instr = g_binary_symbol_get_instruction(symbols[i]);
+ g_object_ref(G_OBJECT(instr));
+ border = g_arch_instruction_get_location2(instr, &length);
+
+ length = 4;
+
+
+ break;
+
+ }
+
+ /* Traiter la diff */
+
+ if (cmp_vmpa_by_phy(last, border) < 0)
+ {
+ joint = load_raw_binary(binary, last,
+ get_phy_addr(last) + compute_vmpa_diff(border, last),
+ statusbar, id);
+
+ ainstr_list_merge(&result, &joint);
+
+ }
+
+ /* Ajout des instructions déjà établies */
+
+ ainstr_list_merge(&result, &instr);
+
+ /* Marquage de la nouvelle dernière bordure */
+
+ copy_vmpa(last, border);
+
+ advance_vmpa(last, length);
+
+ printf("length :: %d\n", length);
+
+ }
+
+ /* Raccord final ? */
+
+ g_loaded_binary_get_data(binary, &max_length);
+
+ if (get_phy_addr(last) < max_length)
+ {
+ joint = load_raw_binary(binary, last, max_length, statusbar, id);
+ ainstr_list_merge(&result, &joint);
+ }
+
+
+
+
+ printf("COUNT :: %zu\n", sym_count);
+
+ //exit(0);
+
+
+ return result;
+
+
+
+}
+
+
+
diff --git a/src/analysis/disass/fetch.h b/src/analysis/disass/fetch.h
index ff62ce8..b9b3bb4 100644
--- a/src/analysis/disass/fetch.h
+++ b/src/analysis/disass/fetch.h
@@ -38,6 +38,12 @@ GArchInstruction *load_raw_binary(const GLoadedBinary *binary, const vmpa2t *bas
/* Procède au désassemblage basique d'un contenu binaire. */
+GArchInstruction *disassemble_binary_content(const GLoadedBinary *, GtkExtStatusBar *, bstatus_id_t);
+
+
+
+
+/* Procède au désassemblage basique d'un contenu binaire. */
GArchInstruction *disassemble_binary_parts(const GLoadedBinary *, GBinPart **, size_t, GtkExtStatusBar *, bstatus_id_t);
diff --git a/src/arch/Makefile.am b/src/arch/Makefile.am
index e87247e..7dd51b9 100644
--- a/src/arch/Makefile.am
+++ b/src/arch/Makefile.am
@@ -13,6 +13,7 @@ libarch_la_SOURCES = \
operand.h operand.c \
processor-int.h \
processor.h processor.c \
+ raw.h raw.c \
register-int.h \
register.h register.c \
translate.h \
diff --git a/src/arch/archbase.h b/src/arch/archbase.h
index 1a8b507..24cfd77 100644
--- a/src/arch/archbase.h
+++ b/src/arch/archbase.h
@@ -55,21 +55,25 @@ typedef enum _MemoryDataSize
{
MDS_UNDEFINED, /* Taille non définie */
- MDS_4_BITS_UNSIGNED, /* Opérande sur 4 bits n.-s. */
- MDS_8_BITS_UNSIGNED, /* Opérande sur 8 bits n.-s. */
- MDS_16_BITS_UNSIGNED, /* Opérande sur 16 bits n.-s. */
- MDS_32_BITS_UNSIGNED, /* Opérande sur 32 bits n.-s. */
- MDS_64_BITS_UNSIGNED, /* Opérande sur 64 bits n.-s. */
-
- MDS_4_BITS_SIGNED, /* Opérande sur 4 bits signés */
- MDS_8_BITS_SIGNED, /* Opérande sur 8 bits signés */
- MDS_16_BITS_SIGNED, /* Opérande sur 16 bits signés */
- MDS_32_BITS_SIGNED, /* Opérande sur 32 bits signés */
- MDS_64_BITS_SIGNED /* Opérande sur 64 bits signés */
+ MDS_4_BITS_UNSIGNED = 0x01, /* Opérande sur 4 bits n.-s. */
+ MDS_8_BITS_UNSIGNED = 0x02, /* Opérande sur 8 bits n.-s. */
+ MDS_16_BITS_UNSIGNED = 0x03, /* Opérande sur 16 bits n.-s. */
+ MDS_32_BITS_UNSIGNED = 0x04, /* Opérande sur 32 bits n.-s. */
+ MDS_64_BITS_UNSIGNED = 0x05, /* Opérande sur 64 bits n.-s. */
+
+ MDS_4_BITS_SIGNED = 0x81, /* Opérande sur 4 bits signés */
+ MDS_8_BITS_SIGNED = 0x82, /* Opérande sur 8 bits signés */
+ MDS_16_BITS_SIGNED = 0x83, /* Opérande sur 16 bits signés */
+ MDS_32_BITS_SIGNED = 0x84, /* Opérande sur 32 bits signés */
+ MDS_64_BITS_SIGNED = 0x85 /* Opérande sur 64 bits signés */
} MemoryDataSize;
+#define MDS_RANGE(mds) ((mds & 0xf) - 1)
+#define MDS_IS_SIGNED(mds) (mds & 0x80)
+
+
#define MDS_4_BITS MDS_4_BITS_UNSIGNED
#define MDS_8_BITS MDS_8_BITS_UNSIGNED
#define MDS_16_BITS MDS_16_BITS_UNSIGNED
diff --git a/src/arch/immediate.c b/src/arch/immediate.c
index 46abe62..88a0f4b 100644
--- a/src/arch/immediate.c
+++ b/src/arch/immediate.c
@@ -69,6 +69,7 @@ struct _GImmOperand
} signed_imm;
bool zpad; /* Ajoute des 0 à l'impression */
+ ImmOperandDisplay display; /* Format général d'affichage */
};
@@ -139,6 +140,7 @@ static void g_imm_operand_init(GImmOperand *operand)
arch->print = (operand_print_fc)g_imm_operand_print;
operand->zpad = false;
+ operand->display = IOD_HEX;
}
@@ -237,6 +239,110 @@ GArchOperand *_g_imm_operand_new_from_data(MemoryDataSize size, const bin_t *dat
}
+
+
+
+/******************************************************************************
+* *
+* Paramètres : size = taille de l'opérande souhaitée. *
+* data = flux de données à analyser. *
+* addr = position courante dans ce flux. [OUT] *
+* end = limite des données à analyser. *
+* 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_data2(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 */
+ off_t pos; /* Position physique */
+
+ result = g_object_new(G_TYPE_IMM_OPERAND, NULL);
+
+ result->size = size;
+
+ pos = get_phy_addr(addr);
+ old = pos;
+
+ switch (size)
+ {
+ case MDS_4_BITS_UNSIGNED:
+ if (!read_u4(&result->unsigned_imm.val8, data, &pos, end, low, endian))
+ goto gionfd_error;
+ break;
+
+ case MDS_8_BITS_UNSIGNED:
+ if (!read_u8(&result->unsigned_imm.val8, data, &pos, end, endian))
+ goto gionfd_error;
+ break;
+
+ case MDS_16_BITS_UNSIGNED:
+ if (!read_u16(&result->unsigned_imm.val16, data, &pos, end, endian))
+ goto gionfd_error;
+ break;
+
+ case MDS_32_BITS_UNSIGNED:
+ if (!read_u32(&result->unsigned_imm.val32, data, &pos, end, endian))
+ goto gionfd_error;
+ break;
+
+ case MDS_64_BITS_UNSIGNED:
+ if (!read_u64(&result->unsigned_imm.val64, data, &pos, end, endian))
+ goto gionfd_error;
+ break;
+
+ case MDS_4_BITS_SIGNED:
+ if (!read_s4(&result->signed_imm.val8, data, &pos, end, low, endian))
+ goto gionfd_error;
+ break;
+
+ case MDS_8_BITS_SIGNED:
+ if (!read_s8(&result->signed_imm.val8, data, &pos, end, endian))
+ goto gionfd_error;
+ break;
+
+ case MDS_16_BITS_SIGNED:
+ if (!read_s16(&result->signed_imm.val16, data, &pos, end, endian))
+ goto gionfd_error;
+ break;
+
+ case MDS_32_BITS_SIGNED:
+ if (!read_s32(&result->signed_imm.val32, data, &pos, end, endian))
+ goto gionfd_error;
+ break;
+
+ case MDS_64_BITS_SIGNED:
+ if (!read_s64(&result->signed_imm.val64, data, &pos, end, endian))
+ goto gionfd_error;
+ break;
+
+ case MDS_UNDEFINED:
+ goto gionfd_error;
+ break;
+
+ }
+
+ advance_vmpa(addr, pos - old);
+
+ 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. *
@@ -321,7 +427,27 @@ GArchOperand *g_imm_operand_new_from_value(MemoryDataSize size, ...)
/******************************************************************************
* *
-* Paramètres : state = true si des zéro sont à ajouter, false sinon. *
+* Paramètres : operand = structure dont le contenu est à consulter. *
+* *
+* Description : Renseigne la taille de la valeur indiquée à la construction. *
+* *
+* Retour : Taille de la valeur représentée en mémoire. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+MemoryDataSize g_imm_operand_get_size(const GImmOperand *operand)
+{
+ return operand->size;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = structure dont le contenu est à définir. *
+* state = true si des zéro sont à ajouter, false sinon. *
* *
* Description : Précise si des zéro doivent compléter l'affichage ou non. *
* *
@@ -340,7 +466,7 @@ void g_imm_operand_pad(GImmOperand *operand, bool state)
/******************************************************************************
* *
-* Paramètres : operand = structure dont le contenu est à définir. *
+* Paramètres : operand = structure dont le contenu est à consulter. *
* *
* Description : Indique le signe d'une valeur immédiate. *
* *
@@ -359,6 +485,45 @@ bool g_imm_operand_does_padding(const GImmOperand *operand)
/******************************************************************************
* *
+* Paramètres : operand = structure dont le contenu est à définir. *
+* display = format global d'un affichage de valeur. *
+* *
+* Description : Définit la grande ligne du format textuel de la valeur. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_imm_operand_set_display(GImmOperand *operand, ImmOperandDisplay display)
+{
+ operand->display = display;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : operand = structure dont le contenu est à consulter. *
+* *
+* Description : Indique la grande ligne du format textuel de la valeur. *
+* *
+* Retour : Format global d'un affichage de valeur. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+ImmOperandDisplay g_imm_operand_get_display(const GImmOperand *operand)
+{
+ return operand->display;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : operand = structure dont le contenu est à consulter. *
* *
* Description : Indique le signe d'une valeur immédiate. *
@@ -475,288 +640,105 @@ bool g_imm_operand_is_null(const GImmOperand *operand)
static size_t g_imm_operand_to_string(const GImmOperand *operand, AsmSyntax syntax, char value[VMPA_MAX_SIZE])
{
size_t result; /* Longueur à retourner */
+ unsigned int range; /* Catégorie de la taille */
+ const char *prefix; /* Entrée en matière */
+ const char *suffix; /* Sortie de matière */
+ const char *alternate; /* Préfixe de forme alternative*/
+ const char *zpad; /* Remplissage par des zéros */
+ const char *lmod; /* Modification de longueur */
+ const char *conv; /* Opérateur de conversion */
+ char format[16]; /* Format d'impression final */
+
+ static const char *zpad_defs[] = { "", "02", "04", "08", "016" };
+ static const char *lmod_defs[] = { "hh", "hh", "h", "", __PRI64_PREFIX };
+ static const char *conv_si_defs[] = { "c", "d", "x", "o" };
+ static const char *conv_us_defs[] = { "c", "u", "x", "o" };
+
+ result = 0; /* Gcc... */
+
+ range = MDS_RANGE(operand->size);
+
+ /* Encadrement pour les caractères */
+ if (operand->display == IOD_CHAR)
+ {
+ prefix = (syntax == ASX_ATT ? "$'" : "'");
+ suffix = "'";
+ }
+ else
+ {
+ prefix = (syntax == ASX_ATT ? "$" : "");
+ suffix = "";
+ }
+
+ /* Préfix de forme '0x' ou '0' */
+ if (operand->display == IOD_HEX)
+ alternate = "0x";
+ else if (operand->display == IOD_OCT)
+ alternate = "0";
+ else
+ alternate = "";
+
+ /* Drapeau de remplissage ? */
+ if (operand->display == IOD_HEX)
+ zpad = (operand->zpad ? zpad_defs[range] : "");
+ else
+ zpad = "";
+
+ /* Modification de la longueur fournie */
+ lmod = lmod_defs[range];
- /* Pour gcc (Debian 4.4.5-8) 4.4.5 */
- result = 0;
+ /* Spécification de la conversion */
+ if (MDS_IS_SIGNED(operand->size))
+ conv = conv_si_defs[operand->display];
+ else
+ conv = conv_us_defs[operand->display];
- switch (syntax)
+ snprintf(format, sizeof(format), "%s%s%%%s%s%s%s", prefix, alternate, zpad, lmod, conv, suffix);
+
+ switch (operand->size)
{
- case ASX_INTEL:
- switch (operand->size)
- {
- case MDS_UNDEFINED:
- result = snprintf(value, VMPA_MAX_SIZE, "0x???");
- break;
-
- case MDS_4_BITS_UNSIGNED:
- result = snprintf(value, VMPA_MAX_SIZE, "0x%hhx", operand->unsigned_imm.val8);
-
- case MDS_8_BITS_UNSIGNED:
- if (operand->zpad)
- result = snprintf(value, VMPA_MAX_SIZE, "0x%02hhx", operand->unsigned_imm.val8);
- else
- result = snprintf(value, VMPA_MAX_SIZE, "0x%hhx", operand->unsigned_imm.val8);
- break;
-
- case MDS_16_BITS_UNSIGNED:
- if (operand->zpad)
- result = snprintf(value, VMPA_MAX_SIZE, "0x%04hx", operand->unsigned_imm.val16);
- else
- result = snprintf(value, VMPA_MAX_SIZE, "0x%hx", operand->unsigned_imm.val16);
- break;
-
- case MDS_32_BITS_UNSIGNED:
- if (operand->zpad)
- result = snprintf(value, VMPA_MAX_SIZE, "0x%08x", operand->unsigned_imm.val32);
- else
- result = snprintf(value, VMPA_MAX_SIZE, "0x%x", operand->unsigned_imm.val32);
- break;
-
- case MDS_64_BITS_UNSIGNED:
- if (operand->zpad)
- result = snprintf(value, VMPA_MAX_SIZE, "0x%016" PRIx64, operand->unsigned_imm.val64);
- else
- result = snprintf(value, VMPA_MAX_SIZE, "0x%" PRIx64, operand->unsigned_imm.val64);
- break;
-
- case MDS_4_BITS_SIGNED:
- if (g_imm_operand_is_negative(operand))
- result = snprintf(value, VMPA_MAX_SIZE, "0x%hhx", ~operand->signed_imm.val8 + 1);
- else
- result = snprintf(value, VMPA_MAX_SIZE, "0x%hhx", operand->signed_imm.val8);
- break;
-
- case MDS_8_BITS_SIGNED:
- if (operand->zpad)
- {
- if (g_imm_operand_is_negative(operand))
- result = snprintf(value, VMPA_MAX_SIZE, "0x%02hhx", ~operand->signed_imm.val8 + 1);
- else
- result = snprintf(value, VMPA_MAX_SIZE, "0x%02hhx", operand->signed_imm.val8);
- }
- else
- {
- if (g_imm_operand_is_negative(operand))
- result = snprintf(value, VMPA_MAX_SIZE, "0x%hhx", ~operand->signed_imm.val8 + 1);
- else
- result = snprintf(value, VMPA_MAX_SIZE, "0x%hhx", operand->signed_imm.val8);
- }
- break;
-
- case MDS_16_BITS_SIGNED:
- if (operand->zpad)
- {
- if (g_imm_operand_is_negative(operand))
- result = snprintf(value, VMPA_MAX_SIZE, "0x%04hx", ~operand->signed_imm.val16 + 1);
- else
- result = snprintf(value, VMPA_MAX_SIZE, "0x%04hx", operand->signed_imm.val16);
- }
- else
- {
- if (g_imm_operand_is_negative(operand))
- result = snprintf(value, VMPA_MAX_SIZE, "0x%hx", ~operand->signed_imm.val16 + 1);
- else
- result = snprintf(value, VMPA_MAX_SIZE, "0x%hx", operand->signed_imm.val16);
- }
- break;
-
- case MDS_32_BITS_SIGNED:
- if (operand->zpad)
- {
- if (g_imm_operand_is_negative(operand))
- result = snprintf(value, VMPA_MAX_SIZE, "0x%08x", ~operand->signed_imm.val32 + 1);
- else
- result = snprintf(value, VMPA_MAX_SIZE, "0x%08x", operand->signed_imm.val32);
- }
- else
- {
- if (g_imm_operand_is_negative(operand))
- result = snprintf(value, VMPA_MAX_SIZE, "0x%x", ~operand->signed_imm.val32 + 1);
- else
- result = snprintf(value, VMPA_MAX_SIZE, "0x%x", operand->signed_imm.val32);
- }
- break;
-
- case MDS_64_BITS_SIGNED:
- if (operand->zpad)
- {
- if (g_imm_operand_is_negative(operand))
- result = snprintf(value, VMPA_MAX_SIZE, "0x%016" PRIx64, ~operand->signed_imm.val64 + 1);
- else
- result = snprintf(value, VMPA_MAX_SIZE, "0x%016" PRIx64, operand->signed_imm.val64);
- }
- else
- {
- if (g_imm_operand_is_negative(operand))
- result = snprintf(value, VMPA_MAX_SIZE, "0x%" PRIx64, ~operand->signed_imm.val64 + 1);
- else
- result = snprintf(value, VMPA_MAX_SIZE, "0x%" PRIx64, operand->signed_imm.val64);
- }
- break;
- }
- break;
-
- case ASX_ATT:
- switch (operand->size)
- {
- case MDS_UNDEFINED:
- result = snprintf(value, VMPA_MAX_SIZE, "$0x???");
- break;
-
- case MDS_4_BITS_UNSIGNED:
- result = snprintf(value, VMPA_MAX_SIZE, "$0x%hhx", operand->unsigned_imm.val8);
-
- case MDS_8_BITS_UNSIGNED:
- if (operand->zpad)
- result = snprintf(value, VMPA_MAX_SIZE, "$0x%02hhx", operand->unsigned_imm.val8);
- else
- result = snprintf(value, VMPA_MAX_SIZE, "$0x%hhx", operand->unsigned_imm.val8);
- break;
-
- case MDS_16_BITS_UNSIGNED:
- if (operand->zpad)
- result = snprintf(value, VMPA_MAX_SIZE, "$0x%04hx", operand->unsigned_imm.val16);
- else
- result = snprintf(value, VMPA_MAX_SIZE, "$0x%hx", operand->unsigned_imm.val16);
- break;
-
- case MDS_32_BITS_UNSIGNED:
- if (operand->zpad)
- result = snprintf(value, VMPA_MAX_SIZE, "$0x%08x", operand->unsigned_imm.val32);
- else
- result = snprintf(value, VMPA_MAX_SIZE, "$0x%x", operand->unsigned_imm.val32);
- break;
-
- case MDS_64_BITS_UNSIGNED:
- if (operand->zpad)
- result = snprintf(value, VMPA_MAX_SIZE, "$0x%016" PRIx64, operand->unsigned_imm.val64);
- else
- result = snprintf(value, VMPA_MAX_SIZE, "$0x%" PRIx64, operand->unsigned_imm.val64);
- break;
-
- case MDS_4_BITS_SIGNED:
- if (g_imm_operand_is_negative(operand))
- result = snprintf(value, VMPA_MAX_SIZE, "$0x%hhx", ~operand->signed_imm.val8 + 1);
- else
- result = snprintf(value, VMPA_MAX_SIZE, "$0x%hhx", operand->signed_imm.val8);
- break;
-
- case MDS_8_BITS_SIGNED:
- if (operand->zpad)
- {
- if (g_imm_operand_is_negative(operand))
- result = snprintf(value, VMPA_MAX_SIZE, "$0x%02hhx", ~operand->signed_imm.val8 + 1);
- else
- result = snprintf(value, VMPA_MAX_SIZE, "$0x%02hhx", operand->signed_imm.val8);
- }
- else
- {
- if (g_imm_operand_is_negative(operand))
- result = snprintf(value, VMPA_MAX_SIZE, "$0x%hhx", ~operand->signed_imm.val8 + 1);
- else
- result = snprintf(value, VMPA_MAX_SIZE, "$0x%hhx", operand->signed_imm.val8);
- }
- break;
-
- case MDS_16_BITS_SIGNED:
- if (operand->zpad)
- {
- if (g_imm_operand_is_negative(operand))
- result = snprintf(value, VMPA_MAX_SIZE, "$0x%04hx", ~operand->signed_imm.val16 + 1);
- else
- result = snprintf(value, VMPA_MAX_SIZE, "$0x%04hx", operand->signed_imm.val16);
- }
- else
- {
- if (g_imm_operand_is_negative(operand))
- result = snprintf(value, VMPA_MAX_SIZE, "$0x%hx", ~operand->signed_imm.val16 + 1);
- else
- result = snprintf(value, VMPA_MAX_SIZE, "$0x%hx", operand->signed_imm.val16);
- }
- break;
-
- case MDS_32_BITS_SIGNED:
- if (operand->zpad)
- {
- if (g_imm_operand_is_negative(operand))
- result = snprintf(value, VMPA_MAX_SIZE, "$0x%08x", ~operand->signed_imm.val32 + 1);
- else
- result = snprintf(value, VMPA_MAX_SIZE, "$0x%08x", operand->signed_imm.val32);
- }
- else
- {
- if (g_imm_operand_is_negative(operand))
- result = snprintf(value, VMPA_MAX_SIZE, "$0x%x", ~operand->signed_imm.val32 + 1);
- else
- result = snprintf(value, VMPA_MAX_SIZE, "$0x%x", operand->signed_imm.val32);
- }
- break;
-
- case MDS_64_BITS_SIGNED:
- if (operand->zpad)
- {
- if (g_imm_operand_is_negative(operand))
- result = snprintf(value, VMPA_MAX_SIZE, "$0x%016" PRIx64, ~operand->signed_imm.val64 + 1);
- else
- result = snprintf(value, VMPA_MAX_SIZE, "$0x%016" PRIx64, operand->signed_imm.val64);
- }
- else
- {
- if (g_imm_operand_is_negative(operand))
- result = snprintf(value, VMPA_MAX_SIZE, "$0x%" PRIx64, ~operand->signed_imm.val64 + 1);
- else
- result = snprintf(value, VMPA_MAX_SIZE, "$0x%" PRIx64, operand->signed_imm.val64);
- }
- break;
- }
- break;
-
- case ASX_COUNT:
- switch (operand->size)
- {
- case MDS_UNDEFINED:
- result = snprintf(value, VMPA_MAX_SIZE, "0x???");
- break;
-
- case MDS_4_BITS_UNSIGNED:
- result = snprintf(value, VMPA_MAX_SIZE, "%hhu", operand->unsigned_imm.val8);
-
- case MDS_8_BITS_UNSIGNED:
- result = snprintf(value, VMPA_MAX_SIZE, "%hhu", operand->unsigned_imm.val8);
- break;
-
- case MDS_16_BITS_UNSIGNED:
- result = snprintf(value, VMPA_MAX_SIZE, "%hu", operand->unsigned_imm.val16);
- break;
-
- case MDS_32_BITS_UNSIGNED:
- result = snprintf(value, VMPA_MAX_SIZE, "%u", operand->unsigned_imm.val32);
- break;
-
- case MDS_64_BITS_UNSIGNED:
- result = snprintf(value, VMPA_MAX_SIZE, "%" PRIu64, operand->unsigned_imm.val64);
- break;
-
- case MDS_4_BITS_SIGNED:
- result = snprintf(value, VMPA_MAX_SIZE, "%hhd", operand->signed_imm.val8);
- break;
-
- case MDS_8_BITS_SIGNED:
- result = snprintf(value, VMPA_MAX_SIZE, "%hhd", operand->signed_imm.val8);
- break;
-
- case MDS_16_BITS_SIGNED:
- result = snprintf(value, VMPA_MAX_SIZE, "%hd", operand->signed_imm.val16);
- break;
-
- case MDS_32_BITS_SIGNED:
- result = snprintf(value, VMPA_MAX_SIZE, "%d", operand->signed_imm.val32);
- break;
-
- case MDS_64_BITS_SIGNED:
- result = snprintf(value, VMPA_MAX_SIZE, "%" PRId64, operand->signed_imm.val64);
- break;
- }
+ case MDS_UNDEFINED:
+ result = snprintf(value, VMPA_MAX_SIZE, "<? undef value ?>");
+ break;
+
+ case MDS_4_BITS_UNSIGNED:
+ result = snprintf(value, VMPA_MAX_SIZE, format, operand->unsigned_imm.val8);
+ break;
+
+ case MDS_8_BITS_UNSIGNED:
+ result = snprintf(value, VMPA_MAX_SIZE, format, operand->unsigned_imm.val8);
+ break;
+
+ case MDS_16_BITS_UNSIGNED:
+ result = snprintf(value, VMPA_MAX_SIZE, format, operand->unsigned_imm.val16);
+ break;
+
+ case MDS_32_BITS_UNSIGNED:
+ result = snprintf(value, VMPA_MAX_SIZE, format, operand->unsigned_imm.val32);
+ break;
+
+ case MDS_64_BITS_UNSIGNED:
+ result = snprintf(value, VMPA_MAX_SIZE, format, operand->unsigned_imm.val64);
+ break;
+
+ case MDS_4_BITS_SIGNED:
+ result = snprintf(value, VMPA_MAX_SIZE, format, operand->signed_imm.val8);
+ break;
+
+ case MDS_8_BITS_SIGNED:
+ result = snprintf(value, VMPA_MAX_SIZE, format, operand->signed_imm.val8);
+ break;
+
+ case MDS_16_BITS_SIGNED:
+ result = snprintf(value, VMPA_MAX_SIZE, format, operand->signed_imm.val16);
+ break;
+
+ case MDS_32_BITS_SIGNED:
+ result = snprintf(value, VMPA_MAX_SIZE, format, operand->signed_imm.val32);
+ break;
+
+ case MDS_64_BITS_SIGNED:
+ result = snprintf(value, VMPA_MAX_SIZE, format, operand->signed_imm.val64);
break;
}
diff --git a/src/arch/immediate.h b/src/arch/immediate.h
index 01971fd..71d482a 100644
--- a/src/arch/immediate.h
+++ b/src/arch/immediate.h
@@ -35,6 +35,17 @@
+/* Grande ligne d'un format d'affichage */
+typedef enum _ImmOperandDisplay
+{
+ IOD_CHAR,
+ IOD_DEC,
+ IOD_HEX,
+ IOD_OCT
+
+} ImmOperandDisplay;
+
+
#define G_TYPE_IMM_OPERAND g_imm_operand_get_type()
#define G_IMM_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_imm_operand_get_type(), GImmOperand))
#define G_IS_IMM_OPERAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_imm_operand_get_type()))
@@ -57,14 +68,28 @@ GArchOperand *_g_imm_operand_new_from_data(MemoryDataSize, const bin_t *, off_t
#define g_imm_operand_new_from_data(size, data, pos, len, endian) _g_imm_operand_new_from_data(size, data, pos, len, NULL, endian)
/* Crée un opérande réprésentant une valeur numérique. */
+GArchOperand *_g_imm_operand_new_from_data2(MemoryDataSize, const bin_t *, vmpa2t *, off_t, bool *, SourceEndian);
+
+#define g_imm_operand_new_from_data2(size, data, pos, len, endian) _g_imm_operand_new_from_data(size, data, pos, len, NULL, endian)
+
+/* Crée un opérande réprésentant une valeur numérique. */
GArchOperand *g_imm_operand_new_from_value(MemoryDataSize, ...);
+/* Renseigne la taille de la valeur indiquée à la construction. */
+MemoryDataSize g_imm_operand_get_size(const GImmOperand *);
+
/* Précise si des zéro doivent compléter l'affichage ou non. */
void g_imm_operand_pad(GImmOperand *, bool);
/* Indique le signe d'une valeur immédiate. */
bool g_imm_operand_does_padding(const GImmOperand *);
+/* Définit la grande ligne du format textuel de la valeur. */
+void g_imm_operand_set_display(GImmOperand *operand, ImmOperandDisplay display);
+
+/* Indique la grande ligne du format textuel de la valeur. */
+ImmOperandDisplay g_imm_operand_get_display(const GImmOperand *);
+
/* Indique le signe d'une valeur immédiate. */
bool g_imm_operand_is_negative(const GImmOperand *);
diff --git a/src/arch/instruction-int.h b/src/arch/instruction-int.h
index 076eec2..8730792 100644
--- a/src/arch/instruction-int.h
+++ b/src/arch/instruction-int.h
@@ -97,6 +97,7 @@ struct _GArchInstructionClass
#define ainstr_list_prev_iter(iter, head) dl_list_prev_iter(iter, head, GArchInstruction, flow)
#define ainstr_list_next_iter(iter, head) dl_list_next_iter(iter, head, GArchInstruction, flow)
#define ainstr_list_add_tail(new, head) dl_list_add_tail(new, head, GArchInstruction, flow)
+#define ainstr_list_merge(head1, head2) dl_list_merge(head1, head2, GArchInstruction, flow)
#define ainstr_list_for_each(pos, head) dl_list_for_each(pos, head, GArchInstruction, flow)
diff --git a/src/arch/instruction.c b/src/arch/instruction.c
index 3a62a90..95910ba 100644
--- a/src/arch/instruction.c
+++ b/src/arch/instruction.c
@@ -171,6 +171,32 @@ void g_arch_instruction_set_location(GArchInstruction *instr, const vmpa2t *addr
}
+
+/******************************************************************************
+* *
+* Paramètres : instr = instruction quelconque à consulter. *
+* offset = position physique dans le code binaire/NULL. [OUT] *
+* length = taille de l'instruction ou NULL. [OUT] *
+* address = adresse virtuelle ou position physique/NULL. [OUT] *
+* *
+* Description : Fournit la localisation d'une instruction. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+const vmpa2t *g_arch_instruction_get_location2(const GArchInstruction *instr, off_t *length)
+{
+ if (length != NULL) *length = instr->length;
+
+ return &instr->address2;
+
+}
+
+
+
/******************************************************************************
* *
* Paramètres : instr = instruction quelconque à consulter. *
@@ -854,9 +880,13 @@ GArchInstruction *g_arch_instruction_get_next_iter(const GArchInstruction *list,
result = ainstr_list_next_iter(iter, list);
+ /* FIXME : utiliser les nouvelles adresses !
+
if (result != NULL && result->address >= max)
result = NULL;
+ */
+
return result;
}
diff --git a/src/arch/instruction.h b/src/arch/instruction.h
index a059161..08135a9 100644
--- a/src/arch/instruction.h
+++ b/src/arch/instruction.h
@@ -34,7 +34,7 @@
#include "../analysis/type.h"
#include "../decomp/context.h"
#include "../decomp/instruction.h"
-#include "../format/executable.h"
+//#include "../format/executable.h"
@@ -59,6 +59,13 @@ GType g_arch_instruction_get_type(void);
/* Définit la localisation d'une instruction. */
void g_arch_instruction_set_location(GArchInstruction *, const vmpa2t *, off_t);
+
+
+/* Fournit la localisation d'une instruction. */
+const vmpa2t *g_arch_instruction_get_location2(const GArchInstruction *, off_t *);
+
+
+
/* Fournit la localisation d'une instruction. */
void g_arch_instruction_get_location(const GArchInstruction *, off_t *, off_t *, vmpa_t *);
diff --git a/src/arch/raw.c b/src/arch/raw.c
new file mode 100644
index 0000000..0d6ae4a
--- /dev/null
+++ b/src/arch/raw.c
@@ -0,0 +1,246 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * artificial.c - instructions pures vues de l'esprit
+ *
+ * Copyright (C) 2009-2012 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "raw.h"
+
+
+#include "immediate.h"
+#include "instruction-int.h"
+
+
+
+/* ------------------------- INSTRUCTION INCONNUE / DONNEES ------------------------- */
+
+
+/* Définition générique d'une instruction d'architecture inconnue (instance) */
+struct _GRawInstruction
+{
+ GArchInstruction parent; /* A laisser en premier */
+
+};
+
+/* Définition générique d'une instruction d'architecture inconnue (classe) */
+struct _GRawInstructionClass
+{
+ GArchInstructionClass parent; /* A laisser en premier */
+
+};
+
+
+/* Initialise la classe générique des opérandes. */
+static void g_raw_instruction_class_init(GRawInstructionClass *);
+
+/* Initialise une instance d'opérande d'architecture. */
+static void g_raw_instruction_init(GRawInstruction *);
+
+/* Supprime toutes les références externes. */
+static void g_raw_instruction_dispose(GRawInstruction *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_raw_instruction_finalize(GRawInstruction *);
+
+/* Fournit le nom humain de l'instruction manipulée. */
+static const char *g_raw_instruction_get_keyword(const GRawInstruction *, AsmSyntax);
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* INSTRUCTION INCONNUE / DONNEES */
+/* ---------------------------------------------------------------------------------- */
+
+
+/* Indique le type défini pour une instruction inconnue d'architecture. */
+G_DEFINE_TYPE(GRawInstruction, g_raw_instruction, G_TYPE_ARCH_INSTRUCTION);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe générique des opérandes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_raw_instruction_class_init(GRawInstructionClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+ GArchInstructionClass *instr; /* Encore une autre vision... */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_raw_instruction_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_raw_instruction_finalize;
+
+ instr = G_ARCH_INSTRUCTION_CLASS(klass);
+
+ instr->get_key = (get_instruction_keyword_fc)g_raw_instruction_get_keyword;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : instr = instance à initialiser. *
+* *
+* Description : Initialise une instance d'instruction d'architecture. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_raw_instruction_init(GRawInstruction *instr)
+{
+ GArchInstruction *parent; /* Instance parente */
+
+ parent = G_ARCH_INSTRUCTION(instr);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : instr = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_raw_instruction_dispose(GRawInstruction *instr)
+{
+ G_OBJECT_CLASS(g_raw_instruction_parent_class)->dispose(G_OBJECT(instr));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : instr = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_raw_instruction_finalize(GRawInstruction *instr)
+{
+ G_OBJECT_CLASS(g_raw_instruction_parent_class)->finalize(G_OBJECT(instr));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : data = 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] *
+* end = limite des données à analyser. *
+* 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 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 */
+ size_t i; /* Boucle de parcours */
+ GArchOperand *operand; /* Octet non décodé à afficher */
+
+ /* Par soucis de cohérence */
+ if (count == 0) return NULL;
+
+ result = g_object_new(G_TYPE_RAW_INSTRUCTION, NULL);
+
+ old = dup_vmpa(addr);
+
+ for (i = 0; i < count; i++)
+ {
+ operand = g_imm_operand_new_from_data2(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);
+ }
+
+ g_arch_instruction_set_location(result, old, compute_vmpa_diff(addr, old));
+
+ delete_vmpa(old);
+
+ return result;
+
+ grina_error:
+
+ g_object_unref(G_OBJECT(result));
+
+ return NULL;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : instr = instruction à traiter. *
+* format = format du binaire manipulé. *
+* syntax = type de représentation demandée. *
+* *
+* Description : Fournit le nom humain de l'instruction manipulée. *
+* *
+* Retour : Mot clef de bas niveau. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static const char *g_raw_instruction_get_keyword(const GRawInstruction *instr, AsmSyntax syntax)
+{
+ GArchOperand *operand; /* Octet décodé à afficher */
+ MemoryDataSize size; /* Taille de valeur associée */
+
+ static char *defines[] = { "dn", "db", "dw", "dd", "dq" };
+
+ operand = g_arch_instruction_get_operand(instr, 0);
+ size = g_imm_operand_get_size(G_IMM_OPERAND(operand));
+
+ return defines[MDS_RANGE(size)];
+
+}
diff --git a/src/arch/raw.h b/src/arch/raw.h
new file mode 100644
index 0000000..08dc620
--- /dev/null
+++ b/src/arch/raw.h
@@ -0,0 +1,60 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * raw.h - prototypes pour les instructions pures vues de l'esprit
+ *
+ * Copyright (C) 2009-2012 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _ARCH_RAW_H
+#define _ARCH_RAW_H
+
+
+#include <glib-object.h>
+
+
+#include "instruction.h"
+#include "vmpa.h"
+
+
+
+/* ------------------------- INSTRUCTION INCONNUE / DONNEES ------------------------- */
+
+
+#define G_TYPE_RAW_INSTRUCTION g_raw_instruction_get_type()
+#define G_RAW_INSTRUCTION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_raw_instruction_get_type(), GRawInstruction))
+#define G_IS_RAW_INSTRUCTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_raw_instruction_get_type()))
+#define G_RAW_INSTRUCTION_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_raw_instruction_get_type(), GRawInstructionIface))
+
+
+/* Définition générique d'une instruction d'architecture inconnue (instance) */
+typedef struct _GRawInstruction GRawInstruction;
+
+/* Définition générique d'une instruction d'architecture inconnue (classe) */
+typedef struct _GRawInstructionClass GRawInstructionClass;
+
+
+/* Indique le type défini pour une instruction inconnue d'architecture. */
+GType g_raw_instruction_get_type(void);
+
+/* 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);
+
+
+
+#endif /* _ARCH_RAW_H */
diff --git a/src/editor.c b/src/editor.c
index d67c4d0..1c5fbd9 100644
--- a/src/editor.c
+++ b/src/editor.c
@@ -149,7 +149,7 @@ GtkWidget *create_editor(void)
result = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- gtk_widget_set_size_request(result, 800, 600);
+ gtk_widget_set_size_request(result, 1024, 800);
gtk_window_set_position(GTK_WINDOW(result), GTK_WIN_POS_CENTER);
gtk_container_set_border_width(GTK_CONTAINER(result), 4);
gtk_window_set_title(GTK_WINDOW(result), _("Chrysalide"));
diff --git a/src/format/elf/elf-int.c b/src/format/elf/elf-int.c
index 353ae05..17aeaf2 100644
--- a/src/format/elf/elf-int.c
+++ b/src/format/elf/elf-int.c
@@ -27,11 +27,13 @@
#include <string.h>
+#include "../../arch/raw.h"
+
+
/******************************************************************************
* *
-* Paramètres : content = contenu binaire à parcourir. *
-* length = taille du contenu en question. *
+* 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] *
@@ -44,10 +46,27 @@
* *
******************************************************************************/
-bool read_elf_header(const bin_t *content, off_t length, elf_header *header, bool *is_32b, SourceEndian *endian)
+bool read_elf_header(GElfFormat *format, elf_header *header, bool *is_32b, SourceEndian *endian)
{
bool result; /* Bilan à retourner */
+ const bin_t *content; /* Contenu binaire à lire */
+ off_t length; /* Taille totale du contenu */
off_t pos; /* Position de lecture */
+ GArchInstruction *instr; /* Instruction décodée */
+
+
+ vmpa2t *pos2;
+
+
+ GBinSymbol *symbol;
+
+ size_t i; /* Boucle de parcours */
+ GArchOperand *operand; /* Opérande à venir modifier */
+
+
+
+ content = G_BIN_FORMAT(format)->content;
+ length = G_BIN_FORMAT(format)->length;
result = (length >= EI_NIDENT);
@@ -89,6 +108,37 @@ bool read_elf_header(const bin_t *content, off_t length, elf_header *header, boo
break;
}
+
+ pos2 = make_vmpa(0, 0x123);
+
+
+
+ instr = g_raw_instruction_new_array(content, MDS_8_BITS, 4, pos2, 4, *endian);
+
+
+ for (i = 1; i < 4; i++)
+ {
+ operand = g_arch_instruction_get_operand(instr, i);
+ g_imm_operand_set_display(G_IMM_OPERAND(operand), IOD_CHAR);
+ }
+
+
+
+
+ symbol = g_binary_symbol_new(STP_OBJECT, "toto", 0);
+
+ printf("TOTO\n");
+
+ g_binary_symbol_attach_instruction(symbol, instr);
+ g_binary_format_add_symbol(format, symbol);
+
+
+
+
+
+
+
+
if (*is_32b)
{
result &= read_u16(&header->hdr32.e_type, content, &pos, length, *endian);
diff --git a/src/format/elf/elf-int.h b/src/format/elf/elf-int.h
index 77548da..783d27e 100644
--- a/src/format/elf/elf-int.h
+++ b/src/format/elf/elf-int.h
@@ -53,7 +53,7 @@ struct _GElfFormatClass
/* Procède à la lecture de l'en-tête d'un contenu binaire ELF. */
-bool read_elf_header(const bin_t *, off_t, elf_header *, bool *, SourceEndian *);
+bool read_elf_header(GElfFormat *, elf_header *, bool *, SourceEndian *);
/* Procède à la lecture d'une en-tête de programme ELF. */
bool read_elf_program_header(const GElfFormat *, off_t *, elf_phdr *);
diff --git a/src/format/elf/elf.c b/src/format/elf/elf.c
index e618658..4a56c52 100644
--- a/src/format/elf/elf.c
+++ b/src/format/elf/elf.c
@@ -176,7 +176,7 @@ GBinFormat *g_elf_format_new(const bin_t *content, off_t length)
g_binary_format_set_content(G_BIN_FORMAT(result), content, length);
- if (!read_elf_header(content, length, &result->header, &result->is_32b, &result->endian))
+ if (!read_elf_header(result, &result->header, &result->is_32b, &result->endian))
{
/* TODO */
return NULL;
diff --git a/src/format/elf/helper_x86.c b/src/format/elf/helper_x86.c
index 7d85311..d921592 100644
--- a/src/format/elf/helper_x86.c
+++ b/src/format/elf/helper_x86.c
@@ -295,7 +295,7 @@ void translate_exe_elf_relocations(GElfFormat *format, GArchInstruction **instru
g_binary_routine_set_address(routine, address);
- g_binary_format_add_routine(G_BIN_FORMAT(format), routine);
+ ///// reactiver g_binary_format_add_routine(G_BIN_FORMAT(format), routine);
/* Symbole uniquement */
@@ -403,7 +403,7 @@ void translate_dyn_elf_relocations(GElfFormat *format, GArchInstruction **instru
g_binary_routine_set_address(routine, address);
- g_binary_format_add_routine(G_BIN_FORMAT(format), routine);
+ ///// reactiver g_binary_format_add_routine(G_BIN_FORMAT(format), routine);
/* Symbole uniquement */
diff --git a/src/format/elf/strings.c b/src/format/elf/strings.c
index b75c014..09bd442 100644
--- a/src/format/elf/strings.c
+++ b/src/format/elf/strings.c
@@ -174,7 +174,7 @@ bool parse_elf_string_data(GElfFormat *format, off_t start, off_t size, vmpa_t a
symbol = g_binary_symbol_new(STP_STRING, NULL, address + i - start);
g_binary_symbol_set_alt_name(symbol, strndup((const char *)&content[i], end - i));
- g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol);
+ ///// reactiver g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol);
i = end;
result = true;
diff --git a/src/format/elf/symbols.c b/src/format/elf/symbols.c
index 02197a0..c480c51 100644
--- a/src/format/elf/symbols.c
+++ b/src/format/elf/symbols.c
@@ -223,7 +223,7 @@ static bool load_elf_internal_symbols(GElfFormat *format)
g_binary_routine_set_address(routine, ELF_SYM(format, sym, st_value));
g_binary_routine_set_size(routine, ELF_SYM(format, sym, st_size));
- g_binary_format_add_routine(G_BIN_FORMAT(format), routine);
+ ///// reactiver g_binary_format_add_routine(G_BIN_FORMAT(format), routine);
/* Symbole uniquement */
@@ -231,7 +231,7 @@ static bool load_elf_internal_symbols(GElfFormat *format)
g_binary_symbol_attach_routine(symbol, routine);
- g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol);
+ ///// reactiver g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol);
}
diff --git a/src/format/format.c b/src/format/format.c
index 4b5dfb5..8771c46 100644
--- a/src/format/format.c
+++ b/src/format/format.c
@@ -193,6 +193,9 @@ const bin_t *g_binary_format_get_content(const GBinFormat *format, off_t *length
void g_binary_format_add_symbol(GBinFormat *format, GBinSymbol *symbol)
{
+
+ printf("current :: %d (%p)\n", (int)format->symbols_count, format->symbols);
+
format->symbols = (GBinSymbol **)realloc(format->symbols,
++format->symbols_count * sizeof(GBinSymbol *));
diff --git a/src/format/symbol.c b/src/format/symbol.c
index 467bfd2..b478dc7 100644
--- a/src/format/symbol.c
+++ b/src/format/symbol.c
@@ -42,6 +42,7 @@ struct _GBinSymbol
union
{
+ GArchInstruction *instr; /* Instruction correspondante */
GBinRoutine *routine; /* Compléments pour fonction */
} extra;
@@ -178,6 +179,14 @@ const char *g_binary_symbol_to_string(const GBinSymbol *symbol)
}
+vmpa_t g_binary_symbol_get_address(const GBinSymbol *symbol)
+{
+
+ return 0;
+
+}
+
+
/******************************************************************************
* *
* Paramètres : symbol = symbole à venir consulter. *
@@ -190,9 +199,19 @@ const char *g_binary_symbol_to_string(const GBinSymbol *symbol)
* *
******************************************************************************/
-vmpa_t g_binary_symbol_get_address(const GBinSymbol *symbol)
+const vmpa2t *g_binary_symbol_get_address2(const GBinSymbol *symbol)
{
- return symbol->address;
+ const vmpa2t *result; /* Localisation à retourner */
+
+ switch (symbol->type)
+ {
+ case STP_DATA:
+ result = g_arch_instruction_get_location2(symbol->extra.instr, NULL);
+ break;
+
+ }
+
+ return result;
}
@@ -270,3 +289,44 @@ void g_binary_symbol_attach_routine(GBinSymbol *symbol, GBinRoutine *routine)
symbol->extra.routine = routine;
}
+
+
+/******************************************************************************
+* *
+* Paramètres : symbol = symbole à venir consulter. *
+* instr = représentation du symbole associé. *
+* *
+* Description : Attache l'instruction associée au symbole. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_binary_symbol_attach_instruction(GBinSymbol *symbol, GArchInstruction *instr)
+{
+ symbol->type = STP_DATA;
+
+ symbol->extra.instr = instr;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : symbol = symbole à venir consulter. *
+* *
+* Description : Fournit l'éventuelle instruction associée au symbole. *
+* *
+* Retour : - *
+* *
+* Remarques : Il n'y a pas de transfert de propriété ici ! *
+* *
+******************************************************************************/
+
+GArchInstruction *g_binary_symbol_get_instruction(const GBinSymbol *symbol)
+{
+ return symbol->extra.instr;
+
+}
diff --git a/src/format/symbol.h b/src/format/symbol.h
index 7f0cd1c..bfbf541 100644
--- a/src/format/symbol.h
+++ b/src/format/symbol.h
@@ -35,6 +35,7 @@
/* Types de symbole */
typedef enum _SymbolType
{
+ STP_DATA, /* Données brutes */
STP_OBJECT, /* Objet quelconque */
STP_FUNCTION, /* Simple morceau de code */
STP_STRING /* Chaîne de caractères */
@@ -71,6 +72,11 @@ const char *g_binary_symbol_to_string(const GBinSymbol *);
/* Fournit l'adresse associée à un symbole. */
vmpa_t g_binary_symbol_get_address(const GBinSymbol *);
+
+/* Fournit l'adresse associée à un symbole. */
+const vmpa2t *g_binary_symbol_get_address2(const GBinSymbol *);
+
+
/* Fournit la taille officielle d'un symbole. */
off_t g_binary_symbol_get_size(const GBinSymbol *);
@@ -80,6 +86,12 @@ void g_binary_symbol_set_alt_name(GBinSymbol *, char *);
/* Attache la routine associée au symbole. */
void g_binary_symbol_attach_routine(GBinSymbol *, GBinRoutine *);
+/* Attache l'instruction associée au symbole. */
+void g_binary_symbol_attach_instruction(GBinSymbol *, GArchInstruction *);
+
+/* Fournit l'éventuelle instruction associée au symbole. */
+GArchInstruction *g_binary_symbol_get_instruction(const GBinSymbol *);
+
#endif /* _FORMAT_SYMBOL_H */