From 36760a757f4c3cdecd04d678a41d3484dcdac566 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Mon, 30 May 2016 22:31:59 +0200 Subject: Resolved a suitable symbol depending on the request tolerance. --- ChangeLog | 17 +++++++++++++++++ plugins/pychrysa/format/format.c | 7 ++++--- src/analysis/disass/links.c | 6 +++--- src/analysis/disass/links.h | 2 +- src/arch/target.c | 20 ++------------------ src/arch/target.h | 2 +- src/format/format.c | 11 +++++++++-- src/format/format.h | 2 +- src/gtkext/gtkstatusstack.c | 2 +- src/gui/dialogs/gotox.c | 2 +- 10 files changed, 40 insertions(+), 31 deletions(-) diff --git a/ChangeLog b/ChangeLog index c8bb2c7..c448c35 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +16-05-30 Cyrille Bagard + + * plugins/pychrysa/format/format.c: + * src/analysis/disass/links.c: + * src/analysis/disass/links.h: + * src/arch/target.c: + * src/arch/target.h: + Update code. + + * src/format/format.c: + * src/format/format.h: + Resolve a suitable symbol depending on the request tolerance. + + * src/gtkext/gtkstatusstack.c: + * src/gui/dialogs/gotox.c: + Update code. + 16-05-28 Cyrille Bagard * src/analysis/disass/Makefile.am: diff --git a/plugins/pychrysa/format/format.c b/plugins/pychrysa/format/format.c index 290b189..fb8b249 100644 --- a/plugins/pychrysa/format/format.c +++ b/plugins/pychrysa/format/format.c @@ -427,13 +427,14 @@ static PyObject *py_binary_format_resolve_symbol(PyObject *self, PyObject *args) { PyObject *result; /* Valeur à retourner */ PyObject *py_vmpa; /* Localisation version Python */ + int strict; /* Tolérance acceptée */ int ret; /* Bilan de lecture des args. */ GBinFormat *format; /* Format de binaire manipulé */ GBinSymbol *symbol; /* Enventuel symbole trouvé */ phys_t diff; /* Décallage éventuel mesuré */ bool found; - ret = PyArg_ParseTuple(args, "O", &py_vmpa); + ret = PyArg_ParseTuple(args, "Op", &py_vmpa, &strict); if (!ret) return NULL; ret = PyObject_IsInstance(py_vmpa, (PyObject *)get_python_vmpa_type()); @@ -441,7 +442,7 @@ static PyObject *py_binary_format_resolve_symbol(PyObject *self, PyObject *args) format = G_BIN_FORMAT(pygobject_get(self)); - found = g_binary_format_resolve_symbol(format, get_internal_vmpa(py_vmpa), &symbol, &diff); + found = g_binary_format_resolve_symbol(format, get_internal_vmpa(py_vmpa), strict, &symbol, &diff); if (found) { @@ -526,7 +527,7 @@ PyTypeObject *get_python_binary_format_type(void) { "resolve_symbol", py_binary_format_resolve_symbol, METH_VARARGS, - "resolve_symbol($self, addr, /)\n--\n\nSearch a position inside a routine by a given address." + "resolve_symbol($self, addr, strict, /)\n--\n\nSearch a position inside a routine by a given address." }, { NULL } }; diff --git a/src/analysis/disass/links.c b/src/analysis/disass/links.c index 28cb124..0ce107a 100644 --- a/src/analysis/disass/links.c +++ b/src/analysis/disass/links.c @@ -32,7 +32,7 @@ /* Complète un désassemblage accompli pour une instruction. */ -static void convert_immediate_into_target(GArchInstruction *, size_t, const GBinFormat *); +static void convert_immediate_into_target(GArchInstruction *, size_t, GBinFormat *); @@ -134,7 +134,7 @@ void establish_natural_link(GArchInstruction *instr, GArchInstruction *prev) * * ******************************************************************************/ -static void convert_immediate_into_target(GArchInstruction *instr, size_t index, const GBinFormat *format) +static void convert_immediate_into_target(GArchInstruction *instr, size_t index, GBinFormat *format) { GArchOperand *op; /* Opérande numérique en place */ GImmOperand *imm; /* Version native de l'opérande*/ @@ -179,7 +179,7 @@ static void convert_immediate_into_target(GArchInstruction *instr, size_t index, * * ******************************************************************************/ -void establish_links_for_instruction(GArchInstruction *instr, const GBinFormat *format, const GArchProcessor *proc) +void establish_links_for_instruction(GArchInstruction *instr, GBinFormat *format, const GArchProcessor *proc) { bool skip; /* Saut des conversions */ size_t count; /* Nombre d'opérandes présents */ diff --git a/src/analysis/disass/links.h b/src/analysis/disass/links.h index b1f5a71..d12710b 100644 --- a/src/analysis/disass/links.h +++ b/src/analysis/disass/links.h @@ -35,7 +35,7 @@ void establish_natural_link(GArchInstruction *, GArchInstruction *); /* Complète un désassemblage accompli pour une instruction. */ -void establish_links_for_instruction(GArchInstruction *, const GBinFormat *, const GArchProcessor *); +void establish_links_for_instruction(GArchInstruction *, GBinFormat *, const GArchProcessor *); diff --git a/src/arch/target.c b/src/arch/target.c index 4e731ec..bf4da3a 100644 --- a/src/arch/target.c +++ b/src/arch/target.c @@ -307,7 +307,7 @@ virt_t g_target_operand_get_addr(const GTargetOperand *operand) * * ******************************************************************************/ -bool g_target_operand_resolve(GTargetOperand *operand, const GBinFormat *format, bool strict) +bool g_target_operand_resolve(GTargetOperand *operand, GBinFormat *format, bool strict) { bool result; /* Bilan à retourner */ vmpa2t addr; /* Adresse de recherche */ @@ -320,23 +320,7 @@ bool g_target_operand_resolve(GTargetOperand *operand, const GBinFormat *format, init_vmpa(&addr, VMPA_NO_PHYSICAL, operand->addr); - result = g_binary_format_resolve_symbol(format, &addr, &operand->symbol, &operand->diff); - - /** - * En cas de succès, le compteur de références du symbole trouvé a été incrémenté. - */ - - if (strict) - result &= (operand->diff == 0); - - if (!result && operand->symbol != NULL) - { - g_object_unref(G_OBJECT(operand->symbol)); - - operand->symbol = NULL; - operand->diff = 0; - - } + result = g_binary_format_resolve_symbol(format, &addr, strict, &operand->symbol, &operand->diff); return result; diff --git a/src/arch/target.h b/src/arch/target.h index a284c09..9031ddc 100644 --- a/src/arch/target.h +++ b/src/arch/target.h @@ -64,7 +64,7 @@ MemoryDataSize g_target_operand_get_size(const GTargetOperand *); virt_t g_target_operand_get_addr(const GTargetOperand *); /* Tente une résolution de symbole. */ -bool g_target_operand_resolve(GTargetOperand *, const GBinFormat *, bool); +bool g_target_operand_resolve(GTargetOperand *, GBinFormat *, bool); /* Fournit les indications concernant le symbole associé. */ GBinSymbol *g_target_operand_get_symbol(const GTargetOperand *, phys_t *); diff --git a/src/format/format.c b/src/format/format.c index 5b44156..ef8258f 100644 --- a/src/format/format.c +++ b/src/format/format.c @@ -812,6 +812,7 @@ bool g_binary_format_find_next_symbol_at(GBinFormat *format, const vmpa2t *addr, * * * Paramètres : format = informations chargées à consulter. * * addr = adresse à cibler lors des recherches. * +* strict = indication de tolérance acceptée. * * symbol = éventuel symbole trouvé à déréfenrencer. [OUT] * * diff = décallage entre l'adresse et le symbole. [OUT] * * * @@ -823,17 +824,23 @@ bool g_binary_format_find_next_symbol_at(GBinFormat *format, const vmpa2t *addr, * * ******************************************************************************/ -bool g_binary_format_resolve_symbol(GBinFormat *format, const vmpa2t *addr, GBinSymbol **symbol, phys_t *diff) +bool g_binary_format_resolve_symbol(GBinFormat *format, const vmpa2t *addr, bool strict, GBinSymbol **symbol, phys_t *diff) { bool result; /* Bilan à retourner */ const mrange_t *range; /* Espace mémoire parcouru */ - result = g_binary_format_find_symbol_for(format, addr, symbol); + if (strict) + result = g_binary_format_find_symbol_at(format, addr, symbol); + else + result = g_binary_format_find_symbol_for(format, addr, symbol); if (result) { range = g_binary_symbol_get_range(*symbol); *diff = compute_vmpa_diff(get_mrange_addr(range), addr); + + assert(!strict || *diff == 0); + } return result; diff --git a/src/format/format.h b/src/format/format.h index e21e478..4d5cac5 100644 --- a/src/format/format.h +++ b/src/format/format.h @@ -92,7 +92,7 @@ bool g_binary_format_find_symbol_for(GBinFormat *, const vmpa2t *, GBinSymbol ** bool g_binary_format_find_next_symbol_at(GBinFormat *, const vmpa2t *, GBinSymbol **); /* Recherche le symbole correspondant à une adresse. */ -bool g_binary_format_resolve_symbol(GBinFormat *, const vmpa2t *, GBinSymbol **, phys_t *); +bool g_binary_format_resolve_symbol(GBinFormat *, const vmpa2t *, bool, GBinSymbol **, phys_t *); /* Fournit le prototype de toutes les routines détectées. */ GBinRoutine **g_binary_format_get_routines(const GBinFormat *, size_t *); diff --git a/src/gtkext/gtkstatusstack.c b/src/gtkext/gtkstatusstack.c index 95166d7..cff10fe 100644 --- a/src/gtkext/gtkstatusstack.c +++ b/src/gtkext/gtkstatusstack.c @@ -578,7 +578,7 @@ void gtk_status_stack_update_current_instruction(GtkStatusStack *stack, const GL /* Symbole concerné */ - if (g_binary_format_resolve_symbol(G_BIN_FORMAT(format), addr, &symbol, &diff)) + if (g_binary_format_resolve_symbol(G_BIN_FORMAT(format), addr, false, &symbol, &diff)) { label = g_binary_symbol_get_label(symbol); diff --git a/src/gui/dialogs/gotox.c b/src/gui/dialogs/gotox.c index 5d19fee..0511be8 100644 --- a/src/gui/dialogs/gotox.c +++ b/src/gui/dialogs/gotox.c @@ -378,7 +378,7 @@ static void add_new_location_to_list(GtkTreeStore *store, GLoadedBinary *binary, { format = G_BIN_FORMAT(g_loaded_binary_get_format(binary)); - if (g_binary_format_resolve_symbol(format, addr, &symbol, &diff)) + if (g_binary_format_resolve_symbol(format, addr, true, &symbol, &diff)) { label = g_binary_symbol_get_label(symbol); -- cgit v0.11.2-87-g4458