Skip to content

Commit

Permalink
Merge pull request #5 from achiez/pre-release
Browse files Browse the repository at this point in the history
Pre release 1.5.3 merge to master
  • Loading branch information
achiez authored Oct 28, 2024
2 parents c185533 + f00015b commit cddc6ea
Show file tree
Hide file tree
Showing 119 changed files with 2,484 additions and 1,371 deletions.
48 changes: 48 additions & 0 deletions NebulaAuth.LegacyConverter/EncryptedManifest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Newtonsoft.Json;

#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
//Pragma disable for legacy code


namespace NebulaAuth.LegacyConverter;
public class Manifest
{
[JsonProperty("encrypted")]
public bool Encrypted { get; set; }

[JsonProperty("first_run")]
public bool FirstRun { get; set; }

[JsonProperty("entries")]
public Entry[] Entries { get; set; }

[JsonProperty("periodic_checking")]
public bool PeriodicChecking { get; set; }

[JsonProperty("periodic_checking_interval")]
public long PeriodicCheckingInterval { get; set; }

[JsonProperty("periodic_checking_checkall")]
public bool PeriodicCheckingCheckAll { get; set; }

[JsonProperty("auto_confirm_market_transactions")]
public bool AutoConfirmMarketTransactions { get; set; }

[JsonProperty("auto_confirm_trades")]
public bool AutoConfirmTrades { get; set; }
}

public class Entry
{
[JsonProperty("encryption_iv")]
public string EncryptionIv { get; set; }

[JsonProperty("encryption_salt")]
public string EncryptionSalt { get; set; }

[JsonProperty("filename")]
public string Filename { get; set; }

[JsonProperty("steamid")]
public ulong SteamId { get; set; }
}
183 changes: 152 additions & 31 deletions NebulaAuth.LegacyConverter/Program.cs
Original file line number Diff line number Diff line change
@@ -1,51 +1,172 @@
using Newtonsoft.Json;
using AchiesUtilities.Extensions;
using NebulaAuth.LegacyConverter;
using Newtonsoft.Json;
using SteamLib.Utility.MaFiles;

var currentPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
if (currentPath != null)
Environment.CurrentDirectory = currentPath;


Console.WriteLine(currentPath);
foreach (var path in args)
try
{
var currentPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
if (currentPath != null)
Environment.CurrentDirectory = currentPath;
const string toStoreFolder = "ConvertedMafiles";

if (Path.Exists(path) == false)
if (Directory.Exists(toStoreFolder) == false)
{
Directory.CreateDirectory(toStoreFolder);
}
else
{
Console.WriteLine($"NOT VALID PATH: '{path}'");
continue;
var isEmpty = Directory.GetFiles(toStoreFolder).Length == 0;
Console.ForegroundColor = ConsoleColor.Yellow;
if (!isEmpty)
{
Console.WriteLine(
"WARNING! 'ConverterdMafiles' folder is not empty. Please backup data from it and then continue.");
Console.ResetColor();
Console.WriteLine("Press Y to continue");
while (Console.ReadKey(true).Key != ConsoleKey.Y)
{
}
}
}
Console.WriteLine("Reading: " + path);
try

var decryptMode = false;
while (true)
{
var text = File.ReadAllText(path);
var maf = MafileSerializer.Deserialize(text, out _);
var legacy = MafileSerializer.SerializeLegacy(maf, Formatting.Indented);
var name = Path.GetFileNameWithoutExtension(path);
Write(legacy, name);
Console.WriteLine("Press 'D' to select decrypt mode. Press 'C' to convert mode. Press ESC to exit");
var key = Console.ReadKey(true);
switch (key.Key)
{
case ConsoleKey.D:
decryptMode = true;
break;
case ConsoleKey.C:
break;
case ConsoleKey.Escape:
return;
default:
continue;
}

Console.WriteLine("DONE: " + name);
break;
}
catch (Exception ex)


Manifest? manifest = null;
string? password = null;
if (decryptMode)
{
Console.WriteLine($"ERROR: {ex.Message}");
Console.WriteLine(ex);
var files = Directory.GetFiles(currentPath, "manifest.json");
var manifestPath = files.FirstOrDefault();
if (manifestPath == null)
{
Console.WriteLine("No manifest.json found in current directory");
return;
}

var manifestText = File.ReadAllText(manifestPath);
try
{
manifest = JsonConvert.DeserializeObject<Manifest>(manifestText)!;
}
catch (Exception ex)
{
Console.WriteLine("Can't read manifest: " + ex);
return;
}

if (manifest.Encrypted == false)
{
Console.WriteLine("Manifest is not encrypted");
return;
}

while (true)
{
Console.WriteLine("Please enter your encryption password: ");
password = Console.ReadLine();
if (string.IsNullOrWhiteSpace(password))
continue;

break;
}
}
finally


Console.WriteLine(currentPath);


foreach (var path in args)
{
Console.WriteLine("-----------------------------------------");

if (Path.Exists(path) == false)
{
Console.WriteLine($"NOT VALID PATH: '{path}'");
continue;
}

Console.WriteLine("Reading: " + path);
try
{
var text = File.ReadAllText(path);
if (decryptMode)
{
var fileName = Path.GetFileName(path);
text = DecryptMafile(fileName, text);
if (text == null)
{
Console.WriteLine(path + " not found in manifest. Skipped");
continue;
}
}

var maf = MafileSerializer.Deserialize(text, true, out _);
var legacy = MafileSerializer.SerializeLegacy(maf, Formatting.Indented);
var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path);
Write(legacy, fileNameWithoutExtension);

Console.WriteLine("DONE: " + fileNameWithoutExtension);
}
catch (Exception ex)
{
Console.WriteLine($"ERROR: {ex.Message}");
Console.WriteLine(ex);
}
finally
{
Console.WriteLine("-----------------------------------------");
}


}

//Local Functions

}
void Write(string maf, string name)
{

Console.WriteLine("Press any key to exit...");
Console.ReadKey();
var path = Path.Combine(toStoreFolder, name + "_legacy.mafile");
File.WriteAllText(path, maf);
}

string? DecryptMafile(string fileName, string cipherText)
{
if (password == null) return null;
var entry = manifest?.Entries.FirstOrDefault(x => x.Filename.EqualsIgnoreCase(fileName));
if (entry == null)
{
return null;
}

var iv = entry.EncryptionIv;
var salt = entry.EncryptionSalt;
return SDAEncryptor.DecryptData(password, salt, iv, cipherText);

void Write(string maf, string name)
{

var path = Path.Combine(name + "_legacy.mafile");
File.WriteAllText(path, maf);
}
}
finally
{
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
Loading

0 comments on commit cddc6ea

Please sign in to comment.