crypto attempts

This commit is contained in:
raphaeIl
2025-01-11 02:24:07 -05:00
parent 55c3fc1fec
commit 0b12a29289
18 changed files with 6810 additions and 41 deletions

View File

@@ -4,6 +4,8 @@ using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using NSec.Cryptography;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace Novaria.Common.Crypto
{
@@ -12,15 +14,87 @@ namespace Novaria.Common.Crypto
public static readonly byte[] DEFAULT_SERVERLIST_KEY;
public static readonly byte[] DEFAULT_SERVERLIST_IV;
public static readonly byte[] associatedData;
public static byte[] GenerateRandomPublicKey()
{
byte[] key = new byte[96];
using (RandomNumberGenerator rng = RandomNumberGenerator.Create())
{
rng.GetBytes(key);
}
return key;
}
public static ReadOnlySpan<byte> AEADMARK
{
get
{
return AeadTool.associatedData.AsSpan(12, 1);
}
}
public static byte[] key3 { get; set; }
static AeadTool()
{
DEFAULT_SERVERLIST_KEY = new byte[] { 74, 72, 42, 67, 80, 51, 50, 57, 89, 120, 111, 103, 81, 74, 69, 120 };
DEFAULT_SERVERLIST_IV = new byte[] { 225, 92, 61, 72, 193, 89, 3, 64, 50, 61, 50, 145, 59, 128, 99, 72 };
key3 = new byte[32];
associatedData = new byte[13];
// assume AesGcm not supported (frida log)
associatedData[associatedData.Length - 1] = 1;
}
public static bool Dencrypt_ChaCha20(Span<byte> result, ReadOnlySpan<byte> key, ReadOnlySpan<byte> nonce, ReadOnlySpan<byte> data)
{
Algorithm chaCha20Poly = AeadAlgorithm.ChaCha20Poly1305;
KeyBlobFormat keyBlobFormat = KeyBlobFormat.RawSymmetricKey;
KeyCreationParameters keyCreationParameters = default(KeyCreationParameters);
bool result2;
using (Key key2 = Key.Import(chaCha20Poly, key, keyBlobFormat, ref keyCreationParameters))
{
result2 = AeadAlgorithm.ChaCha20Poly1305.Decrypt(key2, nonce, null, data, result);
}
return result2;
}
public static void Encrypt_ChaCha20(Span<byte> result, ReadOnlySpan<byte> key, ReadOnlySpan<byte> nonce, ReadOnlySpan<byte> data, bool needAssociatedData)
{
Algorithm chaCha20Poly = AeadAlgorithm.ChaCha20Poly1305;
KeyBlobFormat keyBlobFormat = KeyBlobFormat.RawSymmetricKey;
KeyCreationParameters keyCreationParameters = default(KeyCreationParameters);
using (Key key2 = Key.Import(chaCha20Poly, key, keyBlobFormat, ref keyCreationParameters))
{
if (!needAssociatedData)
{
AeadAlgorithm.ChaCha20Poly1305.Encrypt(key2, nonce, null, data, result);
} else
{
nonce.CopyTo(AeadTool.associatedData.AsSpan(0, 12));
AeadAlgorithm.ChaCha20Poly1305.Encrypt(key2, nonce, AeadTool.associatedData.AsSpan<byte>(), data, result);
}
}
}
// probably wrong
public static byte[] DecryptAesCBCInfo(byte[] key, byte[] IV, byte[] cipherBytes)
{
return null;
using (Aes aes = Aes.Create())
{
aes.Key = key;
aes.IV = IV;
aes.Mode = CipherMode.CBC;
aes.Padding = PaddingMode.PKCS7;
using (ICryptoTransform decryptor = aes.CreateDecryptor())
{
return decryptor.TransformFinalBlock(cipherBytes, 0, cipherBytes.Length);
}
}
}
public static byte[] EncryptAesCBCInfo(byte[] key, byte[] IV, byte[] plainBytes)

View File

@@ -9,6 +9,7 @@
<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.24.3" />
<PackageReference Include="NSec.Cryptography" Version="24.4.0" />
</ItemGroup>

View File

@@ -0,0 +1,671 @@
// <auto-generated>
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: player_login.proto
// </auto-generated>
#pragma warning disable 1591, 0612, 3021, 8981
#region Designer generated code
using pb = global::Google.Protobuf;
using pbc = global::Google.Protobuf.Collections;
using pbr = global::Google.Protobuf.Reflection;
using scg = global::System.Collections.Generic;
/// <summary>Holder for reflection information generated from player_login.proto</summary>
public static partial class PlayerLoginReflection {
#region Descriptor
/// <summary>File descriptor for player_login.proto</summary>
public static pbr::FileDescriptor Descriptor {
get { return descriptor; }
}
private static pbr::FileDescriptor descriptor;
static PlayerLoginReflection() {
byte[] descriptorData = global::System.Convert.FromBase64String(
string.Concat(
"ChJwbGF5ZXJfbG9naW4ucHJvdG8iJQoHQWNjb3VudBIMCgRuYW1lGAEgASgJ",
"EgwKBHBhc3MYAiABKAkifgoLVXNlclJlcXVlc3QSGQoHYWNjb3VudBgBIAEo",
"CzIILkFjY291bnQSEAoIcGxhdGZvcm0YAiABKAkSEAoIbGFuZ3VhZ2UYAyAB",
"KAkSDwoHY2hhbm5lbBgEIAEoCRIOCgZkZXZpY2UYBSABKAkSDwoHdmVyc2lv",
"bhgGIAEoBWIGcHJvdG8z"));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { },
new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
new pbr::GeneratedClrTypeInfo(typeof(global::Account), global::Account.Parser, new[]{ "Name", "Pass" }, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::UserRequest), global::UserRequest.Parser, new[]{ "Account", "Platform", "Language", "Channel", "Device", "Version" }, null, null, null, null)
}));
}
#endregion
}
#region Messages
[global::System.Diagnostics.DebuggerDisplayAttribute("{ToString(),nq}")]
public sealed partial class Account : pb::IMessage<Account>
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
, pb::IBufferMessage
#endif
{
private static readonly pb::MessageParser<Account> _parser = new pb::MessageParser<Account>(() => new Account());
private pb::UnknownFieldSet _unknownFields;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public static pb::MessageParser<Account> Parser { get { return _parser; } }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public static pbr::MessageDescriptor Descriptor {
get { return global::PlayerLoginReflection.Descriptor.MessageTypes[0]; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
pbr::MessageDescriptor pb::IMessage.Descriptor {
get { return Descriptor; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public Account() {
OnConstruction();
}
partial void OnConstruction();
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public Account(Account other) : this() {
name_ = other.name_;
pass_ = other.pass_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public Account Clone() {
return new Account(this);
}
/// <summary>Field number for the "name" field.</summary>
public const int NameFieldNumber = 1;
private string name_ = "";
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public string Name {
get { return name_; }
set {
name_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
/// <summary>Field number for the "pass" field.</summary>
public const int PassFieldNumber = 2;
private string pass_ = "";
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public string Pass {
get { return pass_; }
set {
pass_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public override bool Equals(object other) {
return Equals(other as Account);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public bool Equals(Account other) {
if (ReferenceEquals(other, null)) {
return false;
}
if (ReferenceEquals(other, this)) {
return true;
}
if (Name != other.Name) return false;
if (Pass != other.Pass) return false;
return Equals(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public override int GetHashCode() {
int hash = 1;
if (Name.Length != 0) hash ^= Name.GetHashCode();
if (Pass.Length != 0) hash ^= Pass.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
return hash;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public override string ToString() {
return pb::JsonFormatter.ToDiagnosticString(this);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void WriteTo(pb::CodedOutputStream output) {
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
output.WriteRawMessage(this);
#else
if (Name.Length != 0) {
output.WriteRawTag(10);
output.WriteString(Name);
}
if (Pass.Length != 0) {
output.WriteRawTag(18);
output.WriteString(Pass);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
#endif
}
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
if (Name.Length != 0) {
output.WriteRawTag(10);
output.WriteString(Name);
}
if (Pass.Length != 0) {
output.WriteRawTag(18);
output.WriteString(Pass);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(ref output);
}
}
#endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public int CalculateSize() {
int size = 0;
if (Name.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Name);
}
if (Pass.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Pass);
}
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}
return size;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void MergeFrom(Account other) {
if (other == null) {
return;
}
if (other.Name.Length != 0) {
Name = other.Name;
}
if (other.Pass.Length != 0) {
Pass = other.Pass;
}
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void MergeFrom(pb::CodedInputStream input) {
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
input.ReadRawMessage(this);
#else
uint tag;
while ((tag = input.ReadTag()) != 0) {
if ((tag & 7) == 4) {
// Abort on any end group tag.
return;
}
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
break;
case 10: {
Name = input.ReadString();
break;
}
case 18: {
Pass = input.ReadString();
break;
}
}
}
#endif
}
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
uint tag;
while ((tag = input.ReadTag()) != 0) {
if ((tag & 7) == 4) {
// Abort on any end group tag.
return;
}
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
break;
case 10: {
Name = input.ReadString();
break;
}
case 18: {
Pass = input.ReadString();
break;
}
}
}
}
#endif
}
[global::System.Diagnostics.DebuggerDisplayAttribute("{ToString(),nq}")]
public sealed partial class UserRequest : pb::IMessage<UserRequest>
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
, pb::IBufferMessage
#endif
{
private static readonly pb::MessageParser<UserRequest> _parser = new pb::MessageParser<UserRequest>(() => new UserRequest());
private pb::UnknownFieldSet _unknownFields;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public static pb::MessageParser<UserRequest> Parser { get { return _parser; } }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public static pbr::MessageDescriptor Descriptor {
get { return global::PlayerLoginReflection.Descriptor.MessageTypes[1]; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
pbr::MessageDescriptor pb::IMessage.Descriptor {
get { return Descriptor; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public UserRequest() {
OnConstruction();
}
partial void OnConstruction();
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public UserRequest(UserRequest other) : this() {
account_ = other.account_ != null ? other.account_.Clone() : null;
platform_ = other.platform_;
language_ = other.language_;
channel_ = other.channel_;
device_ = other.device_;
version_ = other.version_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public UserRequest Clone() {
return new UserRequest(this);
}
/// <summary>Field number for the "account" field.</summary>
public const int AccountFieldNumber = 1;
private global::Account account_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public global::Account Account {
get { return account_; }
set {
account_ = value;
}
}
/// <summary>Field number for the "platform" field.</summary>
public const int PlatformFieldNumber = 2;
private string platform_ = "";
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public string Platform {
get { return platform_; }
set {
platform_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
/// <summary>Field number for the "language" field.</summary>
public const int LanguageFieldNumber = 3;
private string language_ = "";
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public string Language {
get { return language_; }
set {
language_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
/// <summary>Field number for the "channel" field.</summary>
public const int ChannelFieldNumber = 4;
private string channel_ = "";
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public string Channel {
get { return channel_; }
set {
channel_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
/// <summary>Field number for the "device" field.</summary>
public const int DeviceFieldNumber = 5;
private string device_ = "";
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public string Device {
get { return device_; }
set {
device_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
/// <summary>Field number for the "version" field.</summary>
public const int VersionFieldNumber = 6;
private int version_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public int Version {
get { return version_; }
set {
version_ = value;
}
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public override bool Equals(object other) {
return Equals(other as UserRequest);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public bool Equals(UserRequest other) {
if (ReferenceEquals(other, null)) {
return false;
}
if (ReferenceEquals(other, this)) {
return true;
}
if (!object.Equals(Account, other.Account)) return false;
if (Platform != other.Platform) return false;
if (Language != other.Language) return false;
if (Channel != other.Channel) return false;
if (Device != other.Device) return false;
if (Version != other.Version) return false;
return Equals(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public override int GetHashCode() {
int hash = 1;
if (account_ != null) hash ^= Account.GetHashCode();
if (Platform.Length != 0) hash ^= Platform.GetHashCode();
if (Language.Length != 0) hash ^= Language.GetHashCode();
if (Channel.Length != 0) hash ^= Channel.GetHashCode();
if (Device.Length != 0) hash ^= Device.GetHashCode();
if (Version != 0) hash ^= Version.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
return hash;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public override string ToString() {
return pb::JsonFormatter.ToDiagnosticString(this);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void WriteTo(pb::CodedOutputStream output) {
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
output.WriteRawMessage(this);
#else
if (account_ != null) {
output.WriteRawTag(10);
output.WriteMessage(Account);
}
if (Platform.Length != 0) {
output.WriteRawTag(18);
output.WriteString(Platform);
}
if (Language.Length != 0) {
output.WriteRawTag(26);
output.WriteString(Language);
}
if (Channel.Length != 0) {
output.WriteRawTag(34);
output.WriteString(Channel);
}
if (Device.Length != 0) {
output.WriteRawTag(42);
output.WriteString(Device);
}
if (Version != 0) {
output.WriteRawTag(48);
output.WriteInt32(Version);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
#endif
}
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
if (account_ != null) {
output.WriteRawTag(10);
output.WriteMessage(Account);
}
if (Platform.Length != 0) {
output.WriteRawTag(18);
output.WriteString(Platform);
}
if (Language.Length != 0) {
output.WriteRawTag(26);
output.WriteString(Language);
}
if (Channel.Length != 0) {
output.WriteRawTag(34);
output.WriteString(Channel);
}
if (Device.Length != 0) {
output.WriteRawTag(42);
output.WriteString(Device);
}
if (Version != 0) {
output.WriteRawTag(48);
output.WriteInt32(Version);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(ref output);
}
}
#endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public int CalculateSize() {
int size = 0;
if (account_ != null) {
size += 1 + pb::CodedOutputStream.ComputeMessageSize(Account);
}
if (Platform.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Platform);
}
if (Language.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Language);
}
if (Channel.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Channel);
}
if (Device.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Device);
}
if (Version != 0) {
size += 1 + pb::CodedOutputStream.ComputeInt32Size(Version);
}
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}
return size;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void MergeFrom(UserRequest other) {
if (other == null) {
return;
}
if (other.account_ != null) {
if (account_ == null) {
Account = new global::Account();
}
Account.MergeFrom(other.Account);
}
if (other.Platform.Length != 0) {
Platform = other.Platform;
}
if (other.Language.Length != 0) {
Language = other.Language;
}
if (other.Channel.Length != 0) {
Channel = other.Channel;
}
if (other.Device.Length != 0) {
Device = other.Device;
}
if (other.Version != 0) {
Version = other.Version;
}
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void MergeFrom(pb::CodedInputStream input) {
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
input.ReadRawMessage(this);
#else
uint tag;
while ((tag = input.ReadTag()) != 0) {
if ((tag & 7) == 4) {
// Abort on any end group tag.
return;
}
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
break;
case 10: {
if (account_ == null) {
Account = new global::Account();
}
input.ReadMessage(Account);
break;
}
case 18: {
Platform = input.ReadString();
break;
}
case 26: {
Language = input.ReadString();
break;
}
case 34: {
Channel = input.ReadString();
break;
}
case 42: {
Device = input.ReadString();
break;
}
case 48: {
Version = input.ReadInt32();
break;
}
}
}
#endif
}
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
uint tag;
while ((tag = input.ReadTag()) != 0) {
if ((tag & 7) == 4) {
// Abort on any end group tag.
return;
}
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
break;
case 10: {
if (account_ == null) {
Account = new global::Account();
}
input.ReadMessage(Account);
break;
}
case 18: {
Platform = input.ReadString();
break;
}
case 26: {
Language = input.ReadString();
break;
}
case 34: {
Channel = input.ReadString();
break;
}
case 42: {
Device = input.ReadString();
break;
}
case 48: {
Version = input.ReadInt32();
break;
}
}
}
}
#endif
}
#endregion
#endregion Designer generated code

File diff suppressed because one or more lines are too long

View File

@@ -1,4 +1,5 @@
using System;
using Google.Protobuf.Reflection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -8,6 +9,31 @@ namespace Novaria.Common.Utils
{
public static class Utils
{
public static void SaveFileDescriptorProtoToFile(FileDescriptorProto fileDescriptorProto, string outputDirectory)
{
if (fileDescriptorProto == null)
{
throw new ArgumentNullException(nameof(fileDescriptorProto));
}
if (string.IsNullOrEmpty(outputDirectory))
{
throw new ArgumentException("Output directory cannot be null or empty", nameof(outputDirectory));
}
string protoName = fileDescriptorProto.Name ?? "unknown.proto";
string protoContent = fileDescriptorProto.ToString();
string outputPath = Path.Combine(outputDirectory, protoName);
Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
File.WriteAllText(outputPath, protoContent);
Console.WriteLine($"Saved {protoName} to {outputPath}");
}
public static void PrintByteArray(byte[] byteArray)
{
if (byteArray == null || byteArray.Length == 0)

View File

@@ -0,0 +1,104 @@
using Microsoft.AspNetCore.Mvc;
using Novaria.Common.Crypto;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.Json;
using System.Text;
using Serilog;
using Novaria.Common.Utils;
using System.IO;
using System.Numerics;
using System.Security.Cryptography;
namespace Novaria.SDKServer.Controllers.Api
{
[Route("/agent-zone-1")]
public class GatewayController : ControllerBase
{
public int req_count;
[HttpPost]
public IActionResult PostRequest()
{
//var memoryStream = new MemoryStream();
//Request.Body.CopyTo(memoryStream);
//byte[] requestBodyBytes = memoryStream.ToArray();
//Log.Information("Received Gateway Post Request, Payload: ");
//Utils.PrintByteArray(requestBodyBytes);
Response.Headers.Add("Date", DateTime.UtcNow.ToString("R"));
Response.Headers.Add("Content-Length", "171");
Response.Headers.Add("Connection", "keep-alive");
Response.Headers.Append("Set-Cookie", "SERVERID=eef797ff9d3671d413582d7dc2f39f29|1736422941|1736422941;Path=/");
Response.Headers.Append("Set-Cookie", "SERVERCORSID=eef797ff9d3671d413582d7dc2f39f29|1736422941|1736422941;Path=/;SameSite=None;Secure");
string filePath = "E:\\documents\\Decompiling\\Extracted\\NOVA\\Novaria\\Novaria.SDKServer\\response1"; // Replace with the actual file path
if (req_count == 1)
{
filePath = "E:\\documents\\Decompiling\\Extracted\\NOVA\\Novaria\\Novaria.SDKServer\\response2"; // Replace with the actual file path
}
byte[] fileBytes = System.IO.File.ReadAllBytes(filePath);
Response.Body.WriteAsync(fileBytes, 0, fileBytes.Length);
req_count++;
return new EmptyResult();
}
[HttpOptions] // Ike
public IActionResult OptionsRequest()
{
// store key which is used in AeadTool
// Set response headers
Response.Headers.Add("Date", DateTime.UtcNow.ToString("R"));
Response.Headers.Add("Content-Length", "251");
Response.Headers.Add("Connection", "keep-alive");
// Set cookies
Response.Headers.Append("Set-Cookie", "acw_tc=cb6df452e3196d1ec00d2fcdf7726b25ed2accbaa45e1066701a61d2da90b384;path=/;HttpOnly;Max-Age=1800");
Response.Headers.Append("Set-Cookie", "SERVERID=eef797ff9d3671d413582d7dc2f39f29|1736422941|1736422941;Path=/");
Response.Headers.Append("Set-Cookie", "SERVERCORSID=eef797ff9d3671d413582d7dc2f39f29|1736422941|1736422941;Path=/;SameSite=None;Secure");
// Set binary content as the response body
string filePath = "E:\\documents\\Decompiling\\Extracted\\NOVA\\Novaria\\Novaria.SDKServer\\options_response"; // Replace with the actual file path
byte[] fileBytes = System.IO.File.ReadAllBytes(filePath);
// Write bytes directly to response body
Response.Body.WriteAsync(fileBytes, 0, fileBytes.Length);
// Return no content since the body is written manually
return new EmptyResult();
}
//private DiffieHellmanManaged SendKey;
//// put in connection prob
//public static void SetAeadKey(byte[] pubKey) // original lead to HttpNetworkManager
//{
// byte[] array = this.SendKey.DecryptKeyExchange(pubKey);
// int num = array.Length;
// if (num > 32)
// {
// num = 32;
// }
// this.key3 = new byte[32];
// Buffer.BlockCopy(array, 0, this.key3, 0, num);
// this.HasKey3 = true;
// this.seq = 1;
//}
//public byte[] DecryptKeyExchange(byte[] keyEx)
//{
// BigInteger bigInteger = new BigInteger(keyEx).ModPow(this.m_X, this.m_P);
// byte[] bytes = bigInteger.GetBytes();
// bigInteger.Clear();
// return bytes;
//}
}
}

View File

@@ -0,0 +1,35 @@
using Microsoft.AspNetCore.Mvc;
using Serilog;
namespace Novaria.SDKServer.CoNovariaollers
{
[ApiController]
[Route("/health-game")]
public class HealthGameController : ControllerBase
{
[Route("identity-auth")]
public IResult PostIdentityAuth()
{
Log.Information("post login received!");
string jsonResponse = @"
{
""Code"": 200,
""Data"": {
""Identity"": {
""BirthDate"": """",
""IDCard"": ""500*********11861*"",
""PI"": """",
""RealName"": ""*思"",
""State"": 1,
""Type"": 0,
""Underage"": false
}
},
""Msg"": ""OK""
}
";
return Results.Text(jsonResponse, "application/json");
}
}
}

View File

@@ -39,20 +39,6 @@ namespace Novaria.SDKServer.CoNovariaollers
Log.Information("Response bytes:");
return File(response, "text/html");
}
[HttpGet("{*catchAll}")]
public IResult CatchAllGet(string catchAll)
{
Log.Information($"HttpGet: {catchAll}");
return Results.Empty;
}
[HttpPost("{*catchAll}")]
public IResult CatchAllPost(string catchAll)
{
Log.Information($"HttpGet: {catchAll}");
return Results.Empty;
}
}
}

View File

@@ -1,23 +0,0 @@
using Microsoft.AspNetCore.Mvc;
using Serilog;
namespace Novaria.SDKServer.CoNovariaollers
{
[ApiController]
[Route("/user")]
public class SDKController : ControllerBase
{
[Route("login")]
public IResult PostLogin()
{
Log.Information("post login received!");
return Results.Text(@"
{
""Code"": 200,
""Data"": {},
""Msg"": ""夏萝莉是小楠梁""
}
");
}
}
}

View File

@@ -0,0 +1,129 @@
using Microsoft.AspNetCore.Mvc;
using Serilog;
namespace Novaria.SDKServer.CoNovariaollers
{
[ApiController]
[Route("/user")]
public class UserController : ControllerBase
{
[Route("login")]
public IResult PostLogin()
{
Log.Information("post login received!");
string jsonResponse = @"
{
""Code"": 200,
""Data"": {
""IsNew"": true,
""IsTestAccount"": false,
""User"": {
""DestroyState"": 0,
""ID"": 1,
""PID"": ""CN-NOVA"",
""State"": 1,
""Token"": ""f94d936f7235f84493564ee0282e845cccd44828""
}
},
""Msg"": ""OK""
}
";
return Results.Text(jsonResponse, "application/json");
}
[Route("quick-login")]
public IResult PostQuickLogin()
{
Log.Information("post login received!");
string jsonResponse = @"
{
""Code"": 200,
""Data"": {
""Destroy"": {
""DestroyAt"": 0
},
""Identity"": {
""BirthDate"": """",
""IDCard"": ""500*********11861*"",
""PI"": """",
""RealName"": ""*思"",
""State"": 1,
""Type"": 0,
""Underage"": false
},
""IsTestAccount"": false,
""Keys"": [
{
""NickName"": ""123****4567"",
""Type"": ""mobile""
}
],
""User"": {
""DestroyState"": 0,
""ID"": 1,
""PID"": ""CN-NOVA"",
""State"": 1,
""Token"": ""f94d936f7235f84493564ee0282e845cccd44828""
},
""Yostar"": {
""CreatedAt"": 1735902342,
""DefaultNickName"": """",
""ID"": 1,
""NickName"": ""夏萝莉是小楠梁"",
""Picture"": """",
""State"": 1
}
},
""Msg"": ""OK""
}
";
return Results.Text(jsonResponse, "application/json");
}
[Route("detail")]
public IResult PostDetail()
{
string jsonResponse = @"
{
""Code"": 200,
""Data"": {
""Destroy"": {
""DestroyAt"": 0
},
""Identity"": null,
""IsTestAccount"": false,
""Keys"": [
{
""NickName"": ""123****4567"",
""Type"": ""mobile""
}
],
""User"": {
""DestroyState"": 0,
""ID"": 1,
""PID"": ""CN-NOVA"",
""State"": 1,
""Token"": ""f94d936f7235f84493564ee0282e845cccd44828""
},
""Yostar"": {
""CreatedAt"": 1,
""DefaultNickName"": """",
""ID"": 1,
""NickName"": ""夏萝莉是小楠梁"",
""Picture"": """",
""State"": 1
}
},
""Msg"": ""OK""
}
";
return Results.Text(jsonResponse, "application/json");
}
}
}

View File

@@ -14,9 +14,12 @@
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageReference Include="Serilog" Version="3.1.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Novaria.Common\Novaria.Common.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,7 +1,11 @@
using System.Reflection;
using System.Security.Cryptography;
using System.Collections;
using System.Reflection;
using Google.Protobuf;
using Google.Protobuf.Reflection;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Newtonsoft.Json;
using Novaria.Common.Crypto;
using Novaria.Common.Utils;
using Pb;
using Serilog;
@@ -11,6 +15,106 @@ namespace Novaria.SDKServer
{
public static void Main(string[] args)
{
var protos = FileDescriptorSet.Parser.ParseFrom(PB.ProtoPB);
var tables = FileDescriptorSet.Parser.ParseFrom(PB.TablePB);
var tempDatas = FileDescriptorSet.Parser.ParseFrom(PB.RogueLikeTempDataPB);
foreach (var fileDescriptorProto in protos.File)
{
Console.WriteLine(fileDescriptorProto.ToString());
//Utils.SaveFileDescriptorProtoToFile(fileDescriptorProto, "protos");
}
foreach (var fileDescriptorProto in tables.File)
{
//Utils.SaveFileDescriptorProtoToFile(fileDescriptorProto, "tables");
}
foreach (var fileDescriptorProto in tempDatas.File)
{
//Utils.SaveFileDescriptorProtoToFile(fileDescriptorProto, "temp_datas");
}
Span<byte> ss = new byte[]
{
0, 5, 10, 134, 1, 68, 109, 47, 77, 102, 110, 116, 78, 49, 107, 78,
97, 83, 47, 49, 79, 110, 121, 51, 86, 82, 76, 100, 90, 67, 69, 113,
47, 71, 47, 70, 81, 112, 83, 86, 65, 114, 48, 81, 112, 101, 107, 104,
104, 106, 83, 69, 48, 51, 73, 121, 107, 108, 65, 102, 65, 84, 112, 83,
56, 85, 80, 76, 107, 76, 103, 48, 80, 119, 116, 80, 48, 67, 78, 86,
43, 76, 85, 103, 98, 51, 75, 97, 79, 111, 56, 89, 115, 106, 68, 66,
86, 77, 51, 47, 65, 83, 108, 80, 77, 109, 56, 68, 50, 111, 119, 108,
71, 119, 106, 81, 83, 71, 105, 54, 106, 79, 97, 102, 99, 49, 122, 84,
98, 107, 89, 81, 121, 76, 43, 56, 121, 90, 103
};
Span<byte> result = new byte[ss.Length];
ReadOnlySpan<byte> key = new byte[]
{
21, 218, 151, 4, 236, 175, 191, 183, 193, 244, 248, 163, 11, 144, 99, 164,
138, 121, 155, 96, 50, 149, 206, 111, 180, 143, 229, 65, 219, 192, 118, 47
};
ReadOnlySpan<byte> nonce = new byte[]
{
231, 71, 160, 150, 98, 120, 185, 234, 18, 80, 239, 227
};
ReadOnlySpan<byte> data = new byte[]
{
18, 191, 220, 69, 194, 61, 223, 106, 190, 177, 23, 221, 204, 255, 80, 97,
197, 131, 41, 185, 42, 139, 225, 133, 223, 140, 11, 43, 152, 78, 4, 163,
87, 50, 33, 61, 168, 219, 213, 188, 78, 115, 60, 143, 185, 165, 3, 62,
154, 34, 156, 61, 175, 105, 25, 129, 254, 143, 225, 107, 211, 9, 201, 7,
10, 85, 115, 115, 131, 209, 20, 48, 124, 149, 33, 52, 204, 166, 154, 207,
206, 28, 76, 249, 48, 191, 249, 11, 236, 193, 49, 216, 226, 101, 52, 234,
73, 79, 154, 226, 141, 9, 70, 194, 252, 202, 65, 168, 247, 161, 228, 84,
246, 133, 84, 64, 64, 252, 55, 44, 5, 164, 143, 110, 140, 232, 125, 91,
244, 62, 170, 18, 0, 212, 72, 235, 250, 85, 143, 89, 26, 162, 186, 243,
4, 222, 193, 249, 215, 243, 155, 204, 88, 131, 145
};
AeadTool.Dencrypt_ChaCha20(result, key, nonce, data);
Utils.PrintByteArray(result.ToArray());
return;
//byte[] bytes = File.ReadAllBytes("E:\\documents\\Decompiling\\Extracted\\NOVA\\Novaria\\Novaria.SDKServer\\req1");
// byte[] data = new byte[] {
// 88, 2, 120, 1, 106, 8, 79, 102, 102, 105, 99, 105, 97, 108,
// 98, 5, 122, 104, 95, 67, 78, 114, 16, 100, 99, 49, 56, 101,
// 49, 50, 98, 57, 54, 50, 57, 101, 57, 52, 101, 26, 48, 18,
// 40, 50, 50, 97, 99, 56, 56, 54, 101, 53, 102, 98, 101, 101,
// 102, 52, 100, 98, 98, 56, 100, 56, 51, 54, 100, 56, 98, 99,
// 98, 49, 54, 54, 54, 56, 100, 98, 55, 99, 97, 55, 100, 8,
// 240, 186, 151, 225, 3
//};
//var a = UserRequest.Parser.ParseFrom(data);
//Console.WriteLine(JsonConvert.SerializeObject(a));
//ServerListMeta message;
//using (var input = File.OpenRead("E:\\documents\\Decompiling\\Extracted\\NOVA\\Novaria\\Novaria.SDKServer\\test_protos.pb"))
//{
// message = ServerListMeta.Parser.ParseFrom(input);
//}
//Console.WriteLine(message.Announcement);
//return;
//byte[] bytes = File.ReadAllBytes("E:\\documents\\Decompiling\\Extracted\\NOVA\\Novaria\\Novaria.SDKServer\\req1");
//byte[] result = AeadTool.DecryptAesCBCInfo(AeadTool.DEFAULT_SERVERLIST_KEY, bytes[..16], bytes[16..(((int)(bytes.Length / 16)) * 16)]);
////Utils.PrintByteArray(result);
//string resstr = System.Text.Encoding.UTF8.GetString(result);
//Console.WriteLine(resstr); // Output: "Hello"
Log.Information("Starting SDK Server...");
try
{

View File

@@ -0,0 +1,3 @@
<EFBFBD><EFBFBD>d<EFBFBD>
'<27><1A>!<21>15L<35>M<EFBFBD>m<EFBFBD>P<EFBFBD><50><0F>}n1<6E><31>b
<EFBFBD>&<26><08><><EFBFBD><EFBFBD>u<g<>Ui<55>OP1C<31><43><EFBFBD><EFBFBD>#<23><1D> Ht<48><0E> <20><>EZ<15>j<EFBFBD>MlZ<6C>B<EFBFBD>{<13>m<EFBFBD>tKY'V<>d<EFBFBD><64>?<3F><>ߨ<EFBFBD><DFA8>Lf<4C><66>:`W<>

2
Novaria.SDKServer/req1 Normal file
View File

@@ -0,0 +1,2 @@
<15><>GsQ<>xK!P]<5D><1D>kl<6B><6C><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>b6&J<1E><><EFBFBD>q-<12>H<EFBFBD>ߺ<EFBFBD>8<EFBFBD>Qi<51><69><EFBFBD><EFBFBD><EFBFBD>B4<42>_<EFBFBD><5F>UH<55>H<><48>/z*Q<>Xu<58><75>/<2F>[Hؽ<17>Y<EFBFBD>@<40><1F>JQc&HsV<73><56><11><>& <20><>H<EFBFBD> <0B>
<EFBFBD>$P<><50>e<><65>v<EFBFBD>y<>åV<C3A5> |,|<7C>n<14><><EFBFBD><EFBFBD>v<EFBFBD><76>/i<>aSq<53>S.<2E>4<EFBFBD><34>ߝ<EFBFBD><DF9D>*d!

BIN
Novaria.SDKServer/resData Normal file

Binary file not shown.

BIN
Novaria.SDKServer/response1 Normal file

Binary file not shown.

View File

@@ -0,0 +1 @@
<EFBFBD>bJ<EFBFBD>6|<12>><3E>Od<4F>.<2E>æ<>ADW<44>Q<>i[<5B>

File diff suppressed because it is too large Load Diff