diff options
Diffstat (limited to 'src/arch/dalvik/specins.c')
-rw-r--r-- | src/arch/dalvik/specins.c | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/src/arch/dalvik/specins.c b/src/arch/dalvik/specins.c new file mode 100644 index 0000000..b6a7c4e --- /dev/null +++ b/src/arch/dalvik/specins.c @@ -0,0 +1,115 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * specins.c - gestion des instructions spéciales de la VM Dalvik + * + * Copyright (C) 2011 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 "specins.h" + + +#include "../../common/endianness.h" + + + +/****************************************************************************** +* * +* Paramètres : ctx = contexte lié à l'exécution du processeur. * +* data = flux de données à analyser. * +* pos = position courante dans ce flux. * +* len = taille totale des données à analyser. * +* addr = adresse virtuelle de l'instruction. * +* * +* Description : Détermine si du code doit être écarté du traitement. * +* * +* Retour : true si une nouvelle zone de données est à écarter. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool g_dalvik_guess_special_instruction(GDalvikContext *ctx, const bin_t *data, off_t pos, off_t len, vmpa_t addr) +{ + bool result; /* Bilan à retourner */ + uint16_t ident; /* Valeur lue dans le code */ + vmpa_t start; /* Début d'une zone de données */ + vmpa_t end; /* Fin d'une zone de données */ + uint16_t switch_size; /* Taille du switch considéré */ + uint16_t array_width; /* Taille des éléments */ + uint32_t array_size; /* Taille du tableau */ + + /* Vérification astucieuse et rapide...*/ + if (data[pos] != 0x00 /* DOP_NOP */) return false; + + if (!read_u16(&ident, data, &pos, len, SRE_LITTLE)) + return false; + + start = addr + sizeof(ident); + end = start; + + switch (ident) + { + case DID_PACKED_SWITCH: + + if (!read_u16(&switch_size, data, &pos, len, SRE_LITTLE)) + return false; + + end += sizeof(switch_size) + (1 + switch_size) * sizeof(uint32_t); + + g_dalvik_context_skip_new_area(ctx, start, end); + result = true; + + break; + + case DID_SPARSE_SWITCH: + + if (!read_u16(&switch_size, data, &pos, len, SRE_LITTLE)) + return false; + + end += sizeof(switch_size) + (2 * switch_size) * sizeof(uint32_t); + + g_dalvik_context_skip_new_area(ctx, start, end); + result = true; + + break; + + case DID_FILL_ARRAY_DATA: + + if (!read_u16(&array_width, data, &pos, len, SRE_LITTLE)) + return false; + if (!read_u32(&array_size, data, &pos, len, SRE_LITTLE)) + return false; + + end += sizeof(array_width) + sizeof(array_size) + + array_width * array_size; + + g_dalvik_context_skip_new_area(ctx, start, end); + result = true; + + break; + + default: + result = false; + break; + + } + + return result; + +} |