瀏覽代碼

update scripts for avatar code

ppwwyyxx 10 年之前
父節點
當前提交
26115c48df
共有 3 個文件被更改,包括 25 次插入22 次删除
  1. 10 4
      android-interact.sh
  2. 2 3
      decrypt-db.sh
  3. 13 15
      wechat/avatar.py

+ 10 - 4
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

+ 2 - 3
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 <[email protected]>
 
@@ -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

+ 13 - 15
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):