diff --git a/android-interact.sh b/android-interact.sh index fc4867a..113d502 100755 --- a/android-interact.sh +++ b/android-interact.sh @@ -1,4 +1,4 @@ -#!/bin/bash -e +#!/bin/bash # File: android-interact.sh # Date: Fri Jun 26 10:38:07 2015 +0800 # Author: Yuxin Wu @@ -18,7 +18,7 @@ adb root if [[ $1 == "uin" ]]; then adb pull $MM_DIR/shared_prefs/system_config_prefs.xml 2>/dev/null - uin=$($GREP 'default_uin' system_config_prefs.xml | $GREP -o 'value="-\?[0-9]*' | cut -c 8-) + uin=$($GREP 'default_uin' system_config_prefs.xml | $GREP -o 'value="\-?[0-9]*' | cut -c 8-) [[ -n $uin ]] || { >&2 echo "Failed to get wechat uin. You can try other methods, or report a bug." exit 1 @@ -26,7 +26,7 @@ if [[ $1 == "uin" ]]; then rm system_config_prefs.xml echo "Got wechat uin: $uin" elif [[ $1 == "imei" ]]; then - imei=$(adb shell dumpsys iphonesubinfo | $GREP 'Device ID' | $GREP -o '[0-9]\+') + imei=$(adb shell dumpsys iphonesubinfo | $GREP 'Device ID' | $GREP -o '[0-9]+') [[ -n $imei ]] || { >&2 echo "Failed to get imei. You can try other methods, or report a bug." exit 1 @@ -78,7 +78,7 @@ elif [[ $1 == "db" || $1 == "res" ]]; then fi elif [[ $1 == "db-decrypt" ]]; then echo "Getting uin..." - $0 uin | tail -n1 | $GREP -o '-\?[0-9]*' | tee /tmp/uin + $0 uin | tail -n1 | $GREP -o '\-?[0-9]*' | tee /tmp/uin echo "Getting imei..." $0 imei | tail -n1 | $GREP -o '[0-9]*' | tee /tmp/imei echo "Getting db..." diff --git a/compatibility.sh b/compatibility.sh index 9565876..0f99b4a 100755 --- a/compatibility.sh +++ b/compatibility.sh @@ -13,7 +13,7 @@ if [ `uname` = 'Darwin' ]; then MD5SUM='md5' else REALPATH='readlink -f' - GREP=grep + GREP='grep -E' MD5SUM='md5sum' fi diff --git a/wechat/avatar.py b/wechat/avatar.py index 5cb2b7e..5e78cbf 100644 --- a/wechat/avatar.py +++ b/wechat/avatar.py @@ -25,16 +25,21 @@ class AvatarReader(object): filename = os.path.join(dir1, dir2, "user_{}.png.bm".format(filename)) - index_avatar = self.query_index(filename) - if index_avatar == -1: - logger.warn("Avatar not found for {}".format(username)) + try: + index_avatar = self.query_index(filename) + if index_avatar == -1: + logger.warn("Avatar not found for {}".format(username)) + return None + else: + img = self.read_bm_block(index_avatar) + return img + except: + logger.warn("Failed to retrieve avatar!") return None - else: - img = self.read_bm_block(index_avatar) - return img + def read_bm_block(self, pos): - file_idx = pos >> 32 + file_idx = pos >> 32 fname = os.path.join(self.avt_dir, 'avatar.block.' + '{:05d}'.format(file_idx)) # 16 is unknown prefix @@ -45,8 +50,8 @@ class AvatarReader(object): f.seek(start_pos) size = (96, 96, 3) img = np.zeros(size, dtype='uint8') - for i in range(96): - for j in range(96): + for i in xrange(96): + for j in xrange(96): r, g, b, a = map(ord, f.read(4)) img[i,j] = (r, g, b) return img diff --git a/wechat/libchathelper.py b/wechat/libchathelper.py index cfe9014..febce1c 100644 --- a/wechat/libchathelper.py +++ b/wechat/libchathelper.py @@ -19,7 +19,7 @@ class LibChatHelper(object): """ Build LibChat messages from WeChat Msg""" """ Types of message whose contents are fully parsed. - No need to save extra data for them. """ + No need to save extra data for them. """ FullyParsed = [TYPE_MSG, TYPE_SPEAK, TYPE_EMOJI, TYPE_CUSTOM_EMOJI, TYPE_IMG] diff --git a/wechat/msg.py b/wechat/msg.py index 96c2bfa..50e5a0a 100644 --- a/wechat/msg.py +++ b/wechat/msg.py @@ -67,7 +67,7 @@ class WeChatMsg(object): pass return "LOCATION:" + label + " ({},{})".format(loc['x'], loc['y']) elif self.type == TYPE_LINK: - pq = PyQuery(self.content_xml_ready, parser='xml') + pq = PyQuery(self.content_xml_ready) url = pq('url').text() if not url: title = pq('title').text()