diff options
Diffstat (limited to 'src/debug/jdwp/misc')
-rw-r--r-- | src/debug/jdwp/misc/Makefile.am | 1 | ||||
-rw-r--r-- | src/debug/jdwp/misc/header.c | 26 | ||||
-rw-r--r-- | src/debug/jdwp/misc/header.h | 5 | ||||
-rw-r--r-- | src/debug/jdwp/misc/id.c | 148 | ||||
-rw-r--r-- | src/debug/jdwp/misc/id.h | 131 |
5 files changed, 309 insertions, 2 deletions
diff --git a/src/debug/jdwp/misc/Makefile.am b/src/debug/jdwp/misc/Makefile.am index cfb4a06..44c6224 100644 --- a/src/debug/jdwp/misc/Makefile.am +++ b/src/debug/jdwp/misc/Makefile.am @@ -3,6 +3,7 @@ noinst_LTLIBRARIES = libdebugjdwpmisc.la libdebugjdwpmisc_la_SOURCES = \ header.h header.c \ + id.h id.c \ types.h types.c libdebugjdwpmisc_la_LDFLAGS = diff --git a/src/debug/jdwp/misc/header.c b/src/debug/jdwp/misc/header.c index ad41c90..8e381a1 100644 --- a/src/debug/jdwp/misc/header.c +++ b/src/debug/jdwp/misc/header.c @@ -2,7 +2,7 @@ /* OpenIDA - Outil d'analyse de fichiers binaires * header.c - constitution des deux types d'en-têtes JDWP * - * Copyright (C) 2010 Cyrille Bagard + * Copyright (C) 2010-2012 Cyrille Bagard * * This file is part of OpenIDA. * @@ -121,6 +121,30 @@ void set_jdwp_reply_header(jdwp_header *header, bin_t *blob, uint32_t length, ui /****************************************************************************** * * +* 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] * * * diff --git a/src/debug/jdwp/misc/header.h b/src/debug/jdwp/misc/header.h index d8fa845..f76a852 100644 --- a/src/debug/jdwp/misc/header.h +++ b/src/debug/jdwp/misc/header.h @@ -2,7 +2,7 @@ /* OpenIDA - Outil d'analyse de fichiers binaires * header.h - prototypes pour la constitution des deux types d'en-têtes JDWP * - * Copyright (C) 2010 Cyrille Bagard + * Copyright (C) 2010-2012 Cyrille Bagard * * This file is part of OpenIDA. * @@ -39,6 +39,9 @@ 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 *); diff --git a/src/debug/jdwp/misc/id.c b/src/debug/jdwp/misc/id.c new file mode 100644 index 0000000..bf49ede --- /dev/null +++ b/src/debug/jdwp/misc/id.c @@ -0,0 +1,148 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * id.c - constitution des identifiants de taille dynamique + * + * 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 "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, SRE_BIG)) + 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 new file mode 100644 index 0000000..49a103b --- /dev/null +++ b/src/debug/jdwp/misc/id.h @@ -0,0 +1,131 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * id.h - prototypes pour la constitution des identifiants de taille dynamique + * + * 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_MISC_ID_H +#define _DEBUG_JDWP_MISC_ID_H + + +#include <stdbool.h> + + +#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 */ |