File: uleb128.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 (38 lines) | stat: -rw-r--r-- 710 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
#include <r_util.h>

/* dex/dwarf uleb128 implementation */

R_API const ut8 *r_uleb128 (const ut8 *data, ut32 *v) {
	ut8 c;
	ut32 s, sum;
	for (s = sum = 0; ; s += 7) {
		c = *(data++) & 0xff;
		sum |= ((ut32) (c&0x7f) << s);
		if (!(c&0x80)) break;
	}
	if (v) *v = sum;
	return data;
}

R_API const ut8 *r_leb128 (const ut8 *data, st32 *v) {
	ut8 c;
	st32 s, sum;
	for (s = sum = 0; ;  s+= 7) {
		c = *data++ & 0x0ff;
		sum |= ((st32) ((*data++) & 0x7f) << s);
		if (!(c&0x80)) break;
	}
	if ((s < (8 * sizeof (sum))) && (c & 0x40))
		sum |= -(((long)1) << s);
	if (v) *v = sum;
	return data;
}

#if 0
main() {
	ut32 n;
	ut8 *buf = "\x10\x02\x90\x88";
	r_uleb128 (buf, &n);
	printf ("n = %d\n", n);
}
#endif