diff options
Diffstat (limited to 'src/debug/jdwp/sets')
-rw-r--r-- | src/debug/jdwp/sets/Makefile.am | 1 | ||||
-rw-r--r-- | src/debug/jdwp/sets/list.c | 86 | ||||
-rw-r--r-- | src/debug/jdwp/sets/list.h | 14 | ||||
-rw-r--r-- | src/debug/jdwp/sets/thread.c | 116 | ||||
-rw-r--r-- | src/debug/jdwp/sets/thread.h | 46 | ||||
-rw-r--r-- | src/debug/jdwp/sets/vm.c | 109 | ||||
-rw-r--r-- | src/debug/jdwp/sets/vm.h | 13 |
7 files changed, 368 insertions, 17 deletions
diff --git a/src/debug/jdwp/sets/Makefile.am b/src/debug/jdwp/sets/Makefile.am index 98a76b4..55277bf 100644 --- a/src/debug/jdwp/sets/Makefile.am +++ b/src/debug/jdwp/sets/Makefile.am @@ -3,6 +3,7 @@ noinst_LTLIBRARIES = libdebugjdwpsets.la libdebugjdwpsets_la_SOURCES = \ list.h list.c \ + thread.h thread.c \ vm.h vm.c libdebugjdwpsets_la_LDFLAGS = diff --git a/src/debug/jdwp/sets/list.c b/src/debug/jdwp/sets/list.c index 0dad1e8..84c6ac0 100644 --- a/src/debug/jdwp/sets/list.c +++ b/src/debug/jdwp/sets/list.c @@ -2,7 +2,7 @@ /* OpenIDA - Outil d'analyse de fichiers binaires * list.c - ensemble des jeux de commandes de JDWP * - * Copyright (C) 2010 Cyrille Bagard + * Copyright (C) 2010-2012 Cyrille Bagard * * This file is part of OpenIDA. * @@ -27,12 +27,15 @@ #include <stddef.h> +#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, jdwp_payload *); +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 *); @@ -41,8 +44,10 @@ 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_payload; /* Libération de la mémoire */ + free_jdwp_payload_fc free_got_payload; /* Libération de la mémoire */ } jdwp_command; @@ -53,16 +58,38 @@ 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_payload = (free_jdwp_payload_fc)free_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 + } + } }; @@ -70,10 +97,40 @@ static jdwp_command _commands[][256] = { /****************************************************************************** * * +* 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. * @@ -84,12 +141,12 @@ static jdwp_command _commands[][256] = { * * ******************************************************************************/ -bool get_jdwp_payload(const bin_t *blob, off_t len, uint8_t set, uint8_t cmd, jdwp_payload *payload) +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, payload); + else result = _commands[set][cmd].get_payload(blob, len, sizes, payload); return result; @@ -99,6 +156,7 @@ bool get_jdwp_payload(const bin_t *blob, off_t len, uint8_t set, uint8_t cmd, jd /****************************************************************************** * * * 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. * * * @@ -110,9 +168,17 @@ bool get_jdwp_payload(const bin_t *blob, off_t len, uint8_t set, uint8_t cmd, jd * * ******************************************************************************/ -void free_jdwp_payload(jdwp_payload *payload, uint8_t set, uint8_t cmd) +void free_jdwp_payload(jdwp_payload *payload, bool got, uint8_t set, uint8_t cmd) { - if (_commands[set][cmd].free_payload != NULL) - _commands[set][cmd].free_payload(payload); + 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 index 2fb135e..9880e69 100644 --- a/src/debug/jdwp/sets/list.h +++ b/src/debug/jdwp/sets/list.h @@ -2,7 +2,7 @@ /* OpenIDA - Outil d'analyse de fichiers binaires * list.h - prototypes pour l'ensemble des jeux de commandes de JDWP * - * Copyright (C) 2010 Cyrille Bagard + * Copyright (C) 2010-2012 Cyrille Bagard * * This file is part of OpenIDA. * @@ -37,17 +37,25 @@ 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 */ 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, jdwp_payload *); +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 *, uint8_t, uint8_t); +void free_jdwp_payload(jdwp_payload *, bool, uint8_t, uint8_t); diff --git a/src/debug/jdwp/sets/thread.c b/src/debug/jdwp/sets/thread.c new file mode 100644 index 0000000..9391ff6 --- /dev/null +++ b/src/debug/jdwp/sets/thread.c @@ -0,0 +1,116 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * thread.c - interactions avec les différents threads + * + * Copyright (C) 2012 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * OpenIDA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Foobar. If not, see <http://www.gnu.org/licenses/>. + */ + + +#include "thread.h" + + +#include <string.h> + + +#include "../misc/id.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_vm_version_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); + +} diff --git a/src/debug/jdwp/sets/thread.h b/src/debug/jdwp/sets/thread.h new file mode 100644 index 0000000..f8c3abe --- /dev/null +++ b/src/debug/jdwp/sets/thread.h @@ -0,0 +1,46 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * thread.h - prototypes pour les interactions avec les différents threads + * + * Copyright (C) 2012 Cyrille Bagard + * + * This file is part of OpenIDA. + * + * OpenIDA is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * OpenIDA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Foobar. If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _DEBUG_JDWP_SETS_THREAD_H +#define _DEBUG_JDWP_SETS_THREAD_H + + +#include <stdbool.h> + + +#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 *); + + + +#endif /* _DEBUG_JDWP_SETS_THREAD_H */ diff --git a/src/debug/jdwp/sets/vm.c b/src/debug/jdwp/sets/vm.c index fdb1ec0..d8e3255 100644 --- a/src/debug/jdwp/sets/vm.c +++ b/src/debug/jdwp/sets/vm.c @@ -2,7 +2,7 @@ /* OpenIDA - Outil d'analyse de fichiers binaires * vm.c - constitution des charges utiles liées à la VM * - * Copyright (C) 2010 Cyrille Bagard + * Copyright (C) 2010-2012 Cyrille Bagard * * This file is part of OpenIDA. * @@ -24,9 +24,11 @@ #include "vm.h" +#include <malloc.h> #include <string.h> +#include "../misc/id.h" #include "../misc/types.h" #include "../../../common/endianness.h" @@ -36,6 +38,7 @@ * * * 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. * @@ -46,7 +49,7 @@ * * ******************************************************************************/ -bool get_jdwp_vm_version(const bin_t *blob, off_t len, jdwp_cmd_vm_version_reply *reply) +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 */ @@ -95,3 +98,105 @@ void free_jdwp_vm_version(jdwp_cmd_vm_version_reply *reply) 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 index de2c7db..996001f 100644 --- a/src/debug/jdwp/sets/vm.h +++ b/src/debug/jdwp/sets/vm.h @@ -2,7 +2,7 @@ /* OpenIDA - Outil d'analyse de fichiers binaires * vm.h - prototypes pour la constitution des charges utiles liées à la VM * - * Copyright (C) 2010 Cyrille Bagard + * Copyright (C) 2010-2012 Cyrille Bagard * * This file is part of OpenIDA. * @@ -34,11 +34,20 @@ /* Reconstitue une réponse quant à une version de serveur. */ -bool get_jdwp_vm_version(const bin_t *, off_t, jdwp_cmd_vm_version_reply *); +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 */ |