-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #120 from BigBang1112/dev
GBX.NET 2.0.7
- Loading branch information
Showing
119 changed files
with
1,701 additions
and
306 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace GBX.NET.BlockInfo; | ||
|
||
public class Class1 | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using GBX.NET.Exceptions; | ||
using GBX.NET.Serialization; | ||
using System.Text; | ||
|
||
namespace GBX.NET.Crypto; | ||
|
||
public static partial class Cry | ||
{ | ||
private const ulong Key = 0xCF08317C90460052; | ||
|
||
[Zomp.SyncMethodGenerator.CreateSyncVersion] | ||
public static async Task<string> DecryptAsync(Stream stream, CancellationToken cancellationToken = default) | ||
{ | ||
if (Gbx.LZO is null) | ||
{ | ||
throw new LzoNotDefinedException(); | ||
} | ||
|
||
using var r = new GbxReader(stream); | ||
var uncompressedSize = r.ReadInt32(); | ||
var compressedData = await r.ReadDataAsync(cancellationToken); | ||
|
||
var uncompressedData = new byte[uncompressedSize]; | ||
|
||
Gbx.LZO.Decompress(compressedData, uncompressedData); | ||
|
||
var shift = uncompressedSize & 0x3F; | ||
var rotkey = (Key << shift) | (Key >> (64 - shift)); | ||
|
||
var rotkeyBytes = BitConverter.GetBytes(rotkey); | ||
|
||
for (int i = 0; i < uncompressedSize; i++) | ||
{ | ||
uncompressedData[i] ^= rotkeyBytes[i & 0x7]; | ||
} | ||
|
||
return Encoding.ASCII.GetString(uncompressedData); | ||
} | ||
|
||
public static async Task<string> DecryptAsync(string fileName, CancellationToken cancellationToken = default) | ||
{ | ||
#if !NETSTANDARD2_0 | ||
await | ||
#endif | ||
using var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, useAsync: true); | ||
return await DecryptAsync(fs, cancellationToken); | ||
} | ||
|
||
public static string Decrypt(string fileName) | ||
{ | ||
using var fs = File.OpenRead(fileName); | ||
return Decrypt(fs); | ||
} | ||
|
||
[Zomp.SyncMethodGenerator.CreateSyncVersion] | ||
public static async Task EncryptAsync(Stream stream, string contents, CancellationToken cancellationToken = default) | ||
{ | ||
if (Gbx.LZO is null) | ||
{ | ||
throw new LzoNotDefinedException(); | ||
} | ||
|
||
var uncompressedData = Encoding.ASCII.GetBytes(contents); | ||
|
||
var shift = uncompressedData.Length & 0x3F; | ||
var rotkey = (Key << shift) | (Key >> (64 - shift)); | ||
|
||
var rotkeyBytes = BitConverter.GetBytes(rotkey); | ||
|
||
for (int i = 0; i < uncompressedData.Length; i++) | ||
{ | ||
uncompressedData[i] ^= rotkeyBytes[i & 0x7]; | ||
} | ||
|
||
using var w = new GbxWriter(stream); | ||
|
||
w.Write(uncompressedData.Length); | ||
|
||
var compressedData = Gbx.LZO.Compress(uncompressedData); | ||
await w.WriteDataAsync(compressedData, cancellationToken); | ||
} | ||
|
||
public static async Task EncryptAsync(string fileName, string contents, CancellationToken cancellationToken = default) | ||
{ | ||
#if !NETSTANDARD2_0 | ||
await | ||
#endif | ||
using var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None, 4096, useAsync: true); | ||
await EncryptAsync(fs, contents, cancellationToken); | ||
} | ||
|
||
public static void Encrypt(string fileName, string contents) | ||
{ | ||
using var fs = File.Create(fileName); | ||
Encrypt(fs, contents); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System.Text; | ||
|
||
namespace GBX.NET.Crypto; | ||
|
||
public static partial class MD5 | ||
{ | ||
public static byte[] Compute(byte[] data) | ||
{ | ||
#if NET6_0_OR_GREATER | ||
return System.Security.Cryptography.MD5.HashData(data); | ||
#else | ||
using var md5 = System.Security.Cryptography.MD5.Create(); | ||
return md5.ComputeHash(data); | ||
#endif | ||
} | ||
|
||
public static byte[] Compute(string data) | ||
{ | ||
return Compute(Encoding.ASCII.GetBytes(data)); | ||
} | ||
|
||
#if NET8_0_OR_GREATER | ||
public static async ValueTask<byte[]> ComputeAsync(byte[] data, CancellationToken cancellationToken = default) | ||
{ | ||
await using var ms = new MemoryStream(data); | ||
return await System.Security.Cryptography.MD5.HashDataAsync(ms, cancellationToken); | ||
} | ||
#elif NET6_0_OR_GREATER || NETSTANDARD2_0 | ||
public static async Task<byte[]> ComputeAsync(byte[] data, CancellationToken cancellationToken = default) | ||
{ | ||
using var md5 = System.Security.Cryptography.MD5.Create(); | ||
#if NET6_0_OR_GREATER | ||
await using var ms = new MemoryStream(data); | ||
return await md5.ComputeHashAsync(ms, cancellationToken); | ||
#else | ||
return await Task.FromResult(md5.ComputeHash(data)); | ||
#endif | ||
} | ||
#endif | ||
|
||
public static async Task<byte[]> ComputeAsync(string data, CancellationToken cancellationToken = default) | ||
{ | ||
return await ComputeAsync(Encoding.ASCII.GetBytes(data), cancellationToken); | ||
} | ||
} |
Oops, something went wrong.