def uleb128_decode(f):
    """Decode Unsigned LEB128

    http://en.wikipedia.org/wiki/LEB128#Decode_unsigned_integer"""
    result = 0
    shift = 0
    while True:
        b = ord(f.read(1))
        result |= (b & 0x7F) << shift
        if b & 0x80 == 0:
            break
        shift += 7
    return result