获取手机微信聊天内容 ( 附源码 )

现在将基本思路梳理一下,以下为 Android 手机应用代码,
在此仅作技术研究和讨论,大家可别干坏事哦。
( 手动坏笑.jpg)
 
目标:获取手机微信的聊天内容
 
思路:微信的聊天记录保存在手机本地 EnMicroMsg.db 数据库 message 表中。
只要获取该数据库,即可读取对应的聊天内容;
 
难点及前提:
一,数据库保存在 /data/data/com.tencent.mm/ 路径下,普通手机没有权限查看该目录。
解决方案: 给手机 ROOT 或使用已 ROOT 的设备。
如何 ROOT 网上教程太多,在此不赘述。
或直接安装 夜神模拟器,支持 ROOT 功能。
 
二,微信数据库是加密的,需要破解微信数据库的密码
解决方案:密码由 IMEI + UIN 再经过 MD5 可获取。
 
如何破解微信数据库的密码,下面我们分三个部分说明:
1,获取手机 IMEI
2,获取微信 UIN
3,用密码读取数据库内容
 
一,如何获取 IMEI ?
微信配置文件已有记录 IME 号,在路径 /data/data/com.tencent.mm/MicroMsg/CompatibleInfo.cfg 文件中第 258 位。
获取代码为:
    public static String getWxIMEI(String CompatibleInfoPath) {
        String imei = ""; FileInputStream campatiFile = null; try { campatiFile = new FileInputStream(CompatibleInfoPath); ObjectInputStream localObjectInputStream = new ObjectInputStream(campatiFile); Map DL = (Map) localObjectInputStream.readObject(); imei = (String) DL.get(258); campatiFile.close(); } catch (Exception e) { e.printStackTrace(); } return imei; }
若取回来的 IMEI 为空,则使用设备自带的 IMEI。
获取代码为:
 TelephonyManager tm = (TelephonyManager) getApplicationContext().getSystemService(TELEPHONY_SERVICE);
 String strIMEI =tm.getDeviceId();
 
二,如何获取 UIN ?
UIN 在微信 app_brand_global_sp.xml 文件中,具体路径在 /data/data/com.tencent.mm/shared_prefs/app_brand_global_sp.xml
内容如下,其中<string></string>标签中就是 UIN :
 
获取代码为:
public void getUins(String filePath) { try { File app_brand_global_sp = new File(filePath); if (app_brand_global_sp.exists()) { FileInputStream in = new FileInputStream(app_brand_global_sp); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); //取得DocumentBuilderFactory实例 DocumentBuilder builder = factory.newDocumentBuilder(); //从factory获取DocumentBuilder实例 Document doc = builder.parse(in); //解析输入流 得到Document实例 Element rootElement = doc.getDocumentElement(); NodeList items = rootElement.getElementsByTagName("set"); for (int i = 0; i < items.getLength(); i++) { Node item = items.item(i); NodeList properties = item.getChildNodes(); for (int j = 0; j < properties.getLength(); j++) { Node property = properties.item(j); String nodeName = property.getNodeName(); if (nodeName.equals("string")) { String Uin = property.getFirstChild().getNodeValue(); mapUIN.put(Common.getMD5("mm" + Uin).toLowerCase(), Uin); LogInputUtil.e(TAG, "MMUIN = " + Common.getMD5("mm" + Uin).toLowerCase() + ", UIN = " + Uin + ",path = " + filePath); } } } } } catch (Exception e) { MyLog.inputLogToFile(TAG, "获取Uin异常 getUin errMsg = " + e.getMessage() + ",path = " + filePath); } }
三:获取密码取得微信数据库聊天信息:
微信数据库路径为:/data/data/com.tencent.mm/wxFolderPath/EnMicroMsg.db
 
wxFolderPath 为 32 位文件夹,指某一个微信的文件路径,不同微信数值不一样,请具体实际情况输入自己的文件夹 ,EnMicroMsg.db 就是这个微信的数据库
 
获取代码为:
 String pass = Common.getMD5(wxIMEI + mapUIN.get(wxFolderPath)).substring(0, 7).toLowerCase();
获得密码后即可打开数据库
代码为:
String dbPath = "/data/data/com.tencent.mm/wxFolderPath/EnMicroMsg.db";
SQLiteDatabase dataTarget SQLiteDatabase.openOrCreateDatabase(dbPath , pass , null, hook);

数据库可视化工具可下载:SQLite Database Browser

核心代码示例 请点击我

猜你喜欢

转载自www.cnblogs.com/lydg/p/11362963.html
今日推荐