A
A
Andrew2012-02-06 05:18:55
Python
Andrew, 2012-02-06 05:18:55

Python hex or binary data man

Good afternoon!
In flash, it is possible to convert an object as an array of bytes and then any mockery of these bytes and an array (somehow +\- any number to a byte)
I'm trying to solve a similar problem in python, that is, read the file byte by byte, subtract its position from the byte (yes -yes, it sounds crazy, but somehow it works on flash)
Something similar was achieved through But extra 3 zeros are written to the file ... I don’t know what to do ((
f = open('ac.swf', 'rb+')
ff = open('aaaa.swf', 'wb+')
data = f.read()
for i,el in enumerate(data):
el = unpack('<b', el)
ff.write(pack('i', el[0]-i))

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
alz, 2012-02-06
@alz

Are you unpacking a byte and packing it into an integer? Maybe in bytes and pack?

D
DmZ, 2012-02-06
@DmZ

They said above correctly - you pack not what you unpacked.
If the file is small, then it is probably more convenient to immediately read it into an array, process it, and then write the array.
For example like this:
data = file('ac.swf','rb').read()
bytearr = unpack('<%db'%len(data), data)
# Process array bytearr: enumerate(bytearr)...
file('aaaa.swf','wb').write(pack('<%db'%len(bytearr), bytearr))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question