Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android读取WhatsApp数据_Android_Whatsapp - Fatal编程技术网

Android读取WhatsApp数据

Android读取WhatsApp数据,android,whatsapp,Android,Whatsapp,到目前为止,我在谷歌上搜索了很多关于解密扩展名为 .db.5 但没有一种方法对我有效。我尝试了一个Crypto.class,它可以在stackoverflow链接中看到,用于读取WhatsApp数据库文件,但该文件对我也不起作用 这是我的加密类: import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream;

到目前为止,我在谷歌上搜索了很多关于解密扩展名为

.db.5

但没有一种方法对我有效。我尝试了一个Crypto.class,它可以在stackoverflow链接中看到,用于读取WhatsApp数据库文件,但该文件对我也不起作用

这是我的加密类:

   import java.io.File;
   import java.io.FileInputStream;
   import java.io.FileOutputStream;
   import java.io.InputStream;

   import javax.crypto.Cipher;
   import javax.crypto.CipherInputStream;
   import javax.crypto.spec.SecretKeySpec;

    import android.util.Log;

  public class Crypto
 {

public FileInputStream mIn;
public FileOutputStream mOut;

public Crypto(String fileIn, String fileOut)
{
    try
    {
        mIn = new FileInputStream(new File(fileIn));
        mOut = new FileOutputStream(new File(fileOut));
        decrypt(mIn, mOut);
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}

public static void decrypt(InputStream in, FileOutputStream out) throws Exception
{
    final String string = "346a23652a46392b4d73257c67317e352e3372482177652c";
    byte[] hexAsBytes = hexStringToByteArray(string);

    SecretKeySpec keySpec = new SecretKeySpec(hexAsBytes, "AES");
    Cipher cipher = Cipher.getInstance("AES");

    cipher.init(Cipher.DECRYPT_MODE, keySpec);

    in = new CipherInputStream(in, cipher);
    byte[] buffer = new byte[24];
    int bytesRead;
    while ((bytesRead = in.read(buffer)) != -1)
    {
        out.write(buffer, 0, bytesRead);
        String si = new String(buffer);
        Log.d("Crypto", si);
    }

}

public static byte[] hexStringToByteArray(String s)
{
    int len = s.length();
    byte[] data = new byte[len / 2];
    for(int i = 0; i < len; i += 2)
    {
        data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16));
    }
    return data;
}

       }  
我只想解密这个文件并查看所有聊天记录。为了测试,我正在尝试这个文件msgstore.db.crypt5


如果我做错了,我需要帮助?

我已经通过以下方法做到了:

在设备上设置根目录并尝试以下代码::

public void copyDbToSdcard()
{
    try
    {
        String comando = "cp -r /data/data/com.whatsapp/databases/msgstore.db /sdcard/My_Custom_Folder/";
        Process suProcess = Runtime.getRuntime().exec("su");
        DataOutputStream os = new DataOutputStream(suProcess.getOutputStream());
        os.writeBytes(comando + "\n");
        os.flush();
        os.writeBytes("exit\n");
        os.flush();
        try
        {
            int suProcessRetval = suProcess.waitFor();
            if(255 != suProcessRetval)
            {
                //
            }
            else
            {
                //
            }
        }
        catch (Exception ex)
        {
            Log.e("ERROR-->", ex.toString());
        }
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}  


    private void openAndQueryDatabase()
{
    try
    {
        DataBaseHelper dbHelper = new DataBaseHelper(this.getApplicationContext());
        newDB = dbHelper.getWritableDatabase();

        Cursor c = newDB.rawQuery("SELECT data FROM messages where data!=''", null);

        if(c != null)
        {
            if(c.moveToFirst())
            {
                do
                {

                    String data = c.getString(c.getColumnIndex("data"));

                    results.add(data); //adding to arrayList

                }
                while (c.moveToNext());
            }
        }

                while (c3.moveToNext());
            }
        }
    }

    catch (SQLiteException se)
    {
        Log.e(getClass().getSimpleName(), "Could not create or Open the database");
    }
}  
然后将结果显示在
文本视图中或您想要的任何位置

我在这里找到了这个代码 它接受msgstore.db.crypt5并生成msgstore.db,然后您可以使用任何sqLite bowser打开该文件

   package whatsapp;

    import java.io.File;

    import java.io.FileInputStream;

    import java.io.FileOutputStream;

    import java.math.BigInteger;

    import java.security.MessageDigest;

    import java.util.Arrays;

    import javax.crypto.Cipher;

    import javax.crypto.CipherInputStream;

    import javax.crypto.spec.IvParameterSpec;

    import javax.crypto.spec.SecretKeySpec;

    public class WhatsAppDecrypt5 {

        private static final byte[] INITIALIZATION_VECTOR = hexStringToByteArray("1e39f369e90db33aa73b442bbbb6b0b9");
        private static final byte[] ENCRYPTION_KEY = hexStringToByteArray("8d4b155cc9ff81e5cbf6fa7819366a3ec621a656416cd793");
        public static void main(String[] args) throws Exception {



            if (args.length != 3) {
                System.out.println("usage <inputfile> <outputfile> <email>");
            //  System.exit(0);
            }
            decrypt(new File("/Users/ovazquez/Downloads/msgstore.db.crypt5"), new File("/Users/ovazquez/Downloads/msgstore.db"), "theasociatedemail@gmail.com");
            System.out.println("finalizado");
        }

        private static void decrypt(File inputFile, File outputFile, String email)
                throws Exception {

            String emailMD5 = md5(email);

            byte[] emailMD5Bytes = hexStringToByteArray(emailMD5 + emailMD5);

            byte[] decryptionKey = Arrays.copyOf(ENCRYPTION_KEY, 24);

            for (int i = 0; i < 24; i++) {
                decryptionKey[i] ^= emailMD5Bytes[i & 0xF];
            }

            Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding", "SunJCE");
            cipher.init(Cipher.DECRYPT_MODE,new SecretKeySpec(decryptionKey, "AES"), new IvParameterSpec(INITIALIZATION_VECTOR));
            CipherInputStream cIn = new CipherInputStream(new FileInputStream(inputFile), cipher);
            FileOutputStream fOut = new FileOutputStream(outputFile);

            byte[] buffer = new byte[8192];

            int n;

            while ((n = cIn.read(buffer)) != -1) {

                fOut.write(buffer, 0, n);

            }

            cIn.close();

            fOut.close();

        }

        private static byte[] hexStringToByteArray(String s) {

            int len = s.length();

            byte[] data = new byte[len / 2];

            for (int i = 0; i < len; i += 2) {

                data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character
                        .digit(s.charAt(i + 1), 16));

            }

            return data;

        }

        private static String md5(String md5) throws Exception {

            MessageDigest m = MessageDigest.getInstance("MD5");

            m.reset();

            m.update(md5.getBytes());

            byte[] digest = m.digest();

            BigInteger bigInt = new BigInteger(1, digest);

            return bigInt.toString(16);

        }

    }
包装whatsapp;
导入java.io.File;
导入java.io.FileInputStream;
导入java.io.FileOutputStream;
导入java.math.biginger;
导入java.security.MessageDigest;
导入java.util.array;
导入javax.crypto.Cipher;
导入javax.crypto.cipheriputstream;
导入javax.crypto.spec.IvParameterSpec;
导入javax.crypto.spec.SecretKeySpec;
公共类WhatsAppDecrypt5{
私有静态最终字节[]初始化向量=hexStringToByteArray(“1E39F369E90DB33AA73B442BB6B0B9”);
私有静态最终字节[]加密\u密钥=hexStringToByteArray(“8d4b155cc9ff81e5cbf6fa7819366a3ec621a656416cd793”);
公共静态void main(字符串[]args)引发异常{
如果(参数长度!=3){
System.out.println(“用法”);
//系统出口(0);
}
解密(新文件(“/Users/ovazquez/Downloads/msgstore.db.crypt5”)、新文件(“/Users/ovazquez/Downloads/msgstore.db”)、”theasociatedemail@gmail.com");
System.out.println(“finalizado”);
}
私有静态无效解密(文件输入文件、文件输出文件、字符串电子邮件)
抛出异常{
字符串emailMD5=md5(电子邮件);
字节[]emailMD5Bytes=hexStringToByteArray(emailMD5+emailMD5);
byte[]decryptionKey=Arrays.copyOf(加密密钥,24);
对于(int i=0;i<24;i++){
decryptionKey[i]^=emailMD5Bytes[i&0xF];
}
Cipher Cipher=Cipher.getInstance(“AES/CBC/NoPadding”,“SunJCE”);
init(cipher.DECRYPT_模式,新的SecretKeySpec(decryptionKey,“AES”),新的IvParameterSpec(初始化_向量));
CipherInputStream cIn=新的CipherInputStream(新文件InputStream(inputFile),cipher);
FileOutputStream fOut=新的FileOutputStream(outputFile);
字节[]缓冲区=新字节[8192];
int n;
而((n=cIn.read(buffer))!=-1){
四次写入(缓冲区,0,n);
}
cIn.close();
fOut.close();
}
私有静态字节[]hexStringToByteArray(字符串s){
int len=s.length();
字节[]数据=新字节[len/2];
对于(int i=0;i
private byte[] key = { (byte) 141, 75, 21, 92, (byte) 201, (byte) 255,
        (byte) 129, (byte) 229, (byte) 203, (byte) 246, (byte) 250, 120,
        25, 54, 106, 62, (byte) 198, 33, (byte) 166, 86, 65, 108,
        (byte) 215, (byte) 147 };

private final byte[] iv = { 0x1E, 0x39, (byte) 0xF3, 0x69, (byte) 0xE9, 0xD,
        (byte) 0xB3, 0x3A, (byte) 0xA7, 0x3B, 0x44, 0x2B, (byte) 0xBB,
        (byte) 0xB6, (byte) 0xB0, (byte) 0xB9 };
   long start = System.currentTimeMillis();

    // create paths
    backupPath = Environment.getExternalStorageDirectory()
            .getAbsolutePath() + "/WhatsApp/Databases/msgstore.db.crypt5";
    outputPath = Environment.getExternalStorageDirectory()
            .getAbsolutePath() + "/WhatsApp/Databases/msgstore.db.decrypt";

    File backup = new File(backupPath);

    // check if file exists / is accessible
    if (!backup.isFile()) {
        Log.e(TAG, "Backup file not found! Path: " + backupPath);
        return;
    }

    // acquire account name
    AccountManager manager = AccountManager.get(this);
    Account[] accounts = manager.getAccountsByType("com.google");

    if (accounts.length == 0) {
        Log.e(TAG, "Unable to fetch account!");
        return;
    }

    String account = accounts[0].name;

    try {
        // calculate md5 hash over account name
        MessageDigest message = MessageDigest.getInstance("MD5");
        message.update(account.getBytes());
        byte[] md5 = message.digest();

        // generate key for decryption
        for (int i = 0; i < 24; i++)
            key[i] ^= md5[i & 0xF];

        // read encrypted byte stream
        byte[] data = new byte[(int) backup.length()];
        DataInputStream reader = new DataInputStream(new FileInputStream(
                backup));
        reader.readFully(data);
        reader.close();

        // create output writer
        File output = new File(outputPath);
        DataOutputStream writer = new DataOutputStream(
                new FileOutputStream(output));

        // decrypt file
        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        SecretKeySpec secret = new SecretKeySpec(key, "AES");
        IvParameterSpec vector = new IvParameterSpec(iv);
        cipher.init(Cipher.DECRYPT_MODE, secret, vector);
        writer.write(cipher.update(data));
        writer.write(cipher.doFinal());
        writer.close();
    } catch (NoSuchAlgorithmException e) {
        Log.e(TAG, "Could not acquire hash algorithm!", e);
        return;
    } catch (IOException e) {
        Log.e(TAG, "Error accessing file!", e);
        return;
    } catch (Exception e) {
        Log.e(TAG, "Something went wrong during the encryption!", e);
        return;
    }

    long end = System.currentTimeMillis();

    Log.i(TAG, "Success! It took " + (end - start) + "ms");
private byte[]key={(字节)141,75,21,92,(字节)201,(字节)255,
(字节)129,(字节)229,(字节)203,(字节)246,(字节)250120,
25,54,106,62,(字节)198,33,(字节)166,86,65,108,
(字节)215,(字节)147};
私有最终字节[]iv={0x1E,0x39,(字节)0xF3,0x69,(字节)0xE9,0xD,
(字节)0xB3,0x3A,(字节)0xA7,0x3B,0x44,0x2B,(字节)0xBB,
(字节)0xB6,(字节)0xB0,(字节)0xB9};
长启动=System.currentTimeMillis();
//创建路径
backupPath=Environment.getExternalStorageDirectory()
.getAbsolutePath()+“/WhatsApp/Databases/msgstore.db.crypt5”;
outputPath=Environment.getExternalStorageDirectory()
.getAbsolutePath()+“/WhatsApp/Databases/msgstore.db.decrypt”;
文件备份=新文件(备份路径);
//检查文件是否存在/是否可访问
如果(!backup.isFile()){
Log.e(标记“找不到备份文件!路径:”+backupPath);
返回;
}
//获取帐户名
AccountManager=AccountManager.get(这个);
Account[]accounts=manager.getAccountsByType(“com.google”);
如果(accounts.length==0){
Log.e(标记“无法获取帐户!”);
返回;
}
字符串account=accounts[0]。名称;
试一试{
//计算帐户名上的md5哈希
MessageDigest message=MessageDigest.getInstance(“MD5”);
message.update(account.getBytes());
字节[]md5=message.digest();
//生成用于解密的密钥
对于(int i=0;i<24;i++)
键[i]^=md5[i&0xF];
//读取加密字节流
字节[]数据=新字节[(int)backup.length()];
DataInputStream读取器=新DataInputStream(新文件InputStream(
备份);
Readery.readFully(数据);
reader.close();
//创建输出编写器
文件输出=新文件(outputPath);
DataOutputStream编写器=新DataOutputStream(
新文件输出流(输出));
//解密文件
Cipher Cipher=Cipher.getInstance(“AES/CBC/PKCS5Padding”);
SecretKeySpec secret=新的SecretKeySpec(密钥,“AES”);
IvParameterSpec向量=新的IvParameterSpec(iv);
cipher.init(cipher.DECRYPT_模式,secret,vector);
writer.write(密码更新(数据));
writer.write(cipher.doFinal());
writer.close();
}捕获(无算法异常){
Log.e(标记“无法获取哈希算法!”,e);
返回;
}捕获(IOE异常){
Log.e(
private byte[] key = { (byte) 141, 75, 21, 92, (byte) 201, (byte) 255,
        (byte) 129, (byte) 229, (byte) 203, (byte) 246, (byte) 250, 120,
        25, 54, 106, 62, (byte) 198, 33, (byte) 166, 86, 65, 108,
        (byte) 215, (byte) 147 };

private final byte[] iv = { 0x1E, 0x39, (byte) 0xF3, 0x69, (byte) 0xE9, 0xD,
        (byte) 0xB3, 0x3A, (byte) 0xA7, 0x3B, 0x44, 0x2B, (byte) 0xBB,
        (byte) 0xB6, (byte) 0xB0, (byte) 0xB9 };
   long start = System.currentTimeMillis();

    // create paths
    backupPath = Environment.getExternalStorageDirectory()
            .getAbsolutePath() + "/WhatsApp/Databases/msgstore.db.crypt5";
    outputPath = Environment.getExternalStorageDirectory()
            .getAbsolutePath() + "/WhatsApp/Databases/msgstore.db.decrypt";

    File backup = new File(backupPath);

    // check if file exists / is accessible
    if (!backup.isFile()) {
        Log.e(TAG, "Backup file not found! Path: " + backupPath);
        return;
    }

    // acquire account name
    AccountManager manager = AccountManager.get(this);
    Account[] accounts = manager.getAccountsByType("com.google");

    if (accounts.length == 0) {
        Log.e(TAG, "Unable to fetch account!");
        return;
    }

    String account = accounts[0].name;

    try {
        // calculate md5 hash over account name
        MessageDigest message = MessageDigest.getInstance("MD5");
        message.update(account.getBytes());
        byte[] md5 = message.digest();

        // generate key for decryption
        for (int i = 0; i < 24; i++)
            key[i] ^= md5[i & 0xF];

        // read encrypted byte stream
        byte[] data = new byte[(int) backup.length()];
        DataInputStream reader = new DataInputStream(new FileInputStream(
                backup));
        reader.readFully(data);
        reader.close();

        // create output writer
        File output = new File(outputPath);
        DataOutputStream writer = new DataOutputStream(
                new FileOutputStream(output));

        // decrypt file
        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        SecretKeySpec secret = new SecretKeySpec(key, "AES");
        IvParameterSpec vector = new IvParameterSpec(iv);
        cipher.init(Cipher.DECRYPT_MODE, secret, vector);
        writer.write(cipher.update(data));
        writer.write(cipher.doFinal());
        writer.close();
    } catch (NoSuchAlgorithmException e) {
        Log.e(TAG, "Could not acquire hash algorithm!", e);
        return;
    } catch (IOException e) {
        Log.e(TAG, "Error accessing file!", e);
        return;
    } catch (Exception e) {
        Log.e(TAG, "Something went wrong during the encryption!", e);
        return;
    }

    long end = System.currentTimeMillis();

    Log.i(TAG, "Success! It took " + (end - start) + "ms");