diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2015-07-24 18:43:55 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2015-07-24 18:43:55 (GMT) |
commit | 156d2e2f6beda2302552ac79678494d914fda05b (patch) | |
tree | 021825960b7ac3315a336fc085a4f1d07c05df39 | |
parent | 21537636cd8318cf5a720211619ad3c3023b52e9 (diff) |
Replaced all remaining raw accesses to binary contents with the GBinContent wrapper in binary formats.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@555 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
45 files changed, 487 insertions, 827 deletions
@@ -1,3 +1,52 @@ +15-07-24 Cyrille Bagard <nocbos@gmail.com> + + * plugins/mobicore/annotations.c: + * plugins/mobicore/mclf.c: + * plugins/mobicore/mclf-int.c: + * plugins/pychrysa/glibext/bincontent.c: + * plugins/readelf/header.c: + * plugins/readelf/program.c: + * plugins/readelf/section.c: + * plugins/ropgadgets/finder.c: + * plugins/ropgadgets/select.c: + * src/analysis/binaries/file.c: + * src/analysis/binary.c: + * src/analysis/binary-int.h: + * src/analysis/disass/area.c: + * src/analysis/disass/disassembler.c: + * src/analysis/disass/fetch.c: + * src/analysis/disass/output.c: + * src/arch/arm/v7/fetch.c: + * src/arch/immediate.c: + * src/arch/instruction.c: + * src/arch/instruction.h: + * src/arch/instruction-int.h: + * src/arch/raw.c: + * src/format/dex/dex-int.c: + * src/format/elf/dynamic.c: + * src/format/elf/elf-int.c: + * src/format/elf/elf-int.h: + * src/format/elf/helper_arm.c: + * src/format/elf/helper_x86.c: + * src/format/elf/section.c: + * src/format/elf/section.h: + * src/format/elf/strings.c: + * src/format/elf/symbols.c: + * src/format/executable.c: + * src/format/format.c: + * src/format/format.h: + * src/format/format-int.h: + * src/format/java/java-int.c: + * src/format/java/pool.c: + * src/format/pe/pe-int.c: + * src/glibext/gbincontent.c: + * src/glibext/gbincontent.h: + * src/glibext/gbufferline.c: + * src/glibext/gbufferline.h: + * src/gui/panels/strings.c: + Replace all remaining raw accesses to binary contents with the GBinContent + wrapper in binary formats. + 15-07-22 Cyrille Bagard <nocbos@gmail.com> * src/analysis/binary.c: diff --git a/plugins/mobicore/annotations.c b/plugins/mobicore/annotations.c index 94fecaf..f6ffa55 100644 --- a/plugins/mobicore/annotations.c +++ b/plugins/mobicore/annotations.c @@ -72,7 +72,7 @@ static bool annotate_mclf_segment_descriptor(GMCLFFormat *format, const char *pr GDbComment *comment; /* Définition de commentaire */ GBinSymbol *symbol; /* Symbole à intégrer */ - content = G_BIN_FORMAT(format)->conten_; + content = G_BIN_FORMAT(format)->content; /* start */ @@ -123,7 +123,7 @@ static bool annotate_mclf_intro(GMCLFFormat *format, vmpa2t *pos) GDbComment *comment; /* Définition de commentaire */ GBinSymbol *symbol; /* Symbole à intégrer */ - content = G_BIN_FORMAT(format)->conten_; + content = G_BIN_FORMAT(format)->content; init_vmpa(pos, 0, format->header.v1.text.start); @@ -170,7 +170,7 @@ static bool annotate_mclf_header_v1(GMCLFFormat *format, vmpa2t *pos) GBinSymbol *symbol; /* Symbole à intégrer */ const char *text; /* Commentaire variable */ - content = G_BIN_FORMAT(format)->conten_; + content = G_BIN_FORMAT(format)->content; /* flags */ @@ -358,7 +358,7 @@ static bool annotate_mclf_text_segment_header(GMCLFFormat *format, vmpa2t *pos) GDbComment *comment; /* Définition de commentaire */ GBinSymbol *symbol; /* Symbole à intégrer */ - content = G_BIN_FORMAT(format)->conten_; + content = G_BIN_FORMAT(format)->content; copy_vmpa(&old, pos); init_vmpa(pos, 0x80, format->header.v1.text.start + 0x80); diff --git a/plugins/mobicore/mclf-int.c b/plugins/mobicore/mclf-int.c index 2f2300d..cb4dbb3 100644 --- a/plugins/mobicore/mclf-int.c +++ b/plugins/mobicore/mclf-int.c @@ -45,7 +45,7 @@ bool read_mclf_header(GMCLFFormat *format, mclf_header_t *header, SourceEndian e GBinContent *content; /* Contenu binaire à lire */ vmpa2t pos; /* Position de lecture */ - content = G_BIN_FORMAT(format)->conten_; + content = G_BIN_FORMAT(format)->content; init_vmpa(&pos, 0, VMPA_NO_VIRTUAL); @@ -112,7 +112,7 @@ bool read_mclf_segment_desc(GMCLFFormat *format, segment_descriptor_t *segment, bool result; /* Bilan à retourner */ GBinContent *content; /* Contenu binaire à lire */ - content = G_BIN_FORMAT(format)->conten_; + content = G_BIN_FORMAT(format)->content; result = g_binary_content_read_u32(content, pos, endian, &segment->start); result &= g_binary_content_read_u32(content, pos, endian, &segment->len); diff --git a/plugins/mobicore/mclf.c b/plugins/mobicore/mclf.c index c456c04..245508f 100644 --- a/plugins/mobicore/mclf.c +++ b/plugins/mobicore/mclf.c @@ -212,6 +212,7 @@ static void g_mclf_format_refine_portions(const GMCLFFormat *format, GBinPortion { GBinPortion *new; /* Nouvelle portion définie */ char desc[MAX_PORTION_DESC]; /* Description d'une portion */ + phys_t length; /* Taille de portion globale */ vmpa2t addr; /* Emplacement dans le binaire */ /* Segment de code */ @@ -249,7 +250,8 @@ static void g_mclf_format_refine_portions(const GMCLFFormat *format, GBinPortion sprintf(desc, "%s \"%s\"", _("Segment"), "sig"); g_binary_portion_set_desc(new, desc); - init_vmpa(&addr, G_BIN_FORMAT(format)->length - 521, VMPA_NO_VIRTUAL); /* FIXME */ + length = g_binary_content_compute_size(G_BIN_FORMAT(format)->content); + init_vmpa(&addr, length - 521, VMPA_NO_VIRTUAL); /* FIXME */ g_binary_portion_set_values(new, &addr, 521); g_binary_portion_set_rights(new, PAC_READ | PAC_WRITE); diff --git a/plugins/pychrysa/glibext/bincontent.c b/plugins/pychrysa/glibext/bincontent.c index 5c9856e..a418c34 100644 --- a/plugins/pychrysa/glibext/bincontent.c +++ b/plugins/pychrysa/glibext/bincontent.c @@ -157,7 +157,7 @@ static PyObject *py_binary_content_read_u8(PyObject *self, PyObject *args) addr = get_internal_vmpa(addr_obj); if (addr == NULL) /* ... */; - status = g_binary_content_read_u8(content, addr, /*SourceEndian endian*/0, &val); + status = g_binary_content_read_u8(content, addr, &val); if (!status) return NULL; printf("val :: 0x%02hhx\n", val); diff --git a/plugins/readelf/header.c b/plugins/readelf/header.c index d4dd706..6c7e171 100644 --- a/plugins/readelf/header.c +++ b/plugins/readelf/header.c @@ -55,7 +55,7 @@ bool annotate_elf_header(GElfFormat *format) GBinSymbol *symbol; /* Symbole à intégrer */ const char *text; /* Texte constant à insérer */ - content = g_binary_format_get_conten_(G_BIN_FORMAT(format)); + content = g_binary_format_get_content(G_BIN_FORMAT(format)); header = g_elf_format_get_header(format); endian = g_elf_format_get_endianness(format); diff --git a/plugins/readelf/program.c b/plugins/readelf/program.c index ae10369..0a5ce7f 100644 --- a/plugins/readelf/program.c +++ b/plugins/readelf/program.c @@ -68,7 +68,7 @@ static bool annotate_elf_program_header(GElfFormat *format, SourceEndian endian, if (!read_elf_program_header(format, get_phy_addr(pos), &phdr)) return false; - content = g_binary_format_get_conten_(G_BIN_FORMAT(format)); + content = g_binary_format_get_content(G_BIN_FORMAT(format)); /* Champ "p_type" */ diff --git a/plugins/readelf/section.c b/plugins/readelf/section.c index 3884818..8445fc6 100644 --- a/plugins/readelf/section.c +++ b/plugins/readelf/section.c @@ -71,7 +71,7 @@ static bool annotate_elf_section_header(GElfFormat *format, SourceEndian endian, if (!read_elf_section_header(format, get_phy_addr(pos), &shdr)) return false; - content = g_binary_format_get_conten_(G_BIN_FORMAT(format)); + content = g_binary_format_get_content(G_BIN_FORMAT(format)); /* Champ "sh_name" */ diff --git a/plugins/ropgadgets/finder.c b/plugins/ropgadgets/finder.c index a63de93..3fbc0fd 100644 --- a/plugins/ropgadgets/finder.c +++ b/plugins/ropgadgets/finder.c @@ -331,7 +331,7 @@ found_rop_list *list_all_gadgets(GBinFormat *format, unsigned int max_depth, upd g_object_ref(G_OBJECT(format)); domain.format = format; - domain.content = g_binary_format_get_conten_(format); + domain.content = g_binary_format_get_content(format); target = g_exe_format_get_target_machine(G_EXE_FORMAT(format)); domain.proc = get_arch_processor_for_type(target); diff --git a/plugins/ropgadgets/select.c b/plugins/ropgadgets/select.c index 66c2add..826682c 100644 --- a/plugins/ropgadgets/select.c +++ b/plugins/ropgadgets/select.c @@ -1748,7 +1748,7 @@ static void add_new_gadgets_for_category(GBinFormat *format, GtkComboBoxText *co const char *target; /* Sous-traitance requise */ GArchProcessor *proc; /* Architecture du binaire */ MemoryDataSize msize; /* Taille du bus d'adresses */ - const bin_t *content; /* Contenu binaire global */ + const GBinContent *content; /* Contenu binaire global */ GCodeBuffer *buffer; /* Tampon de rassemblement */ size_t i; /* Boucle de parcours */ GArchInstruction *instr; /* Elément de liste de gadgets */ @@ -1770,7 +1770,7 @@ static void add_new_gadgets_for_category(GBinFormat *format, GtkComboBoxText *co g_object_unref(G_OBJECT(proc)); - content = g_binary_format_get_content(G_BIN_FORMAT(format), NULL); + content = g_binary_format_get_content(G_BIN_FORMAT(format)); /* Conversion en contenu textuel */ @@ -1835,6 +1835,8 @@ static void add_new_gadgets_for_category(GBinFormat *format, GtkComboBoxText *co g_object_unref(G_OBJECT(buffer)); + g_object_unref(G_OBJECT(content)); + /* Rajout de la catégorie et filtre au besoin */ gtk_combo_box_text_append_text(combo, category); diff --git a/src/analysis/binaries/file.c b/src/analysis/binaries/file.c index d49ecb4..c946572 100644 --- a/src/analysis/binaries/file.c +++ b/src/analysis/binaries/file.c @@ -173,11 +173,6 @@ GLoadedBinary *g_file_binary_new_from_file(const char *filename) content = g_binary_content_new_from_file(filename); if (content == NULL) goto lbf_error; - ///// - loaded->bin_data = g_binary_content_get(content, &loaded->bin_length); - /////// - - target = find_matching_format(content); desc = get_binary_format_name(target); @@ -194,6 +189,7 @@ GLoadedBinary *g_file_binary_new_from_file(const char *filename) if (loaded->format == NULL) { + g_object_unref(G_OBJECT(content)); log_simple_message(LMT_ERROR, _("Error while loading the binary")); goto lbf_error; } @@ -203,6 +199,7 @@ GLoadedBinary *g_file_binary_new_from_file(const char *filename) if (desc == NULL) { + g_object_unref(G_OBJECT(loaded->format)); log_simple_message(LMT_INFO, _("Unknown architecture")); goto lbf_error; } @@ -213,6 +210,7 @@ GLoadedBinary *g_file_binary_new_from_file(const char *filename) if (loaded->proc == NULL) { + g_object_unref(G_OBJECT(loaded->format)); log_simple_message(LMT_ERROR, _("Unable to load the required processor")); goto lbf_error; } diff --git a/src/analysis/binary-int.h b/src/analysis/binary-int.h index c2657ae..64a957d 100644 --- a/src/analysis/binary-int.h +++ b/src/analysis/binary-int.h @@ -60,9 +60,6 @@ struct _GLoadedBinary save_binary_fc save; /* Sauvegarde au format XML */ get_binary_name_fc get_name; /* Obtention d'une description */ - off_t bin_length; /* Taille des données brutes */ - bin_t *bin_data; /* Données binaires brutes */ - GExeFormat *format; /* Format du binaire */ GArchProcessor *proc; /* Architecture du binaire */ diff --git a/src/analysis/binary.c b/src/analysis/binary.c index ade1131..06f6b13 100644 --- a/src/analysis/binary.c +++ b/src/analysis/binary.c @@ -701,8 +701,9 @@ bool g_loaded_binary_connect(GLoadedBinary *binary) /* Détermination de l'identifiant */ - content = g_binary_format_get_conten_(G_BIN_FORMAT(binary->format)); + content = g_binary_format_get_content(G_BIN_FORMAT(binary->format)); checksum = g_binary_content_get_cheksum(content); + g_object_unref(G_OBJECT(content)); binary->local = g_db_client_new(g_loaded_binary_get_name(binary, false), checksum, diff --git a/src/analysis/disass/area.c b/src/analysis/disass/area.c index dd35eaa..3338b03 100644 --- a/src/analysis/disass/area.c +++ b/src/analysis/disass/area.c @@ -509,7 +509,7 @@ bool load_code_from_mem_area(mem_area **list, size_t *count, size_t *index, cons format = G_BIN_FORMAT(g_loaded_binary_get_format(binary)); proc = g_loaded_binary_get_processor(binary); - content = g_binary_format_get_conten_(format); + content = g_binary_format_get_content(format); /* TODO : unref */ area = (*list) + *index; @@ -632,6 +632,8 @@ bool load_code_from_mem_area(mem_area **list, size_t *count, size_t *index, cons printf("\n"); + g_object_unref(G_OBJECT(content)); + g_object_unref(G_OBJECT(proc)); return result; @@ -680,7 +682,7 @@ static void load_data_from_mem_area(mem_area *area, mem_area *list, size_t count /* Récupération des informations de base */ format = G_BIN_FORMAT(g_loaded_binary_get_format(binary)); - content = g_binary_format_get_conten_(format); + content = g_binary_format_get_content(format); /* TODO g_object_unref(G_OBJECT(format)); */ proc = g_loaded_binary_get_processor(binary); @@ -793,6 +795,8 @@ static void load_data_from_mem_area(mem_area *area, mem_area *list, size_t count } + g_object_unref(G_OBJECT(content)); + } diff --git a/src/analysis/disass/disassembler.c b/src/analysis/disass/disassembler.c index 2b518f9..cd16429 100644 --- a/src/analysis/disass/disassembler.c +++ b/src/analysis/disass/disassembler.c @@ -700,8 +700,10 @@ void disassemble_binary(GLoadedBinary *binary, GArchInstruction **instrs, GCodeB *buffer = g_code_buffer_new(BLC_ASSEMBLY); format = G_BIN_FORMAT(g_loaded_binary_get_format(binary)); - content = g_binary_format_get_conten_(format); + + content = g_binary_format_get_content(format); checksum = g_binary_content_get_cheksum(content); + g_object_unref(G_OBJECT(content)); build_disass_prologue(*buffer, g_loaded_binary_get_name(binary, true), checksum); diff --git a/src/analysis/disass/fetch.c b/src/analysis/disass/fetch.c index d7de724..9ebe231 100644 --- a/src/analysis/disass/fetch.c +++ b/src/analysis/disass/fetch.c @@ -169,7 +169,7 @@ GArchInstruction *disassemble_binary_content(const GLoadedBinary *binary, GtkExt /* Définition à la découpe des parties à traiter */ - content = g_binary_format_get_conten_(format); + content = g_binary_format_get_content(format); length = g_binary_content_compute_size(content); areas = compute_memory_areas(G_EXE_FORMAT(format), length, &count); @@ -235,6 +235,8 @@ GArchInstruction *disassemble_binary_content(const GLoadedBinary *binary, GtkExt /* free */ + g_object_unref(G_OBJECT(content)); + g_object_unref(G_OBJECT(proc)); return result; diff --git a/src/analysis/disass/output.c b/src/analysis/disass/output.c index 91c865a..d698c71 100644 --- a/src/analysis/disass/output.c +++ b/src/analysis/disass/output.c @@ -58,7 +58,7 @@ void print_disassembled_instructions(GCodeBuffer *buffer, const GExeFormat *form GLangOutput *output; /* Modèle de sortie adéquat */ //GArchProcessor *proc; /* Architecture du binaire */ MemoryDataSize msize; /* Taille du bus d'adresses */ - const bin_t *content; /* Contenu binaire global */ + const GBinContent *content; /* Contenu binaire global */ #if 0 const mrange_t *range; /* Cou @@ -130,7 +130,7 @@ void print_disassembled_instructions(GCodeBuffer *buffer, const GExeFormat *form //proc = get_arch_processor_from_format(format); msize = g_arch_processor_get_memory_size(proc); - content = g_binary_format_get_content(G_BIN_FORMAT(format), NULL); + content = g_binary_format_get_content(G_BIN_FORMAT(format)); #if 0 g_arch_instruction_get_location(instrs, NULL, NULL, &start); @@ -276,6 +276,7 @@ void print_disassembled_instructions(GCodeBuffer *buffer, const GExeFormat *form } + g_object_unref(G_OBJECT(content)); /* free portions... */ diff --git a/src/arch/arm/v7/fetch.c b/src/arch/arm/v7/fetch.c index 246d136..73cec6d 100644 --- a/src/arch/arm/v7/fetch.c +++ b/src/arch/arm/v7/fetch.c @@ -373,9 +373,9 @@ void help_fetching_with_instruction_ldr_literal_with_orig(GArchInstruction *inst bool ret; /* Bilan d'une récupération */ off_t val_offset; /* Position de valeur à lire */ vmpa2t sym_addr; /* Adresse de nouveau symbole */ - off_t length; /* Taille des données à lire */ - const bin_t *data; /* Données binaires à lire */ + GBinContent *content; /* Contenu binaire à relire */ uint32_t target; /* Adresse virtuelle visée */ + vmpa2t pos; /* Tête de lecture de valeur */ mrange_t sym_range; /* Espace du nouveau symbole */ VMPA_BUFFER(loc); /* Adresse au format texte */ size_t name_len; /* Taille de nomination finale */ @@ -441,22 +441,15 @@ void help_fetching_with_instruction_ldr_literal_with_orig(GArchInstruction *inst /* Lecture de la valeur vers laquelle renvoyer */ - data = g_binary_format_get_content(format, &length); + content = g_binary_format_get_content(format); + copy_vmpa(&pos, &sym_addr); - printf(">>>>>>> @reading @ 0x%08x (0x%x)\n", (unsigned int)val_offset, offset); + ret = g_binary_content_read_u32(content, &pos, SRE_LITTLE /* FIXME */, &target); + g_object_unref(G_OBJECT(content)); - - ret = read_u32(&target, data, &val_offset, length, SRE_LITTLE /* FIXME */); if (!ret) return; - - printf(">>>>>>> @got target :: 0x%08x\n", (unsigned int)target); - - - - - /* Réalise l'intégration du symbole associé */ sym_instr = g_raw_instruction_new_from_value(&sym_addr, MDS_32_BITS_UNSIGNED, target); @@ -506,7 +499,7 @@ void help_fetching_with_instruction_ldr_literal_with_orig(GArchInstruction *inst //g_imm_operand_set_value(G_IMM_OPERAND(sub_op), MDS_32_BITS_UNSIGNED, target); - + /// FIXME ?! if (target < 0x8000) return; diff --git a/src/arch/immediate.c b/src/arch/immediate.c index fc8e40d..c21239e 100644 --- a/src/arch/immediate.c +++ b/src/arch/immediate.c @@ -354,7 +354,7 @@ GArchOperand *_g_imm_operand_new_from_data(MemoryDataSize size, const GBinConten break; case MDS_8_BITS_UNSIGNED: - if (!g_binary_content_read_u8(content, addr, endian, &uval8)) + if (!g_binary_content_read_u8(content, addr, &uval8)) goto gionfd_error; result->raw = uval8; break; @@ -384,7 +384,7 @@ GArchOperand *_g_imm_operand_new_from_data(MemoryDataSize size, const GBinConten break; case MDS_8_BITS_SIGNED: - if (!g_binary_content_read_s8(content, addr, endian, &sval8)) + if (!g_binary_content_read_s8(content, addr, &sval8)) goto gionfd_error; result->raw = sval8; break; diff --git a/src/arch/instruction-int.h b/src/arch/instruction-int.h index bb45f72..6b2b5c7 100644 --- a/src/arch/instruction-int.h +++ b/src/arch/instruction-int.h @@ -36,7 +36,7 @@ typedef void (* get_instruction_rw_regs_fc) (const GArchInstruction *, GArchRegister ***, size_t *, GArchRegister ***, size_t *); /* Ajoute à un tampon GLib le contenu de l'instance spécifiée. */ -typedef GBufferLine * (* print_instruction_fc) (const GArchInstruction *, GCodeBuffer *, MemoryDataSize, const bin_t *, AsmSyntax); +typedef GBufferLine * (* print_instruction_fc) (const GArchInstruction *, GCodeBuffer *, MemoryDataSize, const GBinContent *, AsmSyntax); /* Reconstruit le cache complet d'une désignation d'instruction. */ typedef void (* build_instruction_keyword_fc) (const GArchInstruction *, AsmSyntax); @@ -64,7 +64,7 @@ struct _GArchInstruction vmpa2t address2; /* Position associée */ off_t offset; /* Position physique de départ */ - off_t length; /* Taille de l'instruction */ + //off_t length; /* Taille de l'instruction */ vmpa_t address; /* Position associée */ diff --git a/src/arch/instruction.c b/src/arch/instruction.c index d6bf183..d9d7693 100644 --- a/src/arch/instruction.c +++ b/src/arch/instruction.c @@ -52,7 +52,7 @@ static void g_arch_instruction_finalize(GArchInstruction *); /* Ajoute à un tampon GLib le contenu de l'instance spécifiée. */ -static GBufferLine *_g_arch_instruction_print(const GArchInstruction *, GCodeBuffer *, MemoryDataSize, const bin_t *, AsmSyntax); +static GBufferLine *_g_arch_instruction_print(const GArchInstruction *, GCodeBuffer *, MemoryDataSize, const GBinContent *, AsmSyntax); @@ -317,7 +317,7 @@ const mrange_t *g_arch_instruction_get_range(const GArchInstruction *instr) void g_arch_instruction_get_location(const GArchInstruction *instr, off_t *offset, off_t *length, vmpa_t *address) { if (offset != NULL) *offset = instr->offset; - if (length != NULL) *length = instr->length; + //if (length != NULL) *length = instr->length; if (address != NULL) *address = instr->address; @@ -833,10 +833,11 @@ const char *g_arch_instruction_get_keyword(const GArchInstruction *instr, AsmSyn /****************************************************************************** * * -* Paramètres : instr = instruction d'assemblage à représenter. * -* buffer = espace où placer ledit contenu. * -* msize = taille idéale des positions et adresses; * -* syntax = type de représentation demandée. * +* Paramètres : instr = instruction d'assemblage à représenter. * +* buffer = espace où placer ledit contenu. * +* msize = taille idéale des positions et adresses; * +* content = contenu binaire global à venir lire. * +* syntax = type de représentation demandée. * * * * Description : Ajoute à un tampon GLib le contenu de l'instance spécifiée. * * * @@ -846,7 +847,7 @@ const char *g_arch_instruction_get_keyword(const GArchInstruction *instr, AsmSyn * * ******************************************************************************/ -static GBufferLine *_g_arch_instruction_print(const GArchInstruction *instr, GCodeBuffer *buffer, MemoryDataSize msize, const bin_t *content, AsmSyntax syntax) +static GBufferLine *_g_arch_instruction_print(const GArchInstruction *instr, GCodeBuffer *buffer, MemoryDataSize msize, const GBinContent *content, AsmSyntax syntax) { GBufferLine *result; /* Ligne de destination */ const char *key; /* Mot clef principal */ @@ -857,8 +858,7 @@ static GBufferLine *_g_arch_instruction_print(const GArchInstruction *instr, GCo g_buffer_line_add_flag(result, BLF_HAS_CODE); - g_buffer_line_fill_for_instr(result, msize/* TODO ! */, msize, - content, get_mrange_length(&instr->range), true); + g_buffer_line_fill_for_instr(result, msize/* TODO ! */, msize, content, true); /* Instruction proprement dite */ @@ -892,6 +892,7 @@ static GBufferLine *_g_arch_instruction_print(const GArchInstruction *instr, GCo * Paramètres : instr = instruction d'assemblage à représenter. * * buffer = espace où placer ledit contenu. * * msize = taille idéale des positions et adresses; * +* content = contenu binaire global à venir lire. * * syntax = type de représentation demandée. * * * * Description : Ajoute à un tampon GLib le contenu de l'instance spécifiée. * @@ -902,7 +903,7 @@ static GBufferLine *_g_arch_instruction_print(const GArchInstruction *instr, GCo * * ******************************************************************************/ -GBufferLine *g_arch_instruction_print(const GArchInstruction *instr, GCodeBuffer *buffer, MemoryDataSize msize, const bin_t *content, AsmSyntax syntax) +GBufferLine *g_arch_instruction_print(const GArchInstruction *instr, GCodeBuffer *buffer, MemoryDataSize msize, const GBinContent *content, AsmSyntax syntax) { return G_ARCH_INSTRUCTION_GET_CLASS(instr)->print(instr, buffer, msize, content, syntax); diff --git a/src/arch/instruction.h b/src/arch/instruction.h index a4ea1b5..b3a272f 100644 --- a/src/arch/instruction.h +++ b/src/arch/instruction.h @@ -213,7 +213,7 @@ size_t g_arch_instruction_compute_group_index(GArchInstruction **, GArchInstruct const char *g_arch_instruction_get_keyword(const GArchInstruction *, AsmSyntax); /* Ajoute à un tampon GLib le contenu de l'instance spécifiée. */ -GBufferLine *g_arch_instruction_print(const GArchInstruction *, GCodeBuffer *, MemoryDataSize, const bin_t *, AsmSyntax); +GBufferLine *g_arch_instruction_print(const GArchInstruction *, GCodeBuffer *, MemoryDataSize, const GBinContent *, AsmSyntax); /* Décompile une instruction de façon générique. */ GDecInstruction *g_arch_instruction_decompile(const GArchInstruction *, GDecContext *); diff --git a/src/arch/raw.c b/src/arch/raw.c index cf990f0..41f46c1 100644 --- a/src/arch/raw.c +++ b/src/arch/raw.c @@ -69,7 +69,7 @@ static void g_raw_instruction_dispose(GRawInstruction *); static void g_raw_instruction_finalize(GRawInstruction *); /* Ajoute à un tampon GLib le contenu de l'instance spécifiée. */ -static GBufferLine *g_raw_instruction_print(const GRawInstruction *, GCodeBuffer *, MemoryDataSize, const bin_t *, AsmSyntax); +static GBufferLine *g_raw_instruction_print(const GRawInstruction *, GCodeBuffer *, MemoryDataSize, const GBinContent *, AsmSyntax); /* Reconstruit le cache complet d'une désignation d'instruction. */ static void g_raw_instruction_build_keyword(const GRawInstruction *, AsmSyntax); @@ -358,6 +358,8 @@ GArchInstruction *g_raw_instruction_new_array(const GBinContent *content, Memory * * * Paramètres : instr = instruction d'assemblage à représenter. * * buffer = espace où placer ledit contenu. * +* msize = taille idéale des positions et adresses; * +* content = contenu binaire global à venir lire. * * syntax = type de représentation demandée. * * * * Description : Ajoute à un tampon GLib le contenu de l'instance spécifiée. * @@ -368,7 +370,7 @@ GArchInstruction *g_raw_instruction_new_array(const GBinContent *content, Memory * * ******************************************************************************/ -static GBufferLine *g_raw_instruction_print(const GRawInstruction *instr, GCodeBuffer *buffer, MemoryDataSize msize, const bin_t *content, AsmSyntax syntax) +static GBufferLine *g_raw_instruction_print(const GRawInstruction *instr, GCodeBuffer *buffer, MemoryDataSize msize, const GBinContent *content, AsmSyntax syntax) { GBufferLine *result; /* Ligne de destination */ GArchInstruction *base; /* Autre version de l'instance */ @@ -392,7 +394,7 @@ static GBufferLine *g_raw_instruction_print(const GRawInstruction *instr, GCodeB g_buffer_line_add_flag(result, BLF_HAS_CODE); - g_buffer_line_fill_for_instr(result, msize/* TODO ! */, msize, content, base->length, true); + g_buffer_line_fill_mrange(result, msize/* TODO ! */, msize); /* Instruction proprement dite */ diff --git a/src/format/dex/dex-int.c b/src/format/dex/dex-int.c index c3d64ff..914f491 100644 --- a/src/format/dex/dex-int.c +++ b/src/format/dex/dex-int.c @@ -60,8 +60,8 @@ bool read_dex_header(const GDexFormat *format, off_t *pos, dex_header *header) result = true; - content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + content = NULL; //G_BIN_FORMAT(format)->content; + length = 0; //G_BIN_FORMAT(format)->length; for (i = 0; i < DEX_FILE_MAGIC_LEN && result; i++) result = read_u8(&header->magic[i], content, pos, length, SRE_LITTLE); @@ -127,8 +127,8 @@ bool read_dex_string_id_item(const GDexFormat *format, off_t *pos, string_id_ite result = true; - content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + content = NULL; //G_BIN_FORMAT(format)->content; + length = 0; //G_BIN_FORMAT(format)->length; result &= read_u32(&str_id->string_data_off, content, pos, length, SRE_LITTLE); @@ -159,8 +159,8 @@ bool read_dex_string_data_item(const GDexFormat *format, off_t *pos, string_data result = true; - content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + content = NULL; //G_BIN_FORMAT(format)->content; + length = 0; //G_BIN_FORMAT(format)->length; result &= read_uleb128(&str_data->utf16_size, content, pos, length); @@ -193,8 +193,8 @@ bool read_dex_type_id_item(const GDexFormat *format, off_t *pos, type_id_item *i result = true; - content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + content = NULL; //G_BIN_FORMAT(format)->content; + length = 0; //G_BIN_FORMAT(format)->length; result &= read_u32(&item->descriptor_idx, content, pos, length, SRE_LITTLE); @@ -225,8 +225,8 @@ bool read_dex_proto_id_item(const GDexFormat *format, off_t *pos, proto_id_item result = true; - content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + content = NULL; //G_BIN_FORMAT(format)->content; + length = 0; //G_BIN_FORMAT(format)->length; result &= read_u32(&proto_id->shorty_idx, content, pos, length, SRE_LITTLE); result &= read_u32(&proto_id->return_type_idx, content, pos, length, SRE_LITTLE); @@ -259,8 +259,8 @@ bool read_dex_field_id_item(const GDexFormat *format, off_t *pos, field_id_item result = true; - content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + content = NULL; //G_BIN_FORMAT(format)->content; + length = 0; //G_BIN_FORMAT(format)->length; result &= read_u16(&field_id->class_idx, content, pos, length, SRE_LITTLE); result &= read_u16(&field_id->type_idx, content, pos, length, SRE_LITTLE); @@ -293,8 +293,8 @@ bool read_dex_method_id_item(const GDexFormat *format, off_t *pos, method_id_ite result = true; - content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + content = NULL; //G_BIN_FORMAT(format)->content; + length = 0; //G_BIN_FORMAT(format)->length; result &= read_u16(&meth_id->class_idx, content, pos, length, SRE_LITTLE); result &= read_u16(&meth_id->proto_idx, content, pos, length, SRE_LITTLE); @@ -327,8 +327,8 @@ bool read_dex_class_def_item(const GDexFormat *format, off_t *pos, class_def_ite result = true; - content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + content = NULL; //G_BIN_FORMAT(format)->content; + length = 0; //G_BIN_FORMAT(format)->length; result &= read_u32(&class_def->class_idx, content, pos, length, SRE_LITTLE); result &= read_u32(&class_def->access_flags, content, pos, length, SRE_LITTLE); @@ -372,8 +372,8 @@ bool read_dex_encoded_field(const GDexFormat *format, off_t *pos, encoded_field result = true; - content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + content = NULL; //G_BIN_FORMAT(format)->content; + length = 0; //G_BIN_FORMAT(format)->length; result &= read_uleb128(&field->field_idx_diff, content, pos, length); result &= read_uleb128(&field->access_flags, content, pos, length); @@ -405,8 +405,8 @@ bool read_dex_encoded_method(const GDexFormat *format, off_t *pos, encoded_metho result = true; - content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + content = NULL; //G_BIN_FORMAT(format)->content; + length = 0; //G_BIN_FORMAT(format)->length; result &= read_uleb128(&method->method_idx_diff, content, pos, length); result &= read_uleb128(&method->access_flags, content, pos, length); @@ -439,8 +439,8 @@ bool read_dex_type_item(const GDexFormat *format, off_t *pos, type_item *item) result = true; - content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + content = NULL; //G_BIN_FORMAT(format)->content; + length = 0; //G_BIN_FORMAT(format)->length; result &= read_u16(&item->type_idx, content, pos, length, SRE_LITTLE); @@ -471,8 +471,8 @@ bool read_dex_type_list(const GDexFormat *format, off_t *pos, type_list *list) result = true; - content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + content = NULL; //G_BIN_FORMAT(format)->content; + length = 0; //G_BIN_FORMAT(format)->length; result &= read_u32(&list->size, content, pos, length, SRE_LITTLE); @@ -507,8 +507,8 @@ bool read_dex_class_data_item(const GDexFormat *format, off_t *pos, class_data_i result = true; - content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + content = NULL; //G_BIN_FORMAT(format)->content; + length = 0; //G_BIN_FORMAT(format)->length; item->static_fields = NULL; item->instance_fields = NULL; @@ -625,8 +625,8 @@ bool read_dex_encoded_type_addr_pair(const GDexFormat *format, off_t *pos, encod result = true; - content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + content = NULL; //G_BIN_FORMAT(format)->content; + length = 0; //G_BIN_FORMAT(format)->length; result &= read_uleb128(&pair->type_idx, content, pos, length); result &= read_uleb128(&pair->addr, content, pos, length); @@ -660,8 +660,8 @@ bool read_dex_encoded_catch_handler(const GDexFormat *format, off_t *pos, encode result = true; - content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + content = NULL; //G_BIN_FORMAT(format)->content; + length = 0; //G_BIN_FORMAT(format)->length; handler->offset = *pos; @@ -733,8 +733,8 @@ bool read_dex_encoded_catch_handler_list(const GDexFormat *format, off_t *pos, e result = true; - content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + content = NULL; //G_BIN_FORMAT(format)->content; + length = 0; //G_BIN_FORMAT(format)->length; saved_off = *pos; @@ -808,8 +808,8 @@ bool read_dex_try_item(const GDexFormat *format, off_t *pos, try_item *item) result = true; - content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + content = NULL; //G_BIN_FORMAT(format)->content; + length = 0; //G_BIN_FORMAT(format)->length; result &= read_u32(&item->start_addr, content, pos, length, SRE_LITTLE); result &= read_u16(&item->insn_count, content, pos, length, SRE_LITTLE); @@ -844,8 +844,8 @@ bool read_dex_code_item(const GDexFormat *format, off_t *pos, code_item *item) result = true; - content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + content = NULL; //G_BIN_FORMAT(format)->content; + length = 0; //G_BIN_FORMAT(format)->length; result &= read_u16(&item->registers_size, content, pos, length, SRE_LITTLE); result &= read_u16(&item->ins_size, content, pos, length, SRE_LITTLE); @@ -937,8 +937,8 @@ bool read_dex_packed_switch(const GDexFormat *format, off_t *pos, packed_switch result = true; - content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + content = NULL; //G_BIN_FORMAT(format)->content; + length = 0; //G_BIN_FORMAT(format)->length; packed->targets = NULL; @@ -1006,8 +1006,8 @@ bool read_dex_sparse_switch(const GDexFormat *format, off_t *pos, sparse_switch result = true; - content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + content = NULL; //G_BIN_FORMAT(format)->content; + length = 0; //G_BIN_FORMAT(format)->length; sparse->keys = NULL; sparse->targets = NULL; @@ -1082,8 +1082,8 @@ bool read_dex_switch(const GDexFormat *format, off_t *pos, dex_switch *dswitch) result = true; - content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + content = NULL; //G_BIN_FORMAT(format)->content; + length = 0; //G_BIN_FORMAT(format)->length; result &= read_u16(&ident, content, (off_t []) { *pos }, length, SRE_LITTLE); diff --git a/src/format/elf/dynamic.c b/src/format/elf/dynamic.c index e1f50b0..f3367f7 100644 --- a/src/format/elf/dynamic.c +++ b/src/format/elf/dynamic.c @@ -87,7 +87,7 @@ bool find_elf_dynamic_item_from_pheader(const GElfFormat *format, const elf_phdr bool result; /* Bilan à retourner */ off_t max; /* Nombre d'entités présentes */ off_t i; /* Boucle de parcours */ - off_t pos; /* Position de lecture */ + phys_t pos; /* Position de lecture */ result = false; @@ -97,7 +97,7 @@ bool find_elf_dynamic_item_from_pheader(const GElfFormat *format, const elf_phdr { pos = ELF_PHDR(format, *dynamic, p_offset) + i * ELF_SIZEOF_DYN(format); - if (!read_elf_dynamic_entry(format, &pos, item)) + if (!read_elf_dynamic_entry(format, pos, item)) break; result = (ELF_DYN(format, *item, d_tag) == type); diff --git a/src/format/elf/elf-int.c b/src/format/elf/elf-int.c index 7ca958b..3e70932 100644 --- a/src/format/elf/elf-int.c +++ b/src/format/elf/elf-int.c @@ -46,22 +46,14 @@ 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 */ + const GBinContent *content; /* Contenu binaire à lire */ + vmpa2t pos; /* Position de lecture */ content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; - result = (length >= EI_NIDENT); + init_vmpa(&pos, 0, VMPA_NO_VIRTUAL); - pos = 0; - - if (result) - { - memcpy(header->hdr32.e_ident, content, EI_NIDENT); - pos += EI_NIDENT; - } + result = g_binary_content_get_raw(content, &pos, EI_NIDENT, (bin_t *)header->hdr32.e_ident); /* Détermination de l'espace d'adressage */ if (result) @@ -95,35 +87,35 @@ bool read_elf_header(GElfFormat *format, elf_header *header, bool *is_32b, Sourc if (*is_32b) { - result &= read_u16(&header->hdr32.e_type, content, &pos, length, *endian); - result &= read_u16(&header->hdr32.e_machine, content, &pos, length, *endian); - result &= read_u32(&header->hdr32.e_version, content, &pos, length, *endian); - result &= read_u32(&header->hdr32.e_entry, content, &pos, length, *endian); - result &= read_u32(&header->hdr32.e_phoff, content, &pos, length, *endian); - result &= read_u32(&header->hdr32.e_shoff, content, &pos, length, *endian); - result &= read_u32(&header->hdr32.e_flags, content, &pos, length, *endian); - result &= read_u16(&header->hdr32.e_ehsize, content, &pos, length, *endian); - result &= read_u16(&header->hdr32.e_phentsize, content, &pos, length, *endian); - result &= read_u16(&header->hdr32.e_phnum, content, &pos, length, *endian); - result &= read_u16(&header->hdr32.e_shentsize, content, &pos, length, *endian); - result &= read_u16(&header->hdr32.e_shnum, content, &pos, length, *endian); - result &= read_u16(&header->hdr32.e_shstrndx, content, &pos, length, *endian); + result &= g_binary_content_read_u16(content, &pos, *endian, &header->hdr32.e_type); + result &= g_binary_content_read_u16(content, &pos, *endian, &header->hdr32.e_machine); + result &= g_binary_content_read_u32(content, &pos, *endian, &header->hdr32.e_version); + result &= g_binary_content_read_u32(content, &pos, *endian, &header->hdr32.e_entry); + result &= g_binary_content_read_u32(content, &pos, *endian, &header->hdr32.e_phoff); + result &= g_binary_content_read_u32(content, &pos, *endian, &header->hdr32.e_shoff); + result &= g_binary_content_read_u32(content, &pos, *endian, &header->hdr32.e_flags); + result &= g_binary_content_read_u16(content, &pos, *endian, &header->hdr32.e_ehsize); + result &= g_binary_content_read_u16(content, &pos, *endian, &header->hdr32.e_phentsize); + result &= g_binary_content_read_u16(content, &pos, *endian, &header->hdr32.e_phnum); + result &= g_binary_content_read_u16(content, &pos, *endian, &header->hdr32.e_shentsize); + result &= g_binary_content_read_u16(content, &pos, *endian, &header->hdr32.e_shnum); + result &= g_binary_content_read_u16(content, &pos, *endian, &header->hdr32.e_shstrndx); } else { - result &= read_u16(&header->hdr64.e_type, content, &pos, length, *endian); - result &= read_u16(&header->hdr64.e_machine, content, &pos, length, *endian); - result &= read_u32(&header->hdr64.e_version, content, &pos, length, *endian); - result &= read_u64(&header->hdr64.e_entry, content, &pos, length, *endian); - result &= read_u64(&header->hdr64.e_phoff, content, &pos, length, *endian); - result &= read_u64(&header->hdr64.e_shoff, content, &pos, length, *endian); - result &= read_u32(&header->hdr64.e_flags, content, &pos, length, *endian); - result &= read_u16(&header->hdr64.e_ehsize, content, &pos, length, *endian); - result &= read_u16(&header->hdr64.e_phentsize, content, &pos, length, *endian); - result &= read_u16(&header->hdr64.e_phnum, content, &pos, length, *endian); - result &= read_u16(&header->hdr64.e_shentsize, content, &pos, length, *endian); - result &= read_u16(&header->hdr64.e_shnum, content, &pos, length, *endian); - result &= read_u16(&header->hdr64.e_shstrndx, content, &pos, length, *endian); + result &= g_binary_content_read_u16(content, &pos, *endian, &header->hdr64.e_type); + result &= g_binary_content_read_u16(content, &pos, *endian, &header->hdr64.e_machine); + result &= g_binary_content_read_u32(content, &pos, *endian, &header->hdr64.e_version); + result &= g_binary_content_read_u64(content, &pos, *endian, &header->hdr64.e_entry); + result &= g_binary_content_read_u64(content, &pos, *endian, &header->hdr64.e_phoff); + result &= g_binary_content_read_u64(content, &pos, *endian, &header->hdr64.e_shoff); + result &= g_binary_content_read_u32(content, &pos, *endian, &header->hdr64.e_flags); + result &= g_binary_content_read_u16(content, &pos, *endian, &header->hdr64.e_ehsize); + result &= g_binary_content_read_u16(content, &pos, *endian, &header->hdr64.e_phentsize); + result &= g_binary_content_read_u16(content, &pos, *endian, &header->hdr64.e_phnum); + result &= g_binary_content_read_u16(content, &pos, *endian, &header->hdr64.e_shentsize); + result &= g_binary_content_read_u16(content, &pos, *endian, &header->hdr64.e_shnum); + result &= g_binary_content_read_u16(content, &pos, *endian, &header->hdr64.e_shstrndx); } return result; @@ -134,7 +126,7 @@ bool read_elf_header(GElfFormat *format, elf_header *header, bool *is_32b, Sourc /****************************************************************************** * * * Paramètres : format = informations chargées à consulter. * -* pos = position de début de lecture. [OUT] * +* phys = position de début de lecture. * * header = structure lue à retourner. [OUT] * * * * Description : Procède à la lecture d'une en-tête de programme ELF. * @@ -145,36 +137,37 @@ bool read_elf_header(GElfFormat *format, elf_header *header, bool *is_32b, Sourc * * ******************************************************************************/ -bool read_elf_program_header(const GElfFormat *format, off_t pos, elf_phdr *header) +bool read_elf_program_header(const GElfFormat *format, phys_t phys, elf_phdr *header) { bool result; /* Bilan à retourner */ - const bin_t *content; /* Contenu binaire à lire */ - off_t length; /* Taille totale du contenu */ + const GBinContent *content; /* Contenu binaire à lire */ + vmpa2t pos; /* Position de lecture */ content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + + init_vmpa(&pos, phys, VMPA_NO_VIRTUAL); if (format->is_32b) { - result = read_u32(&header->phdr32.p_type, content, &pos, length, format->endian); - result &= read_u32(&header->phdr32.p_offset, content, &pos, length, format->endian); - result &= read_u32(&header->phdr32.p_vaddr, content, &pos, length, format->endian); - result &= read_u32(&header->phdr32.p_paddr, content, &pos, length, format->endian); - result &= read_u32(&header->phdr32.p_filesz, content, &pos, length, format->endian); - result &= read_u32(&header->phdr32.p_memsz, content, &pos, length, format->endian); - result &= read_u32(&header->phdr32.p_flags, content, &pos, length, format->endian); - result &= read_u32(&header->phdr32.p_align, content, &pos, length, format->endian); + result = g_binary_content_read_u32(content, &pos, format->endian, &header->phdr32.p_type); + result &= g_binary_content_read_u32(content, &pos, format->endian, &header->phdr32.p_offset); + result &= g_binary_content_read_u32(content, &pos, format->endian, &header->phdr32.p_vaddr); + result &= g_binary_content_read_u32(content, &pos, format->endian, &header->phdr32.p_paddr); + result &= g_binary_content_read_u32(content, &pos, format->endian, &header->phdr32.p_filesz); + result &= g_binary_content_read_u32(content, &pos, format->endian, &header->phdr32.p_memsz); + result &= g_binary_content_read_u32(content, &pos, format->endian, &header->phdr32.p_flags); + result &= g_binary_content_read_u32(content, &pos, format->endian, &header->phdr32.p_align); } else { - result = read_u32(&header->phdr64.p_type, content, &pos, length, format->endian); - result &= read_u32(&header->phdr64.p_flags, content, &pos, length, format->endian); - result &= read_u64(&header->phdr64.p_offset, content, &pos, length, format->endian); - result &= read_u64(&header->phdr64.p_vaddr, content, &pos, length, format->endian); - result &= read_u64(&header->phdr64.p_paddr, content, &pos, length, format->endian); - result &= read_u64(&header->phdr64.p_filesz, content, &pos, length, format->endian); - result &= read_u64(&header->phdr64.p_memsz, content, &pos, length, format->endian); - result &= read_u64(&header->phdr64.p_align, content, &pos, length, format->endian); + result = g_binary_content_read_u32(content, &pos, format->endian, &header->phdr64.p_type); + result &= g_binary_content_read_u32(content, &pos, format->endian, &header->phdr64.p_flags); + result &= g_binary_content_read_u64(content, &pos, format->endian, &header->phdr64.p_offset); + result &= g_binary_content_read_u64(content, &pos, format->endian, &header->phdr64.p_vaddr); + result &= g_binary_content_read_u64(content, &pos, format->endian, &header->phdr64.p_paddr); + result &= g_binary_content_read_u64(content, &pos, format->endian, &header->phdr64.p_filesz); + result &= g_binary_content_read_u64(content, &pos, format->endian, &header->phdr64.p_memsz); + result &= g_binary_content_read_u64(content, &pos, format->endian, &header->phdr64.p_align); } return result; @@ -185,7 +178,7 @@ bool read_elf_program_header(const GElfFormat *format, off_t pos, elf_phdr *head /****************************************************************************** * * * Paramètres : format = informations chargées à consulter. * -* pos = position de la tête de lecture. * +* phys = position de début de lecture. * * section = section lue. [OUT] * * * * Description : Procède à la lecture d'une en-tête de section ELF. * @@ -196,49 +189,50 @@ bool read_elf_program_header(const GElfFormat *format, off_t pos, elf_phdr *head * * ******************************************************************************/ -bool read_elf_section_header(const GElfFormat *format, off_t pos, elf_shdr *section) +bool read_elf_section_header(const GElfFormat *format, phys_t phys, elf_shdr *section) { bool result; /* Bilan à retourner */ - const bin_t *content; /* Contenu binaire à lire */ - off_t length; /* Taille totale du contenu */ + const GBinContent *content; /* Contenu binaire à lire */ + vmpa2t pos; /* Position de lecture */ elf32_shdr *shdr32; /* Version 32 bits */ elf64_shdr *shdr64; /* Version 32 bits */ result = true; content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + + init_vmpa(&pos, phys, VMPA_NO_VIRTUAL); if (format->is_32b) { shdr32 = §ion->shdr32; - result = read_u32(&shdr32->sh_name, content, &pos, length, format->endian); - result &= read_u32(&shdr32->sh_type, content, &pos, length, format->endian); - result &= read_u32(&shdr32->sh_flags, content, &pos, length, format->endian); - result &= read_u32(&shdr32->sh_addr, content, &pos, length, format->endian); - result &= read_u32(&shdr32->sh_offset, content, &pos, length, format->endian); - result &= read_u32(&shdr32->sh_size, content, &pos, length, format->endian); - result &= read_u32(&shdr32->sh_link, content, &pos, length, format->endian); - result &= read_u32(&shdr32->sh_info, content, &pos, length, format->endian); - result &= read_u32(&shdr32->sh_addralign, content, &pos, length, format->endian); - result &= read_u32(&shdr32->sh_entsize, content, &pos, length, format->endian); + result = g_binary_content_read_u32(content, &pos, format->endian, &shdr32->sh_name); + result &= g_binary_content_read_u32(content, &pos, format->endian, &shdr32->sh_type); + result &= g_binary_content_read_u32(content, &pos, format->endian, &shdr32->sh_flags); + result &= g_binary_content_read_u32(content, &pos, format->endian, &shdr32->sh_addr); + result &= g_binary_content_read_u32(content, &pos, format->endian, &shdr32->sh_offset); + result &= g_binary_content_read_u32(content, &pos, format->endian, &shdr32->sh_size); + result &= g_binary_content_read_u32(content, &pos, format->endian, &shdr32->sh_link); + result &= g_binary_content_read_u32(content, &pos, format->endian, &shdr32->sh_info); + result &= g_binary_content_read_u32(content, &pos, format->endian, &shdr32->sh_addralign); + result &= g_binary_content_read_u32(content, &pos, format->endian, &shdr32->sh_entsize); } else { shdr64 = §ion->shdr64; - result = read_u32(&shdr64->sh_name, content, &pos, length, format->endian); - result &= read_u32(&shdr64->sh_type, content, &pos, length, format->endian); - result &= read_u64(&shdr64->sh_flags, content, &pos, length, format->endian); - result &= read_u64(&shdr64->sh_addr, content, &pos, length, format->endian); - result &= read_u64(&shdr64->sh_offset, content, &pos, length, format->endian); - result &= read_u64(&shdr64->sh_size, content, &pos, length, format->endian); - result &= read_u32(&shdr64->sh_link, content, &pos, length, format->endian); - result &= read_u32(&shdr64->sh_info, content, &pos, length, format->endian); - result &= read_u64(&shdr64->sh_addralign, content, &pos, length, format->endian); - result &= read_u64(&shdr64->sh_entsize, content, &pos, length, format->endian); + result = g_binary_content_read_u32(content, &pos, format->endian, &shdr64->sh_name); + result &= g_binary_content_read_u32(content, &pos, format->endian, &shdr64->sh_type); + result &= g_binary_content_read_u64(content, &pos, format->endian, &shdr64->sh_flags); + result &= g_binary_content_read_u64(content, &pos, format->endian, &shdr64->sh_addr); + result &= g_binary_content_read_u64(content, &pos, format->endian, &shdr64->sh_offset); + result &= g_binary_content_read_u64(content, &pos, format->endian, &shdr64->sh_size); + result &= g_binary_content_read_u32(content, &pos, format->endian, &shdr64->sh_link); + result &= g_binary_content_read_u32(content, &pos, format->endian, &shdr64->sh_info); + result &= g_binary_content_read_u64(content, &pos, format->endian, &shdr64->sh_addralign); + result &= g_binary_content_read_u64(content, &pos, format->endian, &shdr64->sh_entsize); } @@ -250,7 +244,7 @@ bool read_elf_section_header(const GElfFormat *format, off_t pos, elf_shdr *sect /****************************************************************************** * * * Paramètres : format = informations chargées à consulter. * -* pos = position de début de lecture. [OUT] * +* phys = position de début de lecture. * * dyn = structure lue à retourner. [OUT] * * * * Description : Procède à la lecture d'une entrée de type 'DYNAMIC' ELF. * @@ -261,24 +255,25 @@ bool read_elf_section_header(const GElfFormat *format, off_t pos, elf_shdr *sect * * ******************************************************************************/ -bool read_elf_dynamic_entry(const GElfFormat *format, off_t *pos, elf_dyn *dyn) +bool read_elf_dynamic_entry(const GElfFormat *format, phys_t phys, elf_dyn *dyn) { bool result; /* Bilan à retourner */ - const bin_t *content; /* Contenu binaire à lire */ - off_t length; /* Taille totale du contenu */ + const GBinContent *content; /* Contenu binaire à lire */ + vmpa2t pos; /* Position de lecture */ content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + + init_vmpa(&pos, phys, VMPA_NO_VIRTUAL); if (format->is_32b) { - result = read_s32(&dyn->dyn32.d_tag, content, pos, length, format->endian); - result &= read_u32(&dyn->dyn32.d_un.d_val, content, pos, length, format->endian); + result = g_binary_content_read_s32(content, &pos, format->endian, &dyn->dyn32.d_tag); + result &= g_binary_content_read_u32(content, &pos, format->endian, &dyn->dyn32.d_un.d_val); } else { - result = read_s64(&dyn->dyn64.d_tag, content, pos, length, format->endian); - result &= read_u64(&dyn->dyn64.d_un.d_val, content, pos, length, format->endian); + result = g_binary_content_read_s64(content, &pos, format->endian, &dyn->dyn64.d_tag); + result &= g_binary_content_read_u64(content, &pos, format->endian, &dyn->dyn64.d_un.d_val); } return result; @@ -300,34 +295,38 @@ bool read_elf_dynamic_entry(const GElfFormat *format, off_t *pos, elf_dyn *dyn) * * ******************************************************************************/ -bool read_elf_symbol(const GElfFormat *format, off_t *pos, elf_sym *sym) +bool read_elf_symbol(const GElfFormat *format, phys_t *phys, elf_sym *sym) { bool result; /* Bilan à retourner */ - const bin_t *content; /* Contenu binaire à lire */ - off_t length; /* Taille totale du contenu */ + const GBinContent *content; /* Contenu binaire à lire */ + vmpa2t pos; /* Position de lecture */ content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + + init_vmpa(&pos, *phys, VMPA_NO_VIRTUAL); if (format->is_32b) { - result = read_u32(&sym->sym32.st_name, content, pos, length, format->endian); - result &= read_u32(&sym->sym32.st_value, content, pos, length, format->endian); - result &= read_u32(&sym->sym32.st_size, content, pos, length, format->endian); - result &= read_u8(&sym->sym32.st_info, content, pos, length, format->endian); - result &= read_u8(&sym->sym32.st_other, content, pos, length, format->endian); - result &= read_u16(&sym->sym32.st_shndx, content, pos, length, format->endian); + result = g_binary_content_read_u32(content, &pos, format->endian, &sym->sym32.st_name); + result &= g_binary_content_read_u32(content, &pos, format->endian, &sym->sym32.st_value); + result &= g_binary_content_read_u32(content, &pos, format->endian, &sym->sym32.st_size); + result &= g_binary_content_read_u8(content, &pos, &sym->sym32.st_info); + result &= g_binary_content_read_u8(content, &pos, &sym->sym32.st_other); + result &= g_binary_content_read_u16(content, &pos, format->endian, &sym->sym32.st_shndx); } else { - result = read_u32(&sym->sym64.st_name, content, pos, length, format->endian); - result &= read_u8(&sym->sym64.st_info, content, pos, length, format->endian); - result &= read_u8(&sym->sym64.st_other, content, pos, length, format->endian); - result &= read_u16(&sym->sym64.st_shndx, content, pos, length, format->endian); - result &= read_u64(&sym->sym64.st_value, content, pos, length, format->endian); - result &= read_u64(&sym->sym64.st_size, content, pos, length, format->endian); + result = g_binary_content_read_u32(content, &pos, format->endian, &sym->sym64.st_name); + result &= g_binary_content_read_u8(content, &pos, &sym->sym64.st_info); + result &= g_binary_content_read_u8(content, &pos, &sym->sym64.st_other); + result &= g_binary_content_read_u16(content, &pos, format->endian, &sym->sym64.st_shndx); + result &= g_binary_content_read_u64(content, &pos, format->endian, &sym->sym64.st_value); + result &= g_binary_content_read_u64(content, &pos, format->endian, &sym->sym64.st_size); } + if (result) + *phys = get_phy_addr(&pos); + return result; } @@ -336,7 +335,7 @@ bool read_elf_symbol(const GElfFormat *format, off_t *pos, elf_sym *sym) /****************************************************************************** * * * Paramètres : format = informations chargées à consulter. * -* pos = position de début de lecture. [OUT] * +* phys = position de début de lecture. [OUT] * * reloc = structure lue à retourner. [OUT] * * * * Description : Procède à la lecture d'une relocalisation ELF. * @@ -347,26 +346,30 @@ bool read_elf_symbol(const GElfFormat *format, off_t *pos, elf_sym *sym) * * ******************************************************************************/ -bool read_elf_relocation(const GElfFormat *format, off_t *pos, elf_rel *reloc) +bool read_elf_relocation(const GElfFormat *format, phys_t *phys, elf_rel *reloc) { bool result; /* Bilan à retourner */ - const bin_t *content; /* Contenu binaire à lire */ - off_t length; /* Taille totale du contenu */ + const GBinContent *content; /* Contenu binaire à lire */ + vmpa2t pos; /* Position de lecture */ content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + + init_vmpa(&pos, *phys, VMPA_NO_VIRTUAL); if (format->is_32b) { - result = read_u32(&reloc->rel32.r_offset, content, pos, length, format->endian); - result &= read_u32(&reloc->rel32.r_info, content, pos, length, format->endian); + result = g_binary_content_read_u32(content, &pos, format->endian, &reloc->rel32.r_offset); + result &= g_binary_content_read_u32(content, &pos, format->endian, &reloc->rel32.r_info); } else { - result = read_u64(&reloc->rel64.r_offset, content, pos, length, format->endian); - result &= read_u64(&reloc->rel64.r_info, content, pos, length, format->endian); + result = g_binary_content_read_u64(content, &pos, format->endian, &reloc->rel64.r_offset); + result &= g_binary_content_read_u64(content, &pos, format->endian, &reloc->rel64.r_info); } + if (result) + *phys = get_phy_addr(&pos); + return result; } diff --git a/src/format/elf/elf-int.h b/src/format/elf/elf-int.h index fd0b74d..e0ae03b 100644 --- a/src/format/elf/elf-int.h +++ b/src/format/elf/elf-int.h @@ -56,19 +56,19 @@ struct _GElfFormatClass 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 *); +bool read_elf_program_header(const GElfFormat *, phys_t, elf_phdr *); /* Procède à la lecture d'une en-tête de section ELF. */ -bool read_elf_section_header(const GElfFormat *, off_t, elf_shdr *); +bool read_elf_section_header(const GElfFormat *, phys_t, elf_shdr *); /* Procède à la lecture d'une entrée de type 'DYNAMIC' ELF. */ -bool read_elf_dynamic_entry(const GElfFormat *, off_t *, elf_dyn *); +bool read_elf_dynamic_entry(const GElfFormat *, phys_t, elf_dyn *); /* Procède à la lecture d'un symbole ELF. */ -bool read_elf_symbol(const GElfFormat *, off_t *, elf_sym *); +bool read_elf_symbol(const GElfFormat *, phys_t *, elf_sym *); /* Procède à la lecture d'une relocalisation ELF. */ -bool read_elf_relocation(const GElfFormat *, off_t *, elf_rel *); +bool read_elf_relocation(const GElfFormat *, phys_t *, elf_rel *); diff --git a/src/format/elf/helper_arm.c b/src/format/elf/helper_arm.c index c77df55..cd2d922 100644 --- a/src/format/elf/helper_arm.c +++ b/src/format/elf/helper_arm.c @@ -53,9 +53,9 @@ bool load_elf_arm_relocated_symbols(GElfFormat *format, const elf_shdr *relxxx, const elf_shdr *dynsym, const elf_shdr *dynstr) { bool result; /* Bilan à retourner */ - off_t rel_start; /* Début de la zone à traiter */ - off_t rel_size; /* Taille de cette même zone */ - off_t iter; /* Boucle de parcours */ + phys_t rel_start; /* Début de la zone à traiter */ + phys_t rel_size; /* Taille de cette même zone */ + phys_t iter; /* Boucle de parcours */ elf_rel reloc; /* Infos de relocalisation */ off_t index; /* Indice de la portion visée */ elf_sym sym; /* Définition complète */ @@ -79,10 +79,6 @@ bool load_elf_arm_relocated_symbols(GElfFormat *format, const elf_shdr *relxxx, get_elf_section_content(format, relxxx, &rel_start, &rel_size, NULL); - printf("rel :: %d -> %d\n", rel_start, rel_start + rel_size); - - - for (iter = rel_start; iter < (rel_start + rel_size); ) { result = read_elf_relocation(format, &iter, &reloc); @@ -147,432 +143,3 @@ bool load_elf_arm_relocated_symbols(GElfFormat *format, const elf_shdr *relxxx, return result; } - - - - - - - - - - - - - - - - - - - - - - - -#if 0 - -#include <malloc.h> -#include <stdio.h> -#include <string.h> - - -#include "elf-int.h" -#include "../symbol.h" -#include "../mangling/demangler.h" -#include "../../arch/immediate.h" -#include "../../arch/processor.h" -#include "../../arch/x86/instruction.h" - - -// Désactivation -#define g_x86_instruction_get_opcode(i) 0 - - -/* symbols.c : Récupère la désignation d'un symbole donné. */ -extern const char *get_elf_symbol_name(GElfFormat *, const elf_shdr *, const elf_shdr *, off_t); - - -/* Décode les instructions liées à la relocalisation. */ -GArchInstruction **decode_elf_relocations(GElfFormat *, const elf_shdr *, size_t *); - -/* Déduit les adresses effectives des relocalisations. */ -void translate_exe_elf_relocations(GElfFormat *, GArchInstruction **, size_t); - -/* Déduit les adresses effectives des relocalisations. */ -void translate_dyn_elf_relocations(GElfFormat *, GArchInstruction **, size_t, const elf_shdr *, const elf_shdr *, const elf_shdr *); - - - -/****************************************************************************** -* * -* Paramètres : format = description de l'exécutable à compléter. * -* relxxx = section .rel.xxx trouvée (zone à traiter). * -* dynsym = section .dynsym trouvée (info. dynamiques). * -* dynstr = section .dynstr trouvée (chaînes de caractères). * -* * -* Description : Charge en mémoire la liste des symboles dynamiques. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool load_elf_x86_relocated_symbols(GElfFormat *format, const elf_shdr *relxxx, const elf_shdr *dynsym, const elf_shdr *dynstr) -{ - bool result; /* Bilan à retourner */ - off_t rel_start; /* Début de la zone à traiter */ - off_t rel_size; /* Taille de cette même zone */ - off_t iter; /* Boucle de parcours */ - elf_rel reloc; /* Infos de relocalisation */ - off_t index; /* Indice de la portion visée */ - const char *name; /* Nom du symbole trouvé */ - GBinSymbol *symbol; /* Nouveau symbole construit */ - - - - - result = true; - - - - get_elf_section_content(format, relxxx, &rel_start, &rel_size, NULL); - - - printf("rel :: %d -> %d\n", rel_start, rel_start + rel_size); - - - - for (iter = rel_start; iter < (rel_start + rel_size); ) - { - result = read_elf_relocation(format, &iter, &reloc); - if (!result) break; - - switch (ELF_REL_TYPE(format, reloc)) - { - case R_386_NONE: - break; - - case R_386_JMP_SLOT: - - index = ELF_REL_SYM(format, reloc); - name = get_elf_symbol_name(format, dynsym, dynstr, index); - - - //printf("got a jump ! >> %d - %s\n", index, name); - - - if (name == NULL) - { - /* FIXME */ - name = "unknown"; - } - - symbol = g_binary_symbol_new(STP_FUNCTION); - g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol); - - break; - - default: - printf("Relocation not supported (%lld) !\n", ELF_REL_TYPE(format, reloc)); - break; - - } - - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : format = description de l'exécutable à compléter. * -* plt = section .plt trouvée (points d'entrées dynamiques). * -* rel = section .rel.plt présentant la table des symboles. * -* dynsym = section listant tous les symboles. * -* dynstr = section contenant le nom de ces symboles. * -* * -* Description : Déduit les adresses effectives des appels externes. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool find_elf_x86_dynamic_symbols(GElfFormat *format, const elf_shdr *plt, const elf_shdr *rel, const elf_shdr *dynsym, const elf_shdr *dynstr) -{ - GArchInstruction **instructions; /* Instructions décodées */ - size_t count; /* Quantité d'instructions */ - size_t i; /* Boucle de parcours */ - - instructions = decode_elf_relocations(format, plt, &count); - - switch (ELF_HDR(format, format->header, e_type)) - { - case ET_EXEC: - translate_exe_elf_relocations(format, instructions, count); - break; - - case ET_DYN: - translate_dyn_elf_relocations(format, instructions, count, rel, dynsym, dynstr); - break; - - } - - for (i = 0; i < count; i++) - /* TODO : free instructions[i] */; - - if (instructions != NULL) - free(instructions); - - return true; - -} - - -/****************************************************************************** -* * -* Paramètres : format = description de l'exécutable à compléter. * -* plt = section .plt trouvée (points d'entrées dynamiques). * -* count = nombre d'instructions lues. [OUT] * -* * -* Description : Décode les instructions liées à la relocalisation. * -* * -* Retour : Liste des instructions décodées ou NULL. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GArchInstruction **decode_elf_relocations(GElfFormat *format, const elf_shdr *plt, size_t *count) -{ - GArchInstruction **result; /* Liste à renvoyer */ - off_t plt_start; /* Début de section */ - off_t plt_size; /* Taille de section */ - vmpa_t plt_address; /* Adresse virtuelle associée */ - GArchProcessor *proc; /* Processeur pour le décodage */ - off_t pos; /* Tête de lecture */ - vmpa_t address; /* Adresse virtuelle courante */ - GArchInstruction *instr; /* Instruction décodée */ - - result = NULL; - *count = 0; - - get_elf_section_content(format, plt, &plt_start, &plt_size, &plt_address); - - proc = NULL;//get_arch_processor_for_type(APT_386); - - for (pos = 0; pos < plt_size; ) - { - address = plt_address + pos; - - instr = g_arch_processor_decode_instruction(proc, NULL /*FIXME*/, &G_BIN_FORMAT(format)->content[plt_start], - &pos, plt_size, address, NULL /*FIXME*/); - - result = (GArchInstruction **)realloc(result, ++(*count) * sizeof(GArchInstruction *)); - result[*count - 1] = instr; - - } - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : format = description de l'exécutable à compléter. * -* instructions = listes des instructions à interpréter. * -* count = nombre d'instructions lues. * -* * -* Description : Déduit les adresses effectives des relocalisations. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void translate_exe_elf_relocations(GElfFormat *format, GArchInstruction **instructions, size_t count) -{ - size_t i; /* Boucle de parcours #1 */ - X86Opcodes opcode_n0; /* Opcode de l'instruction n */ - X86Opcodes opcode_n1; /* Opcode de l'instruction n+1 */ - X86Opcodes opcode_n2; /* Opcode de l'instruction n+2 */ - const GArchOperand *operand; /* Valeur du saut */ - vmpa_t address; /* Adresse virtuelle finale */ - GBinSymbol **symbols; /* Liste des symboles existants*/ - size_t symbols_count; /* Taille de cette liste */ - size_t j; /* Boucle de parcours #2 */ - size_t new_len; /* Taille du nouveau nom */ - char *new_name; /* Nom avec suffixe @plt */ - GBinRoutine *routine; /* Nouvelle routine déduite */ - GBinSymbol *symbol; /* Nouveau symbole construit */ - - for (i = 0; (i + 2) < count; ) - { - opcode_n0 = g_x86_instruction_get_opcode(G_X86_INSTRUCTION(instructions[i])); - opcode_n1 = g_x86_instruction_get_opcode(G_X86_INSTRUCTION(instructions[i + 1])); - opcode_n2 = g_x86_instruction_get_opcode(G_X86_INSTRUCTION(instructions[i + 2])); - - if (opcode_n0 == XOP_JMP_RM1632 - && opcode_n1 == XOP_PUSH_IMM1632 - && opcode_n2 == XOP_JMP_REL1632) - { - operand = g_arch_instruction_get_operand(instructions[i], 0); - - if (g_imm_operand_to_vmpa_t(G_IMM_OPERAND(operand), &address)) - { - symbols = g_binary_format_get_symbols(G_BIN_FORMAT(format), &symbols_count); - - for (j = 0; j < symbols_count; j++) - if (0 /* FIXME g_binary_symbol_get_address(symbols[j]) == address*/) - { - /* Nom final */ - - new_len = strlen(g_binary_symbol_get_label(symbols[j])) + 4 + 1; - new_name = calloc(new_len, sizeof(char)); - snprintf(new_name, new_len, "%s@plt", g_binary_symbol_get_label(symbols[j])); - - g_arch_instruction_get_location(instructions[i], NULL, NULL, &address); - - /* Routine */ - - routine = try_to_demangle_routine(g_binary_symbol_get_label(symbols[j])); - - ///g_binary_routine_set_address(routine, address); - - ///// reactiver g_binary_format_add_routine(G_BIN_FORMAT(format), routine); - - /* Symbole uniquement */ - - symbol = g_binary_symbol_new(STP_FUNCTION); - - g_binary_symbol_attach_routine(symbol, routine); - - g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol); - - break; - - } - - } - - i += 3; - - } - else i++; - - } - -} - - -/****************************************************************************** -* * -* Paramètres : format = description de l'exécutable à compléter. * -* instructions = listes des instructions à interpréter. * -* count = nombre d'instructions lues. * -* * -* Description : Déduit les adresses effectives des relocalisations. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void translate_dyn_elf_relocations(GElfFormat *format, GArchInstruction **instructions, size_t count, const elf_shdr *rel, const elf_shdr *dynsym, const elf_shdr *dynstr) -{ - off_t rel_start; /* Début de la zone à traiter */ - off_t rel_size; /* Taille de cette même zone */ - size_t i; /* Boucle de parcours #1 */ - X86Opcodes opcode_n0; /* Opcode de l'instruction n */ - X86Opcodes opcode_n1; /* Opcode de l'instruction n+1 */ - X86Opcodes opcode_n2; /* Opcode de l'instruction n+2 */ - const GArchOperand *operand; /* Valeur du saut */ - off_t pos; /* Tête de lecture */ - bool negative; /* Tête de lecture invalide ? */ - elf_rel reloc; /* Infos de relocalisation */ - off_t index; /* Indice de la portion visée */ - const char *name; /* Nom du symbole trouvé */ - size_t new_len; /* Taille du nouveau nom */ - char *new_name; /* Nom avec suffixe @plt */ - vmpa_t address; /* Adresse virtuelle finale */ - GBinRoutine *routine; /* Nouvelle routine déduite */ - GBinSymbol *symbol; /* Nouveau symbole construit */ - - get_elf_section_content(format, rel, &rel_start, &rel_size, NULL); - - for (i = 0; (i + 2) < count; ) - { - opcode_n0 = g_x86_instruction_get_opcode(G_X86_INSTRUCTION(instructions[i])); - opcode_n1 = g_x86_instruction_get_opcode(G_X86_INSTRUCTION(instructions[i + 1])); - opcode_n2 = g_x86_instruction_get_opcode(G_X86_INSTRUCTION(instructions[i + 2])); - - if (opcode_n0 == XOP_JMP_RM1632 - && opcode_n1 == XOP_PUSH_IMM1632 - && opcode_n2 == XOP_JMP_REL1632) - { - operand = g_arch_instruction_get_operand(instructions[i + 1], 0); - - if (!g_imm_operand_to_off_t(G_IMM_OPERAND(operand), &pos, &negative)) - goto next_op; - - if ((pos + ELF_SIZEOF_REL(format)) > rel_size) - goto next_op; - - pos += rel_start; - - if (!read_elf_relocation(format, &pos, &reloc)) - goto next_op; - - index = ELF_REL_SYM(format, reloc); - name = get_elf_symbol_name(format, dynsym, dynstr, index); - - if (name == NULL) - { - /* FIXME */ - name = "unknown"; - } - - /* Nom final */ - - new_len = strlen(name) + 4 + 1; - new_name = calloc(new_len, sizeof(char)); - snprintf(new_name, new_len, "%s@plt", name); - - g_arch_instruction_get_location(instructions[i], NULL, NULL, &address); - - /* Routine */ - - routine = try_to_demangle_routine(name); - - ////g_binary_routine_set_address(routine, address); - - ///// reactiver g_binary_format_add_routine(G_BIN_FORMAT(format), routine); - - /* Symbole uniquement */ - - symbol = g_binary_symbol_new(STP_FUNCTION); - - g_binary_symbol_attach_routine(symbol, routine); - - g_binary_format_add_symbol(G_BIN_FORMAT(format), symbol); - - next_op: - - i += 3; - - } - else i++; - - } - -} - -#endif diff --git a/src/format/elf/helper_x86.c b/src/format/elf/helper_x86.c index deb1ead..da71214 100644 --- a/src/format/elf/helper_x86.c +++ b/src/format/elf/helper_x86.c @@ -24,6 +24,25 @@ #include "helper_x86.h" + +bool load_elf_x86_relocated_symbols(GElfFormat *a, const elf_shdr *b, const elf_shdr *c, const elf_shdr *d) +{ + return false; +} + +/* Déduit les adresses effectives des appels externes. */ +bool find_elf_x86_dynamic_symbols(GElfFormat *a, const elf_shdr *b, const elf_shdr *c, const elf_shdr *d, const elf_shdr *e) +{ + return false; +} + + + + + + +#if 0 + #include <malloc.h> #include <stdio.h> #include <string.h> @@ -98,7 +117,7 @@ bool load_elf_x86_relocated_symbols(GElfFormat *format, const elf_shdr *relxxx, for (iter = rel_start; iter < (rel_start + rel_size); ) { - result = read_elf_relocation(format, &iter, &reloc); + result = false;//read_elf_relocation(format, &iter, &reloc); if (!result) break; switch (ELF_REL_TYPE(format, reloc)) @@ -380,7 +399,7 @@ void translate_dyn_elf_relocations(GElfFormat *format, GArchInstruction **instru pos += rel_start; - if (!read_elf_relocation(format, &pos, &reloc)) + if (!false/*read_elf_relocation(format, &pos, &reloc)*/) goto next_op; index = ELF_REL_SYM(format, reloc); @@ -426,3 +445,5 @@ void translate_dyn_elf_relocations(GElfFormat *format, GArchInstruction **instru } } + +#endif diff --git a/src/format/elf/section.c b/src/format/elf/section.c index 3feb869..2b46d9e 100644 --- a/src/format/elf/section.c +++ b/src/format/elf/section.c @@ -48,7 +48,7 @@ bool find_elf_section_by_index(const GElfFormat *format, uint16_t index, elf_shdr *section) { - off_t offset; /* Emplacement à venir lire */ + phys_t offset; /* Emplacement à venir lire */ if (index >= ELF_HDR(format, format->header, e_shnum)) return false; @@ -118,7 +118,7 @@ bool find_elf_section_by_name(const GElfFormat *format, const char *name, elf_sh * * ******************************************************************************/ -bool find_elf_section_by_virtual_address(const GElfFormat *format, uint32_t addr, elf_shdr *section) +bool find_elf_section_by_virtual_address(const GElfFormat *format, virt_t addr, elf_shdr *section) { bool result; /* Bilan à faire remonter */ uint16_t i; /* Boucle de parcours */ @@ -194,7 +194,7 @@ bool find_elf_sections_by_type(const GElfFormat *format, uint32_t type, elf_shdr * * ******************************************************************************/ -void get_elf_section_content(const GElfFormat *format, const elf_shdr *section, off_t *offset, off_t *size, vmpa_t *addr) +void get_elf_section_content(const GElfFormat *format, const elf_shdr *section, phys_t *offset, phys_t *size, virt_t *addr) { *offset = ELF_SHDR(format, *section, sh_offset); *size = ELF_SHDR(format, *section, sh_size); @@ -221,7 +221,7 @@ void get_elf_section_content(const GElfFormat *format, const elf_shdr *section, * * ******************************************************************************/ -bool find_elf_section_content_by_name(const GElfFormat *format, const char *name, off_t *offset, off_t *size, vmpa_t *address) +bool find_elf_section_content_by_name(const GElfFormat *format, const char *name, phys_t *offset, phys_t *size, virt_t *address) { bool result; /* Bilan à retourner */ elf_shdr section; /* Section trouvée ou non */ @@ -253,24 +253,25 @@ bool find_elf_section_content_by_name(const GElfFormat *format, const char *name const char *extract_name_from_elf_string_section(const GElfFormat *format, const elf_shdr *section, off_t index) { const char *result; /* Nom trouvé à renvoyer */ - const bin_t *content; /* Contenu binaire à lire */ - off_t length; /* Taille totale du contenu */ - off_t last; /* Dernier '\0' possible */ - off_t pos; /* Point de lecture */ - - content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + phys_t last; /* Dernier '\0' possible */ + phys_t phys; /* Point de lecture physique */ + vmpa2t pos; /* Position de lecture */ + const GBinContent *content; /* Contenu binaire à lire */ last = ELF_SHDR(format, *section, sh_offset) + ELF_SHDR(format, *section, sh_size); - pos = ELF_SHDR(format, *section, sh_offset) + index; + phys = ELF_SHDR(format, *section, sh_offset) + index; - if ((pos + 1) >= MIN(length, last)) + if ((phys + 1) >= last) return NULL; - result = (const char *)&content[pos]; + init_vmpa(&pos, phys, VMPA_NO_VIRTUAL); + + content = G_BIN_FORMAT(format)->content; + + result = (const char *)g_binary_content_get_raw_access(content, &pos, 1); - if ((pos + strlen(result)) > last) + if ((phys + strlen(result)) > last) return NULL; return result; diff --git a/src/format/elf/section.h b/src/format/elf/section.h index e300ee3..4da3df9 100644 --- a/src/format/elf/section.h +++ b/src/format/elf/section.h @@ -37,16 +37,16 @@ bool find_elf_section_by_index(const GElfFormat *, uint16_t, elf_shdr *); bool find_elf_section_by_name(const GElfFormat *, const char *, elf_shdr *); /* Recherche une section donnée au sein de binaire par type. */ -bool find_elf_section_by_virtual_address(const GElfFormat *, uint32_t, elf_shdr *); +bool find_elf_section_by_virtual_address(const GElfFormat *, virt_t, elf_shdr *); /* Recherche une section donnée au sein de binaire par type. */ bool find_elf_sections_by_type(const GElfFormat *, uint32_t, elf_shdr **, size_t *); /* Fournit les adresses et taille contenues dans une section. */ -void get_elf_section_content(const GElfFormat *, const elf_shdr *, off_t *, off_t *, vmpa_t *); +void get_elf_section_content(const GElfFormat *, const elf_shdr *, phys_t *, phys_t *, virt_t *); /* Recherche une zone donnée au sein de binaire par nom. */ -bool find_elf_section_content_by_name(const GElfFormat *, const char *, off_t *, off_t *, vmpa_t *); +bool find_elf_section_content_by_name(const GElfFormat *, const char *, phys_t *, phys_t *, virt_t *); /* Identifie une chaîne de caractères dans une section adéquate. */ const char *extract_name_from_elf_string_section(const GElfFormat *, const elf_shdr *, off_t); diff --git a/src/format/elf/strings.c b/src/format/elf/strings.c index 6832f5b..4d8a32e 100644 --- a/src/format/elf/strings.c +++ b/src/format/elf/strings.c @@ -37,7 +37,7 @@ /* Enregistre toutes les chaînes de caractères trouvées. */ -bool parse_elf_string_data(GElfFormat *, off_t, off_t, vmpa_t); +bool parse_elf_string_data(GElfFormat *, phys_t, phys_t, virt_t); @@ -56,14 +56,14 @@ bool parse_elf_string_data(GElfFormat *, off_t, off_t, vmpa_t); bool find_all_elf_strings(GElfFormat *format) { bool got_string; /* Indique un remplissage */ - off_t str_start; /* Début de section */ - off_t str_size; /* Taille de section */ - vmpa_t str_addr; /* Adresse virtuelle associée */ + phys_t str_start; /* Début de section */ + phys_t str_size; /* Taille de section */ + virt_t str_addr; /* Adresse virtuelle associée */ elf_shdr *sections; /* Groupe de sections trouvées */ size_t count; /* Quantité de données */ size_t i; /* Boucle de parcours #1 */ - off_t length; /* Taille totale du contenu */ - off_t iter; /* Boucle de parcours #2 */ + phys_t max; /* Borne à ne pas dépasser */ + phys_t iter; /* Boucle de parcours #2 */ elf_phdr phdr; /* En-tête de programme ELF */ got_string = false; @@ -109,10 +109,10 @@ bool find_all_elf_strings(GElfFormat *format) if (!got_string) { - length = G_BIN_FORMAT(format)->length; - length = MIN(length, ELF_HDR(format, format->header, e_phnum) * ELF_SIZEOF_PHDR(format)); + max = ELF_HDR(format, format->header, e_phoff) + + ELF_HDR(format, format->header, e_phnum) * ELF_SIZEOF_PHDR(format); - for (iter = ELF_HDR(format, format->header, e_phoff); iter < length; iter += ELF_SIZEOF_PHDR(format)) + for (iter = ELF_HDR(format, format->header, e_phoff); iter < max; iter += ELF_SIZEOF_PHDR(format)) { if (!read_elf_program_header(format, iter, &phdr)) continue; @@ -148,7 +148,7 @@ bool find_all_elf_strings(GElfFormat *format) * * ******************************************************************************/ -bool parse_elf_string_data(GElfFormat *format, off_t start, off_t size, vmpa_t address) +bool parse_elf_string_data(GElfFormat *format, phys_t start, phys_t size, virt_t address) { bool result; /* Bilan à faire remonter */ GBinContent *content; /* Contenu binaire à lire */ @@ -167,7 +167,7 @@ bool parse_elf_string_data(GElfFormat *format, off_t start, off_t size, vmpa_t a /* Préparation des accès */ - content = g_binary_format_get_conten_(G_BIN_FORMAT(format)); + content = g_binary_format_get_content(G_BIN_FORMAT(format)); data = (char *)malloc(size * sizeof(char)); @@ -194,7 +194,7 @@ bool parse_elf_string_data(GElfFormat *format, off_t start, off_t size, vmpa_t a init_vmpa(&pos, start + i, address + i); - instr = g_raw_instruction_new_array(G_BIN_FORMAT(format)->conten_, MDS_8_BITS, + instr = g_raw_instruction_new_array(G_BIN_FORMAT(format)->content, MDS_8_BITS, end - i, &pos, format->endian); g_raw_instruction_mark_as_string(G_RAW_INSTRUCTION(instr), true); @@ -227,6 +227,8 @@ bool parse_elf_string_data(GElfFormat *format, off_t start, off_t size, vmpa_t a pesd_error: + g_object_unref(G_OBJECT(content)); + free(data); return result; diff --git a/src/format/elf/symbols.c b/src/format/elf/symbols.c index 1fa3d0e..04c584d 100644 --- a/src/format/elf/symbols.c +++ b/src/format/elf/symbols.c @@ -188,15 +188,11 @@ static void register_elf_entry_point(GElfFormat *format, virt_t vaddr, phys_t le routine = g_binary_symbol_get_routine(symbol); g_object_ref(G_OBJECT(routine)); - printf(" -- SYM CHANGE @ 0x%08x\n", vaddr); - _g_binary_symbol_attach_routine(symbol, routine, STP_ENTRY_POINT); } else { - printf(" -- SYM ENTRY @ 0x%08x\n", vaddr); - init_mrange(&range, &addr, len); g_binary_routine_set_range(routine, &range); @@ -229,10 +225,10 @@ static bool load_all_elf_basic_entry_points(GElfFormat *format) elf_phdr dynamic; /* En-tête de programme DYNAMIC*/ elf_dyn item_a; /* Premier élément DYNAMIC */ elf_dyn item_b; /* Second élément DYNAMIC */ - const bin_t *content; /* Contenu binaire à lire */ - off_t length; /* Taille totale du contenu */ + const GBinContent *content; /* Contenu binaire à lire */ + phys_t length; /* Taille totale du contenu */ bool status; /* Bilan d'une opération */ - off_t pos; /* Tête de lecture courante */ + vmpa2t pos; /* Tête de lecture courante */ uint32_t virt_32; /* Adresse virtuelle sur 32b */ uint64_t virt_64; /* Adresse virtuelle sur 64b */ @@ -285,26 +281,24 @@ static bool load_all_elf_basic_entry_points(GElfFormat *format) assert(sizeof(fullname) >= (strlen(prefix) + sizeof(XSTR(UINT64_MAX) + 1))); content = G_BIN_FORMAT(fmt)->content; - length = G_BIN_FORMAT(fmt)->length; - status = g_exe_format_translate_address_into_offset(G_EXE_FORMAT(format), - ELF_DYN(fmt, *ar, d_un.d_val), - &pos); + status = g_exe_format_translate_address_into_vmpa(G_EXE_FORMAT(format), + ELF_DYN(fmt, *ar, d_un.d_val), + &pos); if (!status) return; - if ((pos + ELF_DYN(fmt, *sz, d_un.d_val)) < length) - length = pos + ELF_DYN(fmt, *sz, d_un.d_val); + length = get_phy_addr(&pos) + ELF_DYN(fmt, *sz, d_un.d_val); - for (i = 0; pos < length; i++) + for (i = 0; get_phy_addr(&pos) < length; i++) { if (fmt->is_32b) { - status = read_u32(&virt_32, content, &pos, length, fmt->endian); + status = g_binary_content_read_u32(content, &pos, fmt->endian, &virt_32); ep = virt_32; } else { - status = read_u64(&virt_64, content, &pos, length, fmt->endian); + status = g_binary_content_read_u64(content, &pos, fmt->endian, &virt_64); ep = virt_64; } @@ -354,31 +348,30 @@ static bool load_all_elf_basic_entry_points(GElfFormat *format) if (find_elf_dynamic_item_from_pheader(format, &dynamic, DT_PLTGOT, &item_a)) { - status = g_exe_format_translate_address_into_offset(G_EXE_FORMAT(format), - ELF_DYN(format, item_a, d_un.d_val), - &pos); + status = g_exe_format_translate_address_into_vmpa(G_EXE_FORMAT(format), + ELF_DYN(format, item_a, d_un.d_val), + &pos); if (status) { content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; /* On saute le premier élément... */ if (format->is_32b) - status = read_u32(&virt_32, content, &pos, length, format->endian); + status = g_binary_content_read_u32(content, &pos, format->endian, &virt_32); else - status = read_u64(&virt_64, content, &pos, length, format->endian); + status = g_binary_content_read_u64(content, &pos, format->endian, &virt_64); while (1) { if (format->is_32b) { - status = read_u32(&virt_32, content, &pos, length, format->endian); + status = g_binary_content_read_u32(content, &pos, format->endian, &virt_32); ep = virt_32; } else { - status = read_u64(&virt_64, content, &pos, length, format->endian); + status = g_binary_content_read_u64(content, &pos, format->endian, &virt_64); ep = virt_64; } @@ -428,9 +421,9 @@ static bool load_all_elf_basic_entry_points(GElfFormat *format) bool get_elf_symbol_by_index(GElfFormat *format, const elf_shdr *sym, off_t index, elf_sym *symbol) { - off_t sym_start; /* Début de section */ - off_t sym_size; /* Taille de section */ - off_t offset; /* Emplacement à venir lire */ + phys_t sym_start; /* Début de section */ + phys_t sym_size; /* Taille de section */ + phys_t offset; /* Emplacement à venir lire */ get_elf_section_content(format, sym, &sym_start, &sym_size, NULL); @@ -505,9 +498,9 @@ static bool load_elf_internal_symbols(GElfFormat *format) { elf_shdr strtab; /* Section .strtab trouvée */ bool has_strtab; /* Présence de cette section */ - off_t start; /* Début de la zone à traiter */ - off_t size; /* Taille de cette même zone */ - off_t iter; /* Boucle de parcours */ + phys_t start; /* Début de la zone à traiter */ + phys_t size; /* Taille de cette même zone */ + phys_t iter; /* Boucle de parcours */ elf_sym sym; /* Symbole aux infos visées */ virt_t virt; /* Adresse virtuelle */ vmpa2t addr; /* Localisation d'une routine */ @@ -682,50 +675,48 @@ static bool load_elf_internal_symbols(GElfFormat *format) static bool find_elf_dynamic_item(const GElfFormat *format, const elf_shdr *section, int32_t type, elf_dyn *item) { bool result; /* Bilan à retourner */ - const bin_t *content; /* Contenu binaire à lire */ - off_t length; /* Taille totale du contenu */ - off_t pos; /* Position de lecture */ - off_t tmp; /* Position écrasable */ + const GBinContent *content; /* Contenu binaire à lire */ + phys_t pos; /* Position de lecture */ + vmpa2t tmp; /* Position écrasable */ int32_t tag32; /* Type de l'entrée (32 bits) */ int64_t tag64; /* Type de l'entrée (64 bits) */ result = true; content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; for (pos = ELF_SHDR(format, *section, sh_offset); - pos < length/* FIXME !! + xploit */ && result; + result; pos += ELF_SIZEOF_DYN(format)) { - tmp = pos; + init_vmpa(&tmp, pos, VMPA_NO_VIRTUAL); if (format->is_32b) { - result = read_s32(&tag32, content, &tmp, length, format->endian); + result = g_binary_content_read_s32(content, &tmp, format->endian, &tag32); if (tag32 == type) break; } else { - result = read_s64(&tag64, content, &tmp, length, format->endian); + result = g_binary_content_read_s64(content, &tmp, format->endian, &tag64); if (tag64 == type) break; } } - result &= (pos < length); - if (result) { + init_vmpa(&tmp, pos, VMPA_NO_VIRTUAL); + if (format->is_32b) { - result = read_s32(&item->dyn32.d_tag, content, &pos, length, format->endian); - result &= read_s32(&item->dyn32.d_un.d_val, content, &pos, length, format->endian); + result = g_binary_content_read_s32(content, &tmp, format->endian, &item->dyn32.d_tag); + result &= g_binary_content_read_s32(content, &tmp, format->endian, &item->dyn32.d_un.d_val); } else { - result = read_s64(&item->dyn64.d_tag, content, &pos, length, format->endian); - result &= read_s64(&item->dyn64.d_un.d_val, content, &pos, length, format->endian); + result = g_binary_content_read_s64(content, &tmp, format->endian, &item->dyn64.d_tag); + result &= g_binary_content_read_s64(content, &tmp, format->endian, &item->dyn64.d_un.d_val); } } diff --git a/src/format/executable.c b/src/format/executable.c index 1a66ffc..ab5543a 100644 --- a/src/format/executable.c +++ b/src/format/executable.c @@ -124,13 +124,16 @@ const char *g_exe_format_get_target_machine(const GExeFormat *format) GBinPortion *g_exe_format_get_portions(GExeFormat *format) { vmpa2t addr; /* Emplacement vide de sens */ + phys_t length; /* Taille de portion globale */ if (format->portions == NULL) { format->portions = g_binary_portion_new(BPC_RAW); init_vmpa(&addr, 0, VMPA_NO_VIRTUAL); - g_binary_portion_set_values(format->portions, &addr, G_BIN_FORMAT(format)->length); + length = g_binary_content_compute_size(G_BIN_FORMAT(format)->content); + + g_binary_portion_set_values(format->portions, &addr, length); if (format->refine_portions != NULL) format->refine_portions(format, format->portions); diff --git a/src/format/format-int.h b/src/format/format-int.h index 340264a..70f1021 100644 --- a/src/format/format-int.h +++ b/src/format/format-int.h @@ -41,9 +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 */ + GBinContent *content; /* Contenu binaire à étudier */ virt_t *entry_points; /* Points d'entrée du code */ size_t ep_count; /* Nombre de ces points */ @@ -73,7 +71,7 @@ struct _GBinFormatClass /* Définit le contenu binaire à analyser. */ -void g_binary_format_set_content(GBinFormat *, GBinContent *) __attribute__ ((deprecated)); +void g_binary_format_set_content(GBinFormat *, GBinContent *); diff --git a/src/format/format.c b/src/format/format.c index 3373af3..74549bc 100644 --- a/src/format/format.c +++ b/src/format/format.c @@ -119,10 +119,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); + format->content = content; } @@ -130,39 +127,24 @@ void g_binary_format_set_content(GBinFormat *format, GBinContent *content) /****************************************************************************** * * * Paramètres : format = description de l'exécutable à consulter. * -* length = taille du contenu à fournir. [OUT] * * * * Description : Fournit une référence vers le contenu binaire analysé. * * * -* Retour : Adresse du tampon contenant le contenu du binaire. * +* Retour : Gestionnaire de contenu binaire en place. * * * * Remarques : - * * * ******************************************************************************/ -const bin_t *g_binary_format_get_content(const GBinFormat *format, off_t *length) +GBinContent *g_binary_format_get_content(const GBinFormat *format) { - if (length != NULL) *length = format->length; + g_object_ref(G_OBJECT(format->content)); return format->content; } - - -GBinContent *g_binary_format_get_conten_(const GBinFormat *format) -{ - g_object_ref(G_OBJECT(format->conten_)); - - - return format->conten_; - -} - - - - /****************************************************************************** * * * Paramètres : format = description de l'exécutable à consulter. * diff --git a/src/format/format.h b/src/format/format.h index 51c542f..9fe23f4 100644 --- a/src/format/format.h +++ b/src/format/format.h @@ -55,11 +55,7 @@ typedef struct _GBinFormatClass GBinFormatClass; GType g_binary_format_get_type(void); /* Fournit une référence vers le contenu binaire analysé. */ -const bin_t *g_binary_format_get_content(const GBinFormat *, off_t *); - - -GBinContent *g_binary_format_get_conten_(const GBinFormat *); - +GBinContent *g_binary_format_get_content(const GBinFormat *); /* Fournit un contexte initialisé pour un désassemblage. */ void g_binary_format_setup_disassembling_context(const GBinFormat *, GProcContext *); diff --git a/src/format/java/java-int.c b/src/format/java/java-int.c index 2593f3c..a201d50 100644 --- a/src/format/java/java-int.c +++ b/src/format/java/java-int.c @@ -51,8 +51,8 @@ bool read_java_header(const GJavaFormat *format, off_t *pos, java_header *header uint32_t magic; /* Identifiant Java */ size_t i; /* Boucle de parcours */ - content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + content = NULL; //G_BIN_FORMAT(format)->content; + length = 0; //G_BIN_FORMAT(format)->length; result &= read_u32(&magic, content, pos, length, SRE_BIG); printf("magic :: 0x%08x\n", magic); diff --git a/src/format/java/pool.c b/src/format/java/pool.c index e90484e..f23cd41 100755 --- a/src/format/java/pool.c +++ b/src/format/java/pool.c @@ -61,8 +61,8 @@ bool load_java_pool(GJavaFormat *format, off_t *pos) uint16_t count; /* Nombre d'éléments présents */ uint16_t i; /* Boucle de parcours */ - result = read_u16(&count, G_BIN_FORMAT(format)->content, pos, - G_BIN_FORMAT(format)->length, SRE_BIG); + result = false/*read_u16(&count, G_BIN_FORMAT(format)->content, pos, + G_BIN_FORMAT(format)->length, SRE_BIG)*/; printf("Alloc %hu entries (result=%d)\n", count, result); @@ -86,8 +86,6 @@ bool load_java_pool(GJavaFormat *format, off_t *pos) } - printf("stop at %hd || pos :: %d - max %d\n", i, *pos, G_BIN_FORMAT(format)->length); - return result; } @@ -163,11 +161,11 @@ bool load_java_pool_entry(GJavaFormat *format, constant_pool_entry *entry, off_t uint64_t mantissa64; /* Mantisse du nombre lu 64b */ uint16_t length; /* Taille d'une chaîne */ - result = read_u8(&tag, G_BIN_FORMAT(format)->content, pos, - G_BIN_FORMAT(format)->length, SRE_BIG); + result = false/*read_u8(&tag, G_BIN_FORMAT(format)->content, pos, + G_BIN_FORMAT(format)->length, SRE_BIG)*/; entry->tag = tag; - +#if 0 switch (entry->tag) { case CONSTANT_CLASS: @@ -319,7 +317,7 @@ bool load_java_pool_entry(GJavaFormat *format, constant_pool_entry *entry, off_t break; } - +#endif return result; } diff --git a/src/format/pe/pe-int.c b/src/format/pe/pe-int.c index 8814ea0..bcffe62 100644 --- a/src/format/pe/pe-int.c +++ b/src/format/pe/pe-int.c @@ -53,8 +53,8 @@ bool read_dos_image_header(const GPeFormat *format, off_t *pos, image_dos_header off_t length; /* Taille totale du contenu */ size_t i; /* Boucle de parcours */ - content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + content = NULL; //G_BIN_FORMAT(format)->content; + length = 0; //G_BIN_FORMAT(format)->length; result = read_u16(&header->e_magic, content, pos, length, SRE_LITTLE); result &= read_u16(&header->e_cblp, content, pos, length, SRE_LITTLE); @@ -107,8 +107,8 @@ bool read_pe_file_header(const GPeFormat *format, off_t *pos, image_file_header const bin_t *content; /* Contenu binaire à lire */ off_t length; /* Taille totale du contenu */ - content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + content = NULL; //G_BIN_FORMAT(format)->content; + length = 0; //G_BIN_FORMAT(format)->length; result = read_u16(&header->machine, content, pos, length, SRE_LITTLE); result &= read_u16(&header->number_of_sections, content, pos, length, SRE_LITTLE); @@ -144,8 +144,8 @@ bool read_pe_optional_header(const GPeFormat *format, off_t *pos, image_optional off_t length; /* Taille totale du contenu */ uint32_t i; /* Boucle de parcours */ - content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + content = NULL; //G_BIN_FORMAT(format)->content; + length = 0; //G_BIN_FORMAT(format)->length; result = read_u16(&header->magic, content, pos, length, SRE_LITTLE); result &= read_u8(&header->major_linker_version, content, pos, length, SRE_LITTLE); @@ -209,8 +209,8 @@ bool read_pe_nt_header(const GPeFormat *format, off_t *pos, image_nt_headers *he const bin_t *content; /* Contenu binaire à lire */ off_t length; /* Taille totale du contenu */ - content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + content = NULL; //G_BIN_FORMAT(format)->content; + length = 0; //G_BIN_FORMAT(format)->length; result = read_u32(&header->signature, content, pos, length, SRE_LITTLE); @@ -243,8 +243,8 @@ bool read_pe_image_section_header(const GPeFormat *format, off_t *pos, image_sec off_t length; /* Taille totale du contenu */ size_t i; /* Boucle de parcours */ - content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + content = NULL; //G_BIN_FORMAT(format)->content; + length = 0; //G_BIN_FORMAT(format)->length; result = true; @@ -287,8 +287,8 @@ bool read_pe_image_import_descriptor(const GPeFormat *format, off_t *pos, image_ const bin_t *content; /* Contenu binaire à lire */ off_t length; /* Taille totale du contenu */ - content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + content = NULL; //G_BIN_FORMAT(format)->content; + length = 0; //G_BIN_FORMAT(format)->length; result = read_u32(&desc->original_first_thunk, content, pos, length, SRE_LITTLE); result &= read_u32(&desc->time_date_stamp, content, pos, length, SRE_LITTLE); @@ -324,8 +324,8 @@ bool read_pe_image_import_by_name(const GPeFormat *format, off_t *pos, image_imp off_t new_pos; /* Nouvelle tête de lecture */ size_t i; /* Boucle de parcours */ - content = G_BIN_FORMAT(format)->content; - length = G_BIN_FORMAT(format)->length; + content = NULL; //G_BIN_FORMAT(format)->content; + length = 0; //G_BIN_FORMAT(format)->length; result = read_u32(&link, content, pos, length, SRE_LITTLE); diff --git a/src/glibext/gbincontent.c b/src/glibext/gbincontent.c index 4ea0b03..0230e70 100644 --- a/src/glibext/gbincontent.c +++ b/src/glibext/gbincontent.c @@ -363,30 +363,64 @@ static const binary_part *g_binary_content_find_part(const GBinContent *content, * Paramètres : content = contenu binaire à venir lire. * * addr = position de la tête de lecture. * * length = quantité d'octets à lire. * -* out = réceptacle disponible pour ces données. [OUT] * * * -* Description : Fournit une portion des données représentées. * +* Description : Donne accès à une portion des données représentées. * * * -* Retour : Bilan de l'opération. * +* Retour : Pointeur vers les données à lire ou NULL en cas d'échec. * * * * Remarques : - * * * ******************************************************************************/ -bool g_binary_content_get_raw(const GBinContent *content, vmpa2t *addr, phys_t length, bin_t *out) +const bin_t *g_binary_content_get_raw_access(const GBinContent *content, vmpa2t *addr, phys_t length) { - bool result; - phys_t offset; + phys_t offset; /* Emplacement de départ */ /* FIXME */ offset = get_phy_addr(addr); - memcpy(out, &content->parts[0].data[offset], length); + if ((offset + length) >= get_mrange_length(&content->parts[0].range)) + return NULL; advance_vmpa(addr, length); - return true; + return &content->parts[0].data[offset]; + +} + + +/****************************************************************************** +* * +* Paramètres : content = contenu binaire à venir lire. * +* addr = position de la tête de lecture. * +* length = quantité d'octets à lire. * +* out = réceptacle disponible pour ces données. [OUT] * +* * +* Description : Fournit une portion des données représentées. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool g_binary_content_get_raw(const GBinContent *content, vmpa2t *addr, phys_t length, bin_t *out) +{ + bool result; /* Bilan à remonter */ + const bin_t *data; /* Pointeur vers données utiles*/ + + data = g_binary_content_get_raw_access(content, addr, length); + + if (data != NULL) + { + result = true; + memcpy(out, data, length); + } + else + result = false; + + return result; } @@ -447,7 +481,6 @@ bool g_binary_content_read_u4(const GBinContent *content, vmpa2t *addr, bool *lo * * * 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. * @@ -458,7 +491,7 @@ bool g_binary_content_read_u4(const GBinContent *content, vmpa2t *addr, bool *lo * * ******************************************************************************/ -bool g_binary_content_read_u8(const GBinContent *content, vmpa2t *addr, SourceEndian endian, uint8_t *val) +bool g_binary_content_read_u8(const GBinContent *content, vmpa2t *addr, uint8_t *val) { phys_t start; /* Tête de lecture relative */ const binary_part *part; /* Zone de mémoire effective */ diff --git a/src/glibext/gbincontent.h b/src/glibext/gbincontent.h index 9dd7264..b1e9ec1 100644 --- a/src/glibext/gbincontent.h +++ b/src/glibext/gbincontent.h @@ -62,6 +62,8 @@ const gchar *g_binary_content_get_cheksum(GBinContent *); /* Détermine le nombre d'octets lisibles. */ phys_t g_binary_content_compute_size(const GBinContent *); +/* Donne accès à une portion des données représentées. */ +const bin_t *g_binary_content_get_raw_access(const GBinContent *, vmpa2t *, phys_t); /* Fournit une portion des données représentées. */ bool g_binary_content_get_raw(const GBinContent *, vmpa2t *, phys_t, bin_t *); @@ -72,7 +74,7 @@ bool g_binary_content_get_raw(const GBinContent *, vmpa2t *, phys_t, bin_t *); 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 *); +bool g_binary_content_read_u8(const GBinContent *, vmpa2t *, uint8_t *); /* Lit un nombre non signé sur deux octets. */ bool g_binary_content_read_u16(const GBinContent *, vmpa2t *, SourceEndian, uint16_t *); @@ -85,7 +87,7 @@ bool g_binary_content_read_u64(const GBinContent *, vmpa2t *, SourceEndian, uint #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_s8(c, a, v) g_binary_content_read_u8(c, a, (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) diff --git a/src/glibext/gbufferline.c b/src/glibext/gbufferline.c index 238bfb3..859b6ac 100644 --- a/src/glibext/gbufferline.c +++ b/src/glibext/gbufferline.c @@ -621,8 +621,7 @@ void g_buffer_line_fill_mrange(GBufferLine *line, MemoryDataSize psize, MemoryDa * Paramètres : line = ligne à venir compléter. * * psize = taille souhaitée de l'impression des positions. * * vsize = taille souhaitée de l'impression des adresses. * -* content = contenu binaire global. * -* length = taille de l'extrait de code à afficher. * +* content = contenu binaire global à venir lire. * * full = la portion est assez courte pour être entière ? * * * * Description : Construit le tronc commun d'une ligne d'instruction. * @@ -633,17 +632,17 @@ void g_buffer_line_fill_mrange(GBufferLine *line, MemoryDataSize psize, MemoryDa * * ******************************************************************************/ -void g_buffer_line_fill_for_instr(GBufferLine *line, MemoryDataSize psize, MemoryDataSize vsize, const bin_t *content, off_t length, bool full) +void g_buffer_line_fill_for_instr(GBufferLine *line, MemoryDataSize psize, MemoryDataSize vsize, const GBinContent *content, bool full) { + phys_t length; /* Taille de la couverture */ size_t required; /* Taille de traitement requise*/ char static_buffer[64]; /* Petit tampon local rapide */ char *bin_code; /* Tampon utilisé pour le code */ - off_t start; /* Début de traitement */ - off_t end; /* Limite de traitement */ - off_t i; /* Boucle de parcours #1 */ - char *iter; /* Boucle de parcours #2 */ + vmpa2t pos; /* Boucle de parcours #1 */ + phys_t i; /* Boucle de parcours #2 */ + char *iter; /* Boucle de parcours #3 */ int ret; /* Progression dans l'écriture */ - bin_t byte; /* Octet à représenter */ + uint8_t byte; /* Octet à représenter */ static const char *charset = "0123456789abcdef"; @@ -653,6 +652,8 @@ void g_buffer_line_fill_for_instr(GBufferLine *line, MemoryDataSize psize, Memor /* Détermination du réceptacle */ + length = get_mrange_length(&line->range); + required = length * 3 + 3; if (required <= sizeof(static_buffer)) @@ -662,17 +663,22 @@ void g_buffer_line_fill_for_instr(GBufferLine *line, MemoryDataSize psize, Memor /* Code brut */ - start = get_phy_addr(get_mrange_addr(&line->range)); - end = start + length; + copy_vmpa(&pos, get_mrange_addr(&line->range)); - for (i = start, iter = bin_code; i < end; i++, iter += ret) + for (i = 0, iter = bin_code; i < length; i++, iter += ret) { - byte = content[i]; - - iter[0] = charset[byte >> 4]; - iter[1] = charset[byte & 0x0f]; + if (!g_binary_content_read_u8(content, &pos, &byte)) + { + iter[0] = '?'; + iter[1] = '?'; + } + else + { + iter[0] = charset[byte >> 4]; + iter[1] = charset[byte & 0x0f]; + } - if ((i + 1) < end) + if ((i + 1) < length) { iter[2] = ' '; ret = 3; diff --git a/src/glibext/gbufferline.h b/src/glibext/gbufferline.h index 3a47ee7..e9e6fae 100644 --- a/src/glibext/gbufferline.h +++ b/src/glibext/gbufferline.h @@ -29,6 +29,7 @@ #include <stdbool.h> +#include "gbincontent.h" #include "gbuffersegment.h" #include "../arch/archbase.h" #include "../arch/vmpa.h" @@ -109,7 +110,7 @@ const mrange_t *g_buffer_line_get_range(const GBufferLine *); void g_buffer_line_fill_mrange(GBufferLine *, MemoryDataSize, MemoryDataSize); /* Construit le tronc commun d'une ligne d'instruction. */ -void g_buffer_line_fill_for_instr(GBufferLine *, MemoryDataSize, MemoryDataSize, const bin_t *, off_t, bool); +void g_buffer_line_fill_for_instr(GBufferLine *, MemoryDataSize, MemoryDataSize, const GBinContent *, bool); /* Ajoute un fragment de texte à une colonne de ligne. */ void g_buffer_line_add_segment(GBufferLine *, BufferLineColumn, GBufferSegment *) __attribute__ ((deprecated)); diff --git a/src/gui/panels/strings.c b/src/gui/panels/strings.c index 7996553..8d41165 100644 --- a/src/gui/panels/strings.c +++ b/src/gui/panels/strings.c @@ -489,7 +489,7 @@ static void change_strings_panel_current_binary(GStringsPanel *panel, GLoadedBin g_object_unref(G_OBJECT(proc)); format = g_loaded_binary_get_format(binary); - content = g_binary_format_get_conten_(G_BIN_FORMAT(format)); + content = g_binary_format_get_content(G_BIN_FORMAT(format)); symbols = g_binary_format_get_symbols(G_BIN_FORMAT(format), &count); @@ -540,6 +540,8 @@ static void change_strings_panel_current_binary(GStringsPanel *panel, GLoadedBin } + g_object_unref(G_OBJECT(content)); + } |