diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2008-07-27 19:38:15 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2008-07-27 19:38:15 (GMT) |
commit | 1bf9c5ebe8bb3326e10491974cd43b221e2a56a1 (patch) | |
tree | 01a745a798661478eb7a6e02c0a0831bb1b4950c /src/arch/operand.c | |
parent | dbf4d1f93e54251568854bff0ebc9c84f60857f6 (diff) |
Supported new x86 opcodes (nop and mov).
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@7 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/arch/operand.c')
-rw-r--r-- | src/arch/operand.c | 164 |
1 files changed, 162 insertions, 2 deletions
diff --git a/src/arch/operand.c b/src/arch/operand.c index 98460c9..cd7c2b4 100644 --- a/src/arch/operand.c +++ b/src/arch/operand.c @@ -24,10 +24,10 @@ #include "operand.h" -#include "operand-int.h" - +#include <stdio.h> +#include "operand-int.h" @@ -46,6 +46,9 @@ bool fill_db_operand(asm_operand *operand, uint8_t value) { + operand->type = AOT_NONE; + operand->size = AOS_8_BITS; + operand->value.val8 = value; return true; @@ -53,3 +56,160 @@ bool fill_db_operand(asm_operand *operand, uint8_t value) } +/****************************************************************************** +* * +* Paramètres : operand = instruction à traiter. * +* buffer = tampon de sortie mis à disposition. [OUT] * +* len = taille de ce tampon. * +* syntax = type de représentation demandée. * +* * +* Description : Traduit une opérande de type 'db' en texte. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void print_db_operand(const asm_operand *operand, char *buffer, size_t len, AsmSyntax syntax) +{ + switch (syntax) + { + case ASX_INTEL: + snprintf(buffer, len, "0x%02hhx", operand->value.val8); + break; + + case ASX_ATT: + snprintf(buffer, len, "$0x%02hhx", operand->value.val8); + break; + + } + +} + + +/****************************************************************************** +* * +* Paramètres : operand = structure dont le contenu est à définir. * +* size = taille de l'opérande souhaitée. * +* data = flux de données à analyser. * +* pos = position courante dans ce flux. [OUT] * +* len = taille totale des données à analyser. * +* * +* Description : Crée une opérande contenant une valeur sur x bits. * +* * +* Retour : true si l'opération s'est effectuée avec succès, false sinon.* +* * +* Remarques : - * +* * +******************************************************************************/ + +bool fill_imm_operand(asm_operand *operand, AsmOperandSize size, const uint8_t *data, off_t *pos, off_t len) +{ + /* Vérifications sanitaires */ + switch (size) + { + case AOS_8_BITS: + if ((len - *pos) < 1) return false; + break; + case AOS_16_BITS: + if ((len - *pos) < 2) return false; + break; + case AOS_32_BITS: + if ((len - *pos) < 4) return false; + break; + case AOS_64_BITS: + if ((len - *pos) < 8) return false; + break; + } + + operand->type = AOT_IMM; + operand->size = size; + + switch (size) + { + case AOS_8_BITS: + operand->value.val8 = data[*pos]; + *pos += 1; + break; + case AOS_16_BITS: + operand->value.val16 = data[*pos] || (data[*pos + 1] << 8); + *pos += 2; + break; + case AOS_32_BITS: + operand->value.val32 = data[*pos] || (data[*pos + 1] << 8) || (data[*pos + 2] << 16); + *pos += 4; + break; + case AOS_64_BITS: + /* + operand->value.val64 = data[*pos] || (data[*pos + 1] << 8) || (data[*pos + 2] << 16) + || (data[*pos + 3] << 24) || (data[*pos + 4] << 32) || (data[*pos + 5] << 40) + || (data[*pos + 6] << 48) || (data[*pos + 7] << 56); + */ + *pos += 8; + break; + } + + return true; + +} + + +/****************************************************************************** +* * +* Paramètres : operand = instruction à traiter. * +* buffer = tampon de sortie mis à disposition. [OUT] * +* len = taille de ce tampon. * +* syntax = type de représentation demandée. * +* * +* Description : Traduit une opérande de valeur immédiate en texte. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void print_imm_operand(const asm_operand *operand, char *buffer, size_t len, AsmSyntax syntax) +{ + switch (syntax) + { + case ASX_INTEL: + switch (operand->size) + { + case AOS_8_BITS: + snprintf(buffer, len, "0x%hhx", operand->value.val8); + break; + case AOS_16_BITS: + snprintf(buffer, len, "0x%hx", operand->value.val16); + break; + case AOS_32_BITS: + snprintf(buffer, len, "0x%x", operand->value.val32); + break; + case AOS_64_BITS: + snprintf(buffer, len, "0x%llx", operand->value.val64); + break; + } + break; + + case ASX_ATT: + switch (operand->size) + { + case AOS_8_BITS: + snprintf(buffer, len, "$0x%hhx", operand->value.val8); + break; + case AOS_16_BITS: + snprintf(buffer, len, "$0x%hx", operand->value.val16); + break; + case AOS_32_BITS: + snprintf(buffer, len, "$0x%x", operand->value.val32); + break; + case AOS_64_BITS: + snprintf(buffer, len, "$0x%llx", operand->value.val64); + break; + } + break; + + } + +} |