Skip to content

Instantly share code, notes, and snippets.

@pawlos
Created November 19, 2020 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pawlos/b260ec59a81442232860fcfc4d85817d to your computer and use it in GitHub Desktop.
Save pawlos/b260ec59a81442232860fcfc4d85817d to your computer and use it in GitHub Desktop.
d = open('report2.xls', 'rb').read()
data_chunk = -1
start_address = [0xace1,
0xcc88,
0xecac,
0x10cd0,
0x12cf4,
0x14d18,
0x16d3c,
0x18d60,
0x1ad84,
0x1cda8,
0x1edcc,
0x20df0,
0x22e14,
0x24e38,
0x26e5c,
0x28e80,
0x2aea4,
0x2cec8,
0x2eeec,
0x30f10, #301
0x30f10+0x2024, #302
0x30f10+0x2024*2, #303
0x30f10+0x2024*3, #304
0x30f10+0x2024*4, #305
0x30f10+0x2024*5,
0x30f10+0x2024*6,
0x30f10+0x2024*7,
0x30f10+0x2024*8, #309
0x30f10+0x2024*9,
0x30f10+0x2024*10, #311
0x30f10+0x2024*11, #312
0x30f10+0x2024*12, #313
0x30f10+0x2024*13, #314
0x30f10+0x2024*14, #315
0x30f10+0x2024*15, #316
0x30f10+0x2024*16, #317
0x30f10+0x2024*17, #318
0x30f10+0x2024*18, #319
0x30f10+0x2024*19, #320
0x30f10+0x2024*20, #321
0x30f10+0x2024*21, #322
0x30f10+0x2024*22,]
cnt = len(start_address)-2
lens = [0x2020-0x4D-0x30]
#lens.append(0x4d)
lens.extend([0x2020]*cnt)
lens.append(0X1B9E)
has_data = False
addr = None
def get_data():
global data_chunk, addr
while True:
data_chunk += 1
print(f'Next chunk {data_chunk}')
if data_chunk >= len(start_address):
print('Finished')
break
off = start_address[data_chunk]
addr = off
l = lens[data_chunk]
data = d[off:off+l]
for c in data:
yield c,addr
addr += 1
i = 0
from struct import pack, unpack
file_data = bytearray()
_iter = get_data()
temp = bytearray()
for c,a in _iter:
print(f'{a:4X}')
temp.append(c)
if b'IDAT' == temp[-4:]:
if i == 0:
file_data.extend(temp)
else:
l = list(temp)
print(f'Ditching {len(temp)-8} chars.')
file_data.extend(l[-8:])
temp = bytearray()
print(f'Contains IDAT chunk.')
size = file_data[-8:][0:4]
print(size)
chunk_len = unpack(">I",size)[0]
print(f'Size: {chunk_len}.')
for r in range(chunk_len+4): #data + crc
p,a = next(_iter)
print(f'{a:4X}')
file_data.append(p)
i += 1
print(f'PNG IDAT chunk {i}')
if b'IEND' == temp[-4:]:
p,a = next(_iter)
temp.append(p)
p,a = next(_iter)
temp.append(p)
p,a = next(_iter)
temp.append(p)
p,a = next(_iter)
temp.append(p)
break
if i == 50:
break
if len(temp) > 0:
file_data.extend(temp)
open('file.png','wb').write(file_data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment