From f36b525987442d46c920f76dced29356663ae85b Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Fri, 7 Dec 2018 23:17:48 +0100 Subject: Removed code. --- src/debug/jdwp/Makefile.am | 26 --- src/debug/jdwp/debugger.c | 445 ---------------------------------------- src/debug/jdwp/debugger.h | 61 ------ src/debug/jdwp/jdwp_def.h | 237 --------------------- src/debug/jdwp/misc/Makefile.am | 20 -- src/debug/jdwp/misc/header.c | 196 ------------------ src/debug/jdwp/misc/header.h | 50 ----- src/debug/jdwp/misc/id.c | 148 ------------- src/debug/jdwp/misc/id.h | 131 ------------ src/debug/jdwp/misc/location.c | 64 ------ src/debug/jdwp/misc/location.h | 40 ---- src/debug/jdwp/misc/types.c | 85 -------- src/debug/jdwp/misc/types.h | 44 ---- src/debug/jdwp/packet.c | 422 ------------------------------------- src/debug/jdwp/packet.h | 93 --------- src/debug/jdwp/sets/Makefile.am | 19 -- src/debug/jdwp/sets/list.c | 191 ----------------- src/debug/jdwp/sets/list.h | 64 ------ src/debug/jdwp/sets/thread.c | 222 -------------------- src/debug/jdwp/sets/thread.h | 55 ----- src/debug/jdwp/sets/vm.c | 202 ------------------ src/debug/jdwp/sets/vm.h | 53 ----- src/debug/jdwp/tcp.c | 368 --------------------------------- src/debug/jdwp/tcp.h | 56 ----- 24 files changed, 3292 deletions(-) delete mode 100644 src/debug/jdwp/Makefile.am delete mode 100644 src/debug/jdwp/debugger.c delete mode 100644 src/debug/jdwp/debugger.h delete mode 100644 src/debug/jdwp/jdwp_def.h delete mode 100644 src/debug/jdwp/misc/Makefile.am delete mode 100644 src/debug/jdwp/misc/header.c delete mode 100644 src/debug/jdwp/misc/header.h delete mode 100644 src/debug/jdwp/misc/id.c delete mode 100644 src/debug/jdwp/misc/id.h delete mode 100644 src/debug/jdwp/misc/location.c delete mode 100644 src/debug/jdwp/misc/location.h delete mode 100644 src/debug/jdwp/misc/types.c delete mode 100644 src/debug/jdwp/misc/types.h delete mode 100644 src/debug/jdwp/packet.c delete mode 100644 src/debug/jdwp/packet.h delete mode 100644 src/debug/jdwp/sets/Makefile.am delete mode 100644 src/debug/jdwp/sets/list.c delete mode 100644 src/debug/jdwp/sets/list.h delete mode 100644 src/debug/jdwp/sets/thread.c delete mode 100644 src/debug/jdwp/sets/thread.h delete mode 100644 src/debug/jdwp/sets/vm.c delete mode 100644 src/debug/jdwp/sets/vm.h delete mode 100644 src/debug/jdwp/tcp.c delete mode 100644 src/debug/jdwp/tcp.h diff --git a/src/debug/jdwp/Makefile.am b/src/debug/jdwp/Makefile.am deleted file mode 100644 index f592f49..0000000 --- a/src/debug/jdwp/Makefile.am +++ /dev/null @@ -1,26 +0,0 @@ - -noinst_LTLIBRARIES = libdebugjdwp.la - -libdebugjdwp_la_SOURCES = \ - debugger.h debugger.c \ - jdwp_def.h \ - packet.h packet.c \ - tcp.h tcp.c - -libdebugjdwp_la_LIBADD = \ - misc/libdebugjdwpmisc.la \ - sets/libdebugjdwpsets.la - -libdebugjdwp_la_LDFLAGS = - - -devdir = $(includedir)/chrysalide/$(subdir:src/%=%) - -dev_HEADERS = $(libdebugjdwp_la_SOURCES:%c=) - - -AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) - -AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) - -SUBDIRS = misc sets diff --git a/src/debug/jdwp/debugger.c b/src/debug/jdwp/debugger.c deleted file mode 100644 index 6b406e3..0000000 --- a/src/debug/jdwp/debugger.c +++ /dev/null @@ -1,445 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * debugger.c - débogage d'une cible en Java. - * - * Copyright (C) 2010-2017 Cyrille Bagard - * - * This file is part of Chrysalide. - * - * Chrysalide 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. - * - * Chrysalide 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 Chrysalide. If not, see . - */ - - -#include "debugger.h" - - -#include -#include - - -#include - - -#include "packet.h" -#include "tcp.h" -#include "../debugger-int.h" -#include "../stream.h" -#include "../../core/logs.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 *); - -/* Procède au démarrage effectif de la session de débogage. */ -static bool g_java_debugger_attach(GJavaDebugger *); - -/* Fournit les identifiants de tous les threads actifs. */ -static pid_t *g_java_debugger_list_all_threads(GJavaDebugger *, char ***, size_t *); - -/* Fournit la liste des frames courantes d'un thread donné. */ -static dbg_frame_t *g_java_debugger_get_frames_stack(GJavaDebugger *, pid_t, size_t *); - - - -/* 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); - - parent->attach = (attach_debugger_fc)g_java_debugger_attach; - - parent->all_threads = (dbg_list_all_threads_fc)g_java_debugger_list_all_threads; - parent->frames_stack = (dbg_get_frames_stack_fc)g_java_debugger_get_frames_stack; - -#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(GLoadedBinary *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; - -} - - -/****************************************************************************** -* * -* Paramètres : debugger = instance du module de débogage chargé. * -* * -* Description : Procède au démarrage effectif de la session de débogage. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool g_java_debugger_attach(GJavaDebugger *debugger) -{ - bool result; /* Bilan à retourner */ - GDebugPacket *req; /* Requête à formuler */ - GDebugPacket *ret; /* Obtention de la réponse */ - jdwp_payload *payload; /* Charge utile d'une réponse */ - - req = NULL; - ret = NULL; - - /* Connexion physique */ - - result = g_debug_stream_connect(debugger->stream); - if (!result) goto gjda_error; - - result = false; - - /* Demande de version */ - - req = g_debug_stream_get_free_packet(debugger->stream); - - g_jdwp_packet_set_request_header(G_JDWP_PACKET(req), - JDWP_CST_VIRTUAL_MACHINE, JDWP_CMD_VM_VERSION); - - if (!g_debug_stream_send_packet(debugger->stream, req)) - goto gjda_req_error; - - ret = g_debug_stream_recv_packet(debugger->stream, - (filter_packet_fc)g_jdwp_packet_is_reply, req); - if (!ret) goto gjda_req_error; - - if (!g_jdwp_packet_parse_payload(G_JDWP_PACKET(ret), - JDWP_CST_VIRTUAL_MACHINE, JDWP_CMD_VM_VERSION)) - goto gjda_ret_error; - - payload = g_jdwp_packet_get_payload(G_JDWP_PACKET(ret)); - - log_variadic_message(LMT_INFO, _("The debugger is '%s' (JRE %d.%d; VM %s)."), - payload->vs_reply.description.value, - payload->vs_reply.jdwp_major, payload->vs_reply.jdwp_minor, - payload->vs_reply.vm_version.value); - - g_debug_stream_mark_packet_as_free(debugger->stream, req); - g_debug_stream_mark_packet_as_free(debugger->stream, ret); - - /* Récupération des tailles d'identifiants */ - - req = g_debug_stream_get_free_packet(debugger->stream); - - g_jdwp_packet_set_request_header(G_JDWP_PACKET(req), - JDWP_CST_VIRTUAL_MACHINE, JDWP_CMD_VM_ID_SIZES); - - if (!g_debug_stream_send_packet(debugger->stream, req)) - goto gjda_req_error; - - ret = g_debug_stream_recv_packet(debugger->stream, - (filter_packet_fc)g_jdwp_packet_is_reply, req); - if (!ret) goto gjda_req_error; - - if (!g_jdwp_packet_parse_payload(G_JDWP_PACKET(ret), - JDWP_CST_VIRTUAL_MACHINE, JDWP_CMD_VM_ID_SIZES)) - goto gjda_ret_error; - - payload = g_jdwp_packet_get_payload(G_JDWP_PACKET(ret)); - - g_jdwp_packet_set_sizes(G_JDWP_PACKET(ret), &payload->sz_reply); - - result = true; - - gjda_ret_error: - - g_debug_stream_mark_packet_as_free(debugger->stream, ret); - - gjda_req_error: - - g_debug_stream_mark_packet_as_free(debugger->stream, req); - - gjda_error: - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : debugger = instance du module de débogage chargé. * -* names = désignations de tous les threads ou NULL. [OUT] * -* count = nombre de threads actifs. [OUT] * -* * -* Description : Fournit les identifiants de tous les threads actifs. * -* * -* Retour : Liste des threads décomptés. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static pid_t *g_java_debugger_list_all_threads(GJavaDebugger *debugger, char ***names, size_t *count) -{ - pid_t *result; /* Bilan à retourner */ - GDebugPacket *req; /* Requête à formuler */ - GDebugPacket *ret; /* Obtention de la réponse */ - jdwp_payload *payload; /* Charge utile d'une réponse */ - size_t i; /* Boucle de parcours */ - GDebugPacket *sub_req; /* Requête à formuler */ - jdwp_cmd_thread_name_request ident; /* Indentification d'un thread */ - GDebugPacket *sub_ret; /* Obtention de la réponse */ - jdwp_payload *sub_payload; /* Charge utile d'une réponse */ - - result = NULL; - *count = 0; - - req = g_debug_stream_get_free_packet(debugger->stream); - - g_jdwp_packet_set_request_header(G_JDWP_PACKET(req), - JDWP_CST_VIRTUAL_MACHINE, JDWP_CMD_VM_ALL_THREADS); - - if (!g_debug_stream_send_packet(debugger->stream, req)) - goto gjdlat_req_error; - - ret = g_debug_stream_recv_packet(debugger->stream, - (filter_packet_fc)g_jdwp_packet_is_reply, req); - if (!ret) goto gjdlat_req_error; - - if (!g_jdwp_packet_parse_payload(G_JDWP_PACKET(ret), - JDWP_CST_VIRTUAL_MACHINE, JDWP_CMD_VM_ALL_THREADS)) - goto gjdlat_ret_error; - - payload = g_jdwp_packet_get_payload(G_JDWP_PACKET(ret)); - - *count = payload->th_reply.count; - result = (pid_t *)calloc(*count, sizeof(pid_t)); - - if (names != NULL) - *names = (char **)calloc(*count, sizeof(char *)); - - for (i = 0; i < *count; i++) - { - result[i] = (pid_t)payload->th_reply.threads[i]; - - if (names != NULL) - { - sub_req = g_debug_stream_get_free_packet(debugger->stream); - - g_jdwp_packet_set_request_header(G_JDWP_PACKET(sub_req), - JDWP_CST_THREAD_REFERENCE, JDWP_CMD_THREAD_NAME); - - ident.id = result[i]; - g_jdwp_packet_set_payload(G_JDWP_PACKET(sub_req), (jdwp_payload *)&ident); - - if (!g_debug_stream_send_packet(debugger->stream, sub_req)) - { - g_debug_stream_mark_packet_as_free(debugger->stream, sub_req); - (*names)[i] = strdup("???"); - continue; - } - - sub_ret = g_debug_stream_recv_packet(debugger->stream, - (filter_packet_fc)g_jdwp_packet_is_reply, sub_req); - if (!sub_ret) - { - g_debug_stream_mark_packet_as_free(debugger->stream, sub_req); - (*names)[i] = strdup("???"); - continue; - } - - if (!g_jdwp_packet_parse_payload(G_JDWP_PACKET(sub_ret), - JDWP_CST_THREAD_REFERENCE, JDWP_CMD_THREAD_NAME)) - { - g_debug_stream_mark_packet_as_free(debugger->stream, sub_req); - g_debug_stream_mark_packet_as_free(debugger->stream, sub_ret); - (*names)[i] = strdup("???"); - continue; - } - - sub_payload = g_jdwp_packet_get_payload(G_JDWP_PACKET(sub_ret)); - - (*names)[i] = strdup(sub_payload->th_name.name.value); - - g_debug_stream_mark_packet_as_free(debugger->stream, sub_req); - g_debug_stream_mark_packet_as_free(debugger->stream, sub_ret); - - } - - } - - gjdlat_ret_error: - - g_debug_stream_mark_packet_as_free(debugger->stream, ret); - - gjdlat_req_error: - - g_debug_stream_mark_packet_as_free(debugger->stream, req); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : debugger = instance du module de débogage chargé. * -* thread = thread concerné par l'analyse. * -* count = nombre de frames en place. [OUT] * -* * -* Description : Fournit la liste des frames courantes d'un thread donné. * -* * -* Retour : Liste des frames trouvées. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static dbg_frame_t *g_java_debugger_get_frames_stack(GJavaDebugger *debugger, pid_t thread, size_t *count) -{ - dbg_frame_t *result; /* Bilan à retourner */ - GDebugPacket *req; /* Requête à formuler */ - jdwp_cmd_thread_frames_request frames; /* Ciblage du thread désiré */ - GDebugPacket *ret; /* Obtention de la réponse */ - jdwp_payload *payload; /* Charge utile d'une réponse */ - size_t i; /* Boucle de parcours */ - - result = NULL; - *count = 0; - - req = g_debug_stream_get_free_packet(debugger->stream); - - g_jdwp_packet_set_request_header(G_JDWP_PACKET(req), - JDWP_CST_THREAD_REFERENCE, JDWP_CMD_THREAD_FRAMES); - - frames.id = thread; - frames.start = 0; - frames.length = ALL_FRAMES; - g_jdwp_packet_set_payload(G_JDWP_PACKET(req), (jdwp_payload *)&frames); - - if (!g_debug_stream_send_packet(debugger->stream, req)) - goto gjdgsf_req_error; - - ret = g_debug_stream_recv_packet(debugger->stream, - (filter_packet_fc)g_jdwp_packet_is_reply, req); - if (!ret) goto gjdgsf_req_error; - - if (!g_jdwp_packet_parse_payload(G_JDWP_PACKET(ret), - JDWP_CST_THREAD_REFERENCE, JDWP_CMD_THREAD_FRAMES)) - goto gjdgsf_ret_error; - - payload = g_jdwp_packet_get_payload(G_JDWP_PACKET(ret)); - - *count = payload->th_frames.count; - result = (dbg_frame_t *)calloc(*count, sizeof(dbg_frame_t)); - - for (i = 0; i < *count; i++) - { - /* TODO */ - result[i].addr = payload->th_frames.frames[i].location.index; - - } - - gjdgsf_ret_error: - - g_debug_stream_mark_packet_as_free(debugger->stream, ret); - - gjdgsf_req_error: - - g_debug_stream_mark_packet_as_free(debugger->stream, req); - - return result; - -} diff --git a/src/debug/jdwp/debugger.h b/src/debug/jdwp/debugger.h deleted file mode 100644 index f7a0fbb..0000000 --- a/src/debug/jdwp/debugger.h +++ /dev/null @@ -1,61 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * debugger.h - prototypes pour le débogage d'une cible en Java. - * - * Copyright (C) 2010-2017 Cyrille Bagard - * - * This file is part of Chrysalide. - * - * Chrysalide 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. - * - * Chrysalide 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 Chrysalide. If not, see . - */ - - -#ifndef _DEBUG_JDWP_DEBUGGER_H -#define _DEBUG_JDWP_DEBUGGER_H - - -#include - - -#include "../debugger.h" - - - -#define G_TYPE_JAVA_DEBUGGER (g_java_debugger_get_type()) -#define G_JAVA_DEBUGGER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_JAVA_DEBUGGER, GJavaDebugger)) -#define G_IS_JAVA_DEBUGGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_JAVA_DEBUGGER)) -#define G_JAVA_DEBUGGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_JAVA_DEBUGGER, GJavaDebuggerClass)) -#define G_IS_JAVA_DEBUGGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_JAVA_DEBUGGER)) -#define G_JAVA_DEBUGGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_JAVA_DEBUGGER, GJavaDebuggerClass)) - - -/* Débogueur utilisant un serveur Java (instance) */ -typedef struct _GJavaDebugger GJavaDebugger; - -/* Débogueur utilisant un serveur Java (classe) */ -typedef struct _GJavaDebuggerClass GJavaDebuggerClass; - - -/* Indique le type défini par la GLib pour le débogueur Java. */ -GType g_java_debugger_get_type(void); - -/* Crée un débogueur utilisant un serveur Java distant. */ -GBinaryDebugger *g_java_debugger_new(GLoadedBinary *, void *); - - -void test_java(void); - - - -#endif /* _DEBUG_JDWP_DEBUGGER_H */ diff --git a/src/debug/jdwp/jdwp_def.h b/src/debug/jdwp/jdwp_def.h deleted file mode 100644 index 4e1ae27..0000000 --- a/src/debug/jdwp/jdwp_def.h +++ /dev/null @@ -1,237 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * jdwp_def.h - transcription du protocole Java Debug Wire Protocol - * - * Copyright (C) 2010-2017 Cyrille Bagard - * - * This file is part of Chrysalide. - * - * Chrysalide 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. - * - * Chrysalide 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 Chrysalide. If not, see . - */ - - -#ifndef _DEBUG_JDWP_JDWP_DEF_H -#define _DEBUG_JDWP_JDWP_DEF_H - - -#include -#include - - - -/** - * Les définitions ci-dessous sont issues des pages Web suivantes : - * - http://download.oracle.com/javase/1.4.2/docs/guide/jpda/jdwp-spec.html - * - http://download.oracle.com/javase/1.4.2/docs/guide/jpda/jdwp/jdwp-protocol.html - */ - - - -/* ---------------------------------------------------------------------------------- */ -/* EN-TETES DE PAQUETS JDWP */ -/* ---------------------------------------------------------------------------------- */ - - -/* En-tête générique */ -typedef struct __attribute__((__packed__)) _jdwp_header -{ - uint32_t length; /* Taille totale du paquet */ - uint32_t id; /* Numéro de séquence */ - uint8_t flags; /* Options diverses */ - - union - { - /* Requête */ - struct - { - uint8_t set; /* Jeu de commandes */ - uint8_t command; /* Identifiant de commande */ - }; - - /* Réponse */ - uint16_t error; /* Numéro d'erreur */ - - }; - -} jdwp_header; - - -#define JDWP_FLAGS_NONE 0x00 -#define JDWP_FLAGS_REPLY 0x80 - - - -/* ---------------------------------------------------------------------------------- */ -/* CONSTANTES UTILISEES DANS JDWP */ -/* ---------------------------------------------------------------------------------- */ - - -/* Constantes TypeTag */ -typedef uint8_t jdwp_type_tag; - -#define JDWP_TYPE_TAG_CLASS 1 /* Le type est une classe */ -#define JDWP_TYPE_TAG_INTERFACE 2 /* Le type est une interface */ -#define JDWP_TYPE_TAG_ARRAY 3 /* Le type est un tableau */ - - - - - - -/* ---------------------------------------------------------------------------------- */ -/* TYPES DE BASE DIVERS POUR JDWP */ -/* ---------------------------------------------------------------------------------- */ - - -/* Identifiant de taille dynamique */ -typedef uint64_t jdwp_dynsized_id; - - - -/* "location" */ -typedef struct _jdwp_location -{ - jdwp_type_tag tag; /* Classe ou interface ? */ - - jdwp_dynsized_id class_id; /* Identifiant correspondant */ - jdwp_dynsized_id method_id; /* Méthode concernée */ - uint64_t index; /* Position dans le code */ - -} jdwp_location; - - -/* "string" */ -typedef struct _jdwp_string -{ - uint32_t length; /* Taille de la chaîne */ - char *value; /* Chaîne encodée en UTF-8 */ - -} jdwp_string; - - - - - - - - -/** - * Jeux de commandes. - */ - -#define JDWP_CST_NONE 0 /* Organisation interne */ -#define JDWP_CST_VIRTUAL_MACHINE 1 -#define JDWP_CST_THREAD_REFERENCE 11 - - -/** - * Sous-commandes d'un jeu. - */ - -/* Organisation interne */ - -#define JDWP_CMD_NONE 0 - -/* VirtualMachine Command Set */ - -#define JDWP_CMD_VM_VERSION 1 -#define JDWP_CMD_VM_ALL_THREADS 4 -#define JDWP_CMD_VM_ID_SIZES 7 - -/* ThreadReference Command Set */ - -#define JDWP_CMD_THREAD_NAME 1 -#define JDWP_CMD_THREAD_FRAMES 6 - - -/** - * Charges utiles des paquets. - */ - -/* JDWP_CMD_VM_VERSION */ - -typedef struct _jdwp_cmd_vm_version_reply -{ - jdwp_string description; /* Infos sur la VM */ - uint32_t jdwp_major; /* Numéro majeur de JDWP */ - uint32_t jdwp_minor; /* Numéro mineur de JDWP */ - jdwp_string vm_version; /* Version JRE de la VM ciblée */ - jdwp_string vm_name; /* Nom de la VM */ - -} jdwp_cmd_vm_version_reply; - -/* JDWP_CMD_VM_ALL_THREADS */ - -typedef struct _jdwp_cmd_vm_allthreads_reply -{ - uint32_t count; /* Taille de la liste */ - jdwp_dynsized_id *threads; /* Identifiant des threads */ - -} jdwp_cmd_vm_allthreads_reply; - -/* JDWP_CMD_VM_ID_SIZES */ - -typedef struct _jdwp_cmd_vm_id_sizes_reply -{ - uint32_t field_id_size; /* taille pour un 'fieldID' */ - uint32_t method_id_size; /* taille pour un 'methodID' */ - uint32_t object_id_size; /* taille pour un 'objectID' */ - uint32_t reference_type_id_size; /* taille pour un '...TypeID' */ - uint32_t frame_id_size; /* taille pour un 'frameID' */ - -} jdwp_cmd_vm_id_sizes_reply; - -/* JDWP_CMD_THREAD_NAME */ - -typedef struct _jdwp_cmd_thread_name_request -{ - jdwp_dynsized_id id; /* Identifiant du thread visé */ - -} jdwp_cmd_thread_name_request; - -typedef struct _jdwp_cmd_thread_name_reply -{ - jdwp_string name; /* Désignation humaine */ - -} jdwp_cmd_thread_name_reply; - -/* JDWP_CMD_THREAD_FRAMES */ - -typedef struct _jdwp_cmd_thread_frames_request -{ - jdwp_dynsized_id id; /* Identifiant du thread visé */ - uint32_t start; /* Première frame à traiter */ - uint32_t length; /* Longueur de la liste ou -1 */ - -} jdwp_cmd_thread_frames_request; - -#define ALL_FRAMES 0xffffffff - -typedef struct _jdwp_thread_frame -{ - jdwp_dynsized_id frame_id; /* Identifiant de la frame */ - jdwp_location location; /* Localisation de la frame */ - -} jdwp_thread_frame; - -typedef struct _jdwp_cmd_thread_frames_reply -{ - uint32_t count; /* Taille de la liste */ - jdwp_thread_frame *frames; /* Liste de frames */ - -} jdwp_cmd_thread_frames_reply; - - - -#endif /* _DEBUG_JDWP_JDWP_DEF_H */ diff --git a/src/debug/jdwp/misc/Makefile.am b/src/debug/jdwp/misc/Makefile.am deleted file mode 100644 index aec026d..0000000 --- a/src/debug/jdwp/misc/Makefile.am +++ /dev/null @@ -1,20 +0,0 @@ - -noinst_LTLIBRARIES = libdebugjdwpmisc.la - -libdebugjdwpmisc_la_SOURCES = \ - header.h header.c \ - id.h id.c \ - location.h location.c \ - types.h types.c - -libdebugjdwpmisc_la_LDFLAGS = - - -devdir = $(includedir)/chrysalide/$(subdir:src/%=%) - -dev_HEADERS = $(libdebugjdwpmisc_la_SOURCES:%c=) - - -AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) - -AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) diff --git a/src/debug/jdwp/misc/header.c b/src/debug/jdwp/misc/header.c deleted file mode 100644 index 82ba187..0000000 --- a/src/debug/jdwp/misc/header.c +++ /dev/null @@ -1,196 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * header.c - constitution des deux types d'en-têtes JDWP - * - * Copyright (C) 2010-2017 Cyrille Bagard - * - * This file is part of Chrysalide. - * - * Chrysalide 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. - * - * Chrysalide 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 Chrysalide. If not, see . - */ - - -#include "header.h" - - -#include - - -#include "../../../common/endianness.h" - - - -/****************************************************************************** -* * -* Paramètres : header = en-tête logicielle au format local à constituer. * -* blob = en-tête en gros boutiste du paquet à constituer. * -* length = taille totale du paquet. * -* set = jeu de commandes de la requête. * -* command = commande proprement dite. * -* * -* Description : Définit une en-tête de requête au format JDWP. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void set_jdwp_request_header(jdwp_header *header, bin_t *blob, uint32_t length, uint8_t set, uint8_t command) -{ - off_t pos; /* Tête d'écriture */ - - pos = 0; - - length += sizeof(jdwp_header); - - /* Encodage local */ - - header->length = length; - header->id = 1; - header->flags = JDWP_FLAGS_NONE; - - header->set = set; - header->command = command; - - /* Encodage gros boutiste */ - - write_u32(&length, blob, &pos, sizeof(jdwp_header), SRE_BIG); - write_u32((uint32_t []) { 1 }, blob, &pos, sizeof(jdwp_header), SRE_BIG); - write_u8((uint8_t []) { JDWP_FLAGS_NONE }, blob, &pos, sizeof(jdwp_header), SRE_BIG); - - write_u8(&set, blob, &pos, sizeof(jdwp_header), SRE_BIG); - write_u8(&command, blob, &pos, sizeof(jdwp_header), SRE_BIG); - -} - - -/****************************************************************************** -* * -* Paramètres : header = en-tête logicielle au format local à constituer. * -* blob = en-tête en gros boutiste du paquet à constituer. * -* length = taille totale du paquet. * -* lastid = jeton du paquet à l'origine du besoin de réponse. * -* error = éventuelle indication d'erreur. * -* * -* Description : Définit une en-tête de réponse au format JDWP. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void set_jdwp_reply_header(jdwp_header *header, bin_t *blob, uint32_t length, uint32_t lastid, uint16_t error) -{ - off_t pos; /* Tête d'écriture */ - - pos = 0; - - length += sizeof(jdwp_header); - - /* Encodage local */ - - header->length = length; - header->id = 1; - header->flags = JDWP_FLAGS_REPLY; - - header->error = error; - - /* Encodage gros boutiste */ - - write_u32(&length, blob, &pos, sizeof(jdwp_header), SRE_BIG); - write_u32((uint32_t []) { 1 }, blob, &pos, sizeof(jdwp_header), SRE_BIG); - write_u8((uint8_t []) { JDWP_FLAGS_REPLY }, blob, &pos, sizeof(jdwp_header), SRE_BIG); - - write_u16(&error, blob, &pos, sizeof(jdwp_header), SRE_BIG); - -} - - -/****************************************************************************** -* * -* Paramètres : header = en-tête logicielle au format local à constituer. * -* blob = en-tête en gros boutiste du paquet à constituer. * -* * -* Description : Enregistre au format binaire la valeur actuelle de la taille.* -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void update_jdwp_header_length(const jdwp_header *header, bin_t *blob) -{ - off_t pos; /* Tête d'écriture */ - - pos = 0; - - write_u32(&header->length, blob, &pos, sizeof(jdwp_header), SRE_BIG); - -} - - -/****************************************************************************** -* * -* Paramètres : blob = flux de données à analyser. * -* header = en-tête de paquet JDWP reconstituée. [OUT] * -* * -* Description : Lit une en-tête de paquet au format JDWP. * -* * -* Retour : Bilan de l'opération : true en cas de succès, false sinon. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool get_jdwp_header(const bin_t *blob, jdwp_header *header) -{ - off_t pos; /* Tête de lecture */ - off_t len; /* Taille standard d'en-tête */ - - pos = 0; - len = sizeof(jdwp_header); - - if (!read_u32(&header->length, blob, &pos, len, SRE_BIG)) - return false; - - if (!read_u32(&header->id, blob, &pos, len, SRE_BIG)) - return false; - - if (!read_u8(&header->flags, blob, &pos, len)) - return false; - - /* Réponse ? */ - if (header->flags & JDWP_FLAGS_REPLY) - { - if (!read_u16(&header->error, blob, &pos, len, SRE_BIG)) - return false; - } - - /* Requête ! */ - else - { - if (!read_u8(&header->set, blob, &pos, len)) - return false; - - if (!read_u8(&header->command, blob, &pos, len)) - return false; - - } - - return true; - -} diff --git a/src/debug/jdwp/misc/header.h b/src/debug/jdwp/misc/header.h deleted file mode 100644 index e1bedad..0000000 --- a/src/debug/jdwp/misc/header.h +++ /dev/null @@ -1,50 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * header.h - prototypes pour la constitution des deux types d'en-têtes JDWP - * - * Copyright (C) 2010-2017 Cyrille Bagard - * - * This file is part of Chrysalide. - * - * Chrysalide 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. - * - * Chrysalide 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 Chrysalide. If not, see . - */ - - -#ifndef _DEBUG_JDWP_MISC_HEADER_H -#define _DEBUG_JDWP_MISC_HEADER_H - - -#include - - -#include "../jdwp_def.h" -#include "../../../arch/archbase.h" - - - -/* Définit une en-tête de requête au format JDWP. */ -void set_jdwp_request_header(jdwp_header *, bin_t *, uint32_t, uint8_t, uint8_t); - -/* Définit une en-tête de réponse au format JDWP. */ -void set_jdwp_reply_header(jdwp_header *, bin_t *, uint32_t, uint32_t, uint16_t); - -/* Enregistre au format binaire la valeur actuelle de la taille. */ -void update_jdwp_header_length(const jdwp_header *, bin_t *); - -/* Lit une en-tête de paquet au format JDWP. */ -bool get_jdwp_header(const bin_t *, jdwp_header *); - - - -#endif /* _DEBUG_JDWP_MISC_HEADER_H */ diff --git a/src/debug/jdwp/misc/id.c b/src/debug/jdwp/misc/id.c deleted file mode 100644 index ba2724e..0000000 --- a/src/debug/jdwp/misc/id.c +++ /dev/null @@ -1,148 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * id.c - constitution des identifiants de taille dynamique - * - * Copyright (C) 2012-2017 Cyrille Bagard - * - * This file is part of Chrysalide. - * - * Chrysalide 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. - * - * Chrysalide 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 Chrysalide. If not, see . - */ - - -#include "id.h" - - -#include "../../../common/endianness.h" - - - -/****************************************************************************** -* * -* Paramètres : id = identifiant à fournir. * -* size = référence pour la taille utilisée. * -* blob = flux de données à analyser. [OUT] * -* pos = position courante dans ce flux. [OUT] * -* len = taille totale des données à analyser. * -* * -* Description : Ecrit un identifiant enregistré dans une taille dynamique. * -* * -* Retour : Bilan de l'opération : true en cas de succès, false sinon. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool _set_jdwp_dynsized_id(const jdwp_dynsized_id *id, uint32_t size, bin_t *blob, off_t *pos, off_t len) -{ - uint8_t id8; /* Valeur sur 1 octets */ - uint16_t id16; /* Valeur sur 2 octets */ - uint32_t id32; /* Valeur sur 4 octets */ - uint64_t id64; /* Valeur sur 8 octets */ - - switch (size) - { - case 1: - id8 = (uint8_t)*id; - if (!write_u8(&id8, blob, pos, len, SRE_BIG)) - return false; - break; - - case 2: - id16 = (uint16_t)*id; - if (!write_u16(&id16, blob, pos, len, SRE_BIG)) - return false; - break; - - case 4: - id32 = (uint32_t)*id; - if (!write_u32(&id32, blob, pos, len, SRE_BIG)) - return false; - break; - - case 8: - id64 = (uint64_t)*id; - if (!write_u64(&id64, blob, pos, len, SRE_BIG)) - return false; - break; - - default: - return false; - break; - - } - - return true; - -} - - -/****************************************************************************** -* * -* Paramètres : blob = flux de données à analyser. * -* pos = position courante dans ce flux. [OUT] * -* len = taille totale des données à analyser. * -* size = référence pour la taille utilisée. * -* id = identifiant à fournir. [OUT] * -* * -* Description : Lit un identifiant enregistré dans une taille dynamique. * -* * -* Retour : Bilan de l'opération : true en cas de succès, false sinon. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool _get_jdwp_dynsized_id(const bin_t *blob, off_t *pos, off_t len, uint32_t size, jdwp_dynsized_id *id) -{ - uint8_t id8; /* Valeur sur 1 octets */ - uint16_t id16; /* Valeur sur 2 octets */ - uint32_t id32; /* Valeur sur 4 octets */ - uint64_t id64; /* Valeur sur 8 octets */ - - switch (size) - { - case 1: - if (!read_u8(&id8, blob, pos, len)) - return false; - *id = (jdwp_dynsized_id)id8; - break; - - case 2: - if (!read_u16(&id16, blob, pos, len, SRE_BIG)) - return false; - *id = (jdwp_dynsized_id)id16; - break; - - case 4: - if (!read_u32(&id32, blob, pos, len, SRE_BIG)) - return false; - *id = (jdwp_dynsized_id)id32; - break; - - case 8: - if (!read_u64(&id64, blob, pos, len, SRE_BIG)) - return false; - *id = (jdwp_dynsized_id)id64; - break; - - default: - return false; - break; - - } - - return true; - -} diff --git a/src/debug/jdwp/misc/id.h b/src/debug/jdwp/misc/id.h deleted file mode 100644 index 0000886..0000000 --- a/src/debug/jdwp/misc/id.h +++ /dev/null @@ -1,131 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * id.h - prototypes pour la constitution des identifiants de taille dynamique - * - * Copyright (C) 2012-2017 Cyrille Bagard - * - * This file is part of Chrysalide. - * - * Chrysalide 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. - * - * Chrysalide 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 Chrysalide. If not, see . - */ - - -#ifndef _DEBUG_JDWP_MISC_ID_H -#define _DEBUG_JDWP_MISC_ID_H - - -#include - - -#include "../jdwp_def.h" -#include "../../../arch/archbase.h" - - - -/* Ecrit un identifiant enregistré dans une taille dynamique. */ -bool _set_jdwp_dynsized_id(const jdwp_dynsized_id *, uint32_t, bin_t *, off_t *, off_t); - - -#define set_jdwp_object_id(id, sizes, blob, pos, len) \ - _set_jdwp_dynsized_id(id, sizes->object_id_size, blob, pos, len) - -#define set_jdwp_thread_id(id, sizes, blob, pos, len) \ - _set_jdwp_dynsized_id(id, sizes->object_id_size, blob, pos, len) - -#define set_jdwp_thread_group_id(id, sizes, blob, pos, len) \ - _set_jdwp_dynsized_id(id, sizes->object_id_size, blob, pos, len) - -#define set_jdwp_string_id(id, sizes, blob, pos, len) \ - _set_jdwp_dynsized_id(id, sizes->object_id_size, blob, pos, len) - -#define set_jdwp_class_loader_id(id, sizes, blob, pos, len) \ - _set_jdwp_dynsized_id(id, sizes->object_id_size, blob, pos, len) - -#define set_jdwp_class_object_id(id, sizes, blob, pos, len) \ - _set_jdwp_dynsized_id(id, sizes->object_id_size, blob, pos, len) - -#define set_jdwp_array_id(id, sizes, blob, pos, len) \ - _set_jdwp_dynsized_id(id, sizes->object_id_size, blob, pos, len) - -#define set_jdwp_reference_type_id(id, sizes, blob, pos, len) \ - _set_jdwp_dynsized_id(id, sizes->object_id_size, blob, pos, len) - -#define set_jdwp_class_id(id, sizes, blob, pos, len) \ - _set_jdwp_dynsized_id(id, sizes->reference_type_id_size, blob, pos, len) - -#define set_jdwp_interface_id(id, sizes, blob, pos, len) \ - _set_jdwp_dynsized_id(id, sizes->reference_type_id_size, blob, pos, len) - -#define set_jdwp_array_type_id(id, sizes, blob, pos, len) \ - _set_jdwp_dynsized_id(id, sizes->reference_type_id_size, blob, pos, len) - -#define set_jdwp_method_id(id, sizes, blob, pos, len) \ - _set_jdwp_dynsized_id(id, sizes->method_id_size, blob, pos, len) - -#define set_jdwp_field_id(id, sizes, blob, pos, len) \ - _set_jdwp_dynsized_id(id, sizes->field_id_size, blob, pos, len) - -#define set_jdwp_frame_id(id, sizes, blob, pos, len) \ - _set_jdwp_dynsized_id(id, sizes->frame_id_size, blob, pos, len) - - -/* Lit un identifiant enregistré dans une taille dynamique. */ -bool _get_jdwp_dynsized_id(const bin_t *, off_t *, off_t, uint32_t, jdwp_dynsized_id *); - - -#define get_jdwp_object_id(blob, pos, len, sizes, id) \ - _get_jdwp_dynsized_id(blob, pos, len, sizes->object_id_size, id) - -#define get_jdwp_thread_id(blob, pos, len, sizes, id) \ - _get_jdwp_dynsized_id(blob, pos, len, sizes->object_id_size, id) - -#define get_jdwp_thread_group_id(blob, pos, len, sizes, id) \ - _get_jdwp_dynsized_id(blob, pos, len, sizes->object_id_size, id) - -#define get_jdwp_string_id(blob, pos, len, sizes, id) \ - _get_jdwp_dynsized_id(blob, pos, len, sizes->object_id_size, id) - -#define get_jdwp_class_loader_id(blob, pos, len, sizes, id) \ - _get_jdwp_dynsized_id(blob, pos, len, sizes->object_id_size, id) - -#define get_jdwp_class_object_id(blob, pos, len, sizes, id) \ - _get_jdwp_dynsized_id(blob, pos, len, sizes->object_id_size, id) - -#define get_jdwp_array_id(blob, pos, len, sizes, id) \ - _get_jdwp_dynsized_id(blob, pos, len, sizes->object_id_size, id) - -#define get_jdwp_reference_type_id(blob, pos, len, sizes, id) \ - _get_jdwp_dynsized_id(blob, pos, len, sizes->object_id_size, id) - -#define get_jdwp_class_id(blob, pos, len, sizes, id) \ - _get_jdwp_dynsized_id(blob, pos, len, sizes->reference_type_id_size, id) - -#define get_jdwp_interface_id(blob, pos, len, sizes, id) \ - _get_jdwp_dynsized_id(blob, pos, len, sizes->reference_type_id_size, id) - -#define get_jdwp_array_type_id(blob, pos, len, sizes, id) \ - _get_jdwp_dynsized_id(blob, pos, len, sizes->reference_type_id_size, id) - -#define get_jdwp_method_id(blob, pos, len, sizes, id) \ - _get_jdwp_dynsized_id(blob, pos, len, sizes->method_id_size, id) - -#define get_jdwp_field_id(blob, pos, len, sizes, id) \ - _get_jdwp_dynsized_id(blob, pos, len, sizes->field_id_size, id) - -#define get_jdwp_frame_id(blob, pos, len, sizes, id) \ - _get_jdwp_dynsized_id(blob, pos, len, sizes->frame_id_size, id) - - - -#endif /* _DEBUG_JDWP_MISC_ID_H */ diff --git a/src/debug/jdwp/misc/location.c b/src/debug/jdwp/misc/location.c deleted file mode 100644 index dbf14b1..0000000 --- a/src/debug/jdwp/misc/location.c +++ /dev/null @@ -1,64 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * location.c - constitution des localisations d'instructions courantes - * - * Copyright (C) 2012-2017 Cyrille Bagard - * - * This file is part of Chrysalide. - * - * Chrysalide 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. - * - * Chrysalide 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 Chrysalide. If not, see . - */ - - -#include "location.h" - - -#include "id.h" -#include "../../../common/endianness.h" - - - -/****************************************************************************** -* * -* Paramètres : blob = flux de données à analyser. * -* pos = position courante dans ce flux. [OUT] * -* len = taille totale des données à analyser. * -* sizes = référence pour la taille utilisée. * -* loc = localisation à fournir. [OUT] * -* * -* Description : Lit une localisation d'instruction courante dans l'exécution.* -* * -* Retour : Bilan de l'opération : true en cas de succès, false sinon. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool get_jdwp_location(const bin_t *blob, off_t *pos, off_t len, const jdwp_cmd_vm_id_sizes_reply *sizes, jdwp_location *loc) -{ - if (!read_u8(&loc->tag, blob, pos, len)) - return false; - - if (!get_jdwp_class_id(blob, pos, len, sizes, &loc->class_id)) - return false; - - if (!get_jdwp_method_id(blob, pos, len, sizes, &loc->method_id)) - return false; - - if (!read_u64(&loc->index, blob, pos, len, SRE_BIG)) - return false; - - return true; - -} diff --git a/src/debug/jdwp/misc/location.h b/src/debug/jdwp/misc/location.h deleted file mode 100644 index 4b9bf1b..0000000 --- a/src/debug/jdwp/misc/location.h +++ /dev/null @@ -1,40 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * location.h - prototypes pour la constitution des localisations d'instructions courantes - * - * Copyright (C) 2012-2017 Cyrille Bagard - * - * This file is part of Chrysalide. - * - * Chrysalide 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. - * - * Chrysalide 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 Chrysalide. If not, see . - */ - - -#ifndef _DEBUG_JDWP_MISC_LOCATION_H -#define _DEBUG_JDWP_MISC_LOCATION_H - - -#include - - -#include "../jdwp_def.h" -#include "../../../arch/archbase.h" - - -/* Lit une localisation d'instruction courante dans l'exécution. */ -bool get_jdwp_location(const bin_t *, off_t *, off_t, const jdwp_cmd_vm_id_sizes_reply *, jdwp_location *); - - - -#endif /* _DEBUG_JDWP_MISC_LOCATION_H */ diff --git a/src/debug/jdwp/misc/types.c b/src/debug/jdwp/misc/types.c deleted file mode 100644 index b901704..0000000 --- a/src/debug/jdwp/misc/types.c +++ /dev/null @@ -1,85 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * types.c - constitution des types communs de JDWP - * - * Copyright (C) 2010-2017 Cyrille Bagard - * - * This file is part of Chrysalide. - * - * Chrysalide 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. - * - * Chrysalide 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 Chrysalide. If not, see . - */ - - -#include "types.h" - - -#include -#include - - -#include "../../../common/endianness.h" - - - -/****************************************************************************** -* * -* Paramètres : blob = flux de données à analyser. * -* pos = position courante dans ce flux. [OUT] * -* len = taille totale des données à analyser. * -* str = chaîne de caractères à la sauce JDWP. [OUT] * -* * -* Description : Lit une chaîne de caractères UTF-8 au format JDWP. * -* * -* Retour : Bilan de l'opération : true en cas de succès, false sinon. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool get_jdwp_string(const bin_t *blob, off_t *pos, off_t len, jdwp_string *str) -{ - if (!read_u32(&str->length, blob, pos, len, SRE_BIG)) - return false; - - if ((*pos + str->length) > len) - return false; - - str->value = (char *)calloc(str->length + 1, sizeof(char)); - memcpy(str->value, &blob[*pos], str->length); - - *pos += str->length; - - return true; - -} - - -/****************************************************************************** -* * -* Paramètres : str = chaîne de caractères à la sauce JDWP. * -* * -* Description : Libère de la mémoire une chaîne de caractères UTF-8 JDWP. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void free_jdwp_string(jdwp_string *str) -{ - if (str->value != NULL) - free(str->value); - -} diff --git a/src/debug/jdwp/misc/types.h b/src/debug/jdwp/misc/types.h deleted file mode 100644 index 11f9c60..0000000 --- a/src/debug/jdwp/misc/types.h +++ /dev/null @@ -1,44 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * types.h - prototypes pour la constitution des types communs de JDWP - * - * Copyright (C) 2010-2017 Cyrille Bagard - * - * This file is part of Chrysalide. - * - * Chrysalide 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. - * - * Chrysalide 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 Chrysalide. If not, see . - */ - - -#ifndef _DEBUG_JDWP_MISC_TYPES_H -#define _DEBUG_JDWP_MISC_TYPES_H - - -#include - - -#include "../jdwp_def.h" -#include "../../../arch/archbase.h" - - - -/* Lit une chaîne de caractères UTF-8 au format JDWP. */ -bool get_jdwp_string(const bin_t *, off_t *, off_t, jdwp_string *); - -/* Libère de la mémoire une chaîne de caractères UTF-8 JDWP. */ -void free_jdwp_string(jdwp_string *); - - - -#endif /* _DEBUG_JDWP_MISC_TYPES_H */ diff --git a/src/debug/jdwp/packet.c b/src/debug/jdwp/packet.c deleted file mode 100644 index 3eb6625..0000000 --- a/src/debug/jdwp/packet.c +++ /dev/null @@ -1,422 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * packet.c - définition des paquets destiné au protocole JDWP - * - * Copyright (C) 2010-2017 Cyrille Bagard - * - * This file is part of Chrysalide. - * - * Chrysalide 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. - * - * Chrysalide 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 Chrysalide. If not, see . - */ - - -#include "packet.h" - - -#include "misc/header.h" -#include "../packet-int.h" -#include "../../arch/archbase.h" -#include "../../common/endianness.h" - - - -/* Répresentation d'un paquet de débogage JDWP (instance) */ -struct _GJdwpPacket -{ - GDebugPacket parent; /* A laisser en premier */ - - jdwp_header header; /* En-tête du paquet JDWP */ - bin_t hblob[sizeof(jdwp_header)]; /* Contenu encodé en B.E. */ - - jdwp_payload payload; /* Charge utile du paquet */ - bin_t pblob[sizeof(jdwp_payload)]; /* Contenu encodé en B.E. */ - bool got; /* Précise le type de charge */ - -}; - - -/* Répresentation d'un paquet de débogage JDWP (classe) */ -struct _GJdwpPacketClass -{ - GDebugPacketClass parent; /* A laisser en premier */ - - jdwp_cmd_vm_id_sizes_reply sizes; /* Réf. des tailles dynamiques */ - -}; - - -/* Initialise la classe des paquets de débogage JDWP. */ -static void g_jdwp_packet_class_init(GJdwpPacketClass *); - -/* Initialise une instance de paquet de débogage JDWP. */ -static void g_jdwp_packet_init(GJdwpPacket *); - -/* Précise les zones mémoires correspondant au contenu. */ -static void g_jdwp_packet_vectorize(GJdwpPacket *, struct iovec [UIO_MAXIOV], int *); - - - -/* Indique le type défini pour un paquet de débogage JDWP. */ -G_DEFINE_TYPE(GJdwpPacket, g_jdwp_packet, G_TYPE_DEBUG_PACKET); - - -/****************************************************************************** -* * -* Paramètres : klass = classe à initialiser. * -* * -* Description : Initialise la classe des paquets de débogage JDWP. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_jdwp_packet_class_init(GJdwpPacketClass *klass) -{ - -} - - -/****************************************************************************** -* * -* Paramètres : packet = instance à initialiser. * -* * -* Description : Initialise une instance de paquet de débogage JDWP. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_jdwp_packet_init(GJdwpPacket *packet) -{ - GDebugPacket *dpkt; /* Version parente */ - - dpkt = G_DEBUG_PACKET(packet); - - dpkt->vectorize = (debug_vectorize_fc)g_jdwp_packet_vectorize; - -} - - -/****************************************************************************** -* * -* Paramètres : packet = instance à utiliser comme intermédiaire. * -* sizes = références pour la valeur des tailles dynamiques. * -* * -* Description : Enregistre les différentes tailles dynamiques. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void g_jdwp_packet_set_sizes(GJdwpPacket *packet, const jdwp_cmd_vm_id_sizes_reply *sizes) -{ - G_JDWP_PACKET_GET_CLASS(packet)->sizes = *sizes; - -} - - -/****************************************************************************** -* * -* Paramètres : packet = instance à convertir. * -* iov = table de vecteurs. [OUT] * -* iovcnt = quantité de champs renseignés. [OUT] * -* * -* Description : Précise les zones mémoires correspondant au contenu. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_jdwp_packet_vectorize(GJdwpPacket *packet, struct iovec iov[UIO_MAXIOV], int *iovcnt) -{ - uint32_t length; /* Quantité de données */ - bool empty; /* Présence d'une charge utile */ - - read_u32(&length, packet->hblob, (off_t []) { 0 }, sizeof(jdwp_header), SRE_BIG); - - iov[0].iov_base = packet->hblob; - iov[0].iov_len = sizeof(jdwp_header); - - empty = (length == sizeof(jdwp_header)); - - if (!empty) - { - iov[1].iov_base = packet->pblob; - iov[1].iov_len = length - sizeof(jdwp_header); - } - - *iovcnt = (empty ? 1 : 2); - -} - - -/****************************************************************************** -* * -* Paramètres : packet = instance à consulter. * -* * -* Description : Fournit l'adresse des données de l'en-tête d'un paquet JDWP. * -* * -* Retour : Adresse des données de l'en-tête (à priori de requête). * -* * -* Remarques : - * -* * -******************************************************************************/ - -jdwp_header *g_jdwp_packet_get_header(GJdwpPacket *packet) -{ - return &packet->header; - -} - - -/****************************************************************************** -* * -* Paramètres : packet = instance à consulter. * -* * -* Description : Fournit l'adresse des données de l'en-tête d'un paquet JDWP. * -* * -* Retour : Adresse des données de l'en-tête (à priori de requête). * -* * -* Remarques : - * -* * -******************************************************************************/ - -bin_t *g_jdwp_packet_get_hblob(GJdwpPacket *packet) -{ - return packet->hblob; - -} - - -/****************************************************************************** -* * -* Paramètres : packet = instance à mettre à jour. * -* * -* Description : Recompose l'en-tête d'un paquet à partir de données brutes. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool g_jdwp_packet_parse_header(GJdwpPacket *packet) -{ - return get_jdwp_header(packet->hblob, &packet->header); - -} - - -/****************************************************************************** -* * -* Paramètres : packet = paquet à mettre à jour. * -* set = jeu de commandes de la requête. * -* command = commande proprement dite. * -* * -* Description : Définit l'en-tête du paquet pour une requête au format JDWP. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void g_jdwp_packet_set_request_header(GJdwpPacket *packet, uint8_t set, uint8_t command) -{ - set_jdwp_request_header(&packet->header, packet->hblob, - 0, set, command); - - packet->got = false; - -} - - -/****************************************************************************** -* * -* Paramètres : packet = paquet à mettre à jour. * -* lastid = jeton du paquet à l'origine du besoin de réponse. * -* error = éventuelle indication d'erreur. * -* * -* Description : Définit l'en-tête du paquet pour une réponse au format JDWP. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void g_jdwp_packet_set_reply_header(GJdwpPacket *packet, uint32_t lastid, uint16_t error) -{ - set_jdwp_reply_header(&packet->header, packet->hblob, - 0, lastid, error); - - packet->got = false; - -} - - -/****************************************************************************** -* * -* Paramètres : packet = instance à consulter. * -* payload = modèle de charge à copier. * -* * -* Description : Fournit l'adresse des charges utiles d'un paquet JDWP. * -* * -* Retour : Adresse des données d'une charge utile. * -* * -* Remarques : - * -* * -******************************************************************************/ - -void g_jdwp_packet_set_payload(GJdwpPacket *packet, const jdwp_payload *payload) -{ - off_t len; /* Quantité max puis effective */ - - len = sizeof(jdwp_payload); - - set_jdwp_payload(payload, packet->header.set, packet->header.command, - &G_JDWP_PACKET_GET_CLASS(packet)->sizes, - packet->pblob, &len); - - packet->header.length += len; - - update_jdwp_header_length(&packet->header, packet->hblob); - - packet->got = false; - -} - - -/****************************************************************************** -* * -* Paramètres : packet = instance à consulter. * -* * -* Description : Fournit l'adresse des charges utiles d'un paquet JDWP. * -* * -* Retour : Adresse des données d'une charge utile. * -* * -* Remarques : - * -* * -******************************************************************************/ - -jdwp_payload *g_jdwp_packet_get_payload(GJdwpPacket *packet) -{ - return &packet->payload; - -} - - -/****************************************************************************** -* * -* Paramètres : packet = instance à consulter. * -* * -* Description : Fournit l'adresse des charges utiles d'un paquet JDWP. * -* * -* Retour : Adresse des données d'une charge utile. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bin_t *g_jdwp_packet_get_pblob(GJdwpPacket *packet) -{ - return packet->pblob; - -} - - -/****************************************************************************** -* * -* Paramètres : packet = instance à mettre à jour. * -* set = jeu de commandes concerné. * -* cmd = identifiant d'une commande donnée. * -* * -* Description : Recompose une charge utile à partir de ses données brutes. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool g_jdwp_packet_parse_payload(GJdwpPacket *packet, uint8_t set, uint8_t cmd) -{ - bool result; /* Bilan à retourner */ - - result = get_jdwp_payload(packet->pblob, packet->header.length - sizeof(jdwp_header)/* FIXME */, - set, cmd, &G_JDWP_PACKET_GET_CLASS(packet)->sizes, &packet->payload); - - if (result) - { - packet->header.set = set; - packet->header.command = cmd; - } - - packet->got = true; - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : packet = instance à mettre à jour. * -* * -* Description : Libère la mémoire occupée par une charge utile de paquet. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void g_jdwp_packet_free_payload(GJdwpPacket *packet) -{ - if (packet->header.set == JDWP_CST_NONE || packet->header.command == JDWP_CMD_NONE) - return; - - free_jdwp_payload(&packet->payload, packet->got, - packet->header.set, packet->header.command); - -} - - -/****************************************************************************** -* * -* Paramètres : reply = instance de paquet à analyser. * -* packet = instance de paquet de référence. * -* * -* Description : Détermine si un paquet est une réponse à un premier paquet. * -* * -* Retour : true si le paquet correspond à la réponse attendue. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool g_jdwp_packet_is_reply(const GJdwpPacket *reply, const GJdwpPacket *packet) -{ - return (reply->header.id == packet->header.id - && reply->header.flags & JDWP_FLAGS_REPLY); - -} diff --git a/src/debug/jdwp/packet.h b/src/debug/jdwp/packet.h deleted file mode 100644 index 9475c21..0000000 --- a/src/debug/jdwp/packet.h +++ /dev/null @@ -1,93 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * packet.h - prototypes pour la définition des paquets destiné au protocole JDWP - * - * Copyright (C) 2010-2017 Cyrille Bagard - * - * This file is part of Chrysalide. - * - * Chrysalide 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. - * - * Chrysalide 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 Chrysalide. If not, see . - */ - - -#ifndef _DEBUG_JDWP_PACKET_H -#define _DEBUG_JDWP_PACKET_H - - -#include - - -#include "jdwp_def.h" -#include "sets/list.h" - - - -#define G_TYPE_JDWP_PACKET g_jdwp_packet_get_type() -#define G_JDWP_PACKET(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_jdwp_packet_get_type(), GJdwpPacket)) -#define G_IS_JDWP_PACKET(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_jdwp_packet_get_type())) -#define G_JDWP_PACKET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_JDWP_PACKET, GJdwpPacketClass)) -#define G_IS_JDWP_PACKET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_JDWP_PACKET)) -#define G_JDWP_PACKET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_JDWP_PACKET, GJdwpPacketClass)) - - -/* Répresentation d'un paquet de débogage JDWP (instance) */ -typedef struct _GJdwpPacket GJdwpPacket; - -/* Répresentation d'un paquet de débogage JDWP (classe) */ -typedef struct _GJdwpPacketClass GJdwpPacketClass; - - - -/* Indique le type défini pour un paquet de débogage JDWP. */ -GType g_jdwp_packet_get_type(void); - -/* Enregistre les différentes tailles dynamiques. */ -void g_jdwp_packet_set_sizes(GJdwpPacket *, const jdwp_cmd_vm_id_sizes_reply *); - -/* Fournit l'adresse des données de l'en-tête d'un paquet JDWP. */ -jdwp_header *g_jdwp_packet_get_header(GJdwpPacket *); - -/* Fournit l'adresse des données de l'en-tête d'un paquet JDWP. */ -bin_t *g_jdwp_packet_get_hblob(GJdwpPacket *); - -/* Recompose l'en-tête d'un paquet à partir de données brutes. */ -bool g_jdwp_packet_parse_header(GJdwpPacket *); - -/* Définit l'en-tête du paquet pour une requête au format JDWP. */ -void g_jdwp_packet_set_request_header(GJdwpPacket *, uint8_t, uint8_t); - -/* Définit l'en-tête du paquet pour une réponse au format JDWP. */ -void g_jdwp_packet_set_reply_header(GJdwpPacket *, uint32_t, uint16_t); - -/* Fournit l'adresse des charges utiles d'un paquet JDWP. */ -void g_jdwp_packet_set_payload(GJdwpPacket *, const jdwp_payload *); - -/* Fournit l'adresse des charges utiles d'un paquet JDWP. */ -jdwp_payload *g_jdwp_packet_get_payload(GJdwpPacket *); - -/* Fournit l'adresse des charges utiles d'un paquet JDWP. */ -bin_t *g_jdwp_packet_get_pblob(GJdwpPacket *); - -/* Recompose une charge utile à partir de ses données brutes. */ -bool g_jdwp_packet_parse_payload(GJdwpPacket *, uint8_t, uint8_t); - -/* Libère la mémoire occupée par une charge utile de paquet. */ -void g_jdwp_packet_free_payload(GJdwpPacket *); - -/* Détermine si un paquet est une réponse à un premier paquet. */ -bool g_jdwp_packet_is_reply(const GJdwpPacket *, const GJdwpPacket *); - - - -#endif /* _DEBUG_JDWP_PACKET_H */ diff --git a/src/debug/jdwp/sets/Makefile.am b/src/debug/jdwp/sets/Makefile.am deleted file mode 100644 index cc149b7..0000000 --- a/src/debug/jdwp/sets/Makefile.am +++ /dev/null @@ -1,19 +0,0 @@ - -noinst_LTLIBRARIES = libdebugjdwpsets.la - -libdebugjdwpsets_la_SOURCES = \ - list.h list.c \ - thread.h thread.c \ - vm.h vm.c - -libdebugjdwpsets_la_LDFLAGS = - - -devdir = $(includedir)/chrysalide/$(subdir:src/%=%) - -dev_HEADERS = $(libdebugjdwpsets_la_SOURCES:%c=) - - -AM_CPPFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) - -AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) diff --git a/src/debug/jdwp/sets/list.c b/src/debug/jdwp/sets/list.c deleted file mode 100644 index fcab7be..0000000 --- a/src/debug/jdwp/sets/list.c +++ /dev/null @@ -1,191 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * list.c - ensemble des jeux de commandes de JDWP - * - * Copyright (C) 2010-2017 Cyrille Bagard - * - * This file is part of Chrysalide. - * - * Chrysalide 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. - * - * Chrysalide 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 Chrysalide. If not, see . - */ - - -#include "list.h" - - -#include - - -#include "thread.h" -#include "vm.h" - - -/* Consitue un contenu binaire à partir d'une charge utile. */ -typedef bool (* set_jdwp_payload_fc) (const jdwp_payload *, const jdwp_cmd_vm_id_sizes_reply *, bin_t *, off_t *); - -/* Reconstitue une charge utile à partir d'un contenu binaire. */ -typedef bool (* get_jdwp_payload_fc) (const bin_t *, off_t, const jdwp_cmd_vm_id_sizes_reply *, jdwp_payload *); - -/* Libère le contenu d'une charge utile. */ -typedef void (* free_jdwp_payload_fc) (jdwp_payload *); - - -/* Commandes JDWP */ -typedef struct _jdwp_command -{ - set_jdwp_payload_fc set_payload; /* Constitution du binaire */ - free_jdwp_payload_fc free_set_payload; /* Libération de la mémoire */ - get_jdwp_payload_fc get_payload; /* Constitution de la charge */ - free_jdwp_payload_fc free_got_payload; /* Libération de la mémoire */ - -} jdwp_command; - - -/* Energistrement des différents jeux */ -static jdwp_command _commands[][256] = { - - [JDWP_CST_VIRTUAL_MACHINE] = { - - [JDWP_CMD_VM_VERSION] = { - .set_payload = (set_jdwp_payload_fc)NULL, - .free_set_payload = (free_jdwp_payload_fc)NULL, - .get_payload = (get_jdwp_payload_fc)get_jdwp_vm_version, - .free_got_payload = (free_jdwp_payload_fc)free_jdwp_vm_version - }, - - [JDWP_CMD_VM_ALL_THREADS] = { - .set_payload = (set_jdwp_payload_fc)NULL, - .free_set_payload = (free_jdwp_payload_fc)NULL, - .get_payload = (get_jdwp_payload_fc)get_jdwp_vm_all_threads, - .free_got_payload = (free_jdwp_payload_fc)free_jdwp_all_threads - }, - - [JDWP_CMD_VM_ID_SIZES] = { - .set_payload = (set_jdwp_payload_fc)NULL, - .free_set_payload = (free_jdwp_payload_fc)NULL, - .get_payload = (get_jdwp_payload_fc)get_jdwp_vm_id_sizes, - .free_got_payload = (free_jdwp_payload_fc)NULL - } - - }, - - [JDWP_CST_THREAD_REFERENCE] = { - - [JDWP_CMD_THREAD_NAME] = { - .set_payload = (set_jdwp_payload_fc)set_jdwp_thread_name, - .free_set_payload = (free_jdwp_payload_fc)NULL, - .get_payload = (get_jdwp_payload_fc)get_jdwp_thread_name, - .free_got_payload = (free_jdwp_payload_fc)free_jdwp_thread_name_reply - }, - - [JDWP_CMD_THREAD_FRAMES] = { - .set_payload = (set_jdwp_payload_fc)set_jdwp_thread_frames, - .free_set_payload = (free_jdwp_payload_fc)NULL, - .get_payload = (get_jdwp_payload_fc)get_jdwp_thread_frames, - .free_got_payload = (free_jdwp_payload_fc)free_jdwp_thread_frames_reply - } - - } - -}; - - - -/****************************************************************************** -* * -* Paramètres : payload = charge utile à transcrire. * -* set = jeu de commandes concerné. * -* cmd = identifiant d'une commande donnée. * -* sizes = références pour la valeur des tailles dynamiques. * -* blob = futures données binaires brutes. [OUT] * -* len = quantité de données valides. [OUT] * -* * -* Description : Reconstitue un contenu binaire à partir d'une charge utile. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool set_jdwp_payload(const jdwp_payload *payload, uint8_t set, uint8_t cmd, const jdwp_cmd_vm_id_sizes_reply *sizes, bin_t *blob, off_t *len) -{ - bool result; /* Bilan à retourner */ - - if (_commands[set][cmd].set_payload == NULL) result = false; - else result = _commands[set][cmd].set_payload(payload, sizes, blob, len); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : blob = ensemble de données binaires brutes. * -* len = quantité de données valides. * -* set = jeu de commandes concerné. * -* cmd = identifiant d'une commande donnée. * -* sizes = références pour la valeur des tailles dynamiques. * -* payload = charge utile à reconstituer. [OUT] * -* * -* Description : Reconstitue une charge utile à partir d'un contenu binaire. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool get_jdwp_payload(const bin_t *blob, off_t len, uint8_t set, uint8_t cmd, const jdwp_cmd_vm_id_sizes_reply *sizes, jdwp_payload *payload) -{ - bool result; /* Bilan à retourner */ - - if (_commands[set][cmd].get_payload == NULL) result = false; - else result = _commands[set][cmd].get_payload(blob, len, sizes, payload); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : payload = charge utile à supprimer de la mémoire. * -* got = type de charge utile à traiter. * -* set = jeu de commandes concerné. * -* cmd = identifiant d'une commande donnée. * -* * -* Description : Libère le contenu d'une charge utile. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void free_jdwp_payload(jdwp_payload *payload, bool got, uint8_t set, uint8_t cmd) -{ - if (got) - { - if (_commands[set][cmd].free_got_payload != NULL) - _commands[set][cmd].free_got_payload(payload); - } - else - { - if (_commands[set][cmd].free_set_payload != NULL) - _commands[set][cmd].free_set_payload(payload); - } - -} diff --git a/src/debug/jdwp/sets/list.h b/src/debug/jdwp/sets/list.h deleted file mode 100644 index 02a6fac..0000000 --- a/src/debug/jdwp/sets/list.h +++ /dev/null @@ -1,64 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * list.h - prototypes pour l'ensemble des jeux de commandes de JDWP - * - * Copyright (C) 2010-2017 Cyrille Bagard - * - * This file is part of Chrysalide. - * - * Chrysalide 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. - * - * Chrysalide 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 Chrysalide. If not, see . - */ - - -#ifndef _DEBUG_JDWP_SETS_LIST_H -#define _DEBUG_JDWP_SETS_LIST_H - - -#include - - -#include "../jdwp_def.h" -#include "../../../arch/archbase.h" - - - -/* Ensemble des contenus pris en compte */ -typedef union _jdwp_payload -{ - jdwp_cmd_vm_version_reply vs_reply; /* Infos. sur la version */ - jdwp_cmd_vm_allthreads_reply th_reply; /* Liste des threads */ - jdwp_cmd_vm_id_sizes_reply sz_reply; /* Tailles dynamiques */ - - jdwp_cmd_thread_name_request th_ident; /* Identification d'un thread */ - jdwp_cmd_thread_name_reply th_name; /* Désignation d'un thread */ - jdwp_cmd_thread_frames_request __nu0; /* Inutilisé */ - jdwp_cmd_thread_frames_reply th_frames; /* Pile des frames courantes */ - - bin_t padding[500]; - -} jdwp_payload; - - -/* Reconstitue un contenu binaire à partir d'une charge utile. */ -bool set_jdwp_payload(const jdwp_payload *, uint8_t, uint8_t, const jdwp_cmd_vm_id_sizes_reply *, bin_t *, off_t *); - -/* Reconstitue une charge utile à partir d'un contenu binaire. */ -bool get_jdwp_payload(const bin_t *, off_t, uint8_t, uint8_t, const jdwp_cmd_vm_id_sizes_reply *, jdwp_payload *); - -/* Libère le contenu d'une charge utile. */ -void free_jdwp_payload(jdwp_payload *, bool, uint8_t, uint8_t); - - - -#endif /* _DEBUG_JDWP_SETS_LIST_H */ diff --git a/src/debug/jdwp/sets/thread.c b/src/debug/jdwp/sets/thread.c deleted file mode 100644 index bac30ec..0000000 --- a/src/debug/jdwp/sets/thread.c +++ /dev/null @@ -1,222 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * thread.c - interactions avec les différents threads - * - * Copyright (C) 2012-2017 Cyrille Bagard - * - * This file is part of Chrysalide. - * - * Chrysalide 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. - * - * Chrysalide 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 Chrysalide. If not, see . - */ - - -#include "thread.h" - - -#include -#include - - -#include "../misc/id.h" -#include "../misc/location.h" -#include "../misc/types.h" -#include "../../../common/endianness.h" - - - -/****************************************************************************** -* * -* Paramètres : req = structure de réponse à constituer. * -* sizes = références pour la valeur des tailles dynamiques. * -* blob = ensemble de données binaires brutes. [OUT] * -* len = quantité de données disponibles, puis écrites. [OUT] * -* * -* Description : Prépare une requête demandant le nom d'un thread. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool set_jdwp_thread_name(const jdwp_cmd_thread_name_request *req, const jdwp_cmd_vm_id_sizes_reply *sizes, bin_t *blob, off_t *len) -{ - bool result; /* Bilan à retourner */ - off_t pos; /* Tête de lecture */ - - pos = 0; - memset(blob, 0, sizeof(jdwp_cmd_thread_name_request)); - - result = set_jdwp_thread_id(&req->id, sizes, blob, &pos, *len); - if (!result) return false; - - *len = pos; - - return true; - -} - - -/****************************************************************************** -* * -* Paramètres : blob = ensemble de données binaires brutes. * -* len = quantité de données valides. * -* sizes = références pour la valeur des tailles dynamiques. * -* reply = structure de réponse à constituer. [OUT] * -* * -* Description : Reconstitue une réponse fournissant le nom d'un thread. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool get_jdwp_thread_name(const bin_t *blob, off_t len, const jdwp_cmd_vm_id_sizes_reply *sizes, jdwp_cmd_thread_name_reply *reply) -{ - bool result; /* Bilan à retourner */ - off_t pos; /* Tête de lecture */ - - pos = 0; - memset(reply, 0, sizeof(jdwp_cmd_thread_name_reply)); - - result = get_jdwp_string(blob, &pos, len, &reply->name); - if (!result) return false; - - return true; - -} - - -/****************************************************************************** -* * -* Paramètres : reply = structure de réponse à supprimer de la mémoire. * -* * -* Description : Libère le nom donné à un thread. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void free_jdwp_thread_name_reply(jdwp_cmd_thread_name_reply *reply) -{ - free_jdwp_string(&reply->name); - -} - - -/****************************************************************************** -* * -* Paramètres : req = structure de réponse à constituer. * -* sizes = références pour la valeur des tailles dynamiques. * -* blob = ensemble de données binaires brutes. [OUT] * -* len = quantité de données disponibles, puis écrites. [OUT] * -* * -* Description : Prépare une requête demandant les frames d'un thread. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool set_jdwp_thread_frames(const jdwp_cmd_thread_frames_request *req, const jdwp_cmd_vm_id_sizes_reply *sizes, bin_t *blob, off_t *len) -{ - bool result; /* Bilan à retourner */ - off_t pos; /* Tête de lecture */ - - pos = 0; - memset(blob, 0, sizeof(jdwp_cmd_thread_frames_request)); - - result = set_jdwp_frame_id(&req->id, sizes, blob, &pos, *len); - if (!result) return false; - - result = write_u32(&req->start, blob, &pos, *len, SRE_BIG); - if (!result) return false; - - result = write_u32(&req->length, blob, &pos, *len, SRE_BIG); - if (!result) return false; - - *len = pos; - - return true; - -} - - -/****************************************************************************** -* * -* Paramètres : blob = ensemble de données binaires brutes. * -* len = quantité de données valides. * -* sizes = références pour la valeur des tailles dynamiques. * -* reply = structure de réponse à constituer. [OUT] * -* * -* Description : Reconstitue une réponse fournissant les frames d'un thread. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool get_jdwp_thread_frames(const bin_t *blob, off_t len, const jdwp_cmd_vm_id_sizes_reply *sizes, jdwp_cmd_thread_frames_reply *reply) -{ - bool result; /* Bilan à retourner */ - off_t pos; /* Tête de lecture */ - uint32_t i; /* Boucle de parcours */ - - pos = 0; - memset(reply, 0, sizeof(jdwp_cmd_thread_frames_reply)); - - result = read_u32(&reply->count, blob, &pos, len, SRE_BIG); - if (!result) return false; - - reply->frames = (jdwp_thread_frame *)calloc(reply->count, sizeof(jdwp_thread_frame)); - - for (i = 0; i < reply->count && result; i++) - { - result = get_jdwp_frame_id(blob, &pos, len, sizes, &reply->frames[i].frame_id); - - result &= get_jdwp_location(blob, &pos, len, sizes, &reply->frames[i].location); - - } - - if (!result) - free_jdwp_thread_frames_reply(reply); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : reply = structure de réponse à supprimer de la mémoire. * -* * -* Description : Libère une liste de frames d'un thread. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void free_jdwp_thread_frames_reply(jdwp_cmd_thread_frames_reply *reply) -{ - if (reply->frames != NULL) - free(reply->frames); - -} diff --git a/src/debug/jdwp/sets/thread.h b/src/debug/jdwp/sets/thread.h deleted file mode 100644 index b0df015..0000000 --- a/src/debug/jdwp/sets/thread.h +++ /dev/null @@ -1,55 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * thread.h - prototypes pour les interactions avec les différents threads - * - * Copyright (C) 2012-2017 Cyrille Bagard - * - * This file is part of Chrysalide. - * - * Chrysalide 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. - * - * Chrysalide 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 Chrysalide. If not, see . - */ - - -#ifndef _DEBUG_JDWP_SETS_THREAD_H -#define _DEBUG_JDWP_SETS_THREAD_H - - -#include - - -#include "../jdwp_def.h" -#include "../../../arch/archbase.h" - - -/* Prépare une requête demandant le nom d'un thread. */ -bool set_jdwp_thread_name(const jdwp_cmd_thread_name_request *, const jdwp_cmd_vm_id_sizes_reply *, bin_t *, off_t *); - -/* Reconstitue une réponse fournissant le nom d'un thread. */ -bool get_jdwp_thread_name(const bin_t *, off_t, const jdwp_cmd_vm_id_sizes_reply *, jdwp_cmd_thread_name_reply *); - -/* Libère le nom donné à un thread. */ -void free_jdwp_thread_name_reply(jdwp_cmd_thread_name_reply *); - -/* Prépare une requête demandant les frames d'un thread. */ -bool set_jdwp_thread_frames(const jdwp_cmd_thread_frames_request *, const jdwp_cmd_vm_id_sizes_reply *, bin_t *, off_t *); - -/* Reconstitue une réponse fournissant les frames d'un thread. */ -bool get_jdwp_thread_frames(const bin_t *, off_t, const jdwp_cmd_vm_id_sizes_reply *, jdwp_cmd_thread_frames_reply *); - -/* Libère une liste de frames d'un thread. */ -void free_jdwp_thread_frames_reply(jdwp_cmd_thread_frames_reply *); - - - -#endif /* _DEBUG_JDWP_SETS_THREAD_H */ diff --git a/src/debug/jdwp/sets/vm.c b/src/debug/jdwp/sets/vm.c deleted file mode 100644 index 3ff28d6..0000000 --- a/src/debug/jdwp/sets/vm.c +++ /dev/null @@ -1,202 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * vm.c - constitution des charges utiles liées à la VM - * - * Copyright (C) 2010-2017 Cyrille Bagard - * - * This file is part of Chrysalide. - * - * Chrysalide 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. - * - * Chrysalide 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 Chrysalide. If not, see . - */ - - -#include "vm.h" - - -#include -#include - - -#include "../misc/id.h" -#include "../misc/types.h" -#include "../../../common/endianness.h" - - - -/****************************************************************************** -* * -* Paramètres : blob = ensemble de données binaires brutes. * -* len = quantité de données valides. * -* sizes = références pour la valeur des tailles dynamiques. * -* reply = structure de réponse à constituer. [OUT] * -* * -* Description : Reconstitue une réponse quant à une version de serveur. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool get_jdwp_vm_version(const bin_t *blob, off_t len, const jdwp_cmd_vm_id_sizes_reply *sizes, jdwp_cmd_vm_version_reply *reply) -{ - bool result; /* Bilan à retourner */ - off_t pos; /* Tête de lecture */ - - pos = 0; - memset(reply, 0, sizeof(jdwp_cmd_vm_version_reply)); - - result = get_jdwp_string(blob, &pos, len, &reply->description); - if (!result) return false; - - result = read_u32(&reply->jdwp_major, blob, &pos, len, SRE_BIG); - if (!result) return false; - - result = read_u32(&reply->jdwp_minor, blob, &pos, len, SRE_BIG); - if (!result) return false; - - result = get_jdwp_string(blob, &pos, len, &reply->vm_version); - if (!result) return false; - - result = get_jdwp_string(blob, &pos, len, &reply->vm_name); - if (!result) return false; - - return true; - -} - - -/****************************************************************************** -* * -* Paramètres : reply = structure de réponse à supprimer de la mémoire. * -* * -* Description : Libère le contenu d'une réponse quant à une version. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void free_jdwp_vm_version(jdwp_cmd_vm_version_reply *reply) -{ - free_jdwp_string(&reply->description); - - free_jdwp_string(&reply->vm_version); - - free_jdwp_string(&reply->vm_name); - -} - - -/****************************************************************************** -* * -* Paramètres : blob = ensemble de données binaires brutes. * -* len = quantité de données valides. * -* sizes = références pour la valeur des tailles dynamiques. * -* reply = structure de réponse à constituer. [OUT] * -* * -* Description : Reconstitue une réponse fournissant la liste des threads. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool get_jdwp_vm_all_threads(const bin_t *blob, off_t len, const jdwp_cmd_vm_id_sizes_reply *sizes, jdwp_cmd_vm_allthreads_reply *reply) -{ - bool result; /* Bilan à retourner */ - off_t pos; /* Tête de lecture */ - uint32_t i; /* Boucle de parcours */ - - pos = 0; - memset(reply, 0, sizeof(jdwp_cmd_vm_id_sizes_reply)); - - result = read_u32(&reply->count, blob, &pos, len, SRE_BIG); - if (!result) return false; - - reply->threads = (jdwp_dynsized_id *)calloc(reply->count, sizeof(jdwp_dynsized_id)); - - for (i = 0; i < reply->count && result; i++) - result = get_jdwp_thread_id(blob, &pos, len, sizes, &reply->threads[i]); - - if (!result) - free_jdwp_all_threads(reply); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : reply = structure de réponse à supprimer de la mémoire. * -* * -* Description : Libère le contenu d'une réponse offrant une liste de threads.* -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void free_jdwp_all_threads(jdwp_cmd_vm_allthreads_reply *reply) -{ - free(reply->threads); - -} - - -/****************************************************************************** -* * -* Paramètres : blob = ensemble de données binaires brutes. * -* len = quantité de données valides. * -* sizes = références pour la valeur des tailles dynamiques. * -* reply = structure de réponse à constituer. [OUT] * -* * -* Description : Reconstitue une réponse quant aux tailles spécifiques. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool get_jdwp_vm_id_sizes(const bin_t *blob, off_t len, const jdwp_cmd_vm_id_sizes_reply *sizes, jdwp_cmd_vm_id_sizes_reply *reply) -{ - bool result; /* Bilan à retourner */ - off_t pos; /* Tête de lecture */ - - pos = 0; - memset(reply, 0, sizeof(jdwp_cmd_vm_id_sizes_reply)); - - result = read_u32(&reply->field_id_size, blob, &pos, len, SRE_BIG); - if (!result) return false; - - result = read_u32(&reply->method_id_size, blob, &pos, len, SRE_BIG); - if (!result) return false; - - result = read_u32(&reply->object_id_size, blob, &pos, len, SRE_BIG); - if (!result) return false; - - result = read_u32(&reply->reference_type_id_size, blob, &pos, len, SRE_BIG); - if (!result) return false; - - result = read_u32(&reply->frame_id_size, blob, &pos, len, SRE_BIG); - if (!result) return false; - - return true; - -} diff --git a/src/debug/jdwp/sets/vm.h b/src/debug/jdwp/sets/vm.h deleted file mode 100644 index a63adc7..0000000 --- a/src/debug/jdwp/sets/vm.h +++ /dev/null @@ -1,53 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * vm.h - prototypes pour la constitution des charges utiles liées à la VM - * - * Copyright (C) 2010-2017 Cyrille Bagard - * - * This file is part of Chrysalide. - * - * Chrysalide 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. - * - * Chrysalide 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 Chrysalide. If not, see . - */ - - -#ifndef _DEBUG_JDWP_SETS_VM_H -#define _DEBUG_JDWP_SETS_VM_H - - -#include - - -#include "../jdwp_def.h" -#include "../../../arch/archbase.h" - - - -/* Reconstitue une réponse quant à une version de serveur. */ -bool get_jdwp_vm_version(const bin_t *, off_t, const jdwp_cmd_vm_id_sizes_reply *, jdwp_cmd_vm_version_reply *); - -/* Libère le contenu d'une réponse quant à une version. */ -void free_jdwp_vm_version(jdwp_cmd_vm_version_reply *); - -/* Reconstitue une réponse fournissant la liste des threads. */ -bool get_jdwp_vm_all_threads(const bin_t *, off_t, const jdwp_cmd_vm_id_sizes_reply *, jdwp_cmd_vm_allthreads_reply *); - -/* Libère le contenu d'une réponse offrant une liste de threads. */ -void free_jdwp_all_threads(jdwp_cmd_vm_allthreads_reply *); - -/* Reconstitue une réponse quant aux tailles spécifiques. */ -bool get_jdwp_vm_id_sizes(const bin_t *, off_t, const jdwp_cmd_vm_id_sizes_reply *, jdwp_cmd_vm_id_sizes_reply *); - - - -#endif /* _DEBUG_JDWP_SETS_VM_H */ diff --git a/src/debug/jdwp/tcp.c b/src/debug/jdwp/tcp.c deleted file mode 100644 index 3cd8771..0000000 --- a/src/debug/jdwp/tcp.c +++ /dev/null @@ -1,368 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * tcp.c - gestion des connexions TCP aux serveurs JDWP. - * - * Copyright (C) 2010-2017 Cyrille Bagard - * - * This file is part of Chrysalide. - * - * Chrysalide 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. - * - * Chrysalide 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 Chrysalide. If not, see . - */ - - -#include "tcp.h" - - -#include -#include -#include -#include -#include -#include - - -#include - - -#include "packet.h" -#include "misc/header.h" -#include "sets/list.h" -#include "../stream-int.h" -#include "../../common/net.h" -#include "../../core/logs.h" - - - -/* Flux de communication TCP avec un serveur JDWP (instance) */ -struct _GJdwpTcpClient -{ - GDebugStream parent; /* A laisser en premier */ - - char *server; /* Serveur à contacter */ - char *port; /* Port de connexion */ - int fd; /* Flux ouvert en L./E. */ - -}; - - -/* Flux de communication TCP avec un serveur JDWP (classe) */ -struct _GJdwpTcpClientClass -{ - GDebugStreamClass parent; /* A laisser en premier */ - -}; - - -/* Initialise la classe des flux de communication JDWP over TCP. */ -static void g_jdwp_tcp_client_class_init(GJdwpTcpClientClass *); - -/* Initialise une instance de flux de communication avec JDWP. */ -static void g_jdwp_tcp_client_init(GJdwpTcpClient *); - -/* Etablit de façon effective une connexion à la cible. */ -static bool g_jdwp_tcp_client_connect(GJdwpTcpClient *); - -/* Attend le signalement de données à traiter. */ -static bool g_jdwp_tcp_client_poll(GJdwpTcpClient *); - -/* Envoie un paquet de données à un serveur de débogage. */ -static bool g_jdwp_tcp_client_send_packet(GJdwpTcpClient *, const GJdwpPacket *); - -/* Réceptionne un paquet de données d'un serveur de débogage. */ -static bool g_jdwp_tcp_client_recv_packet(GJdwpTcpClient *, GJdwpPacket *); - -/* Libère le contenu alloué d'un paquet de débogage. */ -static void g_jdwp_tcp_client_free_packet(GJdwpTcpClient *, GJdwpPacket *); - - - -/* Indique le type défini pour un flux de communication TCP avec un serveur JDWP. */ -G_DEFINE_TYPE(GJdwpTcpClient, g_jdwp_tcp_client, G_TYPE_DEBUG_STREAM); - - -/****************************************************************************** -* * -* Paramètres : klass = classe à initialiser. * -* * -* Description : Initialise la classe des flux de communication JVDP over TCP.* -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_jdwp_tcp_client_class_init(GJdwpTcpClientClass *klass) -{ - -} - - -/****************************************************************************** -* * -* Paramètres : client = instance à initialiser. * -* * -* Description : Initialise une instance de flux de communication avec JDWP. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_jdwp_tcp_client_init(GJdwpTcpClient *client) -{ - GDebugStream *stream; /* Version parente */ - - stream = G_DEBUG_STREAM(client); - - stream->connect = (debug_connect_fc)g_jdwp_tcp_client_connect; - - stream->poll = (debug_poll_fc)g_jdwp_tcp_client_poll; - stream->send_packet = (debug_pkt_op_fc)g_jdwp_tcp_client_send_packet; - stream->recv_packet = (debug_pkt_op_fc)g_jdwp_tcp_client_recv_packet; - stream->free_packet = (debug_free_pkt_fc)g_jdwp_tcp_client_free_packet; - - stream->pkt_type = G_TYPE_JDWP_PACKET; - -} - - -/****************************************************************************** -* * -* Paramètres : server = nom ou adresse du serveur à contacter. * -* port = port de connexion. * -* * -* Description : Crée une nouvelle connexion TCP à un serveur JDWP. * -* * -* Retour : Adresse de la structure mise en place. * -* * -* Remarques : - * -* * -******************************************************************************/ - -GDebugStream *g_jdwp_tcp_client_new(const char *server, const char *port) -{ - GJdwpTcpClient *result; /* Structure à retourner */ - - result = g_object_new(G_TYPE_JDWP_TCP_CLIENT, NULL); - - result->server = strdup(server); - result->port = strdup(port); - result->fd = -1; - - return G_DEBUG_STREAM(result); - -} - - -/****************************************************************************** -* * -* Paramètres : client = paramètres de connexion au serveur JDWP. * -* * -* Description : Etablit de façon effective une connexion à la cible. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool g_jdwp_tcp_client_connect(GJdwpTcpClient *client) -{ - struct sockaddr_in addr; /* Infos de connexion distante */ - int sock; /* Flux ouvert à construire */ - char handshake[15]; /* Poignée de main chaleureuse */ - - sock = connect_via_tcp(client->server, client->port, &addr); - if (sock == -1) - { - log_variadic_message(LMT_ERROR, _("Error while connecting to the JDWP server at %s:%s."), - //printf("Echec de connexion au serveur JDWP sur %s:%s\n", - client->server, client->port); - return false; - } - - log_variadic_message(LMT_PROCESS, _("Connected to %s:%hd."), - client->server, ntohs(addr.sin_port)); - - if (send(sock, "JDWP-Handshake", 14, 0) != 14) - goto gjtcc_error; - - if (recv(sock, handshake, 14, 0) != 14) - goto gjtcc_error; - - if (strncmp(handshake, "JDWP-Handshake", 14) != 0) - goto gjtcc_error; - - client->fd = sock; - - return true; - - gjtcc_error: - - log_simple_message(LMT_ERROR, _("Failure in the first JDWP handshake.")); - - close(sock); - - return false; - -} - - -/****************************************************************************** -* * -* Paramètres : client = paramètres de connexion au serveur JDWP. * -* * -* Description : Attend le signalement de données à traiter. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool g_jdwp_tcp_client_poll(GJdwpTcpClient *client) -{ - bool result; /* Statut à faire remonter */ - fd_set rfds; /* Liste des flux à surveiller */ - int ret; /* Bilan d'un appel */ - - result = false; - - FD_ZERO(&rfds); - FD_SET(client->fd, &rfds); - - ret = select(client->fd + 1, &rfds, NULL, NULL, NULL); - - switch (ret) - { - case -1: - perror("select()"); - break; - - case 0: - /* ?! */ - break; - - default: - result = true; - break; - - } - - return true; - -} - - -/****************************************************************************** -* * -* Paramètres : client = flux ouvert en écriture à utiliser. * -* packet = zone mémoire à parcourir. * -* * -* Description : Envoie un paquet de données à un serveur de débogage. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool g_jdwp_tcp_client_send_packet(GJdwpTcpClient *client, const GJdwpPacket *packet) -{ - struct iovec iov[UIO_MAXIOV]; /* Table de vecteurs à écrire */ - int iovcnt; /* Quantité de champs valides */ - int i; /* Boucle de parcours */ - -#if 0 - jdwp_header *header; /* En-tête à reconstituer */ - - header = g_jdwp_packet_get_header(packet); - printf(" send %p :: %u / %hhu.%hhu (%u)\n", packet, header->id, header->set, - header->command, header->length); -#endif - - g_debug_packet_vectorize(G_DEBUG_PACKET(packet), iov, &iovcnt); - - for (i = 0; i < iovcnt; i++) - if (send(client->fd, iov[i].iov_base, iov[i].iov_len, 0) != iov[i].iov_len) - return false; - - return true; - -} - - -/****************************************************************************** -* * -* Paramètres : client = flux ouvert en lecture à utiliser. * -* packet = zone mémoire à remplir. [OUT] * -* * -* Description : Réceptionne un paquet de données d'un serveur de débogage. * -* * -* Retour : Bilan de l'opération. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static bool g_jdwp_tcp_client_recv_packet(GJdwpTcpClient *client, GJdwpPacket *packet) -{ - bin_t *hblob; /* Contenu encodé en B.E. */ - jdwp_header *header; /* En-tête à reconstituer */ - uint32_t length; /* Taille de la charge utile */ - bin_t *pblob; /* Contenu encodé en B.E. */ - - hblob = g_jdwp_packet_get_hblob(packet); - - if (recv(client->fd, hblob, sizeof(jdwp_header), 0) != sizeof(jdwp_header)) - return false; - - if (!g_jdwp_packet_parse_header(packet)) - return false; - - header = g_jdwp_packet_get_header(packet); - length = header->length - sizeof(jdwp_header); - - //printf(" recv %p :: %u / %hu (%u)\n", packet, header->id, header->error, header->length); - - pblob = g_jdwp_packet_get_pblob(packet); - - if (recv(client->fd, pblob, length, 0) != length) - return false; - - return true; - -} - - -/****************************************************************************** -* * -* Paramètres : client = flux ouvert inutile. * -* packet = zone mémoire à libérer. * -* * -* Description : Libère le contenu alloué d'un paquet de débogage. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -static void g_jdwp_tcp_client_free_packet(GJdwpTcpClient *client, GJdwpPacket *packet) -{ - g_jdwp_packet_free_payload(packet); - -} diff --git a/src/debug/jdwp/tcp.h b/src/debug/jdwp/tcp.h deleted file mode 100644 index aa69953..0000000 --- a/src/debug/jdwp/tcp.h +++ /dev/null @@ -1,56 +0,0 @@ - -/* Chrysalide - Outil d'analyse de fichiers binaires - * tcp.h - prototypes pour la gestion des connexions TCP aux serveurs JDWP. - * - * Copyright (C) 2010-2017 Cyrille Bagard - * - * This file is part of Chrysalide. - * - * Chrysalide 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. - * - * Chrysalide 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 Chrysalide. If not, see . - */ - - -#ifndef _DEBUG_JDWP_TCP_H -#define _DEBUG_JDWP_TCP_H - - -#include "../stream.h" - - - -#define G_TYPE_JDWP_TCP_CLIENT g_jdwp_tcp_client_get_type() -#define G_JDWP_TCP_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), g_jdwp_tcp_client_get_type(), GJdwpTcpClient)) -#define G_IS_JDWP_TCP_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_jdwp_tcp_client_get_type())) -#define G_JDWP_TCP_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_JDWP_TCP_CLIENT, GJdwpTcpClientClass)) -#define G_IS_JDWP_TCP_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_JDWP_TCP_CLIENT)) -#define G_JDWP_TCP_CLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_JDWP_TCP_CLIENT, GJdwpTcpClientClass)) - - -/* Flux de communication TCP avec un serveur JDWP (instance) */ -typedef struct _GJdwpTcpClient GJdwpTcpClient; - -/* Flux de communication TCP avec un serveur JDWP (classe) */ -typedef struct _GJdwpTcpClientClass GJdwpTcpClientClass; - - - -/* Indique le type défini pour un flux de communication TCP avec un serveur JDWP. */ -GType g_jdwp_tcp_client_get_type(void); - -/* Crée une nouvelle connexion TCP à un serveur JDWP. */ -GDebugStream *g_jdwp_tcp_client_new(const char *, const char *); - - - -#endif /* _DEBUG_JDWP_TCP_H */ -- cgit v0.11.2-87-g4458