diff --git a/android-interact.sh b/android-interact.sh index 04e20d3..34dcfd7 100755 --- a/android-interact.sh +++ b/android-interact.sh @@ -49,7 +49,7 @@ elif [[ $1 == "db" || $1 == "res" ]]; then if [[ $1 == "res" ]]; then echo "Pulling resources... this might take a long time, because adb sucks..." mkdir -p resource; cd resource - for d in image2 voice2 emoji avatar video; do + for d in image2 voice2 emoji avatar video sfs; do mkdir -p $d; cd $d adb pull $RES_DIR/$chooseUser/$d cd .. @@ -62,11 +62,17 @@ elif [[ $1 == "db" || $1 == "res" ]]; then echo "Resource pulled at ./resource" echo "Total size: $(du -sh resource | cut -f1)" else - echo "Pulling database file..." + echo "Pulling database and avatar index file..." adb pull $MM_DIR/MicroMsg/$chooseUser/EnMicroMsg.db [[ -f EnMicroMsg.db ]] && \ - echo "File successfully downloaded to EnMicroMsg.db" || { - >&2 echo "Failed to pull database from adb" + echo "Database successfully downloaded to EnMicroMsg.db" || { + >&2 echo "Failed to pull database by adb" + exit 1 + } + adb pull $MM_DIR/MicroMsg/$chooseUser/sfs/avatar.index + [[ -f avatar.index ]] && \ + echo "Avatar index successfully downloaded to avatar.index" || { + >&2 echo "Failed to pull avatar index by adb, are you using latest version of wechat?" exit 1 } fi diff --git a/decrypt-db.sh b/decrypt-db.sh index a8f4cba..e773b1a 100755 --- a/decrypt-db.sh +++ b/decrypt-db.sh @@ -1,5 +1,5 @@ #!/bin/bash -e -# File: decrypt_db.sh +# File: decrypt-db.sh # Date: Tue Jun 16 22:23:13 2015 +0800 # Author: Yuxin Wu @@ -29,8 +29,7 @@ uname | grep Darwin > /dev/null && os=darwin || os=linux uname -m | grep x86_64 > /dev/null && version=64bit || version=32bit echo "Use $version sqlcipher of $os." -echo "Dump decoded database... " -echo "Don't worry about libcrypt.so version warning." +echo "Dump decoded database... (Don't worry about libcrypt.so version warning.)" SQLCIPHER=./third-party/sqlcipher/$os/$version diff --git a/wechat/avatar.py b/wechat/avatar.py index e8ea5f2..db1596a 100644 --- a/wechat/avatar.py +++ b/wechat/avatar.py @@ -34,21 +34,19 @@ class AvatarReader(object): return img def read_bm_block(self, pos): - hex_pos = hex(pos) - fname = os.path.join(self.avt_dir, - 'avatar.block.0000' + hex_pos[2]) - f = open(fname, 'rb') - start_pos = pos - 2 ** 34 - f.seek(start_pos+30) - while f.read(1) != b"\x00": - continue - - size = (96, 96, 3) - img = np.zeros(size, dtype='uint8') - for i in range(96): - for j in range(96): - r, g, b, a = map(ord, f.read(4)) - img[i,j] = (r, g, b) + file_idx = 0 + fname = os.path.join(self.avt_dir, + 'avatar.block.0000' + str(file_idx)) + 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') + for i in range(96): + for j in range(96): + r, g, b, a = map(ord, f.read(4)) + img[i,j] = (r, g, b) return img def query_index(self, filename):