/* OpenIDA - Outil d'analyse de fichiers binaires
 * jdwp_def.h - transcription du protocole Java Debug Wire Protocol
 *
 * Copyright (C) 2010 Cyrille Bagard
 *
 *  This file is part of OpenIDA.
 *
 *  OpenIDA is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  OpenIDA is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
 */


#ifndef _DEBUG_JDWP_JDWP_DEF_H
#define _DEBUG_JDWP_JDWP_DEF_H


#include <stdint.h>



/**
 * 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



/* ---------------------------------------------------------------------------------- */
/*                           TYPES DE BASE DIVERS POUR JDWP                           */
/* ---------------------------------------------------------------------------------- */




/* "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_VIRTUAL_MACHINE    1


/**
 * Sous-commandes d'un jeu.
 */

/* VirtualMachine Command Set */

#define JDWP_CMD_VM_VERSION         1


/**
 * 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;






#endif  /* _DEBUG_JDWP_JDWP_DEF_H */