Jul-09-2020, 10:45 PM
as topics. i want to read a binary file. i need some some offset in it and control by big or little endian. but i have problem with it.
i want result like this format. for fullfile. seems i have misunderstand something here. need help with file hex output and big/litte endian please advice.thanks.
path_xd = 'xxxxx' pattern = b'\x14\x02' reg_xd=re.compile(pattern) with open(path_xd, 'r+b') as p_xd: data=p_xd.read() for x in reg_xd.finditer(data): offset=x.start() p_xd.seek(offset) data_1402=p_xd.read(16) xd_name=int.from_bytes(data_1402[2:4], byteorder='little') xd_name=(str(xd_name).replace('0', '')).zfill(2) print(xd_name) print(data_1402) print(data_1402[5:9])i get output like this
Output:b'\x14\x02\x01\x00 \x00\x00\x00\x03\x18\x90BW#\x08\x00'
it's how it look like in termialOutput:402 0100 2000 0000 0318 9042 5723 [..... ......BW#
00000040: 0800 5723 0800
it seems missing some bytes in python output. i want result like this format. for fullfile. seems i have misunderstand something here. need help with file hex output and big/litte endian please advice.thanks.
Output:\x14\x02\x01\x00\x20\x00\x00\x00\x03\x18\x90\x42\x57\x23\x08\x00\x57\x23\x08\x00