• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "qword.h"
2 #include "x86_imm.h"
3 
4 #include <stdio.h>
5 
x86_imm_signsized(unsigned char * buf,size_t buf_len,void * dest,unsigned int size)6 unsigned int x86_imm_signsized( unsigned char * buf, size_t buf_len,
7 				void *dest, unsigned int size ) {
8 	signed char *cp = (signed char *) dest;
9 	signed short *sp = (signed short *) dest;
10 	int32_t *lp = (int32_t *) dest;
11 	qword_t *qp = (qword_t *) dest;
12 
13 	if ( size > buf_len ) {
14 		return 0;
15 	}
16 
17 	/* Copy 'size' bytes from *buf to *op
18 	 * return number of bytes copied */
19 	switch (size) {
20 		case 1:		/* BYTE */
21 			*cp =  *((signed char *) buf);
22 			break;
23 		case 2:		/* WORD */
24 			*sp =  *((signed short *) buf);
25 			break;
26 		case 6:
27 		case 8:		/* QWORD */
28 			*qp = *((qword_t *) buf);
29 			break;
30 		case 4:		/* DWORD */
31 		default:
32 			*lp = *((int32_t *) buf);
33 			break;
34 	}
35 	return (size);
36 }
37 
x86_imm_sized(unsigned char * buf,size_t buf_len,void * dest,unsigned int size)38 unsigned int x86_imm_sized( unsigned char * buf, size_t buf_len, void *dest,
39 			    unsigned int size ) {
40 	unsigned char *cp = (unsigned char *) dest;
41 	unsigned short *sp = (unsigned short *) dest;
42 	uint32_t *lp = (uint32_t *) dest;
43 	qword_t *qp = (qword_t *) dest;
44 
45 	if ( size > buf_len ) {
46 		return 0;
47 	}
48 
49 	/* Copy 'size' bytes from *buf to *op
50 	 * return number of bytes copied */
51 	switch (size) {
52 		case 1:		/* BYTE */
53 			*cp =  *((unsigned char *) buf);
54 			break;
55 		case 2:		/* WORD */
56 			*sp =  *((unsigned short *) buf);
57 			break;
58 		case 6:
59 		case 8:		/* QWORD */
60 			*qp = *((qword_t *) buf);
61 			break;
62 		case 4:		/* DWORD */
63 		default:
64 			*lp = *((uint32_t *) buf);
65 			break;
66 	}
67 
68 	return (size);
69 }
70 
71