diff --git a/README.md b/README.md index cfb11e4..e9b5823 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -## Dump Wechat Messages from Android +## Dump WeChat Messages from Android WeChat(微信), as the most popular mobile IM app in China, failed to allow users to export well-formatted chat history. This tool can parse and dump WeChat chat history on a rooted android phone. @@ -8,7 +8,7 @@ This tool can parse and dump WeChat chat history on a rooted android phone. #### Install Dependencies: + python-PIL + [PyQuery](https://pypi.python.org/pypi/pyquery/1.2.1) -+ pysox(https://pypi.python.org/pypi/pysox/0.3.6.alpha) ++ [pysox](https://pypi.python.org/pypi/pysox/0.3.6.alpha) + python-csscompressor(optional) #### Get Necessary Data: @@ -16,11 +16,11 @@ This tool can parse and dump WeChat chat history on a rooted android phone. + `./android-interact.sh db` + Use your rooted file system manager app + Get WeChat user resource directory from your phone: - + `./android-interact.sh res` # you might need to specify a location if the default doesn't work -+ Get Wechat uin, possible ways are: + + `./android-interact.sh res` # you might need to change the resource location in this script if the default doesn't work ++ Get WeChat uin, possible ways are: + `./android-interact.sh uin` + Login to [web wechat](https://wx.qq.com), get wxuin=1234567 from `document.cookie` -+ Get phone IMEI, possible ways are: ++ Get your phone IMEI number, possible ways are: + `./android-interact.sh imei` + Call `*#06#` on your phone + Find IMEI in system settings @@ -34,15 +34,16 @@ This tool can parse and dump WeChat chat history on a rooted android phone. ``` ./dump_msg.py decrypted_db.db output_dir ``` -+ Dump messages of one contact to single-file html, containing voice messages and images: ++ Dump messages of one contact to rich-content html, containing voice messages, emojis, and images: ``` ./dump_html.py decrypted_db.db output.html ``` ### TODO -+ Group message ++ Add nickname in chatroom + Show name of emoji in text output -+ Search by uid/username.. ++ Search by uid/username ++ Better user experiences... see TODOs ### Disclaimers Use this software at your own risk. The author is not responsible for any potential damage/loss/privacy diff --git a/android-interact.sh b/android-interact.sh index 3119e86..0ae4d63 100755 --- a/android-interact.sh +++ b/android-interact.sh @@ -1,6 +1,6 @@ #!/bin/bash -e # File: android-interact.sh -# Date: Wed Dec 31 23:42:08 2014 +0800 +# Date: Wed Jan 07 21:57:59 2015 +0800 # Author: Yuxin Wu PROG_NAME=`readlink -f "$0"` PROG_DIR=`dirname "$PROG_NAME"` @@ -45,7 +45,7 @@ elif [[ $1 == "db" || $1 == "res" ]]; then if [[ $1 == "res" ]]; then echo "Pulling resources... this might take a long time..." mkdir -p resource; cd resource - for d in image2 voice2 emoji avatar; do + for d in image2 voice2 emoji avatar video; do mkdir -p $d; cd $d adb pull $RES_DIR/$chooseUser/$d cd .. diff --git a/lib/msg.py b/lib/msg.py index c37b69d..d634c36 100644 --- a/lib/msg.py +++ b/lib/msg.py @@ -1,7 +1,7 @@ #!/usr/bin/env python2 # -*- coding: UTF-8 -*- # File: msg.py -# Date: Thu Dec 25 09:56:24 2014 +0800 +# Date: Wed Jan 07 22:00:37 2015 +0800 # Author: Yuxin Wu import re @@ -14,11 +14,12 @@ TYPE_MSG = 1 TYPE_IMG = 3 TYPE_SPEAK = 34 TYPE_NAMECARD = 42 -TYPE_VIDEO = 43 +TYPE_VIDEO_FILE = 43 TYPE_EMOJI = 47 TYPE_LOCATION = 48 TYPE_LINK = 49 # link share OR file from web TYPE_VOIP = 50 +TYPE_WX_VIDEO = 62 # video took by wechat TYPE_SYSTEM = 10000 class WeChatMsg(object): @@ -65,8 +66,10 @@ class WeChatMsg(object): u"No title or url found in TYPE_LINK: {}".format(self.content) return u"FILE:{}".format(title) return u"URL:{}".format(url) - elif self.type == TYPE_VIDEO: + elif self.type == TYPE_VIDEO_FILE: return "VIDEO FILE" + elif self.type == TYPE_WX_VIDEO: + return "WeChat VIDEO" elif self.type == TYPE_NAMECARD: try: pq = PyQuery(self.content) @@ -85,9 +88,15 @@ class WeChatMsg(object): return u"NAMECARD: {}".format(name) elif self.type == TYPE_EMOJI: # TODO add emoji name - return self.content + return self.content_no_first_line else: + return self.content_no_first_line + + @property + def content_no_first_line(self): + if not self.is_chatroom(): return self.content + return self.content[self.content.find('\n')+1:] def __repr__(self): ret = u"{}|{}:{}:{}".format( @@ -105,6 +114,14 @@ class WeChatMsg(object): def __lt__(self, r): return self.createTime < r.createTime + def is_chatroom(self): + return self.talker.endswith('@chatroom') + + def get_msg_talker_id(self): + if not self.is_chatroom(): + return self.talker + return self.content[:self.content.find(':')] + def get_emoji_product_id(self): assert self.type == TYPE_EMOJI, "Wrong call to get_emoji_product_id()!" pq = PyQuery(self.content) @@ -112,3 +129,4 @@ class WeChatMsg(object): if not emoji: return None return emoji.attrs['productid'] + diff --git a/lib/render.py b/lib/render.py index 63076bf..ae4da69 100644 --- a/lib/render.py +++ b/lib/render.py @@ -1,7 +1,7 @@ #!/usr/bin/env python2 # -*- coding: UTF-8 -*- # File: render.py -# Date: Fri Jan 02 23:29:32 2015 +0800 +# Date: Wed Jan 07 22:01:33 2015 +0800 # Author: Yuxin Wu import os @@ -72,7 +72,7 @@ class HTMLRender(object): def render_msg(self, msg): """ render a message, return the html block""" - sender = 'you' if not msg.isSend else 'me' + sender = u'you ' + msg.get_msg_talker_id() if not msg.isSend else 'me' format_dict = {'sender_label': sender, 'time': msg.createTime } def fallback(): @@ -121,6 +121,7 @@ class HTMLRender(object): return template.format(**format_dict) elif msg.type == TYPE_LINK: content = msg.msg_str() + # TODO show a short link with long href, if link too long if content.startswith(u'URL:'): url = content[4:] content = u'URL:{0}'.format(url) @@ -151,19 +152,29 @@ class HTMLRender(object): messages=u''.join(blocks) ) - def prepare_avatar_css(self, talker_name): - avatars = (self.res.get_avatar(self.parser.username), - self.res.get_avatar(talker_name)) - avatar_css = open(FRIEND_AVATAR_CSS_FILE).read().format(avatars=avatars) - self.css_string.append(avatar_css) + def prepare_avatar_css(self, talkers): + avatar_tpl= ensure_unicode(open(FRIEND_AVATAR_CSS_FILE).read()) + my_avatar = self.res.get_avatar(self.parser.username) + css = avatar_tpl.format(name='me', avatar=my_avatar) + + for talker in talkers: + avatar = self.res.get_avatar(talker) + css += avatar_tpl.format(name=talker, avatar=avatar) + self.css_string.append(css) def render_msgs(self, msgs): """ render msgs of one friend, return a list of html""" - talker_name = msgs[0].talker - self.prepare_avatar_css(talker_name) + talker_id = msgs[0].talker + if msgs[0].is_chatroom(): + talkers = set() + for msg in msgs: + talkers.add(msg.get_msg_talker_id()) + else: + talkers = set([talker_id]) + self.prepare_avatar_css(talkers) logger.info(u"Rendering {} messages of {}({})".format( - len(msgs), self.parser.contacts[talker_name], talker_name)) + len(msgs), self.parser.contacts[talker_id], talker_id)) self.prgs = ProgressReporter("Render", total=len(msgs)) slice_by_size = MessageSlicerBySize().slice(msgs) diff --git a/lib/res.py b/lib/res.py index 8450ba6..d4cc38b 100644 --- a/lib/res.py +++ b/lib/res.py @@ -1,12 +1,13 @@ #!/usr/bin/env python2 # -*- coding: UTF-8 -*- # File: res.py -# Date: Sat Dec 27 00:06:26 2014 +0800 +# Date: Wed Jan 07 21:21:39 2015 +0800 # Author: Yuxin Wu import glob import os import re +# TODO: perhaps we don't need to introduce PIL and numpy. libjpeg might be enough import Image import cStringIO import base64 diff --git a/lib/static/avatar.css.tpl b/lib/static/avatar.css.tpl index 2db8231..fa8ffc6 100644 --- a/lib/static/avatar.css.tpl +++ b/lib/static/avatar.css.tpl @@ -1,8 +1,4 @@ -.me .avatar {{ +.{name} .avatar {{ background-size: 100%; - background-image: url("data:image/jpeg;base64,{avatars[0]}"); -}} -.you .avatar {{ - background-size: 100%; - background-image: url("data:image/jpeg;base64,{avatars[1]}"); + background-image: url("data:image/jpeg;base64,{avatar}"); }}