Skip to content

Commit

Permalink
vcryptpp: update C# bindings, create test project
Browse files Browse the repository at this point in the history
  • Loading branch information
craftablescience committed Dec 30, 2024
1 parent be97344 commit b6c1305
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 48 deletions.
9 changes: 7 additions & 2 deletions lang/c/include/vcryptppc/VICE.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

#include <sourceppc/Buffer.h>

#define VCRYPTPP_VICE_KNOWN_CODES_DEFAULT "x9Ke0BY7";

#define VCRYPTPP_VICE_KNOWN_CODES_DEFAULT "x9Ke0BY7";
#define VCRYPTPP_VICE_BLOODY_GOOD_TIME "K4PeJwL7"
#define VCRYPTPP_VICE_KNOWN_CODES_CONTAGION_WEAPONS "fUk0fF69"
#define VCRYPTPP_VICE_KNOWN_CODES_CONTAGION_SCRIPTS "5!rrFz6p"
Expand All @@ -27,6 +26,12 @@
#define VCRYPTPP_VICE_KNOWN_CODES_THE_SHIP "eb3A4m79"
#define VCRYPTPP_VICE_KNOWN_CODES_ZOMBIE_PANIC_SOURCE "5R0ni0pZ"

#define VCRYPTPP_VICE_KNOWN_CODES_EKV_GPU_DEFAULT "X8bU2qll"
#define VCRYPTPP_VICE_KNOWN_CODES_EKV_GPU_ALIEN_SWARM "sW9.JupP"
#define VCRYPTPP_VICE_KNOWN_CODES_EKV_GPU_LEFT_4_DEAD_1 "zp14Hi(]"
#define VCRYPTPP_VICE_KNOWN_CODES_EKV_GPU_LEFT_4_DEAD_2 EKV_GPU_LEFT_4_DEAD_1
#define VCRYPTPP_VICE_KNOWN_CODES_EKV_GPU_PORTAL_2 "UrE66!Ap"

// REQUIRES MANUAL FREE: sourcepp_buffer_free
SOURCEPP_API sourcepp_buffer_t vcryptpp_vice_encrypt(const unsigned char* buffer, size_t bufferLen, const char* code);

Expand Down
16 changes: 9 additions & 7 deletions lang/csharp/src/vcryptpp/VFONT.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
Expand All @@ -7,8 +6,11 @@ namespace vcryptpp
{
internal static unsafe partial class Extern
{
[DllImport("vcryptppc")]
public static extern Buffer vcryptpp_vfont_decrypt(byte* buffer, ulong bufferLen);
internal static unsafe partial class VFONT
{
[LibraryImport("vcryptppc", EntryPoint = "vcryptpp_vfont_decrypt")]
public static partial sourcepp.Buffer Decrypt(byte* buffer, ulong bufferLen);
}
}

public static class VFONT
Expand All @@ -19,8 +21,8 @@ public static byte[] Decrypt(byte[] buffer)
{
fixed (byte* bufferPtr = buffer)
{
Buffer ret = Extern.vcryptpp_vfont_decrypt(bufferPtr, (ulong) buffer.LongLength);
return BufferUtils.ConvertToArrayAndDelete(ref ret);
var ret = Extern.VFONT.Decrypt(bufferPtr, (ulong) buffer.LongLength);
return sourcepp.BufferUtils.ConvertToArrayAndDelete(ref ret);
}
}
}
Expand All @@ -32,8 +34,8 @@ public static byte[] Decrypt(IEnumerable<byte> buffer)
var data = buffer.ToArray();
fixed (byte* bufferPtr = data)
{
Buffer ret = Extern.vcryptpp_vfont_decrypt(bufferPtr, (ulong) data.LongLength);
return BufferUtils.ConvertToArrayAndDelete(ref ret);
var ret = Extern.VFONT.Decrypt(bufferPtr, (ulong) data.LongLength);
return sourcepp.BufferUtils.ConvertToArrayAndDelete(ref ret);
}
}
}
Expand Down
81 changes: 44 additions & 37 deletions lang/csharp/src/vcryptpp/VICE.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
Expand All @@ -7,39 +6,47 @@ namespace vcryptpp
{
internal static unsafe partial class Extern
{
[DllImport("vcryptppc")]
public static extern Buffer vcryptpp_vice_decrypt(byte* buffer, ulong bufferLen, [MarshalAs(UnmanagedType.LPStr)] string code);
internal static unsafe partial class VICE
{
[LibraryImport("vcryptppc", EntryPoint = "vcryptpp_vice_decrypt")]
public static partial sourcepp.Buffer Decrypt(byte* buffer, ulong bufferLen, [MarshalAs(UnmanagedType.LPStr)] string code);

[DllImport("vcryptppc")]
public static extern Buffer vcryptpp_vice_encrypt(byte* buffer, ulong bufferLen, [MarshalAs(UnmanagedType.LPStr)] string code);
[LibraryImport("vcryptppc", EntryPoint = "vcryptpp_vice_encrypt")]
public static partial sourcepp.Buffer Encrypt(byte* buffer, ulong bufferLen, [MarshalAs(UnmanagedType.LPStr)] string code);
}
}

public static class KnownCodes {
public const string DEFAULT = "x9Ke0BY7";

public const string BLOODY_GOOD_TIME = "K4PeJwL7";
public const string CONTAGION_WEAPONS = "fUk0fF69";
public const string CONTAGION_SCRIPTS = "5!rrFz6p";
public const string COUNTER_STRIKE_SOURCE = "d7NSuLq2";
public const string DEFAULT = "x9Ke0BY7";
public const string BLOODY_GOOD_TIME = "K4PeJwL7";
public const string CONTAGION_WEAPONS = "fUk0fF69";
public const string CONTAGION_SCRIPTS = "5!rrFz6p";
public const string COUNTER_STRIKE_SOURCE = "d7NSuLq2";
public const string COUNTER_STRIKE_GLOBAL_OFFENSIVE = COUNTER_STRIKE_SOURCE;
public const string COUNTER_STRIKE_2 = COUNTER_STRIKE_GLOBAL_OFFENSIVE;
public const string COUNTER_STRIKE_PROMOD = "H1aRQ0n1";
public const string DAY_OF_DEFEAT_SOURCE = "Wl0u5B3F";
public const string DYSTOPIA_1_2 = "pH3apO8w";
public const string DYSTOPIA_1_3 = "G8stUh3F";
public const string GOLDEN_EYE_SOURCE = "Gr3naDes";
public const string HALF_LIFE_2_CTF = "R1dj3axP";
public const string HALF_LIFE_2_DM = DEFAULT;
public const string INSURGENCY = "DrA5e3EB";
public const string LEFT_4_DEAD_2 = "SDhfi878";
public const string NO_MORE_ROOM_IN_HELL = "lREeeapA";
public const string NUCLEAR_DAWN = "TA+*veh9";
public const string TACTICAL_INTERVENTION = "71B4Dt1Z";
public const string TEAM_FORTRESS_2 = "E2NcUkG2";
public const string TEAM_FORTRESS_2_ITEMS = "A5fSXbf7";
public const string THE_SHIP = "eb3A4m79";
public const string ZOMBIE_PANIC_SOURCE = "5R0ni0pZ";
}
public const string COUNTER_STRIKE_2 = COUNTER_STRIKE_GLOBAL_OFFENSIVE;
public const string COUNTER_STRIKE_PROMOD = "H1aRQ0n1";
public const string DAY_OF_DEFEAT_SOURCE = "Wl0u5B3F";
public const string DYSTOPIA_1_2 = "pH3apO8w";
public const string DYSTOPIA_1_3 = "G8stUh3F";
public const string GOLDEN_EYE_SOURCE = "Gr3naDes";
public const string HALF_LIFE_2_CTF = "R1dj3axP";
public const string HALF_LIFE_2_DM = DEFAULT;
public const string INSURGENCY = "DrA5e3EB";
public const string LEFT_4_DEAD_2 = "SDhfi878";
public const string NO_MORE_ROOM_IN_HELL = "lREeeapA";
public const string NUCLEAR_DAWN = "TA+*veh9";
public const string TACTICAL_INTERVENTION = "71B4Dt1Z";
public const string TEAM_FORTRESS_2 = "E2NcUkG2";
public const string TEAM_FORTRESS_2_ITEMS = "A5fSXbf7";
public const string THE_SHIP = "eb3A4m79";
public const string ZOMBIE_PANIC_SOURCE = "5R0ni0pZ";

public const string EKV_GPU_DEFAULT = "X8bU2qll";
public const string EKV_GPU_ALIEN_SWARM = "sW9.JupP";
public const string EKV_GPU_LEFT_4_DEAD_1 = "zp14Hi(]";
public const string EKV_GPU_LEFT_4_DEAD_2 = EKV_GPU_LEFT_4_DEAD_1;
public const string EKV_GPU_PORTAL_2 = "UrE66!Ap";
}

public static class VICE
{
Expand All @@ -49,8 +56,8 @@ public static byte[] Decrypt(byte[] buffer, string code = KnownCodes.DEFAULT)
{
fixed (byte* bufferPtr = buffer)
{
Buffer ret = Extern.vcryptpp_vice_decrypt(bufferPtr, (ulong) buffer.LongLength, code);
return BufferUtils.ConvertToArrayAndDelete(ref ret);
var ret = Extern.VICE.Decrypt(bufferPtr, (ulong) buffer.LongLength, code);
return sourcepp.BufferUtils.ConvertToArrayAndDelete(ref ret);
}
}
}
Expand All @@ -62,8 +69,8 @@ public static byte[] Decrypt(IEnumerable<byte> buffer, string code = KnownCodes.
var data = buffer.ToArray();
fixed (byte* bufferPtr = data)
{
Buffer ret = Extern.vcryptpp_vice_decrypt(bufferPtr, (ulong) data.LongLength, code);
return BufferUtils.ConvertToArrayAndDelete(ref ret);
var ret = Extern.VICE.Decrypt(bufferPtr, (ulong) data.LongLength, code);
return sourcepp.BufferUtils.ConvertToArrayAndDelete(ref ret);
}
}
}
Expand All @@ -74,8 +81,8 @@ public static byte[] Encrypt(byte[] buffer, string code)
{
fixed (byte* bufferPtr = buffer)
{
Buffer ret = Extern.vcryptpp_vice_encrypt(bufferPtr, (ulong) buffer.LongLength, code);
return BufferUtils.ConvertToArrayAndDelete(ref ret);
var ret = Extern.VICE.Encrypt(bufferPtr, (ulong) buffer.LongLength, code);
return sourcepp.BufferUtils.ConvertToArrayAndDelete(ref ret);
}
}
}
Expand All @@ -87,8 +94,8 @@ public static byte[] Encrypt(IEnumerable<byte> buffer, string code)
var data = buffer.ToArray();
fixed (byte* bufferPtr = data)
{
Buffer ret = Extern.vcryptpp_vice_encrypt(bufferPtr, (ulong) data.LongLength, code);
return BufferUtils.ConvertToArrayAndDelete(ref ret);
var ret = Extern.VICE.Encrypt(bufferPtr, (ulong) data.LongLength, code);
return sourcepp.BufferUtils.ConvertToArrayAndDelete(ref ret);
}
}
}
Expand Down
33 changes: 33 additions & 0 deletions lang/csharp/test/vcryptpp.test.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34622.214
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "vcryptpp", "..\src\vcryptpp\vcryptpp.csproj", "{1A936830-5F97-4722-9012-67A324764879}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "vcryptpp.test", "vcryptpp.test\vcryptpp.test.csproj", "{01D95D87-20F5-4CD2-8ED3-38DA43962395}"
ProjectSection(ProjectDependencies) = postProject
{1A936830-5F97-4722-9012-67A324764879} = {1A936830-5F97-4722-9012-67A324764879}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1A936830-5F97-4722-9012-67A324764879}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{1A936830-5F97-4722-9012-67A324764879}.Debug|Any CPU.Build.0 = Release|Any CPU
{1A936830-5F97-4722-9012-67A324764879}.Release|Any CPU.ActiveCfg = Debug|Any CPU
{1A936830-5F97-4722-9012-67A324764879}.Release|Any CPU.Build.0 = Debug|Any CPU
{01D95D87-20F5-4CD2-8ED3-38DA43962395}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{01D95D87-20F5-4CD2-8ED3-38DA43962395}.Debug|Any CPU.Build.0 = Release|Any CPU
{01D95D87-20F5-4CD2-8ED3-38DA43962395}.Release|Any CPU.ActiveCfg = Release|Any CPU
{01D95D87-20F5-4CD2-8ED3-38DA43962395}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3F144514-3209-46B0-821C-2E5B44023D86}
EndGlobalSection
EndGlobal
11 changes: 11 additions & 0 deletions lang/csharp/test/vcryptpp.test/VICETest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace vcryptpp.test
{
[TestClass]
public class VICETest
{
[TestMethod]
public void Decrypt()
{
}
}
}
27 changes: 27 additions & 0 deletions lang/csharp/test/vcryptpp.test/vcryptpp.test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\vcryptpp\vcryptpp.csproj" />
</ItemGroup>

<ItemGroup>
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions lang/csharp/test/vpkpp.test.sln
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34622.214
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "vpkpp", "..\src\vpkpp\vpkpp.csproj", "{EA9C7AA7-6C04-433B-8F64-E38462E88CA6}"
Project("{3D6B5B52-47BF-4FB9-9B11-261BC3E44F2C}") = "vpkpp", "..\src\vpkpp\vpkpp.csproj", "{EA9C7AA7-6C04-433B-8F64-E38462E88CA6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "vpkpp.test", "vpkpp.test\vpkpp.test.csproj", "{3BCD0725-785C-41E6-956F-39E25AAA5D4E}"
Project("{3D6B5B52-47BF-4FB9-9B11-261BC3E44F2C}") = "vpkpp.test", "vpkpp.test\vpkpp.test.csproj", "{3BCD0725-785C-41E6-956F-39E25AAA5D4E}"
ProjectSection(ProjectDependencies) = postProject
{EA9C7AA7-6C04-433B-8F64-E38462E88CA6} = {EA9C7AA7-6C04-433B-8F64-E38462E88CA6}
EndProjectSection
Expand Down

0 comments on commit b6c1305

Please sign in to comment.