baseline: OpenMU upstream b5a0961 (fresh source)
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<WarningsAsErrors>nullable;CS4014;VSTHRD110;VSTHRD100</WarningsAsErrors>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<StartupObject>MUnique.OpenMU.SimpleModulusKeyGenerator.Program</StartupObject>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DocumentationFile>bin\Debug\MUnique.OpenMU.SimpleModulusKeyGenerator.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DocumentationFile>bin\Release\MUnique.OpenMU.SimpleModulusKeyGenerator.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Network\MUnique.OpenMU.Network.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
97
src/SimpleModulusKeyGenerator/Program.cs
Normal file
97
src/SimpleModulusKeyGenerator/Program.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
// <copyright file="Program.cs" company="MUnique">
|
||||
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
|
||||
// </copyright>
|
||||
|
||||
namespace MUnique.OpenMU.SimpleModulusKeyGenerator;
|
||||
|
||||
using System.IO;
|
||||
using MUnique.OpenMU.Network.SimpleModulus;
|
||||
|
||||
/// <summary>
|
||||
/// The main entry point class.
|
||||
/// </summary>
|
||||
public static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// Main entry point of the program.
|
||||
/// </summary>
|
||||
/// <param name="args">The arguments.</param>
|
||||
/// <returns>The async task.</returns>
|
||||
public static async Task Main(string[] args)
|
||||
{
|
||||
if (args.Length == 1)
|
||||
{
|
||||
FindOtherKey(args[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
await GenerateNewKeyPairAsync().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
private static void FindOtherKey(string keyFilePath)
|
||||
{
|
||||
var serializer = new SimpleModulusKeySerializer();
|
||||
|
||||
if (serializer.TryDeserialize(keyFilePath, out var modulusKey, out var cryptKey, out var xorKey))
|
||||
{
|
||||
Console.WriteLine($"Loaded Key:");
|
||||
Console.WriteLine($" Modulus: {string.Join(", ", modulusKey.Select(k => k.ToString()))}");
|
||||
Console.WriteLine($" Crypt: {string.Join(", ", cryptKey.Select(k => k.ToString()))}");
|
||||
Console.WriteLine($" XOR: {string.Join(", ", xorKey.Select(k => k.ToString()))}");
|
||||
var generator = new SimpleModulusKeyGenerator();
|
||||
var otherCryptKey = generator.FindOtherKey(modulusKey, cryptKey);
|
||||
var file = new FileInfo(keyFilePath);
|
||||
var otherFileName = GetOtherFileName(file.Name);
|
||||
var otherFilePath = file.DirectoryName is null ? otherFileName : Path.Combine(file.DirectoryName, otherFileName);
|
||||
|
||||
Console.WriteLine($"Calculated Crypt Key: {string.Join(", ", otherCryptKey.Select(k => k.ToString()))}");
|
||||
Console.WriteLine($"To save the calculated key file '{otherFilePath}' press any key");
|
||||
Console.ReadKey(true);
|
||||
serializer.Serialize(otherFilePath, modulusKey, otherCryptKey, xorKey);
|
||||
Console.WriteLine("Key saved");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("Keys could not be read, file too small?", nameof(keyFilePath));
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetOtherFileName(string fileName)
|
||||
{
|
||||
if (fileName.StartsWith("Enc", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return fileName.Replace("Enc", "Dec", StringComparison.InvariantCultureIgnoreCase);
|
||||
}
|
||||
|
||||
if (fileName.StartsWith("Dec", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return fileName.Replace("Dec", "Enc", StringComparison.InvariantCultureIgnoreCase);
|
||||
}
|
||||
|
||||
throw new ArgumentException("File name does not begin with 'Enc' or 'Dec'.", nameof(fileName));
|
||||
}
|
||||
|
||||
private static async Task GenerateNewKeyPairAsync()
|
||||
{
|
||||
var generator = new SimpleModulusKeyGenerator();
|
||||
var result = await generator.GenerateKeysAsync().ConfigureAwait(false);
|
||||
|
||||
Console.WriteLine("Generated key pair:");
|
||||
Console.WriteLine(result);
|
||||
Console.WriteLine(string.Empty);
|
||||
Console.WriteLine("If you want to save them, enter a number and hit enter. They will be saved as 'EncX.dat' and 'DecX.dat'.");
|
||||
if (int.TryParse(Console.ReadLine(), out int number))
|
||||
{
|
||||
var serializer = new SimpleModulusKeySerializer();
|
||||
serializer.Serialize($"Enc{number}.dat", result.ModulusKey, result.EncryptKey, result.XorKey);
|
||||
serializer.Serialize($"Dec{number}.dat", result.ModulusKey, result.DecryptKey, result.XorKey);
|
||||
Console.WriteLine("Keys saved, press any key to exit");
|
||||
Console.ReadKey(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Not a valid number.");
|
||||
}
|
||||
}
|
||||
}
|
||||
10
src/SimpleModulusKeyGenerator/Properties/AssemblyInfo.cs
Normal file
10
src/SimpleModulusKeyGenerator/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
// <copyright file="AssemblyInfo.cs" company="MUnique">
|
||||
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
|
||||
// </copyright>
|
||||
|
||||
using System.Reflection;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("MUnique.OpenMU.SimpleModulusKeyGenerator")]
|
||||
Reference in New Issue
Block a user