formatting, improve output messages

This commit is contained in:
Vita Chumakova
2024-01-19 01:10:22 +04:00
parent 66dd2db74e
commit 01a2b5e0c4
8 changed files with 88 additions and 74 deletions

View File

@@ -1,14 +1,16 @@
using System.Text.Json.Serialization;
namespace YandexKeyExtractor.Models {
public class BackupInfoResponse : StatusResponse {
namespace YandexKeyExtractor.Models;
public class BackupInfoResponse : StatusResponse
{
[JsonPropertyName("backup_info")]
public BackupInfo? Info { get; set; }
public class BackupInfo {
public class BackupInfo
{
[JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)]
[JsonPropertyName("updated")]
public uint Updated { get; set; }
}
}
}

View File

@@ -1,8 +1,9 @@
using System.Text.Json.Serialization;
namespace YandexKeyExtractor.Models {
public class BackupResponse : BackupInfoResponse {
namespace YandexKeyExtractor.Models;
public class BackupResponse : BackupInfoResponse
{
[JsonPropertyName("backup")]
public string? Backup { get; set; }
}
}

View File

@@ -1,8 +1,9 @@
using System.Text.Json.Serialization;
namespace YandexKeyExtractor.Models {
public class CountryResponse : StatusResponse {
namespace YandexKeyExtractor.Models;
public class CountryResponse : StatusResponse
{
[JsonPropertyName("country")]
public string[]? Country { get; set; }
}
}

View File

@@ -1,13 +1,15 @@
using System.Text.Json.Serialization;
namespace YandexKeyExtractor.Models {
public class PhoneNumberResponse : StatusResponse {
namespace YandexKeyExtractor.Models;
public class PhoneNumberResponse : StatusResponse
{
[JsonPropertyName("number")]
public PhoneNumberInfo? PhoneNumber { get; set; }
public class PhoneNumberInfo {
public class PhoneNumberInfo
{
[JsonPropertyName("e164")]
public string? StandardizedNumber { get; set; }
}
}
}

View File

@@ -1,7 +1,9 @@
using System.Text.Json.Serialization;
namespace YandexKeyExtractor.Models {
public class StatusResponse {
namespace YandexKeyExtractor.Models;
public class StatusResponse
{
[JsonPropertyName("status")]
public string? Status { get; set; }
@@ -9,5 +11,4 @@ namespace YandexKeyExtractor.Models {
public string[]? Errors { get; set; }
public bool IsSuccess => Status == "ok";
}
}

View File

@@ -1,8 +1,9 @@
using System.Text.Json.Serialization;
namespace YandexKeyExtractor.Models {
public class TrackResponse : StatusResponse {
namespace YandexKeyExtractor.Models;
public class TrackResponse : StatusResponse
{
[JsonPropertyName("track_id")]
public string? TrackID { get; set; }
}
}

View File

@@ -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();
}

View File

@@ -19,9 +19,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CryptSharpStandard" Version="1.0.0" />
<PackageReference Include="Flurl.Http" Version="4.0.2" />
<PackageReference Include="NaCl.Net" Version="0.1.13" />
<PackageReference Include="CryptSharpStandard" Version="1.0.0"/>
<PackageReference Include="Flurl.Http" Version="4.0.2"/>
<PackageReference Include="NaCl.Net" Version="0.1.13"/>
</ItemGroup>
</Project>