toolkit/crashreporter/google-breakpad/src/third_party/libdisasm/x86_imm.c

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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

mercurial