-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDexFormat.c
38 lines (38 loc) · 912 Bytes
/
DexFormat.c
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 "DexFormat.h"
DF_u4 getUleb128Size(DF_uleb128 value) {
DF_u4 size = 0;
DF_uleb128 tmp = value;
do {
size++;
tmp = tmp >> 7;
}while(tmp != 0);
return size;
}
DF_u4 DF_writeSleb128Data(DF_u1* bytes, DF_u4 idx, DF_sleb128 val) {
DF_u4 next;
do {
next = val >> 7;
if(next != (DF_u4)-1 && next != 0) {
bytes[idx] = (val & 0x007f) | 0x0080;
}else {
bytes[idx] = (val & 0x007f);
}
val = next;
idx++;
}while(val != (DF_u4)-1 && val != 0);
return idx;
}
DF_u4 DF_writeUleb128Data(DF_u1* bytes, DF_u4 idx, DF_uleb128 val) {
DF_u4 next;
do {
next = val >> 7;
if(next > 0) {
bytes[idx] = (val & 0x007f) | 0x0080;
}else {
bytes[idx] = (val & 0x007f);
}
val = next;
idx++;
}while(val != 0);
return idx;
}