summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2011-10-01 17:20:50 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2011-10-01 17:20:50 (GMT)
commit02cb3aa4e7b18b644b034a5c659c332becf99c9b (patch)
tree8d816e5f93820c6ef5ba804d7c0776a65d78329a /src
parente0266175537ec220544c050874be215b11c902fa (diff)
Defined the first real [python] plugin.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@210 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src')
-rw-r--r--src/analysis/binary.c41
-rw-r--r--src/common/environment.c2
-rwxr-xr-xsrc/format/dex/dex.c2
-rw-r--r--src/format/format.c54
-rw-r--r--src/format/format.h2
-rw-r--r--src/gtkext/gtksourceview.c3
-rw-r--r--src/plugins/plugin-def.h27
-rw-r--r--src/plugins/plugin-int.h12
-rw-r--r--src/plugins/plugin.c81
-rw-r--r--src/plugins/plugin.h6
10 files changed, 203 insertions, 27 deletions
diff --git a/src/analysis/binary.c b/src/analysis/binary.c
index 15be43e..f5ff3fb 100644
--- a/src/analysis/binary.c
+++ b/src/analysis/binary.c
@@ -365,17 +365,56 @@ static void g_openida_binary_init(GOpenidaBinary *binary)
GOpenidaBinary *g_openida_binary_new_from_file(const char *filename)
{
GOpenidaBinary *result; /* Adresse à retourner */
+ GPluginModule **pglist; /* Liste de greffons */
+ size_t pgcount; /* Taille de cette liste */
+ size_t i; /* Boucle de parcours */
+
+
+ char *file = strdup(filename);
result = g_object_new(G_TYPE_OPENIDA_BINARY, NULL);
+
+
+
+ printf("%s\n", filename);
+
+
+
+ pglist = get_all_plugins_for_action(PGA_FORMAT_MATCHER, &pgcount);
+
+ if (pgcount > 0)
+ {
+ printf("===>>>> FOUND :: %d\n", pgcount);
+
+
+ /*
+ for (i = 0; i < pgcount; i++)
+ g_plugin_module_execute_action_on_binary(pglist[i], binary, PGA_CODE_PROCESS);
+ */
+ free(pglist);
+
+ }
+
+
+
+
+
+
+
+
+
log_variadic_message(LMT_PROCESS, _("Opening '%s' file..."), filename);
result->filename = strdup(filename);
+ /*
result->bin_data = map_binary_file(filename, &result->bin_length);
if (result->bin_data == NULL) goto lbf_error;
+ */
- result->format = G_EXE_FORMAT(load_new_format(FMT_EXEC, result->bin_data, result->bin_length));
+ result->format = G_EXE_FORMAT(load_new_format(FMT_EXEC, file,
+ &result->bin_data, &result->bin_length));
if (result->format == NULL)
{
log_simple_message(LMT_INFO, _("Unknown binary format"));
diff --git a/src/common/environment.c b/src/common/environment.c
index a0fa568..633d3e2 100644
--- a/src/common/environment.c
+++ b/src/common/environment.c
@@ -52,7 +52,7 @@ char *get_env_var(const char *name)
result = getenv(name);
if (result == NULL) result = strdup("");
- else result = strdup(name);
+ else result = strdup(result);
return result;
diff --git a/src/format/dex/dex.c b/src/format/dex/dex.c
index 174bd2b..287c9ea 100755
--- a/src/format/dex/dex.c
+++ b/src/format/dex/dex.c
@@ -224,6 +224,8 @@ static void g_dex_format_find_all_sources(GDexFormat *format)
bf = G_BIN_FORMAT(format);
+ return; /* FIXME */
+
for (i = 0; i < format->classes_count; i++)
{
source = g_dex_class_get_source_file(format->classes[i], format);
diff --git a/src/format/format.c b/src/format/format.c
index 053a7aa..8e1d864 100644
--- a/src/format/format.c
+++ b/src/format/format.c
@@ -35,6 +35,7 @@
#include "pe/pe.h"
#include "../decomp/expr/block.h"
#include "../panels/log.h"
+#include "../plugins/pglist.h"
@@ -497,9 +498,10 @@ bool init_all_formats(void)
/******************************************************************************
* *
-* Paramètres : type = type de format recherché. *
-* content = contenu binaire à parcourir. *
-* length = taille du contenu en question. *
+* Paramètres : type = type de format recherché. *
+* filename = fichier d'origine des données initiales. *
+* content = contenu binaire à parcourir. [OUT] *
+* length = taille du contenu en question. [OUT] *
* *
* Description : Charge si possible un nouveau format binaire. *
* *
@@ -509,22 +511,62 @@ bool init_all_formats(void)
* *
******************************************************************************/
-GBinFormat *load_new_format(FormatType type, const uint8_t *content, off_t length)
+GBinFormat *load_new_format(FormatType type, char *filename, bin_t **content, off_t *length)
{
GBinFormat *result; /* Adresse à retourner */
+ GPluginModule **pglist; /* Liste de greffons */
+ size_t pgcount; /* Taille de cette liste */
size_t i; /* Boucle de parcours */
result = NULL;
+ printf("analysing... %s\n", filename);
+
+
+
+ pglist = get_all_plugins_for_action(PGA_FORMAT_MATCHER, &pgcount);
+
+ if (pgcount > 0)
+ {
+ lnf_rescan:
+
+ for (i = 0; i < pgcount; i++)
+ switch (g_plugin_module_is_matching(pglist[i], &filename, content, length))
+ {
+ case MFA_MATCHED:
+ /* FIXME */
+ break;
+
+ case MFA_RELOAD:
+ //goto lnf_rescan;
+ break;
+
+ default:
+ break;
+
+ }
+
+ free(pglist);
+
+ }
+
+
+
for (i = 0; i < FID_COUNT && result == NULL; i++)
- if (_formats[i].type == type && _formats[i].match(type, content, length))
+ if (_formats[i].type == type && _formats[i].match(type, *content, *length))
{
log_variadic_message(LMT_INFO, _("%s is matching..."), _formats[i].name);
- result = _formats[i].load(content, length);
+ result = _formats[i].load(*content, *length);
}
+
+
+ printf("FINAL FORMAT :: %p\n", result);
+
+ //exit(0);
+
return result;
}
diff --git a/src/format/format.h b/src/format/format.h
index dd05dd2..7f0b649 100644
--- a/src/format/format.h
+++ b/src/format/format.h
@@ -121,7 +121,7 @@ typedef GBinFormat * (* format_load_fc) (const bin_t *, off_t);
bool init_all_formats(void);
/* Charge si possible un nouveau format binaire. */
-GBinFormat *load_new_format(FormatType, const uint8_t *, off_t);
+GBinFormat *load_new_format(FormatType, char *filename, bin_t **, off_t *);
diff --git a/src/gtkext/gtksourceview.c b/src/gtkext/gtksourceview.c
index 33b61c5..5dea05f 100644
--- a/src/gtkext/gtksourceview.c
+++ b/src/gtkext/gtksourceview.c
@@ -149,6 +149,9 @@ static void gtk_source_view_attach_binary(GtkSourceView *view, GOpenidaBinary *b
buffer = g_openida_binary_get_decompiled_buffer(binary, -1);
+ /* FIXME */
+ if (buffer != NULL)
+
gtk_buffer_view_attach_buffer(GTK_BUFFER_VIEW(view), buffer);
}
diff --git a/src/plugins/plugin-def.h b/src/plugins/plugin-def.h
index 50b8df2..43ec28e 100644
--- a/src/plugins/plugin-def.h
+++ b/src/plugins/plugin-def.h
@@ -42,9 +42,13 @@ typedef enum _PluginType
/* Action(s) menée(s) par le greffon */
typedef enum _PluginAction
{
- PGA_DISASSEMBLE = (1 << 0), /* Désassemblage (non trivial) */
+ PGA_NONE = (0 << 0), /* Aucun intérêt */
- PGA_CODE_PROCESS = (1 << 1) /* Traitement du code existant */
+ PGA_FORMAT_MATCHER = (1 << 0), /* Détection et chargement */
+
+ PGA_DISASSEMBLE = (1 << 1), /* Désassemblage (non trivial) */
+
+ PGA_CODE_PROCESS = (1 << 2) /* Traitement du code existant */
} PluginAction;
@@ -54,11 +58,28 @@ typedef enum _PluginAction
typedef PluginType (* get_plugin_type_fc) (void);
/* Fournit une indication sur le type d'opération(s) menée(s). */
-typedef PluginAction (* get_plugin_action_fc) (void);
+//typedef PluginAction (* get_plugin_action_fc) (void);
/* Exécute une action définie sur un binaire chargé. */
typedef bool (* execute_action_on_binary_fc) (GOpenidaBinary *, PluginAction);
+/* PGA_FORMAT_MATCHER */
+
+/* Bilans d'une reconnaissance */
+typedef enum _MatchingFormatAction
+{
+ MFA_NONE, /* Aucune détection */
+ MFA_MATCHED, /* Format reconnu */
+ MFA_RELOAD, /* Rechargemet opéré */
+
+ MFA_COUNT
+
+} MatchingFormatAction;
+
+
+
+
+
#endif /* _PLUGINS_PLUGIN_DEF_H */
diff --git a/src/plugins/plugin-int.h b/src/plugins/plugin-int.h
index 929dbf9..a0b5758 100644
--- a/src/plugins/plugin-int.h
+++ b/src/plugins/plugin-int.h
@@ -36,6 +36,11 @@
/* Procède à l'initialisation du greffon */
typedef bool (* init_plugin_fc) (GObject *);
+/* Fournit une indication sur le type d'opération(s) menée(s). */
+typedef PluginAction (* get_plugin_action_fc) (const GPluginModule *);
+
+/* Identifie un format à associer à un contenu binaire. */
+typedef MatchingFormatAction (* is_matching_fc) (const GPluginModule *, char **, bin_t **, off_t *);
/* Greffon pour OpenIDA (instance) */
@@ -46,9 +51,11 @@ struct _GPluginModule
GModule *module; /* Abstration de manipulation */
PluginType type; /* Type(s) du greffon */
- PluginAction action; /* Opération(s) menée(s) */
init_plugin_fc init; /* Procédure d'initialisation */
+ get_plugin_action_fc get_action; /* Opération(s) menée(s) */
+
+ is_matching_fc is_matching; /* Recherche de correspondance */
execute_action_on_binary_fc exec_on_bin;/* Action sur un binaire */
@@ -66,6 +73,9 @@ struct _GPluginModuleClass
+
+
+
/* Ajoute un greffon à la liste principale de greffons. */
void add_plugin_to_main_list(GPluginModule *);
diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c
index 2443768..ce8ef37 100644
--- a/src/plugins/plugin.c
+++ b/src/plugins/plugin.c
@@ -99,7 +99,7 @@ GPluginModule *g_plugin_module_new(const gchar *filename, GObject *ref)
{
GPluginModule *result; /* Structure à retourner */
get_plugin_action_fc __get_type; /* Type(s) de greffon */
- get_plugin_action_fc __get_action; /* Actions du greffon */
+ get_plugin_action_fc get_action; /* Actions du greffon */
result = g_object_new(G_TYPE_PLUGIN_MODULE, NULL);
@@ -107,6 +107,21 @@ GPluginModule *g_plugin_module_new(const gchar *filename, GObject *ref)
result->module = g_module_open(filename, G_MODULE_BIND_LAZY);
+ if (!result->module)
+ {
+ printf("err null mod\n");
+ return NULL;
+
+ }
+
+
+ if (!g_module_symbol(result->module, "init_plugin", (gpointer *)&result->init))
+ {
+ printf("Err plugin init sym\n");
+ /* TODO */
+ }
+
+ /*
if (!g_module_symbol(result->module, "get_plugin_type", (gpointer *)&__get_type))
@@ -119,20 +134,20 @@ GPluginModule *g_plugin_module_new(const gchar *filename, GObject *ref)
printf("Plugin type :: 0x%08x\n", result->type);
+ */
-
-#if 1
- if (!g_module_symbol(result->module, "get_plugin_action", (gpointer *)&__get_action))
+ if (!g_module_symbol(result->module, "get_plugin_action", (gpointer *)&get_action))
{
printf("Err plugin get_action sym\n");
//g_object_destroy(result);
return NULL;
}
- result->action = __get_action();
+ result->get_action = get_action;
+ /*
if (result->action & (PGA_DISASSEMBLE | PGA_CODE_PROCESS))
{
if (!g_module_symbol(result->module, "execute_action_on_binary", (gpointer *)&result->exec_on_bin))
@@ -144,14 +159,7 @@ GPluginModule *g_plugin_module_new(const gchar *filename, GObject *ref)
}
-#endif
-
-
- if (!g_module_symbol(result->module, "init_plugin", (gpointer *)&result->init))
- {
- printf("Err plugin init sym\n");
- /* TODO */
- }
+ */
@@ -188,11 +196,56 @@ GPluginModule *g_plugin_module_new(const gchar *filename, GObject *ref)
PluginAction g_plugin_module_get_action(const GPluginModule *plugin)
{
- return plugin->action;
+ return plugin->get_action(plugin);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : plugin = greffon de prise en charge à utiliser. *
+* filename = éventuel nom de fichier associé ou NULL. [OUT] *
+* data = données chargées. [OUT] *
+* length = quantité de ces données. [OUT] *
+* *
+* Description : Identifie un format à associer à un contenu binaire. *
+* *
+* Retour : Bilan de la recherche de correspondances. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+MatchingFormatAction g_plugin_module_is_matching(const GPluginModule *plugin, char **filename, bin_t **data, off_t *length)
+{
+ MatchingFormatAction result; /* Valeur à retourner */
+ char *old_filename; /* Ancien nom de fichier */
+ bin_t *old_data; /* Ancien contenu binaire */
+
+ if (plugin->is_matching == NULL)
+ return MFA_NONE;
+
+ old_filename = *filename;
+ old_data = *data;
+
+ result = plugin->is_matching(plugin, filename, data, length);
+
+ if (result == MFA_RELOAD)
+ {
+ if (old_filename != NULL)
+ free(old_filename);
+ free(old_data);
+ }
+
+ return result;
}
+
+
+
+
/******************************************************************************
* *
* Paramètres : plugin = greffon à consulter. *
diff --git a/src/plugins/plugin.h b/src/plugins/plugin.h
index d17cee5..8df0e0e 100644
--- a/src/plugins/plugin.h
+++ b/src/plugins/plugin.h
@@ -57,9 +57,15 @@ GPluginModule *g_plugin_module_new(const gchar *, GObject *);
/* Indique les opérations offertes par un greffon donné. */
PluginAction g_plugin_module_get_action(const GPluginModule *);
+/* Identifie un format à associer à un contenu binaire. */
+MatchingFormatAction g_plugin_module_is_matching(const GPluginModule *, char **, bin_t **, off_t *);
+
/* Exécute une action définie sur un binaire chargé. */
bool g_plugin_module_execute_action_on_binary(const GPluginModule *, GOpenidaBinary *, PluginAction);
+
+
+
#endif /* _PLUGINS_PLUGIN_H */