/usr/lib/python2.7/dist-packages/hachoir_wx/hex_view/stubs.py is in python-hachoir-wx 0.3-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | # -*- coding: utf-8 -*-
from hachoir_core.tools import alignValue
from math import floor
from hachoir_core.error import warning
def byte_addr(bit):
return bit / 8
def bit_addr(byte):
return byte * 8
def get_file_size(file):
pos = file.tell()
file.seek(0, 2)
size = file.tell()
file.seek(pos)
return size
def to_hex(data):
hex_data = ''
for byte in data:
hex_data += "%02x " % ord(byte)
return hex_data.rstrip(' ')
def calc_char_range(start, end):
aligned_start = byte_addr(start)
aligned_end = byte_addr(alignValue(end, 8))
char_start = calc_char_pos(aligned_start)
char_end = calc_char_pos(aligned_end)
return char_start, char_end
def calc_char_pos(byte_pos):
return byte_pos * 3
def clamp_range(what, begin, end):
what = max(what, begin)
what = min(what, end)
return what
def safe_seek(file, where):
try:
where = max(0, where)
file.seek(where)
except IOError, err:
warning("Cannot seek to %s: %s" % (where, unicode(err)))
return False
return True
def get_page_num(offset, page_width):
return int(floor(offset / float(page_width)))
def get_page_offset(offset, page_width):
return get_page_num(offset, page_width) * page_width
def calc_field_mark(offset, field):
start = field._getAbsoluteAddress() - bit_addr(offset)
size = field._getSize()
return (start, size)
|