From 01a2b5e0c4b6e465e06f93f5a7146f9e2617ec9b Mon Sep 17 00:00:00 2001 From: Vita Chumakova Date: Fri, 19 Jan 2024 01:10:22 +0400 Subject: [PATCH] formatting, improve output messages --- .../Models/BackupInfoResponse.cs | 20 +++++---- YandexKeyExtractor/Models/BackupResponse.cs | 11 ++--- YandexKeyExtractor/Models/CountryResponse.cs | 11 ++--- .../Models/PhoneNumberResponse.cs | 18 ++++---- YandexKeyExtractor/Models/StatusResponse.cs | 17 ++++---- YandexKeyExtractor/Models/TrackResponse.cs | 11 ++--- YandexKeyExtractor/Program.cs | 32 ++++++++------ YandexKeyExtractor/YandexKeyExtractor.csproj | 42 +++++++++---------- 8 files changed, 88 insertions(+), 74 deletions(-) diff --git a/YandexKeyExtractor/Models/BackupInfoResponse.cs b/YandexKeyExtractor/Models/BackupInfoResponse.cs index 148cd54..eddc26a 100644 --- a/YandexKeyExtractor/Models/BackupInfoResponse.cs +++ b/YandexKeyExtractor/Models/BackupInfoResponse.cs @@ -1,14 +1,16 @@ using System.Text.Json.Serialization; -namespace YandexKeyExtractor.Models { - public class BackupInfoResponse : StatusResponse { - [JsonPropertyName("backup_info")] - public BackupInfo? Info { get; set; } +namespace YandexKeyExtractor.Models; - public class BackupInfo { - [JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)] - [JsonPropertyName("updated")] - public uint Updated { get; set; } - } +public class BackupInfoResponse : StatusResponse +{ + [JsonPropertyName("backup_info")] + public BackupInfo? Info { get; set; } + + public class BackupInfo + { + [JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)] + [JsonPropertyName("updated")] + public uint Updated { get; set; } } } diff --git a/YandexKeyExtractor/Models/BackupResponse.cs b/YandexKeyExtractor/Models/BackupResponse.cs index 3f767f3..6c9aed2 100644 --- a/YandexKeyExtractor/Models/BackupResponse.cs +++ b/YandexKeyExtractor/Models/BackupResponse.cs @@ -1,8 +1,9 @@ using System.Text.Json.Serialization; -namespace YandexKeyExtractor.Models { - public class BackupResponse : BackupInfoResponse { - [JsonPropertyName("backup")] - public string? Backup { get; set; } - } +namespace YandexKeyExtractor.Models; + +public class BackupResponse : BackupInfoResponse +{ + [JsonPropertyName("backup")] + public string? Backup { get; set; } } diff --git a/YandexKeyExtractor/Models/CountryResponse.cs b/YandexKeyExtractor/Models/CountryResponse.cs index fec9aad..940d5ef 100644 --- a/YandexKeyExtractor/Models/CountryResponse.cs +++ b/YandexKeyExtractor/Models/CountryResponse.cs @@ -1,8 +1,9 @@ using System.Text.Json.Serialization; -namespace YandexKeyExtractor.Models { - public class CountryResponse : StatusResponse { - [JsonPropertyName("country")] - public string[]? Country { get; set; } - } +namespace YandexKeyExtractor.Models; + +public class CountryResponse : StatusResponse +{ + [JsonPropertyName("country")] + public string[]? Country { get; set; } } diff --git a/YandexKeyExtractor/Models/PhoneNumberResponse.cs b/YandexKeyExtractor/Models/PhoneNumberResponse.cs index 7005ab4..a7d82e6 100644 --- a/YandexKeyExtractor/Models/PhoneNumberResponse.cs +++ b/YandexKeyExtractor/Models/PhoneNumberResponse.cs @@ -1,13 +1,15 @@ using System.Text.Json.Serialization; -namespace YandexKeyExtractor.Models { - public class PhoneNumberResponse : StatusResponse { - [JsonPropertyName("number")] - public PhoneNumberInfo? PhoneNumber { get; set; } +namespace YandexKeyExtractor.Models; - public class PhoneNumberInfo { - [JsonPropertyName("e164")] - public string? StandardizedNumber { get; set; } - } +public class PhoneNumberResponse : StatusResponse +{ + [JsonPropertyName("number")] + public PhoneNumberInfo? PhoneNumber { get; set; } + + public class PhoneNumberInfo + { + [JsonPropertyName("e164")] + public string? StandardizedNumber { get; set; } } } diff --git a/YandexKeyExtractor/Models/StatusResponse.cs b/YandexKeyExtractor/Models/StatusResponse.cs index 1887fc2..cff1fde 100644 --- a/YandexKeyExtractor/Models/StatusResponse.cs +++ b/YandexKeyExtractor/Models/StatusResponse.cs @@ -1,13 +1,14 @@ using System.Text.Json.Serialization; -namespace YandexKeyExtractor.Models { - public class StatusResponse { - [JsonPropertyName("status")] - public string? Status { get; set; } +namespace YandexKeyExtractor.Models; - [JsonPropertyName("errors")] - public string[]? Errors { get; set; } +public class StatusResponse +{ + [JsonPropertyName("status")] + public string? Status { get; set; } - public bool IsSuccess => Status == "ok"; - } + [JsonPropertyName("errors")] + public string[]? Errors { get; set; } + + public bool IsSuccess => Status == "ok"; } diff --git a/YandexKeyExtractor/Models/TrackResponse.cs b/YandexKeyExtractor/Models/TrackResponse.cs index 8e3e1c0..faf177c 100644 --- a/YandexKeyExtractor/Models/TrackResponse.cs +++ b/YandexKeyExtractor/Models/TrackResponse.cs @@ -1,8 +1,9 @@ using System.Text.Json.Serialization; -namespace YandexKeyExtractor.Models { - public class TrackResponse : StatusResponse { - [JsonPropertyName("track_id")] - public string? TrackID { get; set; } - } +namespace YandexKeyExtractor.Models; + +public class TrackResponse : StatusResponse +{ + [JsonPropertyName("track_id")] + public string? TrackID { get; set; } } diff --git a/YandexKeyExtractor/Program.cs b/YandexKeyExtractor/Program.cs index 113f809..536f635 100644 --- a/YandexKeyExtractor/Program.cs +++ b/YandexKeyExtractor/Program.cs @@ -1,6 +1,5 @@ using System; using System.IO; -using System.Runtime.CompilerServices; using YandexKeyExtractor; Console.WriteLine("Initializing..."); @@ -8,51 +7,58 @@ using var handler = WebHandler.Create(); var country = await handler.TryGetCountry(); -PromptInput(out var phoneNumber); +PromptInput(out var phoneNumber, "phone number"); phoneNumber = phoneNumber.TrimStart('+'); var phone = await handler.GetPhoneNumberInfo(phoneNumber, country); var trackID = await handler.SendSMSCodeAndGetTrackID(phone, country); -if (string.IsNullOrEmpty(trackID)) { +if (string.IsNullOrEmpty(trackID)) +{ return; } -PromptInput(out var smsCode); +PromptInput(out var smsCode, "SMS code"); -if (!await handler.CheckCode(smsCode, trackID)) { +if (!await handler.CheckCode(smsCode, trackID)) +{ return; } -if (!await handler.ValidateBackupInfo(phone, trackID, country)) { +if (!await handler.ValidateBackupInfo(phone, trackID, country)) +{ return; } var backup = await handler.GetBackupData(phone, trackID); -if (string.IsNullOrEmpty(backup)) { +if (string.IsNullOrEmpty(backup)) +{ return; } -PromptInput(out var backupPassword); +PromptInput(out var backupPassword, "backup password"); Console.WriteLine("Decrypting..."); var message = Decryptor.Decrypt(backup, backupPassword); -if (string.IsNullOrEmpty(message)) { - Console.WriteLine("Decryption failed!"); +if (string.IsNullOrEmpty(message)) +{ + Console.WriteLine("Decryption failed! Most likely the password is wrong"); return; } Console.WriteLine("Successfully decrypted!"); await File.WriteAllTextAsync("result.txt", message); -Console.WriteLine($"Written {message.Split('\n').Length} authenticators to result file"); +Console.WriteLine($"Written {message.Split('\n').Length} authenticators to the file (result.txt)"); return; -static void PromptInput(out string result, [CallerArgumentExpression("result")] string argumentName = "") { +static void PromptInput(out string result, string argumentName = "") +{ Console.WriteLine($"Enter {argumentName}:"); var input = Console.ReadLine(); - while (string.IsNullOrEmpty(input)) { + while (string.IsNullOrEmpty(input)) + { Console.WriteLine($"{argumentName} is invalid, try again:"); input = Console.ReadLine(); } diff --git a/YandexKeyExtractor/YandexKeyExtractor.csproj b/YandexKeyExtractor/YandexKeyExtractor.csproj index f195a55..880e5f5 100644 --- a/YandexKeyExtractor/YandexKeyExtractor.csproj +++ b/YandexKeyExtractor/YandexKeyExtractor.csproj @@ -1,27 +1,27 @@ - - 1.0.0.0 - 1.0.0.0 - enable - Exe - net8.0 - + + 1.0.0.0 + 1.0.0.0 + enable + Exe + net8.0 + - - - false - false - false - false - false - link - + + + false + false + false + false + false + link + - - - - - + + + + +