-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
82 lines (73 loc) · 2.55 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Org.BouncyCastle;
using Org.BouncyCastle.Crypto;
namespace ABE
{
public class Program
{
public static void Main(String[] args)
{
//Security.addProvider(new Bouncy());
if ((args.Length < 3))
{
usage();
return;
}
String mode = args[0];
if ((!"pack".Equals(mode)
&& (!"unpack".Equals(mode)
&& !"pack-kk".Equals(mode))))
{
usage();
return;
}
bool unpack = "unpack".Equals(mode);
String backupFilename = unpack ? args[1] : args[2];
// TODO: Warning!!!, inline IF is not supported ?
String tarFilename = unpack ? args[2] : args[1];
// TODO: Warning!!!, inline IF is not supported ?
String password = null;
if ((args.Length > 3))
{
password = args[3];
}
if ((password == null))
{
password = Environment.GetEnvironmentVariable("ABE_PASSWD");
}
if (unpack)
{
try
{
AndroidBackup.extractAsTar(backupFilename, tarFilename, password);
}
catch (InvalidCipherTextException exception)
{
Console.WriteLine($"Error: {exception.Message} , Check supplied password");
}
catch (Exception e)
{
Console.WriteLine($"Error: {e.Message}");
}
}
else
{
bool isKitKat = "pack-kk".Equals(mode);
AndroidBackup.packTar(tarFilename, backupFilename, password, isKitKat);
}
}
private static void usage()
{
Console.WriteLine("Usage:");
Console.WriteLine(" unpack:\tabe unpack\t<backup.ab> <backup.tar> [password]");
Console.WriteLine(" pack:\t\tabe pack\t<backup.tar> <backup.ab> [password]");
Console.WriteLine(" pack for 4.4:\tabe pack-kk\t<backup.tar> <backup.ab> [password]");
Console.WriteLine("If the filename is `-`, then data is read from standard input");
Console.WriteLine("or written to standard output.");
Console.WriteLine("Envvar ABE_PASSWD is tried when password is not given");
}
}
}