好友
阅读权限 10
听众
最后登录 1970-1-1
本帖最后由 pan2112 于 2019-12-29 14:52 编辑
debug版,懒得编译正式版(debug版也可以直接安装的)。
qq,微信 多测试过(备份-清空(或者重新安装应用)-还原)数据多还在(也不用重新登陆),换机还原也没问题。
还原的主要核心部分就是要修改还原以后文件的权限(不修改权限的话还原是无效的,由于本人文化水平低,英文大部分看不懂,研究了10几天才知道)
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
另外求个能一键新机的软件啊,有那种免费的么?(好穷,用来给自己店铺刷单的(坑多多),绝对不是乱七八糟的用途的,应用变量过不去。。。谢谢啦!!)
免费评分
查看全部评分