summaryrefslogtreecommitdiff
path: root/src/format/java/pool.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2009-05-11 23:42:48 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2009-05-11 23:42:48 (GMT)
commit96cb6971ee3ca529958b8cb1e8e55a6eb4e60eae (patch)
tree68e49f325de3e93ef186d3e078da8ddc473aedf7 /src/format/java/pool.c
parent80dc0ac97987ad9246bee7c47458a015339453bf (diff)
Reorganized the way the program is built again and added partial support for the JVM.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@63 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/format/java/pool.c')
-rwxr-xr-xsrc/format/java/pool.c140
1 files changed, 129 insertions, 11 deletions
diff --git a/src/format/java/pool.c b/src/format/java/pool.c
index f735819..eec2918 100755
--- a/src/format/java/pool.c
+++ b/src/format/java/pool.c
@@ -30,12 +30,16 @@
#include "java-int.h"
#include "../../common/endianness.h"
+#include "../../common/extstr.h"
/* Charge les propriétés d'une constante du réservoir. */
bool load_java_pool_entry(java_format *, constant_pool_entry *, off_t *);
+/* Fournit une entrée donnée du réservoir de constantes. */
+const constant_pool_entry *get_java_pool_entry(const java_format *, uint16_t, ConstantPoolTag);
+
/******************************************************************************
@@ -319,36 +323,150 @@ bool load_java_pool_entry(java_format *format, constant_pool_entry *entry, off_t
/******************************************************************************
* *
-* Paramètres : format = description de l'exécutable à compléter. *
+* Paramètres : format = description de l'exécutable à consulter. *
* index = indice de l'élément dont la valeur est à recupérer. *
-* str = adresse où placer la chaîne de caractères trouvée. *
+* expected = type de l'élément à trouver à l'indice donné. *
* *
-* Description : Recherche une chaîne de caractères dans le réservoir. *
+* Description : Fournit une entrée donnée du réservoir de constantes. *
* *
-* Retour : true si l'opération s'est bien déroulée, false sinon. *
+* Retour : Entrée du réservoir de constantes ou NULL en cas d'erreur. *
* *
* Remarques : - *
* *
******************************************************************************/
-bool get_java_pool_ut8_string(java_format *format, uint16_t index, const char **str)
+const constant_pool_entry *get_java_pool_entry(const java_format *format, uint16_t index, ConstantPoolTag expected)
{
- bool result; /* Bilan à renvoyer */
+ const constant_pool_entry *result; /* Entrée à retourner */
constant_pool_entry *entry; /* Entrée du réservoir visée */
- result = (index <= format->pool_len);
+ result = NULL;
- if (result)
+ if (/*index < 0 && FIXME */index <= format->pool_len);
{
entry = &format->pool[index - 1];
- result = (entry->tag == CONSTANT_UTF8);
+ if (entry->tag == expected)
+ result = entry;
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = description de l'exécutable à consulter. *
+* index = indice de l'élément de la table à recupérer. *
+* expected = type de l'élément à trouver à l'indice donné. *
+* *
+* Description : Construit une version humaine de référence. *
+* *
+* Retour : Référence construite ou NULL en cas de problème. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+char *build_reference_from_java_pool(const java_format *format, uint16_t index, JavaRefType expected)
+{
+ char *result; /* Chaîne humaine à retourner */
+ const constant_pool_entry *entry; /* Entrée du réservoir visée 1 */
+ const constant_pool_entry *subentry; /* Entrée du réservoir visée 2 */
+ const char *tmp; /* Copie de chaîne intouchable */
- if (result)
- (*str) = entry->info.utf8.bytes;
+ result = NULL;
+ switch (expected)
+ {
+ case JRT_FIELD:
+ entry = get_java_pool_entry(format, index, CONSTANT_FIELD_REF);
+ break;
+ case JRT_METHOD:
+ entry = get_java_pool_entry(format, index, CONSTANT_METHOD_REF);
+ break;
+ case JRT_INTERFACE_METHOD:
+ entry = get_java_pool_entry(format, index, CONSTANT_INTERFACE_METHOD_REF);
+ break;
+ default:
+ entry = NULL;
+ break;
}
+ if (entry == NULL)
+ goto brfjp_error;
+
+ /* Lieu parent où trouver la référence */
+
+ subentry = get_java_pool_entry(format, entry->info.ref.class_index, CONSTANT_CLASS);
+
+ if (subentry == NULL)
+ goto brfjp_error;
+
+ if (!get_java_pool_ut8_string(format, subentry->info.class.name_index, &tmp))
+ goto brfjp_error;
+
+ result = strdup(tmp);
+
+ /* Champ proprement dit */
+
+ subentry = get_java_pool_entry(format, entry->info.ref.name_and_type_index, CONSTANT_NAME_AND_TYPE);
+
+ if (subentry == NULL)
+ goto brfjp_error;
+
+ if (!get_java_pool_ut8_string(format, subentry->info.name_type.name_index, &tmp))
+ goto brfjp_error;
+
+ result = stradd(result, ".");
+ result = stradd(result, tmp);
+
+ /* Petites retouches finales */
+
+ result = strrpl(result, "/", ".");
+ result = strrpl(result, "<", "&lt;");
+ result = strrpl(result, ">", "&gt;");
+
+ return result;
+
+ brfjp_error:
+
+ if (result != NULL)
+ free(result);
+
+ return NULL;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : format = description de l'exécutable à consulter. *
+* index = indice de l'élément dont la valeur est à recupérer. *
+* str = adresse où placer la chaîne de caractères trouvée. *
+* *
+* Description : Recherche une chaîne de caractères dans le réservoir. *
+* *
+* Retour : true si l'opération s'est bien déroulée, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool get_java_pool_ut8_string(const java_format *format, uint16_t index, const char **str)
+{
+ bool result; /* Bilan à renvoyer */
+ const constant_pool_entry *entry; /* Entrée du réservoir visée */
+
+ entry = get_java_pool_entry(format, index, CONSTANT_UTF8);
+
+ result = (entry != NULL);
+
+ if (result)
+ (*str) = entry->info.utf8.bytes;
+
return result;
}