Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | #include "qword.h" |
michael@0 | 2 | #include "x86_imm.h" |
michael@0 | 3 | |
michael@0 | 4 | #include <stdio.h> |
michael@0 | 5 | |
michael@0 | 6 | unsigned int x86_imm_signsized( unsigned char * buf, size_t buf_len, |
michael@0 | 7 | void *dest, unsigned int size ) { |
michael@0 | 8 | signed char *cp = (signed char *) dest; |
michael@0 | 9 | signed short *sp = (signed short *) dest; |
michael@0 | 10 | int32_t *lp = (int32_t *) dest; |
michael@0 | 11 | qword_t *qp = (qword_t *) dest; |
michael@0 | 12 | |
michael@0 | 13 | if ( size > buf_len ) { |
michael@0 | 14 | return 0; |
michael@0 | 15 | } |
michael@0 | 16 | |
michael@0 | 17 | /* Copy 'size' bytes from *buf to *op |
michael@0 | 18 | * return number of bytes copied */ |
michael@0 | 19 | switch (size) { |
michael@0 | 20 | case 1: /* BYTE */ |
michael@0 | 21 | *cp = *((signed char *) buf); |
michael@0 | 22 | break; |
michael@0 | 23 | case 2: /* WORD */ |
michael@0 | 24 | *sp = *((signed short *) buf); |
michael@0 | 25 | break; |
michael@0 | 26 | case 6: |
michael@0 | 27 | case 8: /* QWORD */ |
michael@0 | 28 | *qp = *((qword_t *) buf); |
michael@0 | 29 | break; |
michael@0 | 30 | case 4: /* DWORD */ |
michael@0 | 31 | default: |
michael@0 | 32 | *lp = *((int32_t *) buf); |
michael@0 | 33 | break; |
michael@0 | 34 | } |
michael@0 | 35 | return (size); |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | unsigned int x86_imm_sized( unsigned char * buf, size_t buf_len, void *dest, |
michael@0 | 39 | unsigned int size ) { |
michael@0 | 40 | unsigned char *cp = (unsigned char *) dest; |
michael@0 | 41 | unsigned short *sp = (unsigned short *) dest; |
michael@0 | 42 | uint32_t *lp = (uint32_t *) dest; |
michael@0 | 43 | qword_t *qp = (qword_t *) dest; |
michael@0 | 44 | |
michael@0 | 45 | if ( size > buf_len ) { |
michael@0 | 46 | return 0; |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | /* Copy 'size' bytes from *buf to *op |
michael@0 | 50 | * return number of bytes copied */ |
michael@0 | 51 | switch (size) { |
michael@0 | 52 | case 1: /* BYTE */ |
michael@0 | 53 | *cp = *((unsigned char *) buf); |
michael@0 | 54 | break; |
michael@0 | 55 | case 2: /* WORD */ |
michael@0 | 56 | *sp = *((unsigned short *) buf); |
michael@0 | 57 | break; |
michael@0 | 58 | case 6: |
michael@0 | 59 | case 8: /* QWORD */ |
michael@0 | 60 | *qp = *((qword_t *) buf); |
michael@0 | 61 | break; |
michael@0 | 62 | case 4: /* DWORD */ |
michael@0 | 63 | default: |
michael@0 | 64 | *lp = *((uint32_t *) buf); |
michael@0 | 65 | break; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | return (size); |
michael@0 | 69 | } |
michael@0 | 70 |