-
Notifications
You must be signed in to change notification settings - Fork 2
/
Program.cs
131 lines (113 loc) · 3.65 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using System.CommandLine;
using System.CommandLine.Builder;
using System.CommandLine.Help;
using System.CommandLine.Parsing;
using hpesuperpower;
var prog = "hpesuperpower.exe";
var head = @"HPE Superpower tool.
Google Play Games Emulator modding tool.
Author: ChsBuffer
".Trim();
var rootCmd = new RootCommand(head)
{
Name = prog,
};
// --dev
var variantOption = new Option<bool>("--dev", "(Global option) Apply to Google Play Games Emulator for Developers");
rootCmd.AddGlobalOption(variantOption);
// Auto Patch (Unlock+Extract+Patch+Flash)
var magiskArgument = new Argument<FileInfo>("apkfile", "Magisk APK file path");
var magiskCmd = new Command("magisk", "Root your Google Play Games with single command. Tested on Magisk v28.0, v28.1")
{
magiskArgument
};
rootCmd.AddCommand(magiskCmd);
// Unlock
var unlockCmd = new Command("unlock", "Unlock bootloader");
rootCmd.AddCommand(unlockCmd);
// List
var humanOption = new Option<bool>("-h", "Human readable");
var listCommand = new Command("ls", "List partitions in aggregate.img"){
humanOption
};
rootCmd.AddCommand(listCommand);
var partitionNameArg = new Argument<string>("partname", "Partition name");
var partitionFileArg = new Argument<FileInfo>("file", "Path to the partition image file");
// Extract
var extractCmd = new Command("extract", "Extract partition from aggregate.img") {
partitionNameArg,
partitionFileArg
};
rootCmd.AddCommand(extractCmd);
// Flash
var superpowerOption = new Option<bool>("--superpower", "Patch magisk patched boot image again to remove install restriction");
var flashCmd = new Command("flash", "Flash partition to aggregate.img") {
partitionNameArg,
partitionFileArg,
superpowerOption
};
rootCmd.AddCommand(flashCmd);
var flashExample = @$"
Example:
{prog} flash boot_a magisk_patched.img --superpower
{prog} flash boot_a boot_a.img.bak".Trim();
// Restore
var restoreCmd = new Command("restore", "Undo all changes made by this tool");
rootCmd.AddCommand(restoreCmd);
var parser = new CommandLineBuilder(rootCmd)
.UseEnvironmentVariableDirective()
.UseParseDirective()
.UseTypoCorrections()
.UseParseErrorReporting()
.UseExceptionHandler()
.CancelOnProcessTermination()
.UseHelp(ctx =>
{
if (ctx.Command == flashCmd)
{
ctx.HelpBuilder.CustomizeLayout(_ =>
HelpBuilder.Default
.GetLayout()
.Append(_ => _.Output.WriteLine(flashExample))
);
}
})
.Build();
magiskCmd.SetHandler((dev, magisk) =>
{
var m = new HPEInstallation(dev);
if (!m.Check(write: true)) return;
m.Unlock();
m.Patch(magisk);
}, variantOption, magiskArgument);
unlockCmd.SetHandler((dev, magisk) =>
{
var m = new HPEInstallation(dev);
if (!m.Check(write: true)) return;
m.Unlock();
}, variantOption, magiskArgument);
listCommand.SetHandler((dev, human) =>
{
var m = new HPEInstallation(dev);
if (!m.Check(write: false)) return;
PartitionCommand.List(m.aggregateImg, human);
}, variantOption, humanOption);
extractCmd.SetHandler((dev, partname, outfile) =>
{
var m = new HPEInstallation(dev);
if (!m.Check(write: false)) return;
PartitionCommand.Extract(m.aggregateImg, partname, outfile);
}, variantOption, partitionNameArg, partitionFileArg);
flashCmd.SetHandler((dev, partname, infile, superpower) =>
{
var m = new HPEInstallation(dev);
if (!m.Check(write: true)) return;
m.FlashCommand(partname, infile, superpower);
}, variantOption, partitionNameArg, partitionFileArg, superpowerOption);
restoreCmd.SetHandler((dev) =>
{
var m = new HPEInstallation(dev);
if (!m.Check(write: true)) return;
m.Restore();
}, variantOption);
parser.Invoke(args);