def read_uleb128(data):
# the first bit of each byte is 1, unless that's the last byte
total = 0
found = False
# so technically it doesn't have to be 5...
if len(data) != 5:
log(3, "read_uleb128, where len(data) == %i" % len(data))
#assert len(data) == 5
for i in xrange(5):
value = ord(data[i])
high_bit = (ord(data[i]) >> 7)
# clear the high bit
total += (value & 0x7f) << (i * 7) | total
# this is the last byte, so break
if high_bit == 0:
found = True
break
if not found: # redundant to also check for "i == 4"?
log(3, "invalid ULEB128")
assert False
# return (value, num_of_bytes) # where num_of_bytes indicates how much space this LEB128 took up
return total, i+1
# http://llvm.org/docs/doxygen/html/LEB128_8h_source.html
# hex => decimal
###############3
# 00 => 0
# 01 => 1
# 7f => -1
# 80 7f => -128
评论列表
文章目录