python - Using struct.unpack() without knowing anything about the string -


i need parse big-endian binary file , convert little-endian. however, people have handed file on me seem unable tell me data types contains, or how organized — thing know is big-endian binary file some old data. function struct.unpack(), however, requires format character first argument.

this first line of binary file:

import binascii path = "bc2003_lr_m32_chab_im.ised"             open(path, 'rb') fd:     line = fd.readline()     print binascii.hexlify(line) 

a0040000dd0000000000000080e2f54780f1094840c61a4800a92d48c0d9424840a05a48404d7548e09d8948a0689a48e03fad48a063c248c01bda48c0b8f448804a0949100b1a49e0d62c49e0ed41499097594900247449a0a57f4900d98549b0278c49a0c2924990ad9949a0eba049e080a8490072b049c0c2b849d077c1493096ca494022d449a021de49a099e849e08ff349500a

is possible change endianness of file without knowing it?

you cannot without knowing datatypes. there little point in attempting otherwise.

even if homogeneous sequence of 1 datatype, you'd still need know dealing with; flipping byte order in double values different short integers.

take @ formatting characters table; different byte size in result in different set of bytes being swapped; double values, need reverse order of every 8 bytes, example.

if know data should in file, @ least have starting point; you'd have puzzle out how values fit bytes given. it'll puzzle, target set of values can build map of datatypes contained, then write byte-order adjustment script. if don't have that, best not start task impossible achieve.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -