File: p_seven.c

package info (click to toggle)
radare2 0.9.6-3.1%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 17,496 kB
  • ctags: 45,959
  • sloc: ansic: 240,999; sh: 3,645; makefile: 2,520; python: 1,212; asm: 312; ruby: 214; awk: 209; perl: 188; lisp: 169; java: 23; xml: 17; php: 6
file content (62 lines) | stat: -rw-r--r-- 1,571 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* radare - LGPL - Copyright 2012-2013 - pancake */
#include <r_print.h>

// TODO: work in progress

#if 0
for(i=0; i<len; i++) {
	packing_7bit_character(config.block+i, buffer);
	cons_printf("%c", buffer[0]);
}
#endif

R_API int r_print_pack7bit (const char *src, char *dest) {
        int len, i, j = 0, shift = 0;
        ut8 ch1, ch2;
        char tmp[2];

        *dest = '\0';
	len = strlen (src);

        for (i=0; i<len; i++ ) {
                ch1 = src[i] & 0x7F;
                ch1 = ch1 >> shift;
                ch2 = src[(i+1)] & 0x7F;
                ch2 = ch2 << (7-shift);

                ch1 = ch1 | ch2;

                j = strlen(dest);
                sprintf (tmp, "%x", (ch1 >> 4));
                dest[j++] = tmp[0];
                sprintf (tmp, "%x", (ch1 & 0x0F));
                dest[j++] = tmp[0];
                dest[j++] = '\0';
                if (7 == ++shift) {
                        shift = 0;
                        i++;
                }
        }
        return 0;
}

R_API int r_print_unpack7bit (const char *src, char *dest) {
        int i, j, shift = 0, len = strlen (src);
        ut8 ch1, ch2 = '\0';
        char buf[8];

        *dest = '\0';

        for (i=0; i<len; i+=2) {
                sprintf (buf, "%c%c", src[i], src[i+1]);
                ch1 = strtol (buf, NULL, 16);

                j = strlen(dest);
                dest[j++] = ((ch1 & (0x7F >> shift)) << shift) | ch2;
                dest[j++] = '\0';
                ch2 = ch1 >> (7-shift);

                shift++;
        }
        return 0;
}