7
7
using System . Text . Json ;
8
8
using System . Text . RegularExpressions ;
9
9
using AdvancedSharpAdbClient ;
10
+ using AdvancedSharpAdbClient . Exceptions ;
10
11
using AdvancedSharpAdbClient . Models ;
11
12
using Spectre . Console ;
12
13
@@ -210,7 +211,8 @@ private static async Task SendRequest(string headers, string arguments) {
210
211
/// </summary>
211
212
/// <param name="client">ADB client</param>
212
213
/// <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 ) {
214
216
AnsiConsole . MarkupLine ( "[green]Decompressing Settings.apk bundled within HyperSploit...[/]" ) ;
215
217
await using var apk = typeof ( Program ) . Assembly
216
218
. GetManifestResourceStream ( "Settings.apk.gz" ) ! ;
@@ -219,12 +221,35 @@ private static async Task Downgrade(AdbClient client, DeviceData device) {
219
221
using var memory = new MemoryStream ( ) ;
220
222
await stream . CopyToAsync ( memory ) ;
221
223
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
+ }
222
229
223
230
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
+ }
225
251
226
252
AnsiConsole . MarkupLine ( "[green]Installation finished, trying the bypass again...[/]" ) ;
227
- AnsiConsole . MarkupLine ( "[yellow]Note: It's unknown whether it succeeded or not![/]" ) ;
228
253
await Bypass ( client , device ) ;
229
254
}
230
255
0 commit comments