From b6066065ed8832c1b32a085a9bc71d84b6002f2f Mon Sep 17 00:00:00 2001 From: Sword York Date: Sat, 10 Oct 2015 11:01:19 +0800 Subject: [PATCH] find correct avatar.block.xxxxx file (maybe) --- wechat/avatar.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/wechat/avatar.py b/wechat/avatar.py index a704e49..5cb2b7e 100644 --- a/wechat/avatar.py +++ b/wechat/avatar.py @@ -34,12 +34,14 @@ class AvatarReader(object): return img def read_bm_block(self, pos): - file_idx = 0 + file_idx = pos >> 32 fname = os.path.join(self.avt_dir, - 'avatar.block.0000' + str(file_idx)) + 'avatar.block.' + '{:05d}'.format(file_idx)) + # 16 is unknown prefix + # 51 = len('xx/xx/user_this-is-md5-of-length-32.png.bm\x00') + # file_idx * (2**32) is offset between block files + start_pos = pos - file_idx * (2**32) + 16 + 51 with open(fname, 'rb') as f: - start_pos = pos + 16 + 51 - # 51 = len('xx/xx/user_this-is-md5-of-length-32.png.bm\x00') f.seek(start_pos) size = (96, 96, 3) img = np.zeros(size, dtype='uint8')