Skip to content

Commit 01840a4

Browse files
committed
anti-'issue spam' and nuclear option
1 parent 42433c1 commit 01840a4

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

Program.cs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Text.Json;
88
using System.Text.RegularExpressions;
99
using AdvancedSharpAdbClient;
10+
using AdvancedSharpAdbClient.Exceptions;
1011
using AdvancedSharpAdbClient.Models;
1112
using Spectre.Console;
1213

@@ -210,7 +211,8 @@ private static async Task SendRequest(string headers, string arguments) {
210211
/// </summary>
211212
/// <param name="client">ADB client</param>
212213
/// <param name="device">Device data</param>
213-
private static async Task Downgrade(AdbClient client, DeviceData device) {
214+
/// <param name="nuclear">Nuclear option</param>
215+
private static async Task Downgrade(AdbClient client, DeviceData device, bool nuclear = false) {
214216
AnsiConsole.MarkupLine("[green]Decompressing Settings.apk bundled within HyperSploit...[/]");
215217
await using var apk = typeof(Program).Assembly
216218
.GetManifestResourceStream("Settings.apk.gz")!;
@@ -219,12 +221,35 @@ private static async Task Downgrade(AdbClient client, DeviceData device) {
219221
using var memory = new MemoryStream();
220222
await stream.CopyToAsync(memory);
221223
memory.Position = 0;
224+
225+
if (nuclear) {
226+
AnsiConsole.MarkupLine("[green]Uninstalling the Settings app...[/]");
227+
await client.ExecuteRemoteCommandAsync("pm uninstall --user 0 com.android.settings", device);
228+
}
222229

223230
AnsiConsole.MarkupLine("[green]Installing unpatched Settings APK to the device...[/]");
224-
await client.InstallAsync(device, memory);
231+
try {
232+
await client.InstallAsync(device, memory);
233+
} catch (AdbException e) {
234+
// ReSharper disable once InvertIf ~ can you please stop nagging me
235+
if (e.Message.Contains("INSTALL_FAILED_VERSION_DOWNGRADE") || e.Message.Contains("INSTALL_FAILED_INVALID_APK")) {
236+
AnsiConsole.MarkupLine(nuclear
237+
? "[red]Unfortunately, you're out of luck.[/] [yellow]You have a patched HyperOS version.[/]"
238+
: "[yellow]Downgrade failed, but you can still try out the nuclear option (it will auto restore)[/]");
239+
if (!nuclear && AnsiConsole.Confirm("[yellow]Try deleting the Settings app altogether?[/]", false))
240+
await Downgrade(client, device, true);
241+
242+
if (nuclear) {
243+
AnsiConsole.MarkupLine("[green]Restoring the original Settings app...[/]");
244+
await client.ExecuteRemoteCommandAsync("cmd package install-existing com.android.settings", device);
245+
}
246+
return;
247+
}
248+
249+
throw;
250+
}
225251

226252
AnsiConsole.MarkupLine("[green]Installation finished, trying the bypass again...[/]");
227-
AnsiConsole.MarkupLine("[yellow]Note: It's unknown whether it succeeded or not![/]");
228253
await Bypass(client, device);
229254
}
230255

0 commit comments

Comments
 (0)