Platinum Partner

Reading A 24-bit Icon In An Mbm File

Here's an example how I read the icon and display it on canvas
It's a continued part of my previous mbm hack.

>>> from appuifw import *
>>> from struct import unpack
>>> def readL(f, pos=None):     # helping function
...     if pos is not None:
...         f.seek(pos)
...     return unpack('L', f.read(4))[0]
...
>>> fxmbm = 'E:\\system\\apps\\FExplorer\\FExplorer.mbm'
>>> f = open(fxmbm, 'rb')
>>> trailer = readL(f, 16)
>>> num = readL(f, trailer)   # 19 icons
>>> offset = []
>>> for i in range(num):
...   offset.append(readL(f))
...
>>> offset
[20L, 68L, 116L, 474L, 588L, 1038L, 1228L, 1636L, 1864L, 2277L, 2430L, 3735L, 41
69L, 4569L, 4697L, 5197L, 5370L, 5897L, 6062L]
>>> start = offset[2]  # folder icon
>>> f.seek(start)
>>> length = readL(f) - readL(f)    # length of data section
>>> width, height = readL(f), readL(f)  # 16 x 13
>>> f.seek(start+0x28)  # start of data section
>>> data_enc = f.read(length)   # got the data
>>> def rle24_decode(bytes):
...     out = []
...     i = 0
...     while i < len(bytes):
...         n = ord(bytes[i])
...         i += 1
...         if n < 0x80:
...             out.append( bytes[i:i+3] * (n+1) )
...             i += 3
...         else:
...             n = 0x100 - n
...             out.append( bytes[i:i+3*n] )
...             i += 3*n
...     return ''.join(out)
...
>>> data = rel24_decode(data_enc)
>>> app.body = canvas = Canvas()
>>> for j in range(height):
...     for i in range(width):
...         p = 3*(j*width+i)
...         color = [ord(data[p+k]) for k in (2,1,0)]  # It's BGR
...         canvas.point((i,j), tuple(color))
...
>>>  # folder icon is drawn on screen
{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}