summaryrefslogtreecommitdiff
path: root/src/analysis
diff options
context:
space:
mode:
Diffstat (limited to 'src/analysis')
-rw-r--r--src/analysis/binary.c182
-rw-r--r--src/analysis/line-int.h2
-rw-r--r--src/analysis/line.c2
3 files changed, 176 insertions, 10 deletions
diff --git a/src/analysis/binary.c b/src/analysis/binary.c
index d2c7f3e..56265f2 100644
--- a/src/analysis/binary.c
+++ b/src/analysis/binary.c
@@ -770,15 +770,18 @@ GOpenidaBinary *g_openida_binary_new_from_xml(xmlXPathContextPtr context, const
size_t access_len; /* Taille d'un chemin interne */
char *access; /* Chemin pour une sous-config.*/
char *filename; /* Chemin du binaire à charger */
+ xmlXPathObjectPtr xobjects; /* Cible d'une recherche */
+ int i; /* Boucle de parcours */
+ GBinPart *part; /* Partie binaire à traiter */
+ off_t offset; /* Position de cette partie */
+ vmpa_t addr; /* Adresse correspondante */
result = NULL;
/* Chemin du fichier à retrouver */
- access_len = strlen(path) + strlen("/Filename") + 1;
-
- access = calloc(access_len, sizeof(char));
- snprintf(access, access_len, "%s/Filename", path);
+ access = strdup(path);
+ access = stradd(access, "/Filename");
filename = get_node_text_value(context, access);
@@ -792,6 +795,129 @@ GOpenidaBinary *g_openida_binary_new_from_xml(xmlXPathContextPtr context, const
free(filename);
}
+ /* Parties à désassembler : default */
+
+ access = strdup(path);
+ access = stradd(access, "/BinParts/Default/Part");
+
+ xobjects = get_node_xpath_object(context, access);
+
+ for (i = 0; i < XPATH_OBJ_NODES_COUNT(xobjects); i++)
+ {
+ part = g_binary_part_load_from_xml(NODE_FROM_PATH_OBJ(xobjects, i));
+
+ if (part != NULL)
+ {
+ g_binary_part_get_values(part, &offset, NULL, NULL);
+
+ if (!g_exe_format_translate_offset_into_address(G_EXE_FORMAT(result->format), offset, &addr))
+ {
+ g_object_unref(G_OBJECT(part));
+ continue;
+ }
+
+ result->parts_count[BPM_DEFAULT]++;
+ result->parts[BPM_DEFAULT] = (GBinPart **)realloc(result->parts[BPM_DEFAULT],
+ result->parts_count[BPM_DEFAULT] * sizeof(GBinPart *));
+
+ result->parts[BPM_DEFAULT][result->parts_count[BPM_DEFAULT] - 1] = part;
+
+ }
+
+ }
+
+ if(xobjects != NULL) /* FIXME */
+ xmlXPathFreeObject(xobjects);
+
+ free(access);
+
+ qsort(result->parts[BPM_DEFAULT], result->parts_count[BPM_DEFAULT],
+ sizeof(GBinPart *), g_binary_part_compare);
+
+ /* Parties à désassembler : routines */
+
+ access = strdup(path);
+ access = stradd(access, "/BinParts/Routines/Part");
+
+ xobjects = get_node_xpath_object(context, access);
+
+ for (i = 0; i < XPATH_OBJ_NODES_COUNT(xobjects); i++)
+ {
+ part = g_binary_part_load_from_xml(NODE_FROM_PATH_OBJ(xobjects, i));
+
+ if (part != NULL)
+ {
+ g_binary_part_get_values(part, &offset, NULL, NULL);
+
+ if (!g_exe_format_translate_offset_into_address(G_EXE_FORMAT(result->format), offset, &addr))
+ {
+ g_object_unref(G_OBJECT(part));
+ continue;
+ }
+ else g_binary_part_set_address(part, addr);
+
+ result->parts_count[BPM_ROUTINES]++;
+ result->parts[BPM_ROUTINES] = (GBinPart **)realloc(result->parts[BPM_ROUTINES],
+ result->parts_count[BPM_ROUTINES] * sizeof(GBinPart *));
+
+ result->parts[BPM_ROUTINES][result->parts_count[BPM_ROUTINES] - 1] = part;
+
+ }
+
+ }
+
+ if(xobjects != NULL) /* FIXME */
+ xmlXPathFreeObject(xobjects);
+
+ free(access);
+
+ qsort(result->parts[BPM_ROUTINES], result->parts_count[BPM_ROUTINES],
+ sizeof(GBinPart *), g_binary_part_compare);
+
+ /* Parties à désassembler : utilisateur */
+
+ access = strdup(path);
+ access = stradd(access, "/BinParts/User/Part");
+
+ xobjects = get_node_xpath_object(context, access);
+
+ for (i = 0; i < XPATH_OBJ_NODES_COUNT(xobjects); i++)
+ {
+ part = g_binary_part_load_from_xml(NODE_FROM_PATH_OBJ(xobjects, i));
+
+ if (part != NULL)
+ {
+ g_binary_part_get_values(part, &offset, NULL, NULL);
+
+ if (!g_exe_format_translate_offset_into_address(G_EXE_FORMAT(result->format), offset, &addr))
+ {
+ g_object_unref(G_OBJECT(part));
+ continue;
+ }
+
+ result->parts_count[BPM_USER]++;
+ result->parts[BPM_USER] = (GBinPart **)realloc(result->parts[BPM_USER],
+ result->parts_count[BPM_USER] * sizeof(GBinPart *));
+
+ result->parts[BPM_USER][result->parts_count[BPM_USER] - 1] = part;
+
+ }
+
+ }
+
+ if(xobjects != NULL) /* FIXME */
+ xmlXPathFreeObject(xobjects);
+
+ free(access);
+
+ qsort(result->parts[BPM_USER], result->parts_count[BPM_USER],
+ sizeof(GBinPart *), g_binary_part_compare);
+
+
+
+
+
+
return result;
}
@@ -816,6 +942,8 @@ bool g_openida_binary_save(const GOpenidaBinary *binary, xmlDocPtr xdoc, xmlXPat
{
bool result; /* Bilan à faire remonter */
char *access; /* Chemin d'accès à un élément */
+ xmlNodePtr node; /* Point d'insertion XML */
+ size_t i; /* Boucle de parcours */
result = true;
@@ -828,16 +956,49 @@ bool g_openida_binary_save(const GOpenidaBinary *binary, xmlDocPtr xdoc, xmlXPat
free(access);
+ /* Parties à désassembler */
+ if (binary->parts_count[BPM_DEFAULT] > 0)
+ {
+ access = strdup(path);
+ access = stradd(access, "/BinParts/Default");
- access = strdup(path);
- access = stradd(access, "/Filename2");
+ node = ensure_node_exist(xdoc, context, access);
- result &= add_content_to_node(xdoc, context, access, binary->filename);
+ free(access);
- free(access);
+ for (i = 0; i < binary->parts_count[BPM_DEFAULT] && result; i++)
+ result &= g_binary_part_save_to_xml(binary->parts[BPM_DEFAULT][i], xdoc, node);
+ }
+
+ if (binary->parts_count[BPM_ROUTINES] > 0)
+ {
+ access = strdup(path);
+ access = stradd(access, "/BinParts/Routines");
+ node = ensure_node_exist(xdoc, context, access);
+
+ free(access);
+
+ for (i = 0; i < binary->parts_count[BPM_ROUTINES] && result; i++)
+ result &= g_binary_part_save_to_xml(binary->parts[BPM_ROUTINES][i], xdoc, node);
+
+ }
+
+ if (binary->parts_count[BPM_USER] > 0)
+ {
+ access = strdup(path);
+ access = stradd(access, "/BinParts/User");
+
+ node = ensure_node_exist(xdoc, context, access);
+
+ free(access);
+
+ for (i = 0; i < binary->parts_count[BPM_USER] && result; i++)
+ result &= g_binary_part_save_to_xml(binary->parts[BPM_USER][i], xdoc, node);
+
+ }
return result;
@@ -914,6 +1075,11 @@ void g_openida_binary_analyse(GOpenidaBinary *binary)
queue = get_work_queue();
+
+ if (binary->parts_count[BPM_ROUTINES] > 0)
+ binary->model = BPM_ROUTINES;
+
+
if (binary->parts[binary->model] != NULL)
{
parts = binary->parts[binary->model];
diff --git a/src/analysis/line-int.h b/src/analysis/line-int.h
index a78d8b2..9c8e52a 100644
--- a/src/analysis/line-int.h
+++ b/src/analysis/line-int.h
@@ -57,8 +57,8 @@ struct _GRenderingLine
#define lines_list_last(head) dl_list_last(head, GRenderingLine, link)
#define lines_list_next_iter(iter, head) dl_list_next_iter(iter, head, GRenderingLine, link)
+#define lines_list_add_before(new, head, pos) dl_list_add_before(new, head, pos, link)
#define lines_list_add_tail(new, head) dl_list_add_tail(new, head, GRenderingLine, link)
-#define lines_list_splice_before(pos, head1, head2) dl_list_splice_before(pos, head1, head2, GRenderingLine, link)
#define lines_list_for_each(pos, head) dl_list_for_each(pos, head, GRenderingLine, link)
diff --git a/src/analysis/line.c b/src/analysis/line.c
index 507597c..24a107b 100644
--- a/src/analysis/line.c
+++ b/src/analysis/line.c
@@ -424,7 +424,7 @@ void g_rendering_line_insert_into_lines(GRenderingLine **lines, GRenderingLine *
else
{
if (first)
- lines_list_splice_before(iter, lines, line);
+ lines_list_add_before(line, lines, iter);
else
/* TODO */;
}