/* Chrysalide - Outil d'analyse de fichiers binaires * op_jump.c - décodage des sauts inconditionnels * * Copyright (C) 2009 Cyrille Bagard * * This file is part of Chrysalide. * * Chrysalide 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. * * Chrysalide 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 . */ #include "opcodes.h" #include "../instruction-int.h" #include "operand.h" /****************************************************************************** * * * Paramètres : data = flux de données à analyser. * * pos = position courante dans ce flux. [OUT] * * len = taille totale des données à analyser. * * addr = adresse virtuelle de l'instruction. * * proc = architecture ciblée par le désassemblage. * * * * Description : Décode une instruction de type 'jr rs'. * * * * Retour : Instruction mise en place ou NULL. * * * * Remarques : - * * * ******************************************************************************/ GArchInstruction *mips_read_instr_jump_register(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, const GMipsProcessor *proc) { GArchInstruction *result; /* Instruction à retourner */ result = g_mips_instruction_new(MOP_JR); if (!mips_read_n_operands(result, data, pos, len, 1, MIPS_OTP_RS)) { /* TODO free(result);*/ return NULL; } return result; } /****************************************************************************** * * * Paramètres : data = flux de données à analyser. * * pos = position courante dans ce flux. [OUT] * * len = taille totale des données à analyser. * * addr = adresse virtuelle de l'instruction. * * proc = architecture ciblée par le désassemblage. * * * * Description : Décode une instruction de type 'jalr[.hb] [rd, ]rs'. * * * * Retour : Instruction mise en place ou NULL. * * * * Remarques : - * * * ******************************************************************************/ GArchInstruction *mips_read_instr_jump_and_link_register(const bin_t *data, off_t *pos, off_t len, vmpa_t addr, const GMipsProcessor *proc) { GArchInstruction *result; /* Instruction à retourner */ off_t tmp; /* Pour ne pas toucher à 'pos' */ uint32_t code; /* Code binaire à décoder */ GArchOperand *operand; /* Opérande à analyser */ const mips_register *reg; /* Registre implicite ? */ tmp = *pos; if (!read_u32(&code, data, &tmp, len, SRE_LITTLE/* FIXME */)) return NULL; if (code & 0x400) result = g_mips_instruction_new(MOP_JALR_HB); else result = g_mips_instruction_new(MOP_JALR); if (!mips_read_n_operands(result, data, pos, len, 2, MIPS_OTP_RD, MIPS_OTP_RS)) { /* TODO free(result);*/ return NULL; } operand = G_ARCH_INSTRUCTION(result)->operands[0]; reg = g_mips_register_operand_get_register(G_MIPS_REGISTER_OPERAND(operand)); if (is_mips_register_return_address(reg)) { g_arch_instruction_detach_operand(G_ARCH_INSTRUCTION(result), operand); /* TODO free(operand);*/ } return result; }