13 bool malformed_uleb =
true;
24 data_end = data + datalen;
25 if (data && datalen > 0) {
27 for (
s = 0; data < data_end;
s += 7) {
31 *
error =
rz_str_newf(
"rz_uleb128: undefined behaviour in %d shift on ut32\n", (
int)
s);
35 sum |= ((
ut64)(
c & 0x7f) <<
s);
38 malformed_uleb =
false;
60 while (
c > 0x7f &&
i <
size) {
73 ut64 s = 0, sum = 0, l = 0;
76 sum |= ((
ut64)(
c & 0x7f) <<
s);
96 if (!(tmptarget =
realloc(otarget, l))) {
103 target = otarget + l - 1;
120 const ut8 *data_end = data + datalen;
121 if (data && datalen > 0) {
126 while (data < data_end) {
127 c = *(data++) & 0x0ff;
128 sum |= ((
st64)(
c & 0x7f) <<
s);
135 if ((
s < (8 *
sizeof(sum))) && (
c & 0x40)) {
136 sum |= -((
st64)1 <<
s);
146 const ut8 *
p = *data;
159 if ((
value & 0x40) != 0) {
160 result |= ~0ULL <<
offset;
168 #define BYTE_AT(type, i, shift) (((type)(p[i]) & 0x7f) << (shift))
170 #define LEB128_1(type) (BYTE_AT(type, 0, 0))
171 #define LEB128_2(type) (BYTE_AT(type, 1, 7) | LEB128_1(type))
172 #define LEB128_3(type) (BYTE_AT(type, 2, 14) | LEB128_2(type))
173 #define LEB128_4(type) (BYTE_AT(type, 3, 21) | LEB128_3(type))
174 #define LEB128_5(type) (BYTE_AT(type, 4, 28) | LEB128_4(type))
175 #define LEB128_6(type) (BYTE_AT(type, 5, 35) | LEB128_5(type))
176 #define LEB128_7(type) (BYTE_AT(type, 6, 42) | LEB128_6(type))
177 #define LEB128_8(type) (BYTE_AT(type, 7, 49) | LEB128_7(type))
178 #define LEB128_9(type) (BYTE_AT(type, 8, 56) | LEB128_8(type))
179 #define LEB128_10(type) (BYTE_AT(type, 9, 63) | LEB128_9(type))
181 #define SHIFT_AMOUNT(type, sign_bit) (sizeof(type) * 8 - 1 - (sign_bit))
182 #define SIGN_EXTEND(type, value, sign_bit) \
183 ((type)((value) << SHIFT_AMOUNT(type, sign_bit)) >> \
184 SHIFT_AMOUNT(type, sign_bit))
187 if (
p <
max && !(
p[0] & 0x80)) {
190 }
else if (
p + 1 <
max && !(
p[1] & 0x80)) {
193 }
else if (
p + 2 <
max && !(
p[2] & 0x80)) {
196 }
else if (
p + 3 <
max && !(
p[3] & 0x80)) {
199 }
else if (
p + 4 <
max && !(
p[4] & 0x80)) {
212 if (
p <
max && !(
p[0] & 0x80)) {
216 }
else if (
p + 1 <
max && !(
p[1] & 0x80)) {
220 }
else if (
p + 2 <
max && !(
p[2] & 0x80)) {
224 }
else if (
p + 3 <
max && !(
p[3] & 0x80)) {
228 }
else if (
p + 4 <
max && !(
p[4] & 0x80)) {
230 bool sign_bit_set = (
p[4] & 0x8);
231 int top_bits =
p[4] & 0xf0;
232 if ((sign_bit_set && top_bits != 0x70) || (!sign_bit_set && top_bits != 0)) {
245 if (
p <
max && !(
p[0] & 0x80)) {
248 }
else if (
p + 1 <
max && !(
p[1] & 0x80)) {
251 }
else if (
p + 2 <
max && !(
p[2] & 0x80)) {
254 }
else if (
p + 3 <
max && !(
p[3] & 0x80)) {
257 }
else if (
p + 4 <
max && !(
p[4] & 0x80)) {
260 }
else if (
p + 5 <
max && !(
p[5] & 0x80)) {
263 }
else if (
p + 6 <
max && !(
p[6] & 0x80)) {
266 }
else if (
p + 7 <
max && !(
p[7] & 0x80)) {
269 }
else if (
p + 8 <
max && !(
p[8] & 0x80)) {
272 }
else if (
p + 9 <
max && !(
p[9] & 0x80)) {
283 if (
p <
max && !(
p[0] & 0x80)) {
287 }
else if (
p + 1 <
max && !(
p[1] & 0x80)) {
291 }
else if (
p + 2 <
max && !(
p[2] & 0x80)) {
295 }
else if (
p + 3 <
max && !(
p[3] & 0x80)) {
299 }
else if (
p + 4 <
max && !(
p[4] & 0x80)) {
303 }
else if (
p + 5 <
max && !(
p[5] & 0x80)) {
307 }
else if (
p + 6 <
max && !(
p[6] & 0x80)) {
311 }
else if (
p + 7 <
max && !(
p[7] & 0x80)) {
315 }
else if (
p + 8 <
max && !(
p[8] & 0x80)) {
319 }
else if (
p + 9 <
max && !(
p[9] & 0x80)) {
321 bool sign_bit_set = (
p[9] & 0x1);
322 int top_bits =
p[9] & 0xfe;
323 if ((sign_bit_set && top_bits != 0x7e) || (!sign_bit_set && top_bits != 0)) {
352 ut8 *
buf =
"\x10\x02\x90\x88";
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
RZ_API void Ht_() free(HtName_(Ht) *ht)
void * realloc(void *ptr, size_t size)
int main(int argc, char **argv)
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
#define cond(bop, top, mask, flags)
RZ_API size_t read_u32_leb128(const ut8 *p, const ut8 *max, ut32 *out_value)
RZ_API const ut8 * rz_uleb128(const ut8 *data, int datalen, RZ_NULLABLE ut64 *v, const char **error)
RZ_API size_t read_i64_leb128(const ut8 *p, const ut8 *max, st64 *out_value)
#define SIGN_EXTEND(type, value, sign_bit)
RZ_API const ut8 * rz_leb128(const ut8 *data, int datalen, st64 *v)
RZ_API const ut8 * rz_uleb128_decode(const ut8 *data, int *datalen, ut64 *v)
RZ_API int rz_uleb128_len(const ut8 *data, int size)
RZ_API st64 rz_sleb128(const ut8 **data, const ut8 *end)
RZ_API size_t read_i32_leb128(const ut8 *p, const ut8 *max, st32 *out_value)
RZ_API ut8 * rz_uleb128_encode(const ut64 s, int *len)
RZ_API size_t read_u64_leb128(const ut8 *p, const ut8 *max, ut64 *out_value)
void error(const char *msg)
ut64(WINAPI *w32_GetEnabledXStateFeatures)()