summaryrefslogtreecommitdiff
path: root/src/debug/jdwp/debugger.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/debug/jdwp/debugger.c')
-rw-r--r--src/debug/jdwp/debugger.c204
1 files changed, 204 insertions, 0 deletions
diff --git a/src/debug/jdwp/debugger.c b/src/debug/jdwp/debugger.c
new file mode 100644
index 0000000..a99c6d0
--- /dev/null
+++ b/src/debug/jdwp/debugger.c
@@ -0,0 +1,204 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * debugger.c - débogage d'une cible en Java.
+ *
+ * Copyright (C) 2010 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "debugger.h"
+
+
+#include "packet.h"
+#include "tcp.h"
+
+
+#include "../debugger-int.h"
+#include "../stream.h"
+
+
+
+
+
+/* Débogueur utilisant un serveur JAVA (instance) */
+struct _GJavaDebugger
+{
+ GBinaryDebugger parent; /* A laisser en premier */
+
+ GDebugStream *stream;
+
+};
+
+/* Débogueur utilisant un serveur JAVA (classe) */
+struct _GJavaDebuggerClass
+{
+ GBinaryDebuggerClass parent; /* A laisser en premier */
+
+};
+
+
+
+
+
+/* Initialise la classe du débogueur utilisant Java. */
+static void g_java_debugger_class_init(GJavaDebuggerClass *);
+
+/* Procède à l'initialisation du débogueur utilisant Java. */
+static void g_java_debugger_init(GJavaDebugger *);
+
+
+
+/* Indique le type défini par la GLib pour le débogueur java. */
+G_DEFINE_TYPE(GJavaDebugger, g_java_debugger, G_TYPE_BINARY_DEBUGGER);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe de débogueur à initialiser. *
+* *
+* Description : Initialise la classe du débogueur utilisant Java. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_java_debugger_class_init(GJavaDebuggerClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : debugger = instance de débogueur à préparer. *
+* *
+* Description : Procède à l'initialisation du débogueur utilisant Java. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_java_debugger_init(GJavaDebugger *debugger)
+{
+ GBinaryDebugger *parent; /* Instance parente */
+
+ parent = G_BINARY_DEBUGGER(debugger);
+#if 0
+ parent->run = (basic_debugger_fc)g_java_debugger_run;
+ parent->resume = (resume_debugger_fc)g_java_debugger_resume;
+ parent->kill = (basic_debugger_fc)g_java_debugger_kill;
+#endif
+
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : binary = binaire représenter à déboguer. *
+* options = paramètres destinés au débogage. *
+* *
+* Description : Crée un débogueur utilisant un serveur JAVA distant. *
+* *
+* Retour : Instance de débogueur mise en place ou NULL. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GBinaryDebugger *g_java_debugger_new(GOpenidaBinary *binary, void *options)
+{
+ GBinaryDebugger *result; /* Débogueur à retourner */
+
+ result = g_object_new(G_TYPE_JAVA_DEBUGGER, NULL);
+
+
+ G_JAVA_DEBUGGER(result)->stream = g_jdwp_tcp_client_new("localhost", "9000");
+
+ return result;
+
+}
+
+
+
+
+
+
+
+void test_java(void)
+{
+ GBinaryDebugger *debugger;
+ GDebugPacket *packet;
+ GDebugPacket *packet2;
+ jdwp_payload *payload;
+
+ printf("JDWP-start !!!!\n");
+
+ printf("size == %d\n", sizeof(jdwp_header));
+
+
+ debugger = g_java_debugger_new(NULL, NULL);
+
+
+ g_debug_stream_connect(G_JAVA_DEBUGGER(debugger)->stream);
+
+
+ packet = g_debug_stream_get_free_packet(G_JAVA_DEBUGGER(debugger)->stream);
+
+
+ g_jdwp_packet_set_request_header(G_JDWP_PACKET(packet), JDWP_CST_VIRTUAL_MACHINE, JDWP_CMD_VM_VERSION);
+
+ if (!g_debug_stream_send_packet(G_JAVA_DEBUGGER(debugger)->stream, packet))
+ printf("erreur envoi\n");
+
+ packet2 = g_debug_stream_recv_packet(G_JAVA_DEBUGGER(debugger)->stream, (filter_packet_fc)g_jdwp_packet_is_reply, packet);
+
+ if (!packet2)
+ printf("erreur réception\n");
+
+ if (!g_jdwp_packet_parse_payload(G_JDWP_PACKET(packet2), JDWP_CST_VIRTUAL_MACHINE, JDWP_CMD_VM_VERSION))
+ printf("erreur de décodage\n");
+
+ payload = g_jdwp_packet_get_payload(G_JDWP_PACKET(packet2));
+
+
+
+ printf("-----------\n");
+
+ printf("desc :: '%s'\n", payload->vs_reply.description.value);
+
+ printf("version :: %d.%d\n", payload->vs_reply.jdwp_major, payload->vs_reply.jdwp_minor);
+
+ printf("version :: '%s'\n", payload->vs_reply.vm_version.value);
+ printf("name :: '%s'\n", payload->vs_reply.vm_name.value);
+
+ printf("-----------\n");
+
+
+
+ g_jdwp_packet_free_payload(G_JDWP_PACKET(packet2), JDWP_CST_VIRTUAL_MACHINE, JDWP_CMD_VM_VERSION);
+
+
+ printf("JDWP-end !!!!\n");
+
+}