diff options
Diffstat (limited to 'src/arch')
| -rw-r--r-- | src/arch/dalvik/operands/register.c | 1 | ||||
| -rw-r--r-- | src/arch/x86/Makefile.am | 47 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/Makefile.am | 57 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/adc.c (renamed from src/arch/x86/op_adc.c) | 6 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/add.c (renamed from src/arch/x86/op_add.c) | 6 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/and.c (renamed from src/arch/x86/op_and.c) | 6 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/arpl.c (renamed from src/arch/x86/op_arpl.c) | 6 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/call.c (renamed from src/arch/x86/op_call.c) | 6 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/cld.c (renamed from src/arch/x86/op_cld.c) | 5 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/cmp.c (renamed from src/arch/x86/op_cmp.c) | 6 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/cmps.c (renamed from src/arch/x86/op_cmps.c) | 5 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/dec.c (renamed from src/arch/x86/op_dec.c) | 6 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/hlt.c (renamed from src/arch/x86/op_hlt.c) | 5 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/inc.c (renamed from src/arch/x86/op_inc.c) | 6 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/int.c (renamed from src/arch/x86/op_int.c) | 7 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/jump.c (renamed from src/arch/x86/op_jump.c) | 5 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/lea.c (renamed from src/arch/x86/op_lea.c) | 6 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/leave.c (renamed from src/arch/x86/op_leave.c) | 5 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/mov.c (renamed from src/arch/x86/op_mov.c) | 6 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/movs.c (renamed from src/arch/x86/op_movs.c) | 6 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/movsx.c (renamed from src/arch/x86/op_movsx.c) | 6 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/movzx.c (renamed from src/arch/x86/op_movzx.c) | 6 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/mul.c (renamed from src/arch/x86/op_mul.c) | 6 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/nop.c (renamed from src/arch/x86/op_nop.c) | 4 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/not.c (renamed from src/arch/x86/op_not.c) | 6 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/opcodes.h (renamed from src/arch/x86/opcodes.h) | 10 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/or.c (renamed from src/arch/x86/op_or.c) | 6 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/pop.c (renamed from src/arch/x86/op_pop.c) | 6 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/push.c (renamed from src/arch/x86/op_push.c) | 6 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/rcl.c (renamed from src/arch/x86/op_rcl.c) | 6 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/rcr.c (renamed from src/arch/x86/op_rcr.c) | 6 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/ret.c (renamed from src/arch/x86/op_ret.c) | 6 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/rol.c (renamed from src/arch/x86/op_rol.c) | 6 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/ror.c (renamed from src/arch/x86/op_ror.c) | 6 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/sar.c (renamed from src/arch/x86/op_sar.c) | 6 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/sbb.c (renamed from src/arch/x86/op_sbb.c) | 6 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/scas.c (renamed from src/arch/x86/op_scas.c) | 6 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/set.c (renamed from src/arch/x86/op_set.c) | 5 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/shl.c (renamed from src/arch/x86/op_shl.c) | 6 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/shr.c (renamed from src/arch/x86/op_shr.c) | 6 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/stos.c (renamed from src/arch/x86/op_stos.c) | 6 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/sub.c (renamed from src/arch/x86/op_sub.c) | 6 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/test.c (renamed from src/arch/x86/op_test.c) | 6 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/xchg.c (renamed from src/arch/x86/op_xchg.c) | 6 | ||||
| -rw-r--r-- | src/arch/x86/opcodes/xor.c (renamed from src/arch/x86/op_xor.c) | 6 | ||||
| -rw-r--r-- | src/arch/x86/operand.c | 1305 | ||||
| -rw-r--r-- | src/arch/x86/operand.h | 169 | ||||
| -rw-r--r-- | src/arch/x86/operands/Makefile.am | 21 | ||||
| -rw-r--r-- | src/arch/x86/operands/data.c | 207 | ||||
| -rw-r--r-- | src/arch/x86/operands/data.h | 60 | ||||
| -rw-r--r-- | src/arch/x86/operands/modrm.c | 436 | ||||
| -rw-r--r-- | src/arch/x86/operands/modrm.h | 70 | ||||
| -rw-r--r-- | src/arch/x86/operands/moffs.c | 189 | ||||
| -rw-r--r-- | src/arch/x86/operands/moffs.h | 59 | ||||
| -rw-r--r-- | src/arch/x86/operands/register.c | 265 | ||||
| -rw-r--r-- | src/arch/x86/operands/register.h | 66 | ||||
| -rw-r--r-- | src/arch/x86/operands/relative.c | 221 | ||||
| -rw-r--r-- | src/arch/x86/operands/relative.h | 63 | ||||
| -rw-r--r-- | src/arch/x86/processor.c | 2 | 
59 files changed, 1815 insertions, 1672 deletions
diff --git a/src/arch/dalvik/operands/register.c b/src/arch/dalvik/operands/register.c index cca4ee7..fb95004 100644 --- a/src/arch/dalvik/operands/register.c +++ b/src/arch/dalvik/operands/register.c @@ -60,7 +60,6 @@ static void g_dalvik_register_operand_print(const GDalvikRegisterOperand *, GBuf -  /* Indique le type défini par la GLib pour un opérande de registre Dalvik. */  G_DEFINE_TYPE(GDalvikRegisterOperand, g_dalvik_register_operand, G_TYPE_ARCH_OPERAND); diff --git a/src/arch/x86/Makefile.am b/src/arch/x86/Makefile.am index ff246c0..b7b72d6 100644 --- a/src/arch/x86/Makefile.am +++ b/src/arch/x86/Makefile.am @@ -3,52 +3,13 @@ noinst_LTLIBRARIES = libarchx86.la  libarchx86_la_SOURCES =					\  	instruction.h instruction.c			\ -	op_adc.c							\ -	op_add.c							\ -	op_and.c							\ -	op_arpl.c							\ -	op_call.c							\ -	op_cld.c							\ -	op_cmp.c							\ -	op_cmps.c							\ -	op_dec.c							\ -	op_hlt.c							\ -	op_inc.c							\ -	op_int.c							\ -	op_jump.c							\ -	op_lea.c							\ -	op_leave.c							\ -	op_mov.c							\ -	op_movs.c							\ -	op_movsx.c							\ -	op_movzx.c							\ -	op_mul.c							\ -	op_nop.c							\ -	op_not.c							\ -	op_or.c								\ -	op_pop.c							\ -	op_push.c							\ -	op_rcl.c							\ -	op_rcr.c							\ -	op_ret.c							\ -	op_rol.c							\ -	op_ror.c							\ -	op_sar.c							\ -	op_sbb.c							\ -	op_scas.c							\ -	op_set.c							\ -	op_shl.c							\ -	op_shr.c							\ -	op_stos.c							\ -	op_sub.c							\ -	op_test.c							\ -	op_xchg.c							\ -	op_xor.c							\ -	opcodes.h							\  	operand.h operand.c					\  	processor.h processor.c				\  	registers.h registers.c +libarchx86_la_LIBADD =					\ +	opcodes/libarchx86opcodes.la		\ +	operands/libarchx86operands.la  libarchx86_la_CFLAGS = $(AM_CFLAGS) @@ -60,4 +21,4 @@ AM_CPPFLAGS =  AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) -SUBDIRS =  +SUBDIRS = opcodes operands diff --git a/src/arch/x86/opcodes/Makefile.am b/src/arch/x86/opcodes/Makefile.am new file mode 100644 index 0000000..6f7f71e --- /dev/null +++ b/src/arch/x86/opcodes/Makefile.am @@ -0,0 +1,57 @@ + +noinst_LTLIBRARIES = libarchx86opcodes.la + +libarchx86opcodes_la_SOURCES =			\ +	adc.c								\ +	add.c								\ +	and.c								\ +	arpl.c								\ +	call.c								\ +	cld.c								\ +	cmp.c								\ +	cmps.c								\ +	dec.c								\ +	hlt.c								\ +	inc.c								\ +	int.c								\ +	jump.c								\ +	lea.c								\ +	leave.c								\ +	mov.c								\ +	movs.c								\ +	movsx.c								\ +	movzx.c								\ +	mul.c								\ +	nop.c								\ +	not.c								\ +	opcodes.h							\ +	or.c								\ +	pop.c								\ +	push.c								\ +	rcl.c								\ +	rcr.c								\ +	ret.c								\ +	rol.c								\ +	ror.c								\ +	sar.c								\ +	sbb.c								\ +	scas.c								\ +	set.c								\ +	shl.c								\ +	shr.c								\ +	stos.c								\ +	sub.c								\ +	test.c								\ +	xchg.c								\ +	xor.c + +libarchx86opcodes_la_LIBADD = + +libarchx86opcodes_la_CFLAGS = $(AM_CFLAGS) + + +INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) + +AM_CPPFLAGS =  + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) diff --git a/src/arch/x86/op_adc.c b/src/arch/x86/opcodes/adc.c index f098c8c..7aad32a 100644 --- a/src/arch/x86/op_adc.c +++ b/src/arch/x86/opcodes/adc.c @@ -21,12 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" -#include "operand.h" +#include "../operand.h" diff --git a/src/arch/x86/op_add.c b/src/arch/x86/opcodes/add.c index 71a8da5..5f323e9 100644 --- a/src/arch/x86/op_add.c +++ b/src/arch/x86/opcodes/add.c @@ -21,12 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" -#include "operand.h" +#include "../operand.h" diff --git a/src/arch/x86/op_and.c b/src/arch/x86/opcodes/and.c index 709434d..6eb22cf 100644 --- a/src/arch/x86/op_and.c +++ b/src/arch/x86/opcodes/and.c @@ -21,12 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" -#include "operand.h" +#include "../operand.h" diff --git a/src/arch/x86/op_arpl.c b/src/arch/x86/opcodes/arpl.c index 22ff122..cb3e7db 100644 --- a/src/arch/x86/op_arpl.c +++ b/src/arch/x86/opcodes/arpl.c @@ -21,12 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" -#include "operand.h" +#include "../operand.h" diff --git a/src/arch/x86/op_call.c b/src/arch/x86/opcodes/call.c index 83d00b4..2e5c74d 100644 --- a/src/arch/x86/op_call.c +++ b/src/arch/x86/opcodes/call.c @@ -21,12 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" -#include "operand.h" +#include "../operand.h" diff --git a/src/arch/x86/op_cld.c b/src/arch/x86/opcodes/cld.c index 197202f..2c998b0 100644 --- a/src/arch/x86/op_cld.c +++ b/src/arch/x86/opcodes/cld.c @@ -21,11 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" +#include "../operand.h" diff --git a/src/arch/x86/op_cmp.c b/src/arch/x86/opcodes/cmp.c index dd14bfb..1ff951a 100644 --- a/src/arch/x86/op_cmp.c +++ b/src/arch/x86/opcodes/cmp.c @@ -21,12 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" -#include "operand.h" +#include "../operand.h" diff --git a/src/arch/x86/op_cmps.c b/src/arch/x86/opcodes/cmps.c index 6d2f2b6..725b464 100644 --- a/src/arch/x86/op_cmps.c +++ b/src/arch/x86/opcodes/cmps.c @@ -21,9 +21,10 @@   */ -#include "../instruction-int.h"  #include "opcodes.h" -#include "operand.h" + + +#include "../operand.h" diff --git a/src/arch/x86/op_dec.c b/src/arch/x86/opcodes/dec.c index 609ad6a..87e7b11 100644 --- a/src/arch/x86/op_dec.c +++ b/src/arch/x86/opcodes/dec.c @@ -21,12 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" -#include "operand.h" +#include "../operand.h" diff --git a/src/arch/x86/op_hlt.c b/src/arch/x86/opcodes/hlt.c index 53016a3..cde96fb 100644 --- a/src/arch/x86/op_hlt.c +++ b/src/arch/x86/opcodes/hlt.c @@ -21,11 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" +#include "../operand.h" diff --git a/src/arch/x86/op_inc.c b/src/arch/x86/opcodes/inc.c index 8ebf8bf..ee28566 100644 --- a/src/arch/x86/op_inc.c +++ b/src/arch/x86/opcodes/inc.c @@ -21,12 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" -#include "operand.h" +#include "../operand.h" diff --git a/src/arch/x86/op_int.c b/src/arch/x86/opcodes/int.c index 74bfcd4..8acf17b 100644 --- a/src/arch/x86/op_int.c +++ b/src/arch/x86/opcodes/int.c @@ -21,13 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" -#include "operand.h" -#include "../immediate.h" +#include "../operand.h" diff --git a/src/arch/x86/op_jump.c b/src/arch/x86/opcodes/jump.c index a49782e..c4bf9a5 100644 --- a/src/arch/x86/op_jump.c +++ b/src/arch/x86/opcodes/jump.c @@ -21,9 +21,10 @@   */ -#include "../instruction-int.h"  #include "opcodes.h" -#include "operand.h" + + +#include "../operand.h" diff --git a/src/arch/x86/op_lea.c b/src/arch/x86/opcodes/lea.c index b49dfbb..0291b6f 100644 --- a/src/arch/x86/op_lea.c +++ b/src/arch/x86/opcodes/lea.c @@ -21,12 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" -#include "operand.h" +#include "../operand.h" diff --git a/src/arch/x86/op_leave.c b/src/arch/x86/opcodes/leave.c index 1c57d4d..7e6128a 100644 --- a/src/arch/x86/op_leave.c +++ b/src/arch/x86/opcodes/leave.c @@ -21,11 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" +#include "../operand.h" diff --git a/src/arch/x86/op_mov.c b/src/arch/x86/opcodes/mov.c index ce84e62..a19689f 100644 --- a/src/arch/x86/op_mov.c +++ b/src/arch/x86/opcodes/mov.c @@ -21,12 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" -#include "operand.h" +#include "../operand.h" diff --git a/src/arch/x86/op_movs.c b/src/arch/x86/opcodes/movs.c index 0d3cbad..7a10006 100644 --- a/src/arch/x86/op_movs.c +++ b/src/arch/x86/opcodes/movs.c @@ -21,12 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" -#include "operand.h" +#include "../operand.h" diff --git a/src/arch/x86/op_movsx.c b/src/arch/x86/opcodes/movsx.c index 0cbd817..e5ec52d 100644 --- a/src/arch/x86/op_movsx.c +++ b/src/arch/x86/opcodes/movsx.c @@ -21,12 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" -#include "operand.h" +#include "../operand.h" diff --git a/src/arch/x86/op_movzx.c b/src/arch/x86/opcodes/movzx.c index 1c47582..6648443 100644 --- a/src/arch/x86/op_movzx.c +++ b/src/arch/x86/opcodes/movzx.c @@ -21,12 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" -#include "operand.h" +#include "../operand.h" diff --git a/src/arch/x86/op_mul.c b/src/arch/x86/opcodes/mul.c index 7b48b29..848fbdc 100644 --- a/src/arch/x86/op_mul.c +++ b/src/arch/x86/opcodes/mul.c @@ -21,12 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" -#include "operand.h" +#include "../operand.h" diff --git a/src/arch/x86/op_nop.c b/src/arch/x86/opcodes/nop.c index 5e0bf72..95e692c 100644 --- a/src/arch/x86/op_nop.c +++ b/src/arch/x86/opcodes/nop.c @@ -21,10 +21,12 @@   */ -#include "../instruction-int.h"  #include "opcodes.h" +#include "../operand.h" + +  /******************************************************************************  *                                                                             * diff --git a/src/arch/x86/op_not.c b/src/arch/x86/opcodes/not.c index 78d90ff..1a0c909 100644 --- a/src/arch/x86/op_not.c +++ b/src/arch/x86/opcodes/not.c @@ -21,12 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" -#include "operand.h" +#include "../operand.h" diff --git a/src/arch/x86/opcodes.h b/src/arch/x86/opcodes/opcodes.h index ed5d07e..6b65673 100644 --- a/src/arch/x86/opcodes.h +++ b/src/arch/x86/opcodes/opcodes.h @@ -21,12 +21,12 @@   */ -#ifndef _ARCH_X86_OPCODES_H -#define _ARCH_X86_OPCODES_H +#ifndef _ARCH_X86_OPCODES_OPCODES_H +#define _ARCH_X86_OPCODES_OPCODES_H -#include "instruction.h" -#include "processor.h" +#include "../instruction.h" +#include "../processor.h" @@ -682,4 +682,4 @@ GArchInstruction *x86_read_instr_xor_rm1632_r1632(const bin_t *, off_t *, off_t, -#endif  /* _ARCH_X86_OPCODES_H */ +#endif  /* _ARCH_X86_OPCODES_OPCODES_H */ diff --git a/src/arch/x86/op_or.c b/src/arch/x86/opcodes/or.c index 28e7aa7..14bf0ba 100644 --- a/src/arch/x86/op_or.c +++ b/src/arch/x86/opcodes/or.c @@ -21,12 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" -#include "operand.h" +#include "../operand.h" diff --git a/src/arch/x86/op_pop.c b/src/arch/x86/opcodes/pop.c index ed48c9e..62c0d47 100644 --- a/src/arch/x86/op_pop.c +++ b/src/arch/x86/opcodes/pop.c @@ -21,12 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" -#include "operand.h" +#include "../operand.h" diff --git a/src/arch/x86/op_push.c b/src/arch/x86/opcodes/push.c index 56621e3..8702857 100644 --- a/src/arch/x86/op_push.c +++ b/src/arch/x86/opcodes/push.c @@ -21,12 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" -#include "operand.h" +#include "../operand.h" diff --git a/src/arch/x86/op_rcl.c b/src/arch/x86/opcodes/rcl.c index 6634b83..be98e23 100644 --- a/src/arch/x86/op_rcl.c +++ b/src/arch/x86/opcodes/rcl.c @@ -21,12 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" -#include "operand.h" +#include "../operand.h" diff --git a/src/arch/x86/op_rcr.c b/src/arch/x86/opcodes/rcr.c index 69a63da..a8204f7 100644 --- a/src/arch/x86/op_rcr.c +++ b/src/arch/x86/opcodes/rcr.c @@ -21,12 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" -#include "operand.h" +#include "../operand.h" diff --git a/src/arch/x86/op_ret.c b/src/arch/x86/opcodes/ret.c index 6713992..e1ffddf 100644 --- a/src/arch/x86/op_ret.c +++ b/src/arch/x86/opcodes/ret.c @@ -21,12 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" -#include "operand.h" +#include "../operand.h" diff --git a/src/arch/x86/op_rol.c b/src/arch/x86/opcodes/rol.c index 6f85110..240e953 100644 --- a/src/arch/x86/op_rol.c +++ b/src/arch/x86/opcodes/rol.c @@ -21,12 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" -#include "operand.h" +#include "../operand.h" diff --git a/src/arch/x86/op_ror.c b/src/arch/x86/opcodes/ror.c index cedf20c..af66330 100644 --- a/src/arch/x86/op_ror.c +++ b/src/arch/x86/opcodes/ror.c @@ -21,12 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" -#include "operand.h" +#include "../operand.h" diff --git a/src/arch/x86/op_sar.c b/src/arch/x86/opcodes/sar.c index 8024e42..360cffb 100644 --- a/src/arch/x86/op_sar.c +++ b/src/arch/x86/opcodes/sar.c @@ -21,12 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" -#include "operand.h" +#include "../operand.h" diff --git a/src/arch/x86/op_sbb.c b/src/arch/x86/opcodes/sbb.c index 1939bb8..b842436 100644 --- a/src/arch/x86/op_sbb.c +++ b/src/arch/x86/opcodes/sbb.c @@ -21,12 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" -#include "operand.h" +#include "../operand.h" diff --git a/src/arch/x86/op_scas.c b/src/arch/x86/opcodes/scas.c index 2ec8230..f3275b5 100644 --- a/src/arch/x86/op_scas.c +++ b/src/arch/x86/opcodes/scas.c @@ -21,12 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" -#include "operand.h" +#include "../operand.h" diff --git a/src/arch/x86/op_set.c b/src/arch/x86/opcodes/set.c index 65721d9..7d93723 100644 --- a/src/arch/x86/op_set.c +++ b/src/arch/x86/opcodes/set.c @@ -21,9 +21,10 @@   */ -#include "../instruction-int.h"  #include "opcodes.h" -#include "operand.h" + + +#include "../operand.h" diff --git a/src/arch/x86/op_shl.c b/src/arch/x86/opcodes/shl.c index 9494d3e..487efd6 100644 --- a/src/arch/x86/op_shl.c +++ b/src/arch/x86/opcodes/shl.c @@ -21,12 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" -#include "operand.h" +#include "../operand.h" diff --git a/src/arch/x86/op_shr.c b/src/arch/x86/opcodes/shr.c index 28496a6..a493f71 100644 --- a/src/arch/x86/op_shr.c +++ b/src/arch/x86/opcodes/shr.c @@ -21,12 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" -#include "operand.h" +#include "../operand.h" diff --git a/src/arch/x86/op_stos.c b/src/arch/x86/opcodes/stos.c index 2635c2a..8c285d8 100644 --- a/src/arch/x86/op_stos.c +++ b/src/arch/x86/opcodes/stos.c @@ -21,12 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" -#include "operand.h" +#include "../operand.h" diff --git a/src/arch/x86/op_sub.c b/src/arch/x86/opcodes/sub.c index 31deb4f..8179feb 100644 --- a/src/arch/x86/op_sub.c +++ b/src/arch/x86/opcodes/sub.c @@ -21,12 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" -#include "operand.h" +#include "../operand.h" diff --git a/src/arch/x86/op_test.c b/src/arch/x86/opcodes/test.c index 16109ee..12a2ab5 100644 --- a/src/arch/x86/op_test.c +++ b/src/arch/x86/opcodes/test.c @@ -21,12 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" -#include "operand.h" +#include "../operand.h" diff --git a/src/arch/x86/op_xchg.c b/src/arch/x86/opcodes/xchg.c index dec2560..f4122db 100644 --- a/src/arch/x86/op_xchg.c +++ b/src/arch/x86/opcodes/xchg.c @@ -21,12 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" -#include "operand.h" +#include "../operand.h" diff --git a/src/arch/x86/op_xor.c b/src/arch/x86/opcodes/xor.c index 575d7e7..0d0bfeb 100644 --- a/src/arch/x86/op_xor.c +++ b/src/arch/x86/opcodes/xor.c @@ -21,12 +21,10 @@   */ -#include <malloc.h> +#include "opcodes.h" -#include "../instruction-int.h" -#include "opcodes.h" -#include "operand.h" +#include "../operand.h" diff --git a/src/arch/x86/operand.c b/src/arch/x86/operand.c index 36faa76..85f2fb9 100644 --- a/src/arch/x86/operand.c +++ b/src/arch/x86/operand.c @@ -23,1311 +23,6 @@  #include "operand.h" -#include <malloc.h> -#include <math.h> -#include <stdarg.h> -#include <stdio.h> - - -#include "../operand-int.h" -#include "../../common/extstr.h" - - - -/* ---------------------- COQUILLE VIDE POUR LES OPERANDES X86 ---------------------- */ - - -/* Définition d'un opérande de x86 (instance) */ -struct _GX86Operand -{ -    GArchOperand parent;                    /* Instance parente            */ - -}; - - -/* Définition d'un opérande de x86 (classe) */ -struct _GX86OperandClass -{ -    GArchOperandClass parent;               /* Classe parente              */ - -}; - - -/* Initialise la classe des opérandes x86 de base. */ -static void g_x86_operand_class_init(GX86OperandClass *); - -/* Initialise une instance d'opérande de base pour x86. */ -static void g_x86_operand_init(GX86Operand *); - - - -/* ------------------------ OPERANDES VISANT UN REGISTRE X86 ------------------------ */ - - -/* Définition d'un opérande visant un registre x86 (instance) */ -struct _GX86RegisterOperand -{ -    GX86Operand parent;                     /* Instance parente            */ - -    GX86Register *reg;                      /* Registre représenté         */ - -}; - - -/* Définition d'un opérande visant un registre x86 (classe) */ -struct _GX86RegisterOperandClass -{ -    GX86OperandClass parent;                /* Classe parente              */ - -}; - - -/* Initialise la classe des opérandes de registre x86. */ -static void g_x86_register_operand_class_init(GX86RegisterOperandClass *); - -/* Initialise une instance d'opérande de registre x86. */ -static void g_x86_register_operand_init(GX86RegisterOperand *); - -/* Ajoute du texte simple à un fichier ouvert en écriture. */ -static void g_x86_register_operand_add_text(const GX86RegisterOperand *, GRenderingOptions *, MainRendering, FILE *); - -/*  Ajoute à un tampon GLib le contenu de l'instance spécifiée. */ -static void g_x86_register_operand_to_buffer(const GX86RegisterOperand *, GBufferLine *, GRenderingOptions *); - - - -/* ----------------------- OPERANDES COMPLEXES DE TYPE MOD/RM ----------------------- */ - - -/* Définition d'un opérande x86 de type ModRM (instance) */ -struct _GX86ModRMOperand -{ -    GX86Operand parent;                     /* Instance parente            */ - -    uint8_t scale;                          /* Puissance de deux           */ -    GX86Register *index;                    /* Registre servant d'indice   */ -    GX86Register *base;                     /* Registre de base            */ -    GImmOperand *displacement;              /* Décallage supplémentaire    */ - -}; - - -/* Définition d'un opérande x86 de type ModRM (classe) */ -struct _GX86ModRMOperandClass -{ -    GX86OperandClass parent;                /* Classe parente              */ - -}; - - -/* Initialise la classe des opérandes x86 de type ModRM. */ -static void g_x86_mod_rm_operand_class_init(GX86ModRMOperandClass *); - -/* Initialise une instance d'opérande x86 de type ModRM. */ -static void g_x86_mod_rm_operand_init(GX86ModRMOperand *); - -/* Ajoute du texte simple à un fichier ouvert en écriture. */ -static void g_x86_mod_rm_operand_add_text(const GX86ModRMOperand *, GRenderingOptions *, MainRendering, FILE *); - -/* Ajoute à un tampon GLib le contenu de l'instance spécifiée. */ -static void g_x86_mod_rm_operand_to_buffer(const GX86ModRMOperand *, GBufferLine *, GRenderingOptions *); - - - -/* ------------------------- OPERANDES D'ADRESSES RELATIVES ------------------------- */ - - -/* Définition d'un opérande x86 d'adresse relative (instance) */ -struct _GX86RelativeOperand -{ -    GX86Operand parent;                     /* Instance parente            */ - -    GImmOperand *immediate;                 /* Adresse visée reconstituée  */ - -}; - -/* Définition d'un opérande x86 d'adresse relative (classe) */ -struct _GX86RelativeOperandClass -{ -    GX86OperandClass parent;                /* Classe parente              */ - -}; - - -/* Initialise la classe des opérandes x86 d'adresse relative. */ -static void g_x86_relative_operand_class_init(GX86RelativeOperandClass *); - -/* Initialise une instance d'opérande x86 d'adresse relative. */ -static void g_x86_relative_operand_init(GX86RelativeOperand *); - -/* Ajoute du texte simple à un fichier ouvert en écriture. */ -static void g_x86_relative_operand_add_text(const GX86RelativeOperand *, GRenderingOptions *, MainRendering, FILE *); - -/* Ajoute à un tampon GLib le contenu de l'instance spécifiée. */ -static void g_x86_relative_operand_to_buffer(const GX86RelativeOperand *, GBufferLine *, GRenderingOptions *); - - - -/* ------------------------ OPERANDES D'EMPLACEMENTS MEMOIRE ------------------------ */ - - -/* Définition d'un opérande visant un emplacement mémoire x86 (instance) */ -struct _GX86MOffsOperand -{ -    GX86Operand parent;                     /* Instance parente            */ - -    GImmOperand *offset;                    /* Adresse mémoire visée       */ - -}; - -/* Définition d'un opérande visant un emplacement mémoire x86 (classe) */ -struct _GX86MOffsOperandClass -{ -    GX86OperandClass parent;                /* Classe parente              */ - -}; - - -/* Initialise la classe des opérandes d'emplacement mémoire x86. */ -static void g_x86_moffs_operand_class_init(GX86MOffsOperandClass *); - -/* Initialise une instance d'opérande d'emplacement mémoire x86. */ -static void g_x86_moffs_operand_init(GX86MOffsOperand *); - -/* Ajoute du texte simple à un fichier ouvert en écriture. */ -static void g_x86_moffs_operand_add_text(const GX86MOffsOperand *, GRenderingOptions *, MainRendering, FILE *); - -/* Ajoute à un tampon GLib le contenu de l'instance spécifiée. */ -static void g_x86_moffs_operand_to_buffer(const GX86MOffsOperand *, GBufferLine *, GRenderingOptions *); - - - -/* ---------------------- OPERANDES DE MANIPULATION DE DONNEES ---------------------- */ - - -/* Définition d'un opérande x86 de manipulation de données (instance) */ -struct _GX86DataOperand -{ -    GX86Operand parent;                     /* Instance parente            */ - -    GX86Register *reg;                      /* Registre représenté         */ -    bool dest;                              /* Déduction du type de segment*/ - -}; - -/* Définition d'un opérande x86 de manipulation de données (classe) */ -struct _GX86DataOperandClass -{ -    GX86OperandClass parent;                /* Classe parente              */ - -}; - - -/* Initialise la classe des opérandes x86 pointant des données. */ -static void g_x86_data_operand_class_init(GX86DataOperandClass *); - -/* Initialise une instance d'opérande x86 pointant des données. */ -static void g_x86_data_operand_init(GX86DataOperand *); - -/* Ajoute du texte simple à un fichier ouvert en écriture. */ -static void g_x86_data_operand_add_text(const GX86DataOperand *, GRenderingOptions *, MainRendering, FILE *); - -/* Ajoute à un tampon GLib le contenu de l'instance spécifiée. */ -static void g_x86_data_operand_to_buffer(const GX86DataOperand *, GBufferLine *, GRenderingOptions *); - - - -/* ---------------------------------------------------------------------------------- */ -/*                        COQUILLE VIDE POUR LES OPERANDES X86                        */ -/* ---------------------------------------------------------------------------------- */ - - -/* Indique le type défini par la GLib pour un opérande de x86. */ -G_DEFINE_TYPE(GX86Operand, g_x86_operand, G_TYPE_ARCH_OPERAND); - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : klass = classe à initialiser.                                * -*                                                                             * -*  Description : Initialise la classe des opérandes x86 de base.              * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_x86_operand_class_init(GX86OperandClass *klass) -{ - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = instance à initialiser.                            * -*                                                                             * -*  Description : Initialise une instance d'opérande de base pour x86.         * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_x86_operand_init(GX86Operand *operand) -{ - -} - - - -/* ---------------------------------------------------------------------------------- */ -/*                          OPERANDES VISANT UN REGISTRE X86                          */ -/* ---------------------------------------------------------------------------------- */ - - -/* Indique le type défini par la GLib pour un opérande de registre x86. */ -G_DEFINE_TYPE(GX86RegisterOperand, g_x86_register_operand, G_TYPE_X86_OPERAND); - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : klass = classe à initialiser.                                * -*                                                                             * -*  Description : Initialise la classe des opérandes de registre x86.          * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_x86_register_operand_class_init(GX86RegisterOperandClass *klass) -{ - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = instance à initialiser.                            * -*                                                                             * -*  Description : Initialise une instance d'opérande de registre x86.          * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_x86_register_operand_init(GX86RegisterOperand *operand) -{ -    GContentExporter *parent;               /* Instance parente            */ - -    parent = G_CONTENT_EXPORTER(operand); - -    parent->add_text = (add_text_fc)g_x86_register_operand_add_text; -    parent->export_buffer = (export_buffer_fc)g_x86_register_operand_to_buffer; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : data = flux de données à analyser.                           * -*                pos  = position courante dans ce flux. [OUT]                 * -*                len  = taille totale des données à analyser.                 * -*                size = taille de l'opérande, et donc du registre.            * -*                base = indice du premier registre.                           * -*                                                                             * -*  Description : Crée un opérande visant un registre x86.                     * -*                                                                             * -*  Retour      : Opérande mis en place.                                       * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -GArchOperand *g_x86_register_operand_new_from_opcode(const bin_t *data, off_t *pos, off_t len, MemoryDataSize size, bin_t base) -{ -    GX86RegisterOperand *result;            /* Structure à retourner       */ -    GX86Register *reg;                      /* Registre lu                 */ - -    reg = g_x86_register_new(size, data[*pos] - base); - -    if (reg != NULL) -    { -        (*pos)++; - -        result = g_object_new(G_TYPE_X86_REGISTER_OPERAND, NULL); - -        result->reg = reg; - -    } -    else result = NULL; - -    return G_ARCH_OPERAND(result); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : data  = flux de données à analyser.                          * -*                pos   = position courante dans ce flux. [OUT]                * -*                len   = taille totale des données à analyser.                * -*                size  = taille de l'opérande, et donc du registre.           * -*                first = indique la partie du ModR/M à traiter.               * -*                                                                             * -*  Description : Crée un opérande visant un registre x86.                     * -*                                                                             * -*  Retour      : Opérande mis en place.                                       * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -GArchOperand *g_x86_register_operand_new_from_mod_rm(const bin_t *data, off_t *pos, off_t len, MemoryDataSize size, bool first) -{ -    GX86RegisterOperand *result;            /* Structure à retourner       */ -    bin_t index;                            /* Registre lu                 */ -    GX86Register *reg;                      /* Registre créé               */ - -    if (first) index = data[*pos] & 0x07; -    else index = (data[*pos] & 0x38) >> 3; - -    reg = g_x86_register_new(size, index); - -    if (reg != NULL) -    { -        (*pos)++; - -        result = g_object_new(G_TYPE_X86_REGISTER_OPERAND, NULL); - -        result->reg = reg; - -    } -    else result = NULL; - -    return G_ARCH_OPERAND(result); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : index = indice du registre visé.                             * -*                size  = taille de l'opérande, et donc du registre.           * -*                                                                             * -*  Description : Crée un opérande visant un registre x86 donné.               * -*                                                                             * -*  Retour      : Opérande mis en place.                                       * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -GArchOperand *g_x86_register_operand_new_from_index(bin_t index, MemoryDataSize size) -{ -    GX86RegisterOperand *result;            /* Structure à retourner       */ -    GX86Register *reg;                      /* Registre lu                 */ - -    reg = g_x86_register_new(size, index); - -    if (reg != NULL) -    { -        result = g_object_new(G_TYPE_X86_REGISTER_OPERAND, NULL); - -        result->reg = reg; - -    } -    else result = NULL; - -    return G_ARCH_OPERAND(result); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = opérande à transcrire.                             * -*                options   = options de rendu.                                * -*                rendering = support effectif final des lignes de code.       * -*                stream    = flux ouvert en écriture.                         * -*                                                                             * -*  Description : Ajoute du texte simple à un fichier ouvert en écriture.      * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_x86_register_operand_add_text(const GX86RegisterOperand *operand, GRenderingOptions *options, MainRendering rendering, FILE *stream) -{ -    g_content_exporter_add_text(G_CONTENT_EXPORTER(operand->reg), options, rendering, stream); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = opérande à transcrire.                             * -*                buffer  = espace où placer ledit contenu.                    * -*                options = options de rendu.                                  * -*                                                                             * -*  Description : Ajoute à un tampon GLib le contenu de l'instance spécifiée.  * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_x86_register_operand_to_buffer(const GX86RegisterOperand *operand, GBufferLine *buffer, GRenderingOptions *options) -{ -    g_content_exporter_to_buffer(G_CONTENT_EXPORTER(operand->reg), buffer, options); - -} - - - -/* ---------------------------------------------------------------------------------- */ -/*                         OPERANDES COMPLEXES DE TYPE MOD/RM                         */ -/* ---------------------------------------------------------------------------------- */ - - -/* Indique le type défini par la GLib pour un opérande x86 de type ModRM. */ -G_DEFINE_TYPE(GX86ModRMOperand, g_x86_mod_rm_operand, G_TYPE_ARCH_OPERAND); - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : klass = classe à initialiser.                                * -*                                                                             * -*  Description : Initialise la classe des opérandes x86 de type ModRM.        * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_x86_mod_rm_operand_class_init(GX86ModRMOperandClass *klass) -{ - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = instance à initialiser.                            * -*                                                                             * -*  Description : Initialise une instance d'opérande x86 de type ModRM.        * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_x86_mod_rm_operand_init(GX86ModRMOperand *operand) -{ -    GContentExporter *parent;               /* Instance parente            */ - -    parent = G_CONTENT_EXPORTER(operand); - -    parent->add_text = (add_text_fc)g_x86_mod_rm_operand_add_text; -    parent->export_buffer = (export_buffer_fc)g_x86_mod_rm_operand_to_buffer; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : data = flux de données à analyser.                           * -*                pos  = position courante dans ce flux. [OUT]                 * -*                len  = taille totale des données à analyser.                 * -*                size = taille de l'opérande, et donc du registre.            * -*                                                                             * -*  Description : Crée un opérande x86 de type ModRM.                          * -*                                                                             * -*  Retour      : Opérande mis en place.                                       * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -GArchOperand *g_x86_mod_rm_operand_new(const bin_t *data, off_t *pos, off_t len, MemoryDataSize size) -{ -    GX86ModRMOperand *result;               /* Structure à retourner       */ -    uint8_t mod;                            /* Modificateur présent        */ -    GX86Register *reg;                      /* Registre lu                 */ - -    mod = (data[*pos] & 0xc0); - -    if (mod == 0xc0) -        return g_x86_register_operand_new_from_mod_rm(data, pos, len, size, true); - -    reg = g_x86_register_new(size, data[*pos] & 0x07); -    if (reg == NULL) return NULL; - -    (*pos)++; - -    /* Vieille astuce de l'emplacement mémoire fixe ? */ -    if (g_x86_register_is_base_pointer(reg) && mod == 0x00) -    { -        /* FIXME *///free_x86_register(reg); -        return g_imm_operand_new_from_data(MDS_32_BITS/* FIXME */, data, pos, len, SRE_LITTLE /*FIXME*/); -    } - -    result = g_object_new(G_TYPE_X86_MOD_RM_OPERAND, NULL); - -    /* A la recherche d'un SIB */ -    if (g_x86_register_is_stack_pointer(reg)) -    { -        /* FIXME *///free_x86_register(reg); - -        result->base = g_x86_register_new(size, data[*pos] & 0x07); -        if (result->base == NULL) goto gxmron_error; - -        result->index = g_x86_register_new(size, (data[*pos] & 0x38) >> 3); -        if (result->index == NULL) goto gxmron_error; - -        result->scale = ((data[*pos] & 0xc0) >> 6); - -        if (g_x86_register_is_stack_pointer(result->index)) -        { -            /* FIXME *///free_x86_register(result->index); -            result->index = result->base; -            result->base = NULL; -        } - -        (*pos)++; - -    } - -    else result->index = reg; - -    /* Décallage supplémentaire ? */ -    switch (mod) -    { -        case 0x00: -            if (result->base != NULL && g_x86_register_is_base_pointer(result->base)) -            { -                /* FIXME *///free_x86_register(result->base); -                result->base = NULL; - -                result->displacement = g_imm_operand_new_from_data(size/* FIXME : !convert mds/aos */, data, pos, len, SRE_LITTLE /* FIXME */); -                if (result->displacement == NULL) goto gxmron_error; - -            } -            break; - -        case 0x40: -            result->displacement = g_imm_operand_new_from_data(MDS_8_BITS_SIGNED, data, pos, len, SRE_LITTLE /* FIXME */); -            if (result->displacement == NULL) goto gxmron_error; -            break; - -        case 0x80: -            result->displacement = g_imm_operand_new_from_data(MDS_32_BITS_SIGNED/* FIXME ! 16/32 */, data, pos, len, SRE_LITTLE /* FIXME */); -            if (result->displacement == NULL) goto gxmron_error; -            break; - -    } - -    return G_ARCH_OPERAND(result); - - gxmron_error: - -    /* FIXME free(result);*/ -    return NULL; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand   = opérande à transcrire.                           * -*                options   = options de rendu.                                * -*                rendering = support effectif final des lignes de code.       * -*                stream    = flux ouvert en écriture.                         * -*                                                                             * -*  Description : Ajoute du texte simple à un fichier ouvert en écriture.      * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_x86_mod_rm_operand_add_text(const GX86ModRMOperand *operand, GRenderingOptions *options, MainRendering rendering, FILE *stream) -{ -    GContentExporter *exporter;             /* Autre vision de l'opérande  */ -    char tmp[2];                            /* Echelle en puissance de 2   */ - -    exporter = G_CONTENT_EXPORTER(operand); - -    switch (g_rendering_options_get_syntax(options)) -    { -        case ASX_INTEL: - -            g_content_exporter_insert_text(exporter, stream, "[", 1, RTT_HOOK); - -            if (operand->scale > 0) -            { -                snprintf(tmp, 2, "%d", (int)pow(2, operand->scale));  - -                g_content_exporter_insert_text(exporter, stream, tmp, 1, RTT_IMMEDIATE); - -                g_content_exporter_insert_text(exporter, stream, "*", 1, RTT_SIGNS); - -            } - -            g_content_exporter_add_text(G_CONTENT_EXPORTER(operand->index), -                                        options, rendering, stream); - -            if (operand->base != NULL) -            { -                g_content_exporter_insert_text(exporter, stream, "+", 1, RTT_SIGNS); - -                g_content_exporter_add_text(G_CONTENT_EXPORTER(operand->base), -                                            options, rendering, stream); - -            } - -            if (operand->displacement != NULL) -            { -                if (g_imm_operand_is_negative(operand->displacement)) -                    g_content_exporter_insert_text(exporter, stream, "-", 1, RTT_SIGNS); -                else -                    g_content_exporter_insert_text(exporter, stream, "+", 1, RTT_SIGNS); - -                g_content_exporter_add_text(G_CONTENT_EXPORTER(operand->displacement), -                                            options, rendering, stream); - -            } - -            g_content_exporter_insert_text(exporter, stream, "]", 1, RTT_HOOK); - -            break; - -        case ASX_ATT: - -            /* TODO */ -            g_content_exporter_insert_text(exporter, stream, "[ModRM]", 7, RTT_HOOK); - -            break; - -    } - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = opérande à transcrire.                             * -*                buffer  = espace où placer ledit contenu.                    * -*                options = options de rendu.                                  * -*                                                                             * -*  Description : Ajoute à un tampon GLib le contenu de l'instance spécifiée.  * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_x86_mod_rm_operand_to_buffer(const GX86ModRMOperand *operand, GBufferLine *buffer, GRenderingOptions *options) -{ -    GContentExporter *exporter;             /* Autre vision de l'opérande  */ -    char tmp[2];                            /* Echelle en puissance de 2   */ - -    exporter = G_CONTENT_EXPORTER(operand); - -    switch (g_rendering_options_get_syntax(options)) -    { -        case ASX_INTEL: - -            g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, -                                                  "[", 1, RTT_HOOK); - -            if (operand->scale > 0) -            { -                snprintf(tmp, 2, "%d", (int)pow(2, operand->scale));  - -                g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, -                                                      tmp, 1, RTT_IMMEDIATE); - -                g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, -                                                      "*", 1, RTT_SIGNS); - -            } - -            g_content_exporter_to_buffer(G_CONTENT_EXPORTER(operand->index), buffer, options); - -            if (operand->base != NULL) -            { -                g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, -                                                      "+", 1, RTT_SIGNS); - -                g_content_exporter_to_buffer(G_CONTENT_EXPORTER(operand->base), buffer, options); - -            } - -            if (operand->displacement != NULL) -            { -                if (g_imm_operand_is_negative(operand->displacement)) -                    g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, -                                                          "-", 1, RTT_SIGNS); -                else -                    g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, -                                                          "+", 1, RTT_SIGNS); - -                g_content_exporter_to_buffer(G_CONTENT_EXPORTER(operand->displacement), buffer, options); - -            } - -            g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, -                                                  "]", 1, RTT_HOOK); - -            break; - -        case ASX_ATT: - -            /* TODO */ -            g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, -                                                  "[ModRM]", 7, RTT_HOOK); - -            break; - -    } - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = opérande à consulter.                              * -*                scale   = facteur sous forme de puissance de deux. [OUT      * -*                index   = register principal de l'opérande. [OUT]            * -*                                                                             * -*  Description : Fournit l'indice et l'échelle d'un opérande x86 ModRM.       * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -void g_x86_mod_rm_operand_get_scale_and_index(const GX86ModRMOperand *operand, uint8_t *scale, const GX86Register **index) -{ -    *scale = operand->scale; -    *index = operand->index; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = opérande à consulter.                              * -*                                                                             * -*  Description : Fournit le registre de base d'un opérande x86 ModRM.         * -*                                                                             * -*  Retour      : Registre de base de l'opérande.                              * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -const GX86Register *g_x86_mod_rm_operand_get_base(const GX86ModRMOperand *operand) -{ -    return operand->base; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = opérande à consulter.                              * -*                                                                             * -*  Description : Fournit le décallage supplémentaire d'un opérande x86 ModRM. * -*                                                                             * -*  Retour      : Décallage numérique pour l'opérande.                         * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -const GImmOperand *g_x86_mod_rm_operand_get_displacement(const GX86ModRMOperand *operand) -{ -    return operand->displacement; - -} - - - -/* ---------------------------------------------------------------------------------- */ -/*                           OPERANDES D'ADRESSES RELATIVES                           */ -/* ---------------------------------------------------------------------------------- */ - - -/* Indique le type défini par la GLib pour un opérande x86 d'adresse relative. */ -G_DEFINE_TYPE(GX86RelativeOperand, g_x86_relative_operand, G_TYPE_X86_OPERAND); - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : klass = classe à initialiser.                                * -*                                                                             * -*  Description : Initialise la classe des opérandes x86 d'adresse relative.   * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_x86_relative_operand_class_init(GX86RelativeOperandClass *klass) -{ - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = instance à initialiser.                            * -*                                                                             * -*  Description : Initialise une instance d'opérande x86 d'adresse relative.   * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_x86_relative_operand_init(GX86RelativeOperand *operand) -{ -    GContentExporter *parent;               /* Instance parente            */ - -    parent = G_CONTENT_EXPORTER(operand); - -    parent->add_text = (add_text_fc)g_x86_relative_operand_add_text; -    parent->export_buffer = (export_buffer_fc)g_x86_relative_operand_to_buffer; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : data = flux de données à analyser.                           * -*                pos  = position courante dans ce flux. [OUT]                 * -*                len  = taille totale des données à analyser.                 * -*                size = taille de l'opérande, et donc du registre.            * -*                base = adresse de référence pour le calcul.                  * -*                                                                             * -*  Description : Crée un opérande X86 d'adresse relative.                     * -*                                                                             * -*  Retour      : Opérande mis en place.                                       * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -GArchOperand *g_x86_relative_operand_new(const bin_t *data, off_t *pos, off_t len, MemoryDataSize size, vmpa_t base) -{ -    GX86RelativeOperand *result;            /* Structure à retourner       */ -    off_t init_pos;                         /* Position avant lecture      */ -    int8_t val8;                            /* Valeur sur 8 bits           */ -    int16_t val16;                          /* Valeur sur 16 bits          */ -    int32_t val32;                          /* Valeur sur 32 bits          */ -    vmpa_t address;                         /* Adresse finale visée        */ - -    init_pos = *pos; - -    switch (size) -    { -        case MDS_8_BITS_UNSIGNED: -            read_s8(&val8, data, pos, len, SRE_LITTLE /* FIXME */); -            address = base + (*pos - init_pos) + val8; -            break; -        case MDS_16_BITS_UNSIGNED: -            read_s16(&val16, data, pos, len, SRE_LITTLE /* FIXME */); -            address = base + (*pos - init_pos) + val16; -            break; -        case MDS_32_BITS_UNSIGNED: -            read_s32(&val32, data, pos, len, SRE_LITTLE /* FIXME */); -            address = base + (*pos - init_pos) + val32; -            break; -        default: -            return NULL; -            break; -    } - -    result = g_object_new(G_TYPE_X86_RELATIVE_OPERAND, NULL); -    result->immediate = g_imm_operand_new_from_value(MDS_32_BITS/*FIXME*/, (uint32_t)address/* FIXME */); - -    return G_ARCH_OPERAND(result); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand   = opérande à transcrire.                           * -*                options   = options de rendu.                                * -*                rendering = support effectif final des lignes de code.       * -*                stream    = flux ouvert en écriture.                         * -*                                                                             * -*  Description : Ajoute du texte simple à un fichier ouvert en écriture.      * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_x86_relative_operand_add_text(const GX86RelativeOperand *operand, GRenderingOptions *options, MainRendering rendering, FILE *stream) -{ -    g_content_exporter_add_text(G_CONTENT_EXPORTER(operand->immediate), options, rendering, stream); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = opérande à transcrire.                             * -*                buffer  = espace où placer ledit contenu.                    * -*                options = options de rendu.                                  * -*                                                                             * -*  Description : Ajoute à un tampon GLib le contenu de l'instance spécifiée.  * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_x86_relative_operand_to_buffer(const GX86RelativeOperand *operand, GBufferLine *buffer, GRenderingOptions *options) -{ -    g_content_exporter_to_buffer(G_CONTENT_EXPORTER(operand->immediate), buffer, options); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = opérande à traiter.                                * -*                                                                             * -*  Description : Fournit l'adresse représentée par une opérande X86.          * -*                                                                             * -*  Retour      : Valeur portée par l'opérande.                                * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -const GImmOperand *g_x86_relative_operand_get_value(const GX86RelativeOperand *operand) -{ -    return operand->immediate; - -} - - - -/* ---------------------------------------------------------------------------------- */ -/*                          OPERANDES D'EMPLACEMENTS MEMOIRE                          */ -/* ---------------------------------------------------------------------------------- */ - - -/* Indique le type défini par la GLib pour un opérande d'emplacement mémoire x86. */ -G_DEFINE_TYPE(GX86MOffsOperand, g_x86_moffs_operand, G_TYPE_X86_OPERAND); - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : klass = classe à initialiser.                                * -*                                                                             * -*  Description : Initialise la classe des opérandes d'emplacement mémoire x86.* -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_x86_moffs_operand_class_init(GX86MOffsOperandClass *klass) -{ - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = instance à initialiser.                            * -*                                                                             * -*  Description : Initialise une instance d'opérande d'emplacement mémoire x86.* -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_x86_moffs_operand_init(GX86MOffsOperand *operand) -{ -    GContentExporter *parent;               /* Instance parente            */ - -    parent = G_CONTENT_EXPORTER(operand); - -    parent->add_text = (add_text_fc)g_x86_moffs_operand_add_text; -    parent->export_buffer = (export_buffer_fc)g_x86_moffs_operand_to_buffer; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : data = flux de données à analyser.                           * -*                pos  = position courante dans ce flux. [OUT]                 * -*                len  = taille totale des données à analyser.                 * -*                size = taille de l'opérande, et donc du registre.            * -*                                                                             * -*  Description : Crée un opérande d'emplacement mémoire x86.                  * -*                                                                             * -*  Retour      : Opérande mis en place.                                       * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -GArchOperand *g_x86_moffs_operand_new(const bin_t *data, off_t *pos, off_t len, MemoryDataSize size) -{ -    GX86MOffsOperand *result;               /* Structure à retourner       */ -    GImmOperand *offset;                    /* Emplacement lu              */ - -    result = NULL; - -    offset = g_imm_operand_new_from_data(size, data, pos, len, SRE_LITTLE /* FIXME */); - -    if (offset != NULL) -    { -        result = g_object_new(G_TYPE_X86_MOFFS_OPERAND, NULL); -        result->offset = offset; -    } - -    return G_ARCH_OPERAND(result); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand   = opérande à transcrire.                           * -*                options   = options de rendu.                                * -*                rendering = support effectif final des lignes de code.       * -*                stream    = flux ouvert en écriture.                         * -*                                                                             * -*  Description : Ajoute du texte simple à un fichier ouvert en écriture.      * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_x86_moffs_operand_add_text(const GX86MOffsOperand *operand, GRenderingOptions *options, MainRendering rendering, FILE *stream) -{ -    g_content_exporter_insert_text(G_CONTENT_EXPORTER(operand), stream, "ds:", 3, RTT_SEGMENT); - -    g_content_exporter_add_text(G_CONTENT_EXPORTER(operand->offset), options, rendering, stream); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = opérande à transcrire.                             * -*                buffer  = espace où placer ledit contenu.                    * -*                options = options de rendu.                                  * -*                                                                             * -*  Description : Ajoute à un tampon GLib le contenu de l'instance spécifiée.  * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_x86_moffs_operand_to_buffer(const GX86MOffsOperand *operand, GBufferLine *buffer, GRenderingOptions *options) -{ -    g_content_exporter_insert_into_buffer(G_CONTENT_EXPORTER(operand), buffer, BLC_ASSEMBLY, -                                          "ds:", 3, RTT_SEGMENT); - -    g_content_exporter_to_buffer(G_CONTENT_EXPORTER(operand->offset), buffer, options); - -} - - - -/* ---------------------------------------------------------------------------------- */ -/*                        OPERANDES DE MANIPULATION DE DONNEES                        */ -/* ---------------------------------------------------------------------------------- */ - - -/* Indique le type défini par la GLib pour un opérande x86 de manipulation de données. */ -G_DEFINE_TYPE(GX86DataOperand, g_x86_data_operand, G_TYPE_X86_OPERAND); - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : klass = classe à initialiser.                                * -*                                                                             * -*  Description : Initialise la classe des opérandes x86 pointant des données. * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_x86_data_operand_class_init(GX86DataOperandClass *klass) -{ - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = instance à initialiser.                            * -*                                                                             * -*  Description : Initialise une instance d'opérande pointant des données.     * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_x86_data_operand_init(GX86DataOperand *operand) -{ -    GContentExporter *parent;               /* Instance parente            */ - -    parent = G_CONTENT_EXPORTER(operand); - -    parent->add_text = (add_text_fc)g_x86_data_operand_add_text; -    parent->export_buffer = (export_buffer_fc)g_x86_data_operand_to_buffer; - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : size = taille de l'opérande, et donc du registre.            * -*                dest = indique si la cible est une destination ou une source.* -*                                                                             * -*  Description : Crée un opérande x86 de manipulation de données.             * -*                                                                             * -*  Retour      : Opérande mis en place.                                       * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -GArchOperand *g_x86_data_operand_new(MemoryDataSize size, bool dest) -{ -    GX86DataOperand *result;                /* Structure à retourner       */ - -    result = g_object_new(G_TYPE_X86_DATA_OPERAND, NULL); - -    result->reg = g_x86_register_new(MDS_32_BITS/* FIXME size*/, dest ? 0x07 : 0x06); -    result->dest = dest; - -    return G_ARCH_OPERAND(result); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = opérande à transcrire.                             * -*                options   = options de rendu.                                * -*                rendering = support effectif final des lignes de code.       * -*                stream    = flux ouvert en écriture.                         * -*                                                                             * -*  Description : Ajoute du texte simple à un fichier ouvert en écriture.      * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_x86_data_operand_add_text(const GX86DataOperand *operand, GRenderingOptions *options, MainRendering rendering, FILE *stream) -{ -    GContentExporter *exporter;             /* Autre vision de l'opérande  */ - -    exporter = G_CONTENT_EXPORTER(operand); - -    if (operand->dest) -        g_content_exporter_insert_text(exporter, stream, "es:", 3, RTT_SEGMENT); -    else -        g_content_exporter_insert_text(exporter, stream, "ds:", 3, RTT_SEGMENT); - -    g_content_exporter_insert_text(exporter, stream, "[", 1, RTT_HOOK); - -    g_content_exporter_add_text(G_CONTENT_EXPORTER(operand->reg), options, rendering, stream); - -    g_content_exporter_insert_text(exporter, stream, "]", 1, RTT_HOOK); - -} - - -/****************************************************************************** -*                                                                             * -*  Paramètres  : operand = opérande à transcrire.                             * -*                buffer  = espace où placer ledit contenu.                    * -*                options = options de rendu.                                  * -*                                                                             * -*  Description : Ajoute à un tampon GLib le contenu de l'instance spécifiée.  * -*                                                                             * -*  Retour      : -                                                            * -*                                                                             * -*  Remarques   : -                                                            * -*                                                                             * -******************************************************************************/ - -static void g_x86_data_operand_to_buffer(const GX86DataOperand *operand, GBufferLine *buffer, GRenderingOptions *options) -{ -    GContentExporter *exporter;             /* Autre vision de l'opérande  */ - -    exporter = G_CONTENT_EXPORTER(operand); - -    if (operand->dest) -        g_content_exporter_insert_into_buffer(G_CONTENT_EXPORTER(operand), buffer, BLC_ASSEMBLY, -                                              "es:", 3, RTT_SEGMENT); -    else -        g_content_exporter_insert_into_buffer(G_CONTENT_EXPORTER(operand), buffer, BLC_ASSEMBLY, -                                              "ds:", 3, RTT_SEGMENT); - -    g_content_exporter_insert_into_buffer(G_CONTENT_EXPORTER(operand), buffer, BLC_ASSEMBLY, -                                          "[", 1, RTT_HOOK); - -    g_content_exporter_to_buffer(G_CONTENT_EXPORTER(operand->reg), buffer, options); - -    g_content_exporter_insert_into_buffer(G_CONTENT_EXPORTER(operand), buffer, BLC_ASSEMBLY, -                                          "]", 1, RTT_HOOK); - -} - - - -/* ---------------------------------------------------------------------------------- */ -/*                           AIDE A LA CREATION D'OPERANDES                           */ -/* ---------------------------------------------------------------------------------- */ -  /******************************************************************************  *                                                                             * diff --git a/src/arch/x86/operand.h b/src/arch/x86/operand.h index 17d8844..01a12c5 100644 --- a/src/arch/x86/operand.h +++ b/src/arch/x86/operand.h @@ -28,174 +28,15 @@  #include <stdbool.h> -#include "../immediate.h" +#include "operands/data.h" +#include "operands/modrm.h" +#include "operands/moffs.h" +#include "operands/register.h" +#include "operands/relative.h"  #include "../instruction.h" -#include "registers.h" -/* ---------------------- COQUILLE VIDE POUR LES OPERANDES X86 ---------------------- */ - - -#define G_TYPE_X86_OPERAND                  g_x86_operand_get_type() -#define G_X86_OPERAND(obj)                  (G_TYPE_CHECK_INSTANCE_CAST((obj), g_x86_operand_get_type(), GX86Operand)) -#define G_IS_X86_OPERAND(obj)               (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_x86_operand_get_type())) -#define G_X86_OPERAND_GET_IFACE(inst)       (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_x86_operand_get_type(), GX86OperandIface)) - - -/* Définition d'un opérande de x86 (instance) */ -typedef struct _GX86Operand GX86Operand; - -/* Définition d'un opérande de x86 (classe) */ -typedef struct _GX86OperandClass GX86OperandClass; - - -/* Indique le type défini par la GLib pour un opérande de x86. */ -GType g_x86_operand_get_type(void); - - - -/* ------------------------ OPERANDES VISANT UN REGISTRE X86 ------------------------ */ - - -#define G_TYPE_X86_REGISTER_OPERAND                  g_x86_register_operand_get_type() -#define G_X86_REGISTER_OPERAND(obj)                  (G_TYPE_CHECK_INSTANCE_CAST((obj), g_x86_register_operand_get_type(), GX86RegisterOperand)) -#define G_IS_X86_REGISTER_OPERAND(obj)               (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_x86_register_operand_get_type())) -#define G_X86_REGISTER_OPERAND_GET_IFACE(inst)       (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_x86_register_operand_get_type(), GX86RegisterOperandIface)) - - -/* Définition d'un opérande visant un registre x86 (instance) */ -typedef struct _GX86RegisterOperand GX86RegisterOperand; - -/* Définition d'un opérande visant un registre x86 (classe) */ -typedef struct _GX86RegisterOperandClass GX86RegisterOperandClass; - - -/* Indique le type défini par la GLib pour un opérande de registre x86. */ -GType g_x86_register_operand_get_type(void); - -/* Crée un opérande visant un registre x86. */ -GArchOperand *g_x86_register_operand_new_from_opcode(const bin_t *, off_t *, off_t, MemoryDataSize, bin_t); - -/* Crée un opérande visant un registre x86. */ -GArchOperand *g_x86_register_operand_new_from_mod_rm(const bin_t *, off_t *, off_t, MemoryDataSize, bool); - -/* Crée un opérande visant un registre x86 donné. */ -GArchOperand *g_x86_register_operand_new_from_index(bin_t, MemoryDataSize); - - - -/* ----------------------- OPERANDES COMPLEXES DE TYPE MOD/RM ----------------------- */ - - -#define G_TYPE_X86_MOD_RM_OPERAND                  g_x86_mod_rm_operand_get_type() -#define G_X86_MOD_RM_OPERAND(obj)                  (G_TYPE_CHECK_INSTANCE_CAST((obj), g_x86_mod_rm_operand_get_type(), GX86ModRMOperand)) -#define G_IS_X86_MOD_RM_OPERAND(obj)               (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_x86_mod_rm_operand_get_type())) -#define G_X86_MOD_RM_OPERAND_GET_IFACE(inst)       (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_x86_mod_rm_operand_get_type(), GX86ModRMOperandIface)) - - -/* Définition d'un opérande x86 de type ModRM (instance) */ -typedef struct _GX86ModRMOperand GX86ModRMOperand; - -/* Définition d'un opérande x86 de type ModRM (classe) */ -typedef struct _GX86ModRMOperandClass GX86ModRMOperandClass; - - -/* Indique le type défini par la GLib pour un opérande x86 de type ModRM. */ -GType g_x86_mod_rm_operand_get_type(void); - -/* Crée un opérande x86 de type ModRM. */ -GArchOperand *g_x86_mod_rm_operand_new(const bin_t *, off_t *, off_t, MemoryDataSize); - -/* Fournit l'indice et l'échelle d'un opérande x86 ModRM. */ -void g_x86_mod_rm_operand_get_scale_and_index(const GX86ModRMOperand *operand, uint8_t *, const GX86Register **); - -/* Fournit le registre de base d'un opérande x86 ModRM. */ -const GX86Register *g_x86_mod_rm_operand_get_base(const GX86ModRMOperand *); - -/* Fournit le décallage supplémentaire d'un opérande x86 ModRM. */ -const GImmOperand *g_x86_mod_rm_operand_get_displacement(const GX86ModRMOperand *); - - - -/* ------------------------- OPERANDES D'ADRESSES RELATIVES ------------------------- */ - - -#define G_TYPE_X86_RELATIVE_OPERAND                  g_x86_relative_operand_get_type() -#define G_X86_RELATIVE_OPERAND(obj)                  (G_TYPE_CHECK_INSTANCE_CAST((obj), g_x86_relative_operand_get_type(), GX86RelativeOperand)) -#define G_IS_X86_RELATIVE_OPERAND(obj)               (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_x86_relative_operand_get_type())) -#define G_X86_RELATIVE_OPERAND_GET_IFACE(inst)       (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_x86_relative_operand_get_type(), GX86RelativeOperandIface)) - - -/* Définition d'un opérande x86 d'adresse relative (instance) */ -typedef struct _GX86RelativeOperand GX86RelativeOperand; - -/* Définition d'un opérande x86 d'adresse relative (classe) */ -typedef struct _GX86RelativeOperandClass GX86RelativeOperandClass; - - -/* Indique le type défini par la GLib pour un opérande x86 d'adresse relative. */ -GType g_x86_relative_operand_get_type(void); - -/* Crée un opérande X86 d'adresse relative. */ -GArchOperand *g_x86_relative_operand_new(const bin_t *, off_t *, off_t, MemoryDataSize, vmpa_t); - -/* Fournit l'adresse représentée par une opérande X86. */ -const GImmOperand *g_x86_relative_operand_get_value(const GX86RelativeOperand *); - - - -/* ------------------------ OPERANDES D'EMPLACEMENTS MEMOIRE ------------------------ */ - - -#define G_TYPE_X86_MOFFS_OPERAND                  g_x86_moffs_operand_get_type() -#define G_X86_MOFFS_OPERAND(obj)                  (G_TYPE_CHECK_INSTANCE_CAST((obj), g_x86_moffs_operand_get_type(), GX86MoffsOperand)) -#define G_IS_X86_MOFFS_OPERAND(obj)               (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_x86_moffs_operand_get_type())) -#define G_X86_MOFFS_OPERAND_GET_IFACE(inst)       (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_x86_moffs_operand_get_type(), GX86MoffsOperandIface)) - - -/* Définition d'un opérande visant un emplacement mémoire x86 (instance) */ -typedef struct _GX86MOffsOperand GX86MOffsOperand; - -/* Définition d'un opérande visant un emplacement mémoire x86 (classe) */ -typedef struct _GX86MOffsOperandClass GX86MOffsOperandClass; - - -/* Indique le type défini par la GLib pour un opérande d'emplacement mémoire x86. */ -GType g_x86_moffs_operand_get_type(void); - -/* Crée un opérande d'emplacement mémoire x86. */ -GArchOperand *g_x86_moffs_operand_new(const bin_t *, off_t *, off_t, MemoryDataSize); - - - -/* ---------------------- OPERANDES DE MANIPULATION DE DONNEES ---------------------- */ - - -#define G_TYPE_X86_DATA_OPERAND                  g_x86_data_operand_get_type() -#define G_X86_DATA_OPERAND(obj)                  (G_TYPE_CHECK_INSTANCE_CAST((obj), g_x86_data_operand_get_type(), GX86DataOperand)) -#define G_IS_X86_DATA_OPERAND(obj)               (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_x86_data_operand_get_type())) -#define G_X86_DATA_OPERAND_GET_IFACE(inst)       (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_x86_data_operand_get_type(), GX86DataOperandIface)) - - -/* Définition d'un opérande x86 de manipulation de données (instance) */ -typedef struct _GX86DataOperand GX86DataOperand; - -/* Définition d'un opérande x86 de manipulation de données (classe) */ -typedef struct _GX86DataOperandClass GX86DataOperandClass; - - -/* Indique le type défini par la GLib pour un opérande x86 de manipulation de données. */ -GType g_x86_data_operand_get_type(void); - -/* Crée un opérande x86 de manipulation de données. */ -GArchOperand *g_x86_data_operand_new(MemoryDataSize, bool); - - - -/* ------------------------- AIDE A LA CREATION D'OPERANDES ------------------------- */ - -  /* Construction d'identifiants typés */  #define X86_OTP_IMM_TYPE    0x8000 diff --git a/src/arch/x86/operands/Makefile.am b/src/arch/x86/operands/Makefile.am new file mode 100644 index 0000000..ac48667 --- /dev/null +++ b/src/arch/x86/operands/Makefile.am @@ -0,0 +1,21 @@ + +noinst_LTLIBRARIES = libarchx86operands.la + +libarchx86operands_la_SOURCES =			\ +	data.h data.c						\ +	modrm.h modrm.c						\ +	moffs.h moffs.c						\ +	register.h register.c				\ +	relative.h relative.c + +libarchx86_la_CFLAGS = $(AM_CFLAGS) + + +INCLUDES = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) + +AM_CPPFLAGS =  + +AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS) $(COMPLIANCE_FLAGS) + + +SUBDIRS =  diff --git a/src/arch/x86/operands/data.c b/src/arch/x86/operands/data.c new file mode 100644 index 0000000..22f16b7 --- /dev/null +++ b/src/arch/x86/operands/data.c @@ -0,0 +1,207 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * data.c - opérandes de manipulation de données + * + * Copyright (C) 2012 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 "data.h" + + +#include "../registers.h" +#include "../../operand-int.h" + + + +/* Définition d'un opérande x86 de manipulation de données (instance) */ +struct _GX86DataOperand +{ +    GArchOperand parent;                    /* Instance parente            */ + +    GX86Register *reg;                      /* Registre représenté         */ +    bool dest;                              /* Déduction du type de segment*/ + +}; + +/* Définition d'un opérande x86 de manipulation de données (classe) */ +struct _GX86DataOperandClass +{ +    GArchOperandClass parent;               /* Classe parente              */ + +}; + + +/* Initialise la classe des opérandes x86 pointant des données. */ +static void g_x86_data_operand_class_init(GX86DataOperandClass *); + +/* Initialise une instance d'opérande x86 pointant des données. */ +static void g_x86_data_operand_init(GX86DataOperand *); + +/* Ajoute du texte simple à un fichier ouvert en écriture. */ +static void g_x86_data_operand_add_text(const GX86DataOperand *, GRenderingOptions *, MainRendering, FILE *); + +/* Ajoute à un tampon GLib le contenu de l'instance spécifiée. */ +static void g_x86_data_operand_to_buffer(const GX86DataOperand *, GBufferLine *, GRenderingOptions *); + + + +/* Indique le type défini par la GLib pour un opérande x86 de manipulation de données. */ +G_DEFINE_TYPE(GX86DataOperand, g_x86_data_operand, G_TYPE_ARCH_OPERAND); + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : klass = classe à initialiser.                                * +*                                                                             * +*  Description : Initialise la classe des opérandes x86 pointant des données. * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_x86_data_operand_class_init(GX86DataOperandClass *klass) +{ + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = instance à initialiser.                            * +*                                                                             * +*  Description : Initialise une instance d'opérande pointant des données.     * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_x86_data_operand_init(GX86DataOperand *operand) +{ +    GContentExporter *parent;               /* Instance parente            */ + +    parent = G_CONTENT_EXPORTER(operand); + +    parent->add_text = (add_text_fc)g_x86_data_operand_add_text; +    parent->export_buffer = (export_buffer_fc)g_x86_data_operand_to_buffer; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : size = taille de l'opérande, et donc du registre.            * +*                dest = indique si la cible est une destination ou une source.* +*                                                                             * +*  Description : Crée un opérande x86 de manipulation de données.             * +*                                                                             * +*  Retour      : Opérande mis en place.                                       * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GArchOperand *g_x86_data_operand_new(MemoryDataSize size, bool dest) +{ +    GX86DataOperand *result;                /* Structure à retourner       */ + +    result = g_object_new(G_TYPE_X86_DATA_OPERAND, NULL); + +    result->reg = g_x86_register_new(MDS_32_BITS/* FIXME size*/, dest ? 0x07 : 0x06); +    result->dest = dest; + +    return G_ARCH_OPERAND(result); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = opérande à transcrire.                             * +*                options   = options de rendu.                                * +*                rendering = support effectif final des lignes de code.       * +*                stream    = flux ouvert en écriture.                         * +*                                                                             * +*  Description : Ajoute du texte simple à un fichier ouvert en écriture.      * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_x86_data_operand_add_text(const GX86DataOperand *operand, GRenderingOptions *options, MainRendering rendering, FILE *stream) +{ +    GContentExporter *exporter;             /* Autre vision de l'opérande  */ + +    exporter = G_CONTENT_EXPORTER(operand); + +    if (operand->dest) +        g_content_exporter_insert_text(exporter, stream, "es:", 3, RTT_SEGMENT); +    else +        g_content_exporter_insert_text(exporter, stream, "ds:", 3, RTT_SEGMENT); + +    g_content_exporter_insert_text(exporter, stream, "[", 1, RTT_HOOK); + +    g_content_exporter_add_text(G_CONTENT_EXPORTER(operand->reg), options, rendering, stream); + +    g_content_exporter_insert_text(exporter, stream, "]", 1, RTT_HOOK); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = opérande à transcrire.                             * +*                buffer  = espace où placer ledit contenu.                    * +*                options = options de rendu.                                  * +*                                                                             * +*  Description : Ajoute à un tampon GLib le contenu de l'instance spécifiée.  * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_x86_data_operand_to_buffer(const GX86DataOperand *operand, GBufferLine *buffer, GRenderingOptions *options) +{ +    GContentExporter *exporter;             /* Autre vision de l'opérande  */ + +    exporter = G_CONTENT_EXPORTER(operand); + +    if (operand->dest) +        g_content_exporter_insert_into_buffer(G_CONTENT_EXPORTER(operand), buffer, BLC_ASSEMBLY, +                                              "es:", 3, RTT_SEGMENT); +    else +        g_content_exporter_insert_into_buffer(G_CONTENT_EXPORTER(operand), buffer, BLC_ASSEMBLY, +                                              "ds:", 3, RTT_SEGMENT); + +    g_content_exporter_insert_into_buffer(G_CONTENT_EXPORTER(operand), buffer, BLC_ASSEMBLY, +                                          "[", 1, RTT_HOOK); + +    g_content_exporter_to_buffer(G_CONTENT_EXPORTER(operand->reg), buffer, options); + +    g_content_exporter_insert_into_buffer(G_CONTENT_EXPORTER(operand), buffer, BLC_ASSEMBLY, +                                          "]", 1, RTT_HOOK); + +} diff --git a/src/arch/x86/operands/data.h b/src/arch/x86/operands/data.h new file mode 100644 index 0000000..406698e --- /dev/null +++ b/src/arch/x86/operands/data.h @@ -0,0 +1,60 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * data.h - prototypes pour les opérandes de manipulation de données + * + * Copyright (C) 2012 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 _ARCH_X86_OPERANDS_DATA_H +#define _ARCH_X86_OPERANDS_DATA_H + + +#include <glib-object.h> + + +#include "../../operand.h" +#include "../../../common/endianness.h" + + + +#define G_TYPE_X86_DATA_OPERAND                  g_x86_data_operand_get_type() +#define G_X86_DATA_OPERAND(obj)                  (G_TYPE_CHECK_INSTANCE_CAST((obj), g_x86_data_operand_get_type(), GX86DataOperand)) +#define G_IS_X86_DATA_OPERAND(obj)               (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_x86_data_operand_get_type())) +#define G_X86_DATA_OPERAND_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_X86_DATA_OPERAND, GX86DataOperandClass)) +#define G_IS_X86_DATA_OPERAND_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_X86_DATA_OPERAND)) +#define G_X86_DATA_OPERAND_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_X86_DATA_OPERAND, GX86DataOperandClass)) + + + +/* Définition d'un opérande x86 de manipulation de données (instance) */ +typedef struct _GX86DataOperand GX86DataOperand; + +/* Définition d'un opérande x86 de manipulation de données (classe) */ +typedef struct _GX86DataOperandClass GX86DataOperandClass; + + +/* Indique le type défini par la GLib pour un opérande x86 de manipulation de données. */ +GType g_x86_data_operand_get_type(void); + +/* Crée un opérande x86 de manipulation de données. */ +GArchOperand *g_x86_data_operand_new(MemoryDataSize, bool); + + + +#endif  /* _ARCH_X86_OPERANDS_DATA_H */ diff --git a/src/arch/x86/operands/modrm.c b/src/arch/x86/operands/modrm.c new file mode 100644 index 0000000..892d5dc --- /dev/null +++ b/src/arch/x86/operands/modrm.c @@ -0,0 +1,436 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * modrm.c - opérandes de type mod/rm + * + * Copyright (C) 2012 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 "modrm.h" + + +#include <math.h> + + +#include "register.h" +#include "../../operand-int.h" + + + +/* Définition d'un opérande x86 de type ModRM (instance) */ +struct _GX86ModRMOperand +{ +    GArchOperand parent;                    /* Instance parente            */ + +    uint8_t scale;                          /* Puissance de deux           */ +    GX86Register *index;                    /* Registre servant d'indice   */ +    GX86Register *base;                     /* Registre de base            */ +    GImmOperand *displacement;              /* Décallage supplémentaire    */ + +}; + + +/* Définition d'un opérande x86 de type ModRM (classe) */ +struct _GX86ModRMOperandClass +{ +    GArchOperandClass parent;               /* Classe parente              */ + +}; + + +/* Initialise la classe des opérandes x86 de type ModRM. */ +static void g_x86_mod_rm_operand_class_init(GX86ModRMOperandClass *); + +/* Initialise une instance d'opérande x86 de type ModRM. */ +static void g_x86_mod_rm_operand_init(GX86ModRMOperand *); + +/* Ajoute du texte simple à un fichier ouvert en écriture. */ +static void g_x86_mod_rm_operand_add_text(const GX86ModRMOperand *, GRenderingOptions *, MainRendering, FILE *); + +/* Ajoute à un tampon GLib le contenu de l'instance spécifiée. */ +static void g_x86_mod_rm_operand_to_buffer(const GX86ModRMOperand *, GBufferLine *, GRenderingOptions *); + + + +/* Indique le type défini par la GLib pour un opérande x86 de type ModRM. */ +G_DEFINE_TYPE(GX86ModRMOperand, g_x86_mod_rm_operand, G_TYPE_ARCH_OPERAND); + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : klass = classe à initialiser.                                * +*                                                                             * +*  Description : Initialise la classe des opérandes x86 de type ModRM.        * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_x86_mod_rm_operand_class_init(GX86ModRMOperandClass *klass) +{ + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = instance à initialiser.                            * +*                                                                             * +*  Description : Initialise une instance d'opérande x86 de type ModRM.        * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_x86_mod_rm_operand_init(GX86ModRMOperand *operand) +{ +    GContentExporter *parent;               /* Instance parente            */ + +    parent = G_CONTENT_EXPORTER(operand); + +    parent->add_text = (add_text_fc)g_x86_mod_rm_operand_add_text; +    parent->export_buffer = (export_buffer_fc)g_x86_mod_rm_operand_to_buffer; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                size = taille de l'opérande, et donc du registre.            * +*                                                                             * +*  Description : Crée un opérande x86 de type ModRM.                          * +*                                                                             * +*  Retour      : Opérande mis en place.                                       * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GArchOperand *g_x86_mod_rm_operand_new(const bin_t *data, off_t *pos, off_t len, MemoryDataSize size) +{ +    GX86ModRMOperand *result;               /* Structure à retourner       */ +    uint8_t mod;                            /* Modificateur présent        */ +    GX86Register *reg;                      /* Registre lu                 */ + +    mod = (data[*pos] & 0xc0); + +    if (mod == 0xc0) +        return g_x86_register_operand_new_from_mod_rm(data, pos, len, size, true); + +    reg = g_x86_register_new(size, data[*pos] & 0x07); +    if (reg == NULL) return NULL; + +    (*pos)++; + +    /* Vieille astuce de l'emplacement mémoire fixe ? */ +    if (g_x86_register_is_base_pointer(reg) && mod == 0x00) +    { +        /* FIXME *///free_x86_register(reg); +        return g_imm_operand_new_from_data(MDS_32_BITS/* FIXME */, data, pos, len, SRE_LITTLE /*FIXME*/); +    } + +    result = g_object_new(G_TYPE_X86_MOD_RM_OPERAND, NULL); + +    /* A la recherche d'un SIB */ +    if (g_x86_register_is_stack_pointer(reg)) +    { +        /* FIXME *///free_x86_register(reg); + +        result->base = g_x86_register_new(size, data[*pos] & 0x07); +        if (result->base == NULL) goto gxmron_error; + +        result->index = g_x86_register_new(size, (data[*pos] & 0x38) >> 3); +        if (result->index == NULL) goto gxmron_error; + +        result->scale = ((data[*pos] & 0xc0) >> 6); + +        if (g_x86_register_is_stack_pointer(result->index)) +        { +            /* FIXME *///free_x86_register(result->index); +            result->index = result->base; +            result->base = NULL; +        } + +        (*pos)++; + +    } + +    else result->index = reg; + +    /* Décallage supplémentaire ? */ +    switch (mod) +    { +        case 0x00: +            if (result->base != NULL && g_x86_register_is_base_pointer(result->base)) +            { +                /* FIXME *///free_x86_register(result->base); +                result->base = NULL; + +                result->displacement = g_imm_operand_new_from_data(size/* FIXME : !convert mds/aos */, data, pos, len, SRE_LITTLE /* FIXME */); +                if (result->displacement == NULL) goto gxmron_error; + +            } +            break; + +        case 0x40: +            result->displacement = g_imm_operand_new_from_data(MDS_8_BITS_SIGNED, data, pos, len, SRE_LITTLE /* FIXME */); +            if (result->displacement == NULL) goto gxmron_error; +            break; + +        case 0x80: +            result->displacement = g_imm_operand_new_from_data(MDS_32_BITS_SIGNED/* FIXME ! 16/32 */, data, pos, len, SRE_LITTLE /* FIXME */); +            if (result->displacement == NULL) goto gxmron_error; +            break; + +    } + +    return G_ARCH_OPERAND(result); + + gxmron_error: + +    /* FIXME free(result);*/ +    return NULL; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand   = opérande à transcrire.                           * +*                options   = options de rendu.                                * +*                rendering = support effectif final des lignes de code.       * +*                stream    = flux ouvert en écriture.                         * +*                                                                             * +*  Description : Ajoute du texte simple à un fichier ouvert en écriture.      * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_x86_mod_rm_operand_add_text(const GX86ModRMOperand *operand, GRenderingOptions *options, MainRendering rendering, FILE *stream) +{ +    GContentExporter *exporter;             /* Autre vision de l'opérande  */ +    char tmp[2];                            /* Echelle en puissance de 2   */ + +    exporter = G_CONTENT_EXPORTER(operand); + +    switch (g_rendering_options_get_syntax(options)) +    { +        case ASX_INTEL: + +            g_content_exporter_insert_text(exporter, stream, "[", 1, RTT_HOOK); + +            if (operand->scale > 0) +            { +                snprintf(tmp, 2, "%d", (int)pow(2, operand->scale));  + +                g_content_exporter_insert_text(exporter, stream, tmp, 1, RTT_IMMEDIATE); + +                g_content_exporter_insert_text(exporter, stream, "*", 1, RTT_SIGNS); + +            } + +            g_content_exporter_add_text(G_CONTENT_EXPORTER(operand->index), +                                        options, rendering, stream); + +            if (operand->base != NULL) +            { +                g_content_exporter_insert_text(exporter, stream, "+", 1, RTT_SIGNS); + +                g_content_exporter_add_text(G_CONTENT_EXPORTER(operand->base), +                                            options, rendering, stream); + +            } + +            if (operand->displacement != NULL) +            { +                if (g_imm_operand_is_negative(operand->displacement)) +                    g_content_exporter_insert_text(exporter, stream, "-", 1, RTT_SIGNS); +                else +                    g_content_exporter_insert_text(exporter, stream, "+", 1, RTT_SIGNS); + +                g_content_exporter_add_text(G_CONTENT_EXPORTER(operand->displacement), +                                            options, rendering, stream); + +            } + +            g_content_exporter_insert_text(exporter, stream, "]", 1, RTT_HOOK); + +            break; + +        case ASX_ATT: + +            /* TODO */ +            g_content_exporter_insert_text(exporter, stream, "[ModRM]", 7, RTT_HOOK); + +            break; + +    } + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = opérande à transcrire.                             * +*                buffer  = espace où placer ledit contenu.                    * +*                options = options de rendu.                                  * +*                                                                             * +*  Description : Ajoute à un tampon GLib le contenu de l'instance spécifiée.  * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_x86_mod_rm_operand_to_buffer(const GX86ModRMOperand *operand, GBufferLine *buffer, GRenderingOptions *options) +{ +    GContentExporter *exporter;             /* Autre vision de l'opérande  */ +    char tmp[2];                            /* Echelle en puissance de 2   */ + +    exporter = G_CONTENT_EXPORTER(operand); + +    switch (g_rendering_options_get_syntax(options)) +    { +        case ASX_INTEL: + +            g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, +                                                  "[", 1, RTT_HOOK); + +            if (operand->scale > 0) +            { +                snprintf(tmp, 2, "%d", (int)pow(2, operand->scale));  + +                g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, +                                                      tmp, 1, RTT_IMMEDIATE); + +                g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, +                                                      "*", 1, RTT_SIGNS); + +            } + +            g_content_exporter_to_buffer(G_CONTENT_EXPORTER(operand->index), buffer, options); + +            if (operand->base != NULL) +            { +                g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, +                                                      "+", 1, RTT_SIGNS); + +                g_content_exporter_to_buffer(G_CONTENT_EXPORTER(operand->base), buffer, options); + +            } + +            if (operand->displacement != NULL) +            { +                if (g_imm_operand_is_negative(operand->displacement)) +                    g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, +                                                          "-", 1, RTT_SIGNS); +                else +                    g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, +                                                          "+", 1, RTT_SIGNS); + +                g_content_exporter_to_buffer(G_CONTENT_EXPORTER(operand->displacement), buffer, options); + +            } + +            g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, +                                                  "]", 1, RTT_HOOK); + +            break; + +        case ASX_ATT: + +            /* TODO */ +            g_content_exporter_insert_into_buffer(exporter, buffer, BLC_ASSEMBLY, +                                                  "[ModRM]", 7, RTT_HOOK); + +            break; + +    } + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = opérande à consulter.                              * +*                scale   = facteur sous forme de puissance de deux. [OUT      * +*                index   = register principal de l'opérande. [OUT]            * +*                                                                             * +*  Description : Fournit l'indice et l'échelle d'un opérande x86 ModRM.       * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +void g_x86_mod_rm_operand_get_scale_and_index(const GX86ModRMOperand *operand, uint8_t *scale, const GX86Register **index) +{ +    *scale = operand->scale; +    *index = operand->index; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = opérande à consulter.                              * +*                                                                             * +*  Description : Fournit le registre de base d'un opérande x86 ModRM.         * +*                                                                             * +*  Retour      : Registre de base de l'opérande.                              * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +const GX86Register *g_x86_mod_rm_operand_get_base(const GX86ModRMOperand *operand) +{ +    return operand->base; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = opérande à consulter.                              * +*                                                                             * +*  Description : Fournit le décallage supplémentaire d'un opérande x86 ModRM. * +*                                                                             * +*  Retour      : Décallage numérique pour l'opérande.                         * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +const GImmOperand *g_x86_mod_rm_operand_get_displacement(const GX86ModRMOperand *operand) +{ +    return operand->displacement; + +} diff --git a/src/arch/x86/operands/modrm.h b/src/arch/x86/operands/modrm.h new file mode 100644 index 0000000..89a274f --- /dev/null +++ b/src/arch/x86/operands/modrm.h @@ -0,0 +1,70 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * modrm.h - prototypes pour les opérandes de type mod/rm + * + * Copyright (C) 2012 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 _ARCH_X86_OPERANDS_MODRM_H +#define _ARCH_X86_OPERANDS_MODRM_H + + +#include <glib-object.h> + + +#include "../registers.h" +#include "../../immediate.h" +#include "../../operand.h" +#include "../../../common/endianness.h" + + + +#define G_TYPE_X86_MOD_RM_OPERAND                  g_x86_mod_rm_operand_get_type() +#define G_X86_MOD_RM_OPERAND(obj)                  (G_TYPE_CHECK_INSTANCE_CAST((obj), g_x86_mod_rm_operand_get_type(), GX86ModRMOperand)) +#define G_IS_X86_MOD_RM_OPERAND(obj)               (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_x86_mod_rm_operand_get_type())) +#define G_X86_MOD_RM_OPERAND_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_X86_MOD_RM_OPERAND, GX86ModRMOperandClass)) +#define G_IS_X86_MOD_RM_OPERAND_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_X86_MOD_RM_OPERAND)) +#define G_X86_MOD_RM_OPERAND_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_X86_MOD_RM_OPERAND, GX86ModRMOperandClass)) + + +/* Définition d'un opérande x86 de type ModRM (instance) */ +typedef struct _GX86ModRMOperand GX86ModRMOperand; + +/* Définition d'un opérande x86 de type ModRM (classe) */ +typedef struct _GX86ModRMOperandClass GX86ModRMOperandClass; + + +/* Indique le type défini par la GLib pour un opérande x86 de type ModRM. */ +GType g_x86_mod_rm_operand_get_type(void); + +/* Crée un opérande x86 de type ModRM. */ +GArchOperand *g_x86_mod_rm_operand_new(const bin_t *, off_t *, off_t, MemoryDataSize); + +/* Fournit l'indice et l'échelle d'un opérande x86 ModRM. */ +void g_x86_mod_rm_operand_get_scale_and_index(const GX86ModRMOperand *operand, uint8_t *, const GX86Register **); + +/* Fournit le registre de base d'un opérande x86 ModRM. */ +const GX86Register *g_x86_mod_rm_operand_get_base(const GX86ModRMOperand *); + +/* Fournit le décallage supplémentaire d'un opérande x86 ModRM. */ +const GImmOperand *g_x86_mod_rm_operand_get_displacement(const GX86ModRMOperand *); + + + +#endif  /* _ARCH_X86_OPERANDS_MODRM_H */ diff --git a/src/arch/x86/operands/moffs.c b/src/arch/x86/operands/moffs.c new file mode 100644 index 0000000..3754e79 --- /dev/null +++ b/src/arch/x86/operands/moffs.c @@ -0,0 +1,189 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * moffs.c - opérandes d'emplacements mémoire + * + * Copyright (C) 2012 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 "moffs.h" + + +#include "../../immediate.h" +#include "../../operand-int.h" + + + +/* Définition d'un opérande visant un emplacement mémoire x86 (instance) */ +struct _GX86MOffsOperand +{ +    GArchOperand parent;                    /* Instance parente            */ + +    GImmOperand *offset;                    /* Adresse mémoire visée       */ + +}; + +/* Définition d'un opérande visant un emplacement mémoire x86 (classe) */ +struct _GX86MOffsOperandClass +{ +    GArchOperandClass parent;               /* Classe parente              */ + +}; + + +/* Initialise la classe des opérandes d'emplacement mémoire x86. */ +static void g_x86_moffs_operand_class_init(GX86MOffsOperandClass *); + +/* Initialise une instance d'opérande d'emplacement mémoire x86. */ +static void g_x86_moffs_operand_init(GX86MOffsOperand *); + +/* Ajoute du texte simple à un fichier ouvert en écriture. */ +static void g_x86_moffs_operand_add_text(const GX86MOffsOperand *, GRenderingOptions *, MainRendering, FILE *); + +/* Ajoute à un tampon GLib le contenu de l'instance spécifiée. */ +static void g_x86_moffs_operand_to_buffer(const GX86MOffsOperand *, GBufferLine *, GRenderingOptions *); + + + +/* Indique le type défini par la GLib pour un opérande d'emplacement mémoire x86. */ +G_DEFINE_TYPE(GX86MOffsOperand, g_x86_moffs_operand, G_TYPE_ARCH_OPERAND); + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : klass = classe à initialiser.                                * +*                                                                             * +*  Description : Initialise la classe des opérandes d'emplacement mémoire x86.* +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_x86_moffs_operand_class_init(GX86MOffsOperandClass *klass) +{ + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = instance à initialiser.                            * +*                                                                             * +*  Description : Initialise une instance d'opérande d'emplacement mémoire x86.* +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_x86_moffs_operand_init(GX86MOffsOperand *operand) +{ +    GContentExporter *parent;               /* Instance parente            */ + +    parent = G_CONTENT_EXPORTER(operand); + +    parent->add_text = (add_text_fc)g_x86_moffs_operand_add_text; +    parent->export_buffer = (export_buffer_fc)g_x86_moffs_operand_to_buffer; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                size = taille de l'opérande, et donc du registre.            * +*                                                                             * +*  Description : Crée un opérande d'emplacement mémoire x86.                  * +*                                                                             * +*  Retour      : Opérande mis en place.                                       * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GArchOperand *g_x86_moffs_operand_new(const bin_t *data, off_t *pos, off_t len, MemoryDataSize size) +{ +    GX86MOffsOperand *result;               /* Structure à retourner       */ +    GImmOperand *offset;                    /* Emplacement lu              */ + +    result = NULL; + +    offset = g_imm_operand_new_from_data(size, data, pos, len, SRE_LITTLE /* FIXME */); + +    if (offset != NULL) +    { +        result = g_object_new(G_TYPE_X86_MOFFS_OPERAND, NULL); +        result->offset = offset; +    } + +    return G_ARCH_OPERAND(result); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand   = opérande à transcrire.                           * +*                options   = options de rendu.                                * +*                rendering = support effectif final des lignes de code.       * +*                stream    = flux ouvert en écriture.                         * +*                                                                             * +*  Description : Ajoute du texte simple à un fichier ouvert en écriture.      * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_x86_moffs_operand_add_text(const GX86MOffsOperand *operand, GRenderingOptions *options, MainRendering rendering, FILE *stream) +{ +    g_content_exporter_insert_text(G_CONTENT_EXPORTER(operand), stream, "ds:", 3, RTT_SEGMENT); + +    g_content_exporter_add_text(G_CONTENT_EXPORTER(operand->offset), options, rendering, stream); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = opérande à transcrire.                             * +*                buffer  = espace où placer ledit contenu.                    * +*                options = options de rendu.                                  * +*                                                                             * +*  Description : Ajoute à un tampon GLib le contenu de l'instance spécifiée.  * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_x86_moffs_operand_to_buffer(const GX86MOffsOperand *operand, GBufferLine *buffer, GRenderingOptions *options) +{ +    g_content_exporter_insert_into_buffer(G_CONTENT_EXPORTER(operand), buffer, BLC_ASSEMBLY, +                                          "ds:", 3, RTT_SEGMENT); + +    g_content_exporter_to_buffer(G_CONTENT_EXPORTER(operand->offset), buffer, options); + +} diff --git a/src/arch/x86/operands/moffs.h b/src/arch/x86/operands/moffs.h new file mode 100644 index 0000000..b4f8889 --- /dev/null +++ b/src/arch/x86/operands/moffs.h @@ -0,0 +1,59 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * moffs.h - prototypes pour les opérandes d'emplacements mémoire + * + * Copyright (C) 2012 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 _ARCH_X86_OPERANDS_MOFFS_H +#define _ARCH_X86_OPERANDS_MOFFS_H + + +#include <glib-object.h> + + +#include "../../operand.h" +#include "../../../common/endianness.h" + + + +#define G_TYPE_X86_MOFFS_OPERAND                  g_x86_moffs_operand_get_type() +#define G_X86_MOFFS_OPERAND(obj)                  (G_TYPE_CHECK_INSTANCE_CAST((obj), g_x86_moffs_operand_get_type(), GX86MoffsOperand)) +#define G_IS_X86_MOFFS_OPERAND(obj)               (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_x86_moffs_operand_get_type())) +#define G_X86_MOFFS_OPERAND_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_X86_MOFFS_OPERAND, GX86MoffsOperandClass)) +#define G_IS_X86_MOFFS_OPERAND_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_X86_MOFFS_OPERAND)) +#define G_X86_MOFFS_OPERAND_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_X86_MOFFS_OPERAND, GX86MoffsOperandClass)) + + +/* Définition d'un opérande visant un emplacement mémoire x86 (instance) */ +typedef struct _GX86MOffsOperand GX86MOffsOperand; + +/* Définition d'un opérande visant un emplacement mémoire x86 (classe) */ +typedef struct _GX86MOffsOperandClass GX86MOffsOperandClass; + + +/* Indique le type défini par la GLib pour un opérande d'emplacement mémoire x86. */ +GType g_x86_moffs_operand_get_type(void); + +/* Crée un opérande d'emplacement mémoire x86. */ +GArchOperand *g_x86_moffs_operand_new(const bin_t *, off_t *, off_t, MemoryDataSize); + + + +#endif  /* _ARCH_X86_OPERANDS_MOFFS_H */ diff --git a/src/arch/x86/operands/register.c b/src/arch/x86/operands/register.c new file mode 100644 index 0000000..a70ea60 --- /dev/null +++ b/src/arch/x86/operands/register.c @@ -0,0 +1,265 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * register.c - opérandes visant un registre x86 + * + * Copyright (C) 2012 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 "register.h" + + +#include "../../operand-int.h" + + + +/* Définition d'un opérande visant un registre x86 (instance) */ +struct _GX86RegisterOperand +{ +    GArchOperand parent;                    /* Instance parente            */ + +    GX86Register *reg;                      /* Registre représenté         */ + +}; + + +/* Définition d'un opérande visant un registre x86 (classe) */ +struct _GX86RegisterOperandClass +{ +    GArchOperandClass parent;               /* Classe parente              */ + +}; + + +/* Initialise la classe des opérandes de registre x86. */ +static void g_x86_register_operand_class_init(GX86RegisterOperandClass *); + +/* Initialise une instance d'opérande de registre x86. */ +static void g_x86_register_operand_init(GX86RegisterOperand *); + +/* Ajoute du texte simple à un fichier ouvert en écriture. */ +static void g_x86_register_operand_add_text(const GX86RegisterOperand *, GRenderingOptions *, MainRendering, FILE *); + +/*  Ajoute à un tampon GLib le contenu de l'instance spécifiée. */ +static void g_x86_register_operand_to_buffer(const GX86RegisterOperand *, GBufferLine *, GRenderingOptions *); + + + +/* Indique le type défini par la GLib pour un opérande de registre x86. */ +G_DEFINE_TYPE(GX86RegisterOperand, g_x86_register_operand, G_TYPE_ARCH_OPERAND); + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : klass = classe à initialiser.                                * +*                                                                             * +*  Description : Initialise la classe des opérandes de registre x86.          * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_x86_register_operand_class_init(GX86RegisterOperandClass *klass) +{ + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = instance à initialiser.                            * +*                                                                             * +*  Description : Initialise une instance d'opérande de registre x86.          * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_x86_register_operand_init(GX86RegisterOperand *operand) +{ +    GContentExporter *parent;               /* Instance parente            */ + +    parent = G_CONTENT_EXPORTER(operand); + +    parent->add_text = (add_text_fc)g_x86_register_operand_add_text; +    parent->export_buffer = (export_buffer_fc)g_x86_register_operand_to_buffer; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                size = taille de l'opérande, et donc du registre.            * +*                base = indice du premier registre.                           * +*                                                                             * +*  Description : Crée un opérande visant un registre x86.                     * +*                                                                             * +*  Retour      : Opérande mis en place.                                       * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GArchOperand *g_x86_register_operand_new_from_opcode(const bin_t *data, off_t *pos, off_t len, MemoryDataSize size, bin_t base) +{ +    GX86RegisterOperand *result;            /* Structure à retourner       */ +    GX86Register *reg;                      /* Registre lu                 */ + +    reg = g_x86_register_new(size, data[*pos] - base); + +    if (reg != NULL) +    { +        (*pos)++; + +        result = g_object_new(G_TYPE_X86_REGISTER_OPERAND, NULL); + +        result->reg = reg; + +    } +    else result = NULL; + +    return G_ARCH_OPERAND(result); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : data  = flux de données à analyser.                          * +*                pos   = position courante dans ce flux. [OUT]                * +*                len   = taille totale des données à analyser.                * +*                size  = taille de l'opérande, et donc du registre.           * +*                first = indique la partie du ModR/M à traiter.               * +*                                                                             * +*  Description : Crée un opérande visant un registre x86.                     * +*                                                                             * +*  Retour      : Opérande mis en place.                                       * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GArchOperand *g_x86_register_operand_new_from_mod_rm(const bin_t *data, off_t *pos, off_t len, MemoryDataSize size, bool first) +{ +    GX86RegisterOperand *result;            /* Structure à retourner       */ +    bin_t index;                            /* Registre lu                 */ +    GX86Register *reg;                      /* Registre créé               */ + +    if (first) index = data[*pos] & 0x07; +    else index = (data[*pos] & 0x38) >> 3; + +    reg = g_x86_register_new(size, index); + +    if (reg != NULL) +    { +        (*pos)++; + +        result = g_object_new(G_TYPE_X86_REGISTER_OPERAND, NULL); + +        result->reg = reg; + +    } +    else result = NULL; + +    return G_ARCH_OPERAND(result); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : index = indice du registre visé.                             * +*                size  = taille de l'opérande, et donc du registre.           * +*                                                                             * +*  Description : Crée un opérande visant un registre x86 donné.               * +*                                                                             * +*  Retour      : Opérande mis en place.                                       * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GArchOperand *g_x86_register_operand_new_from_index(bin_t index, MemoryDataSize size) +{ +    GX86RegisterOperand *result;            /* Structure à retourner       */ +    GX86Register *reg;                      /* Registre lu                 */ + +    reg = g_x86_register_new(size, index); + +    if (reg != NULL) +    { +        result = g_object_new(G_TYPE_X86_REGISTER_OPERAND, NULL); + +        result->reg = reg; + +    } +    else result = NULL; + +    return G_ARCH_OPERAND(result); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = opérande à transcrire.                             * +*                options   = options de rendu.                                * +*                rendering = support effectif final des lignes de code.       * +*                stream    = flux ouvert en écriture.                         * +*                                                                             * +*  Description : Ajoute du texte simple à un fichier ouvert en écriture.      * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_x86_register_operand_add_text(const GX86RegisterOperand *operand, GRenderingOptions *options, MainRendering rendering, FILE *stream) +{ +    g_content_exporter_add_text(G_CONTENT_EXPORTER(operand->reg), options, rendering, stream); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = opérande à transcrire.                             * +*                buffer  = espace où placer ledit contenu.                    * +*                options = options de rendu.                                  * +*                                                                             * +*  Description : Ajoute à un tampon GLib le contenu de l'instance spécifiée.  * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_x86_register_operand_to_buffer(const GX86RegisterOperand *operand, GBufferLine *buffer, GRenderingOptions *options) +{ +    g_content_exporter_to_buffer(G_CONTENT_EXPORTER(operand->reg), buffer, options); + +} diff --git a/src/arch/x86/operands/register.h b/src/arch/x86/operands/register.h new file mode 100644 index 0000000..11bc87e --- /dev/null +++ b/src/arch/x86/operands/register.h @@ -0,0 +1,66 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * register.h - prototypes pour les opérandes visant un registre x86 + * + * Copyright (C) 2012 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 _ARCH_X86_OPERANDS_REGISTER_H +#define _ARCH_X86_OPERANDS_REGISTER_H + + +#include <glib-object.h> + + +#include "../registers.h" +#include "../../operand.h" +#include "../../../common/endianness.h" + + + +#define G_TYPE_X86_REGISTER_OPERAND                  g_x86_register_operand_get_type() +#define G_X86_REGISTER_OPERAND(obj)                  (G_TYPE_CHECK_INSTANCE_CAST((obj), g_x86_register_operand_get_type(), GX86RegisterOperand)) +#define G_IS_X86_REGISTER_OPERAND(obj)               (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_x86_register_operand_get_type())) +#define G_X86_REGISTER_OPERAND_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_X86_REGISTER_OPERAND, GX86RegisterOperandClass)) +#define G_IS_X86_REGISTER_OPERAND_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_X86_REGISTER_OPERAND)) +#define G_X86_REGISTER_OPERAND_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_X86_REGISTER_OPERAND, GX86RegisterOperandClass)) + + +/* Définition d'un opérande visant un registre x86 (instance) */ +typedef struct _GX86RegisterOperand GX86RegisterOperand; + +/* Définition d'un opérande visant un registre x86 (classe) */ +typedef struct _GX86RegisterOperandClass GX86RegisterOperandClass; + + +/* Indique le type défini par la GLib pour un opérande de registre x86. */ +GType g_x86_register_operand_get_type(void); + +/* Crée un opérande visant un registre x86. */ +GArchOperand *g_x86_register_operand_new_from_opcode(const bin_t *, off_t *, off_t, MemoryDataSize, bin_t); + +/* Crée un opérande visant un registre x86. */ +GArchOperand *g_x86_register_operand_new_from_mod_rm(const bin_t *, off_t *, off_t, MemoryDataSize, bool); + +/* Crée un opérande visant un registre x86 donné. */ +GArchOperand *g_x86_register_operand_new_from_index(bin_t, MemoryDataSize); + + + +#endif  /* _ARCH_X86_OPERANDS_REGISTER_H */ diff --git a/src/arch/x86/operands/relative.c b/src/arch/x86/operands/relative.c new file mode 100644 index 0000000..3235a0d --- /dev/null +++ b/src/arch/x86/operands/relative.c @@ -0,0 +1,221 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * relative.c - opérandes d'adresses relatives + * + * Copyright (C) 2012 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 "relative.h" + + +#include "../../operand-int.h" + + + +/* Définition d'un opérande x86 d'adresse relative (instance) */ +struct _GX86RelativeOperand +{ +    GArchOperand parent;                    /* Instance parente            */ + +    GImmOperand *immediate;                 /* Adresse visée reconstituée  */ + +}; + +/* Définition d'un opérande x86 d'adresse relative (classe) */ +struct _GX86RelativeOperandClass +{ +    GArchOperandClass parent;               /* Classe parente              */ + +}; + + +/* Initialise la classe des opérandes x86 d'adresse relative. */ +static void g_x86_relative_operand_class_init(GX86RelativeOperandClass *); + +/* Initialise une instance d'opérande x86 d'adresse relative. */ +static void g_x86_relative_operand_init(GX86RelativeOperand *); + +/* Ajoute du texte simple à un fichier ouvert en écriture. */ +static void g_x86_relative_operand_add_text(const GX86RelativeOperand *, GRenderingOptions *, MainRendering, FILE *); + +/* Ajoute à un tampon GLib le contenu de l'instance spécifiée. */ +static void g_x86_relative_operand_to_buffer(const GX86RelativeOperand *, GBufferLine *, GRenderingOptions *); + + + +/* Indique le type défini par la GLib pour un opérande x86 d'adresse relative. */ +G_DEFINE_TYPE(GX86RelativeOperand, g_x86_relative_operand, G_TYPE_ARCH_OPERAND); + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : klass = classe à initialiser.                                * +*                                                                             * +*  Description : Initialise la classe des opérandes x86 d'adresse relative.   * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_x86_relative_operand_class_init(GX86RelativeOperandClass *klass) +{ + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = instance à initialiser.                            * +*                                                                             * +*  Description : Initialise une instance d'opérande x86 d'adresse relative.   * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_x86_relative_operand_init(GX86RelativeOperand *operand) +{ +    GContentExporter *parent;               /* Instance parente            */ + +    parent = G_CONTENT_EXPORTER(operand); + +    parent->add_text = (add_text_fc)g_x86_relative_operand_add_text; +    parent->export_buffer = (export_buffer_fc)g_x86_relative_operand_to_buffer; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : data = flux de données à analyser.                           * +*                pos  = position courante dans ce flux. [OUT]                 * +*                len  = taille totale des données à analyser.                 * +*                size = taille de l'opérande, et donc du registre.            * +*                base = adresse de référence pour le calcul.                  * +*                                                                             * +*  Description : Crée un opérande X86 d'adresse relative.                     * +*                                                                             * +*  Retour      : Opérande mis en place.                                       * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GArchOperand *g_x86_relative_operand_new(const bin_t *data, off_t *pos, off_t len, MemoryDataSize size, vmpa_t base) +{ +    GX86RelativeOperand *result;            /* Structure à retourner       */ +    off_t init_pos;                         /* Position avant lecture      */ +    int8_t val8;                            /* Valeur sur 8 bits           */ +    int16_t val16;                          /* Valeur sur 16 bits          */ +    int32_t val32;                          /* Valeur sur 32 bits          */ +    vmpa_t address;                         /* Adresse finale visée        */ + +    init_pos = *pos; + +    switch (size) +    { +        case MDS_8_BITS_UNSIGNED: +            read_s8(&val8, data, pos, len, SRE_LITTLE /* FIXME */); +            address = base + (*pos - init_pos) + val8; +            break; +        case MDS_16_BITS_UNSIGNED: +            read_s16(&val16, data, pos, len, SRE_LITTLE /* FIXME */); +            address = base + (*pos - init_pos) + val16; +            break; +        case MDS_32_BITS_UNSIGNED: +            read_s32(&val32, data, pos, len, SRE_LITTLE /* FIXME */); +            address = base + (*pos - init_pos) + val32; +            break; +        default: +            return NULL; +            break; +    } + +    result = g_object_new(G_TYPE_X86_RELATIVE_OPERAND, NULL); +    result->immediate = g_imm_operand_new_from_value(MDS_32_BITS/*FIXME*/, (uint32_t)address/* FIXME */); + +    return G_ARCH_OPERAND(result); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand   = opérande à transcrire.                           * +*                options   = options de rendu.                                * +*                rendering = support effectif final des lignes de code.       * +*                stream    = flux ouvert en écriture.                         * +*                                                                             * +*  Description : Ajoute du texte simple à un fichier ouvert en écriture.      * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_x86_relative_operand_add_text(const GX86RelativeOperand *operand, GRenderingOptions *options, MainRendering rendering, FILE *stream) +{ +    g_content_exporter_add_text(G_CONTENT_EXPORTER(operand->immediate), options, rendering, stream); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = opérande à transcrire.                             * +*                buffer  = espace où placer ledit contenu.                    * +*                options = options de rendu.                                  * +*                                                                             * +*  Description : Ajoute à un tampon GLib le contenu de l'instance spécifiée.  * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_x86_relative_operand_to_buffer(const GX86RelativeOperand *operand, GBufferLine *buffer, GRenderingOptions *options) +{ +    g_content_exporter_to_buffer(G_CONTENT_EXPORTER(operand->immediate), buffer, options); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = opérande à traiter.                                * +*                                                                             * +*  Description : Fournit l'adresse représentée par une opérande X86.          * +*                                                                             * +*  Retour      : Valeur portée par l'opérande.                                * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +const GImmOperand *g_x86_relative_operand_get_value(const GX86RelativeOperand *operand) +{ +    return operand->immediate; + +} diff --git a/src/arch/x86/operands/relative.h b/src/arch/x86/operands/relative.h new file mode 100644 index 0000000..083444a --- /dev/null +++ b/src/arch/x86/operands/relative.h @@ -0,0 +1,63 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * relative.h - prototypes pour les opérandes d'adresses relatives + * + * Copyright (C) 2012 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 _ARCH_X86_OPERANDS_RELATIVE_H +#define _ARCH_X86_OPERANDS_RELATIVE_H + + +#include <glib-object.h> + + +#include "../../immediate.h" +#include "../../operand.h" +#include "../../../common/endianness.h" + + + +#define G_TYPE_X86_RELATIVE_OPERAND                  g_x86_relative_operand_get_type() +#define G_X86_RELATIVE_OPERAND(obj)                  (G_TYPE_CHECK_INSTANCE_CAST((obj), g_x86_relative_operand_get_type(), GX86RelativeOperand)) +#define G_IS_X86_RELATIVE_OPERAND(obj)               (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_x86_relative_operand_get_type())) +#define G_X86_RELATIVE_OPERAND_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_X86_RELATIVE_OPERAND, GX86RelativeOperandClass)) +#define G_IS_X86_RELATIVE_OPERAND_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_X86_RELATIVE_OPERAND)) +#define G_X86_RELATIVE_OPERAND_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_X86_RELATIVE_OPERAND, GX86RelativeOperandClass)) + + +/* Définition d'un opérande x86 d'adresse relative (instance) */ +typedef struct _GX86RelativeOperand GX86RelativeOperand; + +/* Définition d'un opérande x86 d'adresse relative (classe) */ +typedef struct _GX86RelativeOperandClass GX86RelativeOperandClass; + + +/* Indique le type défini par la GLib pour un opérande x86 d'adresse relative. */ +GType g_x86_relative_operand_get_type(void); + +/* Crée un opérande X86 d'adresse relative. */ +GArchOperand *g_x86_relative_operand_new(const bin_t *, off_t *, off_t, MemoryDataSize, vmpa_t); + +/* Fournit l'adresse représentée par une opérande X86. */ +const GImmOperand *g_x86_relative_operand_get_value(const GX86RelativeOperand *); + + + +#endif  /* _ARCH_X86_OPERANDS_RELATIVE_H */ diff --git a/src/arch/x86/processor.c b/src/arch/x86/processor.c index 672f4e1..e5056f9 100644 --- a/src/arch/x86/processor.c +++ b/src/arch/x86/processor.c @@ -24,8 +24,8 @@  #include "processor.h" +#include "opcodes/opcodes.h"  #include "../processor-int.h" -#include "opcodes.h"  | 
