吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 10379|回复: 37
收起左侧

[Android工具] 应用数据备份工具,需要root权限

  [复制链接]
pan2112 发表于 2019-12-29 12:19
本帖最后由 pan2112 于 2019-12-29 14:52 编辑

debug版,懒得编译正式版(debug版也可以直接安装的)。
qq,微信 多测试过(备份-清空(或者重新安装应用)-还原)数据多还在(也不用重新登陆),换机还原也没问题。

back2.png back3.png back1.png
还原的主要核心部分就是要修改还原以后文件的权限(不修改权限的话还原是无效的,由于本人文化水平低,英文大部分看不懂,研究了10几天才知道)
back4.png
ps:没有任何上传数据到服务器以及其他乱七八糟的行为。有需要源码的留言下,如果确实很多人需要的话我在另外打包上传。(主要是懒,哈哈)

哈哈,看到有个留言说要root的要小心,怕不就不要下哦,不要恶心人。
下面是主要文件源码,需要的自己拿去改:

package com.ppqqjy.backup.Backup;

import android.content.Context;
import android.content.pm.PackageManager;
import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.ppqqjy.backup.MainActivity;
import com.ppqqjy.backup.cmd.Cmd1;
import com.ppqqjy.backup.util.FileUtil;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import static com.ppqqjy.backup.util.FileUtil.getSDpath_pback;

/**
* Created by Administrator on 2019/5/29/029.
*/

public class Apkback {
    private static Context MyContext = MainActivity.getInstance();
    private static Context BackContext = null;
    private static int PackUid, MyUid, flag_file = 0, flag_path = 0;
    private static String Backpath_, Backpath, PackName;
    private static Map map_file, map_path;

    public static void init(String packName, String backpath) {
        map_file = JSON.parseObject("{}");
        map_path = JSON.parseObject("{}");
        PackName = packName;
        Backpath_ = backpath;
        Backpath = getSDpath_pback() + "/pback/" + PackName + "/" + backpath;
    }

    public static Boolean Startback() {
        MyUid = MyContext.getApplicationInfo().uid;
        try {
            // c = createPackageContext(PackName, Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
            BackContext = MyContext.createPackageContext(PackName, Context.CONTEXT_IGNORE_SECURITY);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            return false;
        }
        PackUid = BackContext.getApplicationInfo().uid;
        String[] BackPath = {BackContext.getApplicationInfo().dataDir, ""};//"/data/data/" + PackName,
        String[] path = BackContext.getExternalCacheDir().getPath().split(PackName);
        if (path != null && path.length > 0) {
            BackPath[1] = path[0] + PackName;
        }
        Cmd1.StopApk(PackName, null);
        FileUtil.judeDirExists(Backpath + "/");
        for (int i = 0; i < BackPath.length; i++) {
            Cmd1.ChangeUid(BackPath, MyUid, null);
            setpermission(BackPath);
            File file = new File(BackPath + "/");
            MainActivity.getInstance().pro_setMax((int) Apkback.getTotalSizeOfFilesInDir(file));
            back(file, Backpath + "/");
            Cmd1.ChangeUid(BackPath, PackUid, null);
        }
        String sourceDir = BackContext.getApplicationInfo().sourceDir;
        byte[] b = FileUtil.readTobyte(sourceDir);
        FileUtil.savebyteToFile(Backpath + "/back.apk", b);
        map_file.put("backapk", sourceDir);
        String Str = JSON.toJSONString(map_path);
        FileUtil.saveStringToFile(Backpath + "/map_path.json", Str);
        Str = JSON.toJSONString(map_file);
        FileUtil.saveStringToFile(Backpath + "/map_file.json", Str);

        String jsonContent = FileUtil.readToString(getSDpath_pback() + "/pback/" + PackName + "/backup.json");
        if (jsonContent == null || jsonContent.length() < 1) {
            jsonContent = "{}";
        }

        Map map = JSON.parseObject(jsonContent);
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");//设置日期格式
        String date = df.format(new Date());// new Date()为获取当前系统时间,也可使用当前时间戳
        map.put(Backpath_, date);
        Str = JSON.toJSONString(map);
        FileUtil.saveStringToFile(getSDpath_pback() + "/pback/" + PackName + "/backup.json", Str);

        Log.d("调试输出:2222:", "OK");
        MainActivity.getInstance().pro_setopen();
        return true;
    }

    public static void setpermission(String Pack) {
        File file = new File(Pack);
        if (!file.canWrite()) {
            String[] Packs = Pack.split("/");
            String Packt = "/";
            for (int i = 0; i < Packs.length; i++) {
                if (Packs.length() > 0) {
                    Packt = Packt + Packs + "/";
                    File f = new File(Packt);
                    if (!f.canRead()) {
                        if (Packt == Pack) {
                            Cmd1.chmod(Packt, "700", true, null);
                        } else {
                            Cmd1.chmod(Packt, "771", false, null);
                        }
                    }
                }

            }
        }

    }

    public static void backFile(File file, String PackT) {
        if (file.isDirectory()) {
            File[] Files = file.listFiles();
            if (Files != null && Files.length > 0) {
                map_path.put(flag_path + "", file.getAbsolutePath());
                flag_path++;
                for (File f : Files) {
                    backFile(f, PackT);
                }
            } else {
                Log.d("调试输出:8888_backFile", file.getAbsolutePath());
            }

        } else {
            if (file.length() > 0) {
                byte[] b = FileUtil.readTobyte_File(file);
                MainActivity.getInstance().pro_setProgress((int) file.length());
                if (b != null) {
                    flag_file++;
                    FileUtil.savebyteToFile(PackT + flag_file, b);
                    map_file.put("" + flag_file, file.getAbsolutePath());
                } else {
                    Log.d("调试输出:8888_backFile1", file.getAbsolutePath());
                }
            } else {
                Log.d("调试输出:8888_backFile2", file.getAbsolutePath());
            }
        }
    }

    public static void back(final File file, String PackT) {
        if (file.isFile()) {
            if (file.length() > 0) {
                byte[] b = FileUtil.readTobyte_File(file);
                MainActivity.getInstance().pro_setProgress(file.length());
                if (b != null) {
                    flag_file++;
                    FileUtil.savebyteToFile(PackT + flag_file, b);
                    map_file.put("" + flag_file, file.getAbsolutePath());
                } else {
                    Log.d("调试输出:8888_backFile1", file.getAbsolutePath());
                }
            } else {
                Log.d("调试输出:8888_backFile2", file.getAbsolutePath());
            }
        } else {
            final File[] Files = file.listFiles();
            if (Files != null && Files.length > 0) {
                map_path.put(flag_path + "", file.getAbsolutePath());
                flag_path++;
                for (File f : Files) {
                    backFile(f, PackT);
                }
            } else {
                Log.d("调试输出:8888_backFile", file.getAbsolutePath());
            }

        }
    }


    public static long getTotalSizeOfFilesInDir(final File file) {
        if (file.isFile())
            return file.length();
        final File[] children = file.listFiles();
        long total = 0;
        if (children != null)
            for (final File child : children)
                total += getTotalSizeOfFilesInDir(child);
        return total;
    }

}

package com.ppqqjy.backup.Backup;

import android.content.Context;
import android.content.pm.PackageManager;
import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.ppqqjy.backup.MainActivity;
import com.ppqqjy.backup.cmd.Cmd1;
import com.ppqqjy.backup.util.FileUtil;

import java.io.File;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import static com.ppqqjy.backup.Backup.Apkback.setpermission;
import static com.ppqqjy.backup.util.FileUtil.getSDpath_pback;

/**
* Created by Administrator on 2019/5/29/029.
*/

public class Apkup {
    private static Context MyContext = MainActivity.getInstance();
    private static Context BackContext = null;
    private static int PackUid, MyUid, flag_file = 0, flag_path = 0;
    private static String Backpath,PackName;
    private static Map map_file, map_path, map_paths;

    public static  Boolean init(String packName, String backpath) {
        PackName=packName;
        Backpath = getSDpath_pback() + "/pback/" + packName + "/" + backpath;
        String jsonContent = FileUtil.readToString(Backpath + "/map_file.json");
        if (jsonContent == null || jsonContent.length() < 1) {
            Log.d("调试输出:2222:", "map_file.json未找到");
            return false;
        }
        map_file = JSON.parseObject(jsonContent);
        jsonContent = FileUtil.readToString(Backpath+ "/map_path.json");
        if (jsonContent == null || jsonContent.length() < 1) {
            Log.d("调试输出:2222:", "map_path.json未找到");
            return false;
        }
        map_path = JSON.parseObject(jsonContent);
        map_paths= JSON.parseObject("{}");

        MyUid = MyContext.getApplicationInfo().uid;
        try {
            // c = createPackageContext(PackName, Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
            BackContext = MyContext.createPackageContext(packName, Context.CONTEXT_IGNORE_SECURITY);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            return false;
        }
        PackUid = BackContext.getApplicationInfo().uid;
        return true;
    }

    public static void Startup() {
        String[] BackPath = {"/data/data/"+PackName,BackContext.getApplicationInfo().dataDir, ""};
        String[] path = BackContext.getExternalCacheDir().getPath().split(PackName);
        if (path != null && path.length > 0) {
            BackPath[2] = path[0] + PackName;
        }
        Cmd1.StopApk(PackName,null);
        Cmd1.clear(PackName,null);
        for (int i = 0; i < BackPath.length; i++) {
            File file = new File(BackPath + "/");
            if (!file.exists()) {
                Cmd1.Dir(BackPath + "/",null);
            }

            Cmd1.ChangeUid(BackPath + "/", MyUid, null);
            setpermission(BackPath);
        }
        File file = new File(Backpath+ "/");
        MainActivity.getInstance().pro_setMax((int) Apkback.getTotalSizeOfFilesInDir(file));
        uppath();
        upFile();
        for (int i = 0; i < BackPath.length; i++) {
            Cmd1.ChangeUid(BackPath + "/", PackUid, null);
        }
        MainActivity.getInstance().pro_setopen();
        Log.d("调试输出:2222:", "OK");
    }
    public static void uppath() {
        Set set = map_path.keySet();
        Iterator it = set.iterator();
        while (it.hasNext()) {
            String key = it.next().toString();
            String path = map_path.get(key).toString();
            if (!map_paths.containsKey(path)){
                map_paths.put(path,1);
                File file = new File(path);
                if (!file.exists() || !path.contains(Backpath)) {
                    if (!file.mkdirs()){
                        Log.d("调试输出:8888_path", key + "=" + path);
                    }
                }
            }
        }
    }

    public static void upFile() {
        Set set = map_file.keySet();
        Iterator it = set.iterator();
        while (it.hasNext()) {
            String key = it.next().toString();
            String path = map_file.get(key).toString();
            File file = new File(Backpath + "/"+key);
            if (file.length() > 0) {
                MainActivity.getInstance().pro_setProgress((int) file.length());
                byte[] b = FileUtil.readTobyte_File(file);
                if (b != null) {
                    FileUtil.savebyteToFile(path, b);
                } else {
                    Log.d("调试输出:8888_backFile1", file.getAbsolutePath());
                }
            } else {
                Log.d("调试输出:8888_backFile2", file.getAbsolutePath());
            }

        }

    }

}



package com.ppqqjy.backup.cmd;

import android.util.Log;

import java.io.File;
import java.util.List;

import eu.chainfire.libsuperuser.Shell;

/**
* Created by Administrator on 2019/6/4/004.
*/
public class Cmd1 {
    public static int ret=-1;





    public static void addCommand(String Command) {
        ret=-1;
        LibSuHelper.getInstance().addCommand(Command, 0, new Shell.OnCommandResultListener() {
            @Override
            public void onCommandResult(int commandCode, int exitCode, List<String> output) {
                if (exitCode != 0) {
                    for (String s:output){
                        Log.d("调试输出:output_error:", s);
                    }
                    ret=1;
                } else {
                    ret=0;
                    Log.d("调试输出:2222:", "OK" + exitCode);
                }
            }

        });
    }



    public static Boolean rm(String Path) {
        String Command="rm -r "+ Path;
        addCommand(Command);
        while (ret==-1){
            try {
                Thread.currentThread().sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        if (ret==0){
            Log.d("调试输出:"+Command+"::::", "OK" );
            return true;
        }else {
            Log.d("调试输出:"+Command+"::::", "error1" );
            return false;
        }

    }
    public static Boolean chmod(String Path, String rwxrwxrwx,Boolean R, String errorMsg) {
        String Command ;
        if (R){
            Command="chmod -R "+rwxrwxrwx+" "+ Path;
        }else {
            Command="chmod "+rwxrwxrwx+" "+ Path;
        }
        addCommand(Command);
        while (ret==-1){
            try {
                Thread.currentThread().sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        if (ret==0){
            Log.d("调试输出:"+Command+"::::", "OK" );
            return true;
        }else {
            Log.d("调试输出:"+Command+"::::", "error1" );
            return false;
        }

    }
    public static Boolean ChangeUid(String Path, int uid, String errorMsg) {

        addCommand("chown -R " + uid + " " + Path);
        while (ret==-1){
            try {
                Thread.currentThread().sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        if (ret==0){
            Log.d("调试输出:ChangeUid::::", "OK" );
            return true;
        }else {
            Log.d("调试输出:ChangeUid::::", "error1" );
            return false;
        }

    }

    public static Boolean StopApk(String Path, String errorMsg) {
        addCommand("am force-stop " + Path);
        while (ret==-1){
            try {
                Thread.currentThread().sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        if (ret==0){
            Log.d("调试输出:StopApk::::", "OK" );
            return true;
        }else {
            Log.d("调试输出:StopApk::::", "error1" );
            return false;
        }
    }

    public static Boolean clear(String Path, String errorMsg) {
        addCommand("pm clear " + Path + " HERE");
        while (ret==-1){
            try {
                Thread.currentThread().sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        if (ret==0){
            Log.d("调试输出:clear::::", "OK" );
            return true;
        }else {
            Log.d("调试输出:clear::::", "error1" );
            return false;
        }
    }

    public static Boolean Dir(String Path, String errorMsg) {
        File file = new File(Path);
        if (!file.exists() && !file.mkdirs()) {
            String cmd = "mkdir " + Path;
            addCommand(cmd);
            while (ret==-1){
                try {
                    Thread.currentThread().sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            if (ret==0){
                Log.d("调试输出:Dir::::", "OK" );
                return true;
            }else {
                Log.d("调试输出:Dir::::", "error1" );
                return false;
            }
        }
        return true;
    }

    public static Boolean cp(String filename, String Patht, String errorMsg) {

        String cmd = "cp " + filename + " " + Patht;
        addCommand(cmd);
        while (ret==-1){
            try {
                Thread.currentThread().sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        if (ret==0){
            Log.d("调试输出:"+cmd+"::::", "OK" );
            return true;
        }else {
            Log.d("调试输出:"+cmd+"::::", "error1" );
            return false;
        }
    }

}
链接: https://pan.baidu.com/s/10rgVUQTxja_p60ImB6fQoA 提取码: dxiv
另外求个能一键新机的软件啊,有那种免费的么?(好穷,用来给自己店铺刷单的(坑多多),绝对不是乱七八糟的用途的,应用变量过不去。。。谢谢啦!!)

免费评分

参与人数 5吾爱币 +10 热心值 +5 收起 理由
NingXIU + 1 + 1 谢谢@Thanks!
892818830 + 1 + 1 您好 可以付费帮我修改一下备份还原指定包名APP么
YCDSZZQYKS + 1 + 1 谢谢@Thanks!收藏先,虽然看不懂吧
Hmily + 6 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
853679185 + 1 + 1 能搞成安卓按键精灵,autojs直接调用吗?

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

mfkbbdx1 发表于 2019-12-29 12:28
最大的问题是需要ROOT权限。
 楼主| pan2112 发表于 2019-12-31 22:15
wonchaos 发表于 2019-12-30 23:06
微信那个在MicroMsg文件夹下的个人文件夹直接通过恢复安装的app使用?

我自己测试从小米备份,然后拷贝pback文件夹到乐视,还原以后聊天记录多在,你可以自己试试
 楼主| pan2112 发表于 2019-12-29 12:44
mfkbbdx1 发表于 2019-12-29 12:28
最大的问题是需要ROOT权限。

不要root权限真的不知道怎么弄,哈哈,连思路多么。。。
fudashuai 发表于 2019-12-29 13:41
噢!需要root权限!要多加小心!
1wang 发表于 2019-12-29 13:41
挺好的,就是需要root
daymissed 发表于 2019-12-29 13:45
ROOT就不想使用了,感谢分享
ydh 发表于 2019-12-29 14:35
备份的文件不知道在哪。还不如铁备份
 楼主| pan2112 发表于 2019-12-29 14:45
ydh 发表于 2019-12-29 14:35
备份的文件不知道在哪。还不如铁备份

pback文件夹里面
ancx 发表于 2019-12-29 21:52
有全部的代码包吗,可编译运行那种,求
kaxiu 发表于 2019-12-29 22:02
一般都用钛备份,经常刷机比较实用,辛苦了
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 提醒:禁止复制他人回复等『恶意灌水』行为,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-3-29 22:00

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表